<!-- 
//================================================================================
// Copyright (C) 2003-2004 Technimedia. All Rights Reserved.
// Your license agreement forbids the removal of this notice.
// License Agreement can be viewed in /$LICENSE.HTM 
//================================================================================
// JavaScript Includes
//================================================================================

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_openBrWindow(theURL,winName,features) { //v2.0
  var WinID = window.open(theURL,winName,features);
  //alert(WinID)
  if (!WinID.opener) WinID.opener = self;
}


//////////////////////////////////////////////////////////////////////////
// Disable form elements toggle function
// el = name of element, turnon = true/false
function setDisable(el, turnon) {
	var f = document.forms[0];
 	if (turnon) {
		f[el].disabled = false;
	} else if (!turnon) {
		f[el].disabled = true;
	}
 } 
///////////////////////////////////////////////////////////////////////////
// A utility function that returns true 
// if a string cotains only whitespace characters
function isblank(s){
	for (var i=0; i<s.length; i++){
		var c = s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '')) return false;
	}
	return true;
}
///////////////////////////////////////////////////////////////////////////
// Validate Form
function ValidateForm(f) {
	//alert("Validate form.")
	if (f.country) {
		if (f.country.value!="US"){
			f.zip.optional = true
			f.state.optional = true;
			}
		}
	var msg = "";
	var empty_fields = "";
	var empty_ddb = "";
	var mismatch_pw = "";
	var mismatch_email = "";
	var bad_email = "";
	var errors = "";
	// Loop through form elements
	for (var i=0; i< f.length; i++) {
		var e = f.elements[i];
		//alert("Field : " + e.id + " Value : " + e.value)
		// Check select boxes to make sure that not the first item is selected
		if (e.type == "select-one" && !e.optional){
			if (e.selectedIndex == 0) {
				empty_ddb += "\n             "  + e.id;
				continue;
				} 
			}
		// Password checker
		if (e.type == "password" && !e.optional){
			//alert("e " + e.type);
			//alert("e2 " + f.elements[i+1].type)
			if (f.elements[i+1].type=="password") {
				var e2 = f.elements[i+1];
				//alert("PW Check " + e2.type);
				if(e.value!=e2.value) {
					mismatch_pw = true
					continue;
					}
				}
			}
		
		// Check for required text fields and textareas
		if (((e.type =="text") || (e.type== "textarea")) && !e.optional) {
			// Check for empty field
			
			if ((e.value == null || e.value == "" ) || isblank(e.value)) {
				empty_fields += "\n             "  + e.id
				continue;
				}

			// Check for required numeric entries
			/*if (e.numeric || (e.min!= null) || (e.max != null)) {
				var v = parseFloat(e.value);
				if (isNaN(v) || ((e.min != null) && (v < e.min)) || ((e.max != null) && ( v> e.max))) {
						errors += "-  The field " + e.name + " must be a number.";
						if(e.min != null)
							errors += " that is greater than " + e.min;
						if(e.max != null && e.min != null)
							errors +=  "  and less than " + e.max;
						else if (e.max != null)
							errors += " that is less than " + e.max;
						errors += "\n";
				}
			}*/
		//////////////////////////////////////////////////////////////////////////////////////
		// begin edit by matryxsoftware 
		//*** EDITED BY TECHNIMEDIA 03/5/04	
		//Email Checker	
		if(f.email) {
			if (f.email.value!==f.em_check.value){
				mismatch_email = true
				continue;
				}		
			//Email Validator
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(f.email.value)){
				bad_email = false
				continue;
			} else {
				bad_email = true
				continue;
				}
			
			}
		// End edit by Matryx Software
		//////////////////////////////////////////////////////////////////////////////////////

			}	
		}
	///////////////////////////////////////////////////////////////
	// If errors then don't submit
	if (!empty_fields && !empty_ddb && !mismatch_pw && !mismatch_email && !errors) return true;
	
	msg += "-----------------------------------------------------------------------------------\n";
	msg +=" This form was not submitted because of the following error(s).\n";
	msg +=" Please correct these errors and re-submit.\n";
	msg +="-----------------------------------------------------------------------------------\n\n";


	if (mismatch_pw) {
		msg += " - The passwords you have entered do not match.\n";
		if (errors || empty_ddb || empty_fields) msg += "\n";
	}

	//////////////////////////////////////////////////////////////////////////////////////
	// begin edit by matryxsoftware 
	
	if (bad_email) {
		msg += " - The email address you have entered appears to be invalid.\n";
		if (errors || empty_ddb || empty_fields) msg += "\n";
	}

	if (mismatch_email) {
		msg += " - The email addresses you have entered do not match.\n";
		if (errors || empty_ddb || empty_fields) msg += "\n";
	}
	
	// End Edit By MATRYXSoftware
	//////////////////////////////////////////////////////////////////////////////////////

	if (empty_fields) {
		msg += " - The following required field(s) are empty:\n" + empty_fields + "\n";
		if (errors || empty_ddb) msg += "\n";
	}
	if (empty_ddb) {
		msg += " - The following require a selection:\n" + empty_ddb + "\n";
		if (errors) msg += "\n";
	}	
	msg += errors;	
	alert(msg);
	return false;	
}

