<!--
function Dollar (val) {  // force to valid dollar amount
var str,pos,rnd=0;
  if (val < .995) rnd = 1;  // for old Netscape browsers
  str = escape (val*1.0 + 0.005001 + rnd);  // float, round, escape
  pos = str.indexOf (".");
  if (pos > 0) str = str.substring (rnd, pos + 3);
  return str;
}

function fnUpdatePrice (obj) {
  //subtotal it
  if (obj.tournament.value == "Error") {
      	obj.item_name.value = '';
      	obj.amount.value = '';
      	totalPrice = 0.00;
  } else {
    	obj.item_name.value = obj.tournament.value;
    	var strPrice = new String(obj.tournament.value);
    	strPrice = fnRight(strPrice, "($", true);
    	strPrice = fnLeft(strPrice, ")", true);
    	obj.amount.value = Dollar(strPrice);
  	totalPrice = Dollar(strPrice);
  }
  
  obj.amount.value = Dollar (totalPrice);
  if (obj.tot) obj.tot.value = "$" + Dollar (totalPrice);  //this is read only for totalling the selected cart
}

function fnUpdatePrice2 (obj) {
  //subtotal it
  if (obj.level.value == "Error") {
      	obj.item_name.value = '';
      	obj.amount.value = '';
      	totalPrice = 0.00;
  } else if (obj.level.value == "Premier Sponsor - $250") {
    	obj.item_name.value = obj.level.value;
    	obj.amount.value = '250.00';
  	totalPrice = 250.00;
  } else if (obj.level.value == "Event Sponsor - $150") {
      	obj.item_name.value = obj.level.value;
      	obj.amount.value = '150.00';
    	totalPrice = 150.00;
  } else if (obj.level.value == "Hole Sponsor - $100") {
      	obj.item_name.value = obj.level.value;
      	obj.amount.value = '100.00';
    	totalPrice = 100.00;
  }
  
  obj.amount.value = Dollar (totalPrice);
  if (obj.tot) obj.tot.value = "$" + Dollar (totalPrice);  //this is read only for totalling the selected cart
}

function ProcessForm (obj) { // process un-named selects
  var totalPrice;
  
  if (obj.tournament.value == "Error") {
  	window.alert ('Please specify the tournament you want.');
  	return false;
  }
  if (obj.teamname.value == "") {
    	window.alert ('Please specify a team name.');
    	obj.teamname.focus();
    	return false;
  }
  if (obj.p1name.value == "") {
    	window.alert ('Please specify player 1\'s name.');
    	obj.p1name.focus();
    	return false;
  }
  if (obj.p1address.value == "") {
      	window.alert ('Please specify player 1\'s address.');
      	obj.p1address.focus();
      	return false;
  }
  if (obj.p1zip.value == "") {
    	window.alert ('Please specify player 1\'s city, state, and zip code.');
    	obj.p1zip.focus();
    	return false;
  }
  if (obj.p1phone.value == "") {
    	window.alert ('Please specify player 1\'s phone.');
    	obj.p1phone.focus();
    	return false;
  }
  if (obj.p1email.value == "") {
    	window.alert ('Please specify player 1\'s email.');
    	obj.p1email.focus();
    	return false;
  }
  if (obj.p2name.value == "") {
    	window.alert ('Please specify player 2\'s name.');
    	obj.p2name.focus();
    	return false;
  }
  if (obj.p2address.value == "") {
      	window.alert ('Please specify player 2\'s address.');
      	obj.p2address.focus();
      	return false;
  }
  if (obj.p2zip.value == "") {
    	window.alert ('Please specify player 1\'s city, state, and zip code.');
    	obj.p2zip.focus();
    	return false;
  }
  if (obj.p2phone.value == "") {
    	window.alert ('Please specify player 2\'s phone.');
    	obj.p2phone.focus();
    	return false;
  }
  if (obj.p2email.value == "") {
    	window.alert ('Please specify player 2\'s email.');
    	obj.p2email.focus();
    	return false;
  }
  if (obj.howdidyouhear.value == "Error") {
    	window.alert ('Please specify how you heard of us.');
    	return false;
  }
  fnUpdatePrice(obj);
  var strLine1 = obj.p1name.value + "; " + obj.p1address.value + "; " + obj.p1zip.value + "; "+ obj.p1phone.value + "; " + obj.p1email.value + "; " + obj.p1highschools.value;
  var strLine2 = obj.p2name.value + "; " + obj.p2address.value + "; " + obj.p2zip.value + "; "+ obj.p2phone.value + "; " + obj.p2email.value + "; " + obj.p2highschools.value;
  strLine2 = strLine2 + "; How did you hear of us: " + obj.howdidyouhear.value;
  obj.on0.value = "Team name: " + obj.teamname.value + "; Player 1";
  obj.os0.value = strLine1;
  obj.on1.value = "Player 2";
  obj.os1.value = strLine2;
  window.alert("A new window will appear adding \nyour items to the PayPal shopping \ncart.  Do not be alarmed. \nThis is normal, secure and safe.");
  return true;
}

