// JavaScript Document

//Redirecting to mobile website if accessed from mobile browsers.

var mobile = (/iphone|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));
if (mobile) {
    window.location = "http://mobile.mirage.com/";
}

//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 MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function SetStatusbar(msg){
	window.status=msg;
	return true;
}

// ****************************************************************
// *********** POPUP WINDOOW **************************************
// ****************************************************************
function popWin(theURL, winName, popW, popH, features) { 
    popW = '640';
    popH = '550';
    
	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(); }
}

function popWin2(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(); }
}

// Custom functions

function MMVWin() {
var winleft = (screen.width - 776) / 2;
var winUp = (screen.height - 500) / 2;
Win = window.open('http://www.mgmmiragevacations.com/mirage/overview.asp?referrer=M19','mmv','toolbar=yes,scrollbars=yes,resizable=yes,status=yes,width=776,height=500,top='+winUp+',left='+winleft);
if (parseInt(navigator.appVersion) >= 4) { Win.focus(); }
}

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(); }
}

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(); }
}


function JetWin() {
var winleft = (screen.width - 600) / 2;
var winUp = (screen.height - 550) / 2;
Win = window.open('http://mirage-jet.admission.com/cgi/guide.cgi?l=EN&amp;C=US','jet','toolbar=yes,scrollbars=yes,resizable=yes,status=yes,width=600,height=550,top='+winUp+',left='+winleft);
if (parseInt(navigator.appVersion) >= 4) { Win.focus(); }
}

// Center Dinner Window
function DinnerWin(Restaurant) { 
window.open(pageTracker._getLinkerUrl('https://reservations.mgmmirage.com/bookingengine.aspx?pid=160&host=dining&code='+Restaurant,'dinner'));
}


// Center Room Window
function RoomWin(theURL,ad,nights) { 
if (theURL == '') { theURL = 'https://reservations.mgmmirage.com/bookingengine.aspx?host=hotel&pid=160'; }
if (ad!=''){ theURL = theURL + "&ad=" + ad;}
if (nights!=''){theURL = theURL + "&nights=" + nights;}
window.open(pageTracker._getLinkerUrl(theURL)); 
}

// Center Room Window
function RoomWinES(theURL,ad,nights) { 
if (theURL == '') { theURL = 'https://reservations.mgmmirage.com/bookingengine.aspx?host=hotel&pid=160&lang=es-ES'; }
if (ad!=''){ theURL = theURL + "&ad=" + ad;}
if (nights!=''){theURL = theURL + "&nights=" + nights;}
window.open(pageTracker._getLinkerUrl(theURL)); 
}

// Center Room Window
function RoomWinFr(theURL,ad,nights) { 
if (theURL == '') { theURL = 'https://reservations.mgmmirage.com/bookingengine.aspx?host=hotel&pid=160&lang=fr-FR'; }
if (ad!=''){ theURL = theURL + "&ad=" + ad;}
if (nights!=''){theURL = theURL + "&nights=" + nights;}
window.open(pageTracker._getLinkerUrl(theURL)); 
}

// Center Room Window
function RoomWinIt(theURL,ad,nights) { 
if (theURL == '') { theURL = 'https://reservations.mgmmirage.com/bookingengine.aspx?host=hotel&pid=160&lang=it-IT'; }
if (ad!=''){ theURL = theURL + "&ad=" + ad;}
if (nights!=''){theURL = theURL + "&nights=" + nights;}
window.open(pageTracker._getLinkerUrl(theURL)); 
}

// Center Room Window
function RoomWinDE(theURL,ad,nights) { 
if (theURL == '') { theURL = 'https://reservations.mgmmirage.com/bookingengine.aspx?host=hotel&pid=160&lang=de-DE'; }
if (ad!=''){ theURL = theURL + "&ad=" + ad;}
if (nights!=''){theURL = theURL + "&nights=" + nights;}
window.open(pageTracker._getLinkerUrl(theURL)); 
}

