// doorman_ALL.js -- js functions controlling entering user prefs

// ####################################################
// #                                                  #
// #                     FUNCTIONS                    #
// #                                                  #
// ####################################################

// ###########################################
// #               index.php                 #
// ###########################################

function pageFadeIn(element) { // fades in content
	$(element).hide();
	$(element).fadeIn('slow');
	return false;
}

// ###########################################
// #               login.php                 #
// ###########################################

function validateLogin() { // client validation of login input
	$("#login form").submit(function(event) { 
		var email = $("#email");
		var emailVal = email.val();
		var pass = $("#pass");
		var passVal = pass.val();
		
		// trim the input
		var emailVal = emailVal.replace(/^\s+|\s+$/g, '');
		var passVal = passVal.replace(/^\s+|\s+$/g, '');
		
		var isEmail = /^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$/; // validates email, disregard jslint rec re unescaped '-'
		var errorMsg = $("p.error");

		$(errorMsg).remove();
		
		if(passVal === "") {
			$(pass).before('<p class="error">Please enter your password</p>');
			event.preventDefault();
		}
		if(emailVal === "") {
			$(email).before('<p class="error">Please enter your email</p>');
			event.preventDefault();
		}		
		else if(!isEmail.test(emailVal)) {
			$(email).before('<p class="error">Please enter a valid email</p>');
			event.preventDefault();
		}
	});	
}

// ###########################################
// #           forgot_password.php           #
// ###########################################

function validateForgotPass() { // client validation of login input
	$("#forgotPass form").submit(function(event) { 
		var email = $("#email");
		var emailVal = email.val();
		
		// trim the input
		var emailVal = emailVal.replace(/^\s+|\s+$/g, '');
		
		var isEmail = /^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$/; // validates email, disregard jslint rec re unescaped '-'
		var errorMsg = $("p.error");

		$(errorMsg).remove();
		
		if(emailVal === "") {
			$(email).before('<p class="error">Please enter your email</p>');
			event.preventDefault();
		}		
		else if(!isEmail.test(emailVal)) {
			$(email).before('<p class="error">Please enter a valid email</p>');
			event.preventDefault();
		}
	});	
}

// ###########################################
// #               register.php              #
// ###########################################

function validateSignup() { // client validation of register input
	$("#register form").submit(function(event) { 
		var regEmail = $("#email");
		var regEmailVal = regEmail.val();
		var pass1 = $("#pass1");
		var pass1Val = pass1.val();
		var pass2 = $("#pass2");
		var pass2Val = pass2.val();
		
		// trim the input
		var regEmailVal = regEmailVal.replace(/^\s+|\s+$/g, '');
		var pass1Val = pass1Val.replace(/^\s+|\s+$/g, '');
		
		var isEmail = /^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$/; // validates email, disregard jslint rec re unescaped '-'
		var errorMsg = $("p.error");

		$(errorMsg).remove();
		
		if(pass1Val === "") {
			$(pass1).before('<p class="error">Please enter a password</p>');
			event.preventDefault();
		}
		else if(pass1Val.length < 4) {
			$(pass1).before('<p class="error">Minimum password length is 4 characters</p>');
			event.preventDefault();
		}
		else if(pass1Val !== pass2Val) {
			$(pass2).before('<p class="error">Your passwords don\'t match</p>');
			event.preventDefault();
		}
		if(regEmailVal === "") {
			$(regEmail).before('<p class="error">Please enter your email</p>');
			event.preventDefault();
		}		
		else if(!isEmail.test(regEmailVal)) {
			$(regEmail).before('<p class="error">Please enter a valid email</p>');
			event.preventDefault();
		}
	});	
}

// ###########################################
// #               contact.php               #
// ###########################################

