
//Flash Music on/off - need to rewrite flash
function setOne(){};
function setZero() {};

// DHTML Menu function 7/13/05 v2.1 - DG/RCS. Returns X & Y position used for DHTML menu.
function getElement(id) { 
return document.all ? document.all(id) : 
document.getElementById ? document.getElementById(id) : 
document.layers ? document.layers[id] : 
null; 
} 

function findx(eElement, loc)
{
	var posleft = 0;
	var iobj;
	// Handle NS 4
	if (navigator.appName=="Netscape" && parseInt(navigator.appVersion)==4)  //Navigator 4 handled separately
	{
		 iobj = document.anchors.NN.x;
		 posleft = iobj;
	} else {
	// Handle IE + NS6
  		  posleft = eElement.offsetLeft;          // initialize var to store calculations
   		 var eParElement = eElement.offsetParent;     // identify first offset parent element  
  		  while (eParElement != null)
  		  {                                            // move up through element hierarchy
   		     posleft += eParElement.offsetLeft;      // appending left offset of each parent
   		     eParElement = eParElement.offsetParent;  // until no more offset parents exist
  		  }
	}
	
	if (loc==1) {return posleft+0;} //RESERVATIONS
	else if (loc==2) {return posleft+146;} //ENTERTAINMENT
	else if (loc==3) {return posleft+288;} //AMENITIES
	else if (loc==4) {return posleft+390;} //DINING
	else if (loc==5) {return posleft+467;} //CASINO
	else if (loc==6) {return posleft+549;} //SHOPPING
	else if (loc==7) {return posleft+625;} //CONVENTIONS
	return false;
	//(document.layers)
}
function findy(eElement, loc)
{
	var postop = 0;
	var iobj;
	// Handle NS 4
	if (navigator.appName=="Netscape" && parseInt(navigator.appVersion)==4)  //Navigator 4 handled separately
	{
		 iobj = document.anchors.NN.y;
		 posleft = iobj;
	} else {
	// Handle IE + NS6
  		  postop = eElement.offsetTop;          // initialize var to store calculations
   		 var eParElement = eElement.offsetParent;     // identify first offset parent element  
  		  while (eParElement != null)
  		  {                                            // move up through element hierarchy
   		     postop += eParElement.offsetTop;      // appending left offset of each parent
   		     eParElement = eParElement.offsetParent;  // until no more offset parents exist
  		  }
	}
	
	if (loc==1) {return postop+11;} // RESERVATIONS
	else if (loc==2) {return postop+11;} //ENTERTAINMENT
	else if (loc==3) {return postop+11;} //AMENITIES
	else if (loc==4) {return postop+11;} //DINING
	else if (loc==5) {return postop+11;} //CASINO
	else if (loc==6) {return postop+11;} //SHOPPING
	else if (loc==7) {return postop+11;} //CONVENTIONS
	return false;
	//(document.layers)
}

//Macromedia Functions
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function SetStatusbar(msg){
	window.status=msg;
	return true;
}


// Center Pop Window - 10.13.03 RCS - v2.0
function winBRopen(theURL, Name, popW, popH, scroll, resize, menu, stat, tool) { 
var winleft = (screen.width - popW) / 2;
var winUp = (screen.height - popH) / 2;
winProp = 'width='+popW+',height='+popH+',left='+winleft+',top='+winUp+',scrollbars='+scroll+',resizable='+resize+',menubar='+menu+',status='+stat+',toolbar='+tool+''
Win = window.open(theURL, Name, winProp)
if (parseInt(navigator.appVersion) >= 4) { Win.focus(); }
}

// Center Pop Window
// <a href="javascript:popWin('page.aspx','sweepstakes','700','500','scrollbars=yes,resizable=yes,status=yes,toolbar=yes');">Link</a>
function popWin(theURL, winName, popW, popH, features) { 
var winleft = (screen.width - popW) / 2;
var winUp = (screen.height - popH) / 2;
winProp = 'width='+popW+',height='+popH+',left='+winleft+',top='+winUp+',resizable=yes,status=yes,'+features;
Win = window.open(theURL,winName,winProp);
if (parseInt(navigator.appVersion) >= 4) { Win.focus(); }
}

// Center Room Window
function RoomWin(theURL) { 
if (theURL == null) { theURL = 'https://secure02.mgm-mirage.com/ezbook/index.aspx?prop=bay'; }
var winleft = (screen.width - 800) / 2;
var winUp = (screen.height - 460) / 2;
winProp = 'width=800,height=460,left='+winleft+',top='+winUp+',scrollbars=yes,resizable=yes,menubar=yes,toolbar=yes,status=yes';
Win = window.open(theURL,'resWin',winProp);
if (parseInt(navigator.appVersion) >= 4) { Win.focus(); }
}

