$(document).ready(init);

function init(){

	$('a[href*="https://resnet.paragoncasinoresort.com/CGI-BIN/LANSAWEB?procfun inquiry icpin04 PC1"]').attr("href","https://resnet.paragoncasinoresort.com/CGI-BIN/LANSAWEB?procfun+inquiry+icpin04+PC1");
	$('a[href*="https://resnet.paragoncasinoresort.com/CGI-BIN/LANSAWEB?procfun inquiry icpin04 RV1"]').attr("href","https://resnet.paragoncasinoresort.com/CGI-BIN/LANSAWEB?procfun+inquiry+icpin04+RV1");
	$('a[href*="https://resnet.paragoncasinoresort.com/CGI-BIN/LANSAWEB?PROCFUN RN RESNET pc1 FUNCPARMS UP(A2560):;;?/"]').attr("href","https://resnet.paragoncasinoresort.com/CGI-BIN/LANSAWEB?PROCFUN+RN+RESNET+pc1+FUNCPARMS+UP(A2560):;;?/");
	$('a[href*="https://resnet.paragoncasinoresort.com/CGI-BIN/LANSAWEB?PROCFUN RN RESNET rv1 FUNCPARMS UP(A2560):;;?/"]').attr("href","https://resnet.paragoncasinoresort.com/CGI-BIN/LANSAWEB?PROCFUN+RN+RESNET+rv1+FUNCPARMS+UP(A2560):;;?/");

	$("#resnetForm").validate({
		rules: {
			submitHandler:onValid,
			checkIn: {
				required: true,
				date: true
			},
			checkOut: {
				required: true,
				date: true
			}
		},
		submitHandler: onValid
	});


	$("#checkAvailBtn").click(onReservSubmit);
	$("#checkIn").datepicker({ dateFormat: 'mm/dd/yy' });
	
	// for the Table Games page:
	$(".gameDetail").hide();
	$(".gameDetail").first().show();

	$("#gameSelect").change(onGameSelectChange);
}

// for the Table Games page:
function onGameSelectChange() {
	var selectedGame = "#" + $(this).val();
	$(".gameDetail").hide();
	$(selectedGame).fadeIn();
}



function onReservSubmit(e){
	$("#resnetForm").submit();

	e.preventDefault();
}

function onValid(e){

	var promo = $("#resnetForm #promoCode").val();
	var checkIn = $("#resnetForm #checkIn").val();
	var nights = $("#resnetForm #nights").val();
	var adults = $("#resnetForm #adults").val();
	var kids = $("#resnetForm #children").val();

	checkInArray = checkIn.split("/");
	checkInArray[2] = (checkInArray[2].length == 4) ? checkInArray[2].substr(2) : checkInArray[2];
	checkIn = checkInArray[0] + checkInArray[1] + checkInArray[2];


	var resURL = "https://resnet.paragoncasinoresort.com/cgi-bin/lansaweb?procfun+rn+resnet+pc1+funcparms+up%28a2560%29:;"
	resURL += (promo) ? promo + ";" : ";";
	resURL += checkIn + ";";
	resURL += nights + ";";
	resURL += adults + ";";
	resURL += kids + ";?/";

	document.location.href = resURL;
}

