// JavaScript Document
var newwindow;
var IE = document.all?true:false;
var tempUrl,tempX,tempY;

function changeLoc(page){
	location.href=page+".html";
	return true;	
	}
function savePageAsPDF() {
   var pURL = "http://savepageaspdf.pdfonline.com/pdfonline/pdfonline.asp?cURL=" + escape(document.location.href);
  window.open(pURL, "PDFOnline", "scrollbars=yes, resizable=yes,width=640, height=480,menubar,toolbar,location");
}
function printPage() {
	window.print(); }

function openpopup(url){
	newwindow=window.open(url,'name','height=450,width=500, scrollbars=yes, location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no');
	if (window.focus) {newwindow.focus()}}
function openpopuphere(url,name,h,w,scrollbar){

	newwindow=window.open(url,name,'height='+h+',width='+w+', scrollbars='+scrollbar+', location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no');
	if (window.focus) {newwindow.focus()}}
function openpopup2(url){
	newwindow=window.open(url,'name','height=500,width=600, scrollbars=false, location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no');
	if (window.focus) {newwindow.focus()}}
	
function showDiv(id){
	
	if(id=="far"){
	hideDiv('login');
	}
	else if(id=="login"){
		hideDiv('far');
		
		}
		else{ 
			}
			
		document.getElementById(id).style.visibility="visible";
		document.getElementById(id).style.display="block";
	}
function hideDiv(hid){
	document.getElementById(hid).style.visibility="hidden";
		document.getElementById(hid).style.display="none";
	}
function openpopupfeedback(url,name, height, width, scroll){
	newwindow=window.open(url,name,'height='+height+',width='+width+', left=150, top=20, scrollbars='+scroll+', location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no');
	if (window.focus) {newwindow.focus()}}
function newWindowweather(a,b){
	popupWindow = window.open('http://203.92.40.236/ITCWeather/WeatherPopup.asp?city='+a+'&template='+b,'popUpWindow','height=633,width=446,left=50,top=30,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no, status=yes');
	}
function windowWeatherNew(value){
	popupWindow = window.open('http://203.92.40.236/itc/itcweather/'+value,'popUpWindow','height=440,width=650,left=50,top=30,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no, status=yes');}
function closeDiv(){
		document.getElementById("checkMyAv").style.visibility="hidden";
		document.getElementById("checkMyAv").style.display="none";
		document.getElementById('shadedDiv').style.visiblity="hidden";
		document.getElementById('shadedDiv').style.display="none";}
		
function openDiv(url){
		// Detect if the browser is IE or not.
		// If it is not IE, we assume that the browser is NS.
		document.getElementById("checkMyAv").style.left=0+'px';
		document.getElementById("checkMyAv").style.top=0+'px';		
		document.getElementById('shadedDiv').style.visibility="visible";
		document.getElementById('shadedDiv').style.display="block";
		// Main function to retrieve mouse x-y pos.s
		//document.onclick = getMouseXY;
		
		document.attachEvent('onclick',getMouseXY);
		tempUrl = url;
		//alert(tempY+' Y:x '+tempX);
		
	}
function getMouseXY(e) {
	
		// If NS -- that is, !IE -- then set up for mouse capture
		if (!IE) document.captureEvents(Event.MOUSECLICK);
		
		// Set-up to use getMouseXY function onMouseMove
		//document.onclick = getMouseXY;
		
		// Temporary variables to hold mouse x-y pos.s

  if (IE) { // grab the x-y pos.s if browser is IE
/*    tempX = (event.clientX -e.offsetLeft) + document.body.scrollLeft;
    tempY = (event.clientY -e.offsetTop)+ document.body.scrollTop;*/
	tempX = event.clientX + document.body.scrollLeft;
    tempY = event.clientY + document.body.scrollTop;

  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX;
    tempY = e.pageY;
}  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
 		document.getElementById("checkMyAv").style.left=(tempX-400)+'px';
		document.getElementById("checkMyAv").style.top=(tempY-75)+'px';	
		document.getElementById("checkMyAv").style.visibility="visible";
		document.getElementById("checkMyAv").style.display="block";
		document.onclick ="";
  return true}
  