function ProcessForm2 (obj) { // process un-named selects
  var totalPrice;
  
  if (obj.level.value == "Error") {
  	window.alert ('Please specify the sponsorship level you want.');
  	return false;
  }
  if (obj.tournament.value == "Error") {
  	window.alert ('Please specify the tournament level you want.');
  	return false;
  }
  if (obj.compname.value == "") {
    	window.alert ('Please specify your company\'s name.');
    	obj.compname.focus();
    	return false;
  }
  if (obj.compcontact.value == "") {
    	window.alert ('Please specify your company\'s contact person.');
    	obj.compcontact.focus();
    	return false;
  }
  if (obj.address.value == "") {
      	window.alert ('Please specify your company\'s address.');
      	obj.address.focus();
      	return false;
  }
  if (obj.zip.value == "") {
    	window.alert ('Please specify your company\'s city, state, and zip code.');
    	obj.zip.focus();
    	return false;
  }
  if (obj.phone.value == "") {
    	window.alert ('Please specify your company\'s phone.');
    	obj.phone.focus();
    	return false;
  }
  if (obj.email.value == "") {
    	window.alert ('Please specify your company\'s email contact.');
    	obj.email.focus();
    	return false;
  }
  if (obj.howdidyouhear.value == "Error") {
    	window.alert ('Please specify how you heard of us.');
    	return false;
  }
  fnUpdatePrice2(obj);
  var strLine1 = obj.level.value + "; " + obj.tournament.value;
  var strLine2 = obj.compname.value + "; " + obj.compcontact.value + "; " + obj.address.value + "; " + obj.zip.value + "; " + obj.phone.value + "; " + obj.email.value;
  strLine2 = strLine2 + "; How did you hear of us: " + obj.howdidyouhear.value;
  obj.on0.value = "Sponsor Level";
  obj.os0.value = strLine1;
  obj.on1.value = "Contact Information";
  obj.os1.value = strLine2;
  window.alert("A new window will appear adding \nyour items to the PayPal shopping \ncart.  Do not be alarmed. \nThis is normal, secure and safe.");
  return true;
}

function fnRight(strToParse, strToFind, boolCase) {
	//By Cuong Vu
	//June 30, 2004
	//This will find parse the string to the right of strToFind.  If not found, returns a null.
	//Dec 20, 2004 - Fixed bug where strToFind was more than 1 character
	if (strToParse == null || strToFind == null)
		return;
	
	var str1 = "";
	var str2 = "";
	if (boolCase == true) {
		str1 = strToParse.toLowerCase();
		str2 = strToFind.toLowerCase();
	} else {
		str1 = strToParse;
		str2 = strToFind;
	}
	
	var intPos;
	intPos = strToParse.indexOf(strToFind)
	
	if (intPos == -1) {
		return;
	} else {
		return strToParse.slice(intPos + strToFind.length);	
	}
}

function fnLeft(strToParse, strToFind, boolCase) {
	//By Cuong Vu
	//July 1, 2004
	//This will find parse the string to the left of strToFind.  If not found, returns a null.
	if (strToParse == null || strToFind == null)
		return;
	
	var str1 = "";
	var str2 = "";
	if (boolCase == true) {
		str1 = strToParse.toLowerCase();
		str2 = strToFind.toLowerCase();
	} else {
		str1 = strToParse;
		str2 = strToFind;
	}
	
	var intPos;
	intPos = strToParse.indexOf(strToFind)
	
	if (intPos == -1) {
		return;
	} else {
		return strToParse.substr(0, intPos);	
	}
}

