var msgStr = "Oops! It seems that the form has been completed improperly:\n\n";
var valid = true;

function form_validate_dates(ArrivalDate,DepartureDate){
  if(validateFormatDate(ArrivalDate) && validateFormatDate(DepartureDate)){
    if(DateGreatherToday(ArrivalDate)){
      if(!validateDates(ArrivalDate,DepartureDate)){
        msgStr += " - The departure date should be later than the arrival date\n";
        valid = false;
      }
    }
    //else{
    //  msgStr += " - The arrival date should be in the future\n";
    //  valid = false;
    //}
    if(validateDaysbetweenDates(ArrivalDate,DepartureDate)>366){
      msgStr += " - The stay should be one year or less\n";
      valid = false;
    }
  }
  else {
    msgStr += " - Please enter your travel dates 'mm/dd/yyyy' \n";
    valid = false;
  }

}
function form_validate_dates_for_reports(FromDate,ToDate){
  if(validateFormatDate(FromDate) && validateFormatDate(ToDate)){
    if(!DateGreatherToday(FromDate) && !DateGreatherToday(ToDate)){
      if(!validateDates(FromDate,ToDate)){
        msgStr += " - The first date should be later than the second date\n";
        valid = false;
      }
    }
    else{
      msgStr += " - The dates should be in the past\n";
      valid = false;
    }
    if(validateDaysbetweenDates(FromDate,ToDate)>9){
      msgStr += " - The period should be no greater than 9 days\n";
      valid = false;
    }
  }
  else {
    msgStr += " - The format of the first/second date is not correct\n";
    valid = false;
  }

}

function form_validate_name(Name){
  if(!validateBlank(Name)){
    msgStr += " - Please provide us with your name\n";
    valid = false;
  }
}

function form_validate_GENERAL(field){
  if(!validateBlank(field)){
    msgStr += " - Please provide us with your "+field.name+"\n";
    valid = false;
  }
}

function form_validate_email(Email){
  if(!validateBlank(Email)){
    msgStr += " - Please provide us with your email\n";
    valid = false;
  }
  else{
    if(!validateEmail(Email)){
      msgStr += " - Email addres doesn't seem to be valid\n";
      valid = false;
    }
  }
}

function form_validate_phone(Phone){
  //Phone.value = "hola4";
  if(validateBlank(Phone) && !validatePhone(Phone)){
    msgStr += " - Please enter a valid phone number\n";
    valid = false;
  }
}

function form_validate_phoneObligatory(Phone){
  //Phone.value = "hola4";
  if(!validatePhone(Phone)){
    msgStr += " - Please enter a valid phone number\n";
    valid = false;
  }
}

function form_validate_AgentCertified(AgentCertified){
  if(!AgentCertified.checked){
    msgStr += " - Your must be a certified travel agent in order to submit an inquiry as a travel agent. If you are not a travel agent, please uncheck the \"I am a certified travel agent\" option.\n";
    valid = false;
  }
}

function form_validate_TravelerPassword(TravelerPassword,ConfirmPassword){
  if(!validateBlank(TravelerPassword)){
    msgStr += " - Please select a Password\n";
    valid = false;
  }
  else{
    if(TravelerPassword.value != ConfirmPassword.value){
      msgStr += " - Password diferent of Confirm password try again\n";
      valid = false;
    }
  }
}


function validateBasicSearchForm() {
  var ArrivalDate = document.getElementById("InquiryArrival");
  var DepartureDate = document.getElementById("InquiryDeparture");

  msgStr = "Oops! It seems that the form has been completed improperly:\n\n";
  valid = true;

  form_validate_dates(ArrivalDate,DepartureDate);
  if(!valid){
    alert(msgStr);
    return false;
  }
  return valid;
}

