<!--
/* GENERAL VARIABLES */

var d                   = document;
var site_name           = "Marina Dunes Resort";
var site_primary_domain = "marinadunes.com";
var site_link_address   = "/";
var winName             = "MDWin";

/* PAGE ONLOAD EVENTS */

// define as a variable so pages can add additional functions to run on load
var onLoadScripts = "";
window.onload = function() {
  onLoadScripts += "changeLinks(); createMouseovers();";
  setTimeout(onLoadScripts,50);
  }

/* OFF-SITE LINK DYNAMIC MANIPULATION SCRIPT */

if (top.name + "" == "") {
  top.name = winName;
  }

function changeLinks() {
  var i, links, newHref;
  if (document.links) {
    links = document.links;
    for (i = 0; i < links.length; i++) {
      if (links[i].className && links[i].className == "offsite") {
        if (links[i].href && links[i].href != "" && links[i].href != "#") {
          eval("links[i].onmouseover = function() {window.status = '" + links[i].href + "'; return true};");
          eval("links[i].onmouseout  = function() {window.status = ''; return true};");
          newHref = site_link_address + "return.html?getPage=" + escape(links[i].href);
          if (top.name != winName)
            newHref = newHref + "&winName=" + top.name;
          eval("links[i].href        = '" + newHref + "'");
          }
        }
      }
    }
  }

/* IMAGE FADE SCRIPTS */

function setPicture(bwImg, colorImg) {
  if (document.all && document.all.pictureDiv) {
    myPix = document.all.pictureDiv;
    myPix.style.backgroundImage = "url(" + bwImg + ")";
    myPix.style.filter = "progid:DXImageTransform.Microsoft.fade(duration=6)";
    setTimeout("switchPicture('"+colorImg+"')",5500);
    preloadImg(colorImg);
    }
  }

function switchPicture(colorImg) {
  if (document.all && document.all.pictureDiv) {
    myPix = document.all.pictureDiv;
    myPix.filters[0].Apply();
    myPix.style.backgroundImage = "url(" + colorImg + ")";
    myPix.filters[0].Play();
    }
  }

/* MOUSEOVER CREATION AND PRELOAD SCRIPT */

function createMouseovers() {
  var overExt = "_ON";
  if (document.getElementsByTagName) {
    var imgs = document.getElementsByTagName("IMG")
    var i, dotAt, imgFile, imgExt;
    for (i = 0; i < imgs.length; i++) {
      if (imgs[i].className && imgs[i].className == "mouseover") {
        dotAt = imgs[i].src.lastIndexOf(".");
        if (dotAt > 0) {
          imgFile = imgs[i].src.substr(0,dotAt);
          imgExt  = imgs[i].src.substr(dotAt+1);
          if (imgFile.lastIndexOf(overExt) == imgFile.length - overExt.length) {
            // do nothing; image is already on
            }
          else {
            eval("imgs[i].onmouseover = function () {this.src = '" + imgFile + overExt + "." + imgExt + "'};");
            eval("imgs[i].onmouseout = function () {this.src = '" + imgFile + "." + imgExt + "'};");
            preloadImg(imgFile + overExt+ "." + imgExt);
            }
          }
        }
      }
    }
  }

function preloadImg() {
  if (d.images) {
    if (!d.preloads)
      d.preloads = new Array();
    var i, j = d.preloads.length, imgs = preloadImg.arguments;
    for (i = 0; i < imgs.length; i++) {
      d.preloads[j]       = new Image;
      d.preloads[j++].src = imgs[i];
      }
    }
  }

/* EMAIL OUTPUT FUNCTIONS */

// Writes out the opening tag for an email link in the form <a href="mailto:me@domain.com">
function writeEmailLinkOpenTag(addressee, domain, subject, linkCodePrepend, linkCodeAppend) {
  if (writeEmailLinkOpenTag.arguments.length < 2 || domain == "" || domain == null)
    domain = site_primary_domain;
  var emailAddress = addressee + "@" + domain;
  if (writeEmailLinkOpenTag.arguments.length < 3 || subject == null)
    subject = "Inquiry from " + site_primary_domain;
  if (writeEmailLinkOpenTag.arguments.length < 4 || linkCodePrepend == null)
    linkCodePrepend = "";
  if (writeEmailLinkOpenTag.arguments.length < 5 || linkCodeAppend == null)
    linkCodeAppend = "";
  document.write("<a" + linkCodePrepend + " href=\"mailto:" + emailAddress.toLowerCase() + "?subject=" + subject + "\"" + linkCodeAppend + ">");
  }

