function LeftTrim(String,TrimChar)
{
 // **********************************************************
 // This function trims spaces (default) or the specified
 // character from the left of a string or form field.
 // **********************************************************
 String += ""         // Force argument to string.
 TrimChar += ""       // Force argument to string.
 if((TrimChar == "") || (!(TrimChar.length == 1)))
  TrimChar = " "
 if(String.length == 0)
  return(String)
 var Count = 0
 for(Count = 0;Count < String.length;Count++)
 {
  if(!(String.charAt(Count) == TrimChar))
   return(String.substring(Count,String.length))
 }
 return("")
}

function RightTrim(String,TrimChar)
{
 // **********************************************************
 // This function trims spaces (default) or the specified
 // character from the right of a string or form field.
 // **********************************************************
 String += ""        // Force argument to string.
 TrimChar += ""      // Force argument to string.
 if((TrimChar == "") || (!(TrimChar.length == 1)))
  TrimChar = " "
 if(String.length == 0)
  return(String)
 var Count = 0
 for(Count = String.length -1;Count >= 0;Count--)
 {
  if(!(String.charAt(Count) == TrimChar))
   return(String.substring(0,Count + 1))
 }
 return("")
}

function AllTrim(String,TrimChar)
{
 //
 // This function trims spaces (default) or the specified
 // character from the left and the right of a string or form field.
 //
 // Note that this functions uses two other library functions,
 // LeftTrim() and RightTrim().
 // **********************************************************
 String += ""        // Force argument to string.
 TrimChar += ""      // Force argument to string.
 if((TrimChar == "") || (!(TrimChar.length == 1)))
  TrimChar = " "
 return(RightTrim(LeftTrim(String,TrimChar),TrimChar))
}


function  createSelectedCommaList(f)
{

  var comma_list = ""
  for (var idx = 0; idx < f.Prefs.length; idx ++){
        comma_list += f.Prefs.options[idx].value
        comma_list +=",";

	}
f.prod_list.value = comma_list
comma_list = ""
for (var idx = 0; idx < f.Prefs2.length; idx ++){
        comma_list += f.Prefs2.options[idx].value
	comma_list +=",";
	}

f.appl_list.value = comma_list


}



function verifyForgotPasswordForm(f)
{

   	 f['key.alpha'].optional = false;
         f['key.alpha'].min = "3";
         f['key.alpha'].max = "32";
         f['email.address'].min = "6";
         f['email.address'].max = "32";
         f['email.address'].optional = false;

    if (verifyForgotPassword(document.forms[1]) == true) {
    
              return true;
    }else{
    	      return false;
}

}


function verifyChangePasswordForm(f)
{


    if (verifyForgotPassword(document.forms[1]) == true) {
    	if (f['dm.newsletter_password'].value != f['password_confirm'].value) {
                   alert("Password and Password Confirm MUST be equal.");
                    return false;
            }


              return true;
    }else{
    	      return false;
}

}


function verifyLoginForm(f)
{

   	 f['username'].optional = false;
         f['password'].min = "3";
         f['password'].max = "32";
         f['password'].optional = false;

    if (verifyLogin(document.forms[1]) == true) {

              return true;
    }else{
    	      return false;
}

}


