// JavaScript Document
//====================================================================================================
//	File Name		:	reservation.js
//----------------------------------------------------------------------------------------------------
//	Purpose			:	validation in JavaScript.

function adddate(day,month,year,frm,cval2)
{
	with(frm)
	{

	day   = parseInt(day) + 1;
	var monthc=month;
	
	if(cval2=='M' || cval2=='Y' || cval2=='D')
		month = parseInt(monthc)-1;
	else	
		month = parseInt(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 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 Check_ava(day,month,year,day_out,month_out,year_out,cday11,cmonth11,cyear11,Check_Var,Wrong_Date)
{
	
	with(document.frmweek)
	{
		//alert("asdasd");
	
		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,"-");
		
		var one_day=1000*60*60*24;


		var diff=Math.ceil((dt2.getTime()-dt1.getTime())/(one_day));
		
		
		
		//return false;
		if(dt1>dt2)
		{		
			alert(Check_Var);
			return false;
		}
		else if(checkin_date==checkout_date)
		{	
			alert(Check_Var);
			return false;
		}
		else if(dt1<dt3)
		{
			alert(Check_Var);
			return false;
		}
		/*else if(select_hotel.value==0)
		{
			alert(Check_var1.value);
			return false;
		}*/
		else
		{	
			//alert("dfsdf");
			//return false;
			Submit.value = "Check Availability";
			flag=Show_Room(day+'-'+month+"-"+year,day_out+"-"+month_out+"-"+year_out,Check_Var,Wrong_Date);
		}
	}
}

function allDigits(str)
{
	
	return inValidCharSet(str,"0123456789");
}

function inValidCharSet(str,charset)
{
	var result = true;
	var strLen = str.length;
	for (var i=0;i<str.length;i++)
		if (charset.indexOf(str.substr(i,1))<0)
		{
			result = false;
			break;
		}
	return result;
}


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,"-");
		//alert("asdasd");
		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();
		}
	}
}

function Change_Month(Month)
{ 
	 with(document.frmweek)
	 {
		 selected_month.value = Month;
		 submit();
	 } 
}
function Change_Year(Year)
{	
	 with(document.frmweek)
	 {
		  selected_year.value = Year;
		  submit();
	 } 
}
function New_Search()
{
	 with(document.frmweek)
	 {
		Action.value='Reset';
		submit();
	 	
	 }
}

function IsValidInteger(fld,msg)
{
	var regex = /^[0-9]*$/;
	if(!regex.test(fld.value))
	{
		alert(msg);
		fld.focus();
		return false;
	}
	return true;
}


function Check_Ava_Display(hotelid2)
{
	
	with(document.frmweek)
	{ 
	
		//alert(hotelid);
		//SubmitCheck.value = "Availability";
		//selected_month.value = monthlist.value;
		//popupWindowURL("http://www.ezeereservation.com/rez/chariot/avaibility.php?Action=Avaibility&hotelid="+hotelid2, 'PageContent', 900, 400, false, false, true);
		
		window.open ("http://www.ezeereservation.com/rez/riverview/avaibility.php?Action=Avaibility&hotelid="+hotelid2,"Availability","menubar=0,resizable=1,width=900,height=400");
		//popupWindowURL("avaibility.php?room_id="+Room_Id+"&Action=View_Gallary&total="+Total, 'PageContent', 650, 500, false, false, true);
		//submit();
		
	}
}
