// setup browser flags
agt = navigator.userAgent.toLowerCase();
is_ie5 = (agt.indexOf("msie 5.0") != -1); 

var isOpen = 0;

//overload document.getElementById for IE4
if (document.all && !is_ie5) {
  document.getElementById = function (name) {
    return document.all(name);
  }
}

function boxAction(targetUrl) {
  if (document.getElementById) {
    if (!isOpen) {
      var contents = document.getElementById("fast-find-contents");
      contents.innerHTML = "Loading...";

      var req = newXMLHttpRequest();

      var handlerFunction = getReadyStateHandler(req, updateContent);
      req.onreadystatechange = handlerFunction;  
      req.open("POST", targetUrl, true);
      req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

      req.send("");

      document.getElementById('fast-find').style.display='block';
    } else {
      document.getElementById('fast-find').style.display='none';
    }
    isOpen = 1 - isOpen;
  }
}

/*
 * Updates Fast-find list with retrieved XML (as responseText)
 */
function updateContent(fastfindXML) {
  var contents = document.getElementById("fast-find-contents");
  contents.innerHTML = fastfindXML;
}

function newWindow(url, name, width, height) {
  width += 32;
  height += 75;
  photoWindow = window.open(url, name,"location=no,directories=no,menubar=no,statusbar=no,toolbar=no,scrollbars=yes,height=" +height+ ",width=" +width+ ",resizable=yes");
  photoWindow.resizeTo(width,height);
  photoWindow.focus();
  return false;
}

function checkFieldOn(fld) {
  if (fld.value != '') {
    fld.className = 'form-field-filled';
  } else {
    fld.className = 'form-field-hover'
  }
}

function checkFieldOff(fld) {
  if (fld.value != '') {
    fld.className = 'form-field-filled';
  } else {
    fld.className = 'form-field'
  }
}
function checkFieldOn1(fld) {
  if (fld.value != '') {
    fld.className = 'form-field1-filled';
  } else {
    fld.className = 'form-field1-hover'
  }
}

function checkFieldOff1(fld) {
  if (fld.value != '') {
    fld.className = 'form-field1-filled';
  } else {
    fld.className = 'form-field1'
  }
}

function resetStyles(frm) {
  frm.subject.className = 'form-field';
  frm.name.className    = 'form-field';
  frm.url.className     = 'form-field';
  frm.email.className   = 'form-field';
  frm.phone.className   = 'form-field';
  frm.enquiry.className = 'form-field';
}

function showMessage(id) {
  obj = document.getElementById(id);

  if (obj.style.display == 'none') {
  obj.style.display = 'block';
} else {
  obj.style.display = 'none';
}
}

/* script.js */

/**
 * Attaches an onclick event to each link with rel="external" that opens the
 * link in a new window.
 */
function initExternalLinks() {
  var as = document.getElementsByTagName("a");
  for (var i = 0; i < as.length; i++) {
    if (as[i].getAttribute("rel") == "external") {
      as[i].onclick = openNewWindow;
    }
  }

  function openNewWindow() {
    window.open(this.href);
    return false;
  }
}
