// JavaScript Document

function getDateObject(dateString,dateSeperator)
{
	//This function return a date object after accepting 
	//a date string ans dateseparator as arguments
	var curValue=dateString;
	var sepChar=dateSeperator;
	var curPos=0;
	var cDate,cMonth,cYear;

	//extract day portion
	curPos=dateString.indexOf(sepChar);
	cDate=dateString.substring(0,curPos);
	
	//extract month portion				
	endPos=dateString.indexOf(sepChar,curPos+1);	
	cMonth=dateString.substring(curPos+1,endPos);

	//extract year portion				
	curPos=endPos;
	endPos=curPos+5;			
	cYear=curValue.substring(curPos+1,endPos);
	
	//Create Date Object
	dtObject=new Date(cYear,cMonth,cDate);
	
	return dtObject;
}

/*function adddate(day,month,year,frm,cval2)
{
	with(frm)
	{
	//alert("gg");
	
	//alert(month.length);
	//alert("month :" +month);
	//month = parseInt(month);
	//alert("before month : " + month);
	day   = parseInt(day) + 1;
	
	var monthc=month;
	if(monthc.length==2)
		var val2=monthc.substr(1);
	else
		var val2=month;
		
	if(cval2=='M' || cval2=='Y')
		month = parseInt(val2);
	else	
		month = parseInt(val2)-1;
	//alert(val2);
	
	newDate = new Date ( year, month, day );
	year  = newDate.getFullYear();
    
	if(cval2=='M' || cval2=='Y')
		month = newDate.getMonth();
	else
		month = newDate.getMonth()+1;
		
    month = (month<10)?'0'+month:month;
	//alert("parse month : " + month);
    day   = newDate.getDate();
    //day   = (day<10)?'0'+day:day;

    formattedDate = month + '/' + day + '/' + year;
	
	daylist_out.value=day;
	monthlist_out.value=month;
	yearlist_out.value=year;
	
	
	}
	
}
*/

function adddate(day,month,year,frm,cval2)
{
	with(frm)
	{
	
	day   = parseInt(day) + 1;
	var monthc=month;
	
	if(cval2=='M' || cval2=='Y' || cval2=='D')
		month = monthc-1;
	else	
		month = monthc-1;
		
	newDate = new Date ( year, month, day );
	year  = newDate.getFullYear();
    
	if(cval2=='M' || cval2=='Y' || cval2=='D')
		month = newDate.getMonth()+1;
	else
		month = newDate.getMonth()+1;
	
    month = (month<10)?'0'+month:month;
    day   = newDate.getDate();
    formattedDate = month + '/' + day + '/' + year;
	
	daylist_out.value=day;
	monthlist_out.value=month;
	yearlist_out.value=year;
	
	}
	
}

function Check_ava(day,month,year,day_out,month_out,year_out,cday11,cmonth11,cyear11,Check_Var,Wrong_Date)
{
	
	with(document.frmweek)
	{
		
		if(day<10)
		{
			day="0"+day;
		}
		if(day_out<10)
		{
			day_out="0"+day_out;
		}
		if(cday1<10)
		{
			cday1="0"+cday1;
		}
		
		checkin_date=day+"-"+month+"-"+year;
		checkout_date=day_out+"-"+month_out+"-"+year_out;
		select_date=cday11+"-"+cmonth11+"-"+cyear11;//cday1+"-"+cmonth1+"-"+cyear1;
		
		dt1=getDateObject(checkin_date,"-");
		dt2=getDateObject(checkout_date,"-");
		dt3=getDateObject(select_date,"-");
		/*alert(checkin_date);
		alert(checkout_date);*/
		
		var one_day=1000*60*60*24;

		diff=Math.ceil((dt2.getTime()-dt1.getTime())/(one_day));
		
		
		
		if(dt1>dt2)
		{		
			alert(Check_Var);
			return false;
		}
		else if(checkin_date==checkout_date)
		{	
			alert(Check_Var);
			return false;
		}
		else if(dt1<dt3)
		{
			//alert(L_Proper_Arrival_Date);
			alert("Reservation can be accepted after three days from current date.\n So Please Select Correct Check in & Check Out Date.");
			return false;
		}
		else
		{	
			Submit.value = "Check Availability";
			flag=Show_Room(day+'-'+month+"-"+year,day_out+"-"+month_out+"-"+year_out,Check_Var,Wrong_Date);
		}
	}
}


function Show_Room(Adate,Ddate,Check_Var,Wrong_Date)
{
	Stamp = new Date();
	with(document.frmweek)
	{
		var cdate="",cyear,cmonth="";
		var fulldate="";
		cmonth=Stamp.getMonth()+1;
		cdate=Stamp.getDate();
		if(cmonth<10)
		{
			cmonth="0"+cmonth;
		}
		if(cdate<10)
		{
			cdate="0"+cdate;
		}
		fulldate=cdate+"-"+cmonth+"-"+Stamp.getFullYear();
		dt1=getDateObject(Adate,"-");
		dt2=getDateObject(fulldate,"-");
		dt3=getDateObject(Ddate,"-");
		if(dt1<dt2)
		{		
			//alert(L_Proper_Arrival_Date);
			alert(Check_Var);
			return false;
		}
		else if(dt1>dt3)
		{
			//alert(L_Proper_Arrival_Date);
			alert(Check_Var);
			return false;
		}
		else
		{
			Action.value="Show_Room";
			submit();
		}
	}
}

//check ava diaplay
function Check_Ava_Display()
{
	
	with(document.frmweek)
	{ 
window.open("http://www.ezeereservation.com/rez/thepalmskamala/avaibility.php?Action=Avaibility&hotelid=18","","width=950,height=400"); 
	}
}