var cMonth1 = -1;
var cMonth2 = -1;

function bookmarkPage(title, url){
	var agt = navigator.userAgent.toLowerCase();
	var app = navigator.appName.toLowerCase();
	var ieAgent = agt.indexOf('msie');
	var nsAgent = app.indexOf('netscape');
	var opAgent = agt.indexOf('opera');
	
	if (opAgent != -1)
		alert("To Bookmark this page in Opera, Please press [CTRL-T]");
	else if (nsAgent != -1)
		alert("To Bookmark this page in Netscape or Firefox, Please press [CTRL-D]");
	else if (ieAgent != -1) 
		window.external.AddFavorite(url, title);
	
}

function popDays(cObj, cVal){
	
	var dayChooser = document.getElementById(cObj);
	var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null;
	var Days = new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
	var selDate = cVal.split("/");
	var tyear = selDate[1];
	var tmonth = selDate[0];

	var getNoDays = 32 - new Date(tyear, (tmonth - 1), 32).getDate();
	
    while (dayChooser.options.length) { dayChooser.remove(0); }

	var myDate=new Date();
	for (x = 1; x <= getNoDays; x++) {
		myDate.setFullYear(tyear,(tmonth - 1),x);	
		newElem = document.createElement("option");
		newElem.text = Days[myDate.getDay()] + ' ' + x;
		newElem.value = x;
		dayChooser.add(newElem, where);
	}
}

function createMonthDays() {
	/*
	alert(document.getElementById("cCheckIn").value);
	alert(document.getElementById("cCheckOut").value);
*/
	var selIdxA = document.getElementById("departMonth1");
	var selIdxB = document.getElementById("departMonth2");

	if (cMonth1 != selIdxA.selectedIndex) { popDays("departDay1", selIdxA.options[selIdxA.selectedIndex].value); cMonth1 = selIdxA.selectedIndex; }
	if (cMonth2 != selIdxB.selectedIndex) { popDays("departDay2", selIdxB.options[selIdxB.selectedIndex].value); cMonth2 = selIdxB.selectedIndex; }
		
}

// ====== This function displays the tooltip ======
// it can be called from an icon mousover
function showTooltip(marker, map, tooltip, align) {
	//alert(point);
	tooltip.innerHTML = marker.tooltip;
	var point=map.getCurrentMapType().getProjection().fromLatLngToPixel(map.fromDivPixelToLatLng(new GLatLng(0,0),true),map.getZoom());
	var offset=map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),map.getZoom());
	var anchor=marker.getIcon().iconAnchor;
	var width=marker.getIcon().iconSize.width;
	var cwidth=tooltip.clientWidth;
	var height=tooltip.clientHeight;
	//map.panTo(marker.getPoint());
	/* left - center - right, 0 - 2 repsectively */
	if (align == 0) {
		var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(offset.x - point.x - anchor.x + width, offset.y - point.y -anchor.y -height)); 
	} else if (align == 1) {
		var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(offset.x - point.x - anchor.x - (cwidth / 2) + (width / 2), offset.y - point.y -anchor.y -height - 10)); 
	}
	pos.apply(tooltip);
	tooltip.style.visibility="visible";

}

function showMenuPanel(myID, myArray){
	var x;
	for (x = 0; x < myArray.length; x++){
		if (myArray[x] == myID){
			document.getElementById("myMenu" + myArray[x]).style.display = "inline";
		} else {
			document.getElementById("myMenu" + myArray[x]).style.display = "none";
		}
	}
}

function showPanel(myID){ document.getElementById(myID).style.display = "inline"; }
function hidePanel(myID){ document.getElementById(myID).style.display = "none";}

function setValue(type, selectName, value)
{
	var x = eval(document.getElementById(selectName));
	// 1:select 2:text
	if (type == 1){
	for (index = 0; index < x.options.length; index++){
		if  (x.options[index].value == value)
			x.options.selectedIndex = index;
	}
	}else if (type == 2){
		x.value = value;
	}else if (type == 3){
		for (index = 0; index < x.options.length; index++)
		if  (x.options[index].value == value)
			x.options[index].selected = true;
	}else if (type == 4){
		x.innerHTML = value;		
	}
}


/*
function showPanelMe(myName, myID, maxID){

	for (x = 0; x < maxID; x++){
		if (x == myID){
		document.getElementById("cPanel" + x).style.display = "block";
		} else {	
		document.getElementById("cPanel" + x).style.display = "none";
		}
	}
}
*/