function checksign(image){

if(image.src.indexOf('images/plus.jpg')>1){
	image.src='images/minus.jpg';
	image.alt="Collapse";
	newsLetter('divOpen');
}
	else if(image.src.indexOf('images/minus.jpg')>1){
	image.src='images/plus.jpg';
	image.alt="Expand";
	newsLetter('divClose');
	}}
function newsLetter(cont){
		document.getElementById('divClose').style.display='block';
		document.getElementById('divOpen').style.display='none';
		document.getElementById(cont).style.display='block';
		}		
function  setbtn(){
obj=document.getElementById('chkbx');
if(obj.checked){
alert('You have confirmed this booking to be cancelled.');
changeLoc('ITC_Hotel_Booking_cancel_step03');
}
else{
alert('Please confirm that you want to cancel this booking.');
}
}


function checkform(id){
	
	selhotel	=	document.forms[id].getElementsByTagName("select")[0];
	selrooms	=	document.forms[id].getElementsByTagName("select")[1];
	selapr		=	document.forms[id].getElementsByTagName("select")[2];
	
	chk_in		=	document.forms[id].getElementsByTagName("input")[0];
	//chk_in=	document.forms[id].getElementsByTagName("input")[1];//left for calendar image
	chk_out		=	document.forms[id].getElementsByTagName("input")[1];
	minlos		=	document.forms[id].getElementsByTagName("input")[2];
	maxlos		=	document.forms[id].getElementsByTagName("input")[3];
	maxlosval	=  maxlos.value;
	if(maxlosval==1){maxlosval+=1;}
	lead		=	document.forms[id].getElementsByTagName("input")[4];
	rateplanid	=	document.forms[id].getElementsByTagName("input")[5];
		
	if(selhotel.value=="0")
	{
		alert("Please select a hotel for this package to see availability!");
	}
	else if((chk_in.value=="" || chk_in.value=="dd/mm/yyyy") || (chk_out.value=="" || chk_out.value=="dd/mm/yyyy") )
	{
		alert("Please select a checkin/checkout dates to see availability!");
	}
	else 
	{
		stay=calDateDiff(chk_in.value,chk_out.value);
		/*alert("Total Stay ="+stay);
		alert("Check in - Today = "+calDateDiff("",chk_in.value));
		alert("lead value="+lead.value);*/
		if (stay < minlos.value){
			alert("The length of stay is shorter than the minimum number of nights required to avail this package!");
			}
			else if(stay > maxlosval){
				alert("The length of stay is greater than the maximum number of nights required to avail this package!");
				}
				else if(calDateDiff("",chk_in.value) < lead.value){
					alert("This package will be available for booking only on or after "+lead.value+" days from today!");
					}
					else{
						document.forms[id].action+="?checkin="+chk_in.value+"&checkout="+chk_out.value+"&hotel="+selhotel.value+"&rooms="+selrooms.value+"&apr="+selapr.value+"&rateplanid="+rateplanid;					
						document.forms[id].method="GET";
						document.forms[id].submit();
						}
	}}
function calDateDiff(date1,date2){
	
	if(date1==""){
		chk_in_temp=new Date();
		}
		else{
		$arr=date1.split("/");
		chk_in_temp=new Date($arr[2],$arr[1]-1,$arr[0]);
		}
	
		
		if(date2==""){
		chk_out_temp=new Date();
		}
		else{
		$arr=date2.split("/");
		chk_out_temp=new Date($arr[2],$arr[1]-1,$arr[0]);
		}
	//today=new Date()
	//var christmas=new Date(today.getFullYear(), 11, 25); //Month is 0-11 in JavaScript
	/*	
	if (today.getMonth()==11 && today.getDate()>25) //if Christmas has passed already
	christmas.setFullYear(christmas.getFullYear()+1) //calculate next year's Christmas
	//Set 1 day in milliseconds
	*/
	one_day=1000*60*60*24;
	/*alert("Checkout = "+chk_out_temp);
	alert("Check In = " +chk_in_temp);*/
	days_in_between = Math.ceil((chk_out_temp.getTime()-chk_in_temp.getTime())/(one_day));
	
	return days_in_between;
	}