/*
	E-commerce site version 4.0.0
	-----------------------------

*/
var _FORMS_VERSION_=4.00;
var _FORMS_INSTANCE=1;

var detectChange=0;
var submitting=true;
var userWillTolerate=40; //user waits this long in seconds for form to process
var force=0;
var replID=null
var sfpath='/~cpm071/console/resources/';

//---------------- functions -----------------
function dChge(o){
	detectChange=1;
}
function mgeChge(o){
	dChge();
}
function beginSubmit(callfunction){
	/* submit function developed 2006-04-11
	2007-02-04 moved to MGA, added custom function for control actions
	NEED: error checking function call
	*/
	submitting=true; //set state of form to submitting
	try{
		if(typeof callfunction !=='undefined'){
			eval(callfunction);
		}else{
			g('SubmitApplication').disabled=true;
			g('SubmitStatus1').innerHTML='<img src="/images/assets/processing1.gif" /> Submitting Form.. ';
		}
	}catch(e){
		if(e.description || e.message){
			window.open('/tcpublic/epld_02_exe.php?mode=ctrlFailure&set=2&page='+thispage+'&browser='+browser+'&error='+escape(e.description+e.message),'w3');
		}
	}
	//window.body.cursor.style='busy'; 
	setTimeout('submitFail()',userWillTolerate*1000);
	return true;
}
function submitFail(callfunction){
	if(!submitting)return;
	//window.body.cursor.style='pointer'; 
	try{
		if(typeof callfunction !=='undefined'){
			eval(callfunction);
		}else{
			g('SubmitApplication').disabled=false;
			g('SubmitStatus1').innerHTML=' ';
		}
	}catch(e){
		if(e.description || e.message){
			window.open(sfpath+'/bais_02_exe.php?mode=ctrlFalure&set=2&page='+thispage+'&browser='+browser+'&error='+escape(e.description+e.message),'w3');
		}
	}
	alert('There was an error in submitting this information; it looks like it was not successful;\nPlease refresh this page and try one more time.');
	window.open(sfpath+'/bais_02_exe.php?mode=email_emergency&page='+thispage+'&browser='+browser,'w3');
	submitting=false;
}
function focus_nav_cxl(queryMode, msg){
	if(typeof force=='undefined')force=0;
	if(typeof msg=='undefined')msg='You have changed this record\nClicking "OK" will close this page and changes will be lost (click "Cancel" to cancel and return to the record)';
	if(detectChange && !force && !confirm(msg)) return;
	window.close();
}
function focus_nav(navig,queryMode,force,postAdd, focusNavQuery){
	//version 1.3 updated 2007-03-11 - added ability to add query string additions by function
	//version 1.2 updated 2006-02-01 - handles new "remain" mode
	//added 2005-11-03
	/***
	Copied from VH1 v2.4.4 - changes noted [*]
	The function is designed to handle all requests that would be made in focus mode (similar to looking at an invoice in QuickBooks) Possible actions:
	1. navigate (next and previous)
	2. update and set for navigate
	3. update and set for closure
	4. insert new and set for new
	5. insert new and set for closure
	6. [insert new and set for navigate {previous}]
	7. close
	8. [return: for single window mode only]
	9. no action
	10. insert and set to remain - version 1.2
	***/
	if(navig){
		//new feature of previous nav request on an INSERT included
		if(detectChange){
			if(queryMode=='insert' || (force==1 || confirm('You have made changes, save them?')) ){
				//alert('#2 or #6');
				//#2. update and set for navigate
				//#6. insert new and set for nav [previous]
				g('navMode').value='navig'; // [*]
				g('nav').value=navig; // [*] - removed "null" prefix
				document.forms['form1'].submit();
				return;
			}
			//#9. Else no action
			//alert('#9');
			return;
		}
		//#1. Navigate - simplest request - gotten from environment variables exc. for navig
		//alert('#1'); // [*] - custom location, changed query string
		if(typeof focusNavQuery!=='undefined'){
			eval('var q='+focusNavQuery+';');
		}else var q='';
		window.location=thispage+'?navMode=navig&count='+count+'&abs='+ab+'&nav='+navig+q;
	}else{
		//possible requests to: update and kill, update and return, insert and new, insert and close
		if(detectChange){
			if(queryMode=='insert'){
				if(postAdd==2){
					//#10. insert and set to remain
					//alert('#10');
					g('navMode').value='remain';
					g('nav').value=''; // [*]
					document.forms['form1'].submit();
					return;
				}else if(postAdd==1){
					//#4. insert and set for new
					//alert('#4');
					g('navMode').value='insert'; // [*]
					g('nav').value=''; // [*]
					document.forms['form1'].submit();
					return;
				}else{
					//#5. insert and set for closure
					//(note: in single window mode, we'd return to last list)
					//alert('#5');
					g('navMode').value='kill'; // [*]
					g('nav').value=''; // [*]
					document.forms['form1'].submit();
					return;
				}
			}else{
				if(force==1 || confirm('You have made changes, save them?')){
					//#3. update and set for closure
					//alert('#3');
					g('navMode').value='kill'; // [*]
					g('nav').value=''; // [*]
					document.forms['form1'].submit();
					return;
				}
				//#9. Else no action
				//alert('#9');
				return;
			}
		}
		//#7. close - in single window mode we'd return to last list
		//alert('#7');
		window.close();
	}
}
function clear_form(ignores, sets, setLabels, formname){
	/**
	2007-02-25: hours and hours on this thing to make it x compatible - works but boy I need help with js.  I'm still shaky with checkboxes and radio buttons, not sure about select-multiples
	2007-02-07: this now has the ability to setLabels and ghosting
	Created 2005-12-02, ignores is a comma-delimited string like 'option1,option2'.  Sets references an array. This function needs a way to specifically NAME fields to clear and also needs to be more compact/elegant
	**/
	var ignore=new Array();
	if(typeof ignores!=='undefined'){
		var temp=ignores.split(',');
		for(i in temp)ignore[temp[i]]=1;
	}
	if(typeof sets=='undefined'){
		var sets=new Array();
	}
	if(typeof setLabels=='undefined')var setLabels= false;
	if(typeof formname=='undefined')var formname= 'form1';
	if(typeof document.forms[formname]=='undefined'){
		alert(formname+' does not exist');
		return false;
	}
	var e,id,tag,type;
	for(var j in document.forms[formname].elements){
		if(typeof document.forms[formname].elements[j]!=='object')continue;
		e=document.forms[formname].elements[j];
		//element id
		try{
			id='';
			id=e.getAttribute('id');
		}catch(e2){ if(e2.message || e2.description)continue; }
		if(!id)continue;
		//element tag name
		try{
			tag='';
			tag=e.tagName;
		}catch(e3){ if(e3.message || e3.description)continue; }
		if(!(tag=='INPUT' || tag=='SELECT' || tag=='TEXTAREA'))continue;
		//element type
		type='';
		if(g(id).getAttribute('type'))type=g(id).getAttribute('type');
		//ignore specified elements
		if(typeof ignore[id]!=='undefined')continue;
		if(typeof sets[id]!=='undefined'){
			if(type=='checkbox' || type=='radio'){
				g(id).checked=true;
			}else if(type!=='file'){
				g(id).setAttribute('value',sets[id]);
				g(id).className='noGhost';
			}
			continue;
		}
		//do not touch buttons or hidden fields
		if(type=='button' || type=='submit' || type=='hidden')continue;
		//clear the rest
		if(type=='checkbox' || type=='radio'){
			g(id).checked=(g(id).defaultChecked ? true : false);
		}else if(type=='file'){
			g(id).value='';
			g(id).className='noGhost';
		}else{
			if(setLabels && typeof labels[id]!=='undefined'){
				g(id).className='ghost';
				g(id).value=labels[id];
			}else{
				g(id).value='';
				g(id).className='noGhost';
			}
		}
	}
}
function fill(txt,x,type){
	if(type==1 && x.value==txt){
		x.value='';
		x.className='noghost';
	}
	if(type==0 && x.value==''){
		x.className='ghost';
		x.value=txt;
	}
}
/*
function calculatetitles(iblur){
	if(iblur!=='NameSelfAddresseeline'){
		var tit = g('NameSelfTitle').value;
		var fn = g('SystemFirstname').value;
		var m = g('SystemMiddlename').value;
		var ln = g('SystemLastname').value;
		var sal = g('NameSelfSalutation').value;
		var adr = g('NameSelfAddresseeline').value;
		if(tit==' Title')tit='';
		if(fn==' First Name')fn='';
		if(m==' M.N.')m='';
		if(ln==' Last Name')ln='';
		if(sal==' Salutation')sal='';
		if(adr==' Addressee Line')adr='';
		sal+='';
	
		var reg=/ and /;
		if(iblur=='SystemFirstname'){
			g('NameSelfSalutation').value = fn;
		}
		if(sal.match(reg)){
			//title
			if(iblur!=='NameSelfTitle')g('NameSelfTitle').value='Mr. & Mrs.';
			//addressee line
			var al = 'Mr. & Mrs.' + ' ';
			al+=g('NameSelfSalutation').value.replace(reg,' & ') + ' ';
			al+=g('SystemLastname').value;
			g('NameSelfAddresseeline').value = al;
		}else{
			g('NameSelfAddresseeline').value = tit+' '+fn+' '+m+(m?' ':'')+ln;
		}
		if(g('NameSelfSalutation').value!==' Salutation')
			g('NameSelfSalutation').className='noGhost';
		if(g('NameSelfAddresseeline').value!==' Salutation')
			g('NameSelfAddresseeline').className='noGhost';
	}
}
function selectAddTitle(x){
	var y=g('NameSelfTitle');
	for(i=0;i<y.length;i++){
		if(y[i].value.toLowerCase()==x.toLowerCase()){
			y[i].selected=true;
			return true;
		}
	}
	//add value if not there
	y[y.length]=new Option(x, x, true, true);
}
*/
function countryInterlock(x, StateElementId, CountryElementId){
	a_state=g(StateElementId);
	a_country=g(CountryElementId);
	if(x==CountryElementId){
		switch(true){
			case a_country.value=='CAN' && !in_array(a_state.value, canada):
			case a_country.value=='USA' && (in_array(a_state.value, canada) || a_state.value=='UNK'):
				a_state.value='';
			break;
			case (a_country.value!=='' && a_country.value!='USA' && a_country.value!='CAN'):
				a_state.value='UNK';
			break;
		}
	}
	if(x==StateElementId){
		switch(true){
			case in_array(a_state.value, canada):
				a_country.value='CAN'; break;
			case a_state.value=='UNK' && (a_country.value=='USA' || a_country.value=='CAN'):
				a_country.value=''; break;
			case a_state.value!=='':
				a_country.value='USA';
		}
	}
}
function darken( f, mode ){
	typeof f=='undefined'?f='form1':'';
	typeof mode=='undefined'?mode='':'';
	/*
	var labels = new Array();
	labels['re_company']=' Company Name';
	labels['FirstName']=' First Name';
	labels['Email']=' Email';
	labels['MiddleName']=' M.N.';
	labels['LastName']=' Last Name';
	labels['Address']=' Address';
	labels['City']=' City';
	labels['Zip']=' Zip';
	labels['Phone']=' Phone';
	labels['WorkPhone']=' Work Phone';
	labels['Fax']=' Fax';
 	labels['UserName']=' User Name';
 	labels['MisctextParentnotes']=' Notes';
 	labels['MisctextChildnotes']=' Notes';
 	labels['MisctextStaffnotes']=' Notes';
 	labels['PagerVoice']=' Pager/Voice';
 	labels['DateReleased']=' (N/A)';
	*/
	for(var x in labels){
      if(typeof document.forms[f].elements[x]=='undefined')continue;
      if(mode=='clear' && document.forms[f].elements[x].value=='')document.forms[f].elements[x].value=labels[x];
      if(document.forms[f].elements[x].value!=labels[x]){
			document.forms[f].elements[x].className='noGhost';
		}else{
			document.forms[f].elements[x].className='ghost';
		}
   }
}
function expandtext(txtSrcID,locus,next){
	if(typeof next!=='undefined') nextFocus=next;
	replID=txtSrcID;
	document.getElementById('panel').style.visibility='visible';
	var point=GetAbsolutePosition(document.getElementById(locus));
	document.getElementById('panel2').style.top=(point.y - 6)+'px';
	document.getElementById('panel2').style.left=(point.x - 407)+'px';
	document.getElementById('panel2').style.visibility='visible';
	document.getElementById('expanded').value=document.getElementById(txtSrcID).value;
	document.getElementById('expanded').focus();
	return;
}
function fillclose(o){
	document.getElementById(replID).value=o.value;
	document.getElementById('panel').style.visibility='hidden';
	document.getElementById('panel2').style.visibility='hidden';
	if(nextFocus) document.getElementById(nextFocus).focus();
}