function RoomWin(theURL) { 
if (theURL == null) { theURL = 'https://reservations.mgmmirage.com/bookingengine.aspx?pid=010'; }
var winleft = (screen.width - 795) / 2;
var winUp = (screen.height - 460) / 2;
winProp = 'width=795,height=460,left='+winleft+',top='+winUp+',scrollbars=yes,resizable=yes,menubar=yes,toolbar=yes,status=yes';
Win = window.open(theURL,'roomres',winProp);
if (parseInt(navigator.appVersion) >= 4) { Win.focus(); }
}
	

function goToRes(){
	var sURL = ""
	var sArriveDate
	var iArriveMilli
	var sBAD
	var sBAM
	var sBAY
	var iRooms
	var iGuests
	var iNumNights
	var iDayToMilli = 86400000;
	var sDAY
	var sMONTH
	var sYEAR
	
	iIndex = document.all("BAD").selectedIndex;
	sBAD = document.all("BAD").options[iIndex].value;
	
	iIndex = document.all("BAM").selectedIndex;
	sBAM = parseInt(document.all("BAM").options[iIndex].value,10);
	
	iIndex = document.all("BAY").selectedIndex;
	sBAY = document.all("BAY").options[iIndex].value;
	
	if (isValidDate(sBAM + "/" + sBAD + "/" + sBAY) == true){
			sArriveDate = new Date(sBAY, sBAM -1, sBAD);
			
	var oTODAY = new Date();
	 sDAY = oTODAY.getDate();
	 sMONTH = oTODAY.getMonth();
	 sYEAR = oTODAY.getYear();
	 
	 if ((sBAY < sYEAR) || (sBAY == sYEAR && sBAM - 1 < sMONTH) || (sBAY == sYEAR && sBAM -1 == sMONTH && sDAY -1 >= sBAD)){
	 	alert(" Please select an arrival date greater than today.")
	 } 

	 else {	 
			
		iIndex = document.all("nights").selectedIndex;
		iNumNights = parseInt(document.all("nights").options[iIndex].value,10);
		iIndex = document.all("rooms").selectedIndex;
		iRooms = parseInt(document.all("rooms").options[iIndex].value,10);
		iIndex = document.all("guests").selectedIndex;
		iGuests = parseInt(document.all("guests").options[iIndex].value,10);
		sURL = "https://reservations.mgmmirage.com/bookingengine.aspx?pid=010&nights=" + iNumNights + "&ad=" + sBAM + "/" + sBAD + "/" + sBAY + "&rooms=" + iRooms + "&guests=" + iGuests;
					
		if (sURL.length != 0){
			RoomWin(sURL);
		}
		}		
		}
	else{
		alert("Invalid arrival Date");
	}
}

function isValidDate(sDate){
	var arrDate;
	var iMonth;
	var iDay;
	var iYear;
	var bError = false;
			
	arrDate = sDate.split("/");
	if (arrDate.length != 3){
		bError = true;
		}
	else{
		iMonth = parseInt(arrDate[0],10);
		iDay = parseInt(arrDate[1],10);
		iYear = parseInt(arrDate[2],10);
			
		if (isNaN(iMonth) == true ){
			bError = true;
			}
		else{
			if (!(iMonth > 0 && iMonth < 13)){
				bError = true;
			}
		}
			
		if (isNaN(iDay) == true ){
			bError = true;
		}
					
		if (isNaN(iYear) == true ){
			bError = true;
			}
		else{
			if (!(iYear >= 2000 && iYear < 2100)){
				bError = true;
			}
		}
		
		if (!bError){
			if (iMonth == 1 || iMonth == 3 || iMonth == 5 || iMonth == 7 || iMonth == 8 || iMonth == 10 || iMonth == 12){
				if (!(iDay > 0 && iDay < 32)){
					bError = true;
				}
			}
			
			if (iMonth == 4 || iMonth == 6 || iMonth == 9 || iMonth == 11){
				if (!(iDay > 0 && iDay < 31)){
					bError = true;
				}
			}
			
			if (iMonth == 2){
				var iMod = iYear % 4;
				if (iMod == 0){
					if (!(iDay > 0 && iDay < 30)){
						bError = true;
					}
					}
				else{
					if (!(iDay > 0 && iDay < 29)){
						bError = true;
					}
				}
			}
				
		}
	}
		
	return(!bError);
		
}