function enable_mobile_number(element) {

  if (element.value  != ""){
	if (document.account_form.cell_phone_number.value == " enter text...") {
	document.account_form.cell_phone_number.value = "";
	}
	document.account_form.cell_phone_number.disabled= false;
  }
  else {
	document.account_form.cell_phone_number.value = "";
    document.account_form.cell_phone_number.disabled= true;
  }

}
function remove_default_text(element) {
  if (element.value == " enter text...") {
	element.value="";
  }
}

function insert_default_text(element) {
  if (element.value.length ==0) {
	element.value = " enter text...";
  }
}
function validate_fields(edit_mode) {
  // If edit_mode = 1 then emails are not validated'\
  //  var regx_email = /(^([a-z A-Z0-9][a-zA-Z0-9_\-\.]+))((\.{1}\w+)*)(\@\w+)((\.\w{2,3})+)$/;
  var regx_email = /(^([a-zA-z]+)(\_?\w+)*((\-|\.|\_)?\w+)?(\_?\w+)*)(\@)([a-zA-Z0-9]+)((\-|\.)?([a-zA-Z0-9]))*((\.\w{2,3})+)$/;
  var regx_name =/^[a-zA-Z]([a-zA-Z0-9_\-\.']+)?/;
// 'regex for zip is 5 digits + optional 4 digits separated by hyphen
  var regx_zip = /^(\d{5})([\-](\d{4}))?$/;
  var regx_phone1 = /^\d{3}([\-])\d{3}([\-])\d{4}$/;
  var regx_phone2 = /^\d{3}([\.])\d{3}([\.])\d{4}$/;
  var regx_phone3 = /^\d{10}$/;
							 
							 if ((edit_mode != 1) &&  ((document.account_form.salutation.value == "") || (document.account_form.first_name.value == " enter text...") || (document.account_form.last_name.value == " enter text...") || (document.account_form.zip_code.value == " enter text...") ||(document.account_form.email_1.value == " enter text...") || (document.account_form.email_2.value == " enter text...")  || (document.account_form.password_1 == "") ||(document.account_form.password_2 == "") )) {
							   alert (' All fields marked with * are required.');
							   return false;
							 }

 if(document.account_form.salutation.value == "") {
	alert('Please select a salutation.');
	
	return false;
  }
  if ((document.account_form.first_name.value == " enter text...")  || (document.account_form.first_name.value == "" ) || ( ! regx_name.test(document.account_form.first_name.value))) {
	alert('Please enter a valid first name.');
	
    return false;
  }

  if ((document.account_form.last_name.value == " enter text...")  || (document.account_form.last_name.value == "" ) || (! regx_name.test(document.account_form.last_name.value)) ) {
    alert('Please enter a valid last name.');
    return false;
	
  }
							 if ((document.account_form.state.value == "")) {
							   alert ('Please select a state.');
							   return false;
							 }
							 if ((document.account_form.city.value != " enter text...") && ((document.account_form.city.value == "") || (! regx_name.test(document.account_form.city.value)))) {
							   alert ('Please enter a valid city.');
							   return false;
							 };

  if ((document.account_form.zip_code.value == " enter text...")  || (! regx_zip.test(document.account_form.zip_code.value) )) {
    alert('Please enter a valid zip code.');
	
  return false;
}
  var d = new Date();
  var curr_year = d.getFullYear();
  var regx_year = /^\d{4}$/;
  var strt_year = curr_year - 100;							 
    if ((document.account_form.year_of_birth.value > curr_year) || (!regx_year.test(document.account_form.year_of_birth.value)) || (document.account_form.year_of_birth.value < strt_year)) {
	alert ('Please enter a valid year of birth.');

	return false;

  }

if (edit_mode  != 1) {
if ((!regx_email.test(document.account_form.email_1.value)) || (document.account_form.email_1.value != document.account_form.email_2.value)) {
  alert('Please enter valid and matching email addresses.');

  return false;
}
}
							 // In edit mode passwords are not validated if the fields are empty

  if ((edit_mode  != 1) || (document.account_form.password_1.value != "") || (document.account_form.password_2.value != "")) {
	if (document.account_form.password_1.value.length<5) {
	  alert('Passwords must be atleast five characters long.');
	  return false;
	} else if (document.account_form.password_1.value != document.account_form.password_2.value) {
	  alert('Passwords do not match.');
	  return false;
	}
  }

  if ((document.account_form.cell_phone_carriers.value != '') && (!regx_phone1.test(document.account_form.cell_phone_number.value)) && (!regx_phone2.test(document.account_form.cell_phone_number.value)) && (!regx_phone3.test(document.account_form.cell_phone_number.value))) {
	alert('Please enter a valid phone number.');
	
	return false;
  }


  if (! document.account_form.tos_agreed.checked) {
	alert ('Please read the terms and conditions and mark the checkbox.');
	document.account_form.tos_agreed.focus();
	return false;
  }
  return  true;
}




