// 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(checkin_date,checkout_date,cday11,cmonth11,cyear11,Check_Var,Wrong_Date)//,hotel_msg,room_msg)
{
	with(document.frmweek)
	{
		
		 var checkin=checkin_date.split('-');
		 var checkout=checkout_date.split('-');
		
		// date1=checkin[1]+'-'+checkin[0]+'-'+checkin[2];
		// date2=checkout[1]+'-'+checkout[0]+'-'+checkout[2];
		
		
		 date1=checkin[0]+'-'+checkin[1]+'-'+checkin[2];
		 date2=checkout[0]+'-'+checkout[1]+'-'+checkout[2];
		 select_date=cday11+"-"+cmonth11+"-"+cyear11;//cday1+"-"+cmonth1+"-"+cyear1;
		
		dt1=getDateObject(date1,"-");
		dt2=getDateObject(date2,"-");
		dt3=getDateObject(select_date,"-");
				
		/*if((checkin_date=='DD-MM-YYYY' ||  checkout_date=='DD-MM-YYYY') || (checkin_date=='' ||  checkout_date==''))
		{
			
			alert(Check_Var);
			return false;
		}
		else if(date1 > date2)
		{
			alert(Check_Var);
			return false;
		}
		else if(checkin_date==checkout_date)
		{
			alert("Check In & Check Out date can not be same.");	
			return false;
		}*/
		if((checkin_date=='MM-DD-YYYY' ||  checkout_date=='MM-DD-YYYY') || (checkin_date=='' ||  checkout_date==''))
		{
			alert(Check_Var);
			return false;
		}
		else if(dt1>dt2)
		{		
			alert("Please, Select Correct Check in & Check out Date.");
			return false;
		}
		else if(checkin_date==checkout_date)
		{
			alert("Check In & Check Out date can not be same.");	
			return false;
		}
		else if(dt1<dt3)
		{
			//alert(L_Proper_Arrival_Date);
			alert("Please, Select Correct Check in & Check out Date.");
			return false;
		}
	 	else
		{		
			Submit.value = "Check Availability";
			flag=Show_Room(checkin_date,checkout_date,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)
	{
		
			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/econoinn/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();
		
	}
}