function verifyContactForm(f)
{

     f['dm.key.alpha'].optional = false;
     f['dm.key.alpha'].min = "6";
     f['dm.key.alpha'].max = "32";
     f['dm.key.alpha'].display = "Login Name";
     f['dm.newsletter_password'].min = "6";
     f['dm.newsletter_password'].max = "32";
     f['dm.newsletter_password'].optional = false;
     f['dm.newsletter_password'].display = "Password";
     f['password_confirm'].optional = false;
     f['password_confirm'].display = "Password Confirm";
     f['dm.email.address'].optional = false;
     f['dm.email.address'].display = "Email Address";
     f['dm.name.first'].optional = false;
     f['dm.name.first'].display = "First Name";
     f['dm.name.last'].optional = false;
     f['dm.name.last'].display = "Last Name";
     f["dm.company_name"].optional = false;
     f['dm.company_name'].display = "Company Name/Organization Name";
     f["dm.mail_stop"].optional = true;
     f["dm.address.business.first_line"].optional = true;
     f["dm.address.business.second_line"].optional = true;
     f["dm.address.business.city"].optional = true;
     f["dm.state"].optional = true;
     f["dm.address.business.postal_code"].optional = true;
     f["dm.phone.business.number"].optional = true;

     if (verify(f) == true) {
        if (f['dm.newsletter_password'].value != f['password_confirm'].value) {
           alert("Password and Password Confirm MUST be equal.");
            return false;
        }
	var invalid = " "; // Invalid character is a space
			// check for spaces
	if (f['dm.key.alpha'].value.indexOf(invalid) > -1){
	alert("Spaces are not allowed in the desired Login field.");
	return false;
	}	
	if ((f['dm.newsletter_password'].value.indexOf(invalid) > -1)|| (f['password_confirm'].value.indexOf(invalid) > -1)){
	alert("Spaces are not allowed in the Password field.");
	return false;
	}
     //  document.forms[1].key_alpha.value = document.forms[1].loginname.value;
      //  document.forms[1].dm_newsletter_password.value = document.forms[1].password.value;
//	createSelectedCommaList(f);
//	createPrefsList(f);
        return true;
    } else {
        return false;
    }
}






function verifyModifyForm(f)
{

     f['dm.newsletter_password'].min = "6";
     f['dm.newsletter_password'].max = "32";
     f['dm.newsletter_password'].optional = true;
     f['password_confirm'].optional = true;
     f['dm.email.address'].optional = false;
     f['dm.email.address'].display = "Email Address";
     f['dm.name.first'].optional = false;
     f['dm.name.first'].display = "First Name";
     f['dm.name.last'].optional = false;
     f['dm.name.last'].display = "Last Name";
     f["dm.company_name"].optional = false;
     f['dm.company_name'].display = "Company Name/Organization Name";
     f["dm.mail_stop"].optional = true;
     f["dm.address.business.first_line"].optional = true;
     f["dm.address.business.second_line"].optional = true;
     f["dm.address.business.city"].optional = true;
     f["dm.state"].optional = true;
     f["dm.address.business.postal_code"].optional = true;
     f["dm.phone.business.number"].optional = true;


     if (verifyModify(f) == true) {
 	if (f['dm.newsletter_password'].value != f['password_confirm'].value) {
           alert("Password and Password Confirm MUST be equal.");
            return false;
        }
	var invalid = " "; // Invalid character is a space
	// check for spaces
	if (f['dm.key.alpha'].value.indexOf(invalid) > -1){
	alert("Spaces are not allowed in Desired Login field.");
	return false;
	}	
	if ((f['dm.newsletter_password'].value.indexOf(invalid) > -1)|| (f['password_confirm'].value.indexOf(invalid) > -1)){
	alert("Spaces are not allowed in password field.");
	return false;
	}
     //  document.forms[1].key_alpha.value = document.forms[1].loginname.value;
      //  document.forms[1].dm_newsletter_password.value = document.forms[1].password.value;
//	createSelectedCommaList(f);
//	createPrefsList(f);
        return true;
    } else {
        return false;
    }
}


function  createPrefsList(f)
{
  var prefs = ""
  var prefs2 = ""
  for (var idx = 0; idx < f.Prefs.length; idx ++){
        prefs +="<option value=\"" + f.Prefs.options[idx].value + "\">" + f.Prefs.options[idx].text;
  //      prefs += "\n";

        //comma_list += f.Prefs.options[idx].value
        //comma_list +=",";

	}

for (var idx = 0; idx < f.Prefs2.length; idx ++){
        prefs2 +="<option value=\"" + f.Prefs2.options[idx].value + "\">" + f.Prefs2.options[idx].text;
  //      prefs2 += "\n";

	}

f.prefsOp.value = prefs;
f.prefs2Op.value = prefs2;

}