function showSearch() {
	if (document.getElementById('loc-main-search-body-c').style.display == 'none') {
		Effect.toggle('search-more', 'slide', { duration:0.4 } )
	} else {
		Effect.toggle('search-more', 'slide', { duration:0.4 } )
	}
}

function showSearchB(tItem) {
	//alert(tItem.selectedIndex);
	if (tItem.selectedIndex > 0) { 
		if (document.getElementById("search-more").style.display == 'none') {
			Effect.toggle('search-more', 'slide', { duration:0.4 } )
		}
	} else if (tItem.selectedIndex == 0) {
		Effect.toggle('search-more', 'slide', { duration:0.4 } )
	}
}

function loadInto(myView, myUrl){
	alert(myView + "-" + myUrl);
	var x = eval(document.getElementById("_if" + myView));
	x.src = myUrl;
}

function launchCenter(url, name, height, width, scrolling, resize) {
	var popupNow = null;
	var winObject = popupNow;
	var str = "height=" + height + ",innerHeight=" + height;
	str += ",width=" + width + ",innerWidth=" + width + ",scrollbars=" + scrolling + ",resizable=" + resize;
	if (window.screen) {
		var ah = screen.availHeight - 30;
		var aw = screen.availWidth - 10;
		
		var xc = (aw - width) / 2;
		var yc = (ah - height) / 2;
		
		str += ",left=" + xc + ",screenX=" + xc;
		str += ",top=" + yc + ",screenY=" + yc;
	}

	if (winObject == null || winObject.closed)
		winObject = window.open(url, name, str);
	else {
		winObject.location = url;
	}
	winObject.focus();
}

function showMe(me){
	document.getElementById(me).style.visibility = "visible";
}

function hideMe(me){
	document.getElementById(me).style.visibility = "hidden";
}


function validateQuote(tform){
/*
	if (tform.cLocationID.selectedIndex == 0) {
		alert('Please select a Region to Search.');
		tform.cLocationID.focus();
		return(false);
	}*/
	if ((tform.cCheckIn.value.length < 1) || (tform.cCheckOut.value.length < 1)) {
		alert('Please enter a suitable Check In and Check Out Date.\r\n- You have not selected either a Check In or Check Out date.'); 
		return(false);
	}
	if (tform.cCheckIn.value == tform.cCheckOut.value) {
		alert('Please enter a suitable Check In and Check Out Date.\r\n- You can not Check In and Check Out on the same date.'); 
		return(false);
	}
/*
	if (DateDiff(tform.cCheckIn.value, tform.cCheckOut.value) <= 1) {
		alert('Please enter a suitable Check In and Check Out Date.\r\n- You have selected a (1) One Night Stay.\r\n- Unfortunately, we are unable to book One Night Stays.'); 
		return(false);
	}
*/
	if ((tform.cAdults.value == 0) && (tform.cChildren.value == 0)) {
		alert('Please select the correct number of occupants.\r\n- You have not selected a specific number of Adults or Children.'); 
		return(false);
	}
}

function showPNPanel(dr) {

	if (dr == 0) { uVal = -1; wVal = -1; } else if (dr == 1) { uVal = 1; wVal = pItemAll; }
	if ((currentPanelVal + uVal) == wVal) {
		// do nothing
		pItem = currentPanelVal;
	} else {
		pItem = currentPanelVal + uVal;
		showHideSearchPanel(pItem);
	}
	document.getElementById("pg_ident").innerHTML = "Page " + (parseInt(pItem) + 1) + " of " + pItemAll;
}

function showHideSearchPanel(pItem) {

	currentPanelVal = pItem;
	var anchors = document.getElementsByTagName("div");

	for (var i=0; i < anchors.length; i++){
		var anchor = anchors[i];
		if (anchor.getAttribute("rel") == "pg_item"){
							//alert(anchor.getAttribute("id") + ' -- ' + pItem);
			if (anchor.getAttribute("id") == "pg_item" + pItem) {
				anchor.style.display = "block";
				document.getElementById("selbtn" + pItem).style.color = '#CC3333';
			} else {
				anchor.style.display = "none";
				document.getElementById("selbtn" + anchor.getAttribute("id").replace(/pg_item/,'')).style.color = '#000000';
			}
//			anchor.onmouseover = function () { this.style.backgroundColor = '#FFFDF2'; return false;}
//			anchor.onmouseout = function () { this.style.backgroundColor = ''; return false;}
		}
	}
	document.getElementById("pg_ident").innerHTML = "Page " + (parseInt(pItem) + 1) + " of " + pItemAll;
	parent.resizeIframeA("searchFrame");
}

