//login details
	function f_chk_dtls() {
		var username = document.forms[0].username.value;
		var password = document.forms[0].password.value;
				
		if (username == "") {
			alert("Please enter your username");
			document.forms[0].username.focus();
			return false;
		} else
		if (password == "") {
			alert("Please enter your password");
			document.forms[0].password.focus();
			return false;
		} else {
			return true;
		}
	}	

//logout		
	function logout(){
		var agree = confirm("Are you sure you wish to logout?");
		if (agree) {
			document.forms[0].action = "/files/login/logout.php";
			document.forms[0].submit();
			return true;
		} else {
			return false;
		}
	}

//file share check for to see if files are being edited or not
	function edit_file(count){
		count_arr = count.split(",");
		count = count_arr[0];
		document.forms[count].db_action.value = "edit";
		var file = document.forms[count].file.value;
		var edit_by = document.forms[count].edit_by.value;
		var primary_id = document.forms[count].primary_id.value;		
		var myusername = document.forms[count].myusername.value;		

		if ((file == "locked") && (myusername != edit_by)){
			alert("You cannot edit this file as it is currently being edited by " + edit_by);
			return false;
		} else {
			document.forms[count].action="index.php";
			document.forms[count].submit();
			window.open(count_arr[1]);
		}
	}

//file share check to see if you can delete files or not
	function delete_file(count){
		document.forms[count].db_action.value = "delete";
		var file = document.forms[count].file.value;
		var edit_by = document.forms[count].edit_by.value;
		var myusername = document.forms[count].myusername.value;		

		if ((file == "locked") && (myusername != edit_by)) {
			alert("You cannot delete this file as it is currently being edited by " + edit_by);
			return false;
		} else 
		if ((file == "locked") && (myusername == edit_by)) {
			var agree = confirm("Are you sure you wish to delete this file?");
			if (agree) {
				document.forms[count].action = "index.php";
				document.forms[count].submit();
				return true;
			} else {
				return false;
			}
		} else 
		if (file != "locked"){
			var agree = confirm("Are you sure you wish to delete this file?");
			if (agree) {
				document.forms[count].action = "index.php";
				document.forms[count].submit();
				return true;
			} else {
				return false;
			}
		}
	}

//file share check to unlock a file
	function unlock_file(count){
		document.forms[count].db_action.value = "unlock";
		var file = document.forms[count].file.value;
		var edit_by = document.forms[count].edit_by.value;
		var primary_id = document.forms[count].primary_id.value;		
		var myusername = document.forms[count].myusername.value;		

		var agree = confirm("Are you sure you wish to unlock this file?");
		if (agree == true) {
			document.forms[count].action = "index.php";
			document.forms[count].submit();
			return true;
		} else {
			return false;
		}
	}
	

//file share check to restrict a file
	function restrict_file(count){
		document.forms[count].db_action.value = "restrict";
		var file = document.forms[count].file.value;
		var primary_id = document.forms[count].primary_id.value;		
		var myusername = document.forms[count].myusername.value;		

		var agree = confirm("Are you sure you wish to 'Restrict' this file?");
		if (agree == true) {
			document.forms[count].action = "index.php";
			document.forms[count].submit();
			return true;
		} else {
			return false;
		}
	}


//file share check to un_restrict a file
	function un_restrict_file(count){
		document.forms[count].db_action.value = "unrestrict";
		var file = document.forms[count].file.value;
		var primary_id = document.forms[count].primary_id.value;		
		var myusername = document.forms[count].myusername.value;		

		var agree = confirm("Are you sure you wish to 'Release' this file?");
		if (agree == true) {
			document.forms[count].action = "index.php";
			document.forms[count].submit();
			return true;
		} else {
			return false;
		}
	}


//file share check to archive a file
	function archive_file(count){
		document.forms[count].db_action.value = "archive";
		var file = document.forms[count].file.value;
		var primary_id = document.forms[count].primary_id.value;		
		var myusername = document.forms[count].myusername.value;		

		var agree = confirm("Are you sure you wish to 'Archive' this file?");
		if (agree == true) {
			document.forms[count].action = "index.php";
			document.forms[count].submit();
			return true;
		} else {
			return false;
		}
	}


//file share check to un_archive a file
	function un_archive_file(count){
		document.forms[count].db_action.value = "unarchive";
		var file = document.forms[count].file.value;
		var primary_id = document.forms[count].primary_id.value;		
		var myusername = document.forms[count].myusername.value;		

		var agree = confirm("Are you sure you wish to 'Restore' this file?");
		if (agree == true) {
			document.forms[count].action = "index.php";
			document.forms[count].submit();
			return true;
		} else {
			return false;
		}
	}
			
	