// Writes out the closing tag for an email link in the form </a>
function writeEmailLinkCloseTag() {
  document.write("</a>");
  }

// Writes out an email link in the form <a href="mailto:me@domain.com">some text</a>
function writeEmailTextLink(addressee,domain,subject,linkText,linkCodePrepend,linkCodeAppend) {
  writeEmailLinkOpenTag(addressee,domain,subject,linkCodePrepend,linkCodeAppend);
  document.write(linkText);
  writeEmailLinkCloseTag();
  }
  
// Writes out an email link in the form <a href="mailto:me@domain.com">me@domain.com</a>
function writeEmailAddressLink(addressee,domain,subject,linkCodePrepend,linkCodeAppend) {
  writeEmailLinkOpenTag(addressee,domain,linkCodePrepend,linkCodeAppend);
  writeEmailAddress(addressee,domain);
  writeEmailLinkCloseTag();
  }
  
// Writes out an email address
function writeEmailAddress(addressee,domain) {
  if (writeEmailAddress.arguments.length < 2 || domain == "" || domain == null)
    domain = site_primary_domain;
  var emailAddress = addressee + "@" + domain;
  document.write(emailAddress);
  }

/* FORM VALIDATION SCRIPTS */

function checkEmail(varField,varName) {
  if (!isValidEmailAddress(removeExtraSpaces(varField.value))) {
    if (varName.length > 1) // capitalize varName string
      varName = varName.substring(0,1).toUpperCase() + varName.substring(1,varName.length);
    alert(varName + " does not appear to be in the correct format.");
    varField.focus();
    return false;
    }
  else
    return true;
  }

function checkExists(varField,varName) {
  if (removeExtraSpaces(varField.value) == "") {
    alert("Please fill in " + varName + ".");
    varField.focus();
    return false;
    }
  else
    return true;
  }

function checkSelect(varField,varDefault,varName) {
  // This function does not currently support multiple select boxes
  var varValue = null;
  var varType;
  if (varField.length && varField.length > 0 && varField.type && varField.type == "select-one") {
    varType = "select";
    if (varField.selectedIndex)
      varValue = varField.options[varField.selectedIndex].value;
    }
  else if (varField.length && varField.length > 0 && varField[0].type && varField[0].type == "radio") {
    varType = "radio";
    for (var f = 0; f < varField.length; f++) {
      if (varField[f].checked) {
        varValue = varField[f].value;
        break;
        }
      }
    }
  else
    return true;  // some unhandled input type
  if (varValue == null || varValue == varDefault) {
    alert("Please select " + varName + ".");
    if (varType == "radio")
      varField[0].focus();
    else
      varField.focus();
    return false;
    }
  else
    return true;
  }

function checkLength(varField,varName,maxLength,minLength,absoluteLength) {
  var fieldOk  = false;
  var varValue = removeExtraSpaces(varField.value);
  if (absoluteLength == "") {
    if (varValue.length < minLength) {
      if (minLength == 1)
        alert(varName + " you entered is too short. Please make it at least 1 character long.");
      else
        alert(varName + " you entered is too short. Please make it at least " + minLength + " characters long.");
      }
    else if (varValue.length > maxLength)
      alert(varName + " you entered is too long. Please make it less than " + maxLength + " characters long.");
    else
      fieldOk = true;
    }
  else if (varValue.length != absoluteLength) {
    if (absoluteLength == 1)
      alert(varName + " you entered is the wrong length. Please make it 1 character long.");
    else
      alert(varName + " you entered is the wrong length. Please make it " + absolute + " characters long.");
    }
  else
    fieldOk = true;
  if (!fieldOk)
    varField.focus();
  return fieldOk;
  }

/* MISCELLANEOUS SCRIPTS */

