//\///////////////////////////////////////////////////////////////////////////////////
//\ Local jscript for Living Prairie Museum
//\ Last updated Sept.11.2003
//\ S.Vijayvergiya
//\///////////////////////////////////////////////////////////////////////////////////

var NS, VERSION
NS = (navigator.appName == "Netscape");
VERSION = parseInt(navigator.appVersion);

//******************************************************************************
//						general
//******************************************************************************
//clear the contents of a text field
function clearField(textField) {
	textField.value = '';
}
//verify email format
function verifyEmail(textField) {
	var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
  	
  	if(regex.test(textField.value)){
  		return true;
  	}
	else {
		return false;
	}
}
//change the style of the passed object
function cellStyle(obj, new_style) {
	obj.className = new_style;
}
//print the callee page
function printthis(page){ 
	if (NS) {
	page.print() ; 
	} else {
	var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
	document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
	WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box WebBrowser1.outerHTML = ""; 
	}
}
//******************************************************************************
//						functions for eduselect.asp
//******************************************************************************
//resets form so that by default the "all" radio button is selected
//and checkboxes are empty and disabled
function resetEduSelForm(){
	
	if (typeof document.eduForm != 'undefined'){
	
		var theForm
		theForm = document.eduForm;
		theForm.all[0].checked = true;
		
		//reset all checkboxes	
		for (i = 0; i < theForm.length; i ++){
			if(theForm.elements[i].name.charAt(0) == 'o') {
				theForm.elements[i].checked = false;
				theForm.elements[i].disabled = true;
			}
		}
	}
}	
//toggle the checkboxes selectability
function toggleOptions(){
	var theForm
	theForm = document.eduForm;
	
	//disable and clear checkboxes
	if (theForm.all[0].checked) {
		resetEduSelForm();
	}
	//enable checkboxes
	else {
		for (i = 0; i < theForm.length; i++) {
			if (theForm.elements[i].name.charAt(0) == 'o') {
				theForm.elements[i].disabled = false;
			}
		}
	}
}
//******************************************************************************
//						functions for cart.asp
//******************************************************************************
//verify that something is entered as both username and password in a form
function verifyLogin(aForm){
	if(aForm.uname.value == '' || aForm.pword.value == ''){
		alert('please enter a username and password')
	} else {
		aForm.submit();
	}
}

//verify that something is entered as both name and email
function verifyMailList(aForm){
	
	var alertMsg, canSubmit
	canSubmit = true;
	alertMsg = ''
	
	if(aForm.cname.value == ''){
		canSubmit = false;
		clearField(aForm.cname)
		alertMsg = alertMsg + '  - tell us your name\n'
	}
	if(!verifyEmail(aForm.email)){
  		canSubmit = false;
  		alertMsg = alertMsg + '  - check the email address entered\n'
  	}
  	if(!canSubmit){
		alert('Please check the following:\n\n' + alertMsg)
	} else {
		aForm.submit();
	}
}
//verify the contents of the customer detail form
function verifyRegistration(aForm){
	
	var alertMsg, canSubmit
	canSubmit = true;
	alertMsg = ''
	
	if(aForm.uname.value == '' || aForm.uname.value.length < 6 || aForm.uname.value.length > 8){
		canSubmit = false;
		clearField(aForm.uname)
		alertMsg = alertMsg + '  - username must be between 6 and 8 letters\n'
	}
	if(aForm.pword1.value != aForm.pword2.value || aForm.pword1.value == '' || aForm.pword2.value == ''){
		canSubmit = false;
		clearField(aForm.pword1)
		clearField(aForm.pword2)
		alertMsg = alertMsg + '  - the passwords you entered do not match\n'
	}
	if(aForm.fname.value == ''){
		canSubmit = false;
		alertMsg = alertMsg + '  - enter your first name or organization name\n'
	}
	//if(aForm.lname.value == ''){
	//	canSubmit = false;
	//	alertMsg = alertMsg + '  - last name\n'
	//}
	if(aForm.add1.value == ''){
		canSubmit = false;
		alertMsg = alertMsg + '  - enter your mailing address\n'
	}
	
	//if the order of province/country options in the select box is changed then change this:
	//the blank option indicies are to be checked
	if((aForm.country.selectedIndex == 0 && aForm.province.selectedIndex == 0) || aForm.province.selectedIndex == 14){
		canSubmit = false;
		alertMsg = alertMsg + '  - enter your province or territory\n'	
	}
	if(aForm.city.value == ''){
		canSubmit = false;
		alertMsg = alertMsg + '  - enter your city\n'
	}
	if(aForm.postal.value == ''){
		canSubmit = false;
		alertMsg = alertMsg + '  - enter your postal code\n'
	}
  	if(!verifyEmail(aForm.email)){
  		canSubmit = false;
  		alertMsg = alertMsg + '  - enter/check your email address\n'
  	}
	if(!canSubmit){
		alert('Please check the following:\n\n' + alertMsg)
	} else {
		aForm.submit();
	}
}
//******************************************************************************
//						functions for adding links
//******************************************************************************
//verify "add link" form contents before sending
function verifyLinkForm(aForm){
	
	var alertMsg, canSubmit
	canSubmit = true;
	alertMsg = ''
	
	if (aForm.contName.value == ''){
		canSubmit = false;
		alertMsg = alertMsg + ' - enter the contact name\n'
	}
	if (aForm.siteName.value == ''){
		canSubmit = false;
		alertMsg = alertMsg + ' - enter the website address\n'
	}
	if (aForm.siteURL.value == ''){
		canSubmit = false;
		alertMsg = alertMsg + ' - enter the website name\n'
	}
	if(!verifyEmail(aForm.email)){
  		canSubmit = false;
  		alertMsg = alertMsg + ' - enter/check your email address\n'
  	}
	if(!canSubmit){
		alert('Please check the following:\n\n' + alertMsg)
	} else {
		aForm.submit();
	}
}