// start: select the appropriate stylesheet
if (!path) var path = ""; // if the path variable was set before the call to this (.js) file

// start: mouseover script and image preloader
function msover(img,ref)
{
	document.images[img].src = ref;
}

function msout(img,ref)
{
	document.images[img].src = ref;
}

//xx = new Image();
//xx.src="images/question_on.gif";

var currentoption;
var currenttype;
var oldoption;
var calendarBut;

function SetRadio(id, value){
	var radio_id = document.getElementById(id);
	radio_id.checked=value;
}

function Hide(id, hidden){
	var element_id = document.getElementById(id);
	element_id.style.display = (hidden)?'none':'';
}

function SetLabel(id, value){
	var label_id = document.getElementById(id);
	label_id.innerHTML = value;
}

function Disabled(id, hidden){
	var elem_id = document.getElementById(id);
	elem_id.disabled = (hidden)?'disabled':'';
	elem_id.style.backgroundColor = (hidden)?'d4d0c8':'';
}

function Highlight(id, status){
var el_id = document.getElementById(id);
	el_id.style.backgroundImage = (status)?"url(/reservation/images/misc/highlightBg.gif)":"";
	el_id.style.padding = (status)?'3px':'';
	el_id.style.whiteSpace = (status)?'nowrap':'';
}

function SetOption(option){
	if (option==currentoption){
		return;
	}
	oldoption = currentoption;
	currentoption = option;
	if (option == 0){
		SetRadio('searchType1',true);
		SetRadio('searchType2',false);
		SetRadio('searchType3',false);
		SetRadio('searchType4',false);
		Hide('searchType1Option',false);
		Hide('searchType2Option',false);
		Hide('searchType3Option',false);
		Hide('searchType4Option',true);
		Hide('TextSearchLabel', true);
		Hide('TextSearchField', true);
		SetLabel('searchType1Label','I want the room reservation at the beginning of my trip.');
		SetLabel('searchType2Label','I want the room reservation at the end of my trip.');
		SetLabel('searchType3Label','I want the room reservation at the beginning and end of my trip.');
		SetLabel('searchType4Label','');
		SetType('0', true);
		SetLabel('title1','Departure City');
		Hide('title2',true);
		Hide('selectCities2',true);
		Hide('hroSearchDivider',true);
		Hide('hroSearch',true);
		
	}
	else if (option == 1){
		SetRadio('searchType1',true);
		SetRadio('searchType2',false);
		SetRadio('searchType3',false);
		SetRadio('searchType4',false);
		Hide('searchType1Option',false);
		Hide('searchType2Option',false);
		Hide('searchType3Option',false);
		Hide('searchType4Option',false);
		Hide('TextSearchLabel', true);
		Hide('TextSearchField', true);
		SetLabel('searchType1Label','I want to park my car and stay at the hotel before my cruise.');
		SetLabel('searchType2Label','I want to park my car and stay at the hotel both before and after my cruise.');
		SetLabel('searchType3Label','I am flying into the cruise port, and do not need any parking accommodations.');
		SetLabel('searchType4Label','I want to park my car and stay at the hotel after my cruise.');
		SetType('0', true);
		SetLabel('title1','Departure City');
		Hide('title2',true);
		Hide('selectCities2',true);
		Hide('hroSearchDivider',true);
		Hide('hroSearch',true);
		
	}
	else if (option == 2){
		SetRadio('searchType1',true);
		SetRadio('searchType2',false);
		SetRadio('searchType3',false);
		SetRadio('searchType4',false);
		Hide('searchType1Option',true);
		Hide('searchType2Option',true);
		Hide('searchType3Option',true);
		Hide('searchType4Option',true);
		Hide('TextSearchLabel', false);
		Hide('TextSearchField', false);
		SetLabel('searchType1Label','');
		SetLabel('searchType2Label','');
		SetLabel('searchType3Label','');
		SetLabel('searchType4Label','');
		SetType('0', true);

		Hide('selectCities2',false);
		Hide('title2',false);
		SetLabel('title1','Departure Country');
		SetLabel('title2','Departure City');
		Hide('hroSearchDivider',false);
		Hide('hroSearch',false);
	}
}

function GetOption(){
	var Element = document.getElementById('searchOption1');
	if (!Element){
		return 0;
	}
	if (Element.checked){
		return 0;
	}
	Element = document.getElementById('searchOption2');
	if (Element.checked){
		return 2;
	}
	Element = document.getElementById('searchOption3');
	if (Element.checked){
		return 1;
	}
}

