var DateOffset		= 3;
var DateDifference	= 1;
var NoYears			= 4;
var CurrDday 		= new Date();
var CurrMonth		= CurrDday.getMonth();
var CurrDate		= CurrDday.getDate();
var CurrYear		= CurrDday.getFullYear();

var InDay 			= new Date();
var InDay			= new Date(InDay.setDate(InDay.getDate()+DateOffset));
var InMonth			= InDay.getMonth();
var InDate			= InDay.getDate();
var InYear			= InDay.getFullYear();

var OutDay 			= InDay;
var OutDay			= new Date(OutDay.setDate(OutDay.getDate()+DateDifference));
var OutMonth		= OutDay.getMonth();
var OutDate			= OutDay.getDate();
var OutYear			= OutDay.getFullYear();

var nav				= navigator.appName;

var WeekDays		= new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");

var FORM="";var INM="";var IND="";var INY="";var OUTM="";var OUTD="";var OUTY="";var NON="";

function Init(frm,inm,ind,iny,outm,outd,outy,non){
FORM=frm;INM=inm;IND=ind;INY=iny;OUTM=outm;OUTD=outd;OUTY=outy;NON=non;
FillYears();
}

function FillYears(){
	with(document.forms[FORM]){
		for (a=0; a<=NoYears; a++){
		if (a!=NoYears){elements[INY].options[a]= new Option(InYear+a,InYear+a);}
		elements[OUTY].options[a]= new Option(InYear+a,InYear+a);
		}
	}
	LoadDefaultDates();
}

function LoadDefaultDates(){
	with (document.forms[FORM]){
	elements[INY].options[InYear-InYear].selected=true;
	elements[OUTY].options[OutYear-InYear].selected=true;
	elements[INM].options[InMonth].selected=true;
	elements[OUTM].options[OutMonth].selected=true;
	setMonthDays(IND,InMonth,InYear);
	setMonthDays(OUTD,OutMonth,OutYear);
	elements[IND].options[InDate-1].selected=true;
	elements[OUTD].options[OutDate-1].selected=true;
	elements[NON].options[DateDifference-1].selected=true;
	}
	document.images["iday"].src="dd"+returnDay('IN')+".gif";
	document.images["oday"].src="dd"+returnDay('OUT')+".gif";
}

function setMonthDays(objname,mm,yy){
	with (document.forms[FORM]){
		currIndex=elements[objname].selectedIndex;
		elements[objname].options.length=0;
		for (a=1; a<=getMaxDays(mm,yy); a++){
		elements[objname].options[a-1] = (a<10)? new Option("0"+a+"","0"+a+"") : new Option(a,a)
		}
		if (elements[objname].options.length<(currIndex+1)){
		elements[objname].selectedIndex=elements[objname].options.length-1;
		}else{
		elements[objname].selectedIndex=currIndex;
		}
	}
}


function returnDay(val){
	iiy=document.forms[FORM].elements[eval(""+val+"Y")].options[document.forms[FORM].elements[eval(""+val+"Y")].selectedIndex].value;
	iim=document.forms[FORM].elements[eval(""+val+"M")].options[document.forms[FORM].elements[eval(""+val+"M")].selectedIndex].value;
	iid=document.forms[FORM].elements[eval(""+val+"D")].options[document.forms[FORM].elements[eval(""+val+"D")].selectedIndex].value;
	tmpDate1=new Date(iiy,iim,iid);
	return tmpDate1.getDay();
}


function retDay(dd,mm,yy){
tempOptDate= new Date(yy,mm,dd,0,0,0,0);
return WeekDays[tempOptDate.getDay()]

}

function getMaxDays(mm,yy){
mxCount=0;
	if (mm==1 && yy%4==0){
	mxCount=29; }else if (mm==1){
	mxCount=28; }else if (mm==0 || mm==2 || mm==4 || mm==6 || mm==7 || mm==9 || mm==11){
	mxCount=31;	}else{ mxCount=30;}
return mxCount;
}

function countNoDays(inM,inD,inY,outM,outD,outY){
selDays=1;
	if (inY==outY){
		if (inM==outM){
		selDays=outD-inD;
			if (selDays<1){selDays=-1;}
		}else{
			if (inM>outM){
			selDays=-1;
			}else{
				selDays=(getMaxDays(inM,inY)-inD)+outD;
				for (a=0; a<(outM-inM-1); a++){
				selDays=selDays+getMaxDays(inM+1+a,inY);
				}
			}
		}
	}else{
		if (outY>inY){
			selDays=(getMaxDays(inM,inY)-inD)+outD;
			for (k=inM+1; k<=11; k++){
				selDays=selDays+getMaxDays(k,inY);
			}
			for (k=0; k<(outY-inY-1); k++){
				selDays=selDays+getDaysOfYear(inY+1+k);
			}
			for (k=0; k<outM; k++){
				selDays=selDays+getMaxDays(k,outY);
			}
			
		}else{
		selDays=-1;
		}
	}
	return selDays;
}

function getDaysOfYear(yy){
	if (yy%4==0){
	return 366;
	}else{
	return 365;
	}
}

function setCheckOut(){
	with (document.forms[FORM]){
	setMonthDays(IND,elements[INM].options[elements[INM].selectedIndex].value,elements[INY].options[elements[INY].selectedIndex].value);
	tempCheckIn = new Date(elements[INY].options[elements[INY].selectedIndex].value,elements[INM].options[elements[INM].selectedIndex].value,elements[IND].options[elements[IND].selectedIndex].value,0,0,0,0);
	tempCheckOut = new Date(tempCheckIn.setDate(tempCheckIn.getDate()+Number(elements[NON].options[elements[NON].selectedIndex].value)));
	elements[OUTY].selectedIndex = tempCheckOut.getFullYear()-InYear;
	elements[OUTM].selectedIndex = tempCheckOut.getMonth();
	setMonthDays(OUTD,tempCheckOut.getMonth(),tempCheckOut.getFullYear());
	elements[OUTD].selectedIndex = tempCheckOut.getDate()-1;
	}
	document.images["iday"].src="dd"+returnDay('IN')+".gif";
	document.images["oday"].src="dd"+returnDay('OUT')+".gif";
}

