String.prototype.toTitleCase = function() {
var words = this.toLowerCase().split(" ");
for(var i=0;i<words.length;i++)
words[i] = words[i].charAt(0).toUpperCase() + words[i].substring(1);
return words.join(" ");
}

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function getInnerText(node,ignorewhitespace)
{
 var text = "";
 // if the node has children, loop through them
 if(node.hasChildNodes())
 {
  var children = node.childNodes;
  for(var i=0; i<children.length; i++)
  {
   // if node is a text node append it
   if(children[i].nodeName == "#text")
   {
    if(ignorewhitespace)
    {
     if(!/^\s+$/.test(children[i].nodeValue))
     {
      text = text.concat(children[i].nodeValue);
     }
    }
    else
    {
     text = text.concat(children[i].nodeValue);
    }
   }
   // if node is a line break append \n
   else if(children[i].nodeName == "BR")
   {
    text = text.concat("\n");
   }
   // otherwise call this function again to get the text
   else
   {
    text = text.concat(getInnerText(children[i]));
   }
  }
 }
 // it has no children, so get the text
 else
 {
  // if node is a text node append it
  if(node.nodeName == "#text")
  {
   text = text.concat(node.nodeValue);
  }
  // if node is a line break append \n
  else if(node.nodeName == "BR")
  {
   text = text.concat("\n");
  }
 }
 return text;
}

function popupWindow(whatURL) {
	poppedWindow=window.open(whatURL,"poppedWindow","toolbar=no,width=440,height=300,directories=no,status=no,scrollbars=yes,resize=no,menubar=no");
}

function popupMapWindow(whatURL) {
	poppedMapWindow=window.open(whatURL,"poppedMapWindow","toolbar=no,width=500,height=300,directories=no,status=no,scrollbars=yes,resize=no,menubar=no");
}

function confirmBox(whatURL) {
	if (formChanged==1) {
		if (confirm("You have not saved your changes.\nHit CANCEL then SAVE INFORMATION.\nHit OK to go on without saving.")) {
			window.location=whatURL;
		}
	} else {
		window.location=whatURL;
	}
}

function popupWindowConfirmBox(whatURL) {
	if (formChanged==1) {
		if (confirm("You have not saved your changes.\nHit CANCEL then SAVE INFORMATION.\nHit OK to go on without saving.\nHit CLOSE when done.")) {
	poppedWindow=window.open(whatURL,"poppedWindow","toolbar=no,width=440,height=300,directories=no,status=no,scrollbars=yes,resize=no,menubar=no");
		}
	} else {
	poppedWindow=window.open(whatURL,"poppedWindow","toolbar=no,width=440,height=300,directories=no,status=no,scrollbars=yes,resize=no,menubar=no");
	}
}

// Disable submit when clicked.
function disableSubmit(buttonName,formName) {
	var whichForm=eval('document.' + formName);
	var whichButton=eval('document.' + formName + '.' + buttonName);
	whichButton.disabled=true;
	whichButton.className='greybutton';
	whichForm.submit();
}

// Take user here after session timed out
timedouturl = "/login/index.cfm";
function Down() { 
	sec--;      
	if (sec == -1) { 
		sec = 59; 
		min--;
	}
	window.status = "Session will time out in " + min + " minutes " + sec + " seconds.";
	if (min == 5 && sec == 0) {
		alert("Your session will time out in less than 5 minutes.\nPlease submit whatever you are updating now or navigate\nto any other page to reset your 30 minute session.");
	}
	if (min == 0 && sec == 0) {
		alert("Your session has timed out.");
		window.location.href = timedouturl;
	} else {
		down = setTimeout("Down()", 1000);
	}
}

function timeIt(useMinutes) {
	min = useMinutes;
	sec = 0;
	Down();
}

function validate(form_id,email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = document.forms[form_id].elements[email].value;
   if(reg.test(address) == false) {
      return false;
   }
}

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=3000;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		//alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		//alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		//alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		//alert("Please enter a valid date")
		return false
	}
return true
}

function ValidateForm(){
	var dt=document.frmSample.txtDate
	if (isDate(dt.value)==false){
		dt.focus()
		return false
	}
    return true
 }


/*

// Generic rollover functions

function overImage(imgName) {
	if (document.images) {
		imgOn = eval(imgName + "on.src");
		document [imgName].src = imgOn;	
	}
}

function offImage(imgName) {
	if (document.images) {
		imgOff = eval(imgName + "off.src");
		document [imgName].src = imgOff;	
	}
}

function loadImages() {
	on = new Image();
	on.src = "/images/1.gif";
	off = new Image();
	off.src = "/images/0.gif";
}


// if (document.images) {
//	loadImages();
// }

*/

// Returns a handle to the named layer.

