
function testForm (ref){
	var allforms = new Array () ;
	allforms['jform'] = new Array (
		'name' , new Array ( 'trim(value).length > 0' , 'Please enter your name' ) ,
		'hphone' , new Array ( 'trim(value).length > 0' , 'Please enter your phone number' ) ,
		'email' , new Array ( 'trim(value).length > 0' , 'Please enter a valid e-mail address' ) ,
		'position' , new Array ( 'trim(value).length > 0' , 'Please indicate the position you are applying for' ) ,
		'ssn' , new Array ( 'trim(value).length > 0' , 'Please provide your social security number' ) ,
		'other_names' , new Array ( 'value[0].checked==true || value[1].checked==true' , 'Please indicate whether you have ever been employed under other names' ) ,
		'us_authorized' , new Array ( 'value[0].checked==true || value[1].checked==true' , 'Please indicate whether you are authorized to work in the United States' ) ,
		'agreement' , new Array ( 'value.checked==true' , 'Please indicate that you agree with the terms of application' ) 
	);
	
	allforms['wform'] = new Array (
		'email' , new Array ( 'is_email(value)' , 'Please enter a valid e-mail address' ) , 
		'name' , new Array ( 'trim(value).length > 0' , 'Please enter the name of the contact person' ) ,
		'cname' , new Array ( 'trim(value).length > 0' , 'Please enter your company name' ) ,
		'address1' , new Array ( 'trim(value).length > 0' , 'Please enter your company address' ) ,
		'city' , new Array ( 'trim(value).length > 0' , 'Please enter city' ) ,
		'state' , new Array ( 'trim(value).length > 0' , 'Please enter state' ) ,
		'zip' , new Array ( 'trim(value).length > 0' , 'Please enter ZIP' ) ,
		'phone' , new Array ( 'trim(value).length > 0' , 'Please enter the contact phone number' ) 
	);
	
	allforms['cform'] = new Array (
		'email' , new Array ( 'is_email(value)' , 'Please enter a valid e-mail address' ) , 
		'message' , new Array ( 'trim(value).length > 0' , 'What is your message?' ) 
		
	);
	
	allforms['pform'] = new Array (
		'email' , new Array ( 'is_email(value)' , 'Please enter a valid e-mail address' ) 
		
	);
	
	allforms['lform'] = new Array (
		'username' , new Array ( 'is_email(value)' , 'Please enter your username' ) ,
		'password' , new Array ( 'trim(value).length > 0' , 'Type in your password' )
		
	);
	
	var f = document[ref] ;
	var cond , valname;
	for (var i = 0 ; i < allforms[ref].length ; i += 2 ) {
		valname =  (!f[allforms[ref][i]].type || f[allforms[ref][i]].type.indexOf('select') > -1 || f[allforms[ref][i]].type.indexOf('checkbox') > -1) ? '' : '.value'  ;
		cond = allforms[ref][i+1][0].replace (/value/g , "f." + allforms[ref][i] + valname);
		if (!eval (cond)){
			alert (allforms[ref][i+1][1]);
			return false ;
		}
	}
	return true ;
}

function trim (str){
	return str.replace(/^\s*|\s*$/g,"") ;
}

function is_email(str) {
	var str = trim (str) ;
	if (str.indexOf(" ") != -1){
		return false;
	}else if (str.indexOf("@") == -1){
		return false;
	}else if (str.indexOf("@") == 0){
		return false;
	}else if (str.indexOf("@") == (str.length-1)){
		return false;
	}
	var arrayString = str.split("@");
	if (arrayString[1].indexOf(".") == -1){
		return false;
	}else if (arrayString[1].indexOf(".") == 0){
		return false;
	}else if (arrayString[1].charAt(arrayString[1].length-1) == ".") {
		return false;
	}
	return true;
}



function addToCart (part , page , cat , stock){
	var quan = document.getElementById ('quan_' + part ).value ; 
	if (stock <= 0 ) {
		alert ('This item is out of stock.') ;
		return false ;
	}
	if (!parseInt(quan) || parseInt(quan) <= 0) {
		alert ('Please specify the quantity you are ordering');
		return false ;
	}
	if (parseInt(quan) > parseInt(stock) ) {
		if(!confirm ('We have only ' + stock + ' of this item and you are requesting: ' + quan + "\n\n" + "Click OK to order " + stock ) ){
			return false ;
		}	
	}
	window.location = base_href + 'content/page/' + page +'/cat/' + cat + '/cartadd/' + part + '/quan/' + quan	;
}

















