
// get XMLHttpRequest object
var objhttp=getXMLHTTPObject();
var globalURL;

// function sendRequest
function sendRequest(url,data,method,mode,header)
{
    // set default values
    if(!url){url='default_url.htm'};

    if(!data){data='defaultdata=defaultvalue'};

    if(!method){method='post'};

    if(!mode){mode=true};

    if(!header){header='Content-Type:application/x-www-form-urlencoded; charset=UTF-8'};

	globalURL = url;
	
    // open socket connection
    objhttp.open(method,url,mode);
	
    // set http header
    objhttp.setRequestHeader(header.split(':')[0],header.split(':')[1]);

	objhttp.onreadystatechange = callback;
    
	// send data
    objhttp.send(data);
}

function callback(){
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(objhttp.readyState == 4){ //Finished loading the response
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
		var response = objhttp.responseText;	
		
		/*var newURL = "";
		var hashCnt = location.href.split('/').length;
		
		for(var x = 0; x < hashCnt-1; x++)
		{
			newURL += location.href.split('/')[x];
			newURL += "/";
		}
		newURL += globalURL;*/
		
		//bb_save_state();
		
		//alert(location.href.split('/')[x]);
		
		//location.href = newURL;
		//window.location = newURL;
		
		//alert(newURL);
		
		with(window.document)
		{
			open();		
			write(response);
			close();
		}		
	}
}

function getXMLHTTPObject()
{ 
	var objXMLHttp=null;
	
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	return objXMLHttp;
} 