// The scripts below are form validation for the forms in the forms directory
function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}

function shipBill(state){
	if(state){
		$('shippingTable').style.display='none';
	}
	else{
		$('shippingTable').style.display='';
	}
}

var totalErrors=0;	
var formsToCount=0;
var msg="";
var formValidate={
	contactSimple: function(){
		var csErrors=0;
		for(b=1;b<=11;b++){
			var holder='csff_'+b;
			if($(holder)){
				if($(holder).value==''){
					csErrors++;
					if(navigator.appName=='Netscape'){
						$(holder).setAttribute("class", "formAttention");
					}
					else{
						$(holder).className="formAttention";
					}
				}
				else{
					if(navigator.appName=='Netscape'){
						$(holder).setAttribute("class", "formField");
					}
					else{
						$(holder).className="formField";
					}
				}
			}
		}
		if($('csff_7').value!=$('csff_9').value){
			msg+='   * Please check that both emails match \n';
			csErrors++;
			if(navigator.appName=='Netscape'){
				$('csff_7').setAttribute("class", "formAttention");
				$('csff_9').setAttribute("class", "formAttention");
			}
			else{
				$('csff_7').className="formAttention";
				$('csff_9').className="formAttention";
			}
		}
		if(csErrors!=0){
			incrementErrors(csErrors);
		}
		else{
			formsToCount++;
			return formsToCount;
		}
	},
	contact: function(){
		var cErrors=0;
		for(b=1;b<=15;b++){
			var holder='cff_'+b;
			if($(holder)){
				if($(holder).value==''){
					cErrors++;
					if(navigator.appName=='Netscape'){
						$(holder).setAttribute("class", "formAttention");
					}
					else{
						$(holder).className="formAttention";
					}
				}
				else{
					if(navigator.appName=='Netscape'){
						$(holder).setAttribute("class", "formField");
					}
					else{
						$(holder).className="formField";
					}
				}
			}
		}
		if($('cff_11').value!=$('cff_13').value){
			msg+='*   Please check that both emails match';
			cErrors++;
			if(navigator.appName=='Netscape'){
				$('cff_11').setAttribute("class", "formAttention");
				$('cff_13').setAttribute("class", "formAttention");
			}
			else{
				$('cff_11').className="formAttention";
				$('cff_13').className="formAttention";
			}
		}
		if(cErrors!=0){
			incrementErrors(cErrors);
		}
		else{
			formsToCount++;
			return formsToCount;
		}
	},
	billingAddress: function(){
		var baErrors=0;
		for(b=1;b<=10;b++){
			var holder='bff_'+b;
			if($(holder)){
				if($(holder).value==''){
					baErrors++;
					if(navigator.appName=='Netscape'){
						$(holder).setAttribute("class", "formAttention");
					}
					else{
						$(holder).className="formAttention";
					}
				}
				else{
					if(navigator.appName=='Netscape'){
						$(holder).setAttribute("class", "formField");
					}
					else{
						$(holder).className="formField";
					}
				}
			}
		}
		if(baErrors!=0){
			incrementErrors(baErrors);
		}
		else{
			formsToCount++;
			return formsToCount;
		}
	},
	shippingAddress: function(){
		if($('sff_b').checked==true){
			var saErrors=0;
			for(b=1;b<=10;b++){
				var holder='sff_'+b;
				if($(holder)){
					if($(holder).value==''){
						saErrors++;
						if(navigator.appName=='Netscape'){
							$(holder).setAttribute("class", "formAttention");
						}
						else{
							$(holder).className="formAttention";
						}
					}
					else{
						if(navigator.appName=='Netscape'){
							$(holder).setAttribute("class", "formField");
						}
						else{
							$(holder).className="formField";
						}
					}
				}
			}
			if(saErrors!=0){
				incrementErrors(saErrors);
			}
			else{
				formsToCount++;
				return formsToCount;
			}
		}
		else{
			formsToCount++;
			return formsToCount;
		}
	},
	register: function(){
		if($('naff_1').checked==true){
			var rErrors=0;
			if($('rff_1').value.length < 8 || $('rff_1').value==''){
				msg=msg+'   * Username must be a minimum of 8 characters. \n';
				rErrors++;
				if(navigator.appName=='Netscape'){
					$('rff_1').setAttribute("class", "formAttention");
				}
				else{
					$('rff_1').className="formAttention";
				}
			}
			else{
				if(navigator.appName=='Netscape'){
					$('rff_1').setAttribute("class", "formField");
				}
				else{
					$('rff_1').className="formField";
				}
			}
			re = /[0-9]/;
			if($('rff_2').value.length < 6 || !re.test($('rff_2').value)){
				msg=msg+'   * Password must have at least one number and be a minimum of 6 characters long. \n';
				rErrors++;
				if(navigator.appName=='Netscape'){
					$('rff_2').setAttribute("class", "formAttention");
				}
				else{
					$('rff_2').className="formAttention";
				}
			}
			else{
				if(navigator.appName=='Netscape'){
					$('rff_2').setAttribute("class", "formField");
				}
				else{
					$('rff_2').className="formField";
				}
			}
			if($('rff_2').value != $('rff_3').value || $('rff_3').value == ''){
				msg=msg+'   * Passwords do not match. Please re-enter your password \n';
				rErrors++;
				if(navigator.appName=='Netscape'){
					$('rff_2').setAttribute("class", "formAttention");
					$('rff_3').setAttribute("class", "formAttention");
				}
				else{
					$('rff_2').className="formAttention";
					$('rff_3').className="formAttention";
				}
			}
			else{
				if(navigator.appName=='Netscape'){
					$('rff_2').setAttribute("class", "formField");
					$('rff_3').setAttribute("class", "formField");
				}
				else{
					$('rff_2').className="formField";
					$('rff_3').className="formField";
				}
			}
			if(rErrors!=0){
				//alert('Please check the form for '+rErrors+' errors\n'+msg);
				incrementErrors(rErrors);
			}
			else{
				formsToCount++;
				return formsToCount;
			}
		}
		else{
			formsToCount++;
			return formsToCount;
		}
	},
	login: function(){
		var lErrors=0;
		var msg="";
		if($('lff_1').value=='' || $('lff_2').value==''){
			msg='* Please enter a valid username and password.';
			lErrors++;
		}
		if(lErrors!=0){
			alert(msg);
			incrementErrors(lErrors);
		}
		else{
			formsToCount++;
			return formsToCount;
		}
	},
	changePassword: function(){
		var cpErrors=0;
		var msg="";
		if($('cpff_2').value=='' || $('cpff_3').value==''){
			msg='* Please enter a valid password.';
			cpErrors++;
		}
		if(($('cpff_2').value != $('cpff_3').value) || $('cpff_2').value == ''|| $('cpff_3').value == ''){
				msg=msg+'   * Passwords do not match. Please re-enter your password \n';
				cpErrors++;
				if(navigator.appName=='Netscape'){
					$('cpff_2').setAttribute("class", "formAttention");
					$('cpff_3').setAttribute("class", "formAttention");
				}
				else{
					$('cpff_2').className="formAttention";
					$('cpff_3').className="formAttention";
				}
			}
			else{
				if(navigator.appName=='Netscape'){
					$('cpff_2').setAttribute("class", "formField");
					$('cpff_3').setAttribute("class", "formField");
				}
				else{
					$('cpff_2').className="formField";
					$('cpff_3').className="formField";
				}
			}
		if(cpErrors!=0){
			alert(msg);
			incrementErrors(cpErrors);
		}
		else{
			formsToCount++;
			return formsToCount;
		}
	},
	company: function(){
		var ccErrors=0;
		for(b=1;b<=14;b++){
			var holder='ccff_'+b;
			if($(holder)){
				if($(holder).value==''){
					ccErrors++;
					if(navigator.appName=='Netscape'){
						$(holder).setAttribute("class", "formAttention");
					}
					else{
						$(holder).className="formAttention";
					}
				}
				else{
					if(navigator.appName=='Netscape'){
						$(holder).setAttribute("class", "formField");
					}
					else{
						$(holder).className="formField";
					}
				}
			}
		}
		if(ccErrors!=0){
			incrementErrors(ccErrors);
		}
		else{
			formsToCount++;
			return formsToCount;
		}
	},
	creditInfo: function(){
		var ciErrors=0;
		for(b=1;b<=7;b++){
			var holder='ciff_'+b;
			if($(holder)){
				if($(holder).value==''){
					ciErrors++;
					if(navigator.appName=='Netscape'){
						$(holder).setAttribute("class", "formAttention");
					}
					else{
						$(holder).className="formAttention";
					}
				}
				else{
					if(navigator.appName=='Netscape'){
						$(holder).setAttribute("class", "formField");
					}
					else{
						$(holder).className="formField";
					}
				}
			}
		}
		if(ciErrors!=0){
			incrementErrors(ciErrors);
		}
		else{
			formsToCount++;
			return formsToCount;
		}
	},
	shipping: function(){
		var sErrors=0;
		if($('shippingTotal').value=='' || $('shippingTotal').value==0){
			sErrors++
			msg+='   * You must select a shipping option.\n';
			//alert(msg);
		}
		if($('shippingError').value=='Zip/Postal Error'){
			sErrors++
			msg+='   * Please check your shipping address. The location you specified cannot be verified by UPS.\n';
		}
		if(sErrors!=0){
			incrementErrors(sErrors);
		}
		else{
			formsToCount++;
			return formsToCount;
		}
	},
	terms: function(){
		if($('tff_1').checked==false){
			incrementErrors(1);
			if(navigator.appName=='Netscape'){
					$('termsCB').setAttribute("class", "formAttention");
				}
			else{
				$('termsCB').className="formAttention";
			}
		}
		else{
			formsToCount++;
			return formsToCount;
			if(navigator.appName=='Netscape'){
				$('termsCB').setAttribute("class", "formField");
			}
			else{
				$('termsCB').className="formField";
			}
		}
	}
}
function incrementErrors(R){
		totalErrors=eval(totalErrors+R);
		formsToCount++;
		return totalErrors;
		return formsToCount;
	}
function tell(formToSubmit,n,mode){
	//alert(formsToCount);
	if(formsToCount==n && totalErrors==0){
		eval('document.'+formToSubmit+'.submit();');
		//alert('all clear');
	}
	else{
		if(mode!='single'){
			//alert('Oops! There are '+totalErrors+' required fields missing from this form.\n Please check the highlighted fields and try again.');
			alert('Oops! There are some problems with this form.\n Please check the highlighted fields and correct any errors.\n'+msg);
		}
		totalErrors=0;
		formsToCount=0;
		msg="";
	}
}