function rvnoMenuNewsletter(url) {
    window.location = url;
}

// A utility function that returns true if a string contains only
// whitespace characters.

// A utility function that returns true if a string contains only
// whitespace characters.
function isblank(s)
{
    for(var i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
    }
    return true;
}

function hasBlanks(s)
{
    for(var i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if ((c == ' ') && (c != '\n') && (c != '\t'))
        return true;
    }
    return false;
}



function emailCheck (emailStr) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailStr))
	return true;
else 
return false;

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

//emailStr = AllTrim(emailStr);
//var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

//var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

//var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address.
These characters include ( ) < > @ , ; : \ " . [ ] */

//var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a
username or domainname.  It really states which chars aren't allowed.*/

//var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

//var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

//var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

//var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

//var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

//var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

//var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

//var matchArray=emailStr.match(emailPat);

//if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

//alert("Email address seems incorrect (check @ and .'s)");
//return false;
//}
//var user=matchArray[1];
//var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

//for (i=0; i<user.length; i++) {
//if (user.charCodeAt(i)>127) {
//alert("Ths username contains invalid characters.");
//return false;
//   }
//}
//for (i=0; i<domain.length; i++) {
//if (domain.charCodeAt(i)>127) {
//alert("Ths domain name contains invalid characters.");
//return false;
//   }
//}

// See if "user" is valid

//if (user.match(userPat)==null) {

// user is not valid

//alert("The username in the Email Address	 doesn't seem to be valid.");
//return false;
//}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

//var IPArray=domain.match(ipDomainPat);
//if (IPArray!=null) {

// this is an IP address

//for (var i=1;i<=4;i++) {
//if (IPArray[i]>255) {
//alert("Destination IP address is invalid!");
//return false;
//   }
//}
//return true;
//}

// Domain is symbolic name.  Check if it's valid.

//var atomPat=new RegExp("^" + atom + "$");
//var domArr=domain.split(".");
//var len=domArr.length;
//for (i=0;i<len;i++) {
//if (domArr[i].search(atomPat)==-1) {
//alert("The domain name does not seem to be valid.");
//return false;
//   }
//}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding
the domain or country. */

//if (checkTLD && domArr[domArr.length-1].length!=2 &&
//domArr[domArr.length-1].search(knownDomsPat)==-1) {
//alert("The address must end in a well-known domain or two letter " + "country.");
//return false;
//}

// Make sure there's a host name preceding the domain.

//if (len<2) {
//alert("This address is missing a hostname!");
//return false;
//}

// If we've gotten this far, everything's valid!
//return true;
}

//  End -->

function verifyForgotPassword(f){

    var msg;
    var empty_fields = "";
    var errors = "";
    var emailIsValid = true;
    var email = "blank";




 for(var i = 0; i < f.length; i++) {
        var e = f.elements[i];

              if (e.name == "key.alpha")  {
			if(e.value.length < e.min){
	                //  errors += "The Login Name can not be less than 3 characters long";
	                  errors += "The ";
	                  errors += "Login";
	                  errors += " can not be less than ";
	                  errors += e.min;
	                  errors += " characters long \n";
	                }
	                if(e.value.length > e.max) {
	                  errors += "The Login Name can not be great than 32 characters long \n";
			}

	            }




   	if(e.name == "email.address"){
    	              emailIsValid = false;
                      email = e.value;
                      emailIsValid = emailCheck(e.value);
       }

    }

if (!empty_fields && !errors && emailIsValid) {
        return true;
    }

    msg  = "______________________________________________________\n\n"
    msg += "The form was not submitted because of the following error(s).\n";
    msg += "Please correct these error(s) and re-submit.\n";
    msg += "______________________________________________________\n\n"

    if (empty_fields) {
        msg += "- The following required field(s) are empty:"
                + empty_fields + "\n";
        if (errors) msg += "\n";
    	}
    if(!emailIsValid){
    	   msg += "- The email address " + email + " is Invalid \n "
        }



    msg += errors;
    alert(msg);
    return false;
}



