
function getCardValue () {

	var gcNum = self.document.payForm.gc_number.value
	
	if (gcNum.length < 10) {
		top.alert("The gift card number supplied is invalid:\n"+ gcNum);

	} else {
		
		respObj.loadTxt = "looking up card value..";
		respObj.loadDiv = "gcValueText";
		respObj.processResponse = showCardValue;

		submitReq("?a=getValue&gc_number="+ gcNum);
	}

}

function showCardValue () {

	self.document.getElementById(respObj.loadDiv).innerHTML = respObj.lastResponse

}



// the response object that holds information about what to do with the info
// 
respObj = new responseObject();

// the object holding the xmlhttp connection
ajaxCon = false


// blank response object
function responseObject () {

	// text to show in loading screen
	this.loadTxt = false
	// text to show in loading screen
	this.loadDiv = false
	// the function to call after the processing is complete
	this.processResponse = false
	// secondary process that could be run
	this.nextProcess = false
	// the text of the last request
	this.lastResponse = false
	// the xml of the last request
	this.lastXML = false

}


// blank connection object
function ajaxConnection () {

	this.httpCon = getXmlHttpObj();
	this.httpCon.onreadystatechange = updateResponse

}


// request function that uses the two objects
function submitReq (url) {

	if (ajaxCon && ajaxCon.httpCon.readyState > 0 && ajaxCon.httpCon.readyState < 4) {
		ajaxCon.httpCon.abort();
	}
	
	ajaxCon = new ajaxConnection();
	
	if (ajaxCon.httpCon) {

	} else {
		alert ("Your broser may not support HTTP Request")
		return
	}
	

	if (respObj.loadDiv) {
		if (respObj.loadTxt) {
			self.document.getElementById(respObj.loadDiv).innerHTML = respObj.loadTxt
			respObj.loadTxt = false
		} else {
			self.document.getElementById(respObj.loadDiv).innerHTML = "loading..";
		}
	}
	
	respObj.lastResponse = false;
	respObj.lastXML = false;

	ajaxCon.httpCon.open("GET",url,true)
	ajaxCon.httpCon.send(null)

}

// update function that is run when connection is complete. 
// sets the respObj variables and submits to process response object
function updateResponse () {
	
	if (ajaxCon.httpCon.readyState==4 || ajaxCon.httpCon.readyState=="complete") { 
//		self.document.getElementById('playerBox').innerHTML = self.document.getElementById('playerBox').innerHTML +"complete";
		respObj.lastResponse = ajaxCon.httpCon.responseText
		respObj.lastXML      = ajaxCon.httpCon.responseXML
		respObj.processResponse()
	} else {
	//	top.alert(ajaxCon.httpCon.readyState);
	//	self.document.getElementById('playerBox').innerHTML = self.document.getElementById('playerBox').innerHTML +"complete";
	}

}

// function for the xmlhttp objects
function getXmlHttpObj() { 

	var objXMLHttp=null

	if (window.XMLHttpRequest) {
		objXMLHttp=new XMLHttpRequest()
	} else if (window.ActiveXObject) {
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}

	return objXMLHttp

}

