// start: mouseover script and image preloader
	
function msover(img,ref){
	document.images[img].src = ref;
}

function msout(img,ref){
	document.images[img].src = ref;
}

String.prototype.trim = function(){
a = this.replace(/^\s+/, '');
return a.replace(/\s+$/, '');
};

String.prototype.reverse=function(str){
	var newStr="";
	for (i=0;i<=str.length;i++){
		newStr = str.charAt(i) + newStr;
	}
	return newStr;
}

String.prototype.replaceAll=function(haystack, needle, replacement){
	while(haystack.indexOf(needle)!=-1){
		haystack=haystack.replace(needle, " ");
	}
	return haystack;
}	

String.prototype.toProperCase = function(){
	return this.toLowerCase().replace(/^(.)|\s(.)/g, function($1) { return $1.toUpperCase(); });
};

document.getElementsByClassName = function(clsName,/*boolean*/names){
	if(typeof(clsName)=="string"){
		var retVal = new Array();
		var elements = document.getElementsByTagName("*");
		for(i = 0;i < elements.length;i++){
			if(names){
				if(elements[i].className.indexOf(" ") >= 0){
					var classes = elements[i].className.split(" ");
					for(var j = 0;j < classes.length;j++){
						if(classes[j] == clsName){
							retVal.push(elements[i].id);
						}
					}
				}
				else if(elements[i].className == clsName){
					retVal.push(elements[i].id);
				}
			}
			else{
				if(elements[i].className.indexOf(" ") >= 0){
					var classes = elements[i].className.split(" ");
					for(var j = 0;j < classes.length;j++){
						if(classes[j] == clsName){
							retVal.push(elements[i]);
						}
					}
				}
				else if(elements[i].className == clsName){
					retVal.push(elements[i]);
				}	
			}
		}
		return retVal;
	}
	else{
		throw new Error("document.getElementsByClassName() must be passed a string representation of a class name");	
	}
};

document.getElementsByAttribute=function(attribute,/*boolean*/names){
	if(typeof(attribute)=="string"){
		var retVal = new Array();
		var elements = document.getElementsByTagName("*");
		for(i = 0;i < elements.length;i++){
			if(names){
				if(elements[i].getAttribute(attribute)){
					retVal.push(elements[i].id);
				}
			}
			else{
				if(elements[i].getAttribute(attribute)){
					retVal.push(elements[i])
				}
			}
		}
		return retVal;
	}
	else{
		throw new Error("document.getElementsByAttribute() must be passed a string representation of an attribute name");	
	}
};


Array.prototype.inArray = function (value,caseSensitive){
	//**this** represents the array the function is called on.  does not need to be passed because this is prototype function.
	for (i=0; i < this.length; i++) {
		if(!caseSensitive){
			if (this[i].toLowerCase() == value.toLowerCase()) {
				return true;
			}
		}
		else{
			if (this[i] == value) {
				return true;
			}
		}
	}
	return false;
};

/*Pass enforceNumeric() the text field to verify, the event, and an optional array of additional allowable unicode value entries as strings.
This function requires the Array prototype inArray() 
Common exception codes:
36="$"
45="-"
40="("
41=")"
69="E"
84="T"
88="X"
101="e"
116="t"
120="x"
Example call: <input type="text" id="myField" name="myField" onkeypress="return enforceNumeric(this,event,new Array('120','36','88','45'));"/>
*/
function enforceNumeric(/*text field*/ field, /*event*/ e, /*optional array of allowable uncode keycodes*/ allowed){
	char=e.charCode ? e.charCode : e.keyCode;
	if (char!=8 && char!=46){ //8=backspace 46=period
		if (char<48||char>57){
			if(allowed && allowed.length>0){
				for(i=0; i<allowed.length; i++){
					if(allowed.inArray(char)){
						return true;
					}
					else{
						return false;	
					}
				}
			}
			else{
				return false;	
			}
		}
		else{
			return true;
		}
	}
	else if(char==46){
		if(field.value.indexOf(".")==-1){
			return true;
		}
		else{
			return false;	
		}
	}
}

function enforceAlphaNumeric(field,e){
	char=e.charCode? e.charCode : e.keyCode;
	if((char>=48 && char<=57) || (char>=65 && char<=90) || (char>=97 && char<=122)){
		return true;
	}
	else{
		return false;	
	}
}


