var requiredFields = new Array("txtGBXUserIdForLogin", "txtPasswordForLogin");
var fieldNames = new Array("Login ID", "Password");   
var FormOK = GBXUserIdOK = PasswordOK = true;


function checkFields(input) {

	if (!(checkRequiredFieldsBC(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 checkPassword(checkString) 
{
	//also check for spaces here
	//var tot2=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") )  )
	//	{
	//   tot2=tot2+1;
	//	}
	//}
	
	//if (tot2>=1)
	//{
	//	alert('Do not use Spaces or AlphaNumeric Characters in the Password field');    	
	//	document.AForm.txtPassword.value = "" ;
	//}
	
	//removed - small number users have passwords less than 4 or greater than 8 characters
	//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 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.AForm2.txtPassword.value = "" ;
	}
	
	if ((checkString.length >= 4) && (checkString.length <=8)) 
		{ return checkString; }
	else
		{ 
		 alert('Invalid Password, Password must be 4 - 8 characters in length');
		 document.AForm2.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');
		////alert('Please Enter Only AlphaNumeric Characters in the Password field');
		alert('Do not use Spaces or AlphaNumeric Characters in the Password field');    
		document.AForm.elements[fieldname].value = "" ;
	}
}


//-------------------------------------------------------------------------------------------------------------
//---------------------------------------------- Registration -------------------------------------------------
//-------------------------------------------------------------------------------------------------------------

var requiredFields2 = new Array("txtFirstName", "txtLastName", "txtAddress", "txtCity", "txtState","txtZIP", "txtPhone1", "txtEmail", "txtGBXUserId", "txtPassword");
var fieldNames2 = new Array("First Name", "Last Name", "Address", "City", "Region / State / Province", "Zip / Postal Code", "Telephone", "Email Address", "Login ID", "Password");   
var FormOK2 = FNameOK2 = LNameOK2 = AddOK2 = CityOK2 = StateOK2 = ZipOK2 = PhoneOK2 = EmailOK2 = GBXUserIdOK2 = PasswordOK2 = true;


function checkFields2(input) {

	ut = (document.AForm2.userType.selectedIndex)-0;
	if (ut == 0){
		if (document.AForm2.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.AForm2.txtGBXUserId.length; a++) {
        ch = document.AForm2.txtGBXUserId.substring(a, a+1);
		if ((ch==" ") || (ch=="'") ))
			{
				alert('This Login ID contains incompatable characters');
				return(false);
			}
	}
	for (b = 0; b < document.AForm2.txtPassword.length; b++) {
        ch = document.AForm2.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.AForm2.txtPassword.value = "" ;  	
				return(false);
			}
	}
	*/
	//alert("after FOR LOOP")
	//end of ' in userId and password check
	if (!(checkRequiredFieldsBC2(input))) {return false;}	
	if (!(FNameOK2)) { alert("The First Name field requires valid input"); return false; }
	if (!(LNameOK2)) { alert("The Last Name field requires valid input"); return false; }
	if (!(AddOK2)) { alert("The Address field requires valid input"); return false; }
	if (!(CityOK2)) { alert("The City field requires valid input"); return false; }
	if (!(StateOK2)) { alert("The Region / State / Province field requires valid input"); return false; }
	if (!(ZipOK2)) { alert("The ZIP / Postal Code field requires valid input"); return false; }
	if (!(PhoneOK2)) { alert("The Telephone field requires valid input - Phone Format: 1112223333"); return false; }
	if (!(EmailOK2)) { alert("The Email Address field requires valid input"); return false; }
	if (!(GBXUserIdOK2)) { alert("The Login ID field requires valid input"); return false; }
	if (!(PasswordOK2)) { alert("The Password field requires valid input"); return false; }
	else {
	return true; 
	}
}	
		
function checkRequiredFieldsBC2(input)
{             
   
    var fieldCheck   = true;
    var fieldsNeeded = "\nA value must be entered in the following field(s):\n\n\t";

    for(var fieldNum=0; fieldNum < requiredFields2.length; fieldNum++) {
        if ((input.elements[requiredFields2[fieldNum]].value == "") ||
            (input.elements[requiredFields2[fieldNum]].value == " ")) {

            fieldsNeeded += fieldNames2[fieldNum] + "\n\t";
            fieldCheck = false;
        }
    }
  
    if (fieldCheck == true)
    {
		FormOK2 = true
        return true;
    }

    else
    {
		FormOK2 = 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);
	
		//alert("c: " + c);
		//ck for blank
		//if (c == " ") {
		//	alert("blank");
		//	return false;
		//}
		
	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 empty space
		//while ((i < sLength) && (trim(s).charAt(i) != " "))
		//{ i++
		//alert("i: " + i);
		//}

		//if ((i >= sLength) || (trim(s).charAt(i) != " ")) return alert('Invalid Email Address - please remove spaces'); //false;
		//else i += 2;
    
    
    // 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 brokerRegistrationRedirect() {
	
	////userTypeValue = document.AForm2.userType.value

	//utRed = (document.AForm2.userType.selectedIndex)-0;
	utRed = document.getElementById("foo").selectedIndex;
	
	if (utRed == 3){
		//alert('userType Value is ' + userTypeValue);
		//location.replace("http://www.globalbx.com/intregistration.asp");
		location.replace("intregistration.asp");
	}	
	
} 	

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/*
==================================================================
LTrim(string) : Returns a copy of a string without leading spaces.
==================================================================
*/
function LTrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

/*
==================================================================
RTrim(string) : Returns a copy of a string without trailing spaces.
==================================================================
*/
function RTrim(str)
/*
   PURPOSE: Remove trailing blanks from our string.
   IN: str - the string we want to RTrim

*/
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}

/*
=============================================================
Trim(string) : Returns a copy of a string without leading or trailing spaces
=============================================================
*/
function Trim(str)
/*
   PURPOSE: Remove trailing and leading blanks from our string.
   IN: str - the string we want to Trim

   RETVAL: A Trimmed string!
*/
{
   return RTrim(LTrim(str));
}


function Focus()
{
    document.AForm.txtGBXUserIdForLogin.focus(); 
}
