var ajaxdestination="";
function buildPOST(theFormName) {
	var qs = '';    
	theForm = document.forms[theFormName];    
    for (e=0;e<theForm.elements.length;e++) {
        if (theForm.elements[e].name!='') {
            var name = theForm.elements[e].name;
            qs+=(qs=='')?'':'&';
            qs+= name+'='+escape(theForm.elements[e].value);
        }
    }
    qs+="\n";
    return qs;
} 

function pdata(theFormName,what,where,part) {
	try {
    if(navigator.appName == "Microsoft Internet Explorer") {
     xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():
  	 new ActiveXObject("Microsoft.XMLHTTP");} 
else { xmlhttp = new XMLHttpRequest();} 
  }
 catch (e) { return false; }
 
    ajaxdestination = where;
  	var xmlfata = buildPOST(theFormName);
    xmlhttp.open("POST",what,true); //calling testing.php using POST method
   xmlhttp.onreadystatechange  = function() {	
												   if (xmlhttp.readyState == 4)  
	        									   { 
	            									 if (xmlhttp.status == 200) 
	            										{ 
															 if(where=="livechat") {
														document.getElementById(ajaxdestination).innerHTML += xmlhttp.responseText;}
														else
															 document.getElementById(ajaxdestination).innerHTML = xmlhttp.responseText;	
	            										} 
	            										else 
	            										{ 
	                									alert("ERROR..");
	            										} 
	        										} 
   											}
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttp.send("p=" + part + "&" + xmlfata); //Posting txtname to PHP File
}

function getdata(what,where) { // get data from source (what)
 try {
    if(navigator.appName == "Microsoft Internet Explorer") {
     xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():
  	 new ActiveXObject("Microsoft.XMLHTTP");} 
else { xmlhttp = new XMLHttpRequest();} 
  }
 catch (e) { return false; }
if(where!="fmsg") document.getElementById(where).innerHTML ="<br><br><br><br><center><img src='images/loading.gif'></center>";
 ajaxdestination=where;
 xmlhttp.onreadystatechange = function () { // put data returned by requested URL to selected DIV
										  if (xmlhttp.readyState == 4) if (xmlhttp.status == 200);
								document.getElementById(ajaxdestination).innerHTML =xmlhttp.responseText;
											}
 
 
 xmlhttp.open("GET", what);
 xmlhttp.send(null);
  return false;
}