function validateContact() { // client validation of register input
	$("#contact form").submit(function(event) { 
		var conEmail = $("#email");
		var conEmailVal = conEmail.val();
		var name = $("#name");
		var nameVal = $("#name").val();
		var msg = $("#message");
		var msgVal = msg.val();
		
		// trim the input
		var conEmailVal = conEmailVal.replace(/^\s+|\s+$/g, '');
		
		var isEmail = /^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$/; // validates email, disregard jslint rec re unescaped '-'
		var errorMsg = $("p.error");
		
		$(errorMsg).remove();
		
		if(nameVal === "") {
			$(name).before('<p class="error">Please enter your name</p>');
			event.preventDefault();
		}
		
		if(conEmailVal === "") {
			$(conEmail).before('<p class="error">Please enter your email</p>');
			event.preventDefault();
		}		
		else if(!isEmail.test(conEmailVal)) {
			$(conEmail).before('<p class="error">Please enter a valid email</p>');
			event.preventDefault();
		}
		
		if(msgVal === "") {
			$(msg).before('<p class="error">Please enter a message</p>');
			event.preventDefault();
		}
		
		
	});	
}

// ###########################################
// #           change_password.php           #
// ###########################################

function validateChangePass() { // client validation of login input
	$("#changePass form").submit(function(event) { 

		var pass1 = $("#pass1");
		var pass1Val = pass1.val();
		var pass2 = $("#pass2");
		var pass2Val = pass2.val();

		// trim the input
		var pass1Val = pass1Val.replace(/^\s+|\s+$/g, '');

		var errorMsg = $("p.error");

		$(errorMsg).remove();

		if(pass1Val === "") {
			$(pass1).before('<p class="error">Please enter a password</p>');
			event.preventDefault();
		}
		else if(pass1Val.length < 4) {
			$(pass1).before('<p class="error">Password minimum is 4 characters</p>');
			event.preventDefault();
		}
		else if(pass1Val.length > 20) {
			$(pass1).before('<p class="error">Password limit is 20 characters</p>');
			event.preventDefault();
		}
		else if(pass1Val !== pass2Val) {
			$(pass2).before('<p class="error">Your passwords don\'t match</p>');
			event.preventDefault();
		}
		
	});	
}

// ###########################################
// #               prefs.php                 #
// ###########################################

function resetAll() { // clears prefs entry form, hands entry table
	$(".handsPref tr td").removeClass("fold");
	$("#betEntry select").attr("disabled", "disabled").val("");
	$("#firstChoice").removeAttr("disabled").val("");
	$("#hand_001").val("");
	$("#positions input").val(["","","",""]); // this checkbox command appears to slow things down...
}

function cleanUp() { // cleans up prefs entry textarea
	
	// clean up trailing commas
	var dirtyText = $("#hand_001").val();
	var cleanText = dirtyText.replace(/\, $/, "");
	$("#hand_001").val(cleanText);
	
	// clean up double commas
	var dirtyText = $("#hand_001").val();
	var cleanText = dirtyText.replace(/\, ,/, ",");
	$("#hand_001").val(cleanText);
	
	// clean up leading commas
	var dirtyText = $("#hand_001").val();
	var cleanText = dirtyText.replace(/^\, /, "");
	$("#hand_001").val(cleanText);		
}

function handClick(source, target) { // populates "hands" textarea with hand values
	$(source).click(function(){	// default click function for td's
		var sourceText = $(this).text();
		if (!$(this).hasClass("fold")) { // if the td DOESN'T have the class "fold" (i.e., is UNSELECTED)
			if (!$(target).val()){ // if the hand textarea IS empty
				$(target).val(sourceText); // set the hand textarea value to the td text
			}
			else	{ // if the textarea ISN'T empty
				var idString = $(target).val() + ", " + sourceText; // concatenate a ", " to the end of the hand textarea
				$(target).val(idString);
			}	
		}
		else { // if the td HAS the class "fold" (i.e., is already SELECTED)
			var inputText = $(target).val();
			var modInputText = inputText.replace(sourceText, ""); // replace the td text in the textarea with a space
			$(target).val(modInputText);
		}
		cleanUp(); // clean up extraneous commas, spaces
		$(this).toggleClass("fold");
	});	
}

function eraseText(tdText) { // erases hand values from prefs entry textarea
	
	// replace the td text in the textarea with a space
	var inputText = $("#hand_001").val();
	var modInputText = inputText.replace(tdText, ""); 
	$("#hand_001").val(modInputText);
	
	// clean up extraneous commas, spaces
	cleanUp(); 
}

