var uAgt      = navigator.userAgent.toLowerCase();
var isIE      = uAgt.indexOf("msie");
var isAOL     = uAgt.indexOf(" aol ");
var isSAFARI  = uAgt.indexOf("safari");
var isFirefox = uAgt.indexOf("firefox");
var isMac     = uAgt.indexOf("mac os x");

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
var special = new Object()

    special.active = false;

    special.img = "/images/specials/playa-mujeres-01.jpg";
    special.url = "/all-inclusive-resorts/playa-mujeres-mexico/playa-resort-specials.htm";
    special.swf = "/images/specials/special-offer-global-xpm.swf";
    special.lnkTopType = "swf";
    special.lnkTopImg = "/images/specials/special-offers-flash-link.swf";
    special.lnkTopUrl = "/excellence-special-offers.htm";
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

function emailThisPage() {
	var emailThisFormURL = "/forms/email-to-friend_er00.htm";
	var oPageName = document.getElementsByTagName("title")[0];		
	var sPageURL = document.URL;
	var sPageName = ( oPageName != null ) ? sPageName = oPageName.innerHTML: sPageName = "Excellence Resorts";
	var URL = emailThisFormURL + "?PageName="+sPageName+"&PageURL="+sPageURL;
	openCenteredWindow(URL, "emailThisPage", 600, 400);
}

function getEmailPageDetails() {
	var parameters = document.location.search;
	if ( parameters.length > 20 )	{
		var arr = parameters.split("&PageURL=");
		if ( arr.length == 2 ) {
			var pageURL = unescape(arr[1]);
			var pageName = unescape(arr[0].split("?PageName=")[1]);
			var dPageName = document.getElementById("dPageName");
			var oPageName = document.getElementById("pageName");
			var oPageURL = document.getElementById("pageURL");
			if ( dPageName != null ) {
				var oTextNode = document.createTextNode(pageName);
				dPageName.appendChild(oTextNode);
			}
			if ( oPageName != null ) oPageName.value = pageName;
			if ( oPageURL != null ) oPageURL.value = pageURL;
		}
	}
}

function submitForm(formName, preview) {
	var oFrm = document.getElementById(formName);
	var oPreview = document.getElementById("emailPreview");

	if (oFrm) {
		if ( typeof(preview) == "undefined" ) {
			if ( oPreview != null ) oPreview.value = "";
		} else {
			if ( oPreview != null ) oPreview.value = preview;
		}
		if ( emailFormValidation() ) {
			oFrm.submit();
		}
	}
}

function emailFormValidation() {
	var o = document.getElementById("senderName");
	if ( o.value == "" ) {
		alert("Please enter your Name");
		o.focus();
		return false;
	}
	var o = document.getElementById("email");
	if ( o.value == "" ) {
		alert("Please enter your Email Address");
		o.focus();
		return false;
	}
	if (isEmail(o.value) == false) {
		alert("Please enter a valid Email Address.");
		o.focus();
		return false;
	}
	var o = document.getElementById("sendTo");
	if ( o.value == "" ) {
		alert("Please enter Recipient(s) separated by comma");
		o.focus();
		return false;
	} else {
		var arr = o.value.split(",");
		for (t=0; t < arr.length; ++t) {
			var Rep = arr[t].replace(/\n/g,"").replace(/\s/g,"");
			if ( Rep.length > 0 ) {
				if (isEmail(Rep) == false) {
					alert("Please enter a valid Recipient Email Address for: \n" + Rep);
					o.focus();
					return false;
				}
			}
		}
	}
	return true;
}

function isEmail(string) {
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}

function openCenteredWindow(url, name, w, h, scrollbars, resizable) {
	if ( w == 1 ) {
		LeftPosition = -1000;
		TopPosition = -1000;
	} else {
		LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
		TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	}
	
	if ( typeof(scrollbars) == "undefined" ) scrollbars = "yes";
	if ( typeof(resizable) == "undefined" ) resizable = "yes";

	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scrollbars+',resizable='+resizable+',menubar=no,toolbar=no,status=yes,location=no';

	window.open(url,name,settings);
}

/************************************************** */
function FlashTag(src, width, height, version) {
    if (arguments.length < 4) {
        throw new Exception('RequiredAttributeException',
                            'You must pass in a src, width, height, and version when creating a FlashTag.');
    }

    for (var i = 0; i < arguments.length; ++i) {
        if (arguments[i] == undefined || arguments[i] == null) {
            throw new Exception('RequiredAttributeException',
                                'All constructor arguments must have values.');
        }
    }

    // Required
    this.src            =  src;
    this.width          =  width;
    this.height         =  height;
    this.version        =  version;

    this.id             =  null;
    this.flashVars      =  null;
    this.flashVarsStr   =  null;
    this.genericParam   = new Object();
    this.ie = (navigator.appName.indexOf ("Microsoft") != -1) ? 1 : 0;
}

