	var requiredFields = new Array("txtFirstName", "txtLastName", "txtAddress", "txtCity", "txtState","txtZIP", "txtPhone1", "txtEmail", "txtGBXUserId", "txtPassword");
    var fieldNames = new Array("First Name", "Last Name", "Address", "City", "Region / State / Province", "Zip / Postal Code", "Telephone", "Email Address", "Login ID", "Password");   
	var FormOK = FNameOK = LNameOK = AddOK = CityOK = StateOK = ZipOK = PhoneOK = EmailOK = GBXUserIdOK = PasswordOK = true;

function checkFields(input) {

	ut = (document.AForm.userType.selectedIndex)-0;
	if (ut == 0){
		if (document.AForm.userType.value == "") { alert("The User Type field requires valid input"); return false;  }
	}
	//to check for ' in userId and password
	//alert("before FOR LOOP")
	/*
	for (a = 0; a < document.AForm.txtGBXUserId.length; a++) {
        ch = document.AForm.txtGBXUserId.substring(a, a+1);
		if ((ch==" ") || (ch=="'") ))
			{
				alert('This GlobalBX User ID contains incompatable characters');
				return(false);
			}
	}
	for (b = 0; b < document.AForm.txtPassword.length; b++) {
        ch = document.AForm.txtPassword.substring(b, b+1);
		if ((ch==" ") || (ch=="'") ))
			{
				////alert('This Password contains incompatable characters');
				alert('Do not use Spaces or AlphaNumeric Characters in the Password field');  
				document.AForm.txtPassword.value = "" ;  	
				return(false);
			}
	}
	*/
	//alert("after FOR LOOP")
	//end of ' in userId and password check
	if (!(checkRequiredFieldsBC(input))) {return false;}	
	if (!(FNameOK)) { alert("The First Name field requires valid input"); return false; }
	if (!(LNameOK)) { alert("The Last Name field requires valid input"); return false; }
	if (!(AddOK)) { alert("The Address field requires valid input"); return false; }
	if (!(CityOK)) { alert("The City field requires valid input"); return false; }
	if (!(StateOK)) { alert("The Region / State / Province field requires valid input"); return false; }
	//if (!(CountryOK)) { alert("The Country field requires valid input"); return false; }
	if (!(ZipOK)) { alert("The ZIP / Postal Code field requires valid input"); return false; }
	//if (!(PhoneOK)) { alert("The Telephone field requires valid input"); return false; }
	if (!(PhoneOK)) { alert("The Telephone field requires valid input - Phone Format: 1112223333"); return false; }
	if (!(EmailOK)) { alert("The Email Address field requires valid input"); return false; }
	if (!(GBXUserIdOK)) { alert("The Login ID field requires valid input"); return false; }
	if (!(PasswordOK)) { alert("The Password field requires valid input"); return false; }
	else {
	return true; 
	}
}	
		
function checkRequiredFieldsBC(input)
{             
   
    var fieldCheck   = true;
    var fieldsNeeded = "\nA value must be entered in the following field(s):\n\n\t";

    for(var fieldNum=0; fieldNum < requiredFields.length; fieldNum++) {
        if ((input.elements[requiredFields[fieldNum]].value == "") ||
            (input.elements[requiredFields[fieldNum]].value == " ")) {

            fieldsNeeded += fieldNames[fieldNum] + "\n\t";
            fieldCheck = false;
        }
    }
  
    if (fieldCheck == true)
    {
		FormOK = true
        return true;
    }

    else
    {
		FormOK = false
        alert(fieldsNeeded);
        return false;
    }
}

function toNumber(checkString)
		{
			newString = ""; 	  //if not, then massage the numbers
			// LOOP THROUGH STRING CHARACTER BY CHARACTER
			for (i = 0; i < checkString.length; i++) {
				ch = checkString.substring(i, i+1);

			 // CHECKS TO SEE IF A NUMBER IS BETWEEN 0 AND 9, or - 
				if ((ch >="0"  && ch <= "9"))
				{
				 newString += ch;
				 }
				}
	
				return newString;
		}
		