function linkClick(hands, linkText) { // selects/deselects individual hand table values		
	var i = 0;
	var handTd = $(".handsPref tr td");
	
	$("#shortcuts a:contains("+linkText+")").click(function() {
		if (i%2 === 0) {
			for (var j = 0; j < hands.length; j++) {
				handTd.each(function() {
					if($(this).text() == hands[j]) {
						var handText = $(this).text();
						eraseText(handText);
						$(this).removeClass("fold").click();
					}
				});
			}
		}
		else {
			for (var j = 0; j < hands.length; j++) {
				handTd.each(function() {
					if($(this).text() == hands[j]) {
						var handText = $(this).text();
						eraseText(handText);
						$(this).removeClass("fold");
					}
				});
			}
		}
		i++;
		
		return false;
	});
}

function prTopLink(percent, linkText) { // selects/deselects pokerroom top x% values
	var i = 0;
	var handTd = $("table.handsPref tr td");
	
	$("#shortcuts a:contains("+linkText+")").click(function() {
		if (i%2 === 0) {
			handTd.each(function() {
				var klass = this.className;		
				var pattern = /\d?\d?\d/g; // regex id's all numbers in the class name		
				var tops = klass.match(pattern); // array of all the matches	
				var pr = parseInt(tops[0], 10);
				
				if (pr <= (1.7 * percent)) {
					var handText = $(this).text();
					eraseText(handText);
					$(this).removeClass("fold").click();
				}
			});				
		}
		else {
			handTd.each(function() {
				var klass = this.className;		
				var pattern = /\d?\d?\d/g; // regex id's all numbers in the class name		
				var tops = klass.match(pattern); // array of all the matches	
				var pr = parseInt(tops[0], 10);
				
				if (pr <= (1.7 * percent)) {
					var handText = $(this).text();
					eraseText(handText);
					$(this).removeClass("fold");
				}
			});				
		}
		i++;
		return false;
	});	
}

function skTopLink(percent, linkText) { // selects/deselects sklansky top x% values
	var i = 0;
	var handTd = $("table.handsPref tr td");
	
	$("#shortcuts a:contains("+linkText+")").click(function() {
		if (i%2 === 0) {
			handTd.each(function() {
				var klass = this.className;		
				var pattern = /\d?\d?\d/g; // regex id's all numbers in the class name		
				var tops = klass.match(pattern); // array of all the matches	
				var sk = parseInt(tops[1], 10);
				
				if (sk <= (1.7 * percent)) {
					var handText = $(this).text();
					eraseText(handText);
					$(this).removeClass("fold").click();
				}
			});				
		}
		else {
			handTd.each(function() {
				var klass = this.className;		
				var pattern = /\d?\d?\d/g; // regex id's all numbers in the class name		
				var tops = klass.match(pattern); // array of all the matches	
				var sk = parseInt(tops[1], 10);
				
				if (sk <= (1.7 * percent)) {
					var handText = $(this).text();
					eraseText(handText);
					$(this).removeClass("fold");
				}
			});				
		}
		i++;
		return false;
	});	
}

function pptTopLink(percent, linkText) { // selects/deselects propokertools top x% values
	var i = 0;
	var handTd = $("table.handsPref tr td");
	
	$("#shortcuts a:contains("+linkText+")").click(function() {
		if (i%2 === 0) {
			handTd.each(function() {
				var klass = this.className;		
				var pattern = /\d?\d?\d/g; // regex id's all numbers in the class name		
				var tops = klass.match(pattern); // array of all the matches	
				var ppt = parseInt(tops[2], 10);
				
				if (ppt <= (1.7 * percent)) {
					var handText = $(this).text();
					eraseText(handText);
					$(this).removeClass("fold").click();
				}
			});				
		}
		else {
			handTd.each(function() {
				var klass = this.className;		
				var pattern = /\d?\d?\d/g; // regex id's all numbers in the class name		
				var tops = klass.match(pattern); // array of all the matches	
				var ppt = parseInt(tops[2], 10);
				
				if (ppt <= (1.7 * percent)) {
					var handText = $(this).text();
					eraseText(handText);
					$(this).removeClass("fold");
				}
			});				
		}
		i++;
		return false;
	});	
}

