var canada = new Array('AB','BC','MB','NB','NF','NS','NT','ON','PE','PQ','QC','SK','YT');
var submitting=true;
var detectChange=0;
userWaits=10; //user waits this long in seconds for form to process
function mgeChge(o){
	detectChange=1;
}
function g(x){ return document.getElementById(x); }
function ckPass(){
	if(g('Password').value==''){
		alert('Password must not be blank');
		return false;
	}
	if(g('nullPassword').value!==g('Password').value){
		alert('Passwords do not match');
		return false;
	}
	return true;
}
function beginSubmit(){
	submitting=true; //set state of form to submitting
	try{
		document.getElementById('SubmitMain').disabled=true;
		document.getElementById('SubmitStatus').innerHTML='<img src="images/animblue.gif" /> Sending your information.. ';
	}catch(e){  }
	setTimeout('submitFail()',userWaits*1000);
}
function submitFail(){
	if(!submitting)return;
	try{
	document.getElementById('SubmitMain').disabled=false;
	document.getElementById('SubmitStatus').innerHTML=' ';
	}catch(e){ }
	alert('There was an error in submitting this information; it looks like it was not successful;\nPlease refresh this page (Control-R or F5) and try one more time.');
	window.open('usemod_01_exe.php?mode=email_emergency&page=contact_us.php','w4');
	submitting=false;
}
function in_array(needle,haystack){//about the same as the function in PHP
	strCase=1; //insensitive (2=sensitive)
	loc=10; //value (11=key)
	for(i=2;i<arguments.length;i++){
		arguments[i]=='sensitive' || arguments[i]==2?strCase=2:'';
		arguments[i]==11 || arguments[i]=='key'?loc=11:'';
	}
	//find the value
	for(j in haystack){
		if(strCase==1){
			if(loc==10 && haystack[j].toLowerCase()==needle.toLowerCase()){
				return true;
			}else if(loc==11 && j.toLowerCase()==needle.toLowerCase()){
				return true;
			}
		}else{
			if((loc==10 && haystack[j]==needle) || (loc==11 && j==needle)){
				return true;
			}
		}
	}
	return false;
}
function countryInterlock(x, StateElementId, CountryElementId){
	/**
	2005-08-11: only real difficulty about this function is its translation between AddressHomeState and ad_state, etc.
	**/
	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!='CAN' && 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';
		}
	}
}

