// signupformtest.js

//function to check passwords
function comparePasswords() {
	if (document.forms[0].password1.value == document.forms[0].password2.value) {
		return true;
	}
	else {
		alert("The passwords that you typed in do not match. Please retry.");
		document.forms[0].password1.value = "";
		document.forms[0].password2.value = "";
		document.forms[0].password1.focus();
		return false;
	}
}

//check confirmed email
function compareEmail() {
	if (document.forms[0].em.value == document.forms[0].em2.value) {
		return true;
	}
	else {
		alert("The login emails that you typed in do not match. Please retry.");
		document.forms[0].em2.focus();
		return false;
	}
}

//function to check valid email address
function isValidEmail(){
  	validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
  	strEmail = document.forms[0].em.value;

   // search email text for regular exp matches
    if (strEmail.search(validRegExp) == -1) {
      alert('A valid e-mail address is required.\nPlease amend and retry');
	  document.forms[0].em.focus();
      return false;
    } 
    return true; 
}

//function that performs all functions, defined in the onsubmit event handler

function signupformtest(form){
	strfield1   =  document.forms[0].nm.value;
	strfield2   =  document.forms[0].cp.value;
	strfield3   =  document.forms[0].p1.value;
	strfield4   =  document.forms[0].p2.value;
	strfield5   =  document.forms[0].em.value;
	strfield6   =  document.forms[0].z1.value;
	
	strfield7   =  document.forms[0].a1.value;
	strfield8   =  document.forms[0].a2.value;

	strfield9   =  document.forms[0].cy.value;

	strfield10  =  document.forms[0].f1.value;
	strfield11  =  document.forms[0].f2.value;
	strfield12  =  document.forms[0].st.value;

	strfield13 	=	document.forms[0].em2.value;
	strfield14 	=	document.forms[0].password1.value;
	strfield15 	=	document.forms[0].password2.value;


  //name field
    if (strfield1 == "" || strfield1 == null || !isNaN(strfield1) || strfield1.charAt(0) == ' '){
		alert("\"Name\" is a mandatory field. Please amend and retry.");
		document.forms[0].nm.focus();
		return false;
    }

  //company field 
    if (strfield2 == "" || strfield2 == null || strfield2.charAt(0) == ' ')
    {
		alert("\"Company\" is a mandatory field. Please amend and retry.");
		document.forms[0].cp.focus();
		return false;
    }

  //address area field 
    if (strfield7 == "" || strfield7 == null || strfield7.charAt(0) == ' ' )
    {
		alert("\"Address\" is a mandatory field. Please amend and retry.");
		document.forms[0].a1.focus();
		return false;
    }

  //city field 
    if (strfield9 == "" || strfield9 == null || strfield9.charAt(0) == ' ')
    {
		alert("\"City\" is a mandatory field. Please amend and retry.");
		document.forms[0].cy.focus();
		return false;
    }

  //state field 
    if (strfield12 == "")
    {
		alert("\"State\" is a mandatory field. Please amend and retry.");
		document.forms[0].st.focus();
		return false;
    }

    // zip field
	if (isNaN(strfield6) || strfield6.length != 5){
		alert("\"Zip\" must be a 5-digit numeric entry. Please amend and retry.");
		document.forms[0].z1.focus();
		return false;
	}


  //Phone area field 
    if (strfield3 == "" || strfield3 == null || strfield3.charAt(0) == ' ' || isNaN(strfield3) )
    {
		alert("\"Phone area\" is a mandatory field. Please amend and retry.");
		document.forms[0].p1.focus();
		return false;
    }
	
  //Phone field 
    if (strfield4 == "" || strfield4 == null || strfield4.charAt(0) == ' ' || isNaN(strfield4) )
    {
		alert("\"Phone\" is a mandatory field. Please amend and retry.");
		document.forms[0].p2.focus();
		return false;
    }

   // fax field
 	if (strfield10 != "" && strfield10 != null){
		if(isNaN(strfield10)){
			alert("\"Fax area\" must be a numeric entry. Please amend and retry.");
			document.forms[0].f1.focus();
			return false;
		}
	}
	if (strfield11 != "" && strfield11 != null){
		if(isNaN(strfield11)){
			alert("\"Fax\" must be a numeric entry. Please amend and retry.");
			document.forms[0].f2.focus();
			return false;
		}
	}
    
	if(((strfield10 != "" && strfield10 != null) && (strfield11 == "" || strfield11 == null)) ||
	   ((strfield11 != "" && strfield11 != null) && (strfield10 == "" || strfield10 == null))) {
			alert("\"Fax\" entry must have area code.");
			document.forms[0].f1.focus();
			return false;
	}

  //E-mail field 
    if (strfield5 == "" || strfield5 == null || strfield5.charAt(0) == ' ') {
	    alert("\"E-mail\" is a mandatory field. Please amend and retry.");
		document.forms[0].em.focus();
    	return false;
    }

  //confirm E-mail field
    if (strfield13 == "" || strfield13 == null || strfield13.charAt(0) == ' '){
		alert("\"Confirm E-mail\" is a mandatory field. Please amend and retry.");
		document.forms[0].em2.focus();
		return false;
    }

  //Password 1 field
    if (strfield14 == "" || strfield14 == null || strfield14.charAt(0) == ' '){
		alert("\"Desired Password\" is a mandatory field. Please amend and retry.");
		document.forms[0].password1.focus();
		return false;
    }

  //Password 2 field
    if (strfield15 == "" || strfield15 == null || strfield15.charAt(0) == ' '){
		alert("\"confirm Password\" is a mandatory field. Please amend and retry.");
		document.forms[0].password2.focus();
		return false;
    }

  //check valid email
	if (!isValidEmail()){
		return false;
	}

	if (!compareEmail()){
		return false;
	}

	if (!comparePasswords()) {
		return false;
	}

	if (document.forms[0].uwebid.checked == false) {
		if (confirm("Do you want to sign up to use IQWeb?")) {
			document.forms[0].uwebid.checked = true;
		}
	}
	return true;
}