function validateInquiryPrivateForm() {
  var Name = document.getElementById("Name");
  var ArrivalDate = document.getElementById("InquiryArrival");
  var DepartureDate = document.getElementById("InquiryDeparture");
  var Email = document.getElementById("Email");
  var Phone = document.getElementById("Phone");
  msgStr = "Oops! It seems that the form has been completed improperly:\n\n";
  valid = true;

  form_validate_name(Name);
  form_validate_email(Email);
  form_validate_phone(Phone);
  form_validate_dates(ArrivalDate,DepartureDate);
  
  if(!valid){
    alert(msgStr);
    return false;
  }
  return confirm("To submit your inquiry, please verify that the information is correct and then click 'OK'.");
}

function validateContactInfoForm(type) {
  var Name = document.getElementById("Name");
  var ArrivalDate = document.getElementById("InquiryArrival");
  var DepartureDate = document.getElementById("InquiryDeparture");
  var Email = document.getElementById("Email");
  var Phone = document.getElementById("Phone");
  var Message = document.getElementById("Commentsid");
  var countryCodePhone = document.getElementById("countryCodePhone");
  var captchaCode = document.getElementById('vcode');
  
  msgStr = "Oops! It seems that the form has been completed improperly:\n\n";
  valid = true;

  form_validate_name(Name);
  if( type == 'requestcall' || type == 'call' || type == 'email') {
	if(!validateBlank(Phone) || !validatePhoneSevenInt(Phone)){
		msgStr += " - Please enter a valid phone number\n";
		valid = false;
	}	
    if(!validateEmail(Email)){
      msgStr += " - Email addres doesn't seem to be valid\n";
      valid = false;
    }
  /*} else if( type == 'call' ) {
    if(Email.value != '' && !validateEmail(Email)){
      msgStr += " - Email addres doesn't seem to be valid\n";
      valid = false;
    }
	form_validate_phone(Phone);
	*/
  } else {
	form_validate_email(Email);
	form_validate_phone(Phone);
  }
  if ( type == 'email' || type == 'requestcall' ) {
	form_validate_dates(ArrivalDate,DepartureDate);
  }
  if ((type == 'call' || type == 'email' || type == 'requestcall') && countryCodePhone.value == 0){
      msgStr += " - Please Select country (Country Code) \n";
      valid = false;
  }
  
  if(isset(Message)){
  	if(!validateNotAllow(Message.value)){

			msgStr += " - The Message field shouldn't contain a phone, url or email \n";
    		valid = false;
	}
  }
  
  if(captchaCode!=null){
  	if(!validateBlank(captchaCode)){
		msgStr += " - Please enter the letters as they are shown in the image\n";
		valid = false; 
	}
  }		
  
  if(!valid){
    alert(msgStr);
    return false;
  }
  
  return confirm("To submit your inquiry, please verify that the information is correct and then click 'OK'.");
}


function isset(variable_name) {
    try {
         if (typeof(eval(variable_name)) != 'undefined')
         if (eval(variable_name) != null)
         return true;
     } catch(e) { }
    return false;
   }




