var xmlHttp;
var ns=(document.layers);
var ie=(document.all);
var ns6=(document.getElementById&&!document.all);

function xstooltip_findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
   	}
   }
   else if (obj.x) {
       curleft += obj.x;
	}
   return curleft;
}
function xstooltip_findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += (obj.offsetTop - 5)
			obj = obj.offsetParent;
		}
	}
	else if (obj.y) {
		curtop += obj.y;
	}
	return curtop;
}

function xstooltip_show(tooltipId, parentId, posX, posY) {
	it = document.getElementById(tooltipId);
	if ((it.style.top == '' || it.style.top == 0) && (it.style.left == '' || it.style.left == 0)) {
		// need to fixate default size (MSIE problem)
		it.style.width = it.offsetWidth + 'px';
		it.style.height = it.offsetHeight + 'px';
        
		img = document.getElementById(parentId); 
    
		// if tooltip is too wide, shift left to be within parent 
		if (posX + it.offsetWidth > img.offsetWidth) posX = img.offsetWidth - it.offsetWidth;
		if (posX < 0 ) posX = 0; 

		x = xstooltip_findPosX(img) + posX;
		y = xstooltip_findPosY(img) + posY;

		it.style.top = y + 'px';
		it.style.left = x + 'px';
	}
    
	it.style.visibility = 'visible'; 
}

function xstooltip_hide(id) {
	it = document.getElementById(id); 
	it.style.visibility = 'hidden'; 
}

function sendQuery(url,id) {
   xmlHttp = GetXmlHttpObject();
   if (xmlHttp == null) {
      alert ("Browser does not support HTTP Request");
      return;
   }

   xmlHttp.onreadystatechange = function() {
      if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
         document.getElementById(id).innerHTML=xmlHttp.responseText;
      }
   }
   xmlHttp.open("POST",url,true);
   xmlHttp.send(null);
}