function getLayer(name) {

	if (document.layers) {
		return(document.layers[name]);
	}
	else {
		layer = document.getElementById(name);
		if (layer) {
			return(layer);
		} else {
			return(null);
		}
	}
}

// Hides the named layer

function hideLayer(name) {

	var layer = getLayer(name);

	if (layer.style) {
		layer.style.visibility="hidden";	
	} else {
		layer.visibility="hide";
	}

}

// Shows the named layer

function showLayer(name) {

	var layer = getLayer(name);

	if (layer.style) {
		layer.style.visibility="visible";	
	} else {
		layer.visibility="show";
	}

}

function checkReg1() {
	errorMsg='';
	if (!isDate(document.registration.dob.value)) {
		document.getElementById('dobForm').className='ltredbarline';
		errorMsg+='Please enter a valid birthday in mm/dd/yyyy format.\n';
	} else {
		document.getElementById('dobForm').className='ltbluegrey';
	}
	if (document.registration.HSgradYear.selectedIndex==0) {
		document.getElementById('HSgradYearForm').className='ltredbarline';
		errorMsg+='Please enter your graduation year.\n';
	} else {
		document.getElementById('HSgradYearForm').className='ltbluegrey';
	}
	if (document.registration.postal.value.length<5) {
		document.getElementById('postalForm').className='ltredbarline';
		errorMsg+='Please enter your valid zip/postal code.\n';
	} else {
		document.getElementById('postalForm').className='ltbluegrey';
	}
	if (document.registration.schoolID.value==0) {
		document.getElementById('schoolIDForm').className='ltredbarline';
		errorMsg+='Please choose your school.\n';
	} else {
		document.getElementById('schoolIDForm').className='ltbluegrey';
	}
	if (!document.registration.schoolGSA[0].checked&&!document.registration.schoolGSA[1].checked&&!document.registration.schoolGSA[2].checked) {
		document.getElementById('schoolGSAForm').className='ltredbarline';
		errorMsg+='Please choose if your school has a GSA.\n';
	} else {
		document.getElementById('schoolGSAForm').className='ltbluegrey';
	}
	if (errorMsg=='') {
		return true;
	} else {
		alert(errorMsg);
		return false;
	}
}

function otherReg() {
	if (document.registration.state.selectedIndex==2) {
		document.getElementById('otherForm').className='displayinline';
		document.getElementById('countryForm1').className='displayinline';
		document.getElementById('countryForm2').className='displayinline';
		document.getElementById('countryForm1a').className='padding4';
		document.getElementById('countryForm2a').className='padding4';
	} else {
		document.getElementById('otherForm').className='displaynone';
		document.getElementById('countryForm1').className='displaynone';
		document.getElementById('countryForm2').className='displaynone';
		document.getElementById('countryForm1a').className='paddingnone';
		document.getElementById('countryForm2a').className='paddingnone';
		if (document.registration.state.selectedIndex>=68) {
			document.getElementById('countryForm1').className='displayinline';
			document.getElementById('countryForm2').className='displayinline';
			document.getElementById('countryForm1a').className='padding4';
			document.getElementById('countryForm2a').className='padding4';
			document.registration.country.value='Canada';
		} else {
			document.getElementById('countryForm1').className='displaynone';
			document.getElementById('countryForm2').className='displaynone';
			document.getElementById('countryForm1a').className='paddingnone';
			document.getElementById('countryForm2a').className='paddingnone';
			document.registration.country.value='';
		}
	}
}

function mediaReg(doIt) {
	if (doIt&&document.registration.media[0].checked) {
		document.getElementById('parentNameForm2').className='displayinline';
		document.getElementById('parentNameForm2a').className='padding4';	
	} else {
		document.getElementById('parentNameForm2').className='displaynone';
		document.getElementById('parentNameForm2a').className='paddingnone';	
	}	
}

function genderReg(count) {
	if (document.registration.genderID.selectedIndex==count) {
		document.getElementById('otherGenderForm').className='displayinline';
	} else {
		document.getElementById('otherGenderForm').className='displaynone';
	}
}	

function orientationReg(count) {
	if (document.registration.orientationID.selectedIndex==count) {
		document.getElementById('otherOrientationForm').className='displayinline';
	} else {
		document.getElementById('otherOrientationForm').className='displaynone';
	}
}	