/* old site functions - some may no longer be used */
/*
// start: get generic browser type
NN = (navigator.appName == "Netscape" && navigator.appVersion.charAt(0) != "5")?true:false;
IE = (navigator.appName != "Netscape")?true:false;


// start: select the appropriate stylesheet
if(!path) var path = ""; // if the path variable was set before the call to this (.js) file
if(NN){
	document.write("<LINK REL=stylesheet HREF=\""+path+"inc/nn4.css\" TYPE=\"text/css\">");
}
else{
	document.write("<LINK REL=stylesheet HREF=\""+path+"inc/default.css\" TYPE=\"text/css\">");
}
*/
// start: mouseover script and image preloader
function msover(img,ref){
	document.images[img].src = ref;
}
function msout(img,ref){
	document.images[img].src = ref;
}
xx = new Image();
xx.src="images/question_on.gif";
function sportConfirm(){
	var msg = "Please take a minute to review your statistics and make sure that they are accurate. In the event that you would need to change your statistics, you will have to completely resend them to Vanguard Athletics and await approval. Please understand this is necessary to maintain the integrity of the website.\n\n";
	msg += "Click \"OK\" to Submit your stats or \"CANCEL\" to review.";
	if(checkCoachAdd()){
		if(confirm(msg)){
			return true;
		}
		else{
			return false;
		}
	}
	else{
		return false;
	}
}

var home = new Image();
home.src = "images/menu_items/home_over.gif";
var news = new Image();
news.src = "images/menu_items/news_over.gif";
var faqs = new Image();
faqs.src = "images/menu_items/faqs_over.gif";
var samples = new Image();
samples.src = "images/menu_items/samples_over.gif";
var athlete_add = new Image();
athlete_add.src = "images/menu_items/athlete_add_over.gif";
var recruiters = new Image();
recruiters.src = "images/menu_items/recruiters_over.gif";
var contact_us = new Image();
contact_us.src = "images/menu_items/contact_us_over.gif";
	
function checkForm(FORM){
	var temp = "You must complete the following fields:\n\n";
	var complete = true;
	if(FORM.email.value == ""){
		FORM.email.value = "";
		temp += "\tEmail\n";
		complete = false;
	}
	if(FORM.password.value == ""){
		temp += "\tPassword\n";
		complete = false;
	}
	if(!complete){
		alert(temp);
	}
	return complete;
}

function checkAdd(){
	var temp = "You must complete the following fields:\n\n";
	var complete = true;
	if((document.addProd.firstname.value == "") || (document.addProd.lastname.value == "")){
		temp += "\tName\n";
		complete = false;
	}
	if(document.addProd.email.value == "" || document.addProd.email.value.indexOf("@") == -1){
		document.addProd.email.value = "";
		temp += "\tEmail\n";
		complete = false;
	}
	if(document.addProd.password.value == ""){
		temp += "\tPassword\n";
		complete = false;
	}
	if(document.addProd.security_answer.value == ""){
		temp += "\tAnswer to Security Question\n";
		complete = false;
	}
	if(document.addProd.day_of_birth.value == "00" || document.addProd.month_of_birth.value == "00" || document.addProd.year_of_birth.value == "0000"){
		temp += "\tDate of Birth\n";
		complete = false;
	}
	if(document.addProd.address1.value == ""){
		temp += "\tAddress\n";
		complete = false;
	}
	if(document.addProd.city.value == ""){
		temp += "\tCity\n";
		complete = false;
	}
	if(document.addProd.state[document.addProd.state.selectedIndex].value == ""){
		temp += "\tState\n";
		complete = false;
	}
	if(document.addProd.zip.value == ""){
		temp += "\tZip\n";
		complete = false;
	}
	if(document.addProd.phone.value == ""){
		temp += "\tPhone\n";
		complete = false;
	}
	if(document.addProd.schoolname.value == ""){
		temp += "\tSchool Name\n";
		complete = false;
	}
	if(document.addProd.password.value != document.addProd.password2.value){
		temp += "\t** Your Passwords do not match **\n";
		complete = false;
	}
	if(document.addProd.sport[document.addProd.sport.selectedIndex].value == ""){
		temp += "\tSport\n";
		complete = false;
	}
	if(!complete){
		alert(temp);
	}
	return complete;
}