//accmmodation request form
	function chk_dtls() {
		var name = document.forms[0].name.value;
		var email = document.forms[0].email.value;
		var nr_people = document.forms[0].nr_people[document.forms[0].nr_people.selectedIndex].value;		
		var num_nights = document.forms[0].num_nights[document.forms[0].num_nights.selectedIndex].value;		
		var phone = document.forms[0].phone.value;		
		var chalet_name = document.forms[0].chalet_name.value;				
		var mxsource = document.forms[0].mxsource.value;				
		//js trim code by bhaskar 
		String.prototype.trim = function() {
			return this.replace(/^\s+|\s+$/g,"");
		}
		//add check date
		if (name == "") {
			alert("Please enter your name");
			document.forms[0].name.focus();
			return false;
		} else
		if (email.trim() == "") {
			alert("Please enter your email address");
			document.forms[0].email.focus();
			return false;
		}
		else
		if(email.trim()!=='')
		{
			 var regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
			 var bool_result =regex.test(email);
			 if(!bool_result)
		   	{
				alert("Please enter valid email address");
				document.forms[0].email.focus();
				return false;
			}
		}
		
		if (nr_people == "") {
			alert("Please select a number of people");
			document.forms[0].nr_people.focus();
			return false;
		} else
		if (num_nights == "") {
			alert("Please select a number of nights");
			document.forms[0].num_nights.focus();
			return false;			
		} else
		if (phone == "") {
			alert("Please enter your phone number");
			document.forms[0].phone.focus();
			return false;	
		} else
		if (mxsource == "") {
			alert("Please enter where did you hear about Mountain Exposure");
			document.forms[0].mxsource.focus();
			return false;						
		} else		
		if(email.length > 0) {
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) {
				return Validate_date();
			}
			alert("Invalid E-mail Address! Please re-enter.");
			document.forms[0].email.focus();
			return false;
		}
	}


//client database form
	function chk_client_dtls() {
		var name = document.forms[0].name.value;
		var email = document.forms[0].email.value;
		var nr_people = document.forms[0].nr_people[document.forms[0].nr_people.selectedIndex].value;		
		var num_nights = document.forms[0].num_nights[document.forms[0].num_nights.selectedIndex].value;		
		var booking_status = document.forms[0].booking_status[document.forms[0].booking_status.selectedIndex].value;		
		var enquiry_state = document.forms[0].enquiry_state[document.forms[0].enquiry_state.selectedIndex].value;		
		var enquiry_phase = document.forms[0].enquiry_phase[document.forms[0].enquiry_phase.selectedIndex].value;		
								
		if (name == "") {
			alert("Please enter your name");
			document.forms[0].name.focus();
			return false;
		} else
		if (email == "") {
			alert("Please enter your email address");
			document.forms[0].email.focus();
			return false;
		} else
		if (nr_people == "") {
			alert("Please select a number of people");
			document.forms[0].nr_people.focus();
			return false;
		} else
		if (num_nights == "") {
			alert("Please select a number of nights");
			document.forms[0].num_nights.focus();
			return false;			
		} else
		if (booking_status == "") {
			alert("Please select a booking status");
			document.forms[0].booking_status.focus();
			return false;			
		} else
		if (enquiry_state == "") {
			alert("Please select an enquiry state");
			document.forms[0].enquiry_state.focus();
			return false;			
		} else
		if (enquiry_phase == "") {
			alert("Please select an enquiry phase");
			document.forms[0].enquiry_phase.focus();
			return false;			
		} else
		if(email.length > 0) {
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) {
				return Validate_date();
			}
			alert("Invalid E-mail Address! Please re-enter.");
			document.forms[0].email.focus();
			return false;
		}
	}
	
	
//client database search form
function chk_search() {
	var valid;
	var date_from;
	var date_to;
	var arr_day,arr_month,arr_year,days;
	var days_in_mnth = new Array(31, 28, 31, 30, 31, 30,31, 31, 30, 31, 30, 31); /* february set according to if leap year */
	var arr_mnth_name = new Array("JAN", "FEB", "MAR", "APR","MAY", "JUN","JUL", "AUG", "SEP", "OCT", "NOV", "DEC"); /* month names */
	var i =0;
	var arr_mnth;
	valid = true; /* Allow blank dates */

	if (date_from != "") {
		arr_day = document.forms[0].arr_day[document.forms[0].arr_day.selectedIndex].value;
		arr_month = document.forms[0].arr_month[document.forms[0].arr_month.selectedIndex].value;
		arr_year = document.forms[0].arr_year[document.forms[0].arr_year.selectedIndex].value;
		arr_month = arr_month.toUpperCase();

		if ((arr_day == "") && (arr_month != "") && (arr_year != "")) {
			alert("You must also select a day.");
			document.forms[0].arr_day.focus();
			return false;
		} else
		if ((arr_day != "") && (arr_month == "") && (arr_year != "")) {
			alert("You must also select a month.");
			document.forms[0].arr_month.focus();
			return false;
		} else
		if ((arr_day != "") && (arr_month != "") && (arr_year == "")) {
			alert("You must also select a year.");
			document.forms[0].arr_year.focus();
			return false;
		} else
		if ((arr_day == "") && (arr_month == "") && (arr_year != "")) {
			alert("You must select a day and month.");
			document.forms[0].arr_day.focus();
			return false;
		} else
		if ((arr_day == "") && (arr_month != "") && (arr_year == "")) {
			alert("You must also select a day and year.");
			document.forms[0].arr_day.focus();
			return false;
		} else
		if ((arr_day != "") && (arr_month == "") && (arr_year == "")) {
			alert("You must also select a month and year.");
			document.forms[0].arr_month.focus();
			return false;
		}
		
		if (arr_month.length==3) {
			i =0;
			while (i<12 && arr_month != mnth_name[i])
				i++;
				arr_month = i+1;
		}
		year = arr_year;
		if (is_leap_year(parseInt(year,10) ))
			days_in_mnth[1] = 29; /* set up Feb */

			if (arr_day > days_in_mnth[arr_month-1] )
				valid = false; /* Elementary date test */
	}


	if (valid == false) {
		alert("Invalid date! Please check again.");
		document.forms[0].arr_day.focus();
		return false;
	} else {
		return true;
	}		
}
	
	//client database search form
	function reset_form() {
		document.forms[0].action = "mainmenu.php";
		document.forms[0].search_orig.value = "";
		document.forms[0].submit();
	}

	//client database search form
	function change_row(val) {
		if (val == "search") {
			document.forms[0].action = "search.php";		
		}else {
			document.forms[0].action = "mainmenu.php";			
		}
		document.forms[0].submit();
	}
			