function roleReg() {
	if (document.registration.roleID.selectedIndex==2) {	
		document.getElementById('staffForm1').className='displayinline';
		document.getElementById('staffForm2').className='displayinline';
		document.getElementById('staffForm1a').className='padding4';
		document.getElementById('staffForm2a').className='padding4';
	} else {
		document.getElementById('staffForm1').className='displaynone';
		document.getElementById('staffForm2').className='displaynone';
		document.getElementById('staffForm1a').className='paddingnone';
		document.getElementById('staffForm2a').className='paddingnone';
	}
	if (document.registration.roleID.selectedIndex==5) {	
		document.getElementById('parentForm1').className='displayinline';
		document.getElementById('parentForm2').className='displayinline';
		document.getElementById('parentForm1a').className='padding4';
		document.getElementById('parentForm2a').className='padding4';
	} else {
		document.getElementById('parentForm1').className='displaynone';
		document.getElementById('parentForm2').className='displaynone';
		document.getElementById('parentForm1a').className='paddingnone';
		document.getElementById('parentForm2a').className='paddingnone';
	}
	if (document.registration.roleID.selectedIndex==3) {	
		document.getElementById('org1Form1').className='displayinline';
		document.getElementById('org1Form2').className='displayinline';
		document.getElementById('org1Form1a').className='padding4';
		document.getElementById('org1Form2a').className='padding4';
		document.getElementById('org2Form1').className='displayinline';
		document.getElementById('org2Form2').className='displayinline';
		document.getElementById('org2Form1a').className='padding4';
		document.getElementById('org2Form2a').className='padding4';
	} else {
		document.getElementById('org1Form1').className='displaynone';
		document.getElementById('org1Form2').className='displaynone';
		document.getElementById('org1Form1a').className='paddingnone';
		document.getElementById('org1Form2a').className='paddingnone';
		document.getElementById('org2Form1').className='displaynone';
		document.getElementById('org2Form2').className='displaynone';
		document.getElementById('org2Form1a').className='paddingnone';
		document.getElementById('org2Form2a').className='paddingnone';
	}
}

function checkRegD() {
	errorMsg='';
	if (document.registration.firstName.value=='') {
		document.getElementById('firstNameForm').className='ltredbarline';
		errorMsg+='Please enter your first name.\n';
	} else {
		document.getElementById('firstNameForm').className='ltbluegrey';
	}
	if (document.registration.lastName.value=='') {
		document.getElementById('lastNameForm').className='ltredbarline';
		errorMsg+='Please enter your last name.\n';
	} else {
		document.getElementById('lastNameForm').className='ltbluegrey';
	}
	if (!document.registration.useName[0].checked&&!document.registration.useName[1].checked) {
		document.getElementById('useNameForm').className='ltredbarline';
		errorMsg+='Please choose which is your preferred name.\n';
	} else {
		document.getElementById('useNameForm').className='ltbluegrey';
	}
	if (document.registration.sendMailID[0].checked) {
	
		if (document.registration.address1.value=='') {
			document.getElementById('address1Form').className='ltredbarline';
			errorMsg+='Please enter your address.\n';
		} else {
			document.getElementById('cityForm').className='ltbluegrey';
		}
		if (document.registration.city.value=='') {
			document.getElementById('cityForm').className='ltredbarline';
			errorMsg+='Please enter your city.\n';
		} else {
			document.getElementById('cityForm').className='ltbluegrey';
		}
		if (document.registration.state[document.registration.state.selectedIndex].value=='') {
			document.getElementById('stateForm').className='ltredbarline';
			errorMsg+='Please choose your state/province or that it\'s not in the U.S. or Canada.\n';
		} else {
			document.getElementById('stateForm').className='ltbluegrey';
		}
		if (document.registration.state[document.registration.state.selectedIndex].value=='XX'&&document.registration.province.value=='') {
			document.getElementById('stateForm').className='ltredbarline';
			errorMsg+='Please enter your non U.S. or Canada province.\n';
		} else {
			document.getElementById('stateForm').className='ltbluegrey';
		}
		if (document.registration.state[document.registration.state.selectedIndex].value=='XX'&&document.registration.country.value=='') {
			document.getElementById('countryForm').className='ltredbarline';
			errorMsg+='Please enter your country.\n';
		} else {
			document.getElementById('countryForm').className='ltbluegrey';
		}
		if (document.registration.postal.value.length<5) {
			document.getElementById('postalForm').className='ltredbarline';
			errorMsg+='Please enter your valid zip/postal code.\n';
		} else {
			document.getElementById('postalForm').className='ltbluegrey';
		}
	
	}
	if (!isDate(document.registration.dob.value)) {
		document.getElementById('dobForm').className='ltredbarline';
		errorMsg+='Please enter a valid birthday in mm/dd/yyyy format.\n';
	} else {
		document.getElementById('dobForm').className='ltbluegrey';
	}
	if (document.registration.HSgradYear.selectedIndex==0) {
		document.getElementById('HSgradYearForm').className='ltredbarline';
		errorMsg+='Please enter your graduation year.\n';
	} else {
		document.getElementById('HSgradYearForm').className='ltbluegrey';
	}
	if (document.registration.schoolID.value==0) {
		document.getElementById('schoolIDForm').className='ltredbarline';
		errorMsg+='Please choose your school.\n';
	} else {
		document.getElementById('schoolIDForm').className='ltbluegrey';
	}
	if (errorMsg=='') {
		return true;
	} else {
		alert(errorMsg);
		return false;
	}
}

