/**
 * @author kyasui
 */
var core = {
	subject: "I thought you might like to check out MSG Varsity's Talent Show!!!",
    body: 'You can see this page at: http://www.msgvarsitytalentshow.com ',
	mailto: '',
		init: $(document).ready(function() {	
			$("#voteButton").click(function(){
			$.blockUI({ message: '<h1>Processing...</h1>' });
			$("#errorDiv").hide();
			var userID = $("#userID").val();
			var schoolID = $("#schoolID").val();
			var catpchaText = $("#recaptcha_response_field").val();
			var challengeField = $("#recaptcha_challenge_field").val();
			if(catpchaText != "")
			{
			    core.vote(userID, schoolID, catpchaText, challengeField);
			}
			else
			{
			    $("#errorDiv").html("Please make sure the captcha is entered correctly").fadeIn();
			    $("#fakeDiv").hide();
			    $.unblockUI();
			}
			});
			
			
			
			$("#voteButton2").click(function(){
			$.blockUI({ message: '<h1>Processing...</h1>' });
			$("#errorDiv").hide();
			var userID = $("#userID").val();
			var schoolID = $("#schoolID").val();
			var catpchaText = $("#captchaText").val();
			if(catpchaText != "")
			{
			    core.vote(userID, schoolID, catpchaText, "");
			}
			else
			{
			    $("#errorDiv").html("Please make sure the captcha is entered correctly").fadeIn();
			    $("#fakeDiv").hide();
			    $.unblockUI();
			}
			});
			
			
			
			if (document.all) {
				core.mailto = 'mailto:?SUBJECT=' + (core.subject) + '&BODY=' + (core.body);
			    } else {
				core.mailto = 'mailto:?SUBJECT=' + escape(core.subject) + '&BODY=' + escape(core.body);
			    }
			    $('#emailPage').attr('href', core.mailto);
			    
			    
				    
				    //standingsNav();
		}),
     vote: function(userID,schoolID,c,cf) {
    	 $.post('addvote.php', {'userID' : escape(userID), 'schoolID' : escape(schoolID), c:  c, cf: cf},
    	            function(data) {
    		 			$.unblockUI();
    	                if (data == "success") {
    	                  window.location = "success.php?userID="+userID+"&schoolID="+schoolID;
    	                }
    	                else if(data =="captcha")
    	                {
			    if(typeof Recaptcha !== 'undefined')
    	                    {javascript:Recaptcha.reload();}
    	                    $("#errorDiv").html("Please make sure the captcha is entered correctly").fadeIn();
    	                }
    	                else if(data == "iperror")
    	                {
		                    $("#errorDiv").html("Voting is restricted to Continental US IP addresses only").fadeIn();
    	                }
    	                else {
    	                	window.location = "error.php";
    	                } 
    	            });
    }
}
