/* ONLINE BOOKING */
/* LAST UPDATED: 28 April 2009 */
/*
	[Vars]
	b_code = exl_psn : Provider short name
	b_category : [1=Accommodation] [2=Attraction] [3=Events] [4=Adventure] [5=Charter & Rental] [6=Epicurean] [7=Function Centre] [8=Tours] [9=Non Serviced Accommodation]
	elementId  : HTML <DIV> element id
*/

/* BEGIN: REQUEST PRICING */
function au_requestPricing(exl_psn,elementId,b_category){
	au_RequestPricing(exl_psn,elementId,b_category);
}

function au_RequestPricing(exl_psn,elementId,b_category){
	if(elementId == false || elementId == null) elementId = "";
	if(b_category == false || b_category == null) b_category = "";
	var imgLoader = "<div style='text-align:center;color:#666666;font-weight:bold;font-size:14px;'>";
	imgLoader += "<img src='http://img.shopsafe.com/images/ajax-loader.gif' height='18' style='margin-bottom:5px;' /><br />Loading...";
	imgLoader += "</div>";
	var elm = "PRICING"+elementId;
	document.getElementById(elm).innerHTML = imgLoader;
	document.getElementById("BOOKING-AVAILABILITY"+elementId).style.display = "block";
	ajaxRequestPricingBooking(exl_psn,elementId,b_category);
}

/* Request pricing and booking availability for detail pages */
function ajaxRequestPricingBooking(exl_psn,elementId,b_category){
	xmlHttp = getXmlHttpObject();
	var elm = "PRICING"+elementId;
	if(xmlHttp==null) {
		document.getElementById(elm).innerHTML = "Request failed, please try the booking form.";
		return;
	}
	var url = "/services/get_booking_availability.asp";
	url=url+"?exl_psn="+exl_psn;
	url=url+"&category="+b_category;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){ajaxResponsePricingBooking(elementId)};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function ajaxResponsePricingBooking(elementId) {
	var elm = "PRICING"+elementId;
	if(xmlHttp.readyState==4){
		document.getElementById(elm).innerHTML = xmlHttp.responseText;
		document.getElementById(elm).style.display = "block";
		document.getElementById("BOOKING-AVAILABILITY"+elementId).style.display = "block";
	}
}
/* END: REQUEST PRICING */

/* BEGIN: BOOKING FORM */
function au_secureBooking(pid){
	au_SecureBooking(pid);
}
function au_SecureBooking(pid){
	//deprecated: change to au_validateBooking (20090428)
	var e = document.getElementById("formBookingV3-"+pid);
	var b_code = e.b_code.value;
	var b_category = e.b_category.value;
	var b_date = e.b_date.value;
	var b_nights = e.b_nights.value;
	var valid = false;
	
	if(eval(b_nights) < 1) b_nights = 1
	if(b_date != ""){
    var tmp = b_date.split("/");
		if(tmp.length == 3){
		  b_date = tmp[2]+"-"+tmp[1]+"-"+tmp[0];
			valid = true;
		}
	}
	if(valid){
		v3_SecureBooking(b_code,b_category,b_date,b_nights);
	}
	else{
		window.alert("Please enter a valid date (mm/dd/yyyy)");
	}
}

function au_validateBooking(b_code,b_category,b_date,b_nights){
	au_ValidateBooking(b_code,b_category,b_date,b_nights);
}
function au_ValidateBooking(b_code,b_category,b_date,b_nights){
	var valid = false;
	if(eval(b_nights) < 1) b_nights = 1;
	if(b_date != ""){
    var tmp = b_date.split("/");
		if(tmp.length == 3){
		  b_date = tmp[2]+"-"+tmp[1]+"-"+tmp[0];
			valid = true;
		}
	}
	if(valid){
		v3_SecureBooking(b_code,b_category,b_date,b_nights);
	}
	else{
		window.alert("Please enter a valid date (mm/dd/yyyy)");
	}
}
function v3_secureBooking(exl_psn,b_category,b_date,b_nights){
  v3_SecureBooking(exl_psn,b_category,b_date,b_nights);
}
function v3_SecureBooking(exl_psn,b_category,b_date,b_nights){
	var b_url = "http://www.au.v3travel.com/CABS2/SwitchServices/Provider.aspx";
	b_url += "?exl_psn="+exl_psn;
	b_url += "&exl_dn=ShopSafe_Web";
	b_url += "&exl_bs=shopsafe_web";
	b_url += "&exl_mode=PAI";
	b_url += "&category="+b_category;
	b_url += "&date="+b_date;
	if(eval(b_category) == 1){
		b_url += "&nights="+b_nights;
	}
  window.open(b_url);
}
/* END: BOOKING FORM */