// Center Room Window
function RoomWinJA(theURL,ad,nights) { 
if (theURL == '') { theURL = 'https://reservations.mgmmirage.com/bookingengine.aspx?host=hotel&pid=160&lang=ja-JP'; }
if (ad!=''){ theURL = theURL + "&ad=" + ad;}
if (nights!=''){theURL = theURL + "&nights=" + nights;}
window.open(pageTracker._getLinkerUrl(theURL)); 
}

// Center Room Window
function RoomWinCHPRC(theURL,ad,nights) { 
if (theURL == '') { theURL = 'https://reservations.mgmmirage.com/bookingengine.aspx?host=hotel&pid=160&lang=zh-CN'; }
if (ad!=''){ theURL = theURL + "&ad=" + ad;}
if (nights!=''){theURL = theURL + "&nights=" + nights;}
window.open(pageTracker._getLinkerUrl(theURL)); 
}

// Center Room Window
function RoomWinZHTW(theURL,ad,nights) { 
if (theURL == '') { theURL = 'https://reservations.mgmmirage.com/bookingengine.aspx?host=hotel&pid=160&lang=zh-TW'; }
if (ad!=''){ theURL = theURL + "&ad=" + ad;}
if (nights!=''){theURL = theURL + "&nights=" + nights;}
window.open(pageTracker._getLinkerUrl(theURL)); 
}

// Center Room Window
function RoomWinKO(theURL,ad,nights) { 
if (theURL == '') { theURL = 'https://reservations.mgmmirage.com/bookingengine.aspx?host=hotel&pid=160&lang=ko-KO'; }
if (ad!=''){ theURL = theURL + "&ad=" + ad;}
if (nights!=''){theURL = theURL + "&nights=" + nights;}
window.open(pageTracker._getLinkerUrl(theURL)); 
}

// Center Room Window
function RoomWinPTBR(theURL,ad,nights) { 
if (theURL == '') { theURL = 'https://reservations.mgmmirage.com/bookingengine.aspx?host=hotel&pid=160&lang=pt-BR'; }
if (ad!=''){ theURL = theURL + "&ad=" + ad;}
if (nights!=''){theURL = theURL + "&nights=" + nights;}
window.open(pageTracker._getLinkerUrl(theURL)); 
}

// Center Room Window
function RoomWinGui(theURL) { 
if (theURL == null) { theURL = 'https://reservations.mgmmirage.com/bookingengine.aspx?pid=160'; }
window.open(pageTracker._getLinkerUrl(theURL)); 
}

// Center Room Window with promo1
function RoomWinPromo1(theURL,ad,nights) { 
if (theURL == '') { theURL = 'https://reservations.mgmmirage.com/bookingengine.aspx?pid=160&host=promo&code=WEBPROMO'; }
if (ad!=''){ theURL = theURL + "&ad=" + ad;}
if (nights!=''){theURL = theURL + "&nights=" + nights;}
window.open(pageTracker._getLinkerUrl(theURL)); 
}

// Center Room Window with promo1a
function RoomWinPromo1a(theURL,ad,nights) { 
if (theURL == '') { theURL = 'https://reservations.mgmmirage.com/bookingengine.aspx?pid=160&host=promo&show=rates&code=WEBPROMO'; }
if (ad!=''){ theURL = theURL + "&ad=" + ad;}
if (nights!=''){theURL = theURL + "&nights=" + nights;}
window.open(pageTracker._getLinkerUrl(theURL)); 
}

// Center Room Window with promo2
function RoomWinPromo2(theURL,ad,nights) { 
if (theURL == '') { theURL = 'https://reservations.mgmmirage.com/bookingengine.aspx?pid=160&host=promo&code=WINTER'; }
if (ad!=''){ theURL = theURL + "&ad=" + ad;}
if (nights!=''){theURL = theURL + "&nights=" + nights;}
window.open(pageTracker._getLinkerUrl(theURL)); 
}