function GetType(){
	var Element = document.getElementById('searchType1');
	if (Element.checked){
		return 0;
	}
	Element = document.getElementById('searchType2');
	if (Element.checked){
		return 1;
	}
	Element = document.getElementById('searchType3');
	if (Element.checked){
		return 2;
	}
	Element = document.getElementById('searchType4');
	if (Element.checked){
		return 3;
	}
}

function reloadSearchbox(hotelID){
	channel = GetType();
	searchtype = GetSearchType();
	sendValues(channel,searchtype,hotelID);
}
		
function SetType(searchtype, isOptionChange){
	var option = GetOption();
	var beforechange = currenttype;
	
	showSelects();
	
	if (currenttype == searchtype && isOptionChange == false){
		return;
	}
	currenttype = searchtype;
	var channel = 0;
	if (searchtype == 0){
		if (option == 0){
			searchtype = 'PSF';
			channel = 0;
		}
		else if (option == 1){
			searchtype = 'PSC';
			channel = 1;
		}
		else if (option == 2){
			searchtype = 'HRO';
			channel = 2;
		}
	}
	else if (searchtype == 1){
		if (option == 0){
			searchtype = 'PFS';
			channel = 0;
		}
		else if (option == 1){
			searchtype = 'PSCS';
			channel = 1;
		}
		else if (option == 2){
			searchtype = 'HRO';
			channel = 2;
		}
	}
	else if (searchtype == 2){
		if (option == 0){
			searchtype = 'PSFS';
			channel = 0;
		}
		else if (option == 1){
			searchtype = 'FSC';
			channel = 3;
		}
		else if (option == 2){
			searchtype = 'HRO';
			channel = 2;
		}
	}
	else if (searchtype == 3){
		if (option == 1){
			searchtype = 'PCS';
			channel = 1;
		}
	}
	
	if ( !oldoption ) oldoption = 0;

//	if ( searchtype == 'PFS' || searchtype == 'PCS')
//	{
//		var checkin_date = document.getElementById('CheckInDate');
//		var vehicle_date = document.getElementById('VehiclePickUp');
//		vehicle_date.value = checkin_date.value;
//	} 
//	else if ( beforechange == 3 || 
//		(beforechange == 1 && searchtype == 'HRO' && oldoption == 0) ||
//		(beforechange == 1 && searchtype == 'PSC' && isOptionChange == true && oldoption == 0) ||
//		(beforechange == 1 && searchtype == 'PSFS') ||
//		(beforechange == 1 && searchtype == 'PSF' && oldoption != 1) ||
//		(beforechange == 1 && searchtype == 'PSF' && isOptionChange == false) 
//		
//		)
//	{
//		var checkin_date = document.getElementById('CheckInDate');
//		var vehicle_date = document.getElementById('VehiclePickUp');
//		checkin_date.value = vehicle_date.value;
//	}
	
	
	//show and hide fields
	if (searchtype == 'PSF' || searchtype == 'PSC'){
		Hide('CheckInDate', false);
		Hide('CheckOutDate', true);
		Hide('VehiclePickUp', false);
		Hide('CheckInDateBtn', false);
		Hide('CheckOutDateBtn', true);
		Hide('VehiclePickUpBtn', false);
		Disabled('CheckInDate', false);
		Disabled('CheckOutDate', false);
		SetLabel('CheckInDateLabel', 'Check-In Date at Hotel <a href="#null" onmouseover="Tip(searchBoxHelp(1))" onmouseout="UnTip()">[?]</a><br><span class="CheckDateLabel">(not date of flight)</span>');
		SetLabel('CheckOutDateLabel', '');
		SetLabel('VehiclePickUpLabel', 'Vehicle Pick-Up Date');
	}
	else if (searchtype == 'PFS' || searchtype == 'PCS'){
		Hide('CheckInDate', false);
		Hide('CheckOutDate', false);
		Hide('VehiclePickUp', false);
		Hide('CheckInDateBtn', false);
		Hide('CheckOutDateBtn', false);
		Hide('VehiclePickUpBtn', false);
		SetLabel('CheckInDateLabel', 'Date when parking begins');
		SetLabel('CheckOutDateLabel', 'Check-In Date at Hotel<br><span class="CheckDateLabel">(date of return night)</span>');
		SetLabel('VehiclePickUpLabel', 'Check-Out Date at Hotel');
	}
	else if (searchtype == 'PSFS' || searchtype == 'PSCS'){
		Hide('CheckInDate', false);
		Hide('CheckOutDate', false);
		Hide('VehiclePickUp', false);
		Hide('CheckInDateBtn', false);
		Hide('CheckOutDateBtn', false);
		Hide('VehiclePickUpBtn', false);
		Disabled('CheckInDate', false);
		Disabled('CheckOutDate', false);
		SetLabel('CheckInDateLabel', 'Check-In Date at Hotel <a href="#null" onmouseover="Tip(searchBoxHelp(1))" onmouseout="UnTip()">[?]</a><br><span class="CheckDateLabel">(not date of flight)</span>');
		SetLabel('CheckOutDateLabel', 'Return Check-In Date at Hotel<br><span class="CheckDateLabel">(date of return night)</span>');
		SetLabel('VehiclePickUpLabel', 'Vehicle Pick-Up Date');
	}
	else if (searchtype == 'FSC'){
		Hide('CheckInDate', false);
		Hide('CheckOutDate', false);
		Hide('VehiclePickUp', true);
		Hide('CheckInDateBtn', false);
		Hide('CheckOutDateBtn', false);
		Hide('VehiclePickUpBtn', true);
		Disabled('CheckInDate', false);
		Disabled('CheckOutDate', false);
		SetLabel('CheckInDateLabel', 'Check-In Date at Hotel<br><span class="CheckDateLabel">(date of return night)</span>');
		SetLabel('CheckOutDateLabel', 'Check-Out Date at Hotel');
		SetLabel('VehiclePickUpLabel', '');
	}
	else if (searchtype == 'HRO'){
		Hide('CheckInDate', false);
		Hide('CheckOutDate', false);
		Hide('VehiclePickUp', true);
		Hide('CheckInDateBtn', false);
		Hide('CheckOutDateBtn', false);
		Hide('VehiclePickUpBtn', true);
		Disabled('CheckInDate', false);
		Disabled('CheckOutDate', false);
		SetLabel('CheckInDateLabel', 'Check-In Date at Hotel');
		SetLabel('CheckOutDateLabel', 'Check-Out Date at Hotel');
		SetLabel('VehiclePickUpLabel', '');
	}
		UpdateDates(searchtype,true);
		sendValues(channel,searchtype);
	return true;
}

