﻿function check_loginForm(formObj) 
{	
	if (emptyField(formObj.login_userName)) {window.alert("Please enter User Name");formObj.login_userName.focus();return false;}		
	if (emptyField(formObj.login_password)){window.alert("Please enter Password"); formObj.login_password.focus();	return false;}
}
function check_registerForm(formObj) 
{	
    var register_password = formObj.register_password.value;
	var re_password = formObj.re_password.value;
	
	//if (emptyField(formObj.register_title)) {window.alert("The field Title is mandatory");formObj.register_title.focus();return false;}
	if (emptyField(formObj.register_firstName)) {window.alert("The field First Name is mandatory");formObj.register_firstName.focus();return false;}				
	if (emptyField(formObj.register_lastName)) {window.alert("The field Last Name is mandatory");formObj.register_lastName.focus();return false;}
	//if (emptyField(formObj.register_position)) {window.alert("The field Position Name is mandatory");formObj.register_position.focus();return false;}
	if (emptyField(formObj.register_companyName)) {window.alert("The field Company Name is mandatory");formObj.register_companyName.focus();return false;}
	//if (emptyField(formObj.register_companyAddress)) {window.alert("The field Company Address is mandatory");formObj.register_companyAddress.focus();return false;}
	//if (emptyField(formObj.register_city)) {window.alert("The field City is mandatory");formObj.register_city.focus();return false;}
	//if (emptyField(formObj.register_state)) {window.alert("The field State is mandatory");formObj.register_state.focus();return false;}
	//if (emptyField(formObj.register_zipCode)) {window.alert("The field Zip Code is mandatory");formObj.register_zipCode.focus();return false;}
	//if (emptyField(formObj.register_countryID)) {window.alert("The field Country is mandatory");formObj.register_countryID.focus();return false;}
	if (emptyField(formObj.register_phone)) {window.alert("The field Phone is mandatory");formObj.register_phone.focus();return false;}
	//if (emptyField(formObj.register_fax)) {window.alert("The field Fax is mandatory");formObj.register_fax.focus();return false;}
	if (emptyField(formObj.register_email)) {window.alert("The field Email is mandatory");formObj.register_email.focus();return false;}
	if (formObj.register_email.value!='' && !checkEmail(formObj.register_email.value)) {alert("Please enter valid Email address");formObj.register_email.select();return false;}		
	if (emptyField(formObj.register_userName)) {window.alert("The field User Name is mandatory");formObj.register_userName.focus();return false;}
	if (formObj.register_userName.value.length < 4){window.alert("The field User Name must be minimum of 4 characters in length");formObj.register_userName.focus();return false;}		
	if (emptyField(formObj.register_password)) {window.alert("The field Password is mandatory");formObj.register_password.focus();return false;}
	if (formObj.register_password.value.length < 4){window.alert("The field Password must be minimum of 4 characters in length");formObj.register_password.focus();return false;}		
	if (emptyField(formObj.re_password)){window.alert("Please type the Password again to confirm");formObj.re_password.focus();return false;}	
	if (register_password != re_password){window.alert("The passwords you typed do not match.Please retype the new password in both boxes.");formObj.re_password.select();return false;}	
}
function check_updateForm(formObj) 
{	
	if (emptyField(formObj.update_title)) {window.alert("The field Title is mandatory");formObj.update_title.focus();return false;}
	if (emptyField(formObj.update_firstName)) {window.alert("The field First Name is mandatory");formObj.update_firstName.focus();return false;}				
	if (emptyField(formObj.update_lastName)) {window.alert("The field Last Name is mandatory");formObj.update_lastName.focus();return false;}
	if (emptyField(formObj.update_position)) {window.alert("The field Position Name is mandatory");formObj.update_position.focus();return false;}
	if (emptyField(formObj.update_companyName)) {window.alert("The field Company Name is mandatory");formObj.update_companyName.focus();return false;}
	if (emptyField(formObj.update_companyAddress)) {window.alert("The field Company Address is mandatory");formObj.update_companyAddress.focus();return false;}
	if (emptyField(formObj.update_city)) {window.alert("The field City is mandatory");formObj.update_city.focus();return false;}
	if (emptyField(formObj.update_state)) {window.alert("The field State is mandatory");formObj.update_state.focus();return false;}
	if (emptyField(formObj.update_zipCode)) {window.alert("The field Zip Code is mandatory");formObj.update_zipCode.focus();return false;}
	if (emptyField(formObj.update_countryID)) {window.alert("The field Country is mandatory");formObj.update_countryID.focus();return false;}
	if (emptyField(formObj.update_phone)) {window.alert("The field Phone is mandatory");formObj.update_phone.focus();return false;}
	if (emptyField(formObj.update_fax)) {window.alert("The field Fax is mandatory");formObj.update_fax.focus();return false;}
	if (emptyField(formObj.update_email)) {window.alert("The field Email is mandatory");formObj.update_email.focus();return false;}
	if ( formObj.update_email.value!='' && !checkEmail(formObj.update_email.value)) {alert("Please enter valid Email address");formObj.update_email.select();return false;}		
	if (emptyField(formObj.update_userName)) {window.alert("The field User Name is mandatory");formObj.update_userName.focus();return false;}
	
}
function check_contactForm(formObj) 
{	
	if (emptyField(formObj.contact_firstName)) {window.alert("The field First Name is mandatory");formObj.contact_firstName.focus();return false;}				
	if (emptyField(formObj.contact_lastName)) {window.alert("The field Last Name is mandatory");formObj.contact_lastName.focus();return false;}
	if (emptyField(formObj.contact_companyName)) {window.alert("The field Company Name is mandatory");formObj.contact_companyName.focus();return false;}
	if (emptyField(formObj.contact_phone)) {window.alert("The field Phone is mandatory");formObj.contact_phone.focus();return false;}
	if (emptyField(formObj.contact_fax)) {window.alert("The field Fax is mandatory");formObj.contact_fax.focus();return false;}
	if (emptyField(formObj.contact_email)) {window.alert("The field Email is mandatory");formObj.contact_email.focus();return false;}
	if (formObj.contact_email.value!='' && !checkEmail(formObj.contact_email.value)) {alert("Please enter valid Email address");formObj.contact_email.select();return false;}		
	
}
function check_notifyForm(formObj) 
{	
	if (emptyField(formObj.notify_firstName)) {window.alert("The field First Name is mandatory");formObj.notify_firstName.focus();return false;}				
	if (emptyField(formObj.notify_lastName)) {window.alert("The field Last Name is mandatory");formObj.notify_lastName.focus();return false;}
	if (emptyField(formObj.notify_phone)) {window.alert("The field Phone is mandatory");formObj.notify_phone.focus();return false;}
	if (emptyField(formObj.notify_email)) {window.alert("The field Email is mandatory");formObj.notify_email.focus();return false;}
	if (emptyField(formObj.notify_comments)) {window.alert("The field Comments is mandatory");formObj.notify_comments.focus();return false;}
	if ( formObj.notify_email.value!='' && !checkEmail(formObj.notify_email.value)) {alert("Please enter valid Email address");formObj.notify_email.select();return false;}		
	
}
function check_mailSelectionForm(formObj) 
{	
	if (emptyField(formObj.mailSelection_email)) {window.alert("The field Email is mandatory");formObj.mailSelection_email.focus();return false;}
	if ( formObj.mailSelection_email.value!='' && !checkEmail(formObj.mailSelection_email.value)) {alert("Please enter valid Email address");formObj.mailSelection_email.select();return false;}		
}

