var getTransferObject = function(){	return null;	};
if(window.ActiveXObject){
	// Check if the browser has support for ActiveXObject (IE Usually)  
	try{ 
		// Check for the new version of XMLHttp compoment  
		var x=  new ActiveXObject("MSXML2.XMLHTTP"); 
		getTransferObject = function(){ return new ActiveXObject("MSXML2.XMLHTTP"); }
	}catch(_ex){ 
		try{ // Check for late version of XMLHTTP compoment  
			var x = new ActiveXObject("Microsoft.XMLHTTP"); 
			getTransferObject = function(){ return new ActiveXObject("Microsoft.XMLHTTP"); }
		}catch(ex){
			// Otherwise the version of IE is too old  
		} 
	} 
}else if(window.XMLHttpRequest){
	// XMLHttpRequest object supported by Opera, Firefox and Safari - may too in IE 7.  
	getTransferObject = function(){ return new XMLHttpRequest(); }
}

/*
	* make an "Ajax Request".
	* @params: 
		- url : contains the target of the request.
		- params: Hash Table that contains a data that send with the request.
		- aOptions: Associative array that contains an optional property: method of sendinge, 
			2 optional function: 
				- onSuccess(param: RequestObject): will dispatch when the request get a "true" response (status-code=200)
				- onFailure(param: RequestObject): will dispatch when the request get a "false" response (status=code isn't 200)
			and an Hash Table of http headers named: httpHeaders
*/
function doAjaxRequest(params, aOptions){
    var url = FindUrl();
	// get transfer object
	var oReq = getTransferObject();
	if(!oReq){
		// Check for XMLHttpRequest
		throw "Download the newer Firefox or upgrade your browser please.";
		return false;
	}

	// Add HTTP headers to the message
	for(var header in aOptions.httpHeaders){
		oReq.setRequestHeader(header,aOptions.httpHeaders[header]);
	}

	oReq.onreadystatechange = function(){
		if(oReq.readyState==4){
			if(oReq.status==200){
				if(aOptions.onSuccess)
				{   
//				    alert(oReq.responseText)
				    aOptions.onSuccess(oReq);
				} 
			}else{
				if(aOptions.onFailure) aOptions.onFailure(oReq);
			}
		}
	}

	// make parameters string
	var _params = [];
	for(var p in params){
		_params.push(p+"="+encodeURIComponent(params[p]));
	}
	_params = _params.join("&");

	// Default send method: GET
	var method = aOptions.method?aOptions.method:"GET",
		bodyPost= null;


//	if(method=="POST"){
//		oReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
//		oReq.open(method, url, false);
//		bodyPost = _params; // POST data send into the request
//	}else{
//		oReq.open(method, url, false); // GET data send as part of the url
//	}
	
	//send request
	oReq.open("POST",url,false);
	oReq.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	oReq.send(params);
}


function FindUrl()
{
    var Url = document.URL
    var urlSplit = Url.split('/');
    Url = "";
    for (i=0; i<urlSplit.length-1; i++)
    {
        if (urlSplit[i].toLowerCase() != "bo" && urlSplit[i].toLowerCase() != "en")
        {
            Url += urlSplit[i] + "/";
        }
    }
    
    Url += "Ajax/Ajax.aspx"
    
    return Url;
}


function ajaxFailure(oReq)
{
   alert(oReq.responseText)
}