function checkReg2(doIt,titleNum) {
	errorMsg='';
	if (document.registration.firstName.value=='') {
		document.getElementById('firstNameForm').className='ltredbarline';
		errorMsg+='Please enter your first name.\n';
	} else {
		document.getElementById('firstNameForm').className='ltbluegrey';
	}
	if (document.registration.lastName.value=='') {
		document.getElementById('lastNameForm').className='ltredbarline';
		errorMsg+='Please enter your last name.\n';
	} else {
		document.getElementById('lastNameForm').className='ltbluegrey';
	}
	if (!document.registration.useName[0].checked&&!document.registration.useName[1].checked) {
		document.getElementById('useNameForm').className='ltredbarline';
		errorMsg+='Please choose which is your preferred name.\n';
	} else {
		document.getElementById('useNameForm').className='ltbluegrey';
	}
	if (document.registration.city.value=='') {
		document.getElementById('cityForm').className='ltredbarline';
		errorMsg+='Please enter your city.\n';
	} else {
		document.getElementById('cityForm').className='ltbluegrey';
	}
	if (document.registration.state[document.registration.state.selectedIndex].value=='') {
		document.getElementById('stateForm').className='ltredbarline';
		errorMsg+='Please choose your state/province or that it\'s not in the U.S. or Canada.\n';
	} else {
		document.getElementById('stateForm').className='ltbluegrey';
	}
	if (document.registration.state[document.registration.state.selectedIndex].value=='XX'&&document.registration.province.value=='') {
		document.getElementById('stateForm').className='ltredbarline';
		errorMsg+='Please enter your non U.S. or Canada province.\n';
	} else {
		document.getElementById('stateForm').className='ltbluegrey';
	}
	if (document.registration.state[document.registration.state.selectedIndex].value=='XX'&&document.registration.country.value=='') {
		document.getElementById('countryForm').className='ltredbarline';
		errorMsg+='Please enter your country.\n';
	} else {
		document.getElementById('countryForm').className='ltbluegrey';
	}
	if (document.registration.postal.value.length<5) {
		document.getElementById('postalForm').className='ltredbarline';
		errorMsg+='Please enter your valid zip/postal code.\n';
	} else {
		document.getElementById('postalForm').className='ltbluegrey';
	}
	if (!document.registration.sendMailID[0].checked&&!document.registration.sendMailID[1].checked) {
		document.getElementById('sendMailIDForm').className='ltredbarline';
		errorMsg+='Please tell us if we may send mail to you.\n';
	} else {
		document.getElementById('sendMailIDForm').className='ltbluegrey';
	}
	if (document.registration.phone.value!=''&&!document.registration.phoneTypeID[0].checked&&!document.registration.phoneTypeID[1].checked&&!document.registration.phoneTypeID[2].checked) {
		document.getElementById('phoneTypeIDForm').className='ltredbarline';
		errorMsg+='Please tell us the type of phone number.\n';
	} else {
		document.getElementById('phoneTypeIDForm').className='ltbluegrey';
	}
	if (document.registration.phone.value==''&&!document.registration.phoneCall[0].checked&&!document.registration.phoneCall[1].checked) {
		document.getElementById('phoneCallForm').className='ltredbarline';
		errorMsg+='Please tell us if we may call you.\n';
	} else {
		document.getElementById('phoneCallForm').className='ltbluegrey';
	}
	if (doIt&&document.registration.media[0].checked&&document.registration.parentName.value=='') {
		document.getElementById('parentNameForm').className='ltredbarline';
		errorMsg+='Please enter your parent\'s name.\n';
	} else {
		document.getElementById('parentNameForm').className='ltbluegrey';
	}
	if (document.registration.newClub) {
	if (document.registration.newClub[0].checked) {
		if (document.registration.clubName.value=='') {
			document.getElementById('clubNameForm').className='ltredbarline';
			errorMsg+='Please tell us the name of the club.\n';
		} else {
			document.getElementById('clubNameForm').className='ltbluegrey';
		}
		if (document.registration.advisorFirst.value!=''||document.registration.advisorLast.value!='') {
			titleChecked=0;
			for (i=0;i<titleNum;i++) {
				if (document.registration.advisorTitleIDs[i].checked) {
					titleChecked=1;
				}
			}
			if (!titleChecked) {
				document.getElementById('advisorTitleIDsForm').className='ltredbarline';
				errorMsg+='Please tell us the advisor/staff title.\n';
			} else {
				document.getElementById('advisorTitleIDsForm').className='ltbluegrey';
			}
		}
	}
	}
	if (errorMsg=='') {
		return true;
	} else {
		alert(errorMsg);
		return false;
	}
}