function checkEdit(){
	var temp = "You must complete the following fields:\n\n";
	var complete = true;
	if((document.addProd.firstname.value == "") || (document.addProd.lastname.value == "")){
		temp += "\tName\n";
		complete = false;
	}
	if(document.addProd.email.value == "" || document.addProd.email.value.indexOf("@") == -1){
		document.addProd.email.value = "";
		temp += "\tEmail\n";
		complete = false;
	}
	if(document.addProd.address1.value == ""){
		temp += "\tAddress\n";
		complete = false;
	}
	if(document.addProd.city.value == ""){
		temp += "\tCity\n";
		complete = false;
	}
	if(document.addProd.zip.value == ""){
		temp += "\tZip\n";
		complete = false;
	}
	if(document.addProd.phone.value == ""){
		temp += "\tPhone\n";
		complete = false;
	}
	if(!complete){
		alert(temp);
	}
	return complete;
}

function checkCoachAdd(){
	var temp = "You must complete the following fields:\n\n";
	var complete = true;
	if((document.coachAdd.coach_firstname.value == "") || (document.coachAdd.coach_lastname.value == "")){
		temp += "\tName\n";
		complete = false;
	}
	if(document.coachAdd.coach_address1.value == ""){
		temp += "\tAddress\n";
		complete = false;
	}
	if(document.coachAdd.coach_city.value == ""){
		temp += "\tCity\n";
		complete = false;
	}
	if(document.coachAdd.coach_zip.value == ""){
		temp += "\tZip\n";
		complete = false;
	}
	if(document.coachAdd.coach_phone.value == ""){
		temp += "\tPhone\n";
		complete = false;
	}
	if(!complete){
		alert(temp);
	}
	return complete;
}

function formHandler(form){
	var URL = document.form.site.options[document.form.site.selectedIndex].value;
	if(URL != ""){
		window.location.href = URL;
	}
}

function formHandler2(form){
	var URL = document.form.site.options[document.form.site.selectedIndex].value;
	var URLstring = "recruiter_sport.php4?sport=" + URL;
	window.location.href = URLstring;
}

function checkSAM(){
	var temp = "You must complete the following fields:\n\n";
	var complete = true;
	if(document.sam.Name.value == ""){
		temp += "\tName\n";
		complete = false;
	}
	if(document.sam.Email.value == "" || document.sam.Email.value.indexOf("@") == -1){
		document.sam.Email.value = "";
		temp += "\tE-Mail\n";
		complete = false;
	}
	if(document.sam.Address.value == ""){
		temp += "\tAddress\n";
		complete = false;
	}
	if(document.sam.Class.value == ""){
		temp += "\tClass\n";
		complete = false;
	}
	if(document.sam.CoachName.value == ""){
		temp += "\tCoach's Name\n";
		complete = false;
	}
	if(document.sam.CoachPhoneNumber.value == ""){
		temp += "\tCoach's Phone Number\n";
		complete = false;
	}
	if(document.sam.Sport.value == ""){
		temp += "\tSport\n";
		complete = false;
	}
	if(document.sam.References.value == ""){
		temp += "\tReferences\n";
		complete = false;
	}
	if(document.sam.WhyIShouldBeSAM.value == ""){
		temp += "\tWhy I should be SAM\n";
		complete = false;
	}
	if(!complete){
		alert(temp);
	}
	return complete;
}

// start: form validator script
function checkThis(form){
	/*
	Use a hidden input on the submitting form called 
		required to send required field names.
	Just separate the field names with commas like this: 
		<input type="hidden" name="required" value="emailAddress,firstName,lastName">
	If you need all fields required then change the value="all"
	If you don't need the form to be validated, then don't call the script or 
		just omit the hidden input or leave the value empty.
	*/
	required = (form.required && form.required.value)?form.required.value:false;
	requiredFields = required.split(',');
	if(required && required != "all"){
		for(a=0;a<requiredFields.length;a++){
			currentName = eval("form."+requiredFields[a]+".name");
			currentValue = eval("form."+requiredFields[a]+".value");
			if(!currentValue && currentName != "emailAddress" && currentName != "email"){
				alert("You must supply information for all of the required fields.");
				eval("form."+requiredFields[a]+".value = ''");
				eval("form."+requiredFields[a]+".focus()");
				return false;
			}
			else if(currentName == "emailAddress" && (currentValue.indexOf("@") == -1 || currentValue.indexOf("\.") == -1 || currentValue.length < 5 || currentValue == "asdf@asdf.com") || currentName == "email" && (currentValue.indexOf("@") == -1 || currentValue.indexOf("\.") == -1 || currentValue.length < 5 || currentValue == "asdf@asdf.com")){
				alert("You must supply a valid email address.");
				eval("form."+requiredFields[a]+".value = ''");
				eval("form."+requiredFields[a]+".focus()");
				return false;
			}
		}
	}
	else if(required && required == "all"){
		for(i=0;i<form.elements.length;i++){
			if (!form.elements[i].value && form.elements[i].name != "emailAddress" && form.elements[i].name != "email"){
				alert("You must supply information for all of the required fields.");
				form.elements[i].focus();
				return false;
			}
			else if(form.elements[i].name == "emailAddress" && (form.elements[i].value.indexOf("@") == -1 || form.elements[i].value.indexOf("\.") == -1 || form.elements[i].value.length < 5 || form.elements[i].value == "asdf@asdf.com")){
				alert("You must supply a valid email address.");
				form.elements[i].value = "";
				form.elements[i].focus();
				return false;
			}
		}
	}
	else{
		return true;
	}
}
// end: form validator script

