﻿/////////////////////////////////////////////////////////////////////////////////////////
//save the user lang to cookie
function saveUserLang(lang)
{ 
	//document.cookie= "siteLang=" +escape(obj.value)+ "; expires=Fri, 25 Dec 2020 23:59:59 GMT; path=/";
	set_cookie("siteLang", escape(lang),2020,12,25,"/")
	window.location.href = "/";
} 


////////////////////////////////////////////////////////////////////////////////////////////////////
// calendars display function
modalWin = ""; 
var calendarWinIsOpen = false;
function showCalendar_new(obj,datepickerPath)
{
	//find the text control that contains the date
	var ctlName=obj.replace(/btn_show_/i,"");
	var ctlDest=document.getElementById(drpDestination_id);
	var ctlDestValue=ctlDest.value;
	var ctlDestText=ctlDest.options[ctlDest.selectedIndex].text;
	
	var departureDate = "";
	
	if(isnull(ctlDestValue)){
		alert("Please select an option from the 'Leaving From' list.");
		document.getElementById(drpDestination_id).focus();
		return;
	}
	//if the Departure date is empty and he trying to open the return date
	if(ctlName==date2_id && isnull(document.getElementById(date1_id).value)){
		alert("Please enter the 'Departure Date' first.");
		return;
	}
	
	//if he clicks on the Departure date, clean the return date box
	if(ctlName==date1_id){
		document.getElementById(date2_id).value = "";
	}
	
	//if it's the return date control, send the opposite direction to get the right values
	if(ctlName==date2_id){
		ctlDestValue = (ctlDestValue=="DC2NY") ? "NY2DC" : "DC2NY"; 
		departureDate = '&departureDate=' + document.getElementById(date1_id).value
	}
	
	var queryString = '?destinationText=' +ctlDestText+ '&destination=' + ctlDestValue + departureDate + '&ctlID=' + ctlName
	//make sure we activate the iframe in a secure SSL page if we are the cur page is secure (in the dev server is not)
	var HostType = ((document.location.protocol == "https:") ? "https://" : "http://");
	var basePath = "";
	if(HostType=="https://")
		basePath = HostType +  serverUrl;
	
	if(ctlName==date1_id){
		document.getElementById('calendar_date2_div').style.display='none';
		document.getElementById('calendar_date2_iframe').src='';
		if(document.getElementById('calendar_date1_div').style.display=='inline'){
			document.getElementById('calendar_date1_div').style.display='none';
			document.getElementById('calendar_date1_iframe').src='';
		}
		else{
			document.getElementById('calendar_date1_div').style.display='inline';
			document.getElementById('calendar_date1_iframe').style.display='none'
			//document.getElementById('calendar_date1_iframe').src=basePath + '/SITE/TEMPLATES/RESERVATION/dialogs/datepicker/datepicker_calendar_frame.aspx' + queryString + "&calendar_date=calendar_date1";
			//alert(basePath + datepickerPath + queryString + "&calendar_date=calendar_date1")
			document.getElementById('calendar_date1_iframe').src=basePath + datepickerPath + queryString + "&calendar_date=calendar_date1";
		}
	}
	
	if(ctlName==date2_id){
		if(document.getElementById('calendar_date2_div').style.display=='inline'){
			document.getElementById('calendar_date2_div').style.display='none';
			document.getElementById('calendar_date2_iframe').src='';
		}
		else{
			document.getElementById('calendar_date2_div').style.display='inline';
			document.getElementById('calendar_date2_iframe').style.display='none'
			//document.getElementById('calendar_date2_iframe').src= basePath + '/SITE/TEMPLATES/RESERVATION/dialogs/datepicker/datepicker_calendar_frame.aspx' + queryString + "&calendar_date=calendar_date2";
			document.getElementById('calendar_date2_iframe').src= basePath + datepickerPath + queryString + "&calendar_date=calendar_date2";
		}
	}
}

////////////////////////////////////////////////////////////////////////////////////////////////////
function clearDates_new(datepickerPath)
{
	try{
		document.getElementById('calendar_date1_div').style.display='none';
		document.getElementById('calendar_date1_iframe').src='';
	}
	catch(e){}
	try{
		document.getElementById('calendar_date2_div').style.display='none';
		document.getElementById('calendar_date2_iframe').src='';
	}
	catch(e){}

	document.getElementById(date1_id).value = "";
	document.getElementById(date2_id).value = "";
	document.getElementById(date1_id).focus();
	showCalendar(date1_id, datepickerPath);
}


