
function trimString (str) {
  return str.replace(/^\s+|\s+$/g, '');
}

function validateString(field, errmsg, lenmsg, min, max, required) { 
  if (!field.value && !required){
    return true;
  }
  
  if (!field.value){
    alert(errmsg);
    field.focus(); 
    field.select(); 
    return false;
  }
  
  if (trimString(field.value).length < min || field.value.length > max){
   alert(lenmsg);
    field.focus(); 
    field.select();
    return false;
  }
return true; 
}

function validateEmail(email, msg, required) { 
  if (!email.value && !required) { 
  return true; 
  } 
  
  var regEx = /^[\w-\.\+]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,6}$/; 
  if (!regEx .test(email.value)) { 
  alert(msg); 
  email.focus(); 
  email.select();
  return false; 
  } 
return true; 
}

function checkDropdown(errmsg,choice) {
  if (choice.selectedIndex == 0) {
     alert(errmsg);
     choice.focus();
    
   return false;
  }else{
	return true;
  }
}  

function isEmpty(errmsg,strng) {
  if (strng.value.length == 0) {
     alert(errmsg); 
     strng.focus(); 
     strng.select();
    return false;
  }else{
	return true;	  
  }
}

function checkPhone(phone,msg,msg1) {
if (phone.value.length == 0) {
   alert(msg);
   phone.focus(); 
   phone.select();
   return false;
}

var stripped = phone.value.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped)) && phone.value.length!=0) {
       alert(msg1);
	   phone.focus(); 
	   phone.select();
	   return false;
    }
    
return true;
}

function validatePwd(passwd1,passwd2,minlength) {
	var invalid = " "; // Invalid character is a space
	var pw1 = passwd1.value;
	var pw2 = passwd2.value;
	
	// check for minimum length
	if (pw1.length < minlength) {
	alert('Your password must be at least ' + minlength + ' characters long. Try again.');
	passwd1.focus(); 
	passwd1.select();
	return false;
	}
	// check for spaces
	if (pw1.indexOf(invalid) > -1) {
	alert("Sorry, spaces are not allowed.");
	passwd1.focus(); 
	passwd1.select();
	return false;
	}
	
	if (pw1 != pw2) {
		alert ("Your verification password did not match to your first password supplied.");
		passwd2.focus(); 
		passwd2.select();
		return false;
	}
	
	return true;
}

	function noLetters(e){ //onkeypress="return noLetters(event);"
		var keynum;
		var keychar;
		var filter;

		if(window.event) {// IE
			keynum = e.keyCode;
		}else if(e.which) {// Netscape/Firefox/Opera
			keynum = e.which;
		}
		keychar = String.fromCharCode(keynum);
		filter = /^([a-z]|[A-Z]|\+|_|-|\s|\||\?|\\|\*|\/|\[|\]|\{|\}|`|~|!|@|#|\$|%|\^|&|\(|\)|=|;|:|'|"|,|\.|\<|\>)*$/;

		return !filter.test(keychar);
	}
	
	function checkFreePlan(){
		var haswishlist = document.getElementById('hasFreePlan');
		if(haswishlist.value != '1'){
			alert('Please select at least one Floor Plan.');
		    return false;
		}
		return true;
	}
	