function showHideMe(z)
{
	if ((document.getElementById(z).style.display=='inline') || (document.getElementById(z).style.display=='block')) {
		document.getElementById(z).style.display = 'none';
	}
	else {
		document.getElementById(z).style.display = 'inline';
	}
}

function initTICK()
{
	if (!document.getElementsByTagName){ return; }
	
	var anchors = document.getElementsByTagName("div");
	// loop through all anchor tags
	for (var i=0; i < anchors.length; i++){
		var anchor = anchors[i];
		if (anchor.getAttribute("rel") == "content-item"){
			anchor.onmouseover = function () { this.style.backgroundColor = '#E3EBF0'; return false;}
			anchor.onmouseout = function () { this.style.backgroundColor = ''; return false;}
		}
		if (anchor.getAttribute("rel") == "mini-accomm-item"){
			anchor.onmouseover = function () { this.style.backgroundColor = '#FFFDF2'; return false;}
			anchor.onmouseout = function () { this.style.backgroundColor = ''; return false;}
		}
		if (anchor.getAttribute("rel") == "btnTile") {
			anchor.onmouseover = function () { 	this.className = 'btnTile btnSearchHover'; return false; }
			anchor.onmouseout = function () { this.className = 'btnTile btnSearchOut'; return false;}
			anchor.onclick = function () { showHideSearchPanel(this.getAttribute('alt')); parent.document.location.href = "accommodation-search.html#topsearch"; }
		}
	}
	
	/* tr anchors for bedroom */
	var anchors = document.getElementsByTagName("tr");
	
	for (var i=0; i < anchors.length; i++){
		var anchor = anchors[i];
		if (anchor.getAttribute("rel") == "accomm-select"){
	//		anchor.onmouseover =  function () { this.style.backgroundColor='#F7F7F7'; return false;}
	//		anchor.onmouseout = function () { this.style.backgroundColor='#FFFFFF'; return false;}
		}
	}
	
	/* tr anchors for bedroom */
	var anchors = document.getElementsByTagName("a");
	
	for (var i=0; i < anchors.length; i++){
		var anchor = anchors[i];
		if (anchor.getAttribute("rel") == "maplaunch"){
			anchor.onclick = function () { launchCenter(this.getAttribute('href'), 'accmap', 510, 510, 0, 1); return false; }
		}
		if (anchor.getAttribute("rel") == "photolaunch"){
			anchor.onclick = function () { launchCenter(this.getAttribute('href'), 'photowin', 500, 430, 0, 1); return false; }
		}
		if (anchor.getAttribute("rel") == "regionmaplaunch"){
			anchor.onclick = function () { launchCenter(this.getAttribute('href'), 'regionmap', 480, 650, 0, 1); return false; }
		}
		if (anchor.getAttribute("rel") == "loadgmap"){
			anchor.onclick = function () { setXYM(this.getAttribute('xlng'), this.getAttribute('xlat')); getProperty(this.getAttribute('xid'), this.getAttribute('xname')); return false; }
		}

}
	
	/*
	var anchors = document.getElementsByTagName("img");
	// loop through all anchor tags
	for (var i=0; i < anchors.length; i++){
		var anchor = anchors[i];
		if (anchor.getAttribute("rel") == "mini-pics"){
			anchor.style.visibility = "hidden";
			anchor.style.width = "70px";
			anchor.style.height = "70px";
			anchor.style.visibility = "visible";
		}
	}
	*/
}

//
// addLoadEvent()
// Adds event to window.onload without overwriting currently assigned onload functions.
// Function found at Simon Willison's weblog - http://simon.incutio.com/
//
function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}

function GetXmlHttpObject(handler)
{ 
	var xmlhttp=false;

	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		xmlhttp.onreadystatechange = handler;
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			xmlhttp.onreadystatechange = handler;
		} catch (E) {
			xmlhttp = false;
		}
	}
	@end @*/
		
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		xmlhttp = new XMLHttpRequest();
		xmlhttp.onload = handler;
		xmlhttp.onerror = handler;
	}
	
	return xmlhttp;
} 

/* YAHOO calendar */

