// JavaScript Document
		
var arrayBannedStr = new Array("\\", "/", " ", "!", "@", "%", "#", "$", "^", "&", "*", "(", ")", "=", "+", "}", "{", "]", "[", "|", "?", ">", "<", ".", ",");

		function validateExist(obj){
		var err= 0;
		var passerr = 0;
		var txtEmail, txtPass, txtPass2;
		
		//alert("Elements: " + obj.length);
		for (var i=0; i<obj.length; i++){
			var elem = obj.elements[i];
			elem.value = trimAll(elem.value)
			if (elem.name == "txt_email"){	
				txtEmail = elem.value;	
				if(!(confirm_emailExist(elem.name, elem.value))){ 
					err++;
				}
				//alert(confirm_email(elem.name, elem.value));
			}			
			if (elem.name == "txt_password"){	
				txtPass = elem.value;	
				//alert(txtPass);
				if (!(v_passwordExist(elem))) {err++;}
			}			
			if (elem.name == "txt_passwordconfirm"){	txtPass2 = elem.value;	}
			//alert(elem.value);
			
			if (txtEmail == ""){
				setError("email");				
				err++;
			}else{
				unsetError("email");
			}
			
			if (txtPass == ""){
				err++;
				passerr++;
				setError("password");
			}else{
				unsetError("password");
			}
			
			if (txtPass2 == ""){
				err++;
				passerr++;
				setError("passwordconfirm");
			}else{
				unsetError("passwordconfirm");				
			}
			
													
		}//loop
		//alert("Email error: " + passerr);		
		if (passerr == 0){
			if (txtPass != txtPass2){
				showError("txt_passwordconfirm_div");
				err++;
			}else{
				offError("txt_passwordconfirm_div");
			}
		}
		
		if (err > 0){
				document.getElementById("errorDiv").style.display = "block";
				document.getElementById("errorDiv").style.visibility = "visible";
				//document.getElementById("btnSubmit").disabled = true;
				return false;
			}else{
				document.getElementById("errorDiv").style.display = "none";
				document.getElementById("errorDiv").style.visibility = "hidden";
				//document.getElementById("btnSubmit").disabled = false;
				return true;
			}
	}//end function



function confirm_emailExist(e_name, e_val){
	confirm_entry = e_name + "confirm";
	//do email type check here. if it is not a real email format then alert user. 
	//if it is a valid email format then do check below to see if the confirm and the original match.
	var boolValidEmail = emailFormatExist(e_val);
	//alert(boolValidEmail);
	if(boolValidEmail){
			toggle_visibility(e_name + "_div","hidden");
			toggle_visibility("divBadEmailMsg","hidden");
			return true;
	}else{
		toggle_visibility(e_name + "_div","visible"); //email entered is not in the valid format.
		toggle_visibility("divBadEmailMsg","visible");
		return false;
	}
}

//validates the email format. Checks to make sure email is in the form name@domain.xxx.
//also matches email against unwanted domains.
function emailFormatExist(emailvalue){
	var result;
	if(is.ie && on.mac){
		//var filter;
		//stronger regex check, but causes errors on a macintosh in IE.
		//var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		var checkspace=new Boolean();
		var checkat=new Boolean();
		var checkdot=new Boolean();
		
		for (i=0;i<emailvalue.length;i++){
			switch(emailvalue.charAt(i)){
				case ' ': checkspace=true;continue;
				case '@': checkat=true;continue;
				case '.':checkdot=true;continue;
			}
		}
		emailvalarray = emailvalue.split("@");
		if (checkspace==false && checkat==true && checkdot==true){
			if(emailvalarray.length > 2){
				result = false;
			}else{
				result = true;
			}
		}else{
			result = false;
		}
		checkspace=new Boolean();
		checkat=new Boolean();
			checkdot=new Boolean();
	}else{
		//simpler regex that works as well as the more comprehensive one above.
		//var filter = /^[a-zA-Z0-9_][\w\.\+\-]*[a-zA-Z0-9_]@[a-zA-Z0-9_][\w\.-]*[a-zA-Z0-9_]\.(([a-zA-Z]\.{1})*)?[a-zA-Z]{2,4}$/i;
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; //less strict regex than above, allows for '-' and 3+ domain name extension
			//note: using the regexp constructor causes problems in both NN7 on Win2k+ and on IE5.0 on Mac.

		if (filter.test(emailvalue)){
			result = true;
		}else{
			result = false;
		}
	}
	return result;
}