function validateSearch(f) {

		//alert(f,match.checked);
		if (f.match.checked == true && (f.save_search.checked == false) ){
		alert("You have chosen to be notified of new matches to this search.\n You must also save this search to be notified.");
		return false;
		}else{
			//return true;
		}
		
		//alert(f.save_search.checked);
		if (f.save_search.checked == true && ((f.search_name.value == null || f.search_name.value == "" ) || isblank(f.search_name.value)) ) {
		alert("You must enter a name for this search.");
		return false;
		} else {
			return true;
		}
	}


function validateLength(f,e,len){
	
	if (f[e].value.length <= 0 ){
		alert("The field " + f[e].id + " can not be blank.")
		return false;
		}else{	
			//return true;
		}
	
	
	if (f[e].value.length > len) {
		alert("This field only allows " + len + " characters.\n You have entered " + f[e].value.length + ".\nPlease shorten your entry.")
		return false;
		} else {
			return true;
		}
	}

/*function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}*/

// Validate shopping list checkboxes
function ValidateChecks(f) {
	var cnt = 0;
	// Loop through form elements
	for (var i=0; i< f.length; i++) {
		var e = f.elements[i];
		if (e.type == "checkbox" && !e.optional) { 
			//alert("Checkbox.");
			if (e.checked) {
				//alert("Checked.")
				cnt++;
			} 
		}
	}
	if (cnt <= 0) {
		alert("You must check at least one Ad to answer from your shopping list.")
		return false;
	} else {
		return true;
	}
};

function ValidateInput(f) {
	if(f.name=='AddLesson'){
		var e = f.f_lesson_num;
		if((e.value == null || e.value == "" ) || isblank(e.value)) {
			alert("You must enter an ID value for this lesson.\nIt can be alpha-numeric.\nExamples: A, 1a, 2.3, VIII")
			return false;
			}		
		}
	if(f.name=='AddChapter'){
		var e = f.f_chapter_num;
		if((e.value == null || e.value == "" ) || isblank(e.value)) {
			alert("You must enter an ID value for this chapter.\nIt can be alpha-numeric.\nExamples: A, 1a, 2.3, VIII");
			return false;
			}		
		}
		return true;
	}

function toggleCorrect(n) {
	var f = document.forms[0];
	for(i=1;i<=5;i++) {
		f["is_correct_" + i].selected = false;
		}
		f["is_correct_" + n].selected = true;
		return;
}


function toggleChecks(field, state) {
	var f = document.forms[0];
	if (state == "off") {
		for (i = 0; i < f[field].length; i++)
		f[field][i].checked = false;
	} else { 
		for (i = 0; i < f[field].length; i++)
		f[field][i].checked = true;
	}
}

function toggleChecks(theForm, field, state) {
	var f = document[theForm];
	if (state == "off") {
		for (i = 0; i < f[field].length; i++)
		f[field][i].checked = false;
	} else { 
		for (i = 0; i < f[field].length; i++)
		f[field][i].checked = true;
	}
}




function toggleAll(field, i) {
	var f = document.forms[0];
	if (i == 0) { // "All" checkbox selected.
	if (f[field][0].checked == true) {
		for (i = 1; i < f[field].length; i++)
		f[field][i].checked = false;
   		}
	}
	else  {  // A checkbox other than "Any" selected.
		if (f[field][i].checked == true) {
		f[field][0].checked = false;
      }
   }
}

///////////////////////////////////////////////////////////////////////////
function chkTest(formObj) {
	//return confirm('Submit answers and grade test?'); 
	with (formObj) {
		for (i = 0; i < length ; i++) {
			//alert(elements[i].type)
			if (elements[i].type == 'radio'){
				var isChecked = false;
				qName = elements[i].id
				while (elements[i].id == qName) {
					if (elements[i].checked){
						isChecked = true;
					}
					//alert("qName      -->" + qName);
					//confirm("isChecked -->" + isChecked);
					i++
				}
				//alert("Question isChecked -->" + isChecked);
				//} while(elements[i].id == qName);
				if (!isChecked) {
					alert("Please answer "+ qName + ".");
					return false;
				} 
				--i;
			}
		}
	}
	return true;
};
	//}
	//
//};
					
					
					
					
					/*}
				do {
					if (elements[i].checked)
					notChecked = false;
					i++;
					} 
					while (elements[i].name == radName);
					--i;
				
				if (notChecked) {
					alert("Please answer "+ redNum + ".");
					//isOK = false;
					return false;
					} 
					
				}
			}
		}
	}*/
	
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->