// This is the function that performs form verification. It will be invoked
// from the onSubmit() event handler. The handler should return whatever
// value this function returns.
function verify(f)
{
    var msg;
    var empty_fields = "";
    var errors = "";
    var emailIsValid = true;
    var email = "blank";
    var cont = false;
    var prefchecked = false;
    var Prefs = true;
    var Prefs2 = true;
    var selectboxes=false;



    // Loop through the elements of the form, looking for all
    // text and textarea elements that don't have an "optional" property
    // defined. Then, check for fields that are empty and make a list of them.
    // Also, if any of these elements have a "min" or a "max" property defined,
    // then verify that they are numbers and that they are in the right range.
    // Put together error messages for fields that are wrong.
    for(var i = 0; i < f.length; i++) {
        var e = f.elements[i];
    
    if( (e.name.indexOf("pref.prod") != -1) || (e.name.indexOf("pref.appl") != -1)){
    	if(e.checked){
    		prefchecked = true;
    		}
     selectboxes=false;
     
     }		
    
        

    if(e.name == "Prefs"){
    	if(e.options[0].value=="SPACER" ){
    		Prefs = false;
    	}else{
    	  prefchecked = true;
    	  createSelectedCommaList(f)
    	 }
	
    	}

    if(e.name == "Prefs2"){
    	if(e.options[0].value=="SPACER"){
       		Prefs2 = false;
   	    }else{
   		prefchecked = true;
   		createSelectedCommaList(f)
   		    }   
   }



	


if(e.name == "dm.category.newsletter.opt_in"){
	if(!e.checked ){
			errors +="You must check the Subscribe box to continue \n"
		}
		}

if(e.name == "form_support_info"){
	if(e.checked ){
			cont = true;
		}
		}


if(e.name == "form_whats_new_tm"){
	if(e.checked ){
			cont = true;
		}
		}



     	if(e.name == "dm.state"){
          	if(e.value.length == 0){
          		e.value = "";
     		
             }
	}	


 	if(e.name == "dm.key.alpha"){
 		if(e.value.length < 6){
 			errors += "The Login Name must be at least 6 characters long \n"
		 }
		 if(e.value.length > e.max){
		 	errors += "Login Name can not be great than 32 characters long \n";
		 }
	}


 	if(e.name == "dm.newsletter_password"){
 		if(e.value.length < 6){
 			errors += "Password must be at least 6 characters long \n"
		 }
		 if(e.value.length > e.max){
		 	errors += "Password can not be great than 32 characters long \n";
		 }
	}




if(e.name == "dm.pref_country"){

    	if(e.value == "AA"){
             errors += "You must choose a country";
        }

    }


if(e.name == "pref_country"){

    	if(e.value == "AA"){
             errors += "You must choose a country";
        }

    }


     if (((e.type == "text") || (e.type == "password")) && !e.optional) {
            // first check if the field is empty
            if ((e.value == null) || (e.value == "") || isblank(e.value)) {
                empty_fields += "\n          " + e.display;
                continue;
            }




     // Now check for fields that are supposed to be numeric.
            if (e.numeric){// || (e.min != null) || (e.max != null)) {
                var v = parseFloat(e.value);
                if (isNaN(v) ||
                    ((e.min != null) && (v < e.min)) ||
                    ((e.max != null) && (v > e.max))) {
                    errors += "- The field " + e.name + " must be a number";
                    if (e.min != null)
                        errors += " that is greater than " + e.min;
                   if (e.max != null && e.min != null)
                        errors += " and less than " + e.max;
                    else if (e.max != null)
                        errors += " that is less than " + e.max;
                    errors += ".\n";
                }
            }
        }

   	if(e.name == "dm.email.address"){
    	              emailIsValid = false;
                      email = e.value;
                      emailIsValid = emailCheck(e.value);
       }

    }
    // Now, if there were any errors, display the messages, and
    // return false to prevent the form from being submitted.
    // Otherwise return true.
    

  
    if (!empty_fields && !errors && cont && emailIsValid && prefchecked) {
        return true;
    }
  
    msg  = "______________________________________________________\n\n"
    msg += "The form was not submitted because of the following error(s).\n";
    msg += "Please correct these error(s) and re-submit.\n";
    msg += "______________________________________________________\n\n"

    
    if(!cont){
    	     msg += "You must subscribe to an Information Type \n";
    }	     
    	     
    
    if (empty_fields) {
        msg += "- The following required field(s) are empty:"
                + empty_fields + "\n";
        if (errors) msg += "\n";
    	}
    
    if(!prefchecked || (!Prefs2 && !Prefs)){
        	msg += "You must select at least one product interest. \n";
        	}
    
    if(!emailIsValid){
    	   msg += "- The email address " + email + " is Invalid \n "
        }



    msg += errors;
    alert(msg);
    return false;
}