function UpdateDates(searchtype, isTypeChanged){
	var checkin_date = document.getElementById('CheckInDate');
	var checkout_date = document.getElementById('CheckOutDate');
	var vehicle_date = document.getElementById('VehiclePickUp');
	var checkin_time = new Date();
	var checkout_time = new Date();
	var vehicle_time = new Date();
	
	temp_checkin_time  = Date.parse(checkin_date.value);
	temp_checkout_time = Date.parse(checkout_date.value);
	temp_vehicle_time  = Date.parse(vehicle_date.value);

	checkin_time.setTime (isNaN(temp_checkin_time)?  GetCurrentTime()+86400000*7 : temp_checkin_time);
	checkout_time.setTime(isNaN(temp_checkout_time)? GetCurrentTime()+86400000*7 : temp_checkout_time);
	vehicle_time.setTime (isNaN(temp_vehicle_time)?  GetCurrentTime()+86400000*7 : temp_vehicle_time);

	if (searchtype == 'PSF' || searchtype == 'PSC'){
		vehicle_time.setTime(checkin_time.getTime()+86400000*7);
	}
	else if (searchtype == 'PSFS' || searchtype == 'PSCS' || searchtype == 'PFS' || searchtype == 'PCS'){
		if (isTypeChanged === true || (checkout_time.getTime() <= checkin_time.getTime())) { 
			checkout_time.setTime(checkin_time.getTime()+86400000*7);
		}
		if (vehicle_time.getTime() < checkout_time.getTime()+86400000*1) { 
			vehicle_time.setTime(checkout_time.getTime()+86400000*1);
		}
	}
//	else if (searchtype == 'PFS' || searchtype == 'PCS'){
//
//		if (isTypeChanged === true || calendarBut == 'VehiclePickUp' || checkin_time.getTime() <= vehicle_time.getTime()) {
//			checkin_time.setTime(vehicle_time.getTime()+86400000*7);
//			checkout_time.setTime(vehicle_time.getTime()+86400000*8);
//		}
//		if (calendarBut == 'CheckInDate' || checkout_time.getTime() <= checkin_time.getTime()){
//			checkout_time.setTime(checkin_time.getTime()+86400000*1);
//		}
//
//	}
	else if (searchtype == 'FSC' || searchtype == 'HRO'){
		checkout_time.setTime(checkin_time.getTime()+86400000);
	}
	checkin_date.value  = FormatDate(checkin_time.getMonth()+1  + '/' + checkin_time.getDate() + '/' + checkin_time.getFullYear());
	checkout_date.value = FormatDate(checkout_time.getMonth()+1 + '/' + checkout_time.getDate() + '/' + checkout_time.getFullYear());
	vehicle_date.value  = FormatDate(vehicle_time.getMonth()+1  + '/' + vehicle_time.getDate() + '/' + vehicle_time.getFullYear());
}