function betChoice() { // begin betChoice(), function that determines behavior of bet entry menus...
	
	var allSelect = $("#betEntry select");
	var raise = $("#firstPercent");
	var limp = $("#secondPercent");
	var fold = $("#thirdPercent");
	var notRaise = $("#betEntry select:not(#firstPercent)");
	var limpOption = $("#secondPercent option");
	var foldOption = $("#thirdPercent option");
	

	function betInit() { // series of init functions...
		allSelect.attr("disabled", "disabled").val("0");
		raise.removeAttr("disabled").val("blank");
	}
	
	function raiseInit() {
		notRaise.attr("disabled", "disabled").val("0");
	}

	// end series of init functions
		
	betInit(); // initialize betChoice()

	raise.change(function() {
		raiseInit();
		var raiseVal = raise.val();
		var limpRemainder = 100 - parseInt(raiseVal, 10);		

		limp.removeAttr("disabled");
		limpOption.each(function() {
			if ($(this).val() > limpRemainder) {
				$(this).hide();
			}
			else {
				$(this).show();
			}
		});
		limp.val(limpRemainder);
		fold.removeAttr("disabled");
		foldOption.each(function() {
			if ($(this).val() > 0) {
				$(this).hide();
			}
			else {
				$(this).show();
			}
		});
	}); // end raise change function
	
	limp.change(function() {
		fold.attr("disabled", "disabled");
		
		var raiseVal = raise.val();
		var limpVal = limp.val();
		var foldRemainder = 100 - (parseInt(raiseVal, 10) + parseInt(limpVal, 10));
		
		fold.removeAttr("disabled");
		foldOption.each(function() {
			if ($(this).val() != foldRemainder) {
				$(this).hide();
			}
			else {
				$(this).show();
			}
		});
		if(foldRemainder < 0) { // deal with Safari not hiding the option vals
			fold.val("0");
		}
		else {
			fold.val(foldRemainder);			
		}			
	});
			
} // end betChoice() code

var eraseFadeIn = function() { // used by jqm onShow for erase prefs dialog
	$("#erase").fadeIn();
};

// ###########################################
// #               start.php                 #
// ###########################################

function handsFadeIn() { // fades in hands table
	$("table.hands").fadeIn();
}

function compare() { // logic behind whether to raise/limp/fold
	var rNum = Math.ceil(100*Math.random()); // all cells have same rNum (place inside inner function to give cells different rNum)
	$("table.hands tr td").each(function() {
		var klass = this.className;		
		var pattern = /\d?\d?\d/g; // regex id's all numbers in the class name		
		var bet = klass.match(pattern); // array of all the matches	
		var call = parseInt(bet[1], 10);
		var fold = parseInt(bet[2], 10);
		var cThresh = fold;
		var rThresh = fold + call;
		
		// $(this).text(rNum); // to test that it's working when each cell has different rNum
		$("#randomNumber").text("The random number is: " + rNum);

		if (rNum > rThresh) {
			if ($(this).hasClass("pair")) {
				$(this).removeClass("fold").removeClass("pairCall").removeClass("pairRaise").addClass("pairRaise");
			}
			else if ($(this).hasClass("suited")) {
				$(this).removeClass("fold").removeClass("suitedCall").removeClass("suitedRaise").addClass("suitedRaise");
			}
			else {
				$(this).removeClass("fold").removeClass("offsuitCall").removeClass("offsuitRaise").addClass("offsuitRaise");
			}
		}
		else if (rNum > cThresh) {
			if ($(this).hasClass("pair")) {
				$(this).removeClass("fold").removeClass("pairCall").removeClass("pairRaise").addClass("pairCall");
			}
			else if ($(this).hasClass("suited")) {
				$(this).removeClass("fold").removeClass("suitedCall").removeClass("suitedRaise").addClass("suitedCall");
			}
			else {
				$(this).removeClass("fold").removeClass("offsuitCall").removeClass("offsuitRaise").addClass("offsuitCall");
			}
		}
		else {		
			$(this).removeClass("fold").removeClass("pairCall").removeClass("pairRaise").removeClass("suitedCall").removeClass("suitedRaise").removeClass("offsuitCall").removeClass("offsuitRaise").addClass("fold");
		}
	});
}

