var xmlHttp;// global instance of XMLHttpRequest

function createXmlHttpRequest()
{
	xmlHttp = false;

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
        xmlHttp = new XMLHttpRequest();
        if (xmlHttp.overrideMimeType) {
        	// set type accordingly to anticipated content type
           //xmlHttp.overrideMimeType('text/xml');
           xmlHttp.overrideMimeType('text/html');
        }
     } else if (window.ActiveXObject) { // IE
        try {
           xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
           try {
              xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
           } catch (e) {}
        }
     }
     if (!xmlHttp) {
        alert('Cannot create XMLHTTP instance');
        return false;
     }
}

function sendXmlHttpRequest(url, callFunction){
	createXmlHttpRequest();
	xmlHttp.open("GET", url.replace('+','%2B') ,true);
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4){
			if(xmlHttp.status==200){	
				//alert(callFunction);
				try{
					//eval(callFunction);
					callFunction(xmlHttp.responseText);
				}catch(err){
					alert(err.toString());
				}
			}else{
				alert("Error loading page"+ xmlHttp.status +":"+xmlHttp.statusText);
			}
		}
	};
	xmlHttp.send(null);
}

function sendXmlHttpRequestByPost(url, parameters, callbackFunction){

	createXmlHttpRequest();
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4){
		
			if(xmlHttp.status==200){
				try{
					//eval(callbackFunction);
					callbackFunction(xmlHttp.responseText);
				}catch(err){
					
				}
			}else{
				alert("Error loading page"+ xmlHttp.status +":"+xmlHttp.statusText);
			}
		}
	};
    xmlHttp.open('POST', url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", parameters.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(parameters);
    
}

function goToLoginPage(){
	window.location='../member/registration.jsp';
}

//JSON
function testJson(){
	alert(xmlHttp.responseText);
	myObject = JSON.parse(xmlHttp.responseText);
	alert(myObject.address);
}
//JSON

function closeSession(){
}