function GetXmlHttpObject() {
   var xmlHttp=null;
   try {
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
   }
   catch (e) {
      // Internet Explorer
      try {
         xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch (e) {
         xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
   }
   return xmlHttp;
}

function editPoolNotice() {
   document.getElementById('buttonEdit').style.display = 'none';
   document.getElementById('divNotice').style.display = 'none';
   document.getElementById('formNotice').style.display = 'block';
}

function gotocluster(s) {
   var d = s.options[s.selectedIndex].value;
   window.location.href = d;
}

function checkContactForm() {
   if (document.getElementById('send_message').Message.value == "") {
      alert('Please enter a Message in the space provided.');
      document.getElementById('send_message').Message.focus();
      return false;
   }
   else {
      return true;
   }
}

function checkJoinForm() {
   if (document.getElementById('join_pool').Pool.value == "") {
      alert('Please enter a Pool ID.');
      document.getElementById('join_pool').Pool.focus();
      return false;
   }
   else {
      return true;
   }
}

function checkPasswordForm() {
   if (document.getElementById('reset_password').Email.value == "") {
      alert('Please enter an E-mail Address.');
      document.getElementById('reset_password').Email.focus();
      return false;
   }
   else {
      return true;
   }
}

function validateInteger(strValue) {
  var objRegExp  = /(^\d\d*$)/;
  return objRegExp.test(strValue);
}

function confirmCancel() {
   var ret = confirm('Are you sure you want to cancel?');
   if (ret == true) {
      return true;
   }
   else {
      return false;
   }
}

function confirmPickDelete() {
   var ret = confirm('Are you sure you want to delete all picks in this Pool?');
   if (ret == true) {
      var ret2 = confirm('YOU WILL NOT BE ABLE TO UNDO THIS!\n\nAre you really sure you want to delete all picks in this Pool?');
      if (ret2 == true) {
         var ret3 = confirm('FINAL WARNING - YOU WILL NOT BE ABLE TO UNDO THIS!\n\nAre you really sure you want to delete all picks in this Pool?');
         if (ret3 == true) {
            return true;
         }
         else {
            return false;
         }
      }
      else {
         return false;
      }
   }
   else {
      return false;
   }
}

function confirmPoolDelete() {
   var ret = confirm('Are you sure you want to delete this Pool?');
   if (ret == true) {
      var ret2 = confirm('YOU WILL NOT BE ABLE TO UNDO THIS!\n\nAre you really sure you want to delete this Pool?');
      if (ret2 == true) {
         var ret3 = confirm('FINAL WARNING - YOU WILL NOT BE ABLE TO UNDO THIS!\n\nAre you really sure you want to delete this Pool?');
         if (ret3 == true) {
            return true;
         }
         else {
            return false;
         }
      }
      else {
         return false;
      }
   }
   else {
      return false;
   }
}

function setPctTotal(prizeType) {
	var totalPct = 0;
	var winnersBox = eval("document.getElementById('create_step3')." + prizeType + "_prizes");
	for (var p = 1; p <= winnersBox.value; p++) { 
		var pctBox = eval("document.getElementById('create_step3')." + prizeType + "_num_" + p + "_pct");
		totalPct+=parseInt(pctBox.value);
	}
	var totalPctBox = eval("document.getElementById('create_step3')." + prizeType + "_pct_total");
	totalPctBox.value = totalPct + "%";
	var clr = "red";
	if (totalPct == 100) clr = "black";
	totalPctBox.style.color = clr;
	setPrizeTable();
}

function setFundAllocation(prizeType) {
	var w_offset = ((typeof document.getElementById('create_step3').Weekly_prizes != "undefined") && (document.getElementById('create_step3').Weekly_prizes[0].value == 0)) ? 1 : 0;
	var f_offset = (document.getElementById('create_step3').Final_prizes[0].value == 0) ? 1 : 0;
	if (prizeType == 'final') {
		//document.getElementById('create_step3').Final_prize_pct.selectedIndex = document.getElementById('create_step3').Final_prize_pct.length - (document.getElementById('create_step3').Weekly_prize_pct.selectedIndex + 1 + w_offset);
	}
	else {
		//document.getElementById('create_step3').Weekly_prize_pct.selectedIndex = document.getElementById('create_step3').Weekly_prize_pct.length - (document.getElementById('create_step3').Final_prize_pct.selectedIndex + 1 + f_offset);
	}
	if (typeof document.getElementById('create_step3').Weekly_prizes != "undefined") {
		var tot_pct = parseInt(document.getElementById('create_step3').Weekly_prize_pct[document.getElementById('create_step3').Weekly_prize_pct.selectedIndex].value) + parseInt(document.getElementById('create_step3').Final_prize_pct[document.getElementById('create_step3').Final_prize_pct.selectedIndex].value);
	} else {
		var tot_pct = parseInt(document.getElementById('create_step3').Final_prize_pct[document.getElementById('create_step3').Final_prize_pct.selectedIndex].value);
	}
	if (tot_pct != 100) {
		if (typeof document.getElementById('create_step3').Weekly_prizes != "undefined") {
			document.getElementById('create_step3').Weekly_prize_pct.style.color = "red";
		}
		document.getElementById('create_step3').Final_prize_pct.style.color = "red";
	} else {
		if (typeof document.getElementById('create_step3').Weekly_prizes != "undefined") {
			document.getElementById('create_step3').Weekly_prize_pct.style.color = "black";
		}
		document.getElementById('create_step3').Final_prize_pct.style.color = "black";
	}
	setPrizeTable();
}
	
function setDefaultPct() {
	if ((document.getElementById('create_step3').pformat.value == "cf") ||
		(document.getElementById('create_step3').pformat.value == "pk") ||
		(document.getElementById('create_step3').pformat.value == "rr") ||
		(document.getElementById('create_step3').pformat.value == "br")) {
		var wbox = eval("document.getElementById('create_step3').Weekly_prizes");
		if (typeof wbox != "undefined") {
			var end_loop = Math.max(document.getElementById('create_step3').Final_prizes[document.getElementById('create_step3').Final_prizes.selectedIndex].value, document.getElementById('create_step3').Weekly_prizes[document.getElementById('create_step3').Weekly_prizes.selectedIndex].value);
		} else {
			var end_loop = document.getElementById('create_step3').Final_prizes[document.getElementById('create_step3').Final_prizes.selectedIndex].value;
		}
		for (var r = 1; r <= end_loop; r++) {
			if (((document.getElementById('create_step3').pformat.value == "cf") || (document.getElementById('create_step3').pformat.value == "pk")) && (document.getElementById('create_step3').pool_duration.value > 1)) {
				if (r <= document.getElementById('create_step3').Weekly_prizes[document.getElementById('create_step3').Weekly_prizes.selectedIndex].value) {
					var wbox = eval("document.getElementById('create_step3').Weekly_num_" + r + "_pct");
					if (document.getElementById('create_step3').Weekly_prizes[document.getElementById('create_step3').Weekly_prizes.selectedIndex].value == "1") {
						wbox.selectedIndex = 0;
					}
					if (document.getElementById('create_step3').Weekly_prizes[document.getElementById('create_step3').Weekly_prizes.selectedIndex].value == "2") {
						if (r == 1) wbox.selectedIndex = 70;
						if (r == 2) wbox.selectedIndex = 30;
					}
						if (document.getElementById('create_step3').Weekly_prizes[document.getElementById('create_step3').Weekly_prizes.selectedIndex].value == "3") {
						if (r == 1) wbox.selectedIndex = 57;
						if (r == 2) wbox.selectedIndex = 29;
						if (r == 3) wbox.selectedIndex = 14;
					}
						if (document.getElementById('create_step3').Weekly_prizes[document.getElementById('create_step3').Weekly_prizes.selectedIndex].value == "4") {
						if (r == 1) wbox.selectedIndex = 50;
						if (r == 2) wbox.selectedIndex = 27;
						if (r == 3) wbox.selectedIndex = 15;
						if (r == 4) wbox.selectedIndex = 8;
					}
					if (document.getElementById('create_step3').Weekly_prizes[document.getElementById('create_step3').Weekly_prizes.selectedIndex].value == "5") {
						if (r == 1) wbox.selectedIndex = 39;
						if (r == 2) wbox.selectedIndex = 26;
						if (r == 3) wbox.selectedIndex = 17;
						if (r == 4) wbox.selectedIndex = 11;
						if (r == 5) wbox.selectedIndex = 7;
					}
					if (document.getElementById('create_step3').Weekly_prizes[document.getElementById('create_step3').Weekly_prizes.selectedIndex].value == "10") {
						if (r == 1) wbox.selectedIndex = 30;
						if (r == 2) wbox.selectedIndex = 20;
						if (r == 3) wbox.selectedIndex = 15;
						if (r == 4) wbox.selectedIndex = 11;
						if (r == 5) wbox.selectedIndex = 8;
						if (r == 6) wbox.selectedIndex = 6;
						if (r == 7) wbox.selectedIndex = 4;
						if (r == 8) wbox.selectedIndex = 3;
						if (r == 9) wbox.selectedIndex = 2;
						if (r == 10) wbox.selectedIndex = 1;
					}
				}
				document.getElementById('create_step3').Weekly_pct_total.value = "100%";
				document.getElementById('create_step3').Weekly_pct_total.style.color = "black";
			}
			if (r <= document.getElementById('create_step3').Final_prizes[document.getElementById('create_step3').Final_prizes.selectedIndex].value) {
				var fbox = eval("document.getElementById('create_step3').Final_num_" + r + "_pct");
				if (document.getElementById('create_step3').Final_prizes[document.getElementById('create_step3').Final_prizes.selectedIndex].value == "1") {
					fbox.selectedIndex = 0;
				}
				if (document.getElementById('create_step3').Final_prizes[document.getElementById('create_step3').Final_prizes.selectedIndex].value == "2") {
					if (r == 1) fbox.selectedIndex = 70;
					if (r == 2) fbox.selectedIndex = 30;
				}
				if (document.getElementById('create_step3').Final_prizes[document.getElementById('create_step3').Final_prizes.selectedIndex].value == "3") {
					if (r == 1) fbox.selectedIndex = 57;
					if (r == 2) fbox.selectedIndex = 29;
					if (r == 3) fbox.selectedIndex = 14;
				}
				if (document.getElementById('create_step3').Final_prizes[document.getElementById('create_step3').Final_prizes.selectedIndex].value == "4") {
					if (r == 1) fbox.selectedIndex = 50;
					if (r == 2) fbox.selectedIndex = 27;
					if (r == 3) fbox.selectedIndex = 15;
					if (r == 4) fbox.selectedIndex = 8;
				}
				if (document.getElementById('create_step3').Final_prizes[document.getElementById('create_step3').Final_prizes.selectedIndex].value == "5") {
					if (r == 1) fbox.selectedIndex = 39;
					if (r == 2) fbox.selectedIndex = 26;
					if (r == 3) fbox.selectedIndex = 17;
					if (r == 4) fbox.selectedIndex = 11;
					if (r == 5) fbox.selectedIndex = 7;
				}
				if (document.getElementById('create_step3').Final_prizes[document.getElementById('create_step3').Final_prizes.selectedIndex].value == "10") {
					if (r == 1) fbox.selectedIndex = 30;
					if (r == 2) fbox.selectedIndex = 20;
					if (r == 3) fbox.selectedIndex = 15;
					if (r == 4) fbox.selectedIndex = 11;
					if (r == 5) fbox.selectedIndex = 8;
					if (r == 6) fbox.selectedIndex = 6;
					if (r == 7) fbox.selectedIndex = 4;
					if (r == 8) fbox.selectedIndex = 3;
					if (r == 9) fbox.selectedIndex = 2;
					if (r == 10) fbox.selectedIndex = 1;
				}
			}
		}
		document.getElementById('create_step3').Final_pct_total.value = "100%";
		document.getElementById('create_step3').Final_pct_total.style.color = "black";
		setPrizeTable(); 
	}
}

function setPrizeTable() {
   if (document.getElementById('create_step3').Entry_fee.value == "") {
      document.getElementById('create_step3').Entry_fee.value = 0;
   }
   var entryFee = document.getElementById('create_step3').Entry_fee.value;
   var adminFee = 0;
   if (typeof document.getElementById('create_step3').Admin_fee != "undefined") {
		if (document.getElementById('create_step3').Admin_fee.value == "") document.getElementById('create_step3').Admin_fee.value = 0;
		adminFee = parseFloat(document.getElementById('create_step3').Admin_fee.value);
   }
   if ((document.getElementById('create_step3').pformat.value == "cf") || (document.getElementById('create_step3').pformat.value == "pk") && (document.getElementById('create_step3').Entry_fee.value > 0)) {
	  var weekly_prizes = (document.getElementById('create_step3').pool_duration.value > 1) ? document.getElementById('create_step3').Weekly_prizes[document.getElementById('create_step3').Weekly_prizes.selectedIndex].value : 0;
	  var final_prizes = document.getElementById('create_step3').Final_prizes[document.getElementById('create_step3').Final_prizes.selectedIndex].value;
	  if (document.getElementById('create_step3').Fee_type[document.getElementById('create_step3').Fee_type.selectedIndex].value == "rate") {
    	  var w_funds = ((entryFee > 0) && (weekly_prizes > 0)) ? (((parseInt(document.getElementById('create_step3').Participant_num.value) * parseFloat(document.getElementById('create_step3').Entry_fee.value)) - (adminFee / document.getElementById('create_step3').num_of_weeks.value)) * (document.getElementById('create_step3').Weekly_prize_pct[document.getElementById('create_step3').Weekly_prize_pct.selectedIndex].value / 100)) : 0;
	  } else {
       	  var w_funds = ((entryFee > 0) && (weekly_prizes > 0)) ? (((parseInt(document.getElementById('create_step3').Participant_num.value) * parseFloat(document.getElementById('create_step3').Entry_fee.value)) - adminFee) * (document.getElementById('create_step3').Weekly_prize_pct[document.getElementById('create_step3').Weekly_prize_pct.selectedIndex].value / 100)) / document.getElementById('create_step3').num_of_weeks.value : 0;
	  }
      var weekly_prize_pct = (typeof document.getElementById('create_step3').Weekly_prize_pct != "undefined") ? document.getElementById('create_step3').Weekly_prize_pct[document.getElementById('create_step3').Weekly_prize_pct.selectedIndex].value : 0;
      var final_prize_pct = (typeof document.getElementById('create_step3').Final_prize_pct != "undefined") ? document.getElementById('create_step3').Final_prize_pct[document.getElementById('create_step3').Final_prize_pct.selectedIndex].value : 0;
   } else if (document.getElementById('create_step3').pformat.value == "sv") {
      var weekly_prizes = 0;
	  var final_prizes = document.getElementById('create_step3').Final_prizes[document.getElementById('create_step3').Final_prizes.selectedIndex].value;
      var final_prize_pct = (typeof document.getElementById('create_step3').Final_prize_pct != "undefined") ? document.getElementById('create_step3').Final_prize_pct[document.getElementById('create_step3').Final_prize_pct.selectedIndex].value : 0;
   } else if (document.getElementById('create_step3').pformat.value == "sq") {
      var weekly_prizes = 0;
      var final_prizes = (document.getElementById('create_step3').league.value == "ncaab") ? 2 : 4;
      //var final_prize_pct = 100;
   } else if (document.getElementById('create_step3').pformat.value == "br") {
      var weekly_prizes = 0;
	  var final_prizes = document.getElementById('create_step3').Final_prizes[document.getElementById('create_step3').Final_prizes.selectedIndex].value;
      var final_prize_pct = (typeof document.getElementById('create_step3').Final_prize_pct != "undefined") ? document.getElementById('create_step3').Final_prize_pct[document.getElementById('create_step3').Final_prize_pct.selectedIndex].value : 0;
   } else if (document.getElementById('create_step3').pformat.value == "rr") {
      var weekly_prizes = 0;
	  var final_prizes = document.getElementById('create_step3').Final_prizes[document.getElementById('create_step3').Final_prizes.selectedIndex].value;
      var final_prize_pct = (typeof document.getElementById('create_step3').Final_prize_pct != "undefined") ? document.getElementById('create_step3').Final_prize_pct[document.getElementById('create_step3').Final_prize_pct.selectedIndex].value : 0;
   }
   if ((final_prizes > 0) || (weekly_prizes > 0)) {
      if (document.getElementById('create_step3').pformat.value == "sq") {
         var f_funds = (100 * parseFloat(document.getElementById('create_step3').Entry_fee.value) - adminFee);
      } else if (document.getElementById('create_step3').Entry_fee.value > 0) {
		 if (document.getElementById('create_step3').Prize_calc[document.getElementById('create_step3').Prize_calc.selectedIndex].value == "%") {
         	var f_funds = (document.getElementById('create_step3').Fee_type[document.getElementById('create_step3').Fee_type.selectedIndex].value == "flat") ? ((parseInt(document.getElementById('create_step3').Participant_num[document.getElementById('create_step3').Participant_num.selectedIndex].value) * parseFloat(document.getElementById('create_step3').Entry_fee.value)) - adminFee) * (final_prize_pct / 100) : ((parseInt(document.getElementById('create_step3').Participant_num[document.getElementById('create_step3').Participant_num.selectedIndex].value) * parseFloat(document.getElementById('create_step3').Entry_fee.value) * document.getElementById('create_step3').num_of_weeks.value) - adminFee) * (final_prize_pct / 100);
      		var f_est = w_est = 0;
      		for (var r = 1; r <= Math.max(final_prizes, weekly_prizes); r++) {
         		var wbox = eval("document.getElementById('create_step3').weekly_prize_" + r + "_est");
         		var fbox = eval("document.getElementById('create_step3').final_prize_" + r + "_est");
				var w_est_box = eval("document.getElementById('create_step3').Weekly_num_" + r + "_pct");
				var f_est_box = eval("document.getElementById('create_step3').Final_num_" + r + "_pct");
				if (weekly_prizes >= r) {
					w_est = formatCurrency(w_funds * (w_est_box[w_est_box.selectedIndex].value / 100));
					wbox.value = w_est;
				}
				if (final_prizes >= r) {
					f_est = formatCurrency(f_funds * (f_est_box[f_est_box.selectedIndex].value / 100));
         			fbox.value = f_est;
				}
			}
		 } else {
			setMinParticipants();
         }
      }
   }
}

function toggleEntryFee() {
	if (document.getElementById('create_step3').Entry_fee.value == "") {
		document.getElementById('create_step3').Entry_fee.value = 0;
	}
	var entryFee = parseFloat(document.getElementById('create_step3').Entry_fee.value);
	var p_entryFee = parseFloat(document.getElementById('create_step3').p_entry_fee.value);
	if ((p_entryFee > 0) && (entryFee == 0)) {
		document.getElementById('create_step3').submit()
	} else if ((p_entryFee == 0) && (entryFee > 0)) {
		document.getElementById('create_step3').submit()
	} else if (entryFee > 0) {
		if (document.getElementById('create_step3').Prize_calc.selectedIndex == 0) {
			setPrizeTable();
		} else if (document.getElementById('create_step3').Prize_calc.selectedIndex == 1) {
			setMinParticipants();
		}
	}
}

function checkNumeric() {
}

function setMinParticipants() {
   var entryFee = parseFloat(document.getElementById('create_step3').Entry_fee.value);
   var duration = parseInt(document.getElementById('create_step3').pool_duration.value);
   var adminFee = 0;
   if (typeof document.getElementById('create_step3').Admin_fee != "undefined") {
		if (document.getElementById('create_step3').Admin_fee.value == "") {
			document.getElementById('create_step3').Admin_fee.value = 0;
		}
		adminFee = parseFloat(document.getElementById('create_step3').Admin_fee.value);
   }
	var t_funds = 0;
	var weekly_prizes = (typeof document.getElementById('create_step3').Weekly_prizes != "undefined") ? document.getElementById('create_step3').Weekly_prizes[document.getElementById('create_step3').Weekly_prizes.selectedIndex].value : 0;
	var final_prizes = document.getElementById('create_step3').Final_prizes[document.getElementById('create_step3').Final_prizes.selectedIndex].value;
   	for (var r = 1; r <= Math.max(final_prizes, weekly_prizes); r++) {
		var w_box = eval("document.getElementById('create_step3').Weekly_num_" + r + "_pct");
		var f_box = eval("document.getElementById('create_step3').Final_num_" + r + "_pct");
		if (weekly_prizes >= r) {
			if (w_box.value == "") {
				w_box.value = "0";
			}
			t_funds += (parseFloat(w_box.value) * duration);
		}
		if (final_prizes >= r) {
			if (f_box.value == "") {
				f_box.value = "0";
			}
			t_funds += parseFloat(f_box.value);
		}
	}
	t_funds += adminFee;
	if (document.getElementById('create_step3').Fee_type.selectedIndex == 0) {
		min_cnt = Math.ceil(t_funds / entryFee);
	} else {
		min_cnt = Math.ceil(t_funds / (entryFee * duration));
	}
	document.getElementById('create_step3').Participant_num.value = min_cnt + " / " + formatCurrency(t_funds);
}

function checkSquaresPct() {
   var totPct = 0;
   var sPeriods = (document.getElementById('create_step3').league.value == "ncaab") ? 2 : 4;
   var adminFee = 0;
   if (typeof document.getElementById('create_step3').Admin_fee != "undefined") {
		if (document.getElementById('create_step3').Admin_fee.value == "") document.getElementById('create_step3').Admin_fee.value = 0;
		adminFee = parseFloat(document.getElementById('create_step3').Admin_fee.value);
   }
   for (var b = 1; b <= sPeriods; b++) {
      var fbox = eval("document.getElementById('create_step3').Final_num_" + b + "_pct");
      var ebox = eval("document.getElementById('create_step3').final_prize_" + b + "_est");
      totPct+=parseInt(fbox.options[fbox.selectedIndex].value);
	  thisAmt = formatCurrency((parseInt(fbox.options[fbox.selectedIndex].value) / 100 * parseFloat(document.getElementById('create_step3').Entry_fee.value) * 100) - adminFee);
	  ebox.value = thisAmt;
   }
   var totPctBox = eval("document.getElementById('create_step3').Final_pct_total");
   var totAmtBox = eval("document.getElementById('create_step3').Final_amt_total");
	totPctBox.value = totPct + "%";
	totAmtBox.value = formatCurrency((totPct / 100 * parseFloat(document.getElementById('create_step3').Entry_fee.value) * 100) - adminFee);
   if (totPct != 100) {
      totPctBox.style.color = "red";
      totAmtBox.style.color = "red";
   }
   else {
      totPctBox.style.color = "black";
      totAmtBox.style.color = "black";
   }
   setPrizeTable();
}

function checkEmailSyntax(pString) {
   var arg = /\s+/g;
   var newStr = pString.replace(arg, "");
   var re = /\s*,\s*/g;
   var junk = 0;
   var junkArr = new Array();
   eListArr = newStr.split(re);
   for (var x = 0; x < eListArr.length; x++) {
      var em = new String();
      em = eListArr[x];
      if (em != "") {
         if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(em)) {
            junk = junk;
         }
         else {
            junkArr[junk] = em;
            junk++;
         }
       }
   }
   var msg = "";
   if (junk > 0) {
      msg += "The following e-mail address(es) appear to be invalid:\r\n\r\n";
      for (var j = 0; j < junkArr.length; j++) {
          msg += "- " + junkArr[j] + "\r\n";
      }
      msg += "\r\nPlease check your entries!";
   }
   return msg;
}

function createPoolStep1() {

   if (document.getElementById('create_step1').Poolname.value == "") {
      alert("Please enter a Pool Name.");
      document.getElementById('create_step1').Poolname.focus();
      return false;
   }
   if (document.getElementById('create_step1').Poolpassword.value == "") {
      alert("Please enter a Pool Password.");
      document.getElementById('create_step1').Poolpassword.focus();
      return false;
   }
   var len = document.getElementById('create_step1').Poolformat.length;
   var formatSelected = 0;
   for (i = 0; i < len; i++) {
      if (document.getElementById('create_step1').Poolformat[i].checked) {
        formatSelected = 1;
	break;
      }
   }
   if (formatSelected == 0) {
      alert("Please select a Pool Format.");
      return false;
   } 
   else {
      return true;
   }
}

function createPoolStep2() {
   if ((document.getElementById('create_step2').Start_week) && (document.getElementById('create_step2').End_week)) {
      var sWeek = parseInt(document.getElementById('create_step2').Start_week.options[document.getElementById('create_step2').Start_week.selectedIndex].value);
      var eWeek = parseInt(document.getElementById('create_step2').End_week.options[document.getElementById('create_step2').End_week.selectedIndex].value);
      if (sWeek > eWeek) {
         alert("The Start Week can not be greater than the End Week.");
         document.getElementById('create_step2').Start_week.focus();
         return false;
     }
     else {
         return true;
      }
   }
}

function checkEntryFee() {
   	if ((validateInteger(document.getElementById('create_step3').Entry_fee.value) == false) || (document.getElementById('create_step3').Entry_fee.value < 0)) {
      alert("Please enter a valid Entry Fee - positive integer value expected.");
      document.getElementById('create_step3').Entry_fee.select();
   	} else {
	  document.getElementById('create_step3').submit();
	}
}
	
function createPoolStep3() {
   if ((validateInteger(document.getElementById('create_step3').Entry_fee.value) == false) ||
      (document.getElementById('create_step3').Entry_fee.value < 0)) {
      alert("Please enter a valid Entry Fee - positive integer value expected.");
      document.getElementById('create_step3').Entry_fee.select();
      return false;
   }
   if ((document.getElementById('create_step3').pformat.value == "sv") &&  
      (document.getElementById('create_step3').strikes.value > 0)) {
      if ((validateInteger(document.getElementById('create_step3').Rebuy_fee.value) == false) ||
         (document.getElementById('create_step3').Rebuy_fee.value < 0)) {
         alert("Please enter a valid Fee for Optional Strikes - positive integer value expected.");
         document.getElementById('create_step3').Rebuy_fee.select();
         return false;
      }
   }
   if ((typeof document.getElementById('create_step3').Admin_fee != "undefined") &&
	 ((validateInteger(document.getElementById('create_step3').Admin_fee.value) == false) ||
      (document.getElementById('create_step3').Admin_fee.value < 0))) {
      alert("Please enter a valid Admin Fee - positive integer value expected.");
      document.getElementById('create_step3').Admin_fee.select();
      return false;
   }
   if ((document.getElementById('create_step3').pformat.value == "cf") ||
      (document.getElementById('create_step3').pformat.value == "pk")) {
	  	if ((typeof document.getElementById('create_step3').Prize_calc != "undefined") && 
		  (document.getElementById('create_step3').Prize_calc.selectedIndex == 0)) {
    	  	if (document.getElementById('create_step3').Entry_fee.value > 0) {
         		if ((document.getElementById('create_step3').Weekly_prizes[document.getElementById('create_step3').Weekly_prizes.selectedIndex].value > 0) &&
					(document.getElementById('create_step3').Weekly_prize_pct[document.getElementById('create_step3').Weekly_prize_pct.selectedIndex].value == 0)) {
            		alert("You have elected to declare Weekly Prize(s), but did not allocate a percentage of funds.");
            		document.getElementById('create_step3').Weekly_prize_pct.focus();
            		return false;
				}
         		if ((document.getElementById('create_step3').Final_prizes[document.getElementById('create_step3').Final_prizes.selectedIndex].value > 0) &&
					(document.getElementById('create_step3').Final_prize_pct[document.getElementById('create_step3').Final_prize_pct.selectedIndex].value == 0)) {
            		alert("You have elected to declare Final Prize(s), but did not allocate a percentage of funds.");
            		document.getElementById('create_step3').Final_prize_pct.focus();
            		return false;
				}
         		if ((typeof document.getElementById('create_step3').Weekly_prize_pct != "undefined") &&
         			(typeof document.getElementById('create_step3').Final_prize_pct != "undefined")) {
       		  		if (parseInt(document.getElementById('create_step3').Weekly_prize_pct[document.getElementById('create_step3').Weekly_prize_pct.selectedIndex].value) + parseInt(document.getElementById('create_step3').Final_prize_pct[document.getElementById('create_step3').Final_prize_pct.selectedIndex].value) != 100) {
		 				var ret = confirm("WARNING: The Total Fund Allocation does not add up to 100%!\n\nClick 'OK' to continue, or 'Cancel' to correct.");
         				if (ret != true) {
           	 				document.getElementById('create_step3').Weekly_prize_pct.focus();
            				return false;
         				}
					}
				} else if ((typeof document.getElementById('create_step3').Weekly_prize_pct == "undefined") &&
         			(typeof document.getElementById('create_step3').Final_prize_pct != "undefined")) {
       		  		if (parseInt(document.getElementById('create_step3').Final_prize_pct[document.getElementById('create_step3').Final_prize_pct.selectedIndex].value) != 100) {
		 				var ret = confirm("WARNING: The Fund Allocation does not add up to 100%!\n\nClick 'OK' to continue, or 'Cancel' to correct.");
         				if (ret != true) {
           	 				document.getElementById('create_step3').Final_prize_pct.focus();
            				return false;
         				}
         			}
				} else if ((typeof document.getElementById('create_step3').Weekly_prize_pct != "undefined") &&
         			(typeof document.getElementById('create_step3').Final_prize_pct == "undefined")) {
       		  		if (parseInt(document.getElementById('create_step3').Weekly_prize_pct[document.getElementById('create_step3').Weekly_prize_pct.selectedIndex].value) != 100) {
		 				var ret = confirm("WARNING: The Fund Allocation does not add up to 100%!\n\nClick 'OK' to continue, or 'Cancel' to correct.");
         				if (ret != true) {
           	 				document.getElementById('create_step3').Weekly_prize_pct.focus();
            				return false;
         				}
         			}
				}
         	}
      		if ((document.getElementById('create_step3').Entry_fee.value > 0) && 
         		(document.getElementById('create_step3').Final_prizes[document.getElementById('create_step3').Final_prizes.selectedIndex].value > 0)) {
         		if (document.getElementById('create_step3').Final_pct_total.value != "100%") {
            		alert("The Final percentage breakdown must add up to 100%.");
            		document.getElementById('create_step3').Final_num_1_pct.focus();
            		return false;
         		}
      		}
      		if ((document.getElementById('create_step3').Entry_fee.value > 0) && 
         		(typeof document.getElementById('create_step3').Weekly_prize_pct != "undefined") &&
         		(document.getElementById('create_step3').Weekly_prizes[document.getElementById('create_step3').Weekly_prizes.selectedIndex].value > 0)) {
         		if (document.getElementById('create_step3').Weekly_pct_total.value != "100%") {
            		alert("The Weekly percentage breakdown must add up to 100%.");
            		document.getElementById('create_step3').Weekly_num_1_pct.focus();
            		return false;
         		}
         	}
      	}
        if (typeof document.getElementById('create_step3').Weekly_prizes != "undefined") {
        	var end_loop = Math.max(document.getElementById('create_step3').Final_prizes[document.getElementById('create_step3').Final_prizes.selectedIndex].value, document.getElementById('create_step3').Weekly_prizes[document.getElementById('create_step3').Weekly_prizes.selectedIndex].value);
        } else {
          	var end_loop = document.getElementById('create_step3').Final_prizes[document.getElementById('create_step3').Final_prizes.selectedIndex].value;
        }
      	for (var r = 1; r <= end_loop; r++) {
			if (r == 1) { var place_str = "1st"; }
			else if (r == 2) { var place_str = "2nd"; }
			else if (r == 3) { var place_str = "3rd"; }
			else { var place_str = r + "th"; }
			if (typeof document.getElementById('create_step3').Prize_calc != "undefined") {
				var calc_str = (document.getElementById('create_step3').Prize_calc.selectedIndex == 0) ? "percentage" : "dollar amount";
			}
         	var wbox = eval("document.getElementById('create_step3').Weekly_num_" + r + "_pct");
			if (typeof wbox != "undefined") {
				var wval = (document.getElementById('create_step3').Prize_calc.selectedIndex == 0) ? wbox[wbox.selectedIndex].value : wbox.value;
				if ((validateInteger(wval) == false) || (wval == 0)) {
      				alert("Please enter a valid " + calc_str + " for the " + place_str + " Place Weekly Prize - positive integer value expected.");
					wbox.select()
      				return false;
				}
			}
         	var fbox = eval("document.getElementById('create_step3').Final_num_" + r + "_pct");
			if (typeof fbox != "undefined") {
				var fval = (document.getElementById('create_step3').Prize_calc.selectedIndex == 0) ? fbox[fbox.selectedIndex].value : fbox.value;
				if ((validateInteger(fval) == false) || (fval == 0)) {
      				alert("Please enter a valid " + calc_str + " for the " + place_str + " Place Final Prize - positive integer value expected.");
					fbox.select()
      				return false;
				}
			}
		}
   } else if (document.getElementById('create_step3').pformat.value == "sq") {
      var totPct = 0;
      var final_prizes = (document.getElementById('create_step3').league.value == "ncaab") ? 2 : 4;
      for (var b = 1; b <= final_prizes; b++) {
      	var fbox = eval("document.getElementById('create_step3').Final_num_" + b + "_pct");
       	totPct+=parseInt(fbox.options[fbox.selectedIndex].value);
      }
      if (totPct != 100) {
		alert("The Prize Percentage breakdown does not add up to 100%!");
       	document.getElementById('create_step3').Final_num_1_pct.focus();
       	return false;
	  }
   } else {
      if ((document.getElementById('create_step3').Entry_fee.value > 0) && 
        (typeof document.getElementById('create_step3').Final_prize_pct != "undefined") && 
      	(parseInt(document.getElementById('create_step3').Final_prize_pct[document.getElementById('create_step3').Final_prize_pct.selectedIndex].value) == 0)) {
	 		alert("You have elected to declare Final Prize(s), but did not allocate a percentage of funds.");
       	 	document.getElementById('create_step3').Final_prize_pct.focus();
          	return false;
   	  }
      if ((document.getElementById('create_step3').Entry_fee.value > 0) && 
        (typeof document.getElementById('create_step3').Final_prize_pct != "undefined") && 
       	(parseInt(document.getElementById('create_step3').Final_prize_pct[document.getElementById('create_step3').Final_prize_pct.selectedIndex].value) != 100)) {
			var ret = confirm("WARNING: The Fund Allocation does not add up to 100%!\n\nClick 'OK' to continue, or 'Cancel' to correct.");
       		if (ret != true) {
       	 		document.getElementById('create_step3').Final_prize_pct.focus();
        		return false;
      		}
      }
      if ((document.getElementById('create_step3').Final_prizes[document.getElementById('create_step3').Final_prizes.selectedIndex].value > 0) &&
         (typeof document.getElementById('create_step3').Final_prize_pct != "undefined") && 
         (document.getElementById('create_step3').Final_prize_pct[document.getElementById('create_step3').Final_prize_pct.selectedIndex].value == 0)) {

         alert("You have elected to include Final Prize(s), but did not allocate a percentage of funds.");
         document.getElementById('create_step3').Weekly_prize_pct.focus();
         return false;
      }
      if ((document.getElementById('create_step3').Entry_fee.value > 0) && 
         (document.getElementById('create_step3').Final_prizes[document.getElementById('create_step3').Final_prizes.selectedIndex].value > 0)) {
         if ((typeof document.getElementById('create_step3').Final_prize_pct != "undefined") && 
         	(document.getElementById('create_step3').Final_pct_total.value != "100%")) {
            alert("The Final percentage breakdown must add up to 100%.");
            document.getElementById('create_step3').Final_num_1_pct.focus();
            return false;
         }
      }
      var end_loop = document.getElementById('create_step3').Final_prizes[document.getElementById('create_step3').Final_prizes.selectedIndex].value;
      for (var r = 1; r <= end_loop; r++) {
		if (r == 1) { var place_str = "1st"; }
		else if (r == 2) { var place_str = "2nd"; }
		else if (r == 3) { var place_str = "3rd"; }
		else { var place_str = r + "th"; }
		if (typeof document.getElementById('create_step3').Prize_calc != "undefined") {
			var calc_str = (document.getElementById('create_step3').Prize_calc.selectedIndex == 0) ? "percentage" : "dollar amount";
		}
       	var fbox = eval("document.getElementById('create_step3').Final_num_" + r + "_pct");
		if (typeof fbox != "undefined") {
			var fval = (document.getElementById('create_step3').Prize_calc.selectedIndex == 0) ? fbox[fbox.selectedIndex].value : fbox.value;
			if ((validateInteger(fval) == false) || (fval == 0)) {
      			alert("Please enter a valid " + calc_str + " for the " + place_str + " Place Final Prize - positive integer value expected.");
				fbox.select()
      			return false;
			}
		}
	 }
   }
   return true;
}

function createPoolStep5() {
   if (document.getElementById('create_step5').New_emails.value != "") {
      var emailErrorMsg = checkEmailSyntax(document.getElementById('create_step5').New_emails.value);
      if (emailErrorMsg != "") {
        alert(emailErrorMsg);
        document.getElementById('create_step5').New_emails.focus();
        return false;
      }
   }
   else {
      return true;
   }
}

function checkLogin() {
   if (document.getElementById('loginForm').UserId.value == "") {
      alert("Please enter your UserID.");
      document.getElementById('loginForm').UserId.focus();
      return false;
   }
   if (document.getElementById('loginForm').Password.value == "") {
      alert("Please enter a Password.");
      document.getElementById('loginForm').Password.focus();
      return false;
   } else {
      return true;
   }
}

function checkEntries() {
  if (document.getElementById('registration').Username.value == "") {
    alert("Please enter the Username you'd like to use.");
    document.getElementById('registration').Username.focus();
    return false;
  }
  var tmpStr = new String("");
  tmpStr = document.getElementById('registration').Username.value;
  if ((tmpStr.length < 3) || (tmpStr.length > 20)) {
    alert("Usernames must be between 3 and 20 characters.");
    document.getElementById('registration').Username.select();
    return false;
  }
  if (document.getElementById('registration').Password1.value == "") {
    alert("Please enter a Password.");
    document.getElementById('registration').Password1.select();
    return false;
  }
  if (document.getElementById('registration').Password2.value == "") {
    alert("Please confirm your Password.");
    document.getElementById('registration').Password2.select();
    return false;
  }
  tmpStr = document.getElementById('registration').Password1.value;
  if ((tmpStr.length < 6) || (tmpStr.length > 10)) {
    alert("Passwords must be between 6 and 10 characters.");
    document.getElementById('registration').Password1.select();
    return false;
  }
  tmpStr1 = document.getElementById('registration').Password1.value;
  tmpStr2 = document.getElementById('registration').Password2.value;
  if (tmpStr1 != tmpStr2) {
    alert("Passwords must match.");
    document.getElementById('registration').Password1.select();
    return false;
  }
  if (document.getElementById('registration').Fname.value == "") {
    alert("Please enter your First Name.");
    document.getElementById('registration').Fname.focus();
    return false;
  }
  if (document.getElementById('registration').Lname.value == "") {
    alert("Please enter your Last Name.");
    document.getElementById('registration').Lname.focus();
    return false;
  }
  if (document.getElementById('registration').Email.value == "") {
    alert("Please enter your E-mail Address.");
    document.getElementById('registration').Email.focus();
    return false;
  }
  else { return true; }
}

function formatCurrency(num) {
   num = num.toString().replace(/\$|\,/g,'');
   if(isNaN(num))
   num = "0";  
   sign = (num == (num = Math.abs(num)));
   num = Math.floor(num*100+0.50000000001);
   cents = num%100;
   num = Math.floor(num/100).toString();
   if(cents<10) cents = "0" + cents;
   for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
   num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3));
   if(cents != "00") {
   	 return (((sign)?'':'-') + '$' + num + '.' + cents);
   } else {
   	 return (((sign)?'':'-') + '$' + num);
   }
}

