/* CREATES HTTP OBJECT */
function getHTTPObject() { var xmlhttp; /*@cc_on @if (@_jscript_version >= 5) try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { xmlhttp = false; } } @else xmlhttp = false; @end @*/  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') { try { xmlhttp = new XMLHttpRequest(); } catch (e) { xmlhttp = false; } } return xmlhttp; } var http = getHTTPObject(); // We create the HTTP Object 

var undefMatch;
var prodListURL="http://www.cruiseplanet.com.au/ajax/level2_getDeals.php?"
var sideListURL="http://www.cruiseplanet.com.au/ajax/level2_getBest.php?"
var priceListURL="http://www.cruiseplanet.com.au/ajax/level3_getPrices.php?"

function readAJAX(theData,readURL,theResponse) {
	http.open("GET", readURL+theData, true);
	http.onreadystatechange = theResponse;
	http.send(null);
}
/***********************************************************************/

var theLoc;
var newDP;

function setDeparturePointCookie(theDP) {

	// get date data
	var today = new Date().getTime();
	var expiry = new Date(today+725760000);  // plus 12 weeks

	// reset cookie
	var cookieData = "departingFrom="+theDP+";";
	cookieData += "expires="+expiry.toGMTString()+";";
	cookieData += "path=/;";
	cookieData += "domain=.holidayplanet.com.au;";
	document.cookie = cookieData;
}

function immunise() {
	// setDeparturePointCookie("ALL");
}

function setDP(thisLoc) {
	theLoc = thisLoc;

	// get new departure point
	var theSelect = document.getElementById("departurePoints");
	newDP = theSelect.options[theSelect.selectedIndex].value;

	setDeparturePointCookie(newDP);
	
	document.getElementById("productList").innerHTML = "<h3>Please wait...</h3>";
	document.getElementById("rightSideSpecials").innerHTML = "<p>Please wait...</p>";

	// update first listing
	readAJAX("location="+theLoc+"&dp="+newDP,prodListURL,printListingData);
}
function printListingData() {
	if (http.readyState == 4) {
		results = http.responseText;
 		document.getElementById("productList").innerHTML = results;

		// update second listing
		readAJAX("location="+theLoc+"&dp="+newDP,sideListURL,printSideData);
	}
}
function printSideData() {
	if (http.readyState == 4) {
		results = http.responseText;
 		document.getElementById("rightSideSpecials").innerHTML = results;
	}
}

function setDPHotel(thisHotel,thisLoc,thisReg) {
	theID = thisHotel;

	// get new departure point
	var theSelect = document.getElementById("departurePoints");
	newDP = theSelect.options[theSelect.selectedIndex].value;

	setDeparturePointCookie(newDP);
	
	document.getElementById("priceList").innerHTML = "<h4>Please wait...</h4>";
	readAJAX("id="+theID+"&dp="+newDP+"&loc="+thisLoc+"&reg="+thisReg,priceListURL,printPriceData);
}
function printPriceData() {
	if (http.readyState == 4) {
		results = http.responseText;
 		document.getElementById("contentHolder").innerHTML = results;
	}
}