// This is the function that performs form verification. It will be invoked
// from the onSubmit() event handler. The handler should return whatever
// value this function returns.
function verifyModify(f)
{
    var msg;
    var empty_fields = "";
    var errors = "";
    var emailIsValid = true;
    var email = "blank";
    var prefchecked = false;
    var Prefs = true;
    var Prefs2 = true;
    var selectboxes=false;


    var cont = false;
    // Loop through the elements of the form, looking for all
    // text and textarea elements that don't have an "optional" property
    // defined. Then, check for fields that are empty and make a list of them.
    // Also, if any of these elements have a "min" or a "max" property defined,
    // then verify that they are numbers and that they are in the right range.
    // Put together error messages for fields that are wrong.
    for(var i = 0; i < f.length; i++) {        
    
    
    var e = f.elements[i];
    
     if( (e.name.indexOf("pref.prod") != -1) || (e.name.indexOf("pref.appl") != -1)){
     
        	if(e.checked){
       		prefchecked = true;
        		}
        selectboxes=false;
       }		
    
    
     if(e.name == "Prefs"){
     
        	if(e.options[0].value=="SPACER" ){
        	    Prefs = false;
        	}else{
        	  prefchecked = true;
        	  createSelectedCommaList(f)
        	 }
    	
       	}
     if(e.name == "Prefs2"){
     		
              	if(e.options[0].value=="SPACER"){
    			Prefs2 = false;
       		     }else{
       		    prefchecked = true;
       		    createSelectedCommaList(f)
       		    }   
   	}
    
     if(e.name == "dm.state"){
          	if(e.value.length == 0){
     			e.value = "";
		             }
	}	



      if(e.name == "dm.newsletter_password"){
                if(e.value.length != 0){
 		if(e.value.length < 6){
 			errors += "Password must be at least 6 characters long"
		 }
		 if(e.value.length > e.max){
		 	errors += "Password can not be great than 32 characters long";
		 }
	    }
        }




if(e.name == "dm.pref_country"){

    	if(e.value == "AA"){
             errors += "You must choose a country";
        }

    }


if(e.name == "pref_country"){

    	if(e.value == "AA"){
             errors += "You must choose a country";
        }

    }




if(e.name == "form_support_info"){
	if(e.checked ){
		cont = true;
		}
		}


if(e.name == "form_whats_new_tm"){
	if(e.checked ){
		cont = true;
		}
		}


     if ((e.type == "text")  && (!e.optional)) {
            // first check if the field is empty
            if ((e.value == null) || (e.value == "") || isblank(e.value)) {
                empty_fields += "\n          " + e.display;
                continue;
            }
         }

	

     // Now check for fields that are supposed to be numeric.
            if (e.numeric){// || (e.min != null) || (e.max != null)) {
                var v = parseFloat(e.value);
                if (isNaN(v) ||
                    ((e.min != null) && (v < e.min)) ||
                    ((e.max != null) && (v > e.max))) {
                    errors += "- The field " + e.name + " must be a number";
                    if (e.min != null)
                        errors += " that is greater than " + e.min;
                   if (e.max != null && e.min != null)
                        errors += " and less than " + e.max;
                    else if (e.max != null)
                        errors += " that is less than " + e.max;
                    errors += ".\n";
                }
            }


   	
   	if ((e.type == "text") && (e.optional)) {
	            // first check if the field is empty
	            if ((e.value == null) || (e.value == "") || isblank(e.value)) {
	                e.value = "  "
	                continue;
	            }
	          }

   	
   	 	
   	
   	
   	
   	if(e.name == "dm.email.address"){
    	              emailIsValid = false;
                      email = e.value;
                      emailIsValid = emailCheck(e.value);
       }

    }

    // Now, if there were any errors, display the messages, and
    // return false to prevent the form from being submitted.
    // Otherwise return true.
    if (!empty_fields && !errors && cont && emailIsValid && prefchecked) {
        return true;
    }

    msg  = "______________________________________________________\n\n"
    msg += "The form was not submitted because of the following error(s).\n";
    msg += "Please correct these error(s) and re-submit.\n";
    msg += "______________________________________________________\n\n"

    
    if(!cont){
        	     msg += "You must subscribe to an Information Type \n";
        }	     
    
    
    if (empty_fields) {
        msg += "- The following required field(s) are empty:"
                + empty_fields + "\n";
        if (errors) msg += "\n";
    	}

if(!prefchecked){
            	msg += "You must select at least one product interest. \n";
            	}


    if(!emailIsValid){
    	   msg += "- The email address " + email + " is Invalid \n "
        }



    msg += errors;
    alert(msg);
    return false;
}