function UPvalidateContactInfoForm(type) {
  var Name = document.getElementById("UPName");
  var ArrivalDate = document.getElementById("UPInquiryArrival");
  var DepartureDate = document.getElementById("UPInquiryDeparture");
  var Email = document.getElementById("UPEmail");
  var Phone = document.getElementById("UPPhone");
  var Message = document.getElementById("UPCommentsid");
  var countryCodePhone = document.getElementById("UPcountryCodePhone");
  var captchaCode = document.getElementById('UPvcode');
  
  
  var control = undefined;
	
	try {
		control = document.getElementById("controlID");
		
	}catch(e) { }
	
	
  
  
  
  msgStr = "Oops! It seems that the form has been completed improperly:\n\n";
  valid = true;

  form_validate_name(Name);
  if( type == 'requestcall' || type == 'call' || type == 'email') {
	if(!validateBlank(Phone) || !validatePhoneSevenInt(Phone)){
		msgStr += " - Please enter a valid phone number\n";
		valid = false;
	}	
    if(!validateEmail(Email)){
      msgStr += " - Email addres doesn't seem to be valid\n";
      valid = false;
    }
  /*} else if( type == 'call' ) {
    if(Email.value != '' && !validateEmail(Email)){
      msgStr += " - Email addres doesn't seem to be valid\n";
      valid = false;
    }
	form_validate_phone(Phone);
	*/
  } else {
	form_validate_email(Email);
	form_validate_phone(Phone);
  }
  if ( type == 'email' || type == 'requestcall' ) {
	form_validate_dates(ArrivalDate,DepartureDate);
  }
  if ((type == 'call' || type == 'email' || type == 'requestcall') && countryCodePhone.value == 0){
      msgStr += " - Please Select country (Country Code) \n";
      valid = false;
  }
  
  
  if(captchaCode!=null){
  	if(!validateBlank(captchaCode) || captchaCode.value == 'Enter code'){
		msgStr += " - Please enter the letters as they are shown in the image\n";
		valid = false; 
	}
  }
  
  if(isset(Message)){
  	if(!validateNotAllow(Message.value)){

			msgStr += " - The Message field shouldn't contain a phone, url or email \n";
    		valid = false;
	}
  }
  
  
  if(isset(control)){
  	if(control.value == 0){
  		msgStr += " - Please modify your dates.\n";
		valid = false; 
  	}else if(control.value == 5 ){
  		msgStr = " - Wait, Calculating Price ...\n";
		valid = false;
  	}
  }
  
  		
  
  if(!valid){
    alert(msgStr);
    return false;
  }
  
 // return confirm("To submit your inquiry, please verify that the information is correct and then click 'OK'.");
 	return true;
}


function pricingEzBookme(){
	var ArrivalDate = document.getElementById("UPInquiryArrival");
  	var DepartureDate = document.getElementById("UPInquiryDeparture");
  	var Adults = document.getElementById("Adults");
  	var Children = document.getElementById("Children");
  	var PropertyID = document.getElementById("PropertyID");
  	
  	msgStr = '';
  	valid = true;
  	
  	if(!validateFormatDate(ArrivalDate) || !validateFormatDate(DepartureDate)){
  		return false;
  	}
  	
  	
  	form_validate_dates(ArrivalDate,DepartureDate);
  	
  	if(!valid){
  	    var textDate = 'your';
  	    if(msgStr.length > 1){
  	    	textDate = 'Correct';
  	    }
//    	alert(msgStr);
    	document.getElementById('pricingEzBookme').innerHTML = '<div class="spa-10"></div><div class="checks-10-3">Please Select ' + textDate + ' Dates <input name="controlID" id="controlID" type="hidden" value="0" /></div>';
    	return false;
  	}
  	
  	document.getElementById('pricingEzBookme').innerHTML = '<div class="spa-10"></div><div class="checks-10-3">Wait, Calculating Price ... <input name="controlID" id="controlID" type="hidden" value="5" /></div>';
  	var URL = 'http://rentalo.com/web/traveler/calculatePricing.cgi?PropertyID=' + PropertyID.value + '&ArrivalDate=' + ArrivalDate.value + '&DepartureDate=' + DepartureDate.value + '&Adults=' + Adults.value + '&Children=' + Children.value;

  	
  	new Ajax.Updater('pricingEzBookme',URL,{method: 'get'});
  	
  	return true;
}




function validateInquiryForm() {

  var Name = document.getElementById("Name"); 
  var ArrivalDate = document.getElementById("InquiryArrival");
  var DepartureDate = document.getElementById("InquiryDeparture");
  var Email = document.getElementById("Email");
  var Phone = document.getElementById("Phone");

  msgStr = "Oops! It seems that the form has been completed improperly:\n\n";
  valid = true;

  form_validate_name(Name);
  form_validate_email(Email);
  form_validate_phone(Phone);
  form_validate_dates(ArrivalDate,DepartureDate);
  if (document.getElementById("propFinderFlag") && document.inquiryForm[0]){
    var propertyTypes = document.inquiryForm[0].elements['PropertyTypeID'];
  } else {
    var propertyTypes = document.inquiryForm.elements['PropertyTypeID'];
  }
  var propertytypeselected = false;
  for(var i=0;i<propertyTypes.length;i++){
    if(propertyTypes[i].checked) propertytypeselected = true;
  }
  if(!propertytypeselected){
    msgStr += " - At least one property type should be selected\n";
    valid = false;
  }

  if(!valid){
    alert(msgStr);
    return false;
  } else { 
  	if(!verifyBudgetValue('Budget','MinimumBudget')){
  		return false;
  	}
  }
  
  return confirm("To submit your inquiry, please verify that the information is correct and then click 'OK'.");
}



