function leaguePass(){
  if ($("#private").is(":checked")){$("#showPass").show();}else{$("#showPass").hide();}
}

function valCreate(){
  if ($('#leagueName').val() == ""){alert('Please enter a name for your league');return false;}
  if ($("#private").is(":checked") && $('#password').val() == ""){alert('Please enter a password for your league');return false;}
  if ($('#startDate').val() == ""){alert('Please enter a start date for your league');return false;}
  if ($('#endDate').val() == ""){alert('Please enter an ending date for your league');return false;}
  if ($("#liveDraft").is(":checked") && $('#draftDate').val() == ""){alert('Please enter a date for your draft');return false;}
  return true;
}

function valContact(){
  if ($('#contactName').val() == ""){alert('Please tell us your name');return false;}
  if ($('#contactEmail').val() == ""){alert('Please tell us your email address\nso we can get back to you');return false;}
  if ($('#contactMsg').val() == ""){alert('Please enter a message');return false;}
  return true;
}

function updateTZ(){
  var t = $("#liveDraftTime").val();
  var params = "time="+t;
  $.post("/ajax/tz.php",params,function(data){$("#tz").html(data);});
}

function showNewsDate(){
  var active = $("#activeNewsDate").val();
  if (active == ""){return false;}
  var divId = "#newsDate" + active;
  $(divId).hide();
  var newStory = $("#showNewsDate").val();
  var newDivId = "#newsDate" + newStory;
  $("#activeNewsDate").val(newStory);
  $(newDivId).show("slow");
}

function suggestCeleb(){
  $("#searchCelebResults").html("<img src='/images/indicator.gif' />");
  var celeb = $("#searchCeleb").val();
  var params = "celeb=" + celeb;
  $.post("/ajax/suggestCeleb.php",params,function(data){$("#searchCelebResults").html(data);});
  if (celeb != ""){$("#searchCelebX").show();}
}

function clearSearchCeleb(){
  $("#searchCeleb").val("");
  $("#searchCelebResults").html("");
  $("#searchCelebX").hide();
}

function imposeMaxLength(Object, MaxLen){
  return (Object.value.length <= MaxLen);
}

function changeVendorNews(){
  var vendorId = $("#currentVendorNews").val();
  window.location = "/research/headlines/" + vendorId;
}

function showNameBox(){
  $("#nameBox").toggle("slow");
}

function toggleBdays(){
  $("#birthdays").toggle("slow");
}

function toggleBoxoffice(){
  $("#boxoffice").toggle("slow");
}

function changeName(){
  var newName = $("#newName").val();
  var params = "newName=" + newName;
  $.post("/ajax/changeName.php",params,function(data){$("#displayTeamName").html(data);$("#myTeamName").html(data);});
  showNameBox();
}

function snapshot(teamId){
  var snap = "#snapshot" + teamId;
  $(snap).modal({
	opacity:80,
	closeHTML:"Close",
	overlayCss: {backgroundColor:"#3366CC"},
  containerCss:{
	backgroundColor:"#fff",
	borderColor:"#737373",
	borderWidth:"3px",
	borderStyle:"solid",
	color:"#10549f",
	height:"300px",
	padding:"10px",
	width:"400px"
	}
  });
}

function hideCancel(){$.modal.close();}

function commishSell(celebId){
  var snap = "#sell" + celebId;
  $(snap).modal({
	opacity:80,
	closeHTML:"Close",
	overlayCss: {backgroundColor:"#3366CC"},
  containerCss:{
	backgroundColor:"#fff",
	borderColor:"#737373",
	borderWidth:"3px",
	borderStyle:"solid",
	color:"#10549f",
	height:"300px",
	padding:"10px",
	width:"600px"
	}
  });
}

function commishBuy(){
  var snap = "#buy";
  $(snap).modal({
	opacity:80,
	closeHTML:"Close",
	overlayCss: {backgroundColor:"#3366CC"},
  containerCss:{
	backgroundColor:"#fff",
	borderColor:"#737373",
	borderWidth:"3px",
	borderStyle:"solid",
	color:"#10549f",
	height:"300px",
	padding:"10px",
	width:"600px"
	}
  });
}