var oDay;
var oMonth;
var oYear;
var rDay;
var rMonth;
var rYear;
var thDay;
var thMonth;
var thYear;

function validateSearch(){
	var F=document.frmQuote;

	cD();
	if(V()){
		var month1=F.departMonth1.value;
		var month1a = month1.split('/');
		F.cCheckIn.value =  F.departDay1.value + '/' + month1a[2] + '/' + month1a[1];
		
		var month2=F.departMonth2.value;
		var month2a = month2.split('/');
		F.cCheckOut.value = F.departDay2.value + '/' + month2a[2] + '/' + month2a[1];
		setValue(2, "cRegionName", document.frmQuote.cLocationID.options[document.frmQuote.cLocationID.selectedIndex].innerHTML, 0);
		
		if ((F.cCheckIn.value == '6/JUN/2009') || (F.cCheckIn.value == '7/JUN/2009')) {
			alert('Unfortunately, we are unable to provide a quote for this Check-In date.');
			return(false);
		}
		if (F.cLocationID.selectedIndex == 0) {
			alert('Please select a Region to Search.');
			F.cLocationID.focus();
			return(false);
		}
		if (F.cCheckIn.value == F.cCurrentDay.value) {
			alert('To continue with your Accommodation Search:\n\nWe\'re Sorry, You cannot book on the same day as your Check In date.'); 
			return(false);
		}
		if (F.cAdults.value == 0) {
			alert('To continue with your Accommodation Search:\n\nPlease select the correct number of occupants.\r\n- You have not selected a specific number of Adults.'); 
			return(false);
		}
		if (F.cMinMaxPrice.selectedIndex == 0) {
			alert("To continue with your Accommodation Search:\n\n- Please make a \"Price Per Night\" selection.");
			return(false);
		}

		var jAges = '';
		var jSave = F.cCheckIn.value + '|' + F.cCheckOut.value + '|' + F.cAdults.value + '|' + F.cChildren.value + '|' + F.cInfants.value;
		var bError = false;
		
		var msgChildren = document.getElementById("msgChildren");
		var jAgesCount = document.frmQuote.cChildAgeCount.value;
		if (jAgesCount > 0) {
			for (x = 0; x < jAgesCount; x++) {
				var xAge = document.getElementById("cChildAge" + x);
				var xAgeIdx = xAge.selectedIndex;
				if (xAgeIdx == 0) { msgChildren.innerHTML = " * Please enter Children Ages before proceeding"; bError = true; xAge.focus(); break; } else { msgChildren.innerHTML = ""; }
				jAges = jAges + xAge[xAgeIdx].value;
				if (x<(jAgesCount-1)) { jAges = jAges + "|"; }
			}
		}
		setSC(jSave, jAges);

		if (bError == false) { 
			F.submit();	
		} else {
			return(false);
		}

	} else {
		return(false);
	}
}

function validateSearch2(){
	var F=document.frmQuote;
	
	cD();
	if(V()){
		var month1=F.departMonth1.value;
		var month1a = month1.split('/');
		F.cCheckIn.value =  F.departDay1.value + '/' + month1a[2] + '/' + month1a[1];
		
		var month2=F.departMonth2.value;
		var month2a = month2.split('/');
		F.cCheckOut.value = F.departDay2.value + '/' + month2a[2] + '/' + month2a[1];
		
		if ((F.cCheckIn.value == '6/JUN/2009') || (F.cCheckIn.value == '7/JUN/2009')) {
			alert('Unfortunately, we are unable to provide a quote for this Check-In date.');
			return(false);
		}
		if (F.cLocationID.selectedIndex == 0) {
			alert('Please select a Region to Search.');
			F.cLocationID.focus();
			return(false);
		}
		if (F.cCheckIn.value == F.cCurrentDay.value) {
			alert('To continue with your Accommodation Search:\n\nWe\'re Sorry, You cannot book on the same day as your Check In date.'); 
			return(false);
		}
		if (F.cAdults.value == 0) {
			alert('To continue with your Accommodation Search:\n\nPlease select the correct number of occupants.\r\n- You have not selected a specific number of Adults.'); 
			return false;
		}
		if (F.cMinMaxPrice.selectedIndex == 0) {
			alert("To continue with your Accommodation Search:\n\n- Please make a \"Price Per Night\" selection.");
			return false;
		}
		return true;
	} else {
		return false;
	}
}