// Center Room Window with promo2a
function RoomWinPromo2a(theURL,ad,nights) { 
if (theURL == '') { theURL = 'https://reservations.mgmmirage.com/bookingengine.aspx?pid=160&host=promo&show=rates&code=WINTER'; }
if (ad!=''){ theURL = theURL + "&ad=" + ad;}
if (nights!=''){theURL = theURL + "&nights=" + nights;}
window.open(pageTracker._getLinkerUrl(theURL)); 
}

// Center Room Window
function RoomWin2(theURL,ad,nights) { 
if (theURL == '') { theURL = 'https://reservations.mgmmirage.com/bookingengine.aspx?pid=160&host=promo'; }
ad = document.getElementsByName("ad")[0].value;
promotions = document.getElementsByName("promotions")[0];
nights = document.getElementsByName("nights")[0];
guests = document.getElementsByName("guests")[0];
var guestIndex = guests.options[guests.selectedIndex].value;
var nightIndex = nights.options[nights.selectedIndex].value;
var promotionsIndex = promotions.options[promotions.selectedIndex].value;
if (promotions!='' && promotionsIndex!='NONE'){ theURL = theURL + "&code=" + promotionsIndex;}
if (ad!=''){ theURL = theURL + "&ad=" + ad;}
if (nights!=''){theURL = theURL + "&nights=" + nightIndex;}
if (guests!=''){theURL = theURL + "&guests=" + guestIndex;}
window.open(pageTracker._getLinkerUrl(theURL)); 
}

// Center "O" Window
function CirqueWin(theURL,ad,nights) { 
if (theURL == '') { theURL = 'http://mirage-cds.admission.com/cgi/guide.cgi?l=EN&C=US'; }
if (ad!=''){ theURL = theURL + "&ad=" + ad;}
if (nights!=''){theURL = theURL + "&nights=" + nights;}
var winleft = (screen.width - 675) / 2;
var winUp = (screen.height - 550) / 2;
winProp = 'width=675,height=520,left='+winleft+',top='+winUp+',scrollbars=yes,resizable=yes,menubar=yes,toolbar=no,status=yes';
Win = window.open(theURL,'resWin',winProp);
if (parseInt(navigator.appVersion) >= 4) { Win.focus(); }
}


// Bare Cabana Rental Window
function BareCabanaWin(theURL,ad,nights) { 
if (theURL == '') { theURL = 'http://mirage-bare.admission.com/cgi/guide.cgi?l=EN&C=US'; }
if (ad!=''){ theURL = theURL + "&ad=" + ad;}
if (nights!=''){theURL = theURL + "&nights=" + nights;}
var winleft = (screen.width - 675) / 2;
var winUp = (screen.height - 550) / 2;
winProp = 'width=675,height=520,left='+winleft+',top='+winUp+',scrollbars=yes,resizable=yes,menubar=yes,toolbar=no,status=yes';
Win = window.open(theURL,'resWin',winProp);
if (parseInt(navigator.appVersion) >= 4) { Win.focus(); }
}


// Center Danny Gans Window
function DannyGansWin(theURL,ad,nights) { 
//if (theURL == '') { theURL = 'http://gans.admission.com/'; }
if (theURL == '') { theURL = 'http://gans.admission.com/cgi/guide.cgi?l=EN&C=US'; }
if (ad!=''){ theURL = theURL + "&ad=" + ad;}
if (nights!=''){theURL = theURL + "&nights=" + nights;}
var winleft = (screen.width - 600) / 2;
var winUp = (screen.height - 550) / 2;
winProp = 'width=600,height=520,left='+winleft+',top='+winUp+',scrollbars=yes,resizable=yes,menubar=yes,toolbar=no,status=yes';
Win = window.open(theURL,'resWin',winProp);
if (parseInt(navigator.appVersion) >= 4) { Win.focus(); }
}

