//
var lastHTTPRequest = null;

//
function SetClass(element, newClass)
{
	element.className = newClass;
}

//
function NavigateTo(url)
{
	window.location.href = url;
}

//Useful HELPER. Move to common!
function wait(msecs)
{
	var start = new Date().getTime();
	var cur = start
	while(cur - start < msecs)
	{
		cur = new Date().getTime();
	} 
} 

//Generic HTTP request
function SendHTTPRequest(method, url, arguments, divId)
{	
	oHTTPRequest = null;
	//instantiate the http request object
	if (window.XMLHttpRequest) 			//If the browser is Mozilla, Safari, or ...
	{
		oHTTPRequest = new XMLHttpRequest(); 
	}
	else if(window.ActiveXObject)		//Otherwise, if the browser is IE
	{
		oHTTPRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}
	lastHTTPRequest = oHTTPRequest;
	
	//Define the callback function.
	oHTTPRequest.onreadystatechange = function()
	{		
		if(oHTTPRequest.readyState == 4)
		{ 
			if(oHTTPRequest.status == 200)
			{
				//Get the response	
				document.getElementById(divId).innerHTML = oHTTPRequest.responseText;
			}
			else
				document.getElementById(divId).innerHTML = "ERROR MAKING HTTP REQUEST. PLEASE CONTACT webmaster@wesource.com";
		}	
	}
	//Make the asynchronous request
	if(method == "POST")
	{
		oHTTPRequest.open('POST', url , true); 
		oHTTPRequest.send(arguments);
	}
	else if(method == "GET")
	{
		oHTTPRequest.open('GET', url + "?" + arguments , true); 
		oHTTPRequest.send(null);		
	}
}

//Synchronous HTTP request
function SendSyncHTTPRequest(method, url, arguments)
{	
	oHTTPRequest = null;
	//instantiate the http request object
	if (window.XMLHttpRequest) 			//If the browser is Mozilla, Safari, or ...
	{
		oHTTPRequest = new XMLHttpRequest(); 
	}
	else if(window.ActiveXObject)		//Otherwise, if the browser is IE
	{
		oHTTPRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	//Make the asynchronous request
	if(method == "POST")
	{
		oHTTPRequest.open('POST', url , false);
		oHTTPRequest.send(arguments);
		return oHTTPRequest.responseText;
	}
	else if(method == "GET")
	{
		oHTTPRequest.open('GET', url + "?" + arguments , false);
		oHTTPRequest.send(null);
		return oHTTPRequest.responseText;
	}
}

//Continuation-Passing Style HTTP request
function SendCPSHTTPRequest(method, url, arguments, func)
{	
	oHTTPRequest = null;
	//instantiate the http request object
	if (window.XMLHttpRequest) 			//If the browser is Mozilla, Safari, or ...
	{
		oHTTPRequest = new XMLHttpRequest(); 
	}
	else if(window.ActiveXObject)		//Otherwise, if the browser is IE
	{
		oHTTPRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}
	lastHTTPRequest = oHTTPRequest;
	
	//Define the callback function.
	oHTTPRequest.onreadystatechange = function()
	{		
		if(oHTTPRequest.readyState == 4)
		{ 
			if(oHTTPRequest.status == 200)
			{
				//Get the response	
				func(oHTTPRequest.responseText);
			}
			else
				func("ERROR MAKING HTTP REQUEST. PLEASE CONTACT webmaster@wesource.com");
		}	
	}
	//Make the asynchronous request
	if(method == "POST")
	{
		oHTTPRequest.open('POST', url , true); 
		oHTTPRequest.send(arguments);
	}
	else if(method == "GET")
	{
		oHTTPRequest.open('GET', url + "?" + arguments , true); 
		oHTTPRequest.send(null);		
	}
}