function validateInquiryFormS1() {

    var ArrivalDate = document.getElementById("InquiryArrival");
  var DepartureDate = document.getElementById("InquiryDeparture");
  
  msgStr = "Oops! It seems that the form has been completed improperly:\n\n";
  valid = true;

 
  form_validate_dates(ArrivalDate,DepartureDate);
  var propertyTypes = document.inquiryForm.elements['PropertyTypeID'];
  
  var propertytypeselected = false;
  for(var i=0;i<propertyTypes.length;i++){
    if(propertyTypes[i].checked) propertytypeselected = true;
  }
  if(!propertytypeselected){
    msgStr += " - At least one property type should be selected\n";
    valid = false;
  }

  if(!valid){
    alert(msgStr);
    return false;
  } 
  
  return true;
}


function validateInquiryFormSi2() {

    var ArrivalDate = document.getElementById("inpInquiryArrival");
  var DepartureDate = document.getElementById("inpInquiryDeparture");
  
  msgStr = "Oops! It seems that the form has been completed improperly:\n\n";
  valid = true;

 
  form_validate_dates(ArrivalDate,DepartureDate);
  
  
 

  if(!valid){
    alert(msgStr);
    return false;
  } 
  
  return true;
}




function validateNotAllow(data){
		
			var email1 = /([\w\-\.]+)?\@([\w\-\.]+)?\.([a-zA-Z]{2,3}|aero|coop|info|museum|name)/;
			var url1 = /http/; // not url
			var url2 = /www\./; // not url
			
			
			
			if(email1.test(data)){
				return false;
			}
			
			if(url1.test(data) || url2.test(data)) {
	    		return false;
			}
			
			
			var phoneNumers = /\d/; // Numbers
			var simbolNumers = /\(|\)|\s|\-|\.|\+ /; // simbolNumbers
		  	var n=0;
		  	var sn=0;
		  	var valor;
		  	for(i=0;i<data.length;i++){
		  		valor = parseInt(data.charAt(i));
		  		if(phoneNumers.test(valor)){
		    	 	n++;
		    	 }else{
		    	 
		    	 	if(!(simbolNumers.test(data.charAt(i)))){
		    	 		n=0;
		    	 	}
		    	 	
		    	 }

		  	}
			

			if(n>=7){
	    		return false;
			}
			
			return true;		
	}




function validateInquiryFormS2() {

  var Name = document.getElementById("Name"); 
  var Email = document.getElementById("Email");
  var Phone = document.getElementById("Phone");
  var Message = document.getElementById("Commentsid");

  msgStr = "Oops! It seems that the form has been completed improperly:\n\n";
  valid = true;

  form_validate_name(Name);
  form_validate_email(Email);
  form_validate_phone(Phone);


  var contactPhone = document.getElementById("contactPhone");
  var contactEmail = document.getElementById("contactEmail");
  if(!contactPhone.checked && !contactEmail.checked){
  	msgStr += " - Please Select a Contact Preference.\n";
  	valid = false;
  }
   
  if(!validateNotAllow(Message.value)){

			msgStr += " - The Message field shouldn't contain a phone, url or email \n";
    		valid = false;
	}
  

  if(!valid){
    alert(msgStr);
    return false;
  } else { 
  	if(!verifyBudgetValue('Budget','MinimumBudget')){
  		return false;
  	}
  }
  
  
  
  return confirm("To submit your inquiry, please verify that the information is correct and then click 'OK'.");
}




