// ============================================ 
// Guidonet Validation v3.50 v2
// Copyright Comtech Solutions, Salt Lake City, 1997-2001 ALL RIGHTS RESERVED 
// This script code is available under agreement only to Registered 
// Comtech Solutions clients.

	function CheckFields(x)  {
		if( x.name != null )
			if( checkField("Name", x.name, false, 1) )
				return false
		if( x.FirstName != null )
			if( checkField("First Name", x.FirstName, false, 1) )
				return false
		if( x.LastName != null )
			if( checkField("Last Name", x.LastName, false, 1) )
				return false
		if( x.address1 != null )
			if( checkField("Address", x.address1, false, 5) )
				return false
		if( x.city != null )
			if( checkField("City", x.city, false, 2) )
				return false
		if( x.zip != null )
			if( checkField("Zipcode", x.zip, false, 1) )
				return false
		if( x.email != null )
			if( checkFieldEmail(x.email))
				return false
		if( x.username != null )
			if( checkField("Username", x.username, false, 5) )
				return false
		if( x.password != null )
			if( checkFieldPass("Password", x.password, x.vpassword, 5))
				return false
		return(true);
		}
	function checkField(what,where,numeric,len)  {
		tmp = where.value
		if(what=="Account Number")  {
			Chkvalid = true
			for( i=0; i < where.value.length; i++ )  {
				if(tmp.charAt(i)!="0" && Chkvalid)  {
					if (i!=0) {
						where.value = tmp.substring(i,where.value.length)
						tmp = where.value
					}
					Chkvalid = false
				}
			}
			if (checkAcctNumeric(what,where))
			{
				stralert = "Invalid "+what+"\n\n"
				stralert = stralert+"The account number entered does not exist.  Please\n"
				stralert = stralert+"check your label to get your valid account number.\n"
				stralert = stralert+"Online only customers please email:"
				stralert = stralert+"\n\n    subscriptions@refundcents.com\n\n"
				stralert = stralert+"to obtain your account number."
				stralert = stralert+""
				alert(stralert)
				where.focus()
				where.select()
				return true
			}
		}
		if (len==0){ 
		} else {
			if(isEmpty(tmp) || tmp.length < len )  {
				alert("Invalid " + what)
				where.focus()
				where.select()
				return true
				}
		}
		if( numeric )  {
			return checkNumeric(what,where)
			}
		return false
		}
	function checkFieldEmail(where)  {
		tmp = where.value
		NotEmail = false
		if (tmp.indexOf(" ")>=0){
			NotEmail = true
		}
		IndofAt = tmp.indexOf("@")
		EndofAt = tmp.lastIndexOf("@")
		//String can't have more than one "@"
		if (IndofAt!=EndofAt){
			NotEmail=true
		}
		EndofDot = tmp.lastIndexOf(".")
		//"@" must exist, and last "." in string must follow the "@"
		if( IndofAt<1 || EndofDot < IndofAt+1 ){
			NotEmail = true
		}
		//String can't have "." immediately following "@"
		if (tmp.charAt(IndofAt+1)=="."){
			NotEmail = true
		}
		//String must have at least a two-character top-level domain.
		if (EndofDot>tmp.length-3){
			NotEmail = true
		}
		if(NotEmail) {
			alert("Invalid Email Address")
			where.focus()
			return true
			}
		return false;
	}
	function checkFieldPass(what,where,where2,len)  {
		tmp = where.value
		tmp1 = where2.value
		if( tmp!=tmp1)  {
			alert("Invalid " + what + "\nYour password and confirm password do not match")
			where.focus()
			where.select()
			return true;
			}
		if( isEmpty(tmp) || tmp.length < len || isEmpty(tmp1) || tmp1.length < len)  {
			alert("Invalid " + what +"\nPassword must be at least 5 characters.")
			where.focus()
			where.select()
			return true;
			}
			
		return false;
		}
	function isEmpty(str)  {
		if( str == null || str == "" ) 
			return true
		return false
		}
	function checkNumeric(what,where)  {
		var chk = "0123456789-.,/ ";
		for( i=0; i < where.value.length; i++ )  {
			for( j=0; j < chk.length; j++ )  {
				found = false;
				// if( confirm("value(i)=" + where.value.charAt(i) + " value(j)=" + chk.charAt(j)) )
				//	return true;
				if( where.value.charAt(i) == chk.charAt(j) )  {
					found = true;
					break;
					}
				}
			if( !found )  {
				alert("Invalid " + what)
				where.focus()
				where.select()
				return true;
				}
			}
		return false
		}
	function checkAcctNumeric(what,where)  {
		var chk = "0123456789-.,/ ";
		for( i=0; i < where.value.length; i++ )  {
			for( j=0; j < chk.length; j++ )  {
				found = false;
				// if( confirm("value(i)=" + where.value.charAt(i) + " value(j)=" + chk.charAt(j)) )
				//	return true;
				if( where.value.charAt(i) == chk.charAt(j) )  {
					found = true;
					break;
					}
				}
			if( !found )  {
				return true;
				}
			}
		return false
		}
