

/* Form Validation */

function FV() {}

FV.prototype = {

	YD: YAHOO.util.Dom,
	YE: YAHOO.util.Event,
	YA: YAHOO.util.Anim,
	YC: YAHOO.util.Connect,
	strength: -1,
	uidcount: 0,
	uids: {},
	codes: {
		clear:       	 '',
		firstname:       'Please enter your First Name',
		lastname:        'Please enter your Last Name',
		gender:          'Please select your Gender (or Decline)',
		dob:             'Please select your Date of Birth (MM/DD/YYYY)',
		streetaddress:   'Please enter a valid Street Address',
		city:            'Please enter a valid City',
		state:           'Please select a State',
		country:         'Please select your Country',
		postalcode:      'Please enter a valid, 5-digit ZIP/Postal Code',
		email:           'Please enter a valid Email Address',
		email2:          'This Email is already being used',
		email3:          'Email has incorrect format',
		retypeemail:     'Emails do not match',
		retypeemail2:    'Invalid Email Address',
		username:        'This Username is not available',
		username2:       'This username is too short',
		username3:       'Please enter a Username',
		username4:       'This Username is already being used',
		password:        'Please enter a valid Password',
		password3:       'Password cannot be same as Username',
		retypepassword:  'Passwords do not match',
		retypepassword2: 'Invalid Password',
		register: 		 'Registered',
		login_username:  'Username is not registered (try again, or Register)',
		login_password:  'Password is incorrect (try again, or click Forgot Password)'
	},
	allow_pw_validation: true,
	
	init: function() {
		this.YE.on(this.YD.get('password'), 'blur', function(event) {
			var e = event || window.event;
			if (e.keyCode != 9 && this.value.length > 0) {
				FV.showStatus(FV.validate('password', this.value, 'password'), 'password', FV.codes.password);
			}
		});
		this.YE.on(this.YD.get('password'), 'keyup', function(event) {
			var e = event || window.event;
			if (e.keyCode != 9 && this.value.length > 0) {
				FV.validate('password_st', this.value, 'password');
			}
		});
		this.YE.on(this.YD.get('password'), 'blur', function(event) {
			var e = event || window.event;
			if (e.keyCode != 9 && this.value.length > 0) {
				FV.showStatus(FV.validate('password3', this.value, 'password'), 'password', FV.codes.password);
			}
		});
		this.YE.on(this.YD.get('password'), 'keyup', function(event) {
			var e = event || window.event;
			if ((e.keyCode != 9 && e.keyCode != 16) && this.value.length > 0) {
				FV.validate('password3', this.value, 'password');
			}
		});
		
		this.YE.on(this.YD.get('retypepassword'), 'blur', function(event) {
			var e = event || window.event;
			if (e.keyCode != 9 && this.value.length > 0) {
				FV.showStatus(FV.validate('password', this.value, 'password'), 'password', FV.codes.password);
			}
		});
		this.YE.on(this.YD.get('retypepassword'), 'keyup', function(event) {
			var e = event || window.event;
			if ((e.keyCode != 9 && e.keyCode != 16) && this.value.length > 0) {
				FV.validate('password2', this.value, 'retypepassword');
			}
		});
		
		this.YE.on(this.YD.get('firstname'), 'blur', function(event) {
			var e = event || window.event;
			if (e.keyCode != 9 && (this.value.length > 0 || this._av)) {
				FV.showStatus(FV.validate('name', this.value, 'firstname'), 'firstname', FV.codes.firstname);
				this.value=this.value.toProperCase();			
			}
		});
		//this.YE.on(this.YD.get('firstname'), 'keyup', function(event) {
			//var e = event || window.event;
			//if (e.keyCode != 9 && this.value.length > 0) {
				//this._av = true;
			//}
		//});
		
		this.YE.on(this.YD.get('lastname'), 'blur', function(event) {
			var e = event || window.event;
			if (e.keyCode != 9 && (this.value.length > 0 || this._av)) {
				FV.showStatus(FV.validate('name', this.value, 'lastname'), 'lastname', FV.codes.lastname);
				this.value=this.value.toProperCase();			
			}
		});
		//this.YE.on(this.YD.get('lastname'), 'keyup', function(event) {
			//var e = event || window.event;
			//if (e.keyCode != 9 && this.value.length > 0) {
				//this._av = true;
			//}
		//});
		
		this.YE.on(this.YD.get('gender'), 'change', function() {
			FV.validate('selectgender', this.options.selectedIndex, 'gender', true);
		});
		//this.YE.on(this.YD.get('gender'), 'blur', function() {
			//FV.validate('selectgender', this.options.selectedIndex, 'gender', true);
		//});
		
		this.YE.on(this.YD.get('email'), 'blur', function(event) {
			var e = event || window.event;
			if (e.keyCode != 9 && this.value.length > 0) {
				FV.showStatus(FV.validate('email', this.value, 'email'), 'email', FV.codes.email);
			}
		});
		// 10/12/09 dh - WHY do we need to test onKeyup? -- NO NEED TO, we need to test complete email
		//this.YE.on(this.YD.get('email'), 'keyup', function(event) {
			//var e = event || window.event;
			//if (e.keyCode != 9 && this.value.length > 0) {
				//FV.showStatus('email', this.value, 'email');
			//}
		//});
		this.YE.on(this.YD.get('retypeemail'), 'blur', function(event) {
			var e = event || window.event;
			if (e.keyCode != 9 && this.value.length > 0) {
				FV.validate('email2', this.value, 'retypeemail');
			}
		});
		//this.YE.on(this.YD.get('retypeemail'), 'keyup', function(event) {
			//var e = event || window.event;
			//if (e.keyCode != 9 && this.value.length > 0) {
				//FV.validate('email2', this.value, 'retypeemail');
			//}
		//});
		
		this.YE.on(this.YD.get('streetaddress'), 'blur', function(event) {
			var e = event || window.event;
			if (e.keyCode != 9 && this.value.length > 0 || this._av) {
				FV.showStatus(FV.validate('streetaddress', this.value, 'streetaddress'), 'streetaddress', FV.codes.streetaddress);
				this.value=this.value.toProperCase();			
			}
		});
		//this.YE.on(this.YD.get('streetaddress'), 'keyup', function(event) {
			//var e = event || window.event;
			//if (e.keyCode != 9 && this.value.length > 0) {
				//this._av = true;
			//}
		//});
		
		this.YE.on(this.YD.get('city'), 'blur', function(event) {
			var e = event || window.event;
			if (e.keyCode != 9 && this.value.length > 0 || this._av) {
				FV.showStatus(FV.validate('city', this.value, 'city'), 'city', FV.codes.city);
				this.value=this.value.toProperCase();			
			}
		});
		//this.YE.on(this.YD.get('city'), 'keyup', function(event) {
			//var e = event || window.event;
			//if (e.keyCode != 9 && this.value.length > 0) {
				//this._av = true;
			//}
		//});

		this.YE.on(this.YD.get('state'), 'change', function() {
			FV.validate('selectstate', this.options.selectedIndex, 'state', true);
		});
		//this.YE.on(this.YD.get('state'), 'blur', function() {
			//FV.validate('selectstate', this.options.selectedIndex, 'state', true);
		//});
		
		this.YE.on(this.YD.get('postalcode'), 'blur', function(event) {
			var e = event || window.event;
			if (e.keyCode != 9 && (this.value.length > 0 || this._av)) {
				FV.showStatus(FV.validate('postalcode', this.value, 'postalcode'), 'postalcode', FV.codes.postalcode);
			}
		});
		//this.YE.on(this.YD.get('postalcode'), 'keyup', function(event) {
			//var e = event || window.event;
			//if (e.keyCode != 9 && this.value.length > 0) {
				//this._av = true;
			//}
		//});

		this.YE.on(this.YD.get('country'), 'change', function() {
			FV.validate('selectcountry', this.options.selectedIndex, 'country', true);
		});
		//this.YE.on(this.YD.get('country'), 'blur', function() {
			//FV.validate('selectcountry', this.options.selectedIndex, 'country', true);
		//});
		
		this.YE.on(this.YD.get('username'), 'blur', function(event) {
			clearTimeout(FV.ut);
			var e = event || window.event;
			if (e.keyCode != 9 && (this.value.length > 0 || this._av)) {
				FV.validate('username', this.value, 'username');
			}
		});
		//this.YE.on(this.YD.get('username'), 'keyup', function(event) {
			//var e = event || window.event;
			//if ((e.keyCode != 9 && e.keyCode != 16) && this.value.length > 0) {
				//clearTimeout(FV.ut);
				//FV.ut = setTimeout('FV.validate(\'username\', \''+this.value+'\', \'username\');', 5000);
				//this._av = true;
			//}
		//});
		
		//this.YE.on(this.YD.get('login_username'), 'focus', function(event) {
			//var e = event || window.event;
			//if (e.keyCode != 9 && this.value.length > 0) {
				//FV.showStatus(true, this.name, FV.codes.clear);
			//}
		//});
		this.YE.on(this.YD.get('login_username'), 'blur', function(event) {
			var e = event || window.event;
			if (e.keyCode != 9 && this.value.length > 0) {
				FV.validate('login_username', this.value, 'login_username');
			}
		});
		this.YE.on(this.YD.get('login_password'), 'blur', function(event) {
			var e = event || window.event;
			if (e.keyCode != 9 && this.value.length > 0) {
				FV.validate('login_password', this.value, 'login_password');
			}
		});
		
		// FROM WAY ABOVE:
		//this.YE.on(this.YD.get('password'), 'keyup', function(event) {
			//var e = event || window.event;
			//if ((e.keyCode != 9 && e.keyCode != 16) && this.value.length > 0) {
				//FV.validate('password3', this.value, 'password');
			//}
		//});
		
		// I would like for this trigger to revalidate all inputs, display the animated gif while doing so, and then submit the values for processing
		// SEE http://validation.nexpace.com/v7/signup-persist-onfocus.html for example
		//this.YE.on(this.YD.get('register'), 'click', function(event) {
			//var e = event || window.event;
			//FV.showStatus('register',this.value,'register');
		//});
	},
	
	/**
	 * Validate fields
	 *
	 * @param String t - type - (apparently) arbitrary script-internal reference identifier, determines path of code to use in this function
	 * @param String v - this.value - value in the value attribute at time of trigger event (or selectedIndex of option tag)
	 * @param String n - this.name - value of name attribute of input/select tag
	 * @param String sl - select tag = true (indicates it's a select tag, fetch option tag's value), input tag = null/not used
	 *
	 * sample input tag usage:   FV.validate('city', this.value, 'city')
	 * sample select tag usage:  FV.validate('selectstate', this.options.selectedIndex, 'state', true) 
	 */
	validate: function(t, v, n, sl) {
		switch(t) {
			case 'name':
				var r = new RegExp("^[a-zA-Z\-]","g");
				break;

			case 'email':
				// NOTE - has regex BUT NOTHING IS DONE WITH IT! the tests all are in retype email - IS THAT OK, OR SHOULD IT BE DONE HERE ALSO?
				//var r = new RegExp("[a-zA-Z0-9+%-._]+@[a-zA-Z0-9.\\-_]+\\.[a-zA-Z]{2,4}","g");
				// check that email not already exists in user reg table
				var cbEmail = {
					// success vs. failure is about the ajax call, not the response - assume success: "OK" or "FAIL"
					success: function(o) {
						if (o.responseText.indexOf("OK") >= 0) {
							FV.showStatus(true, n);
							return true;
						} else if (o.responseText.indexOf("FAIL_INUSE") >= 0) {
							FV.showStatus(false, n, FV.codes.email2);
							return false;
						} else if (o.responseText.indexOf("FAIL_FORMAT") >= 0) {
							FV.showStatus(false, n, FV.codes.email3);
							return false;
						}
					},
					failure: function(o) {
						//do nothing (what can we do?)
					}
				};
				this.YC.asyncRequest('GET', 'handleXhrRequest.php?name='+t+'&value='+encodeURIComponent(v), cbEmail);
				break;

			case 'email2':
				// 'retypeemail' field validation - checks email & retypeemail fields
				var e1 = this.YD.get('email').value;
				var e2 = this.YD.get(n).value;
				if (v.length >= 5) {
					var r = new RegExp("[a-zA-Z0-9+%-._]+@[a-zA-Z0-9.\\-_]+\\.[a-zA-Z]{2,4}","g");
					if (r.exec(v)) {
						if (e1 == e2) {
							this.showStatus(true, n);
							return true;						 
						}else{
							this.showStatus(false, n, FV.codes.retypeemail);
							return false;
						}
					}else{
						this.showStatus(false, n, FV.codes.retypeemail2);
						return false;
					}
				}else{
					this.showStatus(false, n, FV.codes.retypeemail2);
					return false;
				}
				break;
				
			case 'streetaddress':
				var r = new RegExp("[0-9]+[ ]+[a-zA-Z\-]","i");
				break;
				
			case  'city':
				var r = new RegExp("^[a-zA-Z\-]","g");
				break;
				
			case 'postalcode':
	//			var r = new RegExp("[A-PR-UWYZ][A-HK-Y0-9][A-HJKSTUW0-9]?[ABEHMNPRVWXY0-9]? *[0-9][ABD-HJLN-UW-Z]{2}", "i");
				if (v.length == 5) {
					var r = new RegExp("[0-9]{5}","i");
				}
				break;
			case 'password_st':
				var cb = {
					success: function(o) {
						FV.showStrength(o.responseText, n, v);
					},
					failure: function(o) {
						FV.showStatus(false, n, o.responseText);
					}
				};
				this.YC.asyncRequest('GET','include/validate.php?pass='+encodeURIComponent(v), cb);
				break;
			case 'password':
				if (v.length >= 5) {
					var r = new RegExp("([^a-zA-Z]+)","g");
				}
				if (sl) {
					var p1 = this.YD.get(n).value;
					var p2 = this.YD.get('retypepassword').value;
					if (p1 != p2) {
						this.resetField('retypepassword');
					}
				}
				break;
			case 'password3':
				var p3 = this.YD.get('username').value;
				var p4 = this.YD.get(n).value;
				if (p3 == p4) {
					this.showStatus(false, n, FV.codes.password3);
							return false;
					} else {
						this.showStatus(true, n);
							return true;		
					}
				break;
			case 'password2':
				var p1 = this.YD.get('password').value;
				var p2 = this.YD.get(n).value;
				if (v.length >= 5) {
					var r = new RegExp("([^a-zA-Z]+)","g");
					if (r.exec(v)) {
						if (p1 == p2) {
							this.showStatus(true, n);
							return true;						 
						}else{
							this.showStatus(false, n, FV.codes.retypepassword);
							return false;
						}
					}else{
						this.showStatus(false, n, FV.codes.retypepassword2);
						return false;
					}
				}else{
					this.showStatus(false, n, FV.codes.retypepassword2);
					return false;
				}
				break;
			
			case 'username':
				// regex test pattern - at least 5 alpha-numeric chars or underscores and dots
				var r = new RegExp("^[a-zA-Z0-9_\S@\.]{5,}","g");
				if (r.exec(v)) {
				    // pattern test has passed, move on (do nothing here, fall thru)
					//if (this.uidcount < 2) {
						//if (!sl) { this.uidcount++; }
						//this.uids[v] = -1;
						//this.showStatus(false, n, this.codes.username);
						//return false;
					//}else{
						// WE MAY NOT WANT THIS TEST HERE EITHER:
						if (this.uids[v] != -1 || !this.uids[v]) {
							this.uids[v] = true;
							//this.showStatus(true, n);
							//return true;
						}else{
							this.showStatus(false, n, this.codes.username);
							return false;
						}
					//}
				} else if (this.YD.get(n).value == ''){
					// ELSE -- the pattern test has failed
					// is empty field
					this.showStatus(false, n, this.codes.username3);
					return false;
				} else {
					// WE MAY NOT WANT THIS, should not be set anyway because of commented code above
					this.uids[v] = -1;
					this.showStatus(false, n, this.codes.username2);
					return false;
				}
				// if pattern & min length test passed, call server to check that username not already exists in user reg table
				var cbUsername = {
					// NOTE - this success vs. failure is about the ajax call, not the response - assume success - "OK" or "FAIL"
					success: function(o) {
						stat = o.responseText;
						len = stat.length;
						//stat = stat.trim(); -- latter day javascript -- vers 1.8 (ES5)
						//FV.YD.get('status-username').innerHTML = "__" + stat + "__" + n + "__" + len + "__";
						//"Blue Whale".indexOf("Blue")    // returns 0
						// THERE ARE 2 SPACES BEFORE THE WORD RETURNED!
						//if (o.responseText == "  OK") {
						if (o.responseText.indexOf("OK") >= 0) {
							FV.showStatus(true, n);
							return true;
						} else {
							FV.showStatus(false, n, FV.codes.username4);
							return false;
						}
					},
					failure: function(o) {
						//FV.showResponseMessages(false, n, o.responseText);
					}//,
					//argument: result_code,
					//cache: false
				};
				// arg2 - pass query string: name=t='username' value=v=field-value -- arg3 - callback function: cbUsername 
				this.YC.asyncRequest('GET', 'handleXhrRequest.php?name='+t+'&value='+encodeURIComponent(v), cbUsername);
				break;
				
			case 'selectgender':
				// note - this test can simply be that 'v' (the selectedIndex) is > 0 -- like: if (v > 0) { // passes }
				if (this.YD.get(n).options[v].value != -1) {
					if (sl) {
						this.showStatus(true, n);
					}
					return true;
				}else{
					this.showStatus(false, n, this.codes.gender);
					return false;
				}
				break;
				
			case 'selectstate':
				if (this.YD.get(n).options[v].value != -1) {
					if (sl) {
						this.showStatus(true, n);
					}
					return true;
				}else{
					this.showStatus(false, n, this.codes.state);
					return false;
				}
				break;	
				
			case 'selectcountry':
				if (this.YD.get(n).options[v].value != -1) {
					if (sl) {
						this.showStatus(true, n);
					}
					return true;
				}else{
					this.showStatus(false, n, this.codes.country);
					return false;
				}
				break;
				
			case 'login_username':
				var cbLoginUsername = {
					success: function(o) {
						if (o.responseText.indexOf("OK") >= 0) {
							FV.showStatus(true, n);
							return true;
						} else {
							// let's just show the green check for OK, else get's error message on submit
							//FV.showStatus(false, n, FV.codes.login_username);
							// clear the green check
							FV.showStatus(false, n, FV.codes.clear);
							return false;
						}
					}
				};
				this.YC.asyncRequest('GET', 'handleXhrRequest.php?name='+t+'&username='+encodeURIComponent(v), cbLoginUsername);
				break;

			case 'login_password':
				var cbLoginPassword = {
					success: function(o) {
						if (o.responseText.indexOf("OK") >= 0) {
							FV.showStatus(true, n);
							return true;
						} else {
							// let's just show the green check for OK, else get's error message on submit
							//FV.showStatus(false, n, FV.codes.login_password);
							FV.showStatus(false, n, FV.codes.clear);
							return false;
						}
					}
				};
				var luser = encodeURIComponent(this.YD.get('login_username').value);
				var lpass = encodeURIComponent(v);
				this.YC.asyncRequest('GET', 'handleXhrRequest.php?name='+t+'&username='+luser+'&password='+lpass, cbLoginPassword);
				break;
				
		}
		
		if (r) {
			if (r.exec(v)) {
				return true;
			}else{
				return false;
			}
		}

	},
	
	showStatus: function(s, id, m) {
		FV.YD.get('status-'+id).className = 'l';
		FV.YD.setStyle('status-'+id, 'opacity', 1);
		FV.YD.get('status-'+id).innerHTML = '';
//		FV.YD.get('lbl-'+id).className = '';
		FV.YD.get(id).className = '';
		clearTimeout(FV.YD.get('status-'+id).statim);
		FV.YD.get('status-'+id).statim = setTimeout(function() {
			if (s) {
				FV.YD.get('status-'+id).className = 's';
				if (FV.YD.get('strength-'+id)) {
					FV.YD.get('strength-'+id).style.display = 'block';
				}
			}else{
				FV.YD.setStyle('status-'+id, 'opacity', 1);
//				FV.YD.get('lbl-'+id).className = 'f';
				FV.YD.get('status-'+id).className = 'f';
				FV.YD.get(id).className = 'f';
				FV.YD.get('status-'+id).innerHTML = m;
			}
		}, 1000);
		return s;
	},
	
	showStrength: function(s, id, v) {

		this.strength = (s != 'fail')?parseInt(s):-1;
		var m1 = this.YD.get('m1');
		var m2 = this.YD.get('m2');
		var m3 = this.YD.get('m3');
		
		if (this.strength > -1) {
			
			m1.innerHTML = '';
			m1.style.backgroundColor = '';
			m2.innerHTML = '';
			m2.style.backgroundColor = '';
			m3.innerHTML = '';
			m3.style.backgroundColor = '';
	
			switch(this.strength) {
				case 0:
				case 1:
				default: 
					m1.style.backgroundColor = '#ff3333';
					m1.innerHTML = 'Weak';
					break;
				case 2:
				case 3:
					m1.style.backgroundColor = '#ffcc33';
					m2.style.backgroundColor = '#ffcc33';
					m2.innerHTML = 'Fair';
					break;
				case 4:
					m1.style.backgroundColor = '#99ff66';
					m2.style.backgroundColor = '#99ff66';
					m3.style.backgroundColor = '#99ff66';
					m3.innerHTML = 'Strong';
					break;
			}
		//	this.showStatus(true, id);
		}else{
//			this.showStatus(false, id, this.codes.password);
	//		this.YD.get('strength-'+id).style.display = 'none';
			m1.style.backgroundColor = '';
			m2.style.backgroundColor = '';
			m3.style.backgroundColor = '';
			m2.innerHTML = 'Strength';
		}
},
		
	getType: function(form) {
		var e = 0;

		for(i=0;i<form.length;i++) {
				switch(form[i].id) {
					case 'firstname':
						if (!this.validate('name', form[i].value, form[i].id)) {
							this.showStatus(false, form[i].id, this.codes.firstname)
							e++;
						}
						break;
					case 'lastname':
						if (!this.validate('name', form[i].value, form[i].id)) {
							this.showStatus(false, form[i].id, this.codes.lastname)
							e++;
						}						
						break;
					case 'email':
						if (!this.validate('email', form[i].value, form[i].id)) {
							//WRONG?: this.showStatus(false, 'email', FV.codes.password);
							this.showStatus(false, 'email', FV.codes.email);
							e++;
						}else{
							//WRONG?: this.showStatus(true, 'email', FV.codes.password);
							this.showStatus(true, 'email');
						}
						break;
					case 'retypeemail':
						if (!this.validate('email2', form[i].value, form[i].id)) {
							e++;
						}
						break;
					case 'gender':
						if (!this.validate('selectgender', form[i].options.selectedIndex, form[i].id)) {
							e++;
						}						
						break;
					case 'streetaddress':
						if (!this.validate('streetaddress', form[i].value, form[i].id)) {
							this.showStatus(false, form[i].id, this.codes.streetaddress)
							e++;
						}						
						break;
					// PUT THE TEST HERE FOR THE suiteaddress -- NEEDS THE VALIDATE PART DONE
					case 'suiteaddress':
						//if (!this.validate('suiteaddress', form[i].value, form[i].id)) {
							//this.showStatus(false, form[i].id, this.codes.suiteaddress)
							//e++;
						//}
						break;
					case 'city':
						if (!this.validate('city', form[i].value, form[i].id)) {
							this.showStatus(false, form[i].id, this.codes.city)
							e++;
						}						
						break;
					case 'state':
						if (!this.validate('selectstate', form[i].options.selectedIndex, form[i].id, true)) {
							e++;
						}						
						break;
					case 'postalcode':
						if (!this.validate('postalcode', form[i].value, form[i].id)) {
							this.showStatus(false, form[i].id, this.codes.postalcode)
							e++;
						}						
						break;
					case 'country':
						if (!this.validate('selectcountry', form[i].options.selectedIndex, form[i].id, true)) {
							e++;
						}						
						break;
					case 'username':
						//if (this.uidcount < 2) {
							//this.uidcount--;
						//}
						if (!this.validate('username', form[i].value, form[i].id)) {
							this.showStatus(false, form[i].id, this.codes.username)
							e++;
						}						
						break;
					case 'password':
						if (!this.validate('password', form[i].value, form[i].id)) {
//							this.validate('password', form[i].value, form[i].id);
							this.showStatus(false, 'password', FV.codes.password);
							e++;
						}else{
							this.showStatus(true, 'password', FV.codes.password);
						}
						break;
					case 'retypepassword':
						if (!this.validate('password2', form[i].value, form[i].id)) {
	//						this.validate('password2', form[i].value, form[i].id);
							e++;
						}
						break;
				}
		}
		
		if (e == 0) {
			//this.YD.setStyle(this.YD.get('pg-error'), 'display', 'none');
			return true;
		}else{
			//this.YD.setStyle(this.YD.get('pg-error'), 'display', 'block');
			return false;
		}

	},
	
	resetField: function(id) {
		var field = this.YD.get(id);
		var status = this.YD.get('status-'+ id);
		field.className = '';
		field.value = '';
		status.className = '';
		status.innerHTML = '';
	},

	submit: function(form) {
		//return FV.getType(form);
		return true;
	}
	
};

var FV = new FV();
FV.init();

String.prototype.toProperCase = function() {
	return this.toLowerCase().replace(/^(.)|\s(.)/g, 
		function($1) { return $1.toUpperCase(); });
}

/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Cyanide_7 |  */
var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function autoTab(input,len, e) {
  var keyCode = (isNN) ? e.which : e.keyCode; 
  var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
  if(input.value.length >= len && !containsElement(filter,keyCode)) {
    input.value = input.value.slice(0, len);
    input.form[(getIndex(input)+1) % input.form.length].focus();
  }

  function containsElement(arr, ele) {
    var found = false, index = 0;
    while(!found && index < arr.length)
    if(arr[index] == ele)
    found = true;
    else
    index++;
    return found;
  }

  function getIndex(input) {
    var index = -1, i = 0, found = false;
    while (i < input.form.length && index == -1)
    if (input.form[i] == input)index = i;
    else i++;
    return index;
  }
  return true;
}