// JavaScript Document

window.addEvent('domready', function() {
	$("search-box").addEvent('focus', function() { if (this.value == "Search by Product Title") this.value = ''} );
	$("search-box").addEvent('blur', function() { if (this.value == "") this.value = 'Search by Product Title'} );
});

window.addEvent('domready',function() {
	$$("form").each(function(form) {
		form.addEvent('submit', function() {
			var className;
			for(i=0;i<this.elements.length;i++) {
				className = this.elements[i].className.split(" ");
				if (className.contains("required"))
					switch (this.elements[i].type) {
						case 'select-one':
							if (this.elements[i].selectedIndex == 0) {
								alert("Please fill required fields (marked with *)");
								this.elements[i].focus();
								return false;
							}
						break;
						default:
							if ((this.elements[i].value == "") && (!this.elements[i].disabled)) {
								alert("Please fill required fields (marked with *)");
								this.elements[i].focus();
								return false;
							}
					}
					
				if (this.password1) {
					if (this.password1 && this.password2 && (this.password1.value!=this.password2.value)) {
						alert("Passwords do not match");
						this.password1.focus();
						return false;
					} 
					
					if (((!/.*([0-9]{1,}).*([0-9]{1,}).*/.test(this.password1.value)) || (!/[a-zA-Z]{2,}/.test(this.password1.value)))) {
						alert("Password must be at least 6 characters length, must contain at least 2 digits and 2 letters.");
						this.password1.focus();
						return false;
					}
				}
				
			}
		});
	});
});

