
// Async request utils
var g_strAsyncBasePath = "/";
//g_strAsyncBasePath = "";	// singleboundcreative uses relative dir

//Gets the browser specific XmlHttpRequest Object
function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest(); //Not IE
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP"); //IE
	} else {
		//Display your error message here. 
		//and inform the user they might want to upgrade
		//their browser.
		//alert("Your browser doesn't support the XmlHttpRequest object. ");
	}
}			
//Get our browser specific XmlHttpRequest object.
var receiveReq = getXmlHttpRequestObject();		

function getWLRequestId()
{
	var d = new Date()
	var t = d.getTime()	//number of milliseconds since midnight of January 1, 1970.
	var ran = Math.floor(Math.random()*1000000000); // 9 digit random
	var id = "" + t + "" + ran;
	return id;
}


function wishListRequest(cmd, param1, param2)
{
	//param1 = unescape(param1);
	//param2 = unescape(param2);
	
	//If our XmlHttpRequest object is not in the middle of a request, start the new asyncronous call.
	//if (receiveReq.readyState == 4 || receiveReq.readyState == 0) 
	//{
		//Setup the connection as a GET call to proto_request.jsp
		//True explicity sets the request to asyncronous (default).
		//var strR = g_strAsyncBasePath + "proto_request.jsp?cmd=" + cmd + '&p1=' + param1 + '&p2=' + param2 + '&wlrid='+ getWLRequestId();
		//var strR = g_strAsyncBasePath + "webapp/wcs/stores/servlet/WishListCmd" + wishlistQueryParams + "&cmd=" + cmd + '&p1=' + param1 + '&p2=' + param2 + '&wlrid='+ getWLRequestId();
		//receiveReq.open("GET", strR, true);
		
		//Set the function that will be called when the XmlHttpRequest objects state changes.
		//receiveReq.onreadystatechange = onWishListStateChange; 
		//Make the actual request.
		//receiveReq.send(null);
	//}
	//else // request object busy, try again...
	//{
		// javascript is single-threaded, so multiple deferred requests will take care of themselves, but we might not
		// be able to assume they happen in the order they were requested.
		//setTimeout('wishListRequest('+cmd+', "'+escape(param1)+'","' + escape(param2)+ '")', 10);
		//var strT = 'wishListRequest('+cmd+', "'+escape(param1)+'","' + escape(param2)+ '")';
		//setTimeout(strT, 10); 

	//}
}


//Called when XmlHttpRequest objects state changes as result of wishListRequest.
function onWishListStateChange() 
{
	//Check to see if the XmlHttpRequests state is finished.
	if (receiveReq.readyState == 4) 
	{
		//Set the contents of our span element to the result of the asyncronous call.
		if (document.getElementById('span_result'))
		{
			document.getElementById('span_result').innerHTML = receiveReq.responseText;
			syncWishListAppearance(null);	// defined in wishlist.js
		}
	}
}



function listManagerRequest(cmd, param1, param2, callback)
{
	
	param1 = unescape(param1);
	param2 = unescape(param2);
	
	
	//If our XmlHttpRequest object is not in the middle of a request, start the new asyncronous call.
	if (receiveReq.readyState == 4 || receiveReq.readyState == 0) 
	{
		//Setup the connection as a GET call to proto_lman_request.jsp
		//True explicity sets the request to asyncronous (default).
		receiveReq.open("GET", g_strAsyncBasePath + 'proto_lman_request.jsp?cmd=' + cmd + '&p1=' + param1 + '&p2=' + param2 +  '&wlrid='+ getWLRequestId(), true);
		//Set the function that will be called when the XmlHttpRequest objects state changes.
		receiveReq.onreadystatechange = callback; 
		//Make the actual request.
		receiveReq.send(null);
	}
	else // request object busy, try again...
	{
		// javascript is single-threaded, so multiple deferred requests will take care of themselves, but we might not
		// be able to assume they happen in the order they were requested.
		setTimeout('listManagerRequest('+cmd+', "'+escape(param1)+'","' + escape(param2)+ '", ' + callback + ' )', 10); 

	}
}
//Called when XmlHttpRequest objects state changes as result of listManagerRequest.
function onListManagerStateChange1() 
{
	//Check to see if the XmlHttpRequests state is finished.
	if (receiveReq.readyState == 4) 
	{
		//Set the contents of our span element to the result of the asyncronous call.
		document.getElementById('span_result1').innerHTML = receiveReq.responseText;
	}
}
function onListManagerStateChange2() 
{
	//Check to see if the XmlHttpRequests state is finished.
	if (receiveReq.readyState == 4) 
	{
		//Set the contents of our span element to the result of the asyncronous call.
		document.getElementById('span_result2').innerHTML = receiveReq.responseText;
		buildItemListDragBlock();
	}
}



function tuxDetailRequest(cmd, param1, param2, param3)
{
	
	param1 = unescape(param1);
	param2 = unescape(param2);
	param3 = unescape(param3);
	
	//If our XmlHttpRequest object is not in the middle of a request, start the new asyncronous call.
	if (receiveReq.readyState == 4 || receiveReq.readyState == 0) 
	{
		//Setup the connection as a GET call to proto_lman_request.jsp
		//True explicity sets the request to asyncronous (default).
		receiveReq.open("GET", g_strAsyncBasePath + 'proto_tuxdetail_request.jsp?cmd=' + cmd + '&p1=' + param1 + '&p2=' + param2 + '&p3=' + param3+  '&rid='+ getWLRequestId(), true);
		//Set the function that will be called when the XmlHttpRequest objects state changes.
		receiveReq.onreadystatechange = onTuxDetailStateChange; 
		//Make the actual request.
		receiveReq.send(null);
	}
	else // request object busy, try again...
	{
		// javascript is single-threaded, so multiple deferred requests will take care of themselves, but we might not
		// be able to assume they happen in the order they were requested.
		setTimeout('tuxDetailRequest('+cmd+', "'+escape(param1)+'","' + escape(param2)+ '", "' + escape(param3) + '" )', 10); 
	}
}


function onTuxDetailStateChange() 
{
	
	//Check to see if the XmlHttpRequests state is finished.
	if (receiveReq.readyState == 4) 
	{
		//Set the contents of our span element to the result of the asyncronous call.
		document.getElementById('span_result3').innerHTML = receiveReq.responseText;
		
	}
}