var qstr="";

function xmlhttpPost(strURL,panelresult,pagename,dowork,pictureLocation) { 
    var xmlHttpReq = false; 
    var self = this; 
    // Mozilla/Safari 
    if (window.XMLHttpRequest) { 
        self.xmlHttpReq = new XMLHttpRequest(); 
    } 
    // IE 
    else if (window.ActiveXObject) { 
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); 
    } 
    self.xmlHttpReq.open('POST', strURL, true); 
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
    self.xmlHttpReq.onreadystatechange = function() { 
        if (self.xmlHttpReq.readyState == 4) { 
            updatepage(self.xmlHttpReq.responseText,panelresult,pictureLocation); 
        } 
    } 
    while(qstr.indexOf("+",0)>-1)
        qstr=qstr.replace("+","%2B");
    while(qstr.indexOf(" ",0)>-1)
        qstr=qstr.replace(" ","+");
    self.xmlHttpReq.send(getquerystring(panelresult,pagename,dowork,pictureLocation)); 
} 

function getquerystring(panelresult,pagename,dowork,pictureLocation) {
    if (pictureLocation !='[object]') pictureLocation = document.getElementById(pictureLocation);
	//pictureLocation.style.display = "block";
    pictureLocation.innerHTML = "<div style='text-align:center;padding-top: 100px;'><b><img src='images/Loading.gif' /> Loading...</b></div>";
    qstr = qstr.replace("doWork","null");
	qstr = qstr.replace("pagename","null");
	qstr = qstr + "&null=null&";
    qstr = qstr + "pagename="+ pagename +"&doWork="+ dowork;
	qstr = qstr.replace("&null=null&&null=null&","&null=null&");
    return qstr;
} 

function updatepage(str,panelresult,pictureLocation){
    if (panelresult!='[object]')   panelresult =  document.getElementById(panelresult);
    panelresult.innerHTML = str;
    //pictureLocation.style.display = "none";
} 

function myclear(){
    qstr="";
}

function addKey(name,value){
	if (name=="") return 0;
	qstr = qstr.replace(name +"=","null");
    qstr = qstr + "&null=null&";
    if (name=="body"){
	qstr = qstr + name + '=' + encoding(value);
    }else{
	    qstr = qstr + name + '=' + value;
    }
}
function addfield(formname,fieldname){
    if (fieldname=="") return 0;
    var temp,i;
    if (formname!='[object]')
		temp = eval("document." + formname + "." + fieldname).value;
	else
		temp = formname[fieldname].value;
    //temp = temp.replace(" ","+");
    qstr = qstr + "&null=null&";
    qstr = qstr + fieldname + '=' + temp;
}
function delKey(name){
	qstr = qstr.replace(name +"=","null");
	qstr = qstr + "&null=null&";
}