function validateInquiryFormMPI(){

  var Name = document.getElementById("Name"); 
  var Email = document.getElementById("Email");
  var Phone = document.getElementById("Phone");
  var Message = document.getElementById("Commentsid");
  var countryCodePhone = document.getElementById("countryCodePhone");

  msgStr = "Oops! It seems that the form has been completed improperly:\n\n";
  valid = true;

  form_validate_name(Name);
  form_validate_email(Email);
  
  if(Phone.value != ''){
  	form_validate_phone(Phone);
  }else{
  	form_validate_GENERAL(Phone);
  }
  
  
  if(countryCodePhone.value == 0){
      msgStr += " - Please Select country (Country Code) \n";
      valid = false;
  }
  
  if(!validateNotAllow(Message.value)){

			msgStr += " - The Message field shouldn't contain a phone, url or email \n";
    		valid = false;
	}


  if(!valid){
    alert(msgStr);
    return false;
  } 
  
  return confirm("To submit your inquiry, please verify that the information is correct and then click 'OK'.");
}

// this script has been create for http://rentalo.com/i/add-your-site.html form
function validateFormConversions() {

  var Name = document.getElementById("Name"); 
  var Email = document.getElementById("Email");
  var Phone = document.getElementById("Phone");
  var Destination = document.getElementById("Destination");
  

  msgStr = "Oops! It seems that the form has been completed improperly:\n\n";
  valid = true;

  form_validate_name(Name);
  form_validate_email(Email);
  form_validate_phoneObligatory(Phone);
  form_validate_GENERAL(Destination);

  

  if(!valid){
    alert(msgStr);
    return false;
  } 
  
  return true;
}



// this script has been create for http://rentalo.com/owners.html
function validateFormOwnersConversions() {

  var Name = document.getElementById("Name"); 
  var Email = document.getElementById("Email2");
  var Phone = document.getElementById("Phone");
  var Destination = document.getElementById("Destination");
  

  msgStr = "Oops! It seems that the form has been completed improperly:\n\n";
  valid = true;

  form_validate_name(Name);
  form_validate_email(Email);
  form_validate_phoneObligatory(Phone);
  form_validate_GENERAL(Destination);

  

  if(!valid){
    alert(msgStr);
    return false;
  } 
  
  return true;
}



function sendInquiryForm(){
	if(validateInquiryForm()){
		document.inquiryForm.submit();
		return true;
	}
	return false;
}

function validateInquiryFormAgent() {
  var Name = document.getElementById("Name");
  var ArrivalDate = document.getElementById("InquiryArrival");
  var DepartureDate = document.getElementById("InquiryDeparture");
  var Phone = document.getElementById("Phone");
  
  msgStr = "Oops! It seems that the form has been completed improperly:\n\n";
  valid = true;

  form_validate_name(Name);
  form_validate_phone(Phone);
  form_validate_dates(ArrivalDate,DepartureDate);

  var propertyTypes = document.inquiryForm.elements['PropertyTypeID'];
  var propertytypeselected = false;
  for(var i=0;i<propertyTypes.length;i++){
    if(propertyTypes[i].checked) propertytypeselected = true;
  }
  if(!propertytypeselected){
    msgStr += " - At least one property type should be selected\n";
    valid = false;
  }

  if(!valid){
    alert(msgStr);
    return false;
  }
  return confirm("To submit your inquiry, please verify that the information is correct and then click 'OK'.");
}

