

//For Ajax Transaction
//The Next Three function must not be altered.
//Please follow/supply the parameters needed for the transaction.
//The forth function is where you set the values to be display in your alert box.
//rgb 10/2006
// JavaScript Document
var xmlHttp;
var sIODisplay = "";
var sObjName = "";
var sSetToObj = "";
var sFunction = "";
function sGetResult(sInputURL, sInputQueryString, sInputDisplay, sDisplayTo, sSetTo, sFunctionToCall){
	var sQueryString = (sInputQueryString != "") ? "?"+sInputQueryString:"";
	var sURL = "/Common/" + sInputURL + sQueryString;
	sFunction = sFunctionToCall;
	sIODisplay = sInputDisplay;
	sSetToObj = sSetTo;
	sObjName = sDisplayTo;
	xmlHttp = oGetXmlHttp(AssignResult);
	xmlHttp.open("GET", sURL, true);
	xmlHttp.send(null);
}

function AssignResult(){
	
	document.getElementById(sIODisplay).innerHTML = "";
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete"){
		//document.getElementById(sIODisplay).innerHTML = xmlHttp.responseText;
		var sResponse = xmlHttp.responseText;
		DisplayStatus(sResponse);
	}
}

function oGetXmlHttp(oHandler){
	var oXmlHttp = null;
	
	if (navigator.userAgent.indexOf("Opera") >= 0){
		alert("This application doesn't work in Opera!");
		return;
	}
	
	if (navigator.userAgent.indexOf("MSIE") >= 0){ 
		var sXMLName = "Msxml2.XMLHTTP";
		
		if (navigator.appVersion.indexOf("MSIE 5.5") >= 0){
			sXMLName = "Microsoft.XMLHTTP";
		}
		
		try{ 
			oXmlHttp = new ActiveXObject(sXMLName);
			oXmlHttp.onreadystatechange = oHandler;
			
			return oXmlHttp;
		}catch(e){ 
			alert("Error! Scripting for ActiveX might be disabled.");
			return;
		} 
	}
	
	if (navigator.userAgent.indexOf("Mozilla") >= 0){
		oXmlHttp = new XMLHttpRequest();
		oXmlHttp.onload = oHandler;
		oXmlHttp.onerror = oHandler;
		return oXmlHttp;
	}
}

//
//Add another case statement if you need another ajax transaction.
//
function DisplayStatus(sResponse)
{
	switch(sObjName)
	{
		case 'Transaction':
		
				document.getElementById(sIODisplay).innerHTML=sResponse
				var aNewResponse = document.getElementById(sIODisplay).innerHTML
				var aResponse = aNewResponse.split(",");
				var iTransactID = parseInt(aResponse[2]);
				var iLogID = parseInt(aResponse[3]);
				var iResultID = parseInt(aResponse[0]);
				
				//Populate the text field with the veri sign response...
				//alert(sSetToObj);
				document.forms[0].elements[sSetToObj].value = aNewResponse;
				
				var sImageApp = "<img src=\"/Common/images/app.gif\" width=\"32\" height=\"32\" alt=\"Approved\">";
				var sImageDec = "<img src=\"/Common/images/dec.gif\" width=\"32\" height=\"32\" alt=\"Declined\">";
				var sStartTable = "<table style=\"width:100%;\" border=\"0\" class=\"body\"><tr><td colspan=\"2\"><hr /></td></tr><tr>";
				var sEndTable = "</tr></table>";
				
				switch (iResultID){
					case 0:
						sSentence = "<td valign=\"top\">" + sImageApp + "</td>" +
									"<td>Your transaction has been " + aResponse[1] + ".<br />" +
									"Please wait for a while...</td>";

						break;
					case 125:
						sSentence = "<td valign=\"top\">" + sImageDec + "</td>" +
									"<td>We are unable to complete your purchase at this time.<br />" +
									"Transaction " + aResponse[1] +".<br />" +
									"PNREF: " + aResponse[5] + "<br />" +
									"To verify your Card Details, <a href=\"#\" onclick=\"toggle('loaderContainer', false)\">click here</a>.</td>";

						break;
					case 126:
					case 127:
						sSentence = "<td valign=\"top\">" + sImageApp + "</td>" +
									"<td>Thank you for your purchase, we are currently reviewing your order." +
									"Transaction Under Review: " + aResponse[1] + ".<br />" +
									"PNREF: " + aResponse[5] + "<br />" +
									"AUTHCODE: " + aResponse[4] + "</td>";

									
						break;
					default:
						sSentence = "<td valign=\"top\">" + sImageDec + "</td>" +
									"<td>Transaction: " + aResponse[0] + " - " + aResponse[1] + ".<br />" +
									"To verify your Card Details, <a href=\"#\" onclick=\"toggle('loaderContainer', false)\">click here</a>.</td>";

				}
				document.getElementById(sIODisplay).innerHTML = sStartTable + sSentence + sEndTable;
				if (iResultID == 0 || iResultID == 126 || iResultID == 127) 
				{
					if (sFunction != "")
					{
					setTimeout("sFunction()",3000);
					}
					
					setTimeout("toggle("+"'"+"loaderContainer"+"'"+", false)",3000);
				}
			break;
		default:
	}
}
