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;charset=utf-8'); 
    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' /> "+ VAR_AjaxLoding +"</b></div>";
    qstr = qstr.replace("doWork","null");
	qstr = qstr.replace("pagename","null");
	qstr = qstr + "&null=null&";
    qstr = qstr + "pagename="+ pagename +"&doWork="+ dowork;
	while (qstr.indexOf("&null=null&&null=null&")>-1)
		qstr = qstr.replace("&null=null&&null=null&", "&null=null&");
	qstr = ajax_optimize(qstr);
    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;
	name = name.toLowerCase();
	delKey(name);
    if (name=="body"){
		qstr = qstr + name + '=' + encoding(value);
	}else if (name=="comment"){
		qstr = qstr + name + '=' + encoding(value);
    }else{
   		qstr = qstr + name.toLowerCase() + '=' + value;
    }
	qstr = qstr + '&null=null&';
}
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.toLowerCase() + '=' + temp;
}
function delKey(name){
	if(qstr=='')
		return;
	if(name=='')
		return;
	name=name.toLowerCase();
	var b=true;
	while(qstr.indexOf(name+'=')>-1 && b){
		if(qstr.indexOf(name+'=')>0){
			if('&'==qstr.slice(qstr.indexOf(name+'=')-1,qstr.indexOf(name+'='))){
				qstr = qstr.replace(name+'=','null=');
			}else{
				b=false;
			}
		}else{
			qstr = qstr.replace(name+'=','null=');	
		}
	}
}

function returnvalue(name){
	if (name=='') return;
	var temp = new Array();
	if (qstr=='') return;
	temp = qstr.split('&');
	var t = new Array();
	try{
		for(i=0; i<temp.length;i++){
			t=temp[i].split('=');
			if(t[0]==name)
				return t[1];
		}
	}catch(e){}
	return '';
}


function ajax_optimize(str){
	if(qstr=='') return;
	try{
		var arrQuery = str.split("&");
	}catch(e){return;}
	var arrResult = new Array;
	var result="";
	var state=true,t1,t2;
	try{
		for(var i=0, j=0, t; i<arrQuery.length;i++)
			if(arrQuery[i].indexOf('=')>-1)
				if(arrQuery[i].substr(arrQuery[i].indexOf('=')).length>1){
					t1 = arrQuery[i].substr(0,arrQuery[i].indexOf('='));
					for(t=0,state=true;t<arrResult.length-1;t++)
						if(t1.toLowerCase()==arrResult[t].substr(0,arrResult[t].indexOf('=')).toLowerCase()){
							state=false;
							t=arrResult.length+1;
						}
					if(state){
						arrResult[j] = arrQuery[i];
						j++;
					}
				}
		for(i=0;i<arrResult.length;i++)
			result+=arrResult[i]+'&';
		result = result.replace('undefinednull=null&null=null&','');
		result = result.replace('undefinednull=null&','');
		result = result.replace('undefined','');
	}catch(e){result=qstr;}
	return result;
}