  // JavaScript Document
 // form validator
// (c) www.RobsPcPc.com

window.onerror 	= anError;
var mandatory 	= new Object();
var valuator	= new Object();
var validate	= true;
var taxBase,taxState,savedShip,savedSub;
var	ademail	= /techin\@robspcpc\.com/,
	adname	= /admin/,
	dbugname	= /dbug/;
var UL	= 'Please make the noted corrections and send the form again:';
var FORM1	= 'contact1';

// MOVE THIS 	vv--
/*
mandatory.Name1 	= 'Name is required.';
valuator.Name1	= '.length>1';
mandatory.Comment	= 'Note/Comment is required.';
valuator.Comment	= '.length>1';
mandatory.Email	= 'Email must be valid.';
valuator.Email	= function (wem){
	if(!wem)				{	return 1;	}
	var sr	= /[^a-zA-Z0-9\_\-\.]/;
	var na = wem.split('@');
	if(na[0].length<2)		{	return -1.0;	}
	if(!na[1])				{	return -1.1;	}
	var dm = na[1].split('.');
	if(na[1].length<5)		{	return -1.2;	}
	if(dm[0].length<2)		{	return -2.0;	}
	if(!dm[1])				{	return -2.1;	}
	if(dm[1].length<2)		{	return -2.2;	}
	if(na[0].search(sr)>0)		{	return -3.0;	}
	if(dm[0].search(sr)>0)		{	return -4.0;	}
	if(dm[1].search(sr)>0)		{	return -5.0;	}
	return true;
	};
*/
// MOVE THIS TO PAGE CODE 	--^^


function pressCancel()
{
document.getElementById(FORM1).enctype = 'application/x-www-form-urlencoded';
for (x=1;x<7;x++)
	{
	if(document.getElementById('image'+x) != null|'undefined')
		{	document.getElementById('image'+x).value='';	}
	}
}



function 				calcTotal()
{
var	in1	= savedSub,
	ott	= 0,
	ship	= 0,
	tax1	= 0;
var	ost	= document.getElementById('cust_state').value;
var	pkup	= Number(document.getElementById('deliv_pickup').value)||0;
var	SHIP	= document.getElementById('order_ship');
if(!pkup)
	{
	if(SHIP.type == 'text' && SHIP.value > 0)
		{
		ship	= SHIP;
		
		}
	else
		{	ship	= savedShip;	}
	}
if (document.getElementById('order_exempt').value>'' || ost.toLowerCase() != taxState.toLowerCase())
	{ tax1 = 0; }
else
	{ tax1 = in1*taxBase; }
ott	= in1 + tax1 + ship;
document.getElementById('order_tax').innerHTML		= tax1.toFixed(2);
					SHIP.innerHTML		= ship.toFixed(2);
document.getElementById('order_total').innerHTML	= ott.toFixed(2);
}


function 				init()
{
	document.getElementById('ERR1').innerHTML = '';
}


function 				submitForm(data,val,data2,val2)
{
val = (typeof val == 'undefined')?1:val;
d1	= document.getElementById(data);
d2	= document.getElementById(data2);
f1	= document.getElementById(FORM1);
if(typeof preSubmit == 'function')
	{	preSubmit();	}
if(verifyForm())
	{
	if (d1)
		{ d1.value = val; }
	if (d2 && val2)
		{ d2.setAttribute('value',val2); }
	if(typeof submitUpdate == 'function')
		{	submitUpdate();	}
	f1.submit();
	}
}



function 				verifyForm()
{
var 	locSt	= '',
	errSt	= '';
var ER1 = document.getElementById('ERR1');
var EM1 = (document.getElementById('cust_email') && document.getElementById('cust_email').value.search(ademail)>=0);
var NA1 = (document.getElementById('cust_name') && document.getElementById('cust_name').value.search(adname)>=0);
var DB1 = (document.getElementById('cust_name') && document.getElementById('cust_name').value.search(dbugname)>=0);
		// window.alert("-em: "+EM1+" \n-na: "+NA1+" \n-db: "+DB1);
if(!validate || EM1 || NA1 || DB1)
	{
	if(DB1)
		{
		window.alert("-em: "+EM1+" \n-na: "+NA1+" \n-db: "+DB1);
		}
	else
		{
		return true;
		}
	}
for (CA2 in mandatory)
	{ 
	var CA0,CV0,CV1,CV2;
	CA0	=	CA2.replace(/\d/g,'');
 // window.alert("V[c2]: "+valuator[CA2]+" \nCA2: "+CA2+" \nCA0: "+CA0);
	CV0	= document.getElementById(CA0);
	CV1	= CV0.value;
	if (typeof valuator[CA2] == 'function')
		{
		CV2 = valuator[CA2](CV1);
		}
	else
		{
		CV2 = eval("CV1"+valuator[CA2]); 
		}
	if (CV2>0)
		{ 
		document.getElementById(CA0).parentNode.parentNode.className = "";
		}
	else
		{
		locSt += '<li>'+mandatory[CA2]+'</li>'; 
		document.getElementById(CA0).parentNode.parentNode.className = "errReq1";
		}
	}
if (locSt.length>1)
	{ errSt = '<p>'+UL+'<ul>'+locSt+'</ul></p>'; }
if (errSt!='')
	{
	ER1.innerHTML = errSt;
	// ER1.scrollIntoView();	
	ER1.className = 'err2';
	window.setTimeout("document.getElementById('ERR1').className='err1';",5000);
	return false;
	}
else
	{
	ER1.className = 'invis';
	if(DB1)
		{	return false;	}
	return true;
	}
}



function 				anError(one,two,three)
{
window.alert("Java Error: \n"+one+"\n"+two+"\n"+three);
//stopPropigation();
return false;
}


function 				A_Unc(i1)
{
var i2 = i1.replace(/\+/g,' ');
if(i2.search("/%[A-F0-9]{2}/i"))
	{
	var out2 = unescape(i2);
	return out2;
	}
else
	{ return i1; }
}


function 					A_Enc(i1)
{
	var o1 = unescape(escape(i1));
	var o2 = o1.replace(/([\n\r])/g,'');
	return o2;
}


function chgProp(who,what,how)
{
var frank	= document.getElementById(who);
var e = frank.setAttribute(what,how);
}

// end *.js