/*
function showCalendar(obj)
{
	//find the text control that contains the date
	var ctlName=obj.replace(/btn_show_/i,"");
	var ctlDest=document.getElementById(drpDestination_id);
	var ctlDestValue=ctlDest.value;
	var ctlDestText=ctlDest.options[ctlDest.selectedIndex].text;
	
	var departureDate = "";
	
	if(isnull(ctlDestValue)){
		alert("Please select an option from the 'Leaving From' list.");
		document.getElementById(drpDestination_id).focus();
		return;
	}
	//if the Departure date is empty and he trying to open the return date
	if(ctlName==date2_id && isnull(document.getElementById(date1_id).value)){
		alert("Please enter the 'Departure Date' first.");
		return;
	}
	
	//if he clicks on the Departure date, clean the return date box
	if(ctlName==date1_id){
		document.getElementById(date2_id).value = "";
	}
	
	//if it's the return date control, send the opposite direction to get the right values
	if(ctlName==date2_id){
		ctlDestValue = (ctlDestValue=="DC2NY") ? "NY2DC" : "DC2NY"; 
		departureDate = '&departureDate=' + document.getElementById(date1_id).value
	}
	
	var queryString = '?destinationText=' +ctlDestText+ '&destination=' + ctlDestValue + departureDate + '&ctlID=' + ctlName
	//make sure we activate the iframe in a secure SSL page if we are the cur page is secure (in the dev server is not)
	var HostType = ((document.location.protocol == "https:") ? "https://" : "http://");
	var basePath = "";
	if(HostType=="https://")
		basePath = HostType +  serverUrl;
		
	if(ctlName==date1_id){
		document.getElementById('calendar_date2_div').style.display='none';
		document.getElementById('calendar_date2_iframe').src='';
		if(document.getElementById('calendar_date1_div').style.display=='inline'){
			document.getElementById('calendar_date1_div').style.display='none';
			document.getElementById('calendar_date1_iframe').src='';
		}
		else{
			document.getElementById('calendar_date1_div').style.display='inline';
			document.getElementById('calendar_date1_iframe').style.display='none'
			document.getElementById('calendar_date1_iframe').src=basePath + '/SITE/TEMPLATES/RESERVATION/dialogs/datepicker/datepicker_calendar_frame.aspx' + queryString + "&calendar_date=calendar_date1";
		}
	}
	
	if(ctlName==date2_id){
		if(document.getElementById('calendar_date2_div').style.display=='inline'){
			document.getElementById('calendar_date2_div').style.display='none';
			document.getElementById('calendar_date2_iframe').src='';
		}
		else{
			document.getElementById('calendar_date2_div').style.display='inline';
			document.getElementById('calendar_date2_iframe').style.display='none'
			document.getElementById('calendar_date2_iframe').src= basePath + '/SITE/TEMPLATES/RESERVATION/dialogs/datepicker/datepicker_calendar_frame.aspx' + queryString + "&calendar_date=calendar_date2";
		}
	}

}

////////////////////////////////////////////////////////////////////////////////////////////////////
function clearDates()
{
	try{
		document.getElementById('calendar_date1_div').style.display='none';
		document.getElementById('calendar_date1_iframe').src='';
	}
	catch(e){}
	try{
		document.getElementById('calendar_date2_div').style.display='none';
		document.getElementById('calendar_date2_iframe').src='';
	}
	catch(e){}

	document.getElementById(date1_id).value = "";
	document.getElementById(date2_id).value = "";
	document.getElementById(date1_id).focus();
	showCalendar(date1_id);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
*/

/////////////////////////////////////////////////////////////////////////////////////////
// for firefox
/////////////////////////////////////////////////////////////////////////////////////////
function checkFocus(){ 
	if (window.navigator.appVersion.indexOf("MSIE")==-1) 
		{ 
		if (modalWin!=null && modalWin!="" && !modalWin.closed) 
		{ 
			self.blur(); 
			modalWin.focus(); 
		} 
	} 
} 
	
//************************************************************
//* add url 2 favorits
//************************************************************
function add2fav(url,title)
{
	if (window.sidebar)// Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");	
	else if( window.external ) // IE Favorite		
		window.external.AddFavorite( url, title); 
	else 
		alert("You need to click CTRL+D to bookmark us."); 
}

//************************************************************
//* set the url as the home page
//************************************************************
function setAsHomepage(obj,url)
{
	if (window.sidebar) // Mozilla Firefox Bookmark
		{
			//the message is created on the server, lang sensitive.
			alert(ffSetHomMsg);
		}
	else if(window.external)  // IE Favorite
		obj.style.behavior='url(#default#homepage)';obj.setHomePage(url);
}

function pageWidth() {
	return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;
}