function GetCurrentTime() {
	var time = new Date();
	return time.getTime();
}

function SetDefaultCheckIn(){
	var element = document.getElementById('CheckInDate');
	var time = new Date();
	time.setTime(GetCurrentTime()+86400000*7);
	element.value = FormatDate((time.getMonth()+1) + '/' + time.getDate() + '/' + time.getFullYear());
}


function GetSearchType(){
	var searchtype = GetType();
	var option = GetOption();
	
	if (searchtype == 0){
		if (option == 0){
			searchtype = 'PSF';
			channel = 0;
		}
		else if (option == 1){
			searchtype = 'PSC';
			channel = 1;
		}
		else if (option == 2){
			searchtype = 'HRO';
			channel = 2;
		}
	}
	else if (searchtype == 1){
		if (option == 0){
			searchtype = 'PFS';
			channel = 0;
		}
		else if (option == 1){
			searchtype = 'PSCS';
			channel = 1;
		}
		else if (option == 2){
			searchtype = 'HRO';
			channel = 2;
		}
	}
	else if (searchtype == 2){
		if (option == 0){
			searchtype = 'PSFS';
			channel = 0;
		}
		else if (option == 1){
			searchtype = 'FSC';
			channel = 3;
		}
		else if (option == 2){
			searchtype = 'HRO';
			channel = 2;
		}
	}
	else if (searchtype == 3){
		if (option == 1){
			searchtype = 'PCS';
			channel = 1;
		}
	}
	return searchtype;
}

function CheckDatesForError(){
	var checkin_date = document.getElementById('CheckInDate').value;
	var checkout_date = document.getElementById('CheckOutDate').value;
	var vehicle_date = document.getElementById('VehiclePickUp').value;
	var cityselect = document.getElementById('departure_city_id');
	
	// convert dates to common format
	checkin_date = FormatDate(checkin_date);
	checkout_date = FormatDate(checkout_date);
	vehicle_date = FormatDate(vehicle_date);
	// check for correct dates format
	if (checkin_date.search(/^\d{1,2}\/\d{1,2}\/\d{4}$/) == -1 || checkout_date.search(/^\d{1,2}\/\d{1,2}\/\d{4}$/) == -1 || vehicle_date.search(/^\d{1,2}\/\d{1,2}\/\d{4}$/) == -1 ){
		SetDefaultCheckIn();
		return('Incorrect date format. Dates must be in MM/DD/YYYY format');
	}
	//get timestamps
	var checkin_date_ts = new Date();
	var checkout_date_ts = new Date();
	var vehicle_date_ts = new Date();
	checkin_date_ts.setTime(Date.parse(checkin_date));
	checkout_date_ts.setTime(Date.parse(checkout_date));
	vehicle_date_ts.setTime(Date.parse(vehicle_date));
	
	var today = new Date();
	var today_ts = today.getTime() - 86400000;
	
	var searchtype = GetType();
	var searchoption = GetOption();
	
	// check for dates to be in desired range
	if (checkin_date_ts.getTime() < today_ts){
		SetDefaultCheckIn();
		return('Check-in date must be greater than today date');
	}
	// PSF PSC
	if ( (searchoption == 0 || searchoption == 1) && searchtype == 0){
		if (vehicle_date_ts.getTime() <= checkin_date_ts.getTime()){
			return('Vehicle pick-up date must be greater than check-out date');
		}
	}
	// PFS PCS

	if ( (searchoption == 0 && searchtype == 1) || (searchoption == 1 && searchtype == 3)){
		
		checkin_date_ts.setTime(Date.parse(checkout_date));
		checkout_date_ts.setTime(Date.parse(vehicle_date));
		vehicle_date_ts.setTime(Date.parse(checkin_date));
				
		if (checkin_date_ts.getTime() >= checkout_date_ts.getTime()){
			return('Check-in date must be less than check-out date');
		}
		if (vehicle_date_ts.getTime() >= checkin_date_ts.getTime()){
			return('Vehicle parking begin date must be less than check-in date');
		}
		if (vehicle_date_ts.getTime() < today_ts){
			SetDefaultCheckIn();
			return('Vehicle parking begin date must be greater than today date');
		}
	}
	// PSFS PSCS
	if ( (searchoption == 0 && searchtype == 2) || (searchoption == 1 && searchtype == 1) ){
		if (checkin_date_ts.getTime() >= checkout_date_ts.getTime() ){
			return('Check-in date must be less than return check-in date');
		}
		if (vehicle_date_ts.getTime() <= checkout_date_ts.getTime()){
			return('Vehicle pick-up date must be greater than return check-in date');
		}
	}
	// HRO FSC
	if ( searchoption == 2 || (searchoption == 1 && searchtype == 2)){
		if (checkin_date_ts.getTime() >= checkout_date_ts.getTime()){
			return('Check-in date must be less than check-out date');
		}
	}
	
	return '';
}

