// Author: Ian Lawson

/* 
/////////////////////////////
	Input Hover Function
/////////////////////////////
*/
function clear ()
{
	// determine if the form is available
	if(document.getElementById("searchtxt")) 
		{
		// Grab the search box
		var sr = document.getElementById("searchtxt");
		// Attach Focus event handler
		sr.onfocus = function ()
			{
			sr.value = "";
			sr.className = "field_hov";
			}
		// Attach Blur event handler
		sr.onblur = function ()
			{
			sr.className = "field_blur";
				if(sr.value == "")
				{
					sr.value = sr.defaultValue;
				}
			}
	}
}

// fix absolute positioning text selection problem with IE6
if (window.createPopup && document.compatMode &&
 document.compatMode=="CSS1Compat"){
   document.onreadystatechange = onresize = function fixIE6AbsPos(){
     if (!document.body) return;
     if (document.body.style.margin != "0px") document.body.style.margin = 0;
     onresize = null;
     document.body.style.height = 0;
     setTimeout(function(){ document.body.style.height =
 document.documentElement.scrollHeight+'px'; }, 1);
     setTimeout(function(){ onresize = fixIE6AbsPos; }, 100);
   }
 }
 
/* 
/////////////////////////////
	Clear Initial Value
/////////////////////////////
*/ 
function clearIt(field){
if (field.defaultValue==field.value)
field.value = ""
}
 
/* 
/////////////////////////////
	Initiate the functions
/////////////////////////////
*/
window.onload = function() 
{
	clear();
}

/* 
/////////////////////////////
	Validate Membership
/////////////////////////////
*/

// step 1
function Validate() {
			if (document.becomeForm.firstname.value == "") {
				alert("You must supply your first name.");
				document.becomeForm.firstname.focus();
				return false;
			} else if (document.becomeForm.lastname.value == "") {
				alert("You must supply your last name.");
				document.becomeForm.lastname.focus();
				return false;
			} else if (document.becomeForm.address.value == "") {
				alert("You must supply your street address.");
				document.becomeForm.address.focus();
				return false;
			} else if (document.becomeForm.city.value == "") {
				alert("You must supply the city you live in.");
				document.becomeForm.city.focus();
				return false;
			} else if (document.becomeForm.state.value == "") {
				alert("You must supply the state you live in.");
				document.becomeForm.state.focus();
				return false;
			} else if (document.becomeForm.zip.value == "") {
				alert("You must supply your zip code.");
				document.becomeForm.zip.focus();
				return false;
			} else if (document.becomeForm.email.value != "" && !isEmail(document.becomeForm.email.value)) {
				alert("The e-mail address you've supplied doesn't appear to be valid. Please correct it and try again.");
				document.becomeForm.email.focus();
				return false;
			} else if (document.becomeForm.homephone.value == "") {
				alert("You must supply your home phone number.");
				document.becomeForm.homephone.focus();
				return false;
			}
			
			return true;
		} 
		
// step 2
function Validate2() {
				var pledgeValue = parseInt(document.pledgeForm.pledge.value);
				if (isNaN(pledgeValue)) {
					alert("The value of your pledge must be a number.");
					document.pledgeForm.pledge.focus();
					document.pledgeForm.pledge.select();
					return false;
				} else {
					//figure out what the gift level was by splitting the value of the checked radio button
					for (i = 0; i < document.pledgeForm.gift.length; i++) {
						if (document.pledgeForm.gift[i].checked) {
							var giftParts = document.pledgeForm.gift[i].value.split(/_/);
							var giftValue = parseInt(giftParts[1]);
							break;
						}
					}
					
					if (pledgeValue < giftValue) {
						alert("The pledge value you've entered is too low for the gift you've selected. Please either select a gift from a lower gift level or increase your pledge amount.");
						return false;
					}
					
					if (pledgeValue < 60 && document.pledgeForm.memberCard[0].checked) {
						alert("You must enter a pledge value of at least $60 before you can opt to receive the MemberCard. Please either increase your pledge amount or opt out of the MemberCard.");
						return false;
					}
				}
				
				return true;
			} 
// step 3
function Validate3() {
				if (document.billForm.cardtype[0].checked) {
					var billMethod = "invoice";
				} else if (document.billForm.cardtype[1].checked) {
					var billMethod = "visa";
				} else if (document.billForm.cardtype[2].checked) {
					var billMethod = "mc";
				} else if (document.billForm.cardtype[3].checked) {
					var billMethod = "disc";
				} else {
					alert("Please select a billing method.");
					return false;
				}
				
				switch (billMethod) {
					case "invoice":
						break;
					case "visa":
					case "mc":
					case "disc":
						if (document.billForm.cardname.value == "") {
							alert("Please enter your name as it appears on your credit card.");
							document.billForm.cardname.focus();
							return false;
						}
						
						if (document.billForm.cardnumber1.value == "" || document.billForm.cardnumber2.value == "" || document.billForm.cardnumber3.value == "" || document.billForm.cardnumber4.value == "") {
							alert("Please enter your credit card number.");
							document.billForm.cardnumber1.focus();
							document.billForm.cardnumber1.select();
							return false;
						}
						
						if (document.billForm.ccyear.value == "") {
							alert("Please enter your credit card's expiration year.");
							document.billForm.ccyear.focus();
							return false;
						}
						
						break;
				}

				if (!document.billForm.seniorcitizen[0].checked && !document.billForm.seniorcitizen[1].checked) {
					alert("Please specify whether you are a senior citizen.");
					return false;
				}
				
				if (!document.billForm.contact[0].checked && !document.billForm.contact[1].checked && !document.billForm.contact[2].checked) {
					alert("Please specify how you prefer us to contact you.");
					return false;
				}
				
				return true;
			}
			
			
/* 
/////////////////////////////
	Validate Ednews Signup
/////////////////////////////
*/

function ValidateEdnews() {
				var result = false;
				
				if (document.theForm.frm_name.value == "") {
					alert("You must supply your name before continuing.");
					document.theForm.frm_name.focus();
		
				} else if (document.theForm.frm_email.value == "") {
					alert("You must supply your e-mail address before continuing.");
					document.theForm.frm_email.focus();
		
				} else if (document.theForm.frm_schoolName.value == "") {
					alert("You must supply your school's name before continuing.");
					document.theForm.frm_schoolName.focus();
		
				} else {
					result = true;
				}
				
				return result;
			} 