function validateSearch3(){
	var F=document.frmQuote;
	
	cD();
	if(V()){
		var month1=F.departMonth1.value;
		var month1a = month1.split('/');
		F.cCheckIn.value =  F.departDay1.value + '/' + month1a[2] + '/' + month1a[1]; 
		
		var month2=F.departMonth2.value;
		var month2a = month2.split('/');
		F.cCheckOut.value = F.departDay2.value + '/' + month2a[2] + '/' + month2a[1]; 
		
		cM();
		if ((F.cCheckIn.value == '6/JUN/2009') || (F.cCheckIn.value == '7/JUN/2009')) {
			alert('Unfortunately, we are unable to provide a quote for this Check-In date.');
			return(false);
		}
		if (F.cCheckIn.value == F.cCurrentDay.value) {
			alert('To continue with your Accommodation Search:\n\nWe\'re Sorry, You cannot book on the same day as your Check In date.'); 
			return(false);
		}
		if (F.cAdults.value == 0) {
			alert('To continue with your Accommodation Search:\n\nPlease select the correct number of occupants.\r\n- You have not selected a specific number of Adults.'); 
			return false;
		}
		return true;
	} else {
		return false;
	}
}

function validateSearch4(){
	var F=document.frmQuote;
	
	cD();
	if(V()){
		var month1=F.departMonth1.value;
		var month1a = month1.split('/');
		F.cCheckIn.value =  F.departDay1.value + '/' + month1a[2] + '/' + month1a[1]; 
		
		var month2=F.departMonth2.value;
		var month2a = month2.split('/');
		F.cCheckOut.value = F.departDay2.value + '/' + month2a[2] + '/' + month2a[1]; 
		
		cM();
		if ((F.cCheckIn.value == '6/JUN/2009') || (F.cCheckIn.value == '7/JUN/2009')) {
			alert('Unfortunately, we are unable to provide a quote for this Check-In date.');
			return(false);
		}
		if (F.cCheckIn.value == F.cCurrentDay.value) {
			alert('To continue with your Accommodation Search:\n\nWe\'re Sorry, You cannot book on the same day as your Check In date.'); 
			return(false);
		}
		return true;
	} else {
		return false;
	}
}

function cD(){
	var F=document.frmQuote;
	var oArray=F.departMonth1.options[F.departMonth1.selectedIndex].value.split('/');
	var rArray=F.departMonth2.options[F.departMonth2.selectedIndex].value.split('/');	
	var tArray=todayMonth.split('/');	

	/*
	alert(F.departMonth1.options[F.departMonth1.selectedIndex].value);
	alert(F.departMonth2.options[F.departMonth2.selectedIndex].value);
*/
	
	oDay=parseInt(F.departDay1.options[F.departDay1.selectedIndex].value);
	oMonth=parseInt(oArray[0]);
	oYear=parseInt(oArray[1]);
	
	rDay=parseInt(F.departDay2.options[F.departDay2.selectedIndex].value);
	rMonth=parseInt(rArray[0]);
	rYear=parseInt(rArray[1]);
	
	thDay=parseInt(todayDay);
	thMonth=parseInt(tArray[0]);
	thYear=parseInt(tArray[1]);
	
//	alert(thDay + '-' + thMonth + '-' + thYear);
}

function cM(){
	createMonthDays();
}

function rD(){

    var F=document.frmQuote;
    cD();
    if(rDay!=0){
//		alert(oDay);
		
//		alert(rMonth+"<"+oMonth+" - "+rYear+"=="+oYear+" - "+oYear+">"+rYear);
//		alert(rDay+"<"+oDay+" - "+rMonth+"=="+oMonth);
        if((rMonth<oMonth)&&(rYear==oYear)||(oYear>rYear)){
            F.departMonth2.options.selectedIndex=F.departMonth1.options.selectedIndex; cM();
			F.departDay2.options.selectedIndex=F.departDay1.options.selectedIndex+1;
		} else if(((F.departDay1.length - 1)==F.departDay1.selectedIndex)&&(rMonth==oMonth)&&(oYear==rYear)) {
			F.departMonth2.options.selectedIndex=F.departMonth1.options.selectedIndex+1; cM();
            F.departDay2.options.selectedIndex=0;
		} else if((oDay==31)&&(rMonth==oMonth)&&(oYear==rYear)) {
			F.departMonth2.options.selectedIndex=F.departMonth1.options.selectedIndex+1; cM();
            F.departDay2.options.selectedIndex=0;
        } else if((rDay<oDay)&&(rMonth==oMonth)){
            F.departDay2.options.selectedIndex=F.departDay1.options.selectedIndex+1;
		} else if((rDay==oDay)&&(rMonth==oMonth)&&(oYear==rYear)) {
            F.departDay2.options.selectedIndex=F.departDay1.options.selectedIndex+1;
        }
				
    }
}