/**
 * Specifies the location (URL) of the Flash content to be loaded.
 */
FlashTag.prototype.setSource = function(src) {
    this.src = src; 
}

/**
 * Specifies the width of the Flash content in either pixels or percentage of browser window. 
 */
FlashTag.prototype.setWidth = function(w) {
    this.width = width; 
}

/**
 * Specifies the height of the Flash content in either pixels or percentage of browser window. 
 */
FlashTag.prototype.setHeight = function(h) {
    this.h = height; 
}

/**
 * The required version of the Flash Player for the specified content. 
 */
FlashTag.prototype.setVersion = function(v) {
    this.version = v;
}

/**
 * Identifies the Flash content to the host environment (a web browser, for example) so that
 * it can be referenced using a scripting language. This value will be used for both the 'id'
 * and 'name' attributes depending on the client platform and whether the object or the embed
 * tag are used.
 */
FlashTag.prototype.setId = function(id) {
    this.id = id;
}

/**
 * Specifies the background color of the Flash content. Use this attribute to override the background
 * color setting specified in the Flash file. This attribute does not affect the background
 * color of the HTML page. 
 */
FlashTag.prototype.setBgcolor = function(bgc) {
    if (bgc.charAt(0) != '#') {
        bgc = '#' + bgc;
    }
    this.genericParam['bgcolor'] = bgc;
}

/**
 * Allows you to set multiple Flash vars at once rather than adding them one at a time. The string
 * you pass in should contain all your Flash vars, properly URL encoded. This function can be used in
 * conjunction with addFlashVar.
 */
FlashTag.prototype.addFlashVars = function(fvs) {
    this.flashVarsStr = fvs;
}

/**
 * Used to send root level variables to the Flash content. You can add as many name/value pairs as
 * you want. The formatting of the Flash vars (turning them into a query string) is handled automatically.
 */
FlashTag.prototype.addFlashVar = function(n, v) {
    if (this.flashVars == null) {
        this.flashVars = new Object();
    }

    this.flashVars[n] = v;
}

/**
 * Used to remove Flash vars. This is primarily useful if you want to reuse an instance of the FlashTag
 * but you don't want to send the same variables to more than one piece of Flash content. 
 */
FlashTag.prototype.removeFlashVar = function(n) {
    if (this.flashVars != null) {
        this.flashVars[n] = undefined;
    }
}

/**
 * (true, false) Specifies whether the browser should start Java when loading the Flash Player for the first time.
 * The default value is false if this property is not set. 
 */
FlashTag.prototype.setSwliveconnect = function(swlc) {
    this.genericParam['swliveconnect'] = swlc;
}

/**
 * (true, false) Specifies whether the Flash content begins playing immediately on loading in the browser.
 * The default value is true if this property is not set. 
 */
FlashTag.prototype.setPlay = function(p) {
    this.genericParam['play'] = p;
}

/**
 * (true, false) Specifies whether the Flash content repeats indefinitely or stops when it reaches the last frame.
 * The default value is true if this property is not set. 
 */
FlashTag.prototype.setLoop = function(l) {
    this.genericParam['loop'] = l;
}

/**
 * (true,false) Whether or not to display the full Flash menu. If false, displays a menu that contains only
 * the Settings and the About Flash options. 
 */
FlashTag.prototype.setMenu = function(m) {
    this.genericParam['menu'] = m;
}

/**
 * (low, high, autolow, autohigh, best) Sets the quality at which the Flash content plays.
 */
FlashTag.prototype.setQuality = function(q) {
    if (q != 'low' && q != 'high' && q != 'autolow' && q != 'autohigh' && q != 'best') {
        throw new Exception('UnsupportedValueException',
                            'Supported values are "low", "high", "autolow", "autohigh", and "best".');
    }
    this.genericParam['quality'] = q;
}

/**
 * (showall, noborder, exactfit) Determins how the Flash content scales.
 */
FlashTag.prototype.setScale = function(sc) {
    if (sc != 'showall' && sc != 'noborder' && sc != 'exactfit') {
        throw new Exception('UnsupportedValueException',
                            'Supported values are "showall", "noborder", and "exactfit".');
    }
    this.genericParam['scale'] = sc;
}

/**
 * (l, t, r, b) Align the Flash content along the corresponding edge of the browser window and crop
 * the remaining three sides as needed.
 */
FlashTag.prototype.setAlign= function(a) {
    if (a != 'l' && a != 't' && a != 'r' && a != 'b') {
        throw new Exception('UnsupportedValueException',
                            'Supported values are "l", "t", "r" and "b".');
    }
    this.genericParam['align'] = a;
}

