// JavaScript Document
// start contact.js for chirolane.com
// (c)www.robspcpc.com

document.blockkey = true;
var rev = '20090221.0045';
var verify 	= true;
var GoSubmit	= true;
var EEE	= new Array();
window.onerror = anError;
//var checkarray	= new Object();



function submitForm(data,val,data2,val2)
{
val = val||1;
fm1 = document.getElementById('contact1');
GoSubmit	= (document.getElementById('Name').value != 'HOLD');
if ((typeof document.getElementById(data) != 'undefined') && data)
	{ document.getElementById(data).setAttribute('value',val); }
if ((typeof document.getElementById(data2) != 'undefined') && val2)
	{ document.getElementById(data2).setAttribute('value',val2); }
if(document.getElementById('file1') && document.getElementById('file1').value) 
	{ upload_temp(); }
if(typeof checkarray == 'object' && verify)
	{ if(verifyForm())
		{
		if (GoSubmit)
			{ fm1.submit(); }
		else
			{ window.alert('Form validated ok.'); }
		}
	}
else
	{
	if (GoSubmit)
		{ fm1.submit(); }
	else
		{ window.alert('Form validated ok.'); }
	}
}


// new: verify overrides; ding sets verify if assignd; dong overrides announcement of errors.

function init()
{
	document.getElementById('globalBody').onkeydown = checksubmit;	
}

function checksubmit(tree)
{
var F1	=  document.getElementById('contact1');
var B1	= document.getElementById('Name').value == 'admin';
if(!tree)
	{ tree	= window.event;	}
var pcode	= tree.keyCode;
if(B1)
	{
	window.alert('tree:'+ (typeof tree)+ '\n event:' + typeof window.event + '\n key: ' + (typeof tree.keyCode) + '\n code:'+pcode + ' block:' + document.blockkey);
	}
if (pcode == 13)
	{
	if(document.blockkey)
		{	return false;	} 
	else
		{
		var loc_mode = F1.def_mode.value;
		if(F1[loc_mode])
			{ submitform(loc_mode); }
		else
			{ return false; }
		}

	}
if (document.blockkey > 1 && pcode == document.blockkey)
		{ return false; }
}



function verifyForm(ding,dong)
{
var annc = true;
var ERRS = new Object();
if(typeof ding == 'boolean')
	{ verify = ding; }
if(!verify) { return; }
if(typeof dong == 'boolean')
	{ annc = dong; }
var ER1 = document.getElementById('ERR1');
var errSt="";
var locSt="";
ER1.className = 'vis0';
for (CA1 in checkarray)
	{ 
	var CA2;
	CA2 = CA1.replace(/[0-9]/g,'');
	var ob	= checkarray[CA1];
	var cobj	= document.getElementById(CA2);
	var cval	= cobj.value;
	if(cval.match(/manifest/))
		{ window.alert(ob[1]+eval(ob[1])+ob[2]); }
	if (eval(ob[1])) 
		{
		if(!ERRS[CA2])
			{ cobj.parentNode.parentNode.className = "req0"; }
		}
	else
		{ 
		ERRS[CA2]=1;
		if(ob[2].length>0)
			{	locSt += ob[2]+'<br>';	} 
		cobj.parentNode.parentNode.className = "req1";
		}
	}
if (locSt!="")
	{ 
	if(annc)
		{
		ER1.className = 'err2';
		window.setTimeout("document.getElementById('ERR1').className='err1';",5000);
		ER1.innerHTML = "<b>The following errors occurred:</b><br><blockquote>"+locSt+"</blockquote>";
		ER1.scrollIntoView();
		}
	return false;
	}
else
	{
	return true;
	}
}


function 								chkRadio(which)
{
var zzz;
var CCC = document.specForm(which);
for (i=0;i<CCC.length;i++)
	{
		if (CCC[i].checked)
		{
			zzz = CCC[i].value;
		}
	}
return zzz;
}

var AA=1;
function showPass() 
{ 
document.getElementById('login_pw').className = (AA++%2)?'inp1':'inp0';
}


function 								anError(one,two,three)
{
window.alert("Java Error: \n"+one+"\n"+two+"\n"+three);
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 cleanse(whom)
{
	var iam = document.getElementById(whom);
	var ival = iam.value;
	var clean = ival.replace(/([^0-9])/g,'');
	iam.setAttribute('value',clean);
}


function validemail(whom)
{
var iam = document.getElementById(whom);
//window.alert('whom:'+whom);
if(iam.value)
	{
	var ival 	= iam.value;
	var ydom	= (ival.search(/\@\w{2,}/) 	> 1);
	var ynam	= (ival.search(/^\w{2,}/) 	== 0);
	var yloc	= (ival.search(/\.(\w){2,}$/) 	> 4);
	var ylen	= (ival.length	 		> 7);
	var ychr	= (ival.search(/[^a-z0-9\-\.\@\-_]/i)	< 0);
	if(ival.search(/zx/)==0)
		{ window.alert('Email Validation (name,domain,locale,length,characters): '+ynam+ydom+yloc+ylen+ychr); }	
	if(ynam && ydom && yloc && ylen && ychr)
		{ return true; }
	else
		{ window.alert('Email must be in a valid format: `name@domain.loc`'); }
	iam.focus();
	return false;
	}
else
	{
	return true;
	}
}



function showhide(who1,what1,who2,what2)
{
if(document.getElementById(who1)&&what1)
	{	document.getElementById(who1).className=what1;	}
if(document.getElementById(who2)&&what2)
	{	document.getElementById(who2).className=what2;	}
}



function chgprop(who1)
{
if(who1)
	{
	var wha	= who1.split(',');
	var whom	= document.getElementById(wha[0]);
	if(whom)
		{
		whom.setAttribute(wha[1],wha[2]);
		}
	}
}


function LOAD1()
{
for(ee in EEE)
	{
	var QQ = document.getElementById(EEE[ee]);
	if(QQ)
		{	QQ.focus();		}
	}
if(typeof LOADJUMP == 'function')
	{ LOADJUMP(JUMPARGS); }
}


function upload_temp ()
{
var UCEL	= document.all('uploadCell');
	UCEL.innerText = '.. uploading image ..';
	UCEL.scrollIntoView();
}

