function ValidateFlds() {
var emptyFields = "";
var firstpwd = -1;
var errors = "";
var msg = "";
var count = 0; //
var country = "" ;

var browser = new Object();
browser.isNavigator = false;
browser.isIE = false;
if(navigator.appName.indexOf("Netscape")!=-1){
   browser.isNavigator = true;
}else{
   browser.isIE = true;
}

if(document.forms[0].bcountry){
   if(browser.isNavigator){
     for(var i=0;i<document.forms[0].bcountry.length;i++){
         if(document.forms[0].bcountry.options[i].selected){
            country = document.forms[0].bcountry.options[i].value;
            break;
         }
      }
   }else{
      country = document.forms[0].bcountry.value;
   }

   if ((isBlank(country)))
      emptyFields += "\n        country";
}


for (var tmp = 0; tmp < document.forms[0].length; tmp++)
{
var item = document.forms[0].elements[tmp];
if (((item.type == "text") || (item.type == "textarea") || (item.type == "password")) && (!item.optional))
	{
		if ((item.value == null) || (item.value == "") || isBlank(item.value))
		   	emptyFields += "\n        " + item.name;
	}

//V.P. 02/22/2000
//Do some checking when the country selected is U.S

if (document.forms[0].name == "gepsregbeg") {
   if( (item.type == "text") && (item.name == "PostalCode")  && (country == "US") ){
      if(!checkZipCodeForUS(item.value))
         errors +="\n- Postal Code (required for U.S.) should contain at least 5 digits";
   }
   if( (item.type == "text") && (item.name == "BusinessPhone") &&  (item.value != "") ){
      if(!checkPhoneForUS(item.value) && (country == "US") ){
         errors +="\n- The Business Phone number is not a valid U.S. phone number. It should contain 10 digits (e.g. (510)222-2222)";
      }else{
         if( !checkNonUSPhoneNumber(item.value) )
            errors +="\n- The Business Phone Number is not a valid phone number. It should contain no more than 25 digits and delimiters (e.g. +40 92 534 773)";
      }
   }
   if( (item.type == "text") && (item.name == "Mobile") && (item.value != "")  ){
      if(!checkPhoneForUS(item.value) && (country == "US") ){
         errors +="\n- The Mobile Phone number is not valid U.S. mobile phone number. It should contain 10 digits (e.g. (510)222-2222)";
      }else{
         if( !checkNonUSPhoneNumber(item.value) )
            errors +="\n- The Mobile Phone Number is not a valid mobile phone number. It should contain no more than 25 digits and delimiters (e.g. +40 92 534 773)";
      }
   }
   if( (item.type == "text") && (item.name == "Fax")   && (item.value != "")  ){
      if(!checkPhoneForUS(item.value) && (country == "US") ){
         errors +="\n- The Fax number is not valid U.S. fax phone number. It should contain 10 digits (e.g. (510)222-2222)";
      }else{
         if( !checkNonUSPhoneNumber(item.value) )
            errors +="\n- The Fax Number is not a valid fax phone number. It should contain no more than 25 digits and delimiters (e.g. +40 92 534 773)";
      }
   }
   if( (item.type == "text") && (item.name == "Pager") && (item.value != "")  ){
      if(!checkPhoneForUS(item.value) && (country == "US") ){
         errors +="\n- The Pager Phone number is not valid U.S. pager phone number. It should contains 10 digits (e.g. (510)222-2222)";
      }else{
         if( !checkNonUSPhoneNumber(item.value) )
            errors +="\n- The Pager Phone Number is not a valid pager phone number. It should contain no more than 25 digits and delimiters (e.g. +40 92 534 773)";
      }
   }
   if( (item.type == "text") && (item.name == "State") &&  (country == "US")  ){
      if(!checkStateNameForUS(item.value))
         errors += "\n- State Name (required for U.S.) should contain only 2 characters (e.g. CA for California)";
   }
   if( (item.type == "text") && (item.name == "HomeEmail") && (item.value != "") ){
      if(!checkEmail(item.value))
         errors += "\n- Your Home E-mail address seems incorrect. It doesn't contain '@' sign!";
   }
   if( (item.type == "text") && (item.name == "PagerEmail") && (item.value != "") ){
      if(!checkEmail(item.value) )
         errors += "\n- Your Pager E-mail address seems incorrect. It doesn't contain '@' sign!";
   }
   if( (item.type == "text") && (item.name == "Extension") && (item.value != "") ){
      if(!checkExtension(item.value))
         errors +="\n- Your Extension should contain not more than 5 digits";
   }

} //end of gepsregbeg validation

if (document.forms[0].name == "corpregbeg") {
   if( (item.type == "text") && (item.name == "Email") && (item.value != "") ){
      if (!checkEmail(item.value))
         errors += "\n- Invalid format email address";
   }
   if (item.type == "password" && (item.value != "") )
	   {
	   if (firstpwd < 0)
		   firstpwd = tmp;
	   else
		   { //modified by V.P. 02/17/00
         if ( (item.value.length < 8) && (!emptyFields)){
            errors += "\n- Password should have at least 8 characters and contain at least one digit";
         }
         if (item.value.length > 7){
            var isDigit = false;
            for (var i = 0; i < item.value.length; i++){ //the 0(zero) is not parse as integer(I don't know why)
               if ( parseInt(item.value.charAt(i)) || item.value.charAt(i) == '0' ){
                  isDigit = true;
               //break;
               }
            }
         if(!isDigit)
            errors += "\n- Password should have at least 8 characters and contain at least one digit";
         }  //--
         if (item.value != document.forms[0].elements[firstpwd].value)
			   errors += "\n- Password and Re-type Password has to be the same";
         }
      }
} //end of corpregbeg form validation

if ((item.numeric == null) || (item.min == null) || (item.max != null))
   {}
else
	{
	var itemValue = parseFloat(item.value);
	if (isNaN(itemValue) ||
		((item.min != null) && (itemValue < item.min)) ||
		((item.max != null) && (itemValue > item.max)))
		 {
		 errors += "- The field " + item.name + "must be a number";
		 if (item.min != null)
			errors += " that is greater than " + item.min;
		 if ((item.max != null) && (item.min != null))
			errors += " and less than " + item.max;
		 else if (item.max != null)
			errors += " that is less than " + item.max;
		 errors += ".\n";
		 }
	}
}

if (!emptyFields && !errors) return true;

//msg =  "______________________________________________________\n\n";
msg += "The form was not submitted because of the following error(s).\n";
msg += "Please correct the error(s) and re-submit.\n\n  ";
//msg += "______________________________________________________\n\n";

if (emptyFields)
	msg += "- One or more of the required field(s) are empty"
		"\n";

if (errors)
	msg += errors + "\n";

alert(msg);
return false;

}
function isBlank(fieldString)
{
for (var tmp =0; tmp < fieldString.length; tmp++)
	{ var tmp1 = fieldString.charAt(tmp);
	if ((tmp1 != ' ') && (tmp1 != '\n') && (tmp1 != '\t'))
		return false;
	}
	return true;
}