function verifyLogin(f)
{

    var msg;
    var empty_fields = "";
    var has_blanks = "";
    var errors = "";

 for(var i = 0; i < f.length; i++) {
        var e = f.elements[i];


	      if ((e.name == "password") && ((e.min != null) || (e.max != null))) {
			if(e.value.length < e.min){
	                //  errors += "The Login Name can not be less than 6 characters long";
	                  errors += "The ";
	                  errors += e.name;
	                  errors += " can not be less than ";
	                  errors += e.min;
	                  errors += " characters long";
	                }
	                if(e.value.length > e.max) {
	                  errors += "The Password can not be great than 32 characters long";
			}

            }
    }



  if (!empty_fields && !errors)  {
        return true;
    }

    msg  = "______________________________________________________\n\n"
    msg += "The form was not submitted because of the following error(s).\n";
    msg += "Please correct these error(s) and re-submit.\n";
    msg += "______________________________________________________\n\n"


if (empty_fields) {

        msg += "- The following required field(s) are empty:"
                + empty_fields + "\n";
    	if (errors)
    		msg += "\n";

    }if(has_blanks){

    	msg += "- The following fields have spaces. Spaces are not allowed:"
    		   + has_blanks + "\n";
    }
    
    


    msg += errors;
    alert(msg);
    return false;


}




