﻿/*
  Copyright 2007 Paperheads, All Rights Reserved.
  http://www.paperheads.co.uk
*/

if(typeof(Type) !== 'undefined') {
  Type.registerNamespace("PH.Ethemba");
}
else {
  PH = function() {}
  PH.Ethemba = function() {}
}

PH.Ethemba.ExtranetLogin = function() {
    document.getElementById('extranet_username').value = document.getElementById('input_username').value;
    document.getElementById('extranet_password').value = document.getElementById('input_password').value;
    document.getElementById('extranet_form').submit();
}

PH.Ethemba.SetBackground = function(Url) {
  var oHeadDiv = $get('head');
  if(Url == 'none') {
    oHeadDiv.innerHTML = "";
  } else {
    oHeadDiv.innerHTML = "<embed width='100%' height='100%' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' bgcolor='#000000' allowFullScreen='true' src='" + Url + "'></embed>";
  }
}

PH.Ethemba.ToggleNode = function(node) {
  node = node.parentNode;
  var bExpanded = false;
  
  for(var i=0;i<node.childNodes.length;i++) {
    if(node.childNodes[i].tagName && node.childNodes[i].tagName.toLowerCase() == 'div') {
      if(node.childNodes[i].style.display == 'block') {
        node.childNodes[i].style.display = 'none';
      } else {
        node.childNodes[i].style.display = 'block';
        bExpanded = true;
      }
    }
  }
  
  for(var i=0;i<node.parentNode.childNodes.length;i++) {
    var oSibling = node.parentNode.childNodes[i];
    if(oSibling != node && oSibling.childNodes[2]) {
      oSibling.childNodes[2].style.display = 'none';
    }
  }
}

PH.CheckSearch = function(e, sSearchUrl) {
  var charCode;
  if(window.event) { 
    charCode = e.keyCode;
  } else if(e.which) {
    charCode = e.which;
  }

  if (charCode==13) {
    PH.Search(sSearchUrl);
  } else {
    return true;
  }
}

PH.Search = function(sSearchUrl) {
  var sTerms = "";
  var oSearchTerms = $get('oSearchTerms');
 
  for (i=0;i<oSearchTerms.value.length;i++) {
    if (oSearchTerms.value.charAt(i) == " ") {
      sTerms += "+";
     } else {
      sTerms += oSearchTerms.value.charAt(i);
    }
  }

  sSearchUrl += "?terms=";
  sSearchUrl += escape(sTerms);
  
  window.location.href = sSearchUrl
}

// Notify ScriptManager that this is the end of the script.
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();