function itemDisplay(i,x) {
	if (document.all){
		document.all[i][x].style.display = '';
	}
	else if (document.getElementById){
		document.getElementById(i)[x].style.display = ''
	}
}
function itemHide(i,x) {
	if (document.all){
		document.all[i][x].style.display = 'none';
	} else if (document.getElementById){
		document.getElementById(i)[x].style.display = 'none'
	}
}	
function rowShow(rowid) {
	if (document.all){
		try {
			document.all[rowid].style.display = 'table-row';
		} catch(e) {
			document.all[rowid].style.display = 'block';
		} 
	}
	else if (document.getElementById){
		try {
			document.getElementById(rowid).style.display = 'table-row';
		} catch(e) {
			document.getElementById(rowid).style.display = 'block';
		}
	}
}
function rowHide(rowid) {
	if (document.all){
		document.all[rowid].style.display = 'none';
	} else if (document.getElementById){
		document.getElementById(rowid).style.display = 'none'
	}
}
function validateTextareaLength(formfieldname,formfield,maxChar) {
    if (formfield.value.length > maxChar) {
        diff=formfield.value.length - maxChar;
        if (diff>1) {
            diff = diff + " characters";
        } else {
            diff = diff + " character";
        }   
        alert("The " + formfieldname + " field is limited to " + maxChar + " characters.\n" + "Please reduce the text by " + diff + ".");
	formfield.select();
	return 'too long';

    }
}
function validatePassword(frm) {
	pw=frm.password.value
	pwlen=pw.length
	pw2=frm.password2.value
	if (pwlen <6 || pwlen >12) {
		alert("Please enter a password that is between 6 and 12 characters.")
		frm.password.focus();
		return false;
	}
	if (pw != pw2) {
		alert("The password entries do not match.")
		frm.password.focus();
		return false;
	}
}		

function checkAll(field) {
	if(field) {
		if (!field.length) {
			field.checked=true;
		} else {
			for (i = 0; i < field.length; i++)
			if(!field[i].disabled) {
				field[i].checked=true;
			}
		}
	}
}

function switchDiv(div) {
	document.getElementById(div).style.display=document.getElementById(div).style.display=='' ? 'none' : '';
	document.getElementById(div+'link').innerHTML=document.getElementById(div).style.display=='' ? 'Less..' : 'More..';
}

//SUBFUNCTIONS
function cleanVar(cleaned) {
	//remove beginning and ending spaces and white space characters
	return cleaned.replace(/^[ ]*([^ ]*)[ ]*$/, "$1").replace(/\s*/, "");
}
function validEmail(e) {
	filter = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-_0-9]+\.)+[a-zA-Z]{2,}))$/
	return (filter.test(e) && e.substring(e.length,e.length-3) !='.co')
}

function formatPhone(p) {
	p=cleanVar(p);
	re0=/^([^0-9\+\(]+)([0-9\+\(]+)(.+)$/
	if(p.match(re0)){
		oldp=p;
		p=cleanVar(p.replace(re0,"$2$3 $1"));
		alert("FYI: Moving non-phone text to after phone number:\nOld:  "+oldp+"\nNew: "+p);
	}
	//phone with area code
	re1=/^(?:(?:(?:\+1)|(?:1))[ .\-]?)?\(?([2-9]\d{2})(?:(?:\) ?)||[ .\-])([2-9]\d{2})[ .\-]?(\d{4})(( \D.*)?)$/;
	//phone w/o area code
	re2=/^([2-9]\d{2})[ .\-]?(\d{4})(( \D.*)?)$/;
	//international phone
	re3=/^\+?(011).+$/;
	if (p.match(re1)) {
		return p.replace(re1,"($1) $2-$3$4"); // format all US and Canada phone numbers the same
	} else if (p.match(re2)) {
		return p.replace(re2,"(801) $1-$2$3"); // if no area code, default to 801
	} else if (p.match(re3)) {
		return p; //international phone number, leave alone
	} else {
		return '';
	}
}

function validateZip(z) {
	
	filter=/^[0-9]{5}-?[0-9]{4}$|^[0-9]{5}$|^[A-Z][0-9][A-Z][ ]?[0-9][A-Z][0-9]$|^[A-Z]{1,2}[0-9][0-9A-Z]? ?[0-9][A-Z]{2}$/
	
	return filter.test(z);

}
function validateDateMMDDYY(d) {
	filter=/^(([0]*[1-9])|(1[0-9]))\/(([0]*[1-9])|([1-2][0-9])|(3[0-1]))\/[0-9][0-9]$/
	return filter.test(d);
}
function validateDateMMYY(d) {
	filter=/^(([0]*[1-9])|(1[0-9]))\/[0-9][0-9]$/
	return filter.test(d);
}
function validateDateMMDDYYYY(d) {
	filter=/^(([0]*[1-9])|(1[0-9]))\/(([0]*[1-9])|([1-2][0-9])|(3[0-1]))\/((19[5-9][0-9])|(20[0-4][0-9]))$/
	return filter.test(d);
}
function validateDateMMYYYY(d) {
	filter=/^(([0]*[1-9])|(1[0-9]))\/((19[5-9][0-9])|(20[0-4][0-9]))$/
	return filter.test(d);
}
function on(val) {
	var itm = document.getElementById(val);
	if(navigator.appName.indexOf("Microsoft") > -1){ 
		var canSee="block"; 
	} else { 
		var canSee="table-row"; 
	} 
   itm.style.display=canSee;
}
function off(val) {
   var itm = document.getElementById(val);
   itm.style.display="none";
}