function checkState(){
	if(document.addProd.country.value != ""){
		document.addProd.state["50"].selected = true;
	}
}

function photo(){
	window.open("photo.php","newWin","width=250,height=300,scrollbars=yes");
}

function url(){
	window.open("url.php","newWin","width=250,height=300,scrollbars=yes");
}

function checkSport(sport_id,division){
	if(sport_id[sport_id.selectedIndex].value == "" || division[division.selectedIndex].value == ""){
		alert("You must select a sport and a division in order to register");
		return false;
	}
}

colors = new Array("FF0033", "FF3366", "CC0033", "FF6699", "CC3366", "990033", "FF0066", "FF3399", "FF99CC", "CC0066", "CC6699", "993366", "660033", "FF0099", "FF66CC", "CC3399", "990066", "FF33CC", "CC0099", "FF00CC", "FF00FF", "FF33FF", "FF66FF", "FF99FF", "FFCCFF", "CC00CC", "CC33CC", "CC66CC", "CC99CC", "990099", "993399", "996699", "660066", "663366", "330033", "CC00FF", "CC33FF", "9900CC", "CC66FF", "9933CC", "660099", "9900FF", "9933FF", "CC99FF", "6600CC", "9966CC", "663399", "330066", "6600FF", "9966FF", "6633CC", "330099", "6633FF", "3300CC", "3300FF", "0000FF", "3333FF", "6666FF", "9999FF", "CCCCFF", "0000CC", "3333CC", "6666CC", "9999CC", "000099", "333399", "666699", "000066", "333366", "000033", "0033FF", "3366FF", "0033CC", "6699FF", "3366CC", "003399", "0066FF", "3399FF", "99CCFF", "0066CC", "6699CC", "336699", "003366", "0099FF", "66CCFF", "3399CC", "006699", "33CCFF", "0099CC", "00CCFF", "00FFFF", "33FFFF", "66FFFF", "99FFFF", "CCFFFF", "00CCCC", "33CCCC", "66CCCC", "99CCCC", "009999", "339999", "669999", "006666", "336666", "003333", "00FFCC", "33FFCC", "00CC99", "66FFCC", "33CC99", "009966", "00FF99", "33FF99", "99FFCC", "00CC66", "66CC99", "339966", "006633", "00FF66", "66FF99", "33CC66", "009933", "33FF66", "00FF33", "00FF00", "33FF33", "66FF66", "99FF99", "CCFFCC", "00CC00", "33CC33", "66CC66", "99CC99", "009900", "339933", "669966", "006600", "336633", "003300", "33FF00", "66FF33", "33CC00", "99FF66", "66CC33", "339900", "66FF00", "99FF33", "CCFF99", "66CC00", "99CC66", "669933", "336600", "99FF00", "CCFF66", "99CC33", "669900", "CCFF33", "99CC00", "CCFF00", "FFFF00", "FFFF33", "FFFF66", "FFFF99", "FFFFCC", "CCCC00", "CCCC33", "CCCC66", "CCCC99", "999900", "999933", "999966", "666600", "666633", "333300", "FFCC00", "FFCC33", "CC9900", "FFCC66", "CC9933", "996600", "FF9900", "FF9933", "FFCC99", "CC6600", "CC9966", "996633", "663300", "FF6600", "FF9966", "CC6633", "993300", "FF6633", "CC3300", "FF3300", "FF0000", "FF3333", "FF6666", "FF9999", "FFCCCC", "FFFFFF", "CC0000", "CC3333", "CC6666"	, "CC9999", "CCCCCC", "990000", "993333", "996666", "999999", "660000", "663333", "666666", "330000", "333333", "000000")
counter = 0;