/**
 * (l, t, r, b, tl, tr, bl, br) Align the Flash content along the corresponding edge of the browser
 * window and crop the remaining three sides as needed.
 */
FlashTag.prototype.setSalign= function(sa) {
    if (sa != 'l' && sa != 't' && sa != 'r' && sa != 'b' && sa != 'tl' && sa != 'tr' && sa != 'bl' && sa != 'br') {
        throw new Exception('UnsupportedValueException',
                            'Supported values are "l", "t", "r", "b", "tl", "tr", "bl" and "br".');
    }
    this.genericParam['salign'] = sa;
}

/**
 * (window, opaque, transparent) Sets the Window Mode property of the Flash content for transparency,
 * layering, and positioning in the browser. 
 */
FlashTag.prototype.setWmode = function(wm) {
    if (wm != 'window' && wm != 'opaque' && wm != 'transparent') {
        throw new Exception('UnsupportedValueException',
                            'Supported values are "window", "opaque", and "transparent".');
    }
    this.genericParam['wmode'] = wm;
}
/* Sets the script access variable for the swf's object/embed code
* allowed values are 'always', 'never' and 'same domain'.
*/
FlashTag.prototype.setAllowScriptAccess = function(access) {
	var norm_access = access.toLowerCase();
    if (norm_access != 'always' && norm_access != 'never' && norm_access != 'samedomain') {
        throw new Exception('UnsupportedValueException',
                            'Supported values are "always", "never", and "samedomain".');
    }
    this.genericParam['allowScriptAccess'] = norm_access;
}


/**
 * Specifies the base directory or URL used to resolve all relative path statements in your Flash content.
 */
FlashTag.prototype.setBase = function(base) {
    this.genericParam['base'] = base;
}

/**
 * Get the Flash tag as a string. 
 */
FlashTag.prototype.toString = function() {
    var flashTag = new String();
    if (this.ie) {
        flashTag += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
        if (this.id != null) {
            flashTag += 'id="'+this.id+'" ';
        }
        flashTag += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+this.version+'" ';
        flashTag += 'width="'+this.width+'" ';
        flashTag += 'height="'+this.height+'">';
        flashTag += '<param name="movie" value="'+this.src+'"/>';

        for (var n in this.genericParam) {
            if (this.genericParam[n] != undefined && this.genericParam[n] != null)
            {
                flashTag += '<param name="'+n+'" value="'+this.genericParam[n]+'"/>';
            }
        }

        if (this.flashVars != null) {
            var fv = this.getFlashVarsAsString();
            if (fv.length > 0)
            {
                flashTag += '<param name="flashvars" value="'+fv+'"/>';
            }
        }
        flashTag += '</object>';
    } else {
        flashTag += '<embed src="'+this.src+'"';
        flashTag += ' width="'+this.width+'"';
        flashTag += ' height="'+this.height+'"';
        flashTag += ' type="application/x-shockwave-flash"';
        if (this.id != null) {
            flashTag += ' name="'+this.id+'"';
        }

        for (var n in this.genericParam) {
            if (this.genericParam[n] != undefined && this.genericParam[n] != null)
            {
                flashTag += (' '+n+'="'+this.genericParam[n]+'"');
            }
        }
	// modified by Eric Petersen 7-27-2005 to make addFlashVars work
	// I added "|| this.flashVarsStr != null" to the if statement
        if (this.flashVars != null || this.flashVarsStr != null) {
            var fv = this.getFlashVarsAsString();
            if (fv.length > 0)
            {
                flashTag += ' flashvars="'+fv+'"';
            }
        }
        flashTag += ' pluginspage="http://www.macromedia.com/go/getflashplayer">';
        flashTag += '</embed>';
    }
    return flashTag;
}

/**
 * Write the Flash tag out. Pass in a reference to the document to write to. 
 */
FlashTag.prototype.write = function(doc) {
    doc.write(this.toString());
}

/**
 * Write the Flash tag out. Pass in a reference to the document to write to. 
 */
FlashTag.prototype.getFlashVarsAsString = function() {
    var qs = new String();
    for (var n in this.flashVars) {
        if (this.flashVars[n] != undefined && this.flashVars[n] != null) {
            qs += (escape(n)+'='+escape(this.flashVars[n])+'&');
        }
    }

    if (this.flashVarsStr != null) {
        return qs + this.flashVarsStr;
    }

    return qs.substring(0, qs.length-1);
}

/************************************************************************/
/*
    var oTag = new FlashTag(special.swf, 439, 54, '8,0,0,0');
    oTag.write(document);
*/

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
//addLoadEvent(specials);