function validateInquiryFormSingUpAgent() {
  var Name = document.getElementById("Name");
  var ArrivalDate = document.getElementById("InquiryArrival");
  var DepartureDate = document.getElementById("InquiryDeparture");
  var Email = document.getElementById("Email");
  var Phone = document.getElementById("Phone");
  var AgentCertified = document.getElementById("AgentCertified");
  var TravelerPassword = document.getElementById("AgentPass");
  var ConfirmPassword = document.getElementById("AgentPass2");
  
  msgStr = "Oops! It seems that the form has been completed improperly:\n\n";
  valid = true;

  form_validate_name(Name);
  form_validate_email(Email);
  form_validate_phone(Phone);
  form_validate_dates(ArrivalDate,DepartureDate);
  form_validate_AgentCertified(AgentCertified);
  form_validate_TravelerPassword(TravelerPassword,ConfirmPassword);
  

  var propertyTypes = document.inquiryForm.elements['PropertyTypeID'];
  var propertytypeselected = false;
  for(var i=0;i<propertyTypes.length;i++){
    if(propertyTypes[i].checked) propertytypeselected = true;
  }
  if(!propertytypeselected){
    msgStr += " - At least one property type should be selected\n";
    valid = false;
  }

  if(!valid){
    alert(msgStr);
    return false;
  }
  return confirm("To submit your inquiry, please verify that the information is correct and then click 'OK'.");
}



function validatePLSForm() {
  var Name = document.getElementById("Name");
  var ArrivalDate = document.getElementById("InquiryArrival");
  var DepartureDate = document.getElementById("InquiryDeparture");
  var Email = document.getElementById("Email");
  var Phone = document.getElementById("Phone");
  var Budget = document.getElementById("Budget");
  
  msgStr = "Oops! It seems that the form has been completed improperly:\n\n";
  valid = true;

  form_validate_name(Name);
  form_validate_email(Email);
  form_validate_phone(Phone);
  form_validate_dates(ArrivalDate,DepartureDate);

  if(!validateBlank(Budget)){
    msgStr += " - Please provide a budget\n";
    valid = false;
  }

  var propertyTypes = document.PLSform.elements['PropertyTypeID'];
  var propertytypeselected = false;
  for(var i=0;i<propertyTypes.length;i++){
    if(propertyTypes[i].checked) propertytypeselected = true;
  }
  if(!propertytypeselected){
    msgStr += " - At least one property type should be selected\n";
    valid = false;
  }
  
  if(!valid){
    alert(msgStr);
    return false;
  }
  return confirm("To submit your inquiry, please verify that the information is correct and then click 'OK'.");
}

function validateBookForm() {
  var Name = document.getElementById("Name");
  var Email = document.getElementById("Email");
  var Phone = document.getElementById("Phone");

  var msgStr = "Oops! It seems that the form has been completed improperly:\n\n";
  var valid = true;

  form_validate_name(Name);
  form_validate_email(Email);
  form_validate_phone(Phone);

  if(!valid){
    alert(msgStr);
    return false;
  }
  return valid;
}

function validateModifyForm() {
  var ArrivalDate = document.getElementById("InquiryArrival");
  var DepartureDate = document.getElementById("InquiryDeparture");
  var Phone = document.getElementById("Phone");

  var msgStr = "Oops! It seems that the form has been completed improperly:\n\n";
  var valid = true;

  form_validate_phone(Phone);
  form_validate_dates(ArrivalDate,DepartureDate);

  var propertyTypes = document.searchinquiry.elements['PropertyTypeID'];
  var propertytypeselected = false;
  for(var i=0;i<propertyTypes.length;i++){
    if(propertyTypes[i].checked) propertytypeselected = true;
  }
  if(!propertytypeselected){
    msgStr += " - At least one property type should be selected\n";
    valid = false;
  }

  if(!valid){
    alert(msgStr);
    return false;
  } else { 
  	if(!verifyBudgetValue('Budget','MinimumBudget')){
  		return false;
  	}
  }
  return confirm("To submit your inquiry, please verify that the information is correct and then click 'OK'.");
}

function showWarningBox(pId,pMsg){
	var element = document.getElementById(pId);

	for( var i = 0; element.childNodes[i]; i++ ){
		node = element.childNodes[i];
		//alert('type:' + node.nodeType+',name:'+node.nodeName+',parent:'+node.parentNode+',valeu:'+node.Value);
	}
}

function locateMessageDiv(){
	//alert('width:'+Screen.width);
}
