/***************************************************************************
This function ensures that date from the Input box is parsed to a Java Date Object.
*****************************************************************************/

function ParseDate(dateString)
{
    //Date is in the format of mm/dd/yyyy pulled from textbox.
   date = new Date(dateString)
   return date;
}
/*******************************************************************************
This function ensures that the users select a start date which is less than end date
*********************************************************************************/

function ValidateDate1(startDateStr, endDateStr)
{
	var arrStartDate = startDateStr.split("/");
	var arrEndDate = endDateStr.split("/");
	
	newStartDateStr = arrStartDate[1]+"/"+arrStartDate[0]+"/"+arrStartDate[2];
	newEndDateStr = arrEndDate[1]+"/"+arrEndDate[0]+"/"+arrEndDate[2];
	
   startDate = ParseDate(newStartDateStr);
   endDate = ParseDate(newEndDateStr);

   //alert(startDate.toString()); //here is the error - when it convert to a string it is returning funny values.
   //alert(startDate.getDate());
   if (endDate < startDate) {
     alert("Start Date should be less than End Date");
   }
   //else
   //  alert("Bad");
}

function ValidateDate(startDateStr, endDateStr)
{
   //note the absence of the ParseDate function
   //and it's still about the same amount of typing
   
   var arrStartDate = startDateStr.split("-");
	var arrEndDate = endDateStr.split("-");
	
	newStartDateStr = arrStartDate[1]+"/"+arrStartDate[0]+"/"+arrStartDate[2];
	newEndDateStr = arrEndDate[1]+"/"+arrEndDate[0]+"/"+arrEndDate[2];
	
   startDate = ParseDate(newStartDateStr);
   endDate = ParseDate(newEndDateStr);

   todayDate = new Date();
   
   
   if (todayDate.getTime() > startDate.getTime()) {	
    alert("Check-In date must be tomorrow onwards!");
	
	 return false;
   }else if (endDate.getTime() <= startDate.getTime()) {
     alert("Check Out date must be day after Check-In date!");
	 return false;
   }else{
	return true;
   }
}
function ValidateDateBooking(startDateStr)
{
   var arrStartDate = startDateStr.split("/");
	 
	
	newStartDateStr = arrStartDate[1]+"/"+arrStartDate[0]+"/"+arrStartDate[2];
	 
	
   startDate = ParseDate(newStartDateStr);
   //OR
   //startDate = new Date(startDateStr);
   //AS PARSE DATE DOES THE SAME THING
   //i.e, CREATION OF DATE OBJECT
   
   //note the absence of the ParseDate function
   //and it's still about the same amount of typing
   
   todayDate = new Date();
   
  // alert("now time="+todayDate);
   //alert("startdate time="+startDate);
   if (todayDate.getTime() > startDate.getTime()) {	
    alert("Start Date should not be past date");
	
	 return false;
   }else{
	return true;
   }
}

function getTheDay()

{

	myDays = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
		
	var fromdate = document.searchform.fromdate.value;
	var arrFromDate = 	fromdate.split("/");
	var strFromDate = arrFromDate[1]+"/"+arrFromDate[0]+"/"+arrFromDate[2];
	myDate=new Date(eval('"'+strFromDate+'"'))
		 
	//var thisDay = myDays[myDate.getDay()]
	var thisDay = myDays[document.searchform.hidDay.value]
	if(document.searchform.hidDay.value== myDate.getDay()){	
		return true;
	}else{
		alert("Please select "+ thisDay+".");
		return false;
	}	
}

//TO VALIDATE THE FORM

function check(frm){
		if(frm.fromdate.value==""){
			alert("Please enter from date!");
			return false;
		}	
		if(frm.todate.value==""){
			alert("Please enter to date!");
			return false;
		}
		if(!ValidateDate(frm.fromdate.value, frm.todate.value)){
			return false;
		}
		return true;
	}