//check for deleting a customer		
	function delete_avail(){
		var selected_id = "";
		var agree = confirm("Are you sure you wish to delete all details for the selected customer(s)?");
		num = document.forms[0].elements.length;
		for(i = 0; i < num; i++) {
			if(document.forms[0].elements[i].checked) {
				email_ref = document.forms[0].elements[i].value.split("::::");
				if (email_ref != "") {
					selected_id = email_ref[0] + "::::" + selected_id;
				}
			}
		}		
		if (agree == true) {
			document.forms[0].delete_list.value = selected_id;
			document.forms[0].button_action.value = "db_delete";			
			document.forms[0].action = "mainmenu.php";
			document.forms[0].submit();
			return true;
		} else {
			return false;
		}
	}
	
//function which reads the values from a checkbox and puts them into an email
	function submit_email_top(){
		templates = document.forms[0].templates_top.value;
		return template_sel(templates);
	}

	function submit_email_bottom(){
		templates = document.forms[0].templates_bottom.value;
		return template_sel(templates);
	}

	function template_sel(templates) {
		var email_ref_all = "";
		num = document.forms[0].elements.length;
		for (i = 0; i < num; i++) {
			if (document.forms[0].elements[i].checked) {
				email_ref = document.forms[0].elements[i].value.split("::::");
				if (email_ref != ""){
					if ((document.forms[0].elements[i].value == "arr_date") || (document.forms[0].elements[i].value == "enq_date")) {
						email_ref_all = email_ref_all;
					} else {
						email_ref_all = email_ref[1] + ";" + email_ref_all;						
					}
				}
			}
		}
		if (templates == "Hold Expired") {
			var email_body = "Dear Mr/Ms,%0A%0AAs We have not heard back from you, the chalet you had on hold has now been released again to our sales team. Please do get in touch with us as soon as possible if you are still undecided or if your requirements have changed.%0A%0ABest regards%0A%0AThe Mountain Exposure Team%0A%0AMX Mountain Exposure AG%0A%0A+41 793 51 56 23%0A%0Awww.mountainexposure.com";
			window.location = "mailto:?bcc=" + email_ref_all + "&subject=Zermatt Chalet Availability&body=" + email_body;
		}else 
		if (templates == "Offer Reminder") {
			var email_body = "Dear Mr/Ms,%0A%0AAs We have not heard back from you, we thought we would check with you whether you were still interested in our chalets in Zermatt. We will be happy to place a chalet on hold for you for 48 hours should you wish us to do so.%0A%0ABest regards%0A%0AThe Mountain Exposure Team%0A%0AMX Mountain Exposure AG%0A%0A+41 793 51 56 23%0A%0Awww.mountainexposure.com";
			window.location = "mailto:?bcc=" + email_ref_all + "&subject=Zermatt Chalet Availability&body=" + email_body;
		}else 
		if (templates == "No Availability") {
			var email_body = "Dear Mr/Ms,%0A%0AThank you very much for your enquiry relating to our chalets in Zermatt. \n\nWe very much regret that we are already fully booked for the dates that you requested. We do of course have availability for a number of other weeks of the season.%0A%0AShould your dates be flexible or should you decide to plan a visit for a different period then please do not hesitate to get in touch with us as we would be delighted to be of assistance. %0A%0ABest regards%0A%0AThe Mountain Exposure Team%0A%0AMX Mountain Exposure AG%0A%0A+41 793 51 56 23%0A%0Awww.mountainexposure.com";
			window.location = "mailto:?bcc=" + email_ref_all + "&subject=Zermatt Chalet Availability&body=" + email_body;
		}else
		if (templates == "Send Offer") {
			var email_body = "Dear Mr/Ms,%0A%0AThank you for your interest in our chalets, [DELETE IF NO TELEPHONE CONTACT HAS BEEN MADE: further to our telephone conversation,] we are delighted to be able to confirm that we currently have the following availability:%0A%0A[INSERT DATE] [INSERT CHALET NAME, DESCRIPTION AND PRICE AND WEB LINK]%0A%0A[INSERT DATE] [INSERT CHALET NAME, DESCRIPTION AND PRICE AND WEB LINK]%0A%0A[INSERT DATE] [INSERT CHALET NAME, DESCRIPTION AND PRICE AND WEB LINK]%0A%0A[FOR CATERED CHALETS ONLY: Please note that our catered chalet prices include, among other services, cooked breakfast, daily cleaning, afternoon tea (if required), pre-dinner champagne and canapes, 4 course dinner served with our carefully selected wines, an open bar and our concierge service.]%0A%0APlease do let us know as soon as possible if you wish to book or place a chalet on hold as our availability is constantly changing. Should you ask us to do so, we can place a chalet on hold for you for up to 48 hours at a time. %0A%0AOur experienced team is at your disposal to answer any questions you may have in relation to our chalets and service so please do not hesitate to get in touch with us at your convenience.  %0A%0ABest regards%0A%0AThe Mountain Exposure Team%0A%0AMX Mountain Exposure AG%0A%0A+41 793 51 56 23%0A%0Awww.mountainexposure.com";
			window.location = "mailto:?bcc=" + email_ref_all + "&subject=Zermatt Chalet Availability for [Guest name] from [requested date] for [number of guests] guests&body=" + email_body;
		}else		
		if ((templates == "Blank Email") || (templates == "")){
			var email_body = "";
			window.location = "mailto:?bcc=" + email_ref_all + "&body=" + email_body;						
		}
	}	