// Center Promo Room Window w/ Self Close
function PromoRoomWin(theURL) { 
if (theURL == null) { theURL = 'https://secure02.mgm-mirage.com/ezbook/index.aspx?prop=bay'; }
var winleft = (screen.width - 800) / 2;
var winUp = (screen.height - 460) / 2;
winProp = 'width=800,height=460,left='+winleft+',top='+winUp+',scrollbars=yes,resizable=yes,menubar=yes,toolbar=yes,status=yes';
Win = window.open(theURL,'resWin',winProp);
self.close();
if (parseInt(navigator.appVersion) >= 4) { Win.focus(); }
}


// Center Dinner Window
// function DinnerWin(Restaurant) { 
// var winleft = (screen.width - 775) / 2;
// var winUp = (screen.height - 525) / 2;
// winProp = 'width=775,height=525,left='+winleft+',top='+winUp+',scrollbars=yes,resizable=yes,menubar=no,toolbar=no,status=yes';
// window.open('https://secure02.mgm-mirage.com/rsvip/treasure.asp?ID='+Restaurant,'dinner',winProp);
//}

// Center Pop Window - 10.13.03 RCS - v2.0
function winBRopen(theURL, Name, popW, popH, scroll, resize, menu, stat, tool) { 
var winleft = (screen.width - popW) / 2;
var winUp = (screen.height - popH) / 2;
winProp = 'width='+popW+',height='+popH+',left='+winleft+',top='+winUp+',scrollbars='+scroll+',resizable='+resize+',menubar='+menu+',status='+stat+',toolbar='+tool+''
Win = window.open(theURL, Name, winProp)
if (parseInt(navigator.appVersion) >= 4) { Win.focus(); }
}

// Center Room Window
function RoomWin(theURL) { 
if (theURL == null) { theURL = 'https://reservations.mgmmirage.com/bookingengine.aspx?pid=MBH'; }
Win = window.open(pageTracker._getLinkerUrl(theURL),'resWin');
if (parseInt(navigator.appVersion) >= 4) { Win.focus(); }
}

//  GreyBox Link
function gbLink(URL){ 
new_win = window.open(URL)
}

// Center Promotions Window
function PromotionsWin(theURL,promo) { 
if (theURL == '') { theURL = 'https://reservations.mgmmirage.com/bookingengine.aspx?pid=MBH'; }
if (promo!=''){ theURL = theURL + "&host=promo&code=" + promo;}
Win = window.open(pageTracker._getLinkerUrl(theURL),'resWin');
if (parseInt(navigator.appVersion) >= 4) { Win.focus(); }
}

// Center Dinner Window
function DinnerWin(Restaurant) { 
window.open(pageTracker._getLinkerUrl('https://reservations.mgmmirage.com/bookingengine.aspx?host=dining&pid=mbh&code='+Restaurant),'dinner');
}

// Center Shownet window
function shownetWin(Show) { 
var winleft = (screen.width - 780) / 2;
var winUp = (screen.height - 530) / 2;
Win = window.open('https://res05.mgmmirage.com/cgi-bin/lansaweb?procfun+netsls+netsls+tck+funcparms+IOFRWW(A010):'+Show,'Tickets','scrollbars=yes,resizable=yes,menubar=yes,toolbar=yes,status=yes,width=780,height=530,top='+winUp+',left='+winleft);
if (parseInt(navigator.appVersion) >= 4) { Win.focus(); }
}

// Center Shopping Window
function shopWin(theURL) { 
var winleft = (screen.width - 770) / 2;
var winUp = (screen.height - 490) / 2;
Win = window.open('https://secure.mandalaycommerce.com/cgi-bin/mrgstore/SoftCart.exe/mrgstore/scstore/'+theURL,'Shopping','scrollbars=yes,resizable=yes,menubar=yes,toolbar=yes,status=yes,width=770,height=490,top='+winUp+',left='+winleft);
if (parseInt(navigator.appVersion) >= 4) { Win.focus(); }
}

// Center Golf Window
function golfWin() { 
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=no,toolbar=yes,status=yes';
Win = window.open('http://book.golfswitch.com/WebPro/search.asp?CUSTID=WGW&PART=MB31102','golf',winProp);
if (parseInt(navigator.appVersion) >= 4) { Win.focus(); }
}

// Center Privacy Window
function PrivacyWin() {
var winleft = (screen.width - 450) / 2;
var winUp = (screen.height - 450) / 2;
Win = window.open('http://www.mgmmirage.com/privacy.htm','privacy','toolbar=yes,scrollbars=yes,resizable=yes,status=yes,width=450,height=450,top='+winUp+',left='+winleft);
if (parseInt(navigator.appVersion) >= 4) { Win.focus(); }
}