// Center Terry Fator Window
function TerryFatorWin(theURL,ad,nights) { 
//if (theURL == '') { theURL = 'http://gans.admission.com/'; }
if (theURL == '') { theURL = 'http://mirage-fator.admission.com/cgi/guide.cgi?l=EN&C=US'; }
if (ad!=''){ theURL = theURL + "&ad=" + ad;}
if (nights!=''){theURL = theURL + "&nights=" + nights;}
var winleft = (screen.width - 600) / 2;
var winUp = (screen.height - 550) / 2;
winProp = 'width=600,height=520,left='+winleft+',top='+winUp+',scrollbars=yes,resizable=yes,menubar=yes,toolbar=no,status=yes';
Win = window.open(theURL,'resWin',winProp);
if (parseInt(navigator.appVersion) >= 4) { Win.focus(); }
}


// Comp Window for MPE to be Removed when new interface is posted live.
function CompmMPEWin() {
var winleft = (screen.width - 640) / 2;
var winUp = (screen.height - 500) / 2;
Win = window.open('/interface-comps/MPE.html','mpe','toolbar=yes,scrollbars=yes,resizable=yes,status=yes,width=640,height=500,top='+winUp+',left='+winleft);
if (parseInt(navigator.appVersion) >= 4) { Win.focus(); }
}

// Open guestbook / MPE
function guestBook(email){
var winleft = (screen.width - 740) / 2;
var winUp = (screen.height - 500) / 2;
//var URL = "https://secure02.mgm-mirage.com/Guestbook/Guestbook.aspx?PID=160"
var URL = "https://secure02.mgm-mirage.com/Guestbook/Guestbook.aspx?PID=160"
if (email != undefined){
	URL += "&email=" + email
}
winProp = 'width=740,height=500,left='+winleft+',top='+winUp+',scrollbars=yes,resizable=yes,menubar=yes,toolbar=yes,status=yes';
Win = window.open(URL,'guestbook',winProp);
if (parseInt(navigator.appVersion) >= 4) { Win.focus(); }
}

function ecardsWin(theURL) {
var winleft = (screen.width - 795) / 2;
var winUp = (screen.height - 460) / 2;
Win = window.open('https://secure02.mgm-mirage.com/ecards/'+theURL,'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 Golf Window
function golfWin() { 
var winleft = (screen.width - 795) / 2;
var winUp = (screen.height - 460) / 2;
winProp = 'width=620,height=450,left='+winleft+',top='+winUp+',scrollbars=yes,resizable=yes,menubar=no,toolbar=yes,status=yes';
Win = window.open('https://secure02.mgm-mirage.com/golf/primm/pg_online_res_date.asp?pid=160','golf',winProp);
if (parseInt(navigator.appVersion) >= 4) { Win.focus(); }
}

// Center Golf Window
function golfWinp() { 
var winleft = (screen.width - 795) / 2;
var winUp = (screen.height - 460) / 2;
winProp = 'width=620,height=450,left='+winleft+',top='+winUp+',scrollbars=yes,resizable=yes,menubar=no,toolbar=yes,status=yes';
//Win = window.open('http://www.primmvalleyresorts.com/pages/pvg_online.asp','golf',winProp);
Win = window.open('https://secure02.mgm-mirage.com/golf/mirage/pg_online_res_date.asp?pid=160','golf',winProp);
if (parseInt(navigator.appVersion) >= 4) { Win.focus(); }
}

function keyCheck(objEvent){
	/*This checks to see if the what key has been
	pressed on the user's keyboard.  The ascii value
	of the key that has been pressed is returned 
	by the function*/
	var intKey;
	if(objEvent.which == null){
		intKey = event.keyCode;
	}
	else{
		intKey = evnt.which;
	}
	return intKey;
}
	
// Puts focus on textbox
function enterDir(objEvent, flag){
    if(keyCheck(objEvent) == 13){
        //alert("Enter")
        switch(flag)
        {
            case "guestbook":
	            guestBook(document.mpeForm.email_signup.value);
	            break;
            
        }
        //document.mpeForm.submit();
    }
    else
    {
        return false;
    }
}
     
   