//function which reads the values from a checkbox and puts them into an email
	function submit_email_single(myusername, name, arr_date, email, guests, num_nights){
		if ((document.forms[0].templates_top.value != "") && (document.forms[0].templates_bottom.value != "") && (document.forms[0].templates_top.value != document.forms[0].templates_bottom.value)) {
			alert("You have two templates selected, please select only one; from the top or bottom of the page");
			return false;
		} else
		if (document.forms[0].templates_top.value != "") {
			templates = document.forms[0].templates_top.value;
		} else {
			templates = document.forms[0].templates_bottom.value;			
		}
		if (templates == "Hold Expired") {
			var email_body = "Dear Mr/Ms " + name + ",%0A%0AAs we have not heard back from you, the chalet you had on hold has now been released again to our sales team. Please do get in touch with us as soon as possible if you are still undecided or if your requirements have changed.%0A%0ABest regards%0A%0AThe Mountain Exposure Team%0A%0AMX Mountain Exposure AG%0A%0A+41 793 51 56 23%0A%0Awww.mountainexposure.com";
			window.location = "mailto:" + email + "?subject=Zermatt Chalet Availability for " + name + " from " + arr_date + " for " + guests + " guests&body=" + email_body;
		}else 
		if (templates == "Offer Reminder") {
			var email_body = "Dear Mr/Ms " + name + ",%0A%0AAs we have not heard back from you, we thought we would check with you whether you were still interested in our chalets in Zermatt. We will be happy to place a chalet on hold for you for 48 hours should you wish us to do so.%0A%0ABest regards%0A%0AThe Mountain Exposure Team%0A%0AMX Mountain Exposure AG%0A%0A+41 793 51 56 23%0A%0Awww.mountainexposure.com";
			window.location = "mailto:" + email + "?subject=Zermatt Chalet Availability for " + name + " from " + arr_date + " for " + guests + " guests&body=" + email_body;
		}else 
		if (templates == "No Availability") {
			var email_body = "Dear Mr/Ms " + name + ",%0A%0AThank you very much for your enquiry relating to our chalets in Zermatt. \n\nWe very much regret that we are already fully booked for the dates that you requested. We do of course have availability for a number of other weeks of the season.%0A%0AShould your dates be flexible or should you decide to plan a visit for a different period then please do not hesitate to get in touch with us as we would be delighted to be of assistance. %0A%0ABest regards%0A%0AThe Mountain Exposure Team%0A%0AMX Mountain Exposure AG%0A%0A+41 793 51 56 23%0A%0Awww.mountainexposure.com";
			window.location = "mailto:" + email + "?subject=Zermatt Chalet Availability for " + name + " from " + arr_date + " for " + guests + " guests&body=" + email_body;
		}else
		if (templates == "Send Offer") {
			var popup = null;
			popup = window.open('', '', 'width=1000,height=500,resizable=0,scrollbars=yes,left=2,top=2,alwaysLowered=no,alwaysRaised=yes');
			if (popup != null) {
				if (popup.opener == null) {
					popup.opener = self;
				}
				popup.location.href = "template.php?myusername=" + myusername + "&name=" + name + "&email=" + email + "&arr_date=" + arr_date + "&num_guests=" + guests + "&num_nights=" + num_nights;
			}			
//			var email_body = "Dear Mr/Ms " + name + ",%0A%0AThank you for your interest in our chalets, [DELETE IF NO TELEPHONE CONTACT HAS BEEN MADE: further to our telephone conversation,] we are delighted to be able to confirm that we currently have the following availability:%0A%0A[INSERT DATE] [INSERT CHALET NAME, DESCRIPTION AND PRICE AND WEB LINK]%0A%0A[INSERT DATE] [INSERT CHALET NAME, DESCRIPTION AND PRICE AND WEB LINK]%0A%0A[INSERT DATE] [INSERT CHALET NAME, DESCRIPTION AND PRICE AND WEB LINK]%0A%0A[FOR CATERED CHALETS ONLY: Please note that our catered chalet prices include, among other services, cooked breakfast, daily cleaning, afternoon tea (if required), pre-dinner champagne and canapes, 4 course dinner served with our carefully selected wines, an open bar and our concierge service.]%0A%0APlease do let us know as soon as possible if you wish to book or place a chalet on hold as our availability is constantly changing. Should you ask us to do so, we can place a chalet on hold for you for up to 48 hours at a time. %0A%0AOur experienced team is at your disposal to answer any questions you may have in relation to our chalets and service so please do not hesitate to get in touch with us at your convenience.  %0A%0ABest regards%0A%0AThe Mountain Exposure Team%0A%0AMX Mountain Exposure AG%0A%0A+41 793 51 56 23%0A%0Awww.mountainexposure.com";
//			window.location = "mailto:?bcc=" + email + "&subject=Zermatt Chalet Availability for " + name + " from " + arr_date + " for " + guests + " guests&body=" + email_body;
		}else
		if ((templates == "Blank Email") || (templates == "")){
			var email_body = "";
			window.location = "mailto:" + email + "?body=" + email_body;						
		}
	}
	