function copy_email(){
   var o, i;
   for (i=0; i < document.getElementById('emailSelect').options.length; i++){
      o = document.getElementById('emailSelect').options[i];
      if (o.selected){
         if (document.getElementById('emailText').value != '')
            document.getElementById('emailText').value += ', ';
            document.getElementById('emailText').value += o.text;
      }
   }
}

function checkDate() {
 
   var myDayStr = document.getElementById('DD').value;
   var myMonthStr = document.getElementById('MM').value;
   var myYearStr = document.getElementById('YYYY').value;
   var myMonth = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); var myDateStr = myDayStr + ' ' + myMonth[myMonthStr] + ' ' + myYearStr;

   /* Using form values, create a new date object
   using the setFullYear function */
   var myDate = new Date();
   myDate.setFullYear( myYearStr, myMonthStr, myDayStr );

   if ( myDate.getMonth() != myMonthStr ) {
      alert("Error: " + myDateStr + " is NOT a valid date.");
      return false;
   } else {
      return true;
   }
 
}
 
function showLeaguePools(league) {
   var tmp = document.getElementsByTagName('tr');
   var srch = league.toLowerCase();
   for (j=0; j<tmp.length; j++) {
      if (tmp[j].id.indexOf('tr_') > -1) {
      if (tmp[j].id.indexOf(league) > -1) {
         tmp[j].style.display = '';
      } else {
         tmp[j].style.display = 'none';
      }
      }
   }
}