// This is the function that performs form verification. It will be invoked
// from the onSubmit() event handler. The handler should return whatever
// value this function returns.
function verifyRegistrationForm(f)
{
    var msg;
    var empty_fields = "";
    var has_blanks = "";
    var errors = "";
    var emailIsValid = true;
    var email = "blank";
    var Prefs = true;
    var Prefs2 = true;

    // Loop through the elements of the form, looking for all
    // text and textarea elements that don't have an "optional" property
    // defined. Then, check for fields that are empty and make a list of them.
    // Also, if any of these elements have a "min" or a "max" property defined,
    // then verify that they are numbers and that they are in the right range.
    // Put together error messages for fields that are wrong.

    for(var i = 0; i < f.length; i++) {
        var e = f.elements[i];

      if ((e.type == "text") && ((e.min != null) || (e.max != null))) {
		if(e.value.length < e.min){
                //  errors += "The Login Name can not be less than 6 characters long";
                  errors += "The ";
                  errors += e.name;
                  errors += " can not be less than ";
                  errors += e.min;
                  errors += " characters long";
                }
                if(e.value.length > e.max) {
                  errors += "The Login Name can not be great than 32 characters long";
		}

            }

      if ((e.name == "password") && ((e.min != null) || (e.max != null))) {
		if(e.value.length < e.min){
                //  errors += "The Login Name can not be less than 6 characters long";
                  errors += "The ";
                  errors += e.name;
                  errors += " can not be less than ";
                  errors += e.min;
                  errors += " characters long";
                }
                if(e.value.length > e.max) {
                  errors += "The Password can not be great than 32 characters long";
		}

            }
    if(e.name == "Prefs"){

    	if(e.options[0].value=="SPACER" ){
    		Prefs = false;
    	}
    	}

    if(e.name == "country"){

    	if(e.options[0].selected){
             errors += "You must choose a country";
        }

    }

    if(e.name == "Prefs2"){
          	if(e.options[0].value=="SPACER"){
       		Prefs2 = false;
        	}
        	}



   if(e.name == "notification"){

   	if(!e.checked ){
		errors +="You must check the Subscribe box to continue"
	}
	}

        //First check that the loginname and passwords are correct.
        if ((e.name == "loginname") || (e.name == "password") || (e.name == "password_confirm") || (e.name == "password_confirmation") ||(e.name == "password_reminder")) {
                 // first check if the field is empty
            if ((e.value == null) || (e.value == "") || (isblank(e.value))) {
              empty_fields += "\n          " + e.name;

            }

            else{


              if(hasBlanks(e.value)){

            	has_blanks += "\n            " + e.name;

            }

          }

        }


    if ((e.name == "cityofbirth") || (e.name == "email") || (e.name == "firstname") || (e.name == "lastname")) {

        	if ((e.value == null) || (e.value == "") || (isblank(e.value))) {
        	empty_fields += "\n          " + e.name;
                continue;
        	}

        	if(e.name == "email"){
        	  emailIsValid = false;
                  email = e.value;
                  emailIsValid = verfifyEmail(e.value);
               }

            }


	// Now check for fields that are supposed to be numeric.
            if(e.name == "phone")  {
            	if(e.value.length != 0){
                var v = parseFloat(e.value);
                if (isNaN(v) ||
                    ((e.min != null) && (v < e.min)) ||
                    ((e.max != null) && (v > e.max))) {
                    errors += "- The field " + e.name + " must be a number";
                    if (e.min != null)
                        errors += " that is greater than " + e.min;
                    if (e.max != null && e.min != null)
                        errors += " and less than " + e.max;
                    else if (e.max != null)
                        errors += " that is less than " + e.max;
                    errors += ".\n";
                }
            }
            }


}
if(!Prefs && !Prefs2){
	errors += "\n You must choose at least one Product Category Or one Application \n";
}
// Now, if there were any errors, display the messages, and
    // return false to prevent the form from being submitted.
    // Otherwise return true.
    if (!empty_fields && !errors && emailIsValid && !has_blanks) {
        return true;
    }

    msg  = "______________________________________________________\n\n"
    msg += "The form was not submitted because of the following error(s).\n";
    msg += "Please correct these error(s) and re-submit.\n";
    msg += "______________________________________________________\n\n"


if (empty_fields) {

        msg += "- The following required field(s) are empty:"
                + empty_fields + "\n";
    	if (errors)
    		msg += "\n";

    }if(has_blanks){

    	msg += "- The following fields have spaces. Spaces are not allowed:"
    		   + has_blanks + "\n";
    }if(!emailIsValid){

        msg += "- The email address " + email + " is Invalid \n "

        }


    msg += errors;
    alert(msg);
    return false;


	}