//check for adding a new user	
	function chk_user() {
		var name = document.forms[0].name.value;
		var username_new = document.forms[0].username_new.value;
		var initials = document.forms[0].initials.value;		
		var password_new = document.forms[0].password_new.value;				
		var email = document.forms[0].email.value;
		var accesslevel = document.forms[0].accesslevel[document.forms[0].accesslevel.selectedIndex].value;		
				
		if (name == "") {
			alert("Please enter a name");
			document.forms[0].name.focus();
			return false;
		} else
		if (initials == "") {
			alert("Please enter initials");
			document.forms[0].initials.focus();
			return false;
		} else		
		if (username_new == "") {
			alert("Please enter a username");
			document.forms[0].username_new.focus();
			return false;
		} else
		if (password_new == "") {
			alert("Please enter a password");
			document.forms[0].password_new.focus();
			return false;
		} else
		if (email == "") {
			alert("Please enter an email address");
			document.forms[0].email.focus();
			return false;
		} else
		if (accesslevel == "") {
			alert("Please select an access level");
			document.forms[0].accesslevel.focus();
			return false;
		} else	
		if(email.length > 0) {
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) {
				return true;
			}
			alert("Invalid E-mail Address! Please re-enter.");
			document.forms[0].email.focus();
			return false;
		} else {
			return true;
		}
	}	

//check for deleting a user	
	function delete_user(){
		var agree = confirm("Are you sure you wish to delete all details for this user?");
		if (agree) {
			return true;
		} else {
			return false;
		}
	}	
	
//checks the request a quote form	
	
		//alert("hi ");
	/*	var name = window.document.form1.name.value;
		var email = window.document.form1.email.value;
		var nrOfPeople = window.document.form1.nrOfPeople[document.form1.nrOfPeople.selectedIndex].value;		
		var num_nights = window.document.form1.num_nights[document.form1.num_nights.selectedIndex].value;						
		var contact_by = window.document.form1.contact_by[document.form1.contact_by.selectedIndex].value;								
*/
		/*if(window.document.form1.name.value=='') {
			alert("Please enter your name");
			document.form1.name.focus();
			return false;
		}
		else if(window.document.form1.email.value=='')
       {
			var i,o,w,s=window.document.form1.email.value;
i=s.indexOf("@");
o=s.indexOf(".");
if((i=s.indexOf("@"))==-1)
{

alert('Invalid "Email Id"');
window.document.form1.email.focus();
return false;
}
if((o=s.indexOf("."))<i)
{
alert('Invalid Email Id');
window.document.form1.email.focus();
return false;
}
var X
X=s.length;
if(X<=o+1)
{
alert('Invaild "Email Id"');
window.document.form1.email.focus();
}
}
		
 if(window.document.form1.num_nights.value=='') {
			alert("Please select a number of nights");
			document.form1.num_nights.focus();
			return false;			
		} 
		
			if (window.document.form1.flex_dates.value=='') {
			alert("Please select a 'Contact me by' option");
			document.form1.flex_dates.focus();
			return false;
		} 	
		
		if (window.document.form1.nrOfPeople.value=='') {
			alert("Please select a number of people");
			document.form1.nrOfPeople.focus();
			return false;
		}
		

			
		if (window.document.form1.contact_by.value=='') {
			alert("Please select a 'Contact me by' option");
			document.form1.contact_by.focus();
			return false;
		} 
		/*else if(window.document.form1.email.length > 0) {
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) {
				return Validate_date();
			}
			alert("Invalid E-mail Address! Please re-enter.");
			document.form1.email.focus();
			return false;
		}*/
		
