// Javascript functions for Option Bar

// Ajax script to establish connection with server ------------------------------------------------------------------------->

<!--
function ajaxObject(url) {           // This is the object constructor   
	var that=this;                        // A workaround for some javascript idiosyncrocies   
	this.updating = false;                // Set to true if this object is already working on a request  
	this.callback = function () {}        // A post-processing call -- a stub you overwrite.   
	this.update = function(passData) {    // Initiates the server call.      
		if (that.updating==true) { return false; }    // Abort if we're already processing a call.      
	that.updating=true;              // Set the updating flag.      
	var AJAX = null;                  // Initialize the AJAX variable.      
	if (window.XMLHttpRequest) {      // Are we working with mozilla?         
		AJAX=new XMLHttpRequest();        //  Yes -- this is mozilla.      
	} else {                          // Not Mozilla, must be IE         
		AJAX=new ActiveXObject("Microsoft.XMLHTTP");                //  Wheee, ActiveX, how do we format c: again?     
	}                                                              // End setup Ajax.      
	if (AJAX==null) {                                              // If we couldn't initialize Ajax...         
	return false;                                                // Return false (WARNING - SAME AS ALREADY PROCESSING!)      
	} else {         
	AJAX.onreadystatechange = function() {                      // When the browser has the request info..            
		if (AJAX.readyState==4) {                                //   see if the complete flag is set.               
		that.updating=false;                                  //   Set the updating flag to false so we can do a new request
		that.callback(AJAX.responseText,AJAX.status);         //   Pass respons and status to callback.               
		delete AJAX;                                          //   delete the AJAX object since it's done.           
		}                                                        // End Ajax readystate check.         
	}                                                           // End create post-process fucntion block.         
	var timestamp = new Date();                                 // Get a new date (this will make the url unique)         
	var uri=urlCall+'?'+passData+'&timestamp='+(timestamp*1);   // Append date to url (so the browser doesn't cache the call)  
    AJAX.open("GET", uri, true);                                // Open the url this object was set-up with.         
	AJAX.send(null);                                            // Send the request.         
	return true;                                                // Everything went a-ok.      
	}                                                           // End Ajax setup aok if/else block                   
	}         														// This area set up on constructor calls.   
var urlCall = url;                                                // Remember the url associated with this object.
}  																// End AjaxObject

// End of Ajax Object Build Script
// ------------------------------------------------------------------------------------------------------------------------------->


// Ajax object to show number of cruises a search will produce ------------------------------------------------------------------->

var productPrice = new ajaxObject("http://www.testedonanimals.biz/includes/ajax/getPrice.php"); 	   // Create object
productPrice.callback = function (responseText, responseStatus) {       // What to do with the data   
displayProductPrice(responseText, responseStatus);                            // Your function here
} 	

function displayProductPrice(responseText, responseStatus) {   
	if (responseStatus==200) { 
		var results = new Array(); // Get the response text - there is more than 1 item this time so we need to put into an array
		results = responseText.split("abc");
		var formName = "addToCart_" + results[2];
		document.getElementById(results[2] + "price").innerHTML=results[0];
		document.forms[formName].productPrice.value=results[3];
		//document.getElementById("productPrice").value=results[0];
		if(results[1] != "no") {
		document.getElementById(results[2] + "price").innerHTML=results[1];
		document.forms[formName].productPrice.value=results[4];
		}
	} else {      
		alert("Failed to update this items price.<br />Please contact TOA to purchase this product"); 
	}
}	// End in-line function

function getProductPrice(thisProd) {
var formName = "addToCart_" + thisProd;
var productSize = document.forms[formName].sizeOption.value;
var productId = document.forms[formName].productId.value;

productPrice.update("productSize="+productSize+"&productId="+productId+"&formName="+productId); 
}