function AutoCompleteDates(){
	// TODO
	var errorMessage = CheckDatesForError();
	var notifyMessage = 'Chosen date is not valid for selected period. Dates are set to default.';
	if (errorMessage != ''){
		UpdateDates(GetSearchType());
		//alert(notifyMessage+"\n\n"+errorMessage);
		return false;
	}
	return true;
}


function CheckInputParams(nocity){

	var cityselect = document.getElementById('departure_city_id');
	var cityfield = document.getElementById('TextSearchField');
	var adults = document.getElementById('adults');
	var rooms = document.getElementById('room');
	var autoSuggest = document.getElementById('autoSuggLabel');
	
	var adultscount = Math.floor(adults.options[adults.selectedIndex].innerHTML);
	var roomscount = Math.floor(rooms.options[rooms.selectedIndex].innerHTML.replace("+",""));

	if (nocity != 1){
		// check for city selected
		if (cityselect.options[cityselect.selectedIndex].value == 0 && (GetOption() != 2 || (GetOption() == 2 && cityfield.value==''))) {
		//if (cityselect.options[cityselect.selectedIndex].value == 0) {
			alert ('Please, select departure city');
			return false;
		}
	}
	if (adultscount < roomscount){
		alert('Number of rooms can not be greater than number of adults');
		return false;
	}
	if (roomscount == 10){
		alert('Please contact customer service to book 10 or more rooms.');
		return false;
	}
	
	var errorMessage = CheckDatesForError();
	if (errorMessage != ''){
		UpdateDates(GetSearchType());
		alert(errorMessage);
		return false;
	}
	
	if (autoSuggest){
		if (autoSuggest.value == '1'){ //for forbid enter submit
			autoSuggest.value = '';	
			return false;
		}
	}
	
	document.searchbox.action.value = 'search';
	Disabled('CheckInDate', false);
	Disabled('CheckOutDate', false);
	Disabled('VehiclePickUp', false);
	document.getElementById('departure_city_id').disabled = '';
	return true;
}


function FormatDate(datestring){

	var temp = new Array();
	temp = datestring.split(/[-\/]/);
	if (temp.length != 3){
//		alert('Incorrect date format');
		return datestring;
	}
	if (temp[0].length == 1) {
		temp[0] = "0"+temp[0];
		}
	if (temp[1].length == 1) {
		temp[1] = "0"+temp[1];
		}
	if (temp[2].length == 2){
		temp[2] = '20'+temp[2];
	}
	datestring = temp[0]+'/'+temp[1]+'/'+temp[2];

	return datestring;
}

function SaveSearchPopUp(){
	var url = "saveSearch.php";
	myWin = window.open (url,'newWin','scrollbars=no,status=no,width=385,height=344'); //width=385,height=344'
	return false;
}

function setColor(id){
	var el=document.getElementById(id);
	el.style.backgroundColor = '#07347d';
	el.style.color = '#ffffff';
	
}
function removeColor(id){
	var el=document.getElementById(id);
	el.style.backgroundColor = '#f3f3f3';
	el.style.color = '#003777';
}

function hide(id){
	if (document.getElementById(id)){
		document.getElementById(id).style.visibility = "hidden";
	}
}
function show(id){
	if (document.getElementById(id)){
		document.getElementById(id).style.visibility = "visible";
	}
}
function hideSelects(){
	hide('adults');
	hide('children');
	hide('room');
}
function showSelects(){
	show('adults');
	show('children');
	show('room'); 
}