function chk_request_old() {
 var store="";
 var flag;
 flag=0;
//alert("hi");
if(window.document.form1.name.value=='')
 {
   store+=" Name \n";
   flag=1;
 }  
if(window.document.form1.email.value=='')
{
	store+=" Email Address \n";
	flag=1;
}
else
{
var i,o,w,s=window.document.form1.email.value;
i=s.indexOf("@");
o=s.indexOf(".");
if((i=s.indexOf("@"))==-1)
{

alert('Invalid "Email Id"');
window.document.form1.email.focus();
return false;
}
if((o=s.indexOf("."))<i)
{
alert('Invalid Email Id');
window.document.form1.email.focus();
return false;
}
var X
X=s.length;
if(X<=o+1)
{
alert('Invaild "Email Id"');
window.document.form1.email.focus();
}
}
if(window.document.form1.nrOfPeople.value=='')
{
	store+=" How many people? \n";
	flag=1;
	}

if(window.document.form1.arr_month.value=='')
{
	store+=" Arrival Month \n";
	flag=1;
	}
if(window.document.form1.arr_year.value=='')
{
	store+=" Arrival Year \n";
	flag=1;
	}
if(window.document.form1.arr_day.value=='')
{
	store+=" Arrival Date \n";
	flag=1;
	}
if(window.document.form1.num_nights.value=='')
{
	store+=" Number of nights \n";
	flag=1;
	}	
if(window.document.form1.phone.value=='')
{
	store+=" Phone \n";
	flag=1;
	}
if(window.document.form1.timesvisited.value=='')
{
	store+=" Times Visited \n";
	flag=1;
	}
if(window.document.form1.mxsource.value=='')
{
	store+=" How did you hear of Mountain Exposure? \n";
	flag=1;
	}
if(flag==1)
{
	alert("Please Enter Compulsory Fields..\n"+store);
	return false;
	}
else
{
 return true;
}  
} 

	function chk_request() {
		var name = document.forms[0].name.value;
		var email = document.forms[0].email.value;
		var nrOfPeople = document.forms[0].nrOfPeople[document.forms[0].nrOfPeople.selectedIndex].value;		
		var arr_day = document.forms[0].arr_day[document.forms[0].arr_day.selectedIndex].value;		
		var arr_month = document.forms[0].arr_month[document.forms[0].arr_month.selectedIndex].value;		
		var arr_year = document.forms[0].arr_year[document.forms[0].arr_year.selectedIndex].value;		
		var num_nights = document.forms[0].num_nights[document.forms[0].num_nights.selectedIndex].value;		
		var phone = document.forms[0].phone.value;		
		var chalet_name = document.forms[0].chalet_name.value;				
		var timesvisited = document.forms[0].timesvisited.value;				
		
		//add check date
		if (name == "") {
			alert("Please enter your name");
			document.forms[0].name.focus();
			return false;
		} else
		if (email == "") {
			alert("Please enter your email address");
			document.forms[0].email.focus();
			return false;
		} else
		if (nrOfPeople == "") {
			alert("Please select a number of people");
			document.forms[0].nrOfPeople.focus();
			return false;
		} else
		if (arr_day == "") {
			alert("Please select a date");
			document.forms[0].arr_day.focus();
			return false;
		} else
		if (arr_month == "") {
			alert("Please select a month");
			document.forms[0].arr_month.focus();
			return false;
		} else
		if (arr_year == "") {
			alert("Please select a year");
			document.forms[0].arr_year.focus();
			return false;
		} else
		if (num_nights == "") {
			alert("Please select a number of nights");
			document.forms[0].num_nights.focus();
			return false;			
		} else
		if (phone == "") {
			alert("Please enter your phone number");
			document.forms[0].phone.focus();
			return false;	
		} else
		if (timesvisited == "") {
			alert("Please enter how did you hear about Mountain Exposure");
			document.forms[0].timesvisited.focus();
			return false;						
		} else		
		if(email.length > 0) {
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) {
				return Validate_date();
			}
			alert("Invalid E-mail Address! Please re-enter.");
			document.forms[0].email.focus();
			return false;
		}
	}

	
//checks the request a quote form	
	function chk_comment_dtls() {
		var name = document.forms[0].name.value;
		var email = document.forms[0].email.value;
		var chalet_name = document.forms[0].chalet_name.value;
		var comments = document.forms[0].comments.value;

		if (name == "") {
			alert("Please enter your name");
			document.forms[0].name.focus();
			return false;
		} else
		if (email == "") {
			alert("Please enter your email address");
			document.forms[0].email.focus();
			return false;
		} else
		if (chalet_name == "") {
			alert("Please enter the chalet you stayed at");
			document.forms[0].chalet_name.focus();
			return false;			
		} else		
		if (comments == "") {
			alert("Please enter a comment");
			document.forms[0].comments.focus();
			return false;
		} else		
		if(email.length > 0) {
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) {
				return Validate_date();
			}
			alert("Invalid E-mail Address! Please re-enter.");
			document.forms[0].email.focus();
			return false;
		}
	}	
	
		
