function compareConfirm(elem)
{
	$(".alert").hide();
	val1 = $("#"+elem).val();
	val1 = val1.replace(/ /g,"");
	val2 = $("#confirm"+elem).val();
	val2 = val2.replace(/ /g,"");
	if(val1==val2)
	{
		if(val1.length<6)
		{
			alert("The "+elem+" field must be at least 6 characters. Please re-enter your "+elem+" and re-submit.");
			$("#"+elem).focus();
			return false;
		}
		return true;
	}
	else
	{
		alert("The "+elem+" fields do not match. Please re-enter your "+elem+" and re-submit.");
		$("#"+elem).focus();
		return false;
	}
}
	
function checkLength(elem)
{
	thisCount = returnLength(elem);
	if(thisCount>24)
	{
		$(".validationCheck").html("You've entered more than 24 characters. We recommend no more than 24 characters.");
		$(".validationCheck").addClass("error");
	}
	else
	{
		$(".validationCheck").html(" Character count: "+thisCount);
		$(".validationCheck").removeClass("error");			
	}
}

function returnLength(elem)
{
	elemVal = $("#"+elem).val();
	return elemVal.length;
}
	
function generatePlayerLayer(playerID,playerName)
{
	htmlLayer = "<div id=\"playerLayer\">";
	htmlLayer += "<a href=\"javascript:$('#playerLayer').remove();void(0);\" class=\"playerLayerClose\">[x]</a>";
	htmlLayer += "<div class=\"playerLayerPhoto\"><img src=\"http://mlb.mlb.com/images/players/mugshot/ph_"+playerID+".jpg\" height=\"135\" width=\"90\" alt=\"player photo\" /></div>";
	htmlLayer += "<h4>"+playerName+"</h4>";
	htmlLayer += "<div id=\"playerTable\"></div>";
	htmlLayer += "<a href=\"http://mlb.mlb.com/team/player.jsp?player_id="+playerID+"\">MLB Player File</a>";
	return htmlLayer;
}
		
function validate(criteria,row)
{
	$.ajax({
		type: "POST",
		url: "/scripts/check_criteria.php",
		data: "cri="+$("#"+criteria).val()+"&row="+row,
		success: function(unXML){
			xmlDoc = unXML.documentElement;
			xmlElem = xmlDoc.firstChild;
			xmlResult = xmlElem.textContent;
			if(xmlResult=="invalid")
			{
				$("."+criteria+" .validationCheck").html("Sorry, this "+criteria+" is already in use. Please try another.");
				$("."+criteria+" .validationCheck").addClass("error");
				$("#submit").attr("disabled","disabled");
			}
			else
			{
				$("."+criteria+" .validationCheck").html("");
				$("."+criteria+" .validationCheck").removeClass("error");
				validators = $(".validationCheck");
				checker = false;
				for(x=0;x<validators.length;x++)
				{
					if(validators.eq(x).hasClass("error"))
					{
						checker = true;
						break;
					}
				}
				if(checker==false)
				{
					$("#submit").removeAttr("disabled");
				}
			}
		}
	});
}

function addInvite()
{
	inviteForm = $("#invitations");
	invites = $("#invitations p.invite").size();
	nextInvite = invites+1;
	string = "<p class=\"invite\" style=\"display:none\"> <label for=\"name"+nextInvite+"\">Name:</label> <input type=\"text\" id=\"name"+nextInvite+"\" name=\"name"+nextInvite+"\" /> <label for=\"email"+nextInvite+"\">Email:</label> <input type=\"text\" id=\"email"+nextInvite+"\" class=\"email emailInvite\" name=\"email"+nextInvite+"\" /></p>";
	//alert(string);

	$("#invitations a").before(string);
	if(nextInvite % 2 != 1)
	{
		$("#invitations p").eq(invites).addClass("alternate");
	}
	$("#invitations p").eq(invites).slideDown();
	//alert(invites);
	
	$("input[name=inviteCount]").attr("value",nextInvite);
	return false;
}