function handsFadeOut() { // fades out hands table
	$("table.hands").fadeOut(); // smoother in FF3 on mac w/no argument (e.g., "slow")
}

function sheBang(update) { // hands table refresh logic
	var	sheBangFadeOut = update - 750;
	compare();
	handsFadeIn(); // fade in completes afer compare is done (takes longer)
	setTimeout(handsFadeOut, sheBangFadeOut); // fades out x seconds later
}
	
function wholeSheBang() { // the whole thing (logic + refresh + reset refresh)
	
	changeVal = $("#change_update #refresh").text(); // default is set at 30 secs	
	update = changeVal;	
	update = parseInt(update, 10);
	update = update * 1000;
	if(update < 5000) {
		update = 5000;
	}
	if(update > 120000) {
		update = 120000;
	}
	
	sheBang(update);
	
	setTimeout(wholeSheBang, update);
}

function isPosInt(value) { // determines if argument is a positive integer
	if (value === null || !value.toString().match(/^\d*$/)) {
		return false;
	}	
	return true;
}

function setRefresh() { // allows user to set refresh rate
	$("#change_update input[type='submit']").click(function() {
		var seconds = $("#change_update #change").val();
		var br = $("#change_update p:eq(0) br"); // specifically targets br's introduced before error msg's	
		var errorPara = $("#change_update p.error");
		var errorTarget = $("#change_update p:first");
		var notPosIntError = '<br /><br /><p class="error">Please enter a valid number</p>';
		var blankError = '<br /><br /><p class="error">Please enter a number</p>';
		var tooShortError = '<br /><br /><p class="error">Refresh minimum is 5 seconds</p>';
		var tooLongError = '<br /><br /><p class="error">Refresh maximum is 10 minutes (600 seconds)</p>';
	
		if(!isPosInt(seconds)) {
			errorPara.remove();
			br.remove();
			errorTarget.append(notPosIntError);
			return false;
		}
	
		if(seconds === "") {
			errorPara.remove();
		    br.remove();
			errorTarget.append(blankError);
			return false;
		}
		
		seconds = parseInt(seconds, 10);
		
		if (seconds < 5) {
			errorPara.remove();
			br.remove();
			errorTarget.append(tooShortError);
			return false;
		}
		if(seconds > 600) {
			errorPara.remove();
			br.remove();
			errorTarget.append(tooLongError);
			return false;
		}
		$("#change_update #refresh").text(seconds);
		
		errorPara.remove();
		br.remove(); // kludge -- really shouldn't have <br /> tags in error msgs...
		return false;
	});
}

var changeUpdateFadeIn = function() { // used by jqm onShow for resetting refresh dialog
	$("#change_update").fadeIn();
};

var myClose = function(hash) {
	hash.w.fadeOut('2000', function() {
		hash.o.remove();
	});
};

function showViaKeypress(element_id) { // shows a given element and hides all others
	$(".container").css("display","none");
	$(element_id).show();
}

function showViaLink(array) { // shows proper DIV depending on link 'href'
	array.each(function(i) {	
		$(this).click(function() {
			var target = $(this).attr("href");
			$(".container").css("display","none");
			$(target).show();
			switch(target) {
				case '#early': 	$("#start_nav ul li").removeClass();
								$("#start_nav ul li:first").addClass("early");
								break;
				case '#mid': 	$("#start_nav ul li").removeClass();
								$("#start_nav ul li:eq(1)").addClass("mid");
								break; 
				case '#late': 	$("#start_nav ul li").removeClass();
								$("#start_nav ul li:eq(2)").addClass("late");
								break;
				case '#sb': 	$("#start_nav ul li").removeClass();
								$("#start_nav ul li:eq(3)").addClass("sb");
								break;
			}
		});
	});
}

