
function nxtdate(x){
	if(x!=""){
		var xarray = x.split("/")
		var xdate = new Date(xarray[2] , xarray[1], xarray[0]);
		xdate.setDate(xdate.getDate()+1);
		x1=xdate.getMonth();
		if (String(x1).length==1){
			x1="0"+x1;
		}
		x2=xdate.getDate();
		if (String(x2).length==1){
			x2="0"+x2;
		}
		document.frm.dep_date.value=x2+"/"+x1+"/"+xdate.getYear();
	}
}
	
function chkname(x){
	var y = eval("document.frm.id"+x);
	document.frm.regCode.value=y.value;
	var z = eval("document.frm.nm"+x);
	document.frm.hotelname.value=z.value;
}
function getfares(){
	var dt=true;
	reslink = "http://www.resavenue.com/servlet/checkAvailable.resBookings?regCode="+ document.frm.regCode.value+"&showPkg=Y"
	str = document.frm.txtdeptDateRtrip.value
	if(ValDate(str)){
		adt = new Date(str.substring(6, 10), str.substring(3, 5)-1, str.substring(0, 2));
		reslink = reslink+"&arr_date="+str.substring(0, 2)+str.substring(3, 5)+ str.substring(6, 10);
	}else{
		dt=false;
	}

	str = document.frm.txtretnDateRtrip.value
	if(ValDate(str)){
		ddt = new Date(str.substring(6, 10), str.substring(3, 5)-1, str.substring(0, 2));
		reslink = reslink+"&dep_date="+str.substring(0, 2)+str.substring(3, 5)+ str.substring(6, 10);
	}else{
		dt=false;
	}
	if(dt==true){
		todt = new Date();
		//alert(todt+""+adt+" "+ddt);
		if ((adt>todt) && (ddt>=adt)){
			reslink = reslink+"&curr=INR&roomno=1"
			window.open(reslink);
		}else{
			alert("Invalid Dates!\n\nPlease check the rooms availability only for the future dates");
		}
	}
}

function ValDate(str) 
{
   len = str.length;
   if(len != 10) 
   {
     alert( "Value must be a date in DD/MM/YYYY format.");
     return false;
   }
   else
   {
	   var monthdays = 30 ;
	   var strday = str.substring(0, 2);
	   var strmonth = str.substring(3, 5);
	   var stryear = str.substring(6, 10);

	   if( isNaN(strday) || (strday < 0) || isNaN(stryear) || (stryear < 0) || isNaN(strmonth) || (strmonth < 0)) 
	   {
			//alert(strday+strmonth+stryear);
			alert( "Value must be a valid date in DD/MM/YYYY format.");
			return false;
	   }

	   //  valid month and set maximum days for that month.

	   if((strmonth== 1) || (strmonth == 3) || (strmonth == 5) || (strmonth == 7) || (strmonth == 8) || (strmonth == 10) ||(strmonth == 12)) 
	   { 
		   monthdays = 31;
	   } 
	   else if( (strmonth == 4) || (strmonth == 6) || (strmonth == 9) ||(strmonth == 11) ) 
	   { 
			monthdays = 30;
	   }
	   else if(strmonth == 2) 
	   {
			monthdays = ((stryear % 4) == 0) ? 29 : 28;
	   }
	   else 
	   {
			  //alert(strday+strmonth+stryear);
			  alert( "Value must be a date in DD/MM/YYYY format.");
			  return false;
	   }
	   if(strday > monthdays) 
	   {
			 alert( "Value must be a date in DD/MM/YYYY format.");
			 return false;
	   }
	   return true;
	}
}