// Center Terms of Use Window
function TermsOfUseWin() {
var winleft = (screen.width - 450) / 2;
var winUp = (screen.height - 450) / 2;
Win = window.open('http://www.mgmmirage.com/termsofuse.htm','privacy','toolbar=yes,scrollbars=yes,resizable=yes,status=yes,width=450,height=450,top='+winUp+',left='+winleft);
if (parseInt(navigator.appVersion) >= 4) { Win.focus(); }
}

// Center Ecards Window
function ecardsWin(theURL) {
var winleft = (screen.width - 795) / 2;
var winUp = (screen.height - 460) / 2;
Win = window.open('https://secure02.mgm-mirage.com/Guestbook/Guestbook.aspx?PID=MBH','ecards','toolbar=yes,scrollbars=yes,resizable=yes,status=yes,width=795,height=460,top='+winUp+',left='+winleft);
if (parseInt(navigator.appVersion) >= 4) { Win.focus(); }
}

// Center Virtual Tour Window
function virtualWin(theURL) {
var winleft = (screen.width - 745) / 2;
var winUp = (screen.height - 445) / 2;
Win = window.open('/virtual/'+theURL,'virtual','scrollbars=yes,resizable=yes,status=yes,width=745,height=445,top='+winUp+',left='+winleft);
if (parseInt(navigator.appVersion) >= 4) { Win.focus(); }
}

// Center Seating Chart Window
function seatingWin(theURL) {
var winleft = (screen.width - 745) / 2;
var winUp = (screen.height - 445) / 2;
Win = window.open('/entertainment/'+theURL,'seatingchart','resizable=yes,status=yes,width=535,height=450,top='+winUp+',left='+winleft);
if (parseInt(navigator.appVersion) >= 4) { Win.focus(); }
}


function cakeWin(theURL) {
var winleft = (screen.width - 770) / 2;
var winUp = (screen.height - 550) / 2;
Win = window.open('/amenities/wedding_show_cakes.aspx?cake='+theURL,'cakes','scrollbars=yes,resizable=yes,status=no,width=545,height=550,top='+winUp+',left='+winleft);
if (parseInt(navigator.appVersion) >= 4) { Win.focus(); }
}

function chapelWin(theURL) {
var winleft = (screen.width - 770) / 2;
var winUp = (screen.height - 450) / 2;
Win = window.open('/amenities/wedding_show_chapel.aspx?chapel='+theURL,'chapels','resizable=yes,status=no,width=528,height=450,top='+winUp+',left='+winleft);
if (parseInt(navigator.appVersion) >= 4) { Win.focus(); }
}

function floralWin(theURL) {
var winleft = (screen.width - 770) / 2;
var winUp = (screen.height - 450) / 2;
Win = window.open('/amenities/'+theURL,'flowers','resizable=yes,status=no,width=528,height=525,top='+winUp+',left='+winleft);
if (parseInt(navigator.appVersion) >= 4) { Win.focus(); }
}

function pictureWin(theURL) {
var winleft = (screen.width - 770) / 2;
var winUp = (screen.height - 550) / 2;
Win = window.open('/pictures/popup.aspx?pic='+theURL,'images','scroll=auto,scrollbars=yes,resizable=yes,status=no,width=545,height=500,top='+winUp+',left='+winleft);
if (parseInt(navigator.appVersion) >= 4) { Win.focus(); }
}

//contentWin = window.open(url,"contentWin","resizable=yes,toolbar=no,location=no,width=430,height=435,directories=no,status=no,scroll=auto,scrollbars=yes,menubar=no,left=0,top=5");

// RESERVATIONS GUI
function goToRes(){
	var sURL = ""
	var sFeatures
	var sArriveDate
	var iArriveMilli
	var sBAD
	var sBAM
	var sBAY
	var sDepartDate
	var iDepartMilli
	var sBDD
	var sBDM
	var sBDY
	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 a arrival date greater than today.")
	 } 

	 else {	 
			
		iIndex = document.all("nights").selectedIndex;
		iNumNights = parseInt(document.all("nights").options[iIndex].value,10);
	
		iArriveMilli = parseInt(sArriveDate.valueOf(),10);
		iDepartMilli = iArriveMilli + iNumNights*iDayToMilli;
	
		sDepartDate = new Date(iDepartMilli);
		
		sBDD = sDepartDate.getDate();
		sBDM = sDepartDate.getMonth() + 1;
		sBDY = sDepartDate.getFullYear();
		sURL = escape("prop=bay&arrivaldateForm=" + sBAY + "-" + sBAM + "-" + sBAD  + "&numnightsForm=" + iNumNights);
		sURL = "https://secure02.mgm-mirage.com/ezbook/index.aspx?prop=bay&" + sURL;
		sFeatures = "status=yes,width=795,height=560,resizable=yes,scrollbars=yes,top=0,left=0";

		if (sURL.length != 0){
			window.open(sURL, "reservation", sFeatures);
		}
		}
		}
	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);
		
}