// JavaScript Document
// start front.js for SearchSaver @ slcity.com
//	(c) www.RobsPcPc.com

var verify	= true;
var EEE	= new Array();
window.onerror = anError;
var loc_mode,swapinit,checkarray;
var emalert	= false;
var winParams = 'scrollbars=yes,resizable=yes,menubar=no,toolbar=no,width=280,height=280';

function swap(init)
{
if(init)
	{	checkarray = 'checkexist';	}
else
	{	checkarray = 'checknew';		}
}

function submitform(data,val,data2,val2)
{
val = val||1;
fm1 = document.getElementById('form1');
VER = false;
verify = (typeof eval(checkarray) == 'object')?verify:false;
VER = (verify)?verifyForm():true;
if(VER)
	{
	if (typeof document.getElementById(data) != 'undefined')
		{ document.getElementById(data).setAttribute('value',val); }
	if ((typeof document.getElementById(data2) != 'undefined') && val2)
		{ document.getElementById(data2).setAttribute('value',val2); }
	if(data.indexOf('upload')>0)
		{
		if(document.getElementById('file1') && !document.getElementById('file1').value) 
			{
			window.alert("Supply at least one file name for upload or Cancel.");
			return(false);
			}
		else
			{ upload_temp(); }
		}
	fm1.submit();
	}
}



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('errBlock');
var errSt="";
var locSt="";
var locarray = eval(checkarray);
for (CA1 in locarray)
	{ 
	var CA2;
	CA2 = CA1.replace(/[0-9]/g,'');
	var ob	= locarray[CA1];
	var cobj	= document.getElementById(CA2);
	if(cobj.value.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;
		locSt += ob[2]+'<br>'; 
		cobj.parentNode.parentNode.className = "req1";
		}
	}
if (locSt!="")
	{ 
	if(annc)
		{
		ER1.className = 'err2';
		window.setTimeout("document.getElementById('errBlock').className='err1';",5000);
		ER1.innerHTML = "<b>The following errors occurred:</b><br>"+locSt;
		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; }
	if(emalert)	
		{ 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 PRELOAD()
{
var JARGS;
for(ee in EEE)
	{
	var QQ = document.getElementById(EEE[ee]);
	if(QQ)
		{	QQ.focus();		}
	}
if(typeof JUMPARGS != 'undefined')
	{ JARGS = JUMPARGS;	}

if(typeof LOADJUMP == 'function')
	{ LOADJUMP(JARGS); }

if(typeof LOAD1 == 'function')
	{ LOAD1(); }

if(typeof LOAD2 == 'function')
	{ LOAD2(); }

}


function 		 checksubmit(e)
{
var K;
if (e.keyCode) K=e.keyCode;
else K=e.which;
window.status = 'k:'+K;
if(K == 13)
	{
	if(loc_mode>'')
		{ 
		submitform(loc_mode);
		return false; 
		}
	}

}

function openWindow(theURL,winName,features)
{
	var feat1	= features || winParams;
	var name1	= winName || '_blank';
	var UB = window.open(theURL,name1,feat1);
	UB.focus();
}


function chkSMSC(OVR)
{
var ss = document.getElementById('smsc');
var ii = document.getElementById('smsc').selectedIndex;
var sb = document.getElementById('smscdom_b');
var si = document.getElementById('smscdom_I');
var SD = document.getElementById('smsc_dom');
if(ii==1 || (SD.value>'' && !OVR))
	{
	sb.className='vis1';
	ss.selectedIndex=1;
	si.innerHTML = '';
	}
else
	{
	sb.className = 'vis0';
	sb.value = '';
//	si.innerHTML = 'dom: ' + ss.options[ss.selectedIndex].value;
	SD.value	= '';
	}
}