// ####################################################
// #                                                  #
// #                      ON LOAD                     #
// #                                                  #
// ####################################################

$(document).ready(function(){
	
// ###########################################
// #               index.php                 #
// ###########################################

	pageFadeIn("#content"); // fades in the content of every page
	
	$("#masthead ul a").each(function(){ // adds the ".selected" to the nav tab indicating the current page
		var thisPage = window.location.pathname.split( '/' );
		var thisLink = thisPage[1]; // the thisPage[] value sometimes needs tweaking...
		var matchLink = $(this).attr("href");
		if (matchLink == thisLink) {
			$(this).addClass("selected");
		}
		else if(thisLink == 'forgot_password.php') { // selects the Login tab if on forgot_password.php
			$("#masthead ul a[href='login.php']").addClass("selected");
		}
		else if(thisLink == 'change_password.php') { // selects the Login tab if on forgot_password.php
			$("#masthead ul a[href='user_home.php']").addClass("selected");
		}
		else if(thisLink === '') {
			$("#masthead ul a[href='index.php']").addClass("selected");
		}
	});
	
// ###########################################
// #              register.php               #
// ###########################################

	$("#register input:first").focus(); // focus first text input on register form
	validateSignup();
	
// ###########################################
// #               login.php                 #
// ###########################################

	validateLogin(); // validate user login
	$("#login input:first").focus(); // focus first text input on login form
	
// ###########################################
// #           forgot_password.php           #
// ###########################################	
	
	validateForgotPass(); // validate forgot pass

// ###########################################
// #               contact.php               #
// ###########################################

	validateContact(); // validate user login
	$("#contact input:first").focus(); // focus first text input on login form
	
// ###########################################
// #                 faq.php                 #
// ###########################################
   
	$("#faq").accordion({ // accordion for FAQ
		header: "h2",
		active: false  
	});
	
// ###########################################
// #           change_password.php           #
// ###########################################

	validateChangePass(); // validate change pass
	
// ###########################################
// #               prefs.php                 #
// ###########################################
	
	resetAll(); // clears prefs form on page load
		
	$(function() { // disables text select on the hands entry table
	    $(".handsPref tr td").disableTextSelect(); // and enableTextSelect() to re-enable it again
	});
	
	$("#clearForm").click(function(){ // clears hands table/bet menus when you hit reset button
		resetAll();
		betChoice();
		return false;
	});
	
	$("ul.sf-menu").superfish();// superfish for quick hand group selection links menus
	
	handClick(".handsPref tr td", "#hand_001"); // for clicking individual hands table cells
	
	
	// quick hand group selection links behavior -- generic hands
	var prs = ["AA", "KK", "QQ", "JJ", "TT", "99", "88", "77", "66", "55", "44", "33", "22"];	
	linkClick(prs, 'Pairs');
	
	var bways = ["AKs", "AKo", "AQs", "AQo", "AJs", "AJo", "ATs", "ATo", "KQs", "KQo", "KJs", "KJo", "KTs", "KTo", "QJs", "QJo", "QTs", "QTo"];
	linkClick(bways, 'Broadways');
	
	var axs = ["AKs", "AQs", "AJs", "ATs", "A9s", "A8s", "A7s", "A6s", "A5s", "A4s", "A3s", "A2s"];
	linkClick(axs, 'Suited Aces');
	
	var axo = ["AKo", "AQo", "AJo", "ATo", "A9o", "A8o", "A7o", "A6o", "A5o", "A4o", "A3o", "A2o"];
	linkClick(axo, 'Offsuit Aces');
	
	var kxs = ["KQs", "KJs", "KTs", "K9s", "K8s", "K7s", "K6s", "K5s", "K4s", "K3s", "K2s"];
	linkClick(kxs, 'Suited Kings');
	
	var kxo = ["KQo", "KJo", "KTo", "K9o", "K8o", "K7o", "K6o", "K5o", "K4o", "K3o", "K2o"];
	linkClick(kxo, 'Offsuit Kings');
	
	var qxs = ["QJs", "QTs", "Q9s", "Q8s", "Q7s", "Q6s", "Q5s", "Q4s", "Q3s", "Q2s"];
	linkClick(qxs, 'Suited Queens');
	
	var qxo = ["QJo", "QTo", "Q9o", "Q8o", "Q7o", "Q6o", "Q5o", "Q4o", "Q3o", "Q2o"];
	linkClick(qxo, 'Offsuit Queens');
	
	var scs = ["JTs", "T9s", "98s", "87s", "76s", "65s", "54s", "43s", "32s"];
	linkClick(scs, 'Suited Connectors');
		
	var s1g = ["J9s", "T8s", "97s", "86s", "75s", "64s", "53s", "42s"];
	linkClick(s1g, 'Suited One Gaps');
		
	var s2g = ["Q9s", "J8s", "T7s", "96s", "85s", "74s", "63s", "52s"];
	linkClick(s2g, 'Suited Two Gaps');
			
	var ocs = ["JTo", "T9o", "98o", "87o", "76o", "65o", "54o", "43o", "32o"];
	linkClick(ocs, 'Offsuit Connectors');
			
	var o1g = ["J9o", "T8o", "97o", "86o", "75o", "64o", "53o", "42o"];		
	linkClick(o1g, 'Offsuit One Gaps');
	
	var o2g = ["Q9o", "J8o", "T7o", "96o", "85o", "74o", "63o", "52o"];		
	linkClick(o2g, 'Offsuit Two Gaps');
	
	// quick hand group selection links behavior -- pokerroom top x%
	prTopLink(5, 'Pokerroom Top 5%');
    	prTopLink(10, 'Pokerroom Top 10%');
	prTopLink(15, 'Pokerroom Top 15%');
	prTopLink(20, 'Pokerroom Top 20%');
	prTopLink(25, 'Pokerroom Top 25%');
	prTopLink(30, 'Pokerroom Top 30%');
	prTopLink(40, 'Pokerroom Top 40%');
	prTopLink(50, 'Pokerroom Top 50%');
	prTopLink(60, 'Pokerroom Top 60%');
	prTopLink(70, 'Pokerroom Top 70%');
	prTopLink(80, 'Pokerroom Top 80%');
	prTopLink(90, 'Pokerroom Top 90%');
	prTopLink(100, 'Pokerroom Top 100%');
	
	// quick hand group selection links behavior -- sklansky top x%
	skTopLink(5, 'Sklansky/Karlson Top 5%');
	skTopLink(10, 'Sklansky/Karlson Top 10%');
	skTopLink(15, 'Sklansky/Karlson Top 15%');
	skTopLink(20, 'Sklansky/Karlson Top 20%');
	skTopLink(25, 'Sklansky/Karlson Top 25%');
	skTopLink(30, 'Sklansky/Karlson Top 30%');
	skTopLink(40, 'Sklansky/Karlson Top 40%');
	skTopLink(50, 'Sklansky/Karlson Top 50%');
	skTopLink(60, 'Sklansky/Karlson Top 60%');
	skTopLink(70, 'Sklansky/Karlson Top 70%');
	skTopLink(80, 'Sklansky/Karlson Top 80%');
	skTopLink(90, 'Sklansky/Karlson Top 90%');
	skTopLink(100, 'Sklansky/Karlson Top 100%');
	
	// quick hand group selection links behavior -- propokertools top x%
	pptTopLink(5, 'ProPokerTools.com Top 5%');
	pptTopLink(10, 'ProPokerTools.com Top 10%');
	pptTopLink(15, 'ProPokerTools.com Top 15%');
	pptTopLink(20, 'ProPokerTools.com Top 20%');
	pptTopLink(25, 'ProPokerTools.com Top 25%');
	pptTopLink(30, 'ProPokerTools.com Top 30%');
	pptTopLink(40, 'ProPokerTools.com Top 40%');
	pptTopLink(50, 'ProPokerTools.com Top 50%');
	pptTopLink(60, 'ProPokerTools.com Top 60%');
	pptTopLink(70, 'ProPokerTools.com Top 70%');
	pptTopLink(80, 'ProPokerTools.com Top 80%');
	pptTopLink(90, 'ProPokerTools.com Top 90%');
	pptTopLink(100, 'ProPokerTools.com Top 100%');
	
	$("#shortcuts li.current a").click(function() { // disables default behavior when clicking hand group links
		return false;
	});
	
	// end quick hand group selection	
	
	betChoice(); // contextual menus for raise/fold/call %'s
	
	$("#prefsEntry").submit(function(event) { // client validation of prefs input
		var hands = $("#hand_001");
		var handsLabel = $("h2.label:eq(0)");
		var betLabel = $("h2.label:eq(1)");
		var posLabel = $("h2.label:eq(2)");
		var raise = $("#firstPercent").val();
		var limp = $("#secondPercent").val();
		var fold = $("#thirdPercent").val();
		var totalBet = parseInt(raise, 10) + parseInt(limp, 10) + parseInt(fold, 10);
		var pos = $("#positions input:checked").val();

		var errorMsg = $("p.error");
		
		$(errorMsg).remove();

		if(hands.val() === "") {
			$(handsLabel).after('<p class="error">Please select at least one hand</p>');
			event.preventDefault();
		}
		
		if(raise == 'blank') {
			$(betLabel).after('<p class="error">Please select a bet percentage</p>');
			event.preventDefault();
		}
		
		if(totalBet > 100) {
			$(betLabel).after('<p class="error">Your total bet % is more than 100%</p>');
			event.preventDefault();
		}
		
		if(totalBet < 100) {
			$(betLabel).after('<p class="error">Your total bet % is less than 100%</p>');
			event.preventDefault();
		}
		
		if(!pos) { // per jslint rec (instead of 'pos == null' ('pos === null' doesn't work))
			$(posLabel).after('<p class="error">Please select a position</p>');
			event.preventDefault();
		}
	});
	
	$("table.striped tr:nth-child(odd)").addClass("alt"); // adds striped tables to user prefs tables
	
	$('#current_settings').jqm({trigger: $("#settings_trigger")}); // current settings modal dialog
	
	$('#erase').jqm({trigger:$("#erase_trigger"), onShow: eraseFadeIn}); // erase prefs modal dialog
	
	$('#tutorial').jqm({trigger: $("#tutorial_trigger")}); // current settings modal dialog

// ###########################################
// #               start.php                 #
// ###########################################

	$(function() { // disables text select on the hands entry table
	    $(".hands tr td").disableTextSelect(); // and enableTextSelect() to re-enable it again
	});

	wholeSheBang(); // governs behavior of hands tables
	setRefresh();	// allows user to set hands table refresh rate
	
	$('#change_update').jqm({onShow: changeUpdateFadeIn, onHide: myClose}); // modal settings for refresh rate settings
	
	$(".container").css("display","none"); 	// hides all DIVs with the CLASS container
	$("#early").css("display","block");	// and displays the one with the ID 'early' only
	
	showViaLink($("#start_nav ul li a")); // makes the navigation work after all containers have been hidden
	
	$("#start_nav ul li:not(:first)").removeClass();	

	$(document).keypress(function(e) { 	// listens for any navigation keypress activity
		switch(e.which) {
			// user presses the "1"
			case 49:	showViaKeypress("#early");
						$("#start_nav ul li").removeClass();
						$("#start_nav ul li:first").addClass("early");
						break;	
						
			// user presses the "2" key
			case 50:	showViaKeypress("#mid");
						$("#start_nav ul li").removeClass();
						$("#start_nav ul li:eq(1)").addClass("mid");
						break;
						
			// user presses the "3" key
			case 51:	showViaKeypress("#late");
						$("#start_nav ul li").removeClass();
						$("#start_nav ul li:eq(2)").addClass("late");
						break;
			
			// user presses the "4" key
			case 52:	showViaKeypress("#sb");
						$("#start_nav ul li").removeClass();
						$("#start_nav ul li:eq(3)").addClass("sb");
						break;
		}
	});
	
}); // end $(document).ready