<!--

function MM_validateForm() { //v4.0
	var i,p,q,nm,test,num,min_amt,max_amt,errors='',args=MM_validateForm.arguments;
	for (i=0; i<(args.length-2); i+=3) {
		test=args[i+2];
		val=MM_findObj(args[i]);
    	if (val) {
	 		nm=val.name;
			if(nm == "input_name"){nm = "Property name"} 
			else if(nm == "input_bedrooms"){nm = "No. of bedrooms"} 
			else if(nm == "input_bathrooms"){nm = "No. of bathrooms"} 
			else if(nm == "input_price_peak"){nm = "Price peak"}
			else if(nm == "input_price_offpeak"){nm = "Price off-peak"}
			else if(nm == "input_sleeps_max"){nm = "Sleeps maximum"}
			else if(nm == "your_name"){nm = "Your name"}
			else if(nm == "your_email"){nm = "Your e-mail"}
			else if(nm == "friends_name"){nm = "Friend's name"}
			else if(nm == "friends_email"){nm = "Friend's email"}
			else if(nm == "name"){nm = "Your name"}
			else if(nm == "user_name"){nm = "Your name"}
			else if(nm == "email"){nm = "E-mail address"}

			if ((val=val.value)!="") {
      			if (test.indexOf('isEmail')!=-1) {
					p=val.indexOf('@');
        			if (p<1 || p==(val.length-1)){
						errors+='- '+nm+' must contain a valid e-mail address.\n';
					}
      			} else if(test.indexOf('shorter')!=-1){
					p=test.indexOf('shorter');
					min_amt=test.substring(p+7,p+8);
					if(val.length<min_amt){
						errors+='- '+nm+' length must be at least '+min_amt+' characters.\n';
					}
				} else if (test!='R') {
        			if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        			if (test.indexOf('inRange') != -1) {
						p=test.indexOf(':');
          				min_amt=parseInt(test.substring(8,p));
						max_amt=parseInt(test.substring(p+1));
//alert("min ="+min_amt+"; max = "+max_amt+"; val ("+val+")parsed = "+parseFloat(val));
          				if (parseFloat(val)<min_amt || max_amt<parseFloat(val)) errors+='- '+nm+' must contain a number between '+min_amt+' and '+max_amt+'.\n';
					}
				}
			} else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  		}
		if(MM_findObj("email")&&MM_findObj("confirm_email")){//These values are not present on all forms
			email1=MM_findObj("email");
			email2=MM_findObj("confirm_email");
			if(email1.value!=email2.value){errors+="- Confirm e-mail must be the same as E-mail.\n"}
		}
		if(MM_findObj("password")&&MM_findObj("confirm_password")){//These values are not present on all forms
			password1=MM_findObj("password");
			password2=MM_findObj("confirm_password");
			if(password1.value!=password2.value){errors+="- Confirm password must be the same as Password.\n"}
		}
		if (errors){
			return (errors);
		} else {
			return ("");
		}

	document.MM_returnValue = (errors == '');
}

function check_admin_edit_property_form(){// Called from admin_video_add.php
	anyproblems = "";
	anyproblems = MM_validateForm('input_name','','R','input_bedrooms','','RinRange0:12','input_bathrooms','','RinRange0:12','input_price_peak','','inRange0:99999','input_price_offpeak','','inRange0:99999','input_sleeps_max','','RinRange1:25');
	if(anyproblems){
		alert('The following error(s) occurred:\n'+anyproblems);
	} else {
		MM_findObj("post_name").value = escape(MM_findObj("input_name").value);
		escape("input name = "+MM_findObj("post_name").value);
		MM_findObj("post_price_peak").value = MM_findObj("input_price_peak").value;
		MM_findObj("post_price_offpeak").value = MM_findObj("input_price_offpeak").value;
		MM_findObj("post_bedrooms").value = MM_findObj("input_bedrooms").value;		
		MM_findObj("post_bathrooms").value = MM_findObj("input_bathrooms").value;		
		MM_findObj("post_location").value = escape(MM_findObj("input_location").value);		
		MM_findObj("post_sleeps_max").value = MM_findObj("input_sleeps_max").value;	
		//Update radio button values:
/*		if (MM_findObj("radio_parking")[0].checked){MM_findObj("post_parking").value = 1} else {MM_findObj("post_parking").value = 0;}
		if (MM_findObj("radio_fireplace")[0].checked){MM_findObj("post_fireplace").value = 1} else {MM_findObj("post_fireplace").value = 0;}
		if (MM_findObj("radio_balcony")[0].checked){MM_findObj("post_balcony").value = 1} else {MM_findObj("post_balcony").value = 0;}
		if (MM_findObj("radio_cd_dvd")[0].checked){MM_findObj("post_cd_dvd").value = 1} else {MM_findObj("post_cd_dvd").value = 0;}
		if (MM_findObj("radio_cot")[0].checked){MM_findObj("post_cot").value = 1} else {MM_findObj("post_cot").value = 0;}
*/
		MM_findObj("post_special_features").value = escape(MM_findObj("input_special_features").value);	

		MM_findObj("hiddenForm").submit();
	}
}

function check_availability_form(){
	anyproblems = "";
	test_start_day = MM_findObj("start_day").value;
	test_start_month = MM_findObj("start_month").value;
	test_start_year = MM_findObj("start_year").value;
	test_end_day = MM_findObj("end_day").value;
	test_end_month = MM_findObj("end_month").value;
	test_end_year = MM_findObj("end_year").value;
	test_contract_day = MM_findObj("contract_day").value;
	test_contract_month = MM_findObj("contract_month").value;
	test_contract_year = MM_findObj("contract_year").value;
	
	//Check start date is a valid date:
	if(test_start_day == 31&&(test_start_month==4||test_start_month==6||test_start_month==9||test_start_month==11)){
		anyproblems+= "- Start date is not a valid date.\n";	
	} else if(test_start_month==2&&(test_start_day>28)){
		checkForLeapYear = test_start_year/4;
		checkForLeapYearComparison = Math.floor(checkForLeapYear);
		if(((checkForLeapYear!=checkForLeapYearComparison)&&(test_start_day>28))||test_start_day>29){
			anyproblems+= "- Start date is not a valid date.\n";
		}
	}
	//Check end date is a valid date:
	if(test_end_day == 31&&(test_end_month==4||test_end_month==6||test_end_month==9||test_end_month==11)){
		anyproblems+= "- End date is not a valid date.\n";	
	} else if(test_end_month==2&&(test_end_day>28)){
		checkForLeapYear = test_end_year/4;
		checkForLeapYearComparison = Math.floor(checkForLeapYear);
		if(((checkForLeapYear!=checkForLeapYearComparison)&&(test_end_day>28))||test_end_day>29){
			anyproblems+= "- End date is not a valid date.\n";
		}
	}
	//Check contract date is a valid date:
	if(test_contract_day == 31&&(test_contract_month==4||test_contract_month==6||test_contract_month==9||test_contract_month==11)){
		anyproblems+= "- Contract date is not a valid date.\n";	
	} else if(test_contract_month==2&&(test_contract_day>28)){
		checkForLeapYear = test_contract_year/4;
		checkForLeapYearComparison = Math.floor(checkForLeapYear);
		if(((checkForLeapYear!=checkForLeapYearComparison)&&(test_contract_day>28))||test_contract_day>29){
			anyproblems+= "- Contract date is not a valid date.\n";
		}
	}
	if(anyproblems){
		alert('The following error(s) occurred:\n'+anyproblems);
	} else {
		MM_findObj("post_start_day").value = test_start_day;
		MM_findObj("post_start_month").value = test_start_month;
		MM_findObj("post_start_year").value = test_start_year;
		MM_findObj("post_end_day").value = test_end_day;		
		MM_findObj("post_end_month").value = test_end_month;		
		MM_findObj("post_end_year").value = test_end_year;		
		MM_findObj("post_contract_day").value = test_contract_day;		
		MM_findObj("post_contract_month").value = test_contract_month;		
		MM_findObj("post_contract_year").value = test_contract_year;	
		MM_findObj("post_details").value = MM_findObj("details").value;	
		MM_findObj("post_initials").value = MM_findObj("initials").value;	
		//Update radio button values:
		if (MM_findObj("type_of_availability")[0].checked){
			MM_findObj("post_type").value = 1
		} else if(MM_findObj("type_of_availability")[1].checked){
			MM_findObj("post_type").value = 2;
		} else {
			MM_findObj("post_type").value = 3;	
		}

		MM_findObj("hiddenForm").submit();
	}
	
}

function check_homepage_form(){ // Called from homepage
	anyproblems = "";
	test_start_day = MM_findObj("start_day").value;
	test_start_month = MM_findObj("start_month").value;
	test_start_year = MM_findObj("start_year").value;
	test_end_day = MM_findObj("end_day").value;
	test_end_month = MM_findObj("end_month").value;
	test_end_year = MM_findObj("end_year").value;
	
	// If start date is set, check start date is a valid date: (for the purposes of being set, all 3 boxes need a value
	if(test_start_day>0&&test_start_month>0&&test_start_year>0){
		if(test_start_day == 31&&(test_start_month==4||test_start_month==6||test_start_month==9||test_start_month==11)){
			anyproblems+= "- Start date is not a valid date.\n";	
		} else if(test_start_month==2&&(test_start_day>28)){
			checkForLeapYear = test_start_year/4;
			checkForLeapYearComparison = Math.floor(checkForLeapYear);
			if(((checkForLeapYear!=checkForLeapYearComparison)&&(test_start_day>28))||test_start_day>29){
				anyproblems+= "- Start date is not a valid date.\n";
			}
		}
	} else { // if(test_start_day>0&&test_start_month>0&&test_start_year>0){
		// Set all values to 0 just in case one has been set but not all
		test_start_day = 0;
		test_start_month = 0;
		test_start_year = 0;
	}
	// If end date is set, check end date is a valid date: (for the purposes of being set, all 3 boxes need a value
	if(test_end_day>0&&test_end_month>0&&test_end_year>0){
		if(test_end_day == 31&&(test_end_month==4||test_end_month==6||test_end_month==9||test_end_month==11)){
			anyproblems+= "- End date is not a valid date.\n";	
		} else if(test_end_month==2&&(test_end_day>28)){
			checkForLeapYear = test_end_year/4;
			checkForLeapYearComparison = Math.floor(checkForLeapYear);
			if(((checkForLeapYear!=checkForLeapYearComparison)&&(test_end_day>28))||test_end_day>29){
				anyproblems+= "- End date is not a valid date.\n";
			}
		}
	} else { // if(test_end_day>0&&test_end_month>0&&test_end_year>0){
		// Set all values to 0 just in case one has been set but not all
		test_end_day = 0;
		test_end_month = 0;
		test_end_year = 0;
	}
	if(anyproblems){
		alert('The following error(s) occurred:\n'+anyproblems);
	} else {
		MM_findObj("post_start_day").value = test_start_day;
		MM_findObj("post_start_month").value = test_start_month;
		MM_findObj("post_start_year").value = test_start_year;
		MM_findObj("post_end_day").value = test_end_day;		
		MM_findObj("post_end_month").value = test_end_month;		
		MM_findObj("post_end_year").value = test_end_year;		
		MM_findObj("post_minimum").value = MM_findObj("minimum_people").value;	

		MM_findObj("hiddenForm").submit();
	}
	
}

function checkMailAFriendForm(){ // Called from email_a_friend.php
	anyproblems = "";
	anyproblems = MM_validateForm('your_name','','R','your_email','','RisEmail','friends_name','','R','friends_email','','RisEmail');
	if(anyproblems){
		alert('The following error(s) occurred:\n'+anyproblems);	
	} else {
		MM_findObj("post_your_name").value = MM_findObj("your_name").value;
		MM_findObj("post_your_email").value = MM_findObj("your_email").value;
		MM_findObj("post_friends_name").value = MM_findObj("friends_name").value;
		MM_findObj("post_friends_email").value = MM_findObj("friends_email").value;
		
		MM_findObj("hiddenForm").submit();
	}
}

function checkContactForm(){ // Called from contact_rentals_chamonix.php
	anyproblems = "";
	anyproblems = MM_validateForm('user_name','','R','email','','RisEmail');
	if(anyproblems){
		alert('The following error(s) occurred:\n'+anyproblems);	
	} else {
		MM_findObj("post_name").value = escape(MM_findObj("user_name").value);
		MM_findObj("post_email").value = escape(MM_findObj("email").value);
		MM_findObj("post_telephone").value = escape(MM_findObj("telephone").value);
		MM_findObj("post_query").value = escape(MM_findObj("query").value);
		
		MM_findObj("hiddenForm").submit();
	}
}

//-->