//function to validate the date
function is_leap_year(year) {
	var leap_year_ind;
	leap_year_ind = false;

	if (!(year % 4)) { /* is year a multiple of... */
		leap_year_ind = true; /* then its a leap year */
	}
	if (!(year % 100)) {
		leap_year_ind = false; /* centuries not leap years */
		if (!(year % 400)) {
			leap_year_ind = true; /* but this is a special case */
		}
	}
	return (leap_year_ind);
}
function Validate_date() {
	var valid;
	var date_from;
	var date_to;
	var day,month,year,days;
	var days_in_mnth = new Array(31, 28, 31, 30, 31, 30,31, 31, 30, 31, 30, 31); /* february set according to if leap year */
	var mnth_name = new Array("JAN", "FEB", "MAR", "APR","MAY", "JUN","JUL", "AUG", "SEP", "OCT", "NOV", "DEC"); /* month names */
	var i =0;
	var mnth;
	valid = true; /* Allow blank dates */

	if (date_from != "") {
		day = document.forms[0].arr_day[document.forms[0].arr_day.selectedIndex].value;
		month = document.forms[0].arr_month[document.forms[0].arr_month.selectedIndex].value;
		year = document.forms[0].arr_year[document.forms[0].arr_year.selectedIndex].value;
		month = month.toUpperCase();

		if ((day == "") && (month == "") && (year == "")) {
			alert("You must select a day, month and year.");
			document.forms[0].arr_day.focus();
			return false;
		} else
		if ((day == "") && (month != "") && (year != "")) {
			alert("You must also select a day.");
			document.forms[0].arr_day.focus();
			return false;
		} else
		if ((day != "") && (month == "") && (year != "")) {
			alert("You must also select a month.");
			document.forms[0].arr_month.focus();
			return false;
		} else
		if ((day != "") && (month != "") && (year == "")) {
			alert("You must also select a year.");
			document.forms[0].arr_year.focus();
			return false;
		} else
		if ((day == "") && (month == "") && (year != "")) {
			alert("You must select a day and month.");
			document.forms[0].arr_day.focus();
			return false;
		} else
		if ((day == "") && (month != "") && (year == "")) {
			alert("You must also select a day and year.");
			document.forms[0].arr_day.focus();
			return false;
		} else
		if ((day != "") && (month == "") && (year == "")) {
			alert("You must also select a month and year.");
			document.forms[0].arr_month.focus();
			return false;
		}
				
		if (month.length==3) {
			i =0;
			while (i<12 && month != mnth_name[i])
				i++;
				month = i+1;
		}

		if (is_leap_year(parseInt(year,10) ))
			days_in_mnth[1] = 29; /* set up Feb */

			if (day > days_in_mnth[month-1] )
				valid = false; /* Elementary date test */
	}


	if (valid == false) {
		alert("Invalid date! Please check again.");
		document.forms[0].arr_day.focus();
		return false;
	} else {
		return true;
	}
}	


function Setall() {
	if(document.forms[0].selectall.checked) {
		num = document.forms[0].elements.length;
		for(i = 0; i < num; i++) {
			if(document.forms[0].elements[i].name == "client_db_id") {
				document.forms[0].elements[i].checked = true;
			}
		}
	} else {
		num = document.forms[0].elements.length;
		for(i = 0; i < num; i++) {
			if(document.forms[0].elements[i].name == "client_db_id") {
				document.forms[0].elements[i].checked = false;
			}
		}
	}
}


function Setall_template() {
	if(document.forms[0].selectall.checked) {
		num = document.forms[0].elements.length;
		for(i = 0; i < num; i++) {
			if(document.forms[0].elements[i].name == "chalet_db_id") {
				document.forms[0].elements[i].checked = true;
			}
		}
	} else {
		num = document.forms[0].elements.length;
		for(i = 0; i < num; i++) {
			if(document.forms[0].elements[i].name == "chalet_db_id") {
				document.forms[0].elements[i].checked = false;
			}
		}
	}
}

function chk_template_sel(){
	var primary_id_all = "";	
	num = document.forms[0].elements.length-16;
	for (i = 0; i < num; i++) {
		if (document.forms[0].elements[i].checked) {
			primary_id = document.forms[0].elements[i].value;
			if (document.forms[0].elements[i].value == "") {
				primary_id_all = primary_id_all;
			} else {
				primary_id_all = primary_id + "::::" + primary_id_all;
			}
		}
	}
	document.forms[0].primary_id_submit.value = primary_id_all;
}