function createImgLnk(sLink, sImage, imgW, imgH) {
    var oLnk = document.createElement("A");
    oLnk.href = sLink;

    var oImg = document.createElement("IMG");
    oImg.src = sImage;
    oImg.border = "0";
    if (typeof(imgW) != "undefined") {
        oImg.width = imgW;
    }
    if (typeof(imgH) != "undefined") {
        oImg.height = imgH;
    }

    if (isIE > 0) {
        oImg.setAttribute("onmouseover", function () { switchOn(this) }) 
        oImg.setAttribute("onmouseout", function () { switchOff(this) }) 
    } else {
        oImg.setAttribute("onmouseover","switchOn(this)");
        oImg.setAttribute("onmouseout","switchOff(this)");
    }

    oLnk.appendChild(oImg);

    return oLnk;
}

function switchOn(oImg) {
    oImg.src = oImg.src.replace(/_off/g,"_on");
}
function switchOff(oImg) {
    oImg.src = oImg.src.replace(/_on/g,"_off");
}

function specials_popup() {
    var triggered = false;

    setTimeout("trigger_specials_link()", 500);
    
    if (GetCookie("SHOW_SPECIAL") == "" && special.active) {
        triggered = true;
        document.cookie = "SHOW_SPECIAL=1; path=/;";
        setTimeout("trigger_specials_popup()", 2000);
    }

    if (isMac > 0 && triggered) {
        // DO NOT SHOW THE MAIN FLASH IF "Mac & FF" AND SPECIAL WAS TRIGGERED
    } else {
        showMainFlash();
    }
}

function trigger_specials_link() {
    var oTD = document.getElementById("specials_link");
    if (oTD) {
        if (special.lnkTopType == "swf") {
            var oImgLnk = new FlashTag(special.lnkTopImg, 116, 16, '8,0,0,0');
            oTD.innerHTML += oImgLnk.toString();
        } else {
            var oImgLnk = createImgLnk(special.lnkTopUrl,special.lnkTopImg);
            oTD.appendChild(oImgLnk);
        }
    }
}

function closeSpecial() {
    var holder = document.getElementById("specials_popup");
    holder.innerHTML = "";
    holder.style.visibility = "hidden";

    if (isMac > 0 ) {
        showMainFlash()
    }
}

function showMainFlash() {
    var mainFlashHolder = document.getElementById("mainFlashHolder");
    if (mainFlashHolder) {
        var oTag = new FlashTag("excel-home-anime-29.swf", 504, 586, '8,0,0,0');
        try { oTag.setWmode('opaque') } catch (Exc) { };
        mainFlashHolder.innerHTML = oTag.toString();
    }
}

function hideMainFlash() {
    var mainFlashHolder = document.getElementById("mainFlashHolder");
    if (mainFlashHolder) {
        mainFlashHolder.innerHTML = "";
    }
}

function trigger_specials_popup() {
    var holder = document.getElementById("specials_popup");
    if (holder) {
        var oTbl = document.createElement("TABLE");
        oTbl.setAttribute("border","0");
        oTbl.setAttribute("width","450");
        oTbl.setAttribute("height","450");
        oTbl.setAttribute("cellpadding","0");
        oTbl.setAttribute("cellspacing","0");
        oTbl.style.backgroundColor = "white";
        oTbl.style.border = "solid 1px #666666";

        var oTR0 = oTbl.insertRow(0);
        var oTR1 = oTbl.insertRow(1);
        var oTR2 = oTbl.insertRow(2);

        var oTD0 = oTR0.insertCell(0);
        var oTD1 = oTR1.insertCell(0);
        var oTD2 = oTR2.insertCell(0);

        // ADD IMAGE
        var oMainImg = createImgLnk(special.url,special.img, 450, 357);
        oTD0.appendChild(oMainImg);

        // ADD FLASH
        var oDIV = document.createElement("DIV");
        var oTag = new FlashTag(special.swf, 439, 54, '8,0,0,0');
        oDIV.innerHTML = oTag.toString();
        oDIV.style.cursor = "hand";

        oTD1.style.textAlign = "center";
        oTD1.appendChild(oDIV);

        // ADD CLOSE BUTTON
        var oClose = createImgLnk('javascript:closeSpecial()','/images/specials/btn_close_off.gif');
        oTD2.style.textAlign = "right";
        oTD2.appendChild(oClose);
        if (isSAFARI) {
            holder.style.height = "451";
            holder.style.overflow = "hidden";
            oTD2.style.borderBottom = "solid 1px #666666";
        }
        
        // SHOW THE SPECIAL
        holder.style.position = "absolute";
        holder.style.top = "114px";
        holder.style.left = "380px";
        holder.style.zIndex = "999999";
        holder.appendChild(oTbl);
    }
}
