// JavaScript Document
//-------------Ajax-----------------------------------------------
var gXmlHttpReq;
var objname = "";
var objname1 = "";
var objname2 = "";
var objname3 = "";
function newXMLHttpRequest() 
{  
	var xmlreq = false;  
	if (window.XMLHttpRequest){	// firefox  
		xmlreq = new XMLHttpRequest(); 
	}else if (window.ActiveXObject) {    
		xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
		if(!xmlreq)
			xmlreq = new ActiveXObject("Microsoft.XMLHTTP");//IE    
	} 
	return xmlreq;  
}  
function setInnerHTML(name, InText)
{
	var obj = document.getElementById(name);
	if(obj)
	 	obj.innerHTML = InText;
}

//-----------------------1-------------------------------- 
function processReqChange() 
{ 
	if (gXmlHttpReq.readyState == 4) {//OK  
		if (gXmlHttpReq.status == 200) {  
			setContentsToPage(); 
		}  
		else { 	alert("There was a problem retrieving the XML data:\n" + gXmlHttpReq.statusText);  
		}  
	}  
}  
//strparam = "x=2&y=3&z=4...."
function sendPost(url, strparam) 
{ 
	var paramObj =  document.getElementById("ajaxParam");
	if(paramObj)
		paramObj.value = strparam;
	gXmlHttpReq = newXMLHttpRequest(); 
	gXmlHttpReq.onreadystatechange = processReqChange; 
	gXmlHttpReq.open("POST", url, true); 
	gXmlHttpReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	gXmlHttpReq.send(strparam); 
} 
function setContentsToPage() 
{ 
	var orderHistoryText =gXmlHttpReq.responseText;
	var newStr=orderHistoryText.replace(/\r\n/g,"");
	var matches1 = newStr.match(/<part1>(.*?)<\/part1>/);
	var matches2 = newStr.match(/<part2>(.*?)<\/part2>/);
	var matches3 = newStr.match(/<part3>(.*?)<\/part3>/);
	//TODO -------------------------
	if(matches1 != null)
		setInnerHTML(objname1, matches1[1]);
	if(matches2 != null)
		setInnerHTML(objname2, matches2[1]);
	if(matches3 != null)
		setInnerHTML(objname3, matches3[1]);
} 
function setObject(name1,name2,name3) 
{ 
	objname1 = name1;
	objname2 = name2;
	objname3 = name3;
} 
//-------------------------2------------------------------------------
function processReqChangeOne() 
{ 
	if (gXmlHttpReq.readyState == 4) {//OK  
		if (gXmlHttpReq.status == 200) {  
			setContentsToPageOne(); 
		}  
		else { 	alert("There was a problem retrieving the XML data:\n" + gXmlHttpReq.statusText);  
		}  
	}  
}  

function sendPostOne(url, strparam) 
{ 
	gXmlHttpReq = newXMLHttpRequest(); 
	gXmlHttpReq.onreadystatechange = processReqChangeOne;  
	gXmlHttpReq.open("POST", url, true); 
	gXmlHttpReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	gXmlHttpReq.send(strparam); 
} 
function setContentsToPageOne() 
{ 
	var orderHistoryText =gXmlHttpReq.responseText;
	//TODO -------------------------
	setInnerHTML(objname, orderHistoryText);
} 
function setObjectOne(name) 
{ 
	objname = name;
} 