function rD2(){
    var F=document.frmQuote;
    cD();
	
//	alert(rMonth + '/' + oMonth + '-' + rYear + '/' + oYear);
	if((rMonth<oMonth)&&(rYear==oYear)||(oYear>rYear)){
		F.departMonth2.options.selectedIndex=F.departMonth1.options.selectedIndex; cM();
		F.departDay2.options.selectedIndex=F.departDay1.options.selectedIndex+1;
	}
	else if((rDay<oDay)&&(rMonth==oMonth)){
		F.departDay2.options.selectedIndex=F.departDay1.options.selectedIndex+1;
	}
}

function V(){
    var F=document.frmQuote;
	var trMonth = '';
	var toMonth = '';
	var trDay = '';
	var toDay = '';
	var zhDay = '';
	
//	alert(oMonth + '-' + rMonth);
	if (oMonth < 10) { toMonth = '0' + oMonth; } else { toMonth = oMonth; }
	if (rMonth < 10) { trMonth = '0' + rMonth; } else { trMonth = rMonth; }
	if (thMonth < 10) { zhMonth = '0' + thMonth; } else { zhMonth = thMonth; }
	
	if (oDay < 10) { toDay = '0' + oDay; } else { toDay = oDay; }
	if (rDay < 10) { trDay = '0' + rDay; } else { trDay = rDay; }
	if (thDay < 10) { zhDay = '0' + thDay; } else { zhDay = thDay; }
	
    var oMY=''+oYear+toMonth;
    var rMY=''+rYear+trMonth;

	var oAL = oYear+''+toMonth+''+toDay;
	var rAL = rYear+''+trMonth+''+trDay;
	var tAL = thYear+''+zhMonth+''+zhDay;
	
/*
	alert(oAL+'\n'+rAL+'\n'+tAL);
	
	alert(oMY + '-' + rMY);	
	alert(oDay + '-' + oMonth + '-' + oYear);
	alert(rDay + '-' + rMonth + '-' + rYear);

	alert(oDay+'<'+thDay +'&&'+ oMonth+'<='+thMonth+'&&'+oYear+'<='+thYear);
	alert(((oDay < thDay) && (oMonth <= thMonth) && (oYear <= thYear)));
	*/
	
    if ((oAL < tAL) || (rAL < tAL)) {
		alert("The dates you have chosen are invalid:\n\n- You must choose dates that are greater than the current date.");
        return false;
	} else if (
	((oMonth==2)&&(oDay>29)&&((oYear==2000)||(oYear==2004)||(oYear==2008)))|| 	
	/* if leap year - feb > 29 */
	((oMonth==2)&&(oDay>28)&&(oYear!=2000)&&(oYear!=2004)&&(oYear!=2008))||
	/* if leap year - feb > 28 if not leap year */
	((oMonth==4)&&(oDay>30))||
	/* april && day > 30 */
	((oMonth==6)&&(oDay>30))||
	/* june && day > 30 */
	((oMonth==9)&&(oDay>30))||
	/* sep && day > 30 */
	((oMonth==11)&&(oDay>30))||
	/* nov && day > 30 */
	((rMonth==2)&&(rDay>29)&&((rYear==2000)||(rYear==2004)||(rYear==2008)))||
	/* if leap year - feb > 29 */	
	((rMonth==2)&&(rDay>28)&&(rYear!=2000)&&(rYear!=2004)&&(rYear!=2008))||
	/* if NOT leap year - feb > 28 */
	((rMonth==4)&&(rDay>30))||
	/* april && day > 30 */
	((rMonth==6)&&(rDay>30))||
	/* june && day > 30 */
	((rMonth==9)&&(rDay>30))||
	/* sep && day > 30 */
	((rMonth==11)&&(rDay>30))||
	/* nov && day > 30 */
/*	((oDay<24)&&(oMY<=200708))||*/
	((((rDay<oDay)&&(rMY<=oMY))||(rMY<oMY))&&( (rDay!=0)&&(rMonth!=0)))||
	(((rMonth!=0)&&(rDay==0))||((rMonth==0)&&(rDay!=0))) 
	) {
        alert("The dates you have chosen are invalid.\nPlease choose a different check in and/or check out date.");
        return false;
    }

    return true;
}