function changeCash(){
  var snap = "#changeCash";
  $(snap).modal({
	opacity:80,
	closeHTML:"Close",
	overlayCss: {backgroundColor:"#3366CC"},
  containerCss:{
	backgroundColor:"#fff",
	borderColor:"#737373",
	borderWidth:"3px",
	borderStyle:"solid",
	color:"#10549f",
	height:"300px",
	padding:"10px",
	width:"400px"
	}
  });
}

function prizeDetails(leagueId){
  $("#prizeInfo").modal({
	opacity:80,
	closeHTML:"Close",
	overlayCss: {backgroundColor:"#3366CC"},
  containerCss:{
	backgroundColor:"#fff",
	borderColor:"#737373",
	borderWidth:"3px",
	borderStyle:"solid",
	color:"#10549f",
	height:"300px",
	padding:"10px",
	width:"600px"
	}
  });
  $("#prizeGuts").html("<img src='/images/indicator.gif'>");
  var params = "leagueId="+leagueId;
  $.post("/ajax/getPrize.php",params,function(data){$("#prizeGuts").html(data);});
}


function toggleSideMenu(itemId){
  var divId = "#options" + itemId;
  var arrow = "#arrow" + itemId;
  if($(divId).is(':visible'))
	{
	$(arrow).html("<img src='/images/arrowR.gif' />");
	$(divId).hide("slow");
	}else{
	$(arrow).html("<img src='/images/arrowD.gif' />");
	$(divId).show("slow");
	}
}

function addNewNote(leagueId){
  var newSubject = $("#newSubject").val();
  var newNote = $("#newNote").val();
  if (newSubject == ""){alert("Please fill in the subject");return false;}
  if (newNote == ""){alert("Please fill in the message");return false;}
  var newUrl = "/messages/view/" + leagueId + "/";
  var params = "newSubject=" + newSubject + "&newNote=" + newNote;
  $.post("/ajax/addMessage.php",params,function(data){window.location = newUrl;});
}

function addNewReply(leagueId, messageId){
  var divId = "#replyBox" + messageId;
  var newReply = $(divId).val();
  if (newReply == ""){alert("Please type your comments first.");return false;}
  var newUrl = "/messages/view/" + leagueId + "/";
  var params = "messageId=" + messageId + "&newReply=" + newReply;
  $.post("/ajax/addReply.php",params,function(data){window.location = newUrl;});
}

function showHint(obj){
	this.value = $(obj).attr('title');
	$(obj).addClass('text-label');

	$(obj).focus(function(){
		if(this.value == $(obj).attr('title')) {
			this.value = '';
			$(obj).removeClass('text-label');
		}
	});

	$(obj).blur(function(){
		if(this.value == '') {
			this.value = $(obj).attr('title');
			$(obj).addClass('text-label');
		}
	});
}

function valAccount(){
  if ($('#firstName').val() == ""){alert('Please enter your first name');return false;}
  if ($('#lastName').val() == ""){alert('Please enter your last name');return false;}
  if ($('#email').val() == ""){alert('Please enter your email');return false;}
  return true;
}

function valTN(){
  if ($('#teamName').val() == ""){alert('Please enter a team name');return false;}
  return true;
}

function tipIt(tipId){
  var divId = "#tip"+tipId;
  $(divId).toggle("slow");
}

function quickSearch(){
  $("#quicksearch").modal({
	opacity:80,
	closeHTML:"Close",
	overlayCss: {backgroundColor:"#3366CC"},
  containerCss:{
	backgroundColor:"#fff",
	borderColor:"#737373",
	borderWidth:"3px",
	borderStyle:"solid",
	color:"#10549f",
	height:"400px",
	padding:"10px",
	width:"600px"
	}
  });
}
function qsSuggest(){
  $("#qsResults").html("<img src='/images/indicator.gif'>");
  var celeb = $("#qs").val();
  var params = "celeb="+celeb;
  $.post("/ajax/suggestCelebQS.php",params,function(data){$("#qsResults").html(data);});
}

function addCommas(nStr){
  nStr += '';
  x = nStr.split('.');
  x1 = x[0];
  x2 = x.length > 1 ? '.' + x[1] : '';
  var rgx = /(\d+)(\d{3})/;
  while (rgx.test(x1)) {x1 = x1.replace(rgx, '$1' + ',' + '$2');}
  return x1 + x2;
}