function chk_template(){
		var title = document.forms[0].title[document.forms[0].title.selectedIndex].value;		
		var name = document.forms[0].name.value;
		var email = document.forms[0].email.value;

		var num_nights = document.forms[0].num_nights[document.forms[0].num_nights.selectedIndex].value;		
		var num_guests = document.forms[0].num_guests[document.forms[0].num_guests.selectedIndex].value;		
								
		if (title == "") {
			alert("Please select a title");
			document.forms[0].title.focus();
			return false;
		} else
		if (name == "") {
			alert("Please enter a name");
			document.forms[0].name.focus();
			return false;
		} else				
		if (email == "") {
			alert("Please enter an email address");
			document.forms[0].email.focus();
			return false;			
		} else
		if (num_nights == "") {
			alert("Please select a number of nights");
			document.forms[0].num_nights.focus();
			return false;
		} else
		if (num_guests == "") {
			alert("Please select a number of guests");
			document.forms[0].num_guests.focus();
			return false;
		} else
		if(email.length > 0) {
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) {
				return Validate_date();
			}
			alert("Invalid E-mail Address! Please re-enter.");
			document.forms[0].email.focus();
			return false;			
		} else {
			return true;
		}

}

//opens a new window for the booking status steps explanation
	function openWin (val) { 
		var popup = null;
		popup = window.open('', '', 'width=1000,height=500,resizable=0,scrollbars=yes,left=2,top=2,alwaysLowered=no,alwaysRaised=yes');
		if (popup != null) {
			if (popup.opener == null) {
				popup.opener = self;
			}
			if (val == "view") {
				popup.location.href = "edits/steps_nohref.htm";
			} else {
				popup.location.href = "edits/steps.htm";
			}
		}
	} 
	
	
function pick(step, phase) {
	if (window.opener && !window.opener.closed) {
		window.opener.document.forms[0].booking_status.value = step;
		window.opener.document.forms[0].enquiry_phase.value = phase;		
		window.close();
	}
}


	
function change_status() {
	booking_status = document.forms[0].booking_status.value;
	if ((booking_status == "1 - Enquiry")||(booking_status == "2 - FOLLOW UP CALL")||(booking_status == "3 - OFFER SENT")||(booking_status == "4 - CORRESPONDENCE")||(booking_status == "5 - CHALET ON HOLD")||(booking_status == "6 - OFFER REMINDER")||(booking_status == "7 - GUEST CONFIRMED")||(booking_status == "8 - CONTRACT SENT")||(booking_status == "9 - CONTRACT SIGNED")||(booking_status == "10 - DEPOSIT REMINDER")||(booking_status == "11 - DEPOSIT PAID")||(booking_status == "12 - DEPOSIT CONFIRMED")) {
		phase = "Pre-booking Phase";
		document.forms[0].enquiry_phase.value = phase;				
	}else if ((booking_status == "13 - CONCIERGE REQUEST")||(booking_status == "14 - CONCIERGE RESPONSE")||(booking_status == "15 - FINAL CONSULTATION")||(booking_status == "16 - BALANCE REQUESTED")||(booking_status == "17 - BALANCE PAID")||(booking_status == "18 - DEPARTURE PACK SENT")||(booking_status == "19 - ARRIVAL REMINDER")||(booking_status == "20 - IN RESORT")||(booking_status == "21 - FINAL BILLING")){
		phase = "Delivery Phase";
		document.forms[0].enquiry_phase.value = phase;				
	}else{
		phase = "Follow-up Phase";
		document.forms[0].enquiry_phase.value = phase;						
	}
}

	function chk_img_request() {
		var name = document.forms[0].name.value;
		var email = document.forms[0].email.value;
		var phone = document.forms[0].phone.value;
		var company = document.forms[0].company.value;
		var reason = document.forms[0].reason.value;

		if (name == "") {
			alert("Please enter your name");
			document.forms[0].name.focus();
			return false;
		} else
		if (email == "") {
			alert("Please enter your email address");
			document.forms[0].email.focus();
			return false;
		} else
		if (phone == "") {
			alert("Please enter your phone number");
			document.forms[0].phone.focus();
			return false;			
		} else		
		if (company == "") {
			alert("Please enter your company name");
			document.forms[0].company.focus();
			return false;
		} else		
		if (reason == "") {
			alert("Please enter a reason for requesting this image");
			document.forms[0].reason.focus();
			return false;
		} else		
		if(email.length > 0) {
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) {
				return Validate_date();
			}
			alert("Invalid E-mail Address! Please re-enter.");
			document.forms[0].email.focus();
			return false;
		}
	}	
	
//check for adding a new user	
	function chk_user() {
		var name = document.forms[0].name.value;
		var password_new = document.forms[0].password_new.value;				
		var email_new = document.forms[0].email_new.value;
		var validity = document.forms[0].validity[document.forms[0].validity.selectedIndex].value;		
				
		if (name == "") {
			alert("Please enter a name");
			document.forms[0].name.focus();
			return false;
		} else
		if (password_new == "") {
			alert("Please enter a password");
			document.forms[0].password_new.focus();
			return false;
		} else
		if (email_new == "") {
			alert("Please enter an email address");
			document.forms[0].email_new.focus();
			return false;
		} else
		if (validity == "") {
			alert("Please select password validity");
			document.forms[0].validity.focus();
			return false;
		} else	
		if(email_new.length > 0) {
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email_new)) {
				return true;
			}
			alert("Invalid E-mail Address! Please re-enter.");
			document.forms[0].email_new.focus();
			return false;
		} else {
			return true;
		}
	}	
	