function isValidEmailAddress(email) {
/*
  Check email address for valid syntax & structure.
  If regular expressions available (as of JavaScript 1.2), use that for thorough check.
  (Note that we use an eval statement to prevent earlier browsers from choking on the regex syntax.
  Also note that all the backslashes in the regex pattern have to be escaped as a result.)
  If no regex, just do a simple string check for illegal characters.
*/
  if (!email)
    return false;
  else if (window.RegExp)
    return eval("/^([!#-'\\*\\+\\-\\/-9=\\?A-Z\\^-~]+(\\.[!#-'\\*\\+\\-\\/-9=\\?A-Z\\^-~]+)*|\"[\\x01-\\x09\\x0B\\x0C\\x0E-\\x21\\x23-\\x5B\\x5D-\\x7F]*\")@(([a-zA-Z0-9][-a-zA-Z0-9]*[a-zA-Z0-9]\\.)+[a-zA-Z]{2,}|\\[(([0-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\])$/i.test(email)");
  else {  // Just do a simple check for illegal characters
    var iChars = "*|,\":<>[]{}`\';()&$#%";
    for (var i = 0; i < email.length; i++) {
      if (iChars.indexOf(email.charAt(i)) != -1)
        return false;
      }
    return true;
    }
  }

function removeExtraSpaces(str) {
/*
  Remove any redundant spaces or line returns within the string and eliminate
  leading & trailing spaces and line returns. Requires regular expressions (availabe as of JavaScript 1.2).
  (Note that we use an eval statement to prevent earlier browsers from choking on the regex syntax.
  Also note that all the backslashes in the regex pattern have to be escaped as a result.)
*/
  var output = str;
  if (window.RegExp) {
    output = eval("output.replace(/[ \\t]{2,}/g,' ')");
    output = eval("output.replace(/[\\r\\n]{2,}/g,'\\r\\n')");
    output = eval("output.replace(/^[\\s]*/,'')");
    output = eval("output.replace(/[\\s]*$/,'')");
    }
  return output;
  }

function openResWindow(resPage) {
/*
 With the options specified below for a new window, the outer width of the new window will be approximately
 12 pixels wider than you specify, and the outer height will be approximately 130 pixels taller than you specify.
 Also allow 25 pixels of height for task bar at bottom of screen.
 So, if you want the maximum height for a window, specify a window height 155 pixels less than the height of the screen.
 New SynXis bar window is approximately 812 x 812 pixels (as of 8/1/02).
*/
  var screenHeight = 600; // default to 800x600 screen
  var screenWidth  = 800;
  var winHeight    = 812; // desired height
  var winWidth     = 812; // desired width
  var heightOffset = 155;
  var widthOffset  = 12;
  if (window.screen && window.screen.height && window.screen.height) {
    screenHeight = window.screen.height;
    screenWidth  = window.screen.width;
    }
  if (screenHeight < winHeight)
    winHeight = screenHeight;
  if (screenWidth < winWidth)
    winWidth = screenWidth;
  window.alert("The online reservations will open in a new browser window. The " + site_name + " site will remain open in the background.\n\nYou may need to disable any pop-up blockers you have installed.");
  var resWin = window.open(resPage,"resWin","width=" + (winWidth - widthOffset) + ",height=" + (winHeight - heightOffset) + ",left=0,top=0,location=no,resizable=yes,status=yes,toolbar=yes,menubar=yes,scrollbars=yes");
  }

function popupWindow(url,name,w,h,centered) {
  var screenHeight = 600; // default to 800x600 screen
  var screenWidth  = 800;
  var top = 0, left = 0;
  if (window.screen && window.screen.height && window.screen.height) {
    screenHeight = window.screen.height;
    screenWidth  = window.screen.width;
    }
  screenHeight = screenHeight-40;  // allow room for taskbars, etc.
  screenWidth  = screenWidth-40;
  if ((h == 0) || (screenHeight < h))
    h = screenHeight;
  if ((w == 0) || (screenWidth < w))
    w = screenWidth;
  if (centered) {
    var left = (screen.width - w) / 2;
    var top  = (screen.height - h) / 2;
    }
  var winProps = "toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes,width=" + w + ",height=" + h + ",left=" + left + ",top=" + top + "";
  var popupWin = window.open(url,name,winProps);
  if (parseInt(navigator.appVersion) >= 4)
    popupWin.window.focus();
  }

function openInNewWindow(whichLink,whichLinkText) {
  if (openInNewWindow.arguments.length < 2) whichLinkText = "this link";
  if (window.confirm("Would you like to open " + whichLinkText + " in a new browser window, so that the " + siteName + " site can remain open?\n\nIf so, you may need to disable any pop-up blockers you have installed.")) {
    if (!whichLink.oTarget) whichLink.oTarget = whichLink.target;
    whichLink.target = "_blank";
    }
  else {
    if ((whichLink.oTarget) && (whichLink.oTarget != "_blank")) whichLink.target = whichLink.oTarget;
    else whichLink.target = "";
    }
  }
//-->