function check_updatePassword(formObj){
  var password = formObj.memberPassword.value;
  var re_password = formObj.re_password.value;
  if (formObj.currentPassword.value==''){alert("Please type your current password");formObj.currentPassword.focus();return false;}
  if (formObj.memberPassword.value==''){alert("Please type a new password");formObj.memberPassword.focus();return false;}
  if (formObj.memberPassword.value.length < 4){window.alert("The field Password must be minimum of 4 characters in length");formObj.memberPassword.focus();return false;}		
  if (emptyField(formObj.re_password)){window.alert("Please type the new password again to confirm");formObj.re_password.focus();return false;}	
  if (password != re_password){window.alert("The passwords you typed do not match.Please retype the new password in both boxes.");formObj.re_password.select();return false;}	
}
function emptyField(textObj){
	if (textObj.value.length == 0) return true;
	for (var i=0; i<textObj.value.length; i++) {
		var ch = textObj.value.charAt(i);
		if (ch != ' ' && ch != '\t') return false;	
	}
	return true;	
}
//*************************************************************************************
// trim - this function deletes spaces around the string.
//*************************************************************************************
String.prototype.trim = function(){return this.replace(/(^\s*)|(\s*$)/g, "");}
function MM_openBrWindow(theURL,winName,features){window.open(theURL,winName,features);}
//return false if email is not valid ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function checkEmail(checkThisEmail){
var myEMailIsValid = true;
var myAtSymbolAt = checkThisEmail.indexOf('@');
var myLastDotAt = checkThisEmail.lastIndexOf('.');
var mySpaceAt = checkThisEmail.indexOf(' ');
var myLength = checkThisEmail.length;
if (myAtSymbolAt < 1 ){myEMailIsValid = false}
if (myLastDotAt < myAtSymbolAt){myEMailIsValid = false}
if (myLength - myLastDotAt <= 2){myEMailIsValid = false}
if (mySpaceAt != -1){myEMailIsValid = false}
   return myEMailIsValid
}


function clearForm(){document.forms[0].reset();}
function checkNumbers(){
// 32=space, 45="-", 65-90=Highercase, 97-122=Lowercase, 48-57=Numbers (0-9), 1488-1514=Hebrew, 64=@ , 34= ", 39= '
   if ((event.keyCode > 0 && event.keyCode < 45)  || 
       (event.keyCode >= 46 && event.keyCode < 48)  || 
      (event.keyCode > 57))
 {   
   event.returnValue = false;
   alert("Enter valid number or '-'")
 }
}
function checkLettersAndNumbers(){
// 32=space, 45="-", 65-90=Highercase, 97-122=Lowercase, 48-57=Numbers (0-9), 1488-1514=Hebrew, 64=@ , 34= ", 39= '
   if ((event.keyCode > 57 && event.keyCode < 65) || (event.keyCode > 90 && event.keyCode < 97) || (event.keyCode < 48) || (event.keyCode > 122))
 {   
   event.returnValue = false;
   alert("Must be numbers(0-9) or characters (a-z,A-Z) only")
 }
}

