/**
 * @author GVD
 */
 
 	
	
	function goNav(e) {
		var myName = document.getElementById("username").value;
		var book = this.id ;
		document.location.href = book + "?username=" + myName;
	}
	
	function playGame(e) {
		var myShow = this.className; 
		//alert(myShow.className);
		switch(myShow){
			case "oscars": 
				var myGame = window.open("/AwardShowMania/oscar_08.php", "Oscars_2009", "height=500,width=650,scrollbars=yes");
				myGame.focus();
				break;
			case "globes":
				window.open();
				break;
		}
	}
	
	function showPicks(e) {
		var myOscarPicks = window.open("/AwardShowMania/oscarUserChoices.php", "My Oscar Picks", "height=500,width=750,scrollbars=yes");
				myOscarPicks.focus();
	}
	
	function showMyPicks(e) {
		var myOscarChoices = window.open("/AwardShowMania/oscar_user_changes_08.php", "My Oscar Winners", "height=500,width=750,scrollbars=yes");
				myOscarChoices.focus();
	}
	
	
	var navButtons = ["oscarsHomePage_2.php", "awardShowMania_index.php"];
	
	YAHOO.util.Event.addListener(navButtons, "click", goNav);
	
	YAHOO.util.Event.addListener("playGameButton", "click", playGame);
	
	YAHOO.util.Event.addListener("viewPicksButton", "click", showPicks);
	
	YAHOO.util.Event.addListener("changePicksButton", "click", showMyPicks);
	
	var callback = {success:signUpSuccess, failure:signUpFailure};
	
	var callback2 = {success:logInSuccess, failure:logInFailure};
	
	function signUp() {
		var email = $('username').value;
		var myPass = $('password').value;			
		if ($('join').checked) {			
			var myName = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
				if (myName.test(email)) {					
					var postData = "username="+email+"&password="+myPass;
					var transaction = YAHOO.util.Connect.asyncRequest('POST', '/AwardShowMania/award_sign_up.php', callback, postData);
					return email, myPass;
		} else {
				alert("You must enter a valid e-mail address as your username. And don't worry, we won't sell or distribute your e-mail to anyone else.");
		} }
		
		if($('log').checked) {
			postData = "username="+email+"&password="+myPass;
			transaction = YAHOO.util.Connect.asyncRequest('POST', '/AwardShowMania/log_in_check.php', callback2, postData); 
		}  	
	}
	
	function signUpSuccess(o) {
		if (o.responseText == "You have successfully signed up as a user for Award Show Mania - enjoy!") { 
			$('termsAgree').checked = true;
			alert(o.responseText);
		} else {
			alert(o.responseText);
		}		
	}
	
	
	function signUpFailure(o) {	
		alert("Something has gone wrong. Please try again.");		
	}
	
	function logInSuccess(o) {
		if (o.responseText == "We can't locate you in our user database. Please click the 'join' button and enter an e-mail address and password.") { 			
			alert(o.responseText);
		} else {
			$('termsAgree').checked = true;
			alert(o.responseText);
		}		
	}
	
	
	function logInFailure() {	
		alert("Something has gone wrong. Please try again.");		
	}
	
	/*function highScoresTable() {
		myRow = document.createElement('tr');
		document.getElementById('highScoresTable').attachElement('myRow');
		
		myHeader = document.createElement('th');
		myHeader.setAttribute('colspan', 4);
		myHeader.textNode = "Recent High Scores"
		myRow.attachElement('myHeader');
		
			//for (p=0;p<7;p++) {}
			
	}*/
				
		