function keyPressHandler(e) {
      var kC  = (window.event) ?    // MSIE or Firefox?
		event.keyCode : e.keyCode;
      var Esc = (window.event) ?   
		27 : e.DOM_VK_ESCAPE // MSIE : Firefox
      if(kC==Esc)
		closeDesc();         
}

function popup(param,type,path,width,height){
	if (!width) width = 650;
	if (!height) height = 600;
	
	var	ff = document.getElementById('descr');

	if ( !path ) path='';

	if (document.documentElement.clientHeight < height + 100) {
		height = document.documentElement.clientHeight - 100;
	}

	yPos = document.body.scrollWidth/2 - width/2;
	xPos = document.documentElement.scrollTop + document.documentElement.clientHeight/2 - height/2 - 10; 
	y = document.body.scrollWidth;	
	x = document.documentElement.clientHeight > document.body.scrollHeight ? document.documentElement.clientHeight : document.body.scrollHeight;
	
	body  = '<div class="overlay" style="height: '+x+'px; width:'+y+'px;" onclick="closeDesc()"></div>';
	body += '<div width="' + width + 'px" class="overlayDiv" style="position:absolute; top:'+xPos+'px; left:'+yPos+'px;">';
	body += '<iframe height="' + height + 'px" width="' + width + 'px" marginheight="0" marginwidth="0" frameborder="0" name="frame" style="opacity: 0.999999;" src="';
	if (type == 'descr') {
		body += getProtocol() + '://www.parksleepfly.com/reservation/hotel_details.php?hotelID='+param;
	} else if (type == 'map') {
		var airportID = document.getElementById('airportID').value;
		body += '/reservation/hotel_yahoo_map.php?hotelID='+param+'&airportID='+airportID;
	} else if (type == 'confirmation') {
		body += '/reservation/viator.php?affiliateXMLData=true';
	}  else if ((type == 'hotel') || (type == 'agency') || (type == 'referral')) {
		body += '/partners/notifications_display.php?partner='+ type +'&'+param;
	}  else if (type == 'surveys') {
		body += '/reservation/surveys.php?id='+ param;
	}  else if (type == 'faq') {
		body += '/info/faqs.php?fromCheckout=1&item='+ param;
	}
	
	body += '"></iframe>';
	body += '<div class="overlayClose" style="width:' + width + 'px;"><a href="#null" onclick="closeDesc(); return false;" id="bttn"><img src="'+path+'/reservation/images/buttons/close.gif"></a></div>';
	body += '</div>';

	ff.innerHTML = body;
	/*if (navigator.appName == 'Microsoft Internet Explorer'){
		frames['frame'].window.location.reload();
	}*/
	ff.style.display = 'block';
}

function closeDesc(){
	var	ff = document.getElementById('descr');
		ff.innerHTML = '';
		ff.style.display = 'none';
}
function reDirect(channel){
	if ( channel == 0 ) path = '/';
	else if ( channel == 1 ) path = '/cruiseport-hotels-rooms.html';
	else if ( channel == 2 ) path = '/airport-hotels-rooms.html';
	window.location.href = path;
}

function new_freecap()
{
	// loads new freeCap image
	if(document.getElementById)
	{
		// extract image name from image source (i.e. cut off ?randomness)
		thesrc = document.getElementById("freecap").src;
		thesrc = thesrc.substring(0,thesrc.lastIndexOf(".")+4);
		// add ?(random) to prevent browser/isp caching
		document.getElementById("freecap").src = thesrc+"?"+Math.round(Math.random()*100000);
	} else {
		alert("Sorry, cannot autoreload freeCap image\nSubmit the form and a new freeCap will be loaded");
	}
}

function is_valid_email (email)
{
	return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email);
}

function checkEmail(_form)
{
	if (!_form.email || !is_valid_email(_form.email.value)) {
		alert('Please enter valid Email.');
		return false;
	}
}
function searchBoxHelp(num)
{
	var text = 'The date you are staying at the hotel';
	switch ( GetSearchType() )
	{
		case 'PSF':
		case 'PSC':
		case 'PSFS':
		case 'PSCS':
			text = 'The date you are staying at the hotel';
			break;
	}
		
	return text;
}

function getProtocol() {
	return (document.location.href.toLowerCase().indexOf("https") == 0) ? "https" : "http";
}