function printSwatch(fieldName, previewNum){
	swatchcontent = "";

	for(blip=0; blip<215; blip++){
		counter++
		if(colors[blip]){
			swatchcontent += '<td bgcolor="' + colors[blip] + '">' + '<a href="javascript:setcolor(' + "'" + colors[blip] + "', '" + fieldName + "', '" + previewNum + "'" + ');">' + '<img border="0" src="../images/pixel.gif" width="6" height="6"></a></td>'
		}
		if(counter == 27){
			counter = 0;
			swatchcontent += '</tr><tr>';
		}
	}
	counter = 0;
	document.write(swatchcontent);
}
	
function setcolor(colorHex, fieldName, previewNum){
	document.addProd[fieldName].value = colorHex;
	var thestyle= eval ('document.all.'+previewNum+'.style');
	thestyle.backgroundColor = colorHex;
}

function colorFromPalette(sPassedColorOne,sPassedColorTwo,sPassedColorThree,form){ // select colors with pre-made palettes
	modform.colorOneChoice.value = sPassedColorOne;
	modform.colorTwoChoice.value = sPassedColorThree;
	modform.colorThreeChoice.value = sPassedColorTwo;
	document.all.previewColorOne.style.backgroundColor = "#"+sPassedColorOne;
	document.all.previewColorTwo.style.backgroundColor = "#"+sPassedColorThree;
	document.all.previewColorThree.style.backgroundColor = "#"+sPassedColorTwo;
}
function ShowHideContent(diveffect){
	if(document.all){
		if(document.all[diveffect].style.display == 'none'){
			document.all[diveffect].style.display = 'block';
		}
		else{
			document.all[diveffect].style.display = 'none';
		}
	}
	else{
		if(document.getElementById(diveffect).style.display == 'none'){
			document.getElementById(diveffect).style.display = 'block';
		}
		else{
			document.getElementById(diveffect).style.display = 'none';
		}
	}
}
function ShowContent(diveffect){
	/*
	if(document.all){
		if(document.all[diveffect].style.display == 'none'){
			document.all[diveffect].style.display = 'block';
		}
	}
	else{
	*/
		if(document.getElementById(diveffect).style.display == 'none'){
			document.getElementById(diveffect).style.display = 'block';
		}
	/*
	}
	*/
}
function HideContent(diveffect){
	/*
	if(document.all){
		document.all[diveffect].style.display = 'none';
	}
	else{
	*/
		document.getElementById(diveffect).style.display = 'none';
	/*
	}
	*/
}
function showSample(show){
	if(show===true){
		document.getElementById('athletes').style.display="inline";
		document.getElementById('athletes').onclick=showSample;
	}
	else{
		document.getElementById('athletes').style.display="none";	
	}
}

function grayOut(vis, Opacity,Bgcolor,Zindex) {
	var zindex = Zindex || 10;
	var opacity = Opacity || 70;
	var opaque = (opacity/100);
	var bgcolor = Bgcolor || '#E5E5E5';
	var dark=document.getElementById('darkenScreenObject');
	if (!dark) {
		// The dark layer doesn't exist, it's never been created.  So we'll
		// create it here and apply some basic styles.
		// If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
		var tbody = document.getElementsByTagName("body")[0];
		var tnode = document.createElement('div');           // Create the layer.
		tnode.style.position='absolute';                 // Position absolutely
		tnode.style.top='0px';                           // In the top
		tnode.style.left='0px';                          // Left corner of the page
		tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
		tnode.style.display='none';                      // Start out Hidden
		tnode.id='darkenScreenObject';                   // Name it so we can find it later
		tbody.appendChild(tnode);                            // Add it to the web page
		dark=document.getElementById('darkenScreenObject');  // Get the object.
	}
	if (vis){
		// Calculate the page width and height 
		if( document.body && (document.body.scrollWidth || document.body.scrollHeight )){
			var pageWidth = document.body.scrollWidth+'px';
			var pageHeight = document.body.scrollHeight+'px';
		}
		else if( document.body.offsetWidth ){
			var pageWidth = document.body.offsetWidth+'px';
			var pageHeight = document.body.offsetHeight+'px';
		}
		else{
			var pageWidth='100%';
			var pageHeight='100%';
		}   
		//set the shader to cover the entire page and make it visible.
		dark.style.opacity=opaque;                      
		dark.style.MozOpacity=opaque;                   
		dark.style.filter='alpha(opacity='+opacity+')'; 
		dark.style.zIndex=zindex;        
		dark.style.backgroundColor=bgcolor;  
		dark.style.width= pageWidth;
		dark.style.height= pageHeight;
		dark.style.display='block';                          
	}
	else{
		dark.style.display='none';
	}
}