function loadMSP(did, rd){
	window.open('https://admin.worldtourism.com.au/seologin/?action=edit&did=' + did + '&rd=' + rd, '_winSO', 'resizable=yes,scrollbars=yes,toolbar=yes');
}

function loadMLI(rd, dn){
	window.open('https://admin.worldtourism.com.au/seologin/unlock.asp?rd=' + rd + '&domain=' + dn, '_winSO', 'resizable=yes,scrollbars=yes,toolbar=yes');
}

function loadSurvey() {
	window.open('/survey.html','','scrollbars=yes,menubar=yes,resizable=yes,toolbar=yes,location=yes,status=yes');
}

var monthArr = "000000JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC";

function setSC(setSave, setAge) {
	writeSessionCookie("srchon", "1");
	writeSessionCookie("srch", setSave + "~" + setAge);
//	alert(setSave + '~' + setAge);
}

function procSC() {

	var getCookie = getCookieValue("srch");
	var arrCookie = getCookie.split("~");
	var stage1 = arrCookie[0].split("|");
	var date1 = stage1[0].split("/");
	var date2 = stage1[1].split("/");

	var monthInt1  = ((monthArr.indexOf(date1[1]) / 3) -1);
	var monthInt2 = ((monthArr.indexOf(date2[1]) / 3) -1);

	cSetChildren = arrCookie[1];
	setValue(1, "departDay1", parseFloat(date1[0]), 0);
	setValue(1, "departMonth1", monthInt1 + "/" + date1[2] + "/" + date1[1], 0);
	setValue(1, "departDay2", parseFloat(date2[0]), 0);
	setValue(1, "departMonth2", monthInt2 + "/" + date2[2] + "/" + date2[1], 0);
	setValue(2, "cCheckIn", stage1[0], 0);
	setValue(2, "cCheckOut", stage1[1], 0);
	setValue(1, "cAdults", stage1[2], 0);
	setValue(1, "cChildren", stage1[3], 0);
	setValue(1, "cInfants", stage1[4], 0);
	buildChildrenAges();

}

function writeSessionCookie (cookieName, cookieValue) {
  if (testSessionCookie()) {
    document.cookie = escape(cookieName) + "=" + escape(cookieValue) + "; path=/";
    return true;
  }
  else return false;
}

function getCookieValue (cookieName) {
  var exp = new RegExp (escape(cookieName) + "=([^;]+)");
  if (exp.test (document.cookie + ";")) {
    exp.exec (document.cookie + ";");
    return unescape(RegExp.$1);
  }
  else return false;
}

function testSessionCookie () {
  document.cookie ="testSessionCookie=Enabled";
  if (getCookieValue ("testSessionCookie")=="Enabled")
    return true 
  else
    return false;
}

function testPersistentCookie () {
  writePersistentCookie ("testPersistentCookie", "Enabled", "minutes", 1);
  if (getCookieValue ("testPersistentCookie")=="Enabled")
    return true  
  else 
    return false;
}

function writePersistentCookie (CookieName, CookieValue, periodType, offset) {

  var expireDate = new Date ();
  offset = offset / 1;
  
  var myPeriodType = periodType;
  switch (myPeriodType.toLowerCase()) {
    case "years": 
     var year = expireDate.getYear();     
     // Note some browsers give only the years since 1900, and some since 0.
     if (year < 1000) year = year + 1900;     
     expireDate.setYear(year + offset);
     break;
    case "months":
      expireDate.setMonth(expireDate.getMonth() + offset);
      break;
    case "days":
      expireDate.setDate(expireDate.getDate() + offset);
      break;
    case "hours":
      expireDate.setHours(expireDate.getHours() + offset);
      break;
    case "minutes":
      expireDate.setMinutes(expireDate.getMinutes() + offset);
      break;
    default:
      alert ("Invalid periodType parameter for writePersistentCookie()");
      break;
  } 
  
  document.cookie = escape(CookieName ) + "=" + escape(CookieValue) + "; expires=" + expireDate.toGMTString() + "; path=/";
}  

function deleteCookie (cookieName) {

  if (getCookieValue (cookieName)) writePersistentCookie (cookieName,"Pending delete","years", -1);  
  return true;     
}

// run initTICK
addLoadEvent(initTICK);