// JavaScript Document
function DigitsOnly(objval) {
	var ValidChars = "0123456789";
	for (j = 0; j<objval.length; j++) {
		var Char = objval.charAt(j);
		if (ValidChars.indexOf(Char) == -1) {
			return  false;
		}
	}
	return true;
}
function isDate(txtDate,dateopt){  
	var objDate;  // date object initialized from the txtDate string  
	var mSeconds; // milliseconds from txtDate  
	// date length should be 10 characters - no more, no less  
	if (txtDate.length != 10) return false;  
	// extract day, month and year from the txtDate string  
	// expected format is mm/dd/yyyy  
	// subtraction will cast variables to integer implicitly  
	var day   = txtDate.substring(3,5)  - 0;  
	var month = txtDate.substring(0,2)  - 1; // because months in JS start with 0  
	var year  = txtDate.substring(6,10) - 0;  
	// third and sixth character should be /  
	if (txtDate.substring(2,3) != '/') return false;  
	if (txtDate.substring(5,6) != '/') return false;  
	// test year range  
	if (year < 2009 || year > 3000) return false;  
	// convert txtDate to the milliseconds  
	mSeconds = (new Date(year, month, day)).getTime();  
	var date3 = new Date();
  	var todaymsec = (new Date(date3.getFullYear(), date3.getMonth(), date3.getDay())).getTime();
   	objDate = new Date();  
	objDate.setTime(mSeconds);  
	var todaydate=new Date();
	
	// if there exists difference then date isn't valid
	if(todaydate.getFullYear()>year) {
		return false;
	}
	if(todaydate.getFullYear()==year && todaydate.getMonth()>month) {
		return false;
	}
	if(todaydate.getFullYear()==year && todaydate.getMonth()== month && todaydate.getDate()>day) {
		return false;
	}	  
	
	if(todaymsec>mSeconds) {
		return false;
	}
	if(dateopt=="checkout") {
		fromdateval=document.getElementById('txt_checkin').value;
		fromday=fromdateval.substring(3,5)  - 0;
		frommonth=fromdateval.substring(0,2)  - 1;
		fromyear=fromdateval.substring(6,10) - 0;
		fromsec=(new Date(fromyear, frommonth, fromday)).getTime();
		if(fromsec>mSeconds) {
			return false;
		}
	}
	// set the date object from milliseconds  
	/*objDate = new Date();  
	objDate.setTime(mSeconds);  
	// if there exists difference then date isn't valid  
	if (objDate.getFullYear() != year)  return false;  
	if (objDate.getMonth()    != month) return false;  
	if (objDate.getDate()     != day)   return false;  */
	// otherwise return true  
	return true;
}  
function chk_reservation(frm) {
	if(Trim(frm.txt_name.value)=="") {
		alert("Please enter the Name.");
		frm.txt_name.focus();
		return false;
	}
	else if(Trim(frm.txt_street.value)=="") {
		alert("Please enter the Street.");
		frm.txt_street.focus();
		return false;
	}
	else if(Trim(frm.txt_city.value)=="") {
		alert("Please enter the City.");
		frm.txt_city.focus();
		return false;
	}
	else if(Trim(frm.txt_state.value)=="") {
		alert("Please enter the State.");
		frm.txt_state.focus();
		return false;
	}
	else if(Trim(frm.txt_country.value)=="") {
		alert("Please enter the Country.");
		frm.txt_country.focus();
		return false;
	}
	else if(Trim(frm.txt_email.value)=="") {
		alert("Please enter the Email.");
		frm.txt_email.focus();
		return false;
	}
	else if(!checkValidEmail(Trim(frm.txt_email.value))) {
		alert("Please enter the Valid Email.");
		frm.txt_email.focus();
		return false;
	}
	else if(Trim(frm.txt_mobile.value)=="") {
		alert("Please enter the Mobile.");		
		frm.txt_mobile.focus();
		return false;
	}
	else if((frm.txt_mobile.value).length<5) {
		alert("Please enter valid Mobile number.");		
		frm.txt_mobile.focus();
		return false;
	}
	else if(Trim(frm.txt_checkin.value)=="") {
		alert("Please enter the Checkin date.");
		frm.txt_checkin.focus();
		return false;
	}
	else if(!isDate(Trim(frm.txt_checkin.value),'checkin'))  {
		alert("Please enter valid Checkin date.");
		return false;	
	}
	else if(Trim(frm.txt_checkout.value)=="") {
		alert("Please enter the Checkout date.");
		frm.txt_checkout.focus();
		return false;
	}
	else if(!isDate(Trim(frm.txt_checkout.value),'checkout'))  {
		alert("Please enter valid Checkout date.");
		return false;	
	} 
	/*else if(Trim(frm.sel_brtype.value)=="") {
		alert("Please select the BR type.");
		frm.sel_brtype.focus();
		return false;
	}*/
	else
	{
		convertcurrency(frm.txt_name.value,frm.sel_brtype.value,frm.txt_email.value,frm.txt_checkin.value,frm.txt_checkout.value,frm.txt_adults.value,frm.txt_children.value,frm.txt_mobile.value);
		return false;	
	}
	return true;
}
function Trim(s) {
  // Remove leading spaces and carriage returns
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }

  // Remove trailing spaces and carriage returns

  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}
function checkValidEmail(email)
{
	if(email!= ""){
		if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))) {
			return false;
		}
		return true;
	}
}
function chk_Testimonial(frm) {
	if(frm.txt_username.value=="") {
		alert("Please enter name");
	   	frm.txt_username.focus();
	   	return false;
	}
	if(Trim(frm.txt_email.value)=="") {
		alert("Please enter the Email.");
		frm.txt_email.focus();
		return false;
	} 
	if(!checkValidEmail(Trim(frm.txt_email.value))) {
		alert("Please enter the Valid Email.");
		frm.txt_email.focus();
		return false;
	}
	if(frm.txta_feedback.value=="") {
		alert("Please enter the feedback");
	   	frm.txta_feedback.focus();
	   	return false;
	}	
}