function setNights(){
	with (document.forms[FORM]){
	setMonthDays(OUTD,elements[OUTM].options[elements[OUTM].selectedIndex].value,elements[OUTY].options[elements[OUTY].selectedIndex].value);
	inM=Number(elements[INM].options[elements[INM].selectedIndex].value);
	inD=Number(elements[IND].options[elements[IND].selectedIndex].value);
	inY=Number(elements[INY].options[elements[INY].selectedIndex].value);
	outM=Number(elements[OUTM].options[elements[OUTM].selectedIndex].value);
	outD=Number(elements[OUTD].options[elements[OUTD].selectedIndex].value);
	outY=Number(elements[OUTY].options[elements[OUTY].selectedIndex].value);
	noDays=countNoDays(inM,inD,inY,outM,outD,outY);
		if (noDays!=-1 && noDays<=elements[NON].options.length){
			elements[NON].selectedIndex=noDays-1;
		}
	}
	document.images["iday"].src="dd"+returnDay('IN')+".gif";
	document.images["oday"].src="dd"+returnDay('OUT')+".gif";
}

function submitData(AFFCode){
with (document.forms[FORM]){
	inM=Number(elements[INM].options[elements[INM].selectedIndex].value);
	inD=Number(elements[IND].options[elements[IND].selectedIndex].value);
	inY=Number(elements[INY].options[elements[INY].selectedIndex].value);
	outM=Number(elements[OUTM].options[elements[OUTM].selectedIndex].value);
	outD=Number(elements[OUTD].options[elements[OUTD].selectedIndex].value);
	outY=Number(elements[OUTY].options[elements[OUTY].selectedIndex].value);
	selInday = new Date(inY,inM,inD,0,0,0,0);
	
	noDays=countNoDays(inM,inD,inY,outM,outD,outY);
	
	if (document.forms[FORM].selCity.value=="%" && document.forms[FORM].cmbCity.selectedIndex==0){
	alert('Please Select a City    ');
	FillYears();
	return;
	}
		if (noDays==-1){
		alert('Check Out Date should be greater than Check In Date     ');
		FillYears();
		}else if (noDays>elements[NON].options.length){
			if (noDays>elements[NON].options.length && noDays<31){
			alert('You can not book '+noDays+' days.\r\n\r\nNumber of days should be maximum of '+elements[NON].options.length+'       ');
			FillYears();
			}else if (noDays>30 && noDays<365){
			alert('You have selected more than '+(Math.ceil(noDays/31)-1)+' month(s).\r\n\r\nNumber of days should be maximum of '+elements[NON].options.length+'       ');
			FillYears();
			}else if (noDays>364){
			alert('You have selected more than '+(Math.ceil(noDays/365)-1)+' year(s).\r\n\r\nNumber of days should be maximum of '+elements[NON].options.length+'       ');
			FillYears();
			}
		}else{
			chk=false;
			if (CurrDday.getMonth()<selInday.getMonth()){
			chk=false;
			}else if (CurrDday.getDate()>selInday.getDate()){
			chk=true;
			}
			if (chk){
			alert('Check In Date should be grater than or equal to current date    ');
			FillYears();
			}else{
			document.forms[FORM].afftCode.value=AFFCode;
			docdom=""+document.domain+"";
			if (document.forms[FORM].selCity.value=="%"){
				document.forms[FORM].selCity.value=document.forms[FORM].cmbCity.options[document.forms[FORM].cmbCity.selectedIndex].value;
			}
			document.frm1.action = "http://www.wdcahotels-bookings.com/servlets/WDCAHotels.ResevationSearch";
			document.frm1.submit();
			}
		}

	}
}


var err=false;
var msg="";
function chkForm(){
err=false;
if (document.form1.name.value=="" || document.form1.name.value==" "){
err=true;
msg="Please enter Name";
}
if (form1.mail.value=="" || (form1.mail.value.indexOf(".")==-1) || (form1.mail.value.indexOf("@")==-1) || (form1.mail.value.indexOf(" ")>-1) || (form1.mail.value.indexOf("@")==form1.mail.value.length)|| (form1.mail.value.indexOf(".")==form1.mail.value.length-1) || (form1.mail.value.indexOf(".@")>-1) || (form1.mail.value.indexOf("@.")>-1) || (form1.mail.value.length<6)){
if (msg==""){
	msg="Please enter a valid e-mail address";
}
err=true;
}

	if (err){
	alert(msg);
	err=false;
	msg="";
	return;
	}
	form1.submit();
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)

   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function pop_info(id,URL){
window.open( ""+URL+"", ""+id+"", "left=0,top=0,width="+(screen.width-200)+",height="+(screen.height-80)+",toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=1,resizable=0") ; 
}
function setformat(val){
document.form1.Hformat.value=val;
}
function check(){
with(document.form1){
if (name.value=="" || name.value==" "){alert("Please enter Name");return;}
if (mail.value=="" || mail.value==" "){alert("Please enter e mail address");return;}
if (mail.value.indexOf("@")<0){alert("Please enter a valid e mail address");return;}
if (mail.value.indexOf(".")<0){alert("Please enter a valid e mail address");return;}
}
document.form1.submit();
}