function fnAddQS(strURL, strQSName, strQSValue) {
	//Copyright Cincyco.com

	//if a query string already exists use ampersand, else question mark
	if (strURL == "") return;
	if (strQSName == "") return;
	var intPos = strURL.indexOf("?");
	if (intPos == -1) {
		return strURL + "?" + strQSName + "=" + escape(strQSValue);
	} else {
		return strURL + "&" + strQSName + "=" + escape(strQSValue);
	}
}

function fnEnableButton(formThis, strItemName) {
	//By Cuong Vu
	//January 9, 2007
	if (fnIsNull(strItemName)) return false;
	
	//Catch errors when the form hasn't been loaded yet.
	try {
		var intLength = formThis.elements.length;
	} catch(er) {
		return false;
	}
	
	for (i=0; i < intLength; i++) {
		if ((formThis.elements[i].type == "button") && (formThis.elements[i].name == strItemName)) {
			formThis.elements[i].disabled = false;
			return true;
		}
	}
	return false;
}

function fnDisableAnyButton(formThis, strPartialMatchFind) {
	//By Cuong Vu
	//January 9, 2007
	if (fnIsNull(strPartialMatchFind)) return false;
	
	//Catch errors when the form hasn't been loaded yet.
	try {
		var intLength = formThis.elements.length;
	} catch(er) {
		return false;
	}
	
	for (i=0; i < intLength; i++) {
		if ((formThis.elements[i].type == "button") && (formThis.elements[i].name.indexOf(strPartialMatchFind) > -1)) {
			formThis.elements[i].disabled = true;
		}
	}
	return true;
}

function fnIsNull(strToCheck) {
	//Cuong Vu
	//April 7, 2005
	//Do not compare strToCheck == "", apparently if you pass the number zero (not the string) it breaks.
	if (strToCheck == null) return true;
	var strTest = new String(strToCheck);
	if (strTest.length == 0) return true;
	return false;
}

function fnGetRadioValue(formToProcess, strRadioName) {
	//Cuong Vu
	//January 23, 2005
	for (i=0; i < formToProcess.elements.length; i++) {
		if (formToProcess.elements[i].type == "radio") {
			if (formToProcess.elements[i].name == strRadioName) {
				if (formToProcess.elements[i].checked) {
					return formToProcess.elements[i].value;
				}
			}
		}
	}
	return "";
}

function fnGetItemValue(formThis, strItemName) {
	//By Cuong Vu
	//January 28, 2005
	if (strItemName == "") { return ""; }
	
	//Catch errors when the form hasn't been loaded yet.
	try {
		var intLength = formThis.elements.length;
	} catch(er) {
		return "";
	}
	
	for (i=0; i < intLength; i++) {
		if (formThis.elements[i].name == strItemName) {
			return formThis.elements[i].value;
		}
	}
	return "";
}

function fnTrim(strInput) {
	// Removes leading and trailing spaces from the passed string. Also
	// removes consecutive spaces and replaces it with one space.
	if (strInput == "") { return ""; }
	var strReturn = strInput;
	var ch = strReturn.substring(0, 1);
	while (ch == " ") { // Check for spaces at the beginning of the string
		strReturn = strReturn.substring(1, strReturn.length);
		ch = strReturn.substring(0, 1);
	}
	ch = strReturn.substring(strReturn.length-1, strReturn.length);
	while (ch == " ") { // Check for spaces at the end of the string
		strReturn = strReturn.substring(0, strReturn.length-1);
		ch = strReturn.substring(strReturn.length-1, strReturn.length);
	}
	while (strReturn.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
		strReturn = strReturn.substring(0, strReturn.indexOf("  ")) + strReturn.substring(strReturn.indexOf("  ")+1, strReturn.length); // Again, there are two spaces in each of the strings
	}
	return strReturn; // Return the trimmed string back to the user
} // Ends the "fnTrim" function

function fnIsNumeric(strText) {
	//http://www.codetoad.com/javascript/isnumeric.asp
	//Updated by Cuong Vu
	//January 28, 2005
	//I updated this function to look for negative and decimal numbers as well.
	//This function also has checks for one negative and one decimal.
	//Should probably rewrite using regular expressions.
	var strValidChars = new String("-0123456789.");
	var strTemp = new String(strText);
	var strChar = "";
	var boolFoundNeg = 0;
	var boolFoundDot = 0;

	for (i = 0; i < strTemp.length; i++) { 
		strChar = new String(strTemp.charAt(i));
		if (strValidChars.indexOf(strChar) == -1) {
			return false;
		}
		if (strChar == "-") {
			boolFoundNeg = 1;
			if (i > 0) {
				return false; //negative can only exist at pos 0
			}
		}
		if (strChar == ".") {
			if (boolFoundDot == 1) {
				return false; //can only have one dot
			}
			boolFoundDot = 1;
		}		
	}
	return true;
}