//checking for password validation	
function v_passwordExist(obj){
	var name = obj.name;
	var val = obj.value;
	//alert ("Pass: " + val);
	if(name == "txt_password"){
		var passwrd_length = val.length;
		var passwordok = passwordcheck(val);
		//alert("Password status: " + passwordok);
		if(val == ""){
			document.getElementById("divpassmsg").innerHTML = "Invalid password. Please enter a password between 5-10 characters in length.";
			toggle_visibility(name+"_div","visible");
			toggle_visibility("divpassmsg","hidden");
			toggle_visibility(name+"confirm_div","hidden");
			return false; 
		}else if(passwordok){
			//match it against the confirm field
			var confirmfield = name + "confirm";
			if(val == eval("document.forms[0]."+confirmfield+".value")){
				//password is ok. 
				//alert(val);
				toggle_visibility("divpassmsg","hidden");
				//toggle_visibility(name+"_div","hidden");
				toggle_visibility(name+"confirm_div","hidden");
				return true; 
			}else{
				//password and confirm field did not match up.
				document.getElementById("divpassmsg").innerHTML = "Please enter your password in the 'Confirm Password' field";
				toggle_visibility("divpassmsg","hidden");
				//toggle_visibility(name+"_div","visible");
				toggle_visibility(name+"confirm_div","visible");				
				return false;
			}
		}else{
			if(val.toLowerCase() == "shopper"){
				document.getElementById("divpassmsg").innerHTML = "Invalid password. Note, 'shopper' is a default password for initial log-in and will not be recognized by our system as a valid password.";
			//return false;
			}else{
				document.getElementById("divpassmsg").innerHTML = "Invalid password. Your password must be between 5-10 characters in length and cannot contain spaces nor special characters (eg. #,$,%).";
			}
			//alert user to bad password
			toggle_visibility("divpassmsg","visible");
			toggle_visibility(name+"_div","visible");			
			return false;
		}
	}
}

function passwordcheck(v){	
	var returnvalue = true;
	for(var i = 0; i < v.length; i++){
		//alert(v[i]);		
		for(var q = 0; q < arrayBannedStr.length; q++){
			if(v.charAt(i) == arrayBannedStr[q]){
				//alert("found");
				returnvalue = false;
			}
		}
	}
	if(returnvalue){
		if(v.length > 10 || v.length < 5){ //password has to be a minimum of 5 and a max of 10 characters.
			returnvalue = false;
		}
	}
	if(returnvalue){
		if(v.toLowerCase() == "shopper"){
			returnvalue = false;
		}
	}
	return returnvalue;
}

	
//DESCRIPTION: Removes leading and trailing spaces.	
	function trimAll( strValue ) {	
	 var objRegExp = /^(\s*)$/;
	
	    //check for all spaces	
	    if(objRegExp.test(strValue)) {	
	       strValue = strValue.replace(objRegExp, '');	
	       if( strValue.length == 0)	
	          return strValue;	
	    }
		    
	   //check for leading & trailing spaces	
	   objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;	
	   if(objRegExp.test(strValue)) {	
	       //remove leading and trailing whitespace characters	
	       strValue = strValue.replace(objRegExp, '$2');
	    }	
	  return strValue;	
	}//end function trimAll
	
	function showError(elemid){
		eval("document.getElementById('"+elemid+"').style.visibility='visible'");				
	}
	function offError(elemid){
		eval("document.getElementById('"+elemid+"').style.visibility='hidden'");	
	}
	
	function setError(elemid){		
		eval('document.getElementById("'+ elemid+'").style.color="#c64100";');
	}
	function unsetError(elemid){	
		eval('document.getElementById("'+ elemid+'").style.color="#000000";');			
	}