function trim(s)
{   var i;
	var returnString = "";
	for (i = 0; i < s.length; i++)
	{   
		var c = s.charAt(i);
		if (c != " ") returnString += c;
	}
	return returnString;
}

function chkform()
{
		var arrival = document.getElementById('arrival').value;
		var departure = document.getElementById('departure').value;
		var city = document.getElementById('city').value;
		var people =document.getElementById('people').value;
		
		

	    if(compareDates(arrival, departure)== false)
		{
		return false;
		}
	    var dateRegEx = /^([0123]?\d)[\.\-\/\s]?([01]?\d)[\.\-\/\s]?(\d{4})$/;
		var result1 = arrival.match(dateRegEx);
		var result2 = departure.match(dateRegEx);
	
	
	
		if(arrival == '')	
		{
			alert( "Please Enter The Date Of Arrival Or CheckIn.");
			document.frm.arrival.focus();
			return false;
		}	
		
		if(departure == '')	
		{
			alert( "Please Enter The Date Of departure Or Check Out.");
			document.frm.departure.focus();
			return false;
		}
		
		if(arrival!=''){
		
			var arrday = result1[1];
			var arrmonth = result1[2];
			var depmonth = result2[2];
			var arryear = result1[3];	
			var depyear = result2[3];	
			var depday = result2[1];
			
			
			if(arryear<=depyear){
			
			if(arrmonth==depmonth){
				
					if((depday - arrday < 3))
					{
							alert('Mininum stay is 3 days');							
							document.frm.arrival.focus();
							return false;
					}
				}
			}
			
			if(arryear==depyear){			
				if(arrmonth>depmonth){					
					alert("Arrival month should not be greater than departure month");
					document.frm.arrival.focus();
					return false;
					
				}
			}
			
			if(arryear>depyear){
								
				alert("Arrival year should not be greater than departure year");
				document.frm.arrival.focus();
				return false;
				
			}
			
			
			HoldDate=new Date();
			var to_day = HoldDate.getDate(); 
			var to_month = (HoldDate.getMonth()+1);
			var to_year = HoldDate.getYear();
	
			
		}
		
		
		if(city == '-1')	
		{
			alert("Please specify destination.");
			document.frm.city.focus();
			return false;
		}
		if(people == '-1')	
		{
			alert("Please specify number of guests.");
			document.frm.people.focus();
			return false;
		}
		
		if(result1 == null){
		alert("Please Enter The Correct Format Of Date In 'dd-mm-yyyy'");
		document.frm.arrival.focus();
		 return false;	
		}
		
		if(result2 == null){
		alert("Please Enter The Correct Format Of Date In 'dd-mm-yyyy' Of departure.");
		document.frm.departure.focus();
		return false	
		}
	
}

function compareDates(dt1, dt2){
	
		var dateRegEx = /^([0123]?\d)[\.\-\/\s]?([01]?\d)[\.\-\/\s]?(\d{4})$/;
		var result1 = dt1.match(dateRegEx);
		var result2 = dt2.match(dateRegEx);	
	    if(result1 && result2)
		{
		var arrday = result1[1];
		var arrmonth = result1[2];
		var arryear = result1[3];	
		var depday = result2[1];
	    var depmonth = result2[2];
	    var depyear = result2[3];
		var dif = 0;
		dif += (depmonth - arrmonth);		
		dif += ((depyear - arryear) * 12);	
		
		if((depday - arrday < 0) && (dif <= 0)){		
		
			alert("The Date Of Departure Must Be Date after 3 days of Arrival.");
			document.frm.arrival.focus();
			return false;
		
		}
		
	}
}


function checkDate() 
	{	
		var arrival_val 		= document.getElementById('arrival').value;
		var mySplitResult 		= arrival_val.split(".");
		var mySplitResultDay 	= mySplitResult[0];
		var mySplitResultMonth 	= mySplitResult[1];
		var mySplitResultYear 	= mySplitResult[2];
		var mySplitResultMonth 	= parseInt(mySplitResultMonth - 1);		
		
		var currentDate = new Date();
		var currentDateWithoutTime = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate()).format('dd.MM.yyyy');
		var currentDateWithoutTimeDep = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate()+3).format('dd.MM.yyyy');				
		
		var myDate=new Date();
		myDate.setFullYear(mySplitResultYear,mySplitResultMonth,mySplitResultDay);
		var today = new Date();
				
		if (myDate<today)
		  {
		    var newValtest = new Date(mySplitResultYear, mySplitResultMonth, mySplitResultDay).format('dd.MM.yyyy');
			//alert('Select a date after three days of arrival date');
			//------------Code Written by Imtiyaz----------------
			alert('Select a date after Current date');
			//---------End of IMTIYAZ Coding---------------------
			document.getElementById('arrival').value  =  currentDateWithoutTime;
			document.getElementById('departure').value  =  currentDateWithoutTimeDep; 
			return false;
		  }
		else
		  {
		 	mySplitResultDay = parseInt(mySplitResultDay, 10) + 3;	
			var newVal = new Date(mySplitResultYear, mySplitResultMonth, mySplitResultDay).format('dd.MM.yyyy');			
			document.getElementById('departure').value  =  newVal;
			return false;
		  }
	}
	
	function checkOutDate() 
	{	
		var departure_val 		= document.getElementById('departure').value;
		var mySplitResult 		= departure_val.split(".");
		var mySplitResultDay 	= mySplitResult[0];
		var mySplitResultMonth 	= mySplitResult[1];
		var mySplitResultYear 	= mySplitResult[2];
		var mySplitResultMonth 	= parseInt(mySplitResultMonth - 1);
		
		
		var arrival_val 			= document.getElementById('arrival').value;
		var mySplitResult1 			= arrival_val.split(".");
		var mySplitResultDay1 		= mySplitResult1[0];
		var mySplitResultMonth1 	= mySplitResult1[1];
		var mySplitResultYear1 		= mySplitResult1[2];
		var mySplitResultMonth1 	= parseInt(mySplitResultMonth1 - 1);	
		var mySplitResultDay1 		= parseInt(mySplitResultDay1, 10) + 3;
		
		var currentDate = new Date();
		var currentDateWithoutTimeDep = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate()+3).format('dd.MM.yyyy');	
				
		
		var myDate=new Date();
		var newDate=new Date();
		myDate.setFullYear(mySplitResultYear, mySplitResultMonth, mySplitResultDay);
		newDate.setFullYear(mySplitResultYear1, mySplitResultMonth1, mySplitResultDay1);
		var today = new Date();
				
		
		  
		  if (myDate<newDate)
		  {
		    var newValtest = new Date(mySplitResultYear1, mySplitResultMonth1, mySplitResultDay1).format('dd.MM.yyyy');
			alert('Select a date after three days of arrival date');		
			document.getElementById('departure').value  =  newValtest; 
			return false;
		  }
		 //---------Code Written by IMTIYAZ---------------------------------
		   if (myDate<today)
		  {
			alert('Select a date after three days of arrival date');
			document.getElementById('departure').value  =  currentDateWithoutTimeDep; 
			return false;
		  }
		  //--------------End of Code written by IMTIYAZ-----------------------
	}