function fnIsUnsignedNumeric(strText) {
	//http://www.codetoad.com/javascript/isnumeric.asp
	//Updated by Cuong Vu
	//April 13, 2007
	//I updated this function to look for decimal numbers as well.
	//This function also has checks for one decimal.
	//Should probably rewrite using regular expressions.
	var strValidChars = new String("0123456789.");
	var strTemp = new String(strText);
	var strChar = "";
	var boolFoundDot = 0;

	for (i = 0; i < strTemp.length; i++) { 
		strChar = new String(strTemp.charAt(i));
		if (strValidChars.indexOf(strChar) == -1) {
			return false;
		}
		if (strChar == ".") {
			if (boolFoundDot == 1) {
				return false; //can only have one dot
			}
			boolFoundDot = 1;
		}		
	}
	return true;
}

function fnIsInteger(strText) {
	//http://www.codetoad.com/javascript/isnumeric.asp
	//Updated by Cuong Vu
	//April 13, 2007
	//I updated this function to look for negative numbers as well.
	//This function also has checks for one negative.
	//Should probably rewrite using regular expressions.
	var strValidChars = new String("-0123456789");
	var strTemp = new String(strText);
	var strChar = "";
	var boolFoundNeg = 0;

	for (i = 0; i < strTemp.length; i++) { 
		strChar = new String(strTemp.charAt(i));
		if (strValidChars.indexOf(strChar) == -1) {
			return false;
		}
		if (strChar == "-") {
			boolFoundNeg = 1;
			if (i > 0) {
				return false; //negative can only exist at pos 0
			}
		}		
	}
	return true;
}

function fnIsUnsignedInteger(strText) {
	//http://www.codetoad.com/javascript/isnumeric.asp
	//Updated by Cuong Vu
	//April 13, 2007
	//I updated this function to look for negative numbers as well.
	//Should probably rewrite using regular expressions.
	var strValidChars = new String("0123456789");
	var strTemp = new String(strText);
	var strChar = "";

	for (i = 0; i < strTemp.length; i++) { 
		strChar = new String(strTemp.charAt(i));
		if (strValidChars.indexOf(strChar) == -1) {
			return false;
		}		
	}
	return true;
}

function fnTrimAllTextBoxes(formThis) {
	//By Cuong Vu
	//February 21, 2005
	
	//Catch errors when the form hasn't been loaded yet.
	try {
		var intLength = formThis.elements.length;
	} catch(er) {
		return -1;
	}
	
	var intCounter = 0;
	var filter  = /\S+/;
	
	//loop thru all elements and find if this element is checked
	for (i = 0; i < intLength; i++) {
		if (formThis.elements[i].type == "text") {
			if (filter.test(formThis.elements[i].value)) {
				if (formThis.elements[i].value != fnTrim(formThis.elements[i].value)) {
					formThis.elements[i].value = fnTrim(formThis.elements[i].value);
					intCounter++;
				}
			} else {
				//All whitespace only should be null
				formThis.elements[i].value = "";
				intCounter++;
			}
		}
	}
	return intCounter;
}

function fnIsValidEmailAddress(strToProcess) {
	//http://www.4guysfromrolla.com/webtech/052899-1.shtml
	var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
	var regex = new RegExp(emailReg);
	return regex.test(strToProcess);
}

function fnIsValidDate(intYear, intMonth, intDay) {
	//By Cuong Vu
	//March 28, 2005
	//Javascript is very forgiving and will return an adjusted date even if not valid.  For example, Feb 31, 2006 works.
	//This function will catch that it is not valid.
	//intMonth is 0 to 11 instead of 1-12.  January is month 0.
	var dateToCheck;
	try {
		dateToCheck = new Date(intYear, intMonth, intDay);
	} catch(er) {
		return false;
	}
	 return ((intDay == dateToCheck.getDate()) && (intMonth == dateToCheck.getMonth()) && (intYear == dateToCheck.getFullYear()));
}
//-->