//edit user info submit test

function editformtest(form){
	strfield1   =  document.forms[0].nm.value;
	strfield2   =  document.forms[0].cp.value;
	strfield7   =  document.forms[0].a1.value;
	strfield9   =  document.forms[0].cy.value;
	strfield12  =  document.forms[0].st.value;
	strfield6   =  document.forms[0].z1.value;
	strfield3   =  document.forms[0].p1.value;
	strfield10  =  document.forms[0].f1.value;

  //name field
    if (strfield1 == "" || strfield1 == null || !isNaN(strfield1) || strfield1.charAt(0) == ' '){
		alert("\"Name\" is a mandatory field. Please amend and retry.");
		document.forms[0].nm.focus();
		return false;
    }

  //company field 
    if (strfield2 == "" || strfield2 == null || strfield2.charAt(0) == ' ')
    {
		alert("\"Company\" is a mandatory field. Please amend and retry.");
		document.forms[0].cp.focus();
		return false;
    }

  //address area field 
    if (strfield7 == "" || strfield7 == null || strfield7.charAt(0) == ' ' )
    {
		alert("\"Address\" is a mandatory field. Please amend and retry.");
		document.forms[0].a1.focus();
		return false;
    }

  //city field 
    if (strfield9 == "" || strfield9 == null || strfield9.charAt(0) == ' ')
    {
		alert("\"City\" is a mandatory field. Please amend and retry.");
		document.forms[0].cy.focus();
		return false;
    }

   // zip field
	if (isNaN(strfield6) || strfield6.length != 5){
		alert("\"Zip\" must be a 5-digit numeric entry. Please amend and retry.");
		document.forms[0].z1.focus();
		return false;
	}

  //Phone area field 
    if (strfield3 == "" || strfield3 == null || strfield3.charAt(0) == ' ' || isNaN(strfield3) )
    {
		alert("\"Phone area\" is a mandatory field. It has no space, no dash, no parenthesis including area code. Please amend and retry.");
		document.forms[0].p1.focus();
		return false;
    }

   // fax field
	if (strfield10 != "" && strfield11 != nul0){
		if(isNaN(strfield11)){
			alert("\"Fax\" must be a numeric entry. Please amend and retry.");
			document.forms[0].f2.focus();
			return false;
		}
	}
    
	return true;
}

function clearAllBoxes() {
	document.forms[0].nm.value = "";
	document.forms[0].cp.value = "";
	document.forms[0].a1.value = "";
	document.forms[0].a2.value = "";
	document.forms[0].cy.value = "";
	document.forms[0].z1.value = "";
	document.forms[0].p1.value = "";
	document.forms[0].ext.value = "";
	document.forms[0].f1.value = "";
	document.forms[0].bu.value = "";
	setFocus(document.getElementById('nm'))
}