function checkZipCodeForUS(zipCode){
   var regexp = /^\d{5}\-?\d{0,}$/
   var ok = regexp.exec(zipCode);
   if(ok)
      return true;
   else
      return false;
}
function checkPhoneForUS(phoneNumber){
   //var regexp  = /^[\(\s\W]*\d{3}[\)\s\W]*([-\/\.\s\W])*\d{3}([-\/\.\s\W])*\d{4}$/
   var regexp  = /^[\_\W]*\d{3}[\_\W]*(\_\W])*\d{3}([\_\W])*\d{4}[_\W]*$/
   var ok = regexp.exec(phoneNumber);
   if(ok)
      return true;
   else
      return false;
}
function checkStateNameForUS(stateName){
   var regexp = /^[A-Za-z]{2}$/
   if(stateName.length != 2 )
      return false;
   var ok = regexp.exec(stateName);
   if(!ok)
      return false;
   else
      return true;
}
function checkEmail(email){
   for (var i = 0; i< email.length; i++){
      if((email.charAt(i) == '@') && (i!=email.length-1)) 
              return true;
   }
   return false;
}
function checkEmail2(email){
   var regEmail = /^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/
   var ok = regEmail.exec(email);
   if(ok)
      return true;
   else
      return false;
}
function checkExtension(ext){
   var regexp = /^\d{1,5}$/
   var ok = regexp.exec(ext);
   if(ok)
      return true;
   else
      return false;
}
function checkNonUSPhoneNumber(phoneNumber){
   var regexp = /^[\W\_\d]{1,25}$/
   var ok = regexp.exec(phoneNumber);
   if(ok)
      return true;
   else
      return false;
}