/*  checking for valid Phone or Fax*/
function isPhoneFax(checkString) {
	//	check for incompatable characters
    for (i = 0; i < checkString.length; i++) {
        ch = checkString.substring(i, i+1);
		//if (!((ch >="0"  && ch <= "9") || (ch==" ") || (ch=="-") || (ch=="(") || (ch==")") || (ch=="x") ))
		if (!((ch >="0"  && ch <= "9") || (ch==" ") || (ch=="-") || (ch=="(") || (ch==")") || (ch=="x") ))
			{
				alert('This Phone number contains incompatable characters');
				return(false);
			}
	}
	if (checkString.length >= 10 && checkString.length <=25)
		{
		return (true);
		}
	else 
		{ 
		alert('This Phone number is invalid'); 
		return (false);
		}
}		

// Check whether string s is empty.
function ifEmpty(s)
{   
	return ((s == null) || (s.length == 0))
}

// Returns true if string s is empty or 
// whitespace characters only.

function isWhitespace (s)
{   
	var i;
	var whitespace = " \t\n\r";
	
    // Is s empty?
    if (ifEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
	// Check that current character isn't whitespace.
	var c = s.charAt(i);

	if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

// isEmail (STRING s [, BOOLEAN emptyOK])
// 
// Email address must be of form a@b.c ... in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isEmail (s)
{   
	if (ifEmpty(s)) 
       if (isEmail.arguments.length == 1) return alert('Please Enter Email Address');
       else return (isEmail.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(s)) return alert('invalid email1'); //false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return alert('Invalid Email Address without  "@" '); //false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return alert('Invalid Email Address without  "." '); //false;
    else return true;
}		

function checkPassword(checkString) 
{
	if ((checkString.length >= 4) && (checkString.length <=8)) 
		{ return checkString; }
	else
		{ 
		 alert('Invalid Password, Password must be 4 - 8 characters in length');
		return (''); 
		}
}

function checkPassword2(checkString) 
{
	//also check for spaces here
	var tot3=0
	
	for (j = 0; j < checkString.length ; j++) 
	{
    	ch2 = checkString.substring(j, j+1);
        
	if (!( (ch2 >= "a" && ch2 <= "z") || (ch2 >= "A" && ch2 <= "Z" )  || (ch2 >="0"  && ch2 <= "9") )  )
		{
	   tot3=tot3+1;
		}
	}
	
	if (tot3>=1)
	{
		alert('Do not use Spaces or AlphaNumeric Characters in the Password field');    	
		document.AForm.txtPassword.value = "" ;
	}
	
	if ((checkString.length >= 4) && (checkString.length <=8)) 
		{ return checkString; }
	else
		{ 
		 alert('Invalid Password, Password must be 4 - 8 characters in length');
		 document.AForm.txtPassword.value = "" ;
		////return (''); 
		}	
}

function ForceStrings3(fieldvalue,fieldname){
	var tot=0
		for (i = 0; i < fieldvalue.length ; i++) 
		{
    		ch = fieldvalue.substring(i, i+1);
        
		if (!( (ch >= "a" && ch <= "z") || (ch >= "A" && ch <= "Z" )  || (ch >="0"  && ch <= "9") )  )
			{
		   tot=tot+1;
			//return(false);
			}
		}
	if (tot>=1)
	{
		alert('Please Enter Only AlphaNumeric Characters in ' + fieldname + ' field'); 
		document.AForm.elements[fieldname].value = "" ;
	}
} 

function brokerRegistrationRedirect() {
	
	////userTypeValue = document.AForm.userType.value

	utRed = (document.AForm.userType.selectedIndex)-0;
	if (utRed == 3){
		//alert('userType Value is ' + userTypeValue);
		//location.replace("http://www.globalbx.com/intregistration.asp");
		location.replace("intregistration.asp");
	}	
	
} 	