function submitOnce(form) {
   submitOnce = blockSubmit;
   return true;
}

function blockSubmit(form) {
   return false;
}

function unhideTopics() {

    if (document.layers) { // NS4
       document.layers['hiddenTopics'].display='block';
    }
    else if (document.all) { // IE4+
       document.all('hiddenTopics').style.display='block';
    }
    else if (document.getElementById) { // NS6 and IE5+
       document.getElementById('hiddenTopics').style.display='block';
    }

   return false;
}

/**
*
* imports another script file
*
**/
function jsImport(file) {

  fileName = file;
  if (file.indexOf(".") >= 0) {
    fileNameParts = file.split(".");
    fileName = "/scripts/" + fileNameParts.join("/") + ".js";
  }

  document.write("<script type=\"text/javascript\" src=\"" + fileName + "\"></script>\n");
}

/**
*  removes children of a node recursively
*  @param node
*     The DOM node whose children will be removed
**/
function removeChildren(node) {
   var childCount = node.childNodes.length;
   for (var i=0; i<childCount; i++) {
      var child = node.childNodes[0];
      node.removeChild(child);
   }
}

/**
* toggles a collapsible section
**/
function toggleSection(sectionName, timeoutDays) {
   headerID = sectionName + "Header";
   bodyID = sectionName + "Body";
   header = document.getElementById(headerID);
   toggleElementVisibility(bodyID);
   if (isElementVisible(bodyID) == true)
      header.className = 'collapsibleSectionHeader collapsibleSectionExpanded';
   else
      header.className = 'collapsibleSectionHeader collapsibleSectionCollapsed';
   if (timeoutDays == null)
      timeoutDays = 1000;
   createCookie(sectionName + "Collapsed", isSectionCollapsed(sectionName), timeoutDays);
}

/**
* @return true if the section matching sectionName is collapsed,
*       otherwise false
*/
function isSectionCollapsed(sectionName) {
   if (isElementVisible(sectionName + "Body"))
      return false;
   else
      return true;
}

/**
*  @return true if the element with the given name is currently visible
*  @param elementID - the 'id of the element in the web page
*/
function isElementVisible(elementID) {
   var element = document.getElementById(elementID);
   if (element.style.visibility != 'hidden' &&
      element.style.display != 'none') {
      return true;
   } else {
      return false;
   }
}

/**
*  toggles the visibility of an element with the given name if showElement is true
*  @param elementID - the 'id of the element in the web page
*  @param show - show the element if this value is true, otherwise hide the element
*
*/
function toggleElementVisibility(elementID, show) {
   if (show == null)
      show = !isElementVisible(elementID);
   if (show == true)
      showElement(elementID);
   else
      hideElement(elementID);
}

/**
*  hides an element with the given ID
*  @param elementID - the 'id' of the element in the web page
*/
function hideElement(elementID) {
   var element = document.getElementById(elementID);
   if (element != null) {
      element.style.display = 'none';
      element.style.visibility = 'hidden';
   }
}

/**
* shows an element with the given ID
* @param elementID - the 'id' of the element in the web page
* @param style - the 'style' of the element, uses 'block' if not specified
*/
function showElement(elementID, style) {
   if (style == null)
      style = 'block';
   var element = document.getElementById(elementID);
   if (element != null) {
      element.style.display = style;
      element.style.visibility = 'visible';
   }
}

/**
*  trims whitespace from the string
*  @param s - the string to trim
*  @return - the trimmed string
*/
function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}


/*****************************************************/
/************* Date Functions ************************/
/*****************************************************/

/**
* @param daysAgo
*    number of days to subtract from date
* @return
*   new javascript date object representing the current date, minus daysAgo
*/
function dateAdd(daysAhead) {
   var date = new Date();
   var days = date.getDate();
   date.setDate(days + daysAhead);
   return date;
}

/**
* adds a text node to an existing element, given the elementID
* @param elementID
*     the elementID of the existing DOM node
* @param text
*     the text to add to the node
**/
function setText(elementID, text) {

  var element = document.getElementById(elementID);
  var oldText = element.childNodes[0];
  var newText = document.createTextNode(text);

  if (oldText == null)
    element.appendElement(newText);
  else
    element.replaceChild(newText, oldText);
}

/**************************************************/
/********** Form Functions ************************/
/**************************************************/
function clearSearchBox(searchBox, defaultValue)
{
   if (searchBox.value == defaultValue)
   {
      searchBox.value = '';
   }
}

function clearSearchBoxRecolor(searchBox, defaultValue, recolor)
{
   if (searchBox.value == defaultValue)
   {
      searchBox.value = '';
   }
   
   searchBox.style.color = recolor;
}

function clearTextInputClass(inputID)
{
   var input = document.getElementById(inputID);
   if(input != null)
   {
      input.className = 'text';
   }
}

function getFormElementValue(element) {

  var value;

  if (element == null)
   alert(elementID + " is null");

  /* select box */
  if (element.type == "select-one") {
     var options = element.options;
     value = options[options.selectedIndex];
  }

  /* text or hidden */
  if (element.type == "hidden" ||
       element.type == "text" ||
       element.type == "textarea")
     value = element.value;

}

/**
*  initializes a form element based on the id and value.
*/
function setFormElementValue(elementID, value) {
  var element = document.getElementById(elementID);

  if (element == null)
  alert(elementID + " is null");

  /* select box */
  if (element.type == "select-one") {
     var options = element.options;
     for (var i=0; i<options.length; i++) {
       if (options[i].value == value)
         options[i].selected = true;
     }
  }

  /* text or hidden */
  if (element.type == "hidden" ||
       element.type == "text" ||
       element.type == "textarea")
     element.value = value;

  /* checkbox */
  if (element.type == "checkbox") {
    if (value==true)
       element.checked = true;
    else
       element.checked = false;
  }

  /* radio box */
  if (element.type == "radio") {
    if (value = element.value)
       element.checked = true;
    else
       element.checked = false;
  }

}

/**
 * changes the text of a button jsp include
 */
function changeButtonText(newText) {
   var newNode = document.createTextNode(newText);
   var button = document.getElementById("saveSearchFormSubmit")
   var buttonDiv = button.childNodes[0];
   var oldNode;
   for (var i=0; i<buttonDiv.childNodes.length; i++) {
      if (buttonDiv.childNodes[i].data != null)
        oldNode = buttonDiv.childNodes[i];
   }
   buttonDiv.replaceChild(newNode, oldNode);
}

/***************************************************/
/************ Cookie Functions *********************/
/***************************************************/

/* creates a cookie with the given name and value, set to expire after days */
function createCookie(name,value,days)
{
   if (days)
   {
      var date = new Date();
      date.setTime(date.getTime()+(days*24*60*60*1000));
      var expires = "; expires="+date.toGMTString();
   }
   else var expires = "";
   document.cookie = name+"="+value+expires+"; path=/";
}

/* reads the cookie with the given name */
function readCookie(name)
{
   var nameEQ = name + "=";
   var ca = document.cookie.split(';');
   for(var i=0;i < ca.length;i++)
   {
      var c = ca[i];
      while (c.charAt(0)==' ') c = c.substring(1,c.length);
      if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
   }
   return null;
}

/* deletes the cookie with the given name */
function eraseCookie(name)
{
   createCookie(name,"",-1);
}


function isValueInArray(array, value)
{
   for (var index = 0; index < array.length; index++)
      if (array[index] === value)
         return true;

   return false;
}

function changeFormSubmitLocToGoogle(inputID,formID,radioID)
{  
   var input = document.getElementById(inputID);
   var radio = document.getElementById(radioID);
   var form = document.getElementById(formID);
   if(radio.checked)
   {
      var val = 'http://www.google.com/search';
      input.value = 'site:www.experts-exchange.com ' + input.value;
      form.action = val;
   }
}

function addCookieToIFrame(frameID,cookie,value)
{
   document.getElementById(frameID).src = "/setFrameCookie.jsp?id=" + frameID + "&cookie=" + cookie + "&value=" + value;
}

function getElementPositionById(id)
{
   return getElementPosition(document.getElementById(id));
}

function getElementPosition(element)
{
   var left = 0;
   var top = 0;
   if (element.offsetParent)
   {
      left = element.offsetLeft;
      top = element.offsetTop;
      while (element = element.offsetParent)
      {
         left += element.offsetLeft;
         top += element.offsetTop;
      }
   }

   return [left,top];
}

function scrollToElementById(id)
{
   return scrollToElement(document.getElementById(id));
}

function scrollToElement(element)
{
   var position = getElementPosition(element);
   window.scrollTo(position[0], position[1]);
}

function closeSection(id)
{
   var element = document.getElementById(id);
   element.style.display = 'none';
}

function addCookie(name, value)
{
   var today = new Date();
   today.setTime( today.getTime() );
   var expires = 1000 * 60 * 60 * 24 * 365;
   var expires_date = new Date( today.getTime() + (expires) );
   document.cookie= name + "=" + value + ";path=/" + ";expires=" + expires_date.toGMTString() + ";domain=.experts-exchange.com";
}

function showInfoBox(e, id, positioning)
{
   var source = e.target ? e.target : e.srcElement;
   var posSource = source ? getElementPosition(source) : null;
   var posX = posSource ? posSource[0] : 0;
   var posY = posSource ? posSource[1] : 0;
   var element = document.getElementById(id);
   var style = element.style;

   style.display = "inline";
   
   if (!positioning || !positioning.skipX)
   {
      if (positioning && positioning.right)
      {
         style.left = "";
         style.right = (document.body.clientWidth - posX) + "px";
      }
      else if (!positioning || !positioning.centerX)
      {
         style.right = "";
         style.left = posX + "px";
      }
   }

   if (!positioning || !positioning.skipY)
   {
      if (positioning && positioning.bottom)
         style.top = (posY - element.clientHeight) + "px";
      else if (!positioning || !positioning.centerY)
         style.top = posY + "px";
   }
   
   if (positioning && positioning.centerX && !positioning.skipX)
   {
      style.right = "";
      style.left = ((positioning.centerXBody ? document.body.clientWidth / 2 : posX) - parseInt(element.clientWidth) / 2) + "px";
   }

   if (positioning && positioning.centerY && !positioning.skipY)
      style.top = ((positioning.centerYBody ? document.body.clientHeight / 2 : posY) - parseInt(element.clientHeight) / 2) + "px";
}

function showConfirmBox(e, id, url, positioning) {
   showInfoBox(e, id, positioning);
   document.getElementById("confirmLink" + id).href = url;
}

function showAnswerRatingBox(e, answerID, positioning) {
   showInfoBox(e, "answerRatingBox", positioning);
   document.answerRatingBoxForm.aid.value = answerID;
}

function showAnswerRatingBoxBeta(e, answerID, positioning) {
   showInfoBox(e, "answerRatingBox"+answerID, positioning);
}

function hideInfoBox(id) {
   document.getElementById(id).style.display = "none";
}

function callAsync(url,id) {
   new AsyncInclude(url,id);
}

var currentJSMenuTab = new Array();

function showJSMenuTab(prefix, callback, id)
{
   if (id == currentJSMenuTab[prefix])
      return;
   
   if (currentJSMenuTab[prefix] && document.getElementById(prefix + "MenuItem" + currentJSMenuTab[prefix]))
      document.getElementById(prefix + "MenuItem" + currentJSMenuTab[prefix]).className = "menuItem" + currentJSMenuTab[prefix];
   
   currentJSMenuTab[prefix] = id;

   if (document.getElementById(prefix + "MenuItem" + currentJSMenuTab[prefix]))
      document.getElementById(prefix + "MenuItem" + currentJSMenuTab[prefix]).className = "menuItem" + currentJSMenuTab[prefix] + " currentMenuItem";
   
   if (callback)
      callback(id);
}

function showTPSTab(id)
{
   document.getElementById("tpsContent1").style.display
      = id == 1 ? "block" : "none";
   document.getElementById("tpsContent2").style.display
      = id == 2 ? "block" : "none";
   document.getElementById("tpsContent3").style.display
      = id == 3 ? "block" : "none";
}

function showRzaTab(id)
{
   document.getElementById("rzaContent1").style.display
      = id == 1 ? "block" : "none";
   document.getElementById("rzaContent2").style.display
      = id == 2 ? "block" : "none";
   document.getElementById("rzaContent3").style.display
      = id == 3 ? "block" : "none";
}

function popupAndFocusWindow(url, windowName, features)
{
   var popup = window.open(url, windowName, features);
   popup.focus();
   return false;
}

function popupCSCHelpSized(width, height)
{
   return popupAndFocusWindow('/cscPopup.jsp', 'cscPopup', 'width='+width+',height='+height+',resizable=yes');
}

function popupCSCHelpXPSkin()
{
   return popupCSCHelpSized(615, 520);
}

function popupCSCHelpExpertSkin()
{
   return popupCSCHelpSized(740, 630);
}

function popupCSCHelp()
{
   return popupCSCHelpXPSkin();
}

function showLoginPopup(obj)
{
   var curleft = 0, curtop = 0;
   
   do {
   curleft += obj.offsetLeft;
   curtop += obj.offsetTop;
   } while (obj = obj.offsetParent);
   
   var style = document.getElementById('loginPopup').style;
   
   style.left = curleft + "px";
   style.top = curtop + "px";
   style.display = "block";
   style.visibility = "visible";
}

function closeLoginPopup()
{
   hideElement('loginPopup');
}

function slidingMenuObject(viewportId, sliderId, sliderName, slideDistance, movePace, zoneId, asyncPath, scrollerID, prefix)
{
   this.sliderName = sliderName;
   this.menuLevels = new Array();
   this.menuLevels[0] = zoneId;
   this.asyncPath = asyncPath;
   this.currentMenu = -1;
   this.viewport = document.getElementById(viewportId);
   this.slideLeftDistance = parseInt(slideDistance);
   this.slideRightDistance = slideDistance * -1;
   this.sliderObject = new sliderObject(sliderName, sliderId, slideDistance, movePace, scrollerID);
   this.hideMe = 0;
   this.anchorObj = null;
   this.hideTimeout = null;
   this.prefix = prefix ? prefix : "";
   
   this.show = function(obj, doOffset)
   {  
      var curleft = 0, curtop = obj.offsetHeight;
      
      if (doOffset)
      {
         do
         {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
         } while (obj = obj.offsetParent);
      }
      
      var style = this.viewport.style;
      
      var rightEdge = curleft + this.slideLeftDistance;
      
      var wDiff = 0;
      if (window.innerWidth)
      {
         wDiff = rightEdge - (window.innerWidth - 15);
      }
      else if (document.body.clientWidth)
      {
         wDiff = rightEdge - document.body.clientWidth;
      }
      
      if (wDiff > 0)
      {
         curleft = curleft - wDiff;
      }
      
      style.left = curleft + "px";
      style.top = curtop + "px";
      style.display = "block";
      style.visibility = "visible";

      this.viewport.style.display = 'block';
      this.viewport.style.visibility = 'visible';
   }
   
   this.delayHide = function(anchor)
   {
      this.hideMe = 1;
      this.anchorObj = anchor;
      this.hideTimeout = setTimeout(this.sliderName + '.hide()', 250);
   }
   
   this.dontHide = function()
   {
      this.hideMe = 0;
      if (this.hideTimeout != null)
      {
         clearTimeout(this.hideTimeout);
      }
   }
   
   this.hide = function()
   {
      if (this.hideMe > 0)
      {
         this.viewport.style.display = 'none';
         this.viewport.style.visibility = 'hidden';
         this.anchorObj.className = "";
      }
   }
   
   this.slideLeft = function(zoneID, parentChain, scrollToTop, selectedZones)
   {
      if ((this.currentMenu + 1) < this.menuLevels.length)
      {
         if (zoneID != this.menuLevels[this.currentMenu + 1])
         {
            this.removeSubMenus();
            if(selectedZones != null)
            {
               this.createMenuDivWithCheckbox(zoneID, parentChain, selectedZones);
            }
            else
            {
               this.createMenuDiv(zoneID, parentChain);
            }
         }
      }
      else
      {
         if(selectedZones != null)
         {
            this.createMenuDivWithCheckbox(zoneID, parentChain, selectedZones);
         }
         else
         {
            this.createMenuDiv(zoneID, parentChain);  
         }
      }
      
      this.sliderObject.slideLeft(scrollToTop);
      this.currentMenu++;
   }
   
   this.removeSubMenus = function()
   {
      while (this.menuLevels.length > (this.currentMenu + 1))
      {
         var oldMenu = document.getElementById(this.prefix + 'slider_' + (this.menuLevels.length - 1));
         this.sliderObject.mover.removeChild(oldMenu);
         var removedZone = this.menuLevels.pop();
      }
   }
   
   this.createMenuDiv = function(currentZone, parentalChain)
   {
      var newWidth = parseInt(this.sliderObject.mover.style.width ? this.sliderObject.mover.style.width : 0) + this.sliderObject.slideDistance;
      this.sliderObject.mover.style.width = newWidth + 'px';
      
      var sliderDiv = document.createElement('div');
      sliderDiv.className = 'slideable';
      sliderDiv.id = this.prefix + 'slider_' + (this.currentMenu + 1);
      this.sliderObject.mover.appendChild(sliderDiv);
      this.menuLevels[this.currentMenu + 1] = currentZone;
      AsyncInclude(this.asyncPath + this.sliderName + '&zoneRelationID=' + this.menuLevels[this.currentMenu + 1] + '&pChain=' + parentalChain, sliderDiv.getAttribute('id'));
   }
   
   this.createMenuDivWithCheckbox = function(currentZone, parentalChain, selectedArray)
   {
      var newWidth = parseInt(this.sliderObject.mover.style.width ? this.sliderObject.mover.style.width : 0) + this.sliderObject.slideDistance;
      this.sliderObject.mover.style.width = newWidth + 'px';
      
      var sliderDiv = document.createElement('div');
      sliderDiv.className = 'slideable';
      sliderDiv.id = this.prefix + 'slider_' + (this.currentMenu + 1);
      this.sliderObject.mover.appendChild(sliderDiv);
      this.menuLevels[this.currentMenu + 1] = currentZone;
      
      var params = this.asyncPath + this.sliderName + '&zoneRelationID=' + this.menuLevels[this.currentMenu + 1] + '&pChain=' + parentalChain;
      for(var i=0; i< 3; i++)
      {
         if(selectedArray[i]!=null)
            params += '&selected'+i+'='+selectedArray[i].substring(12);
      }
      AsyncInclude(params, sliderDiv.getAttribute('id'));
   }
   
   this.slideRight = function()
   {
      if (this.currentMenu > 0)
      {
         this.sliderObject.slideRight();
         this.currentMenu--;
      }
   }
   
   this.destroy = function()
   {
      if (this.anchorObj != null)
      {
         this.anchorObj.className = "";
      }
      while (this.sliderObject.mover.hasChildNodes())
      {
         this.sliderObject.mover.removeChild(this.sliderObject.mover.firstChild);
      }   
   }
   
   this.createMenuDiv(zoneId, '');
   this.currentMenu = 0;
}

function sliderObject(sliderName, moverID, slideDistance, movePace, scrollerID)
{
   this.name = sliderName;
   this.slideDistance = parseInt(slideDistance);
   this.moveDistance;
   this.movePace = movePace;
   this.slideProgress = 0;
   this.intervalID;
   this.mover = document.getElementById(moverID);
   this.mover.style.left = '0px';
   this.mover.style.width = '0px';
   
   if (scrollerID)
   {
      this.scroller = document.getElementById(scrollerID);
   }
   
   this.moveHoriz = function()
   {
      var lefty = parseInt(this.mover.style.left ? this.mover.style.left : 0);
      this.mover.style.left = lefty + this.moveDistance + 'px';
      this.slideProgress += this.moveDistance;

      if (this.scroller && this.scrollPace)
      {
         this.scroller.scrollTop -= this.scrollPace;
      }

      if (this.slideProgress == this.currentSlideDistance)
      {
         clearInterval(this.intervalID);
      }
   }
   
   this.slideRight = function()
   {
      this.moveDistance = this.movePace;
      this.slideHoriz(this.slideDistance);
   }
   
   this.slideLeft = function()
   {
      if (this.scroller)
      {
         this.scrollDistance = this.scroller.scrollTop;
         this.scrollPace = this.scrollDistance * this.movePace / this.slideDistance;
      }

      this.moveDistance = this.movePace * -1;
      this.slideHoriz(this.slideDistance * -1);
   }
   
   this.slideHoriz = function(slideDistance)
   {
      this.slideProgress = 0;
      this.currentSlideDistance = slideDistance;
      sliderfunction = this.name + '.sliderObject.moveHoriz()';
      this.intervalID = setInterval(sliderfunction, 5);
   }
}

function Size()
{
   var width = 0;
   var height = 0;
}
function getViewportSize()
{
   var size = new Size();

   if (typeof window.innerWidth != "undefined")
   {
      size.width = window.innerWidth ;
      size.height = window.innerHeight ;
   }
   else if (document.documentElement &&
            (typeof document.documentElement.offsetWidth != "undefined") &&
            (document.documentElement.offsetWidth != 0))
   {
      size.width = document.documentElement.offsetWidth ;
      size.height = document.documentElement.offsetHeight ;
   }
   else if (document.body &&
            (typeof document.body.offsetWidth != "undefined"))
   {
      size.width = document.body.offsetWidth ;
      size.height = document.body.offsetHeight ;
   };
   
   return size;
}

function minimize(id, minimize, uncookied)
{
   if (!uncookied)
   {
      var frame = document.getElementById("minimizeFrame");

      if (frame == null)
      {
         frame = document.createElement("IFRAME");
         frame.src = "about:blank";
         frame.id = "minimizeFrame";
         frame.width = 0;
         frame.height = 0;
         frame.style.display = "none";
         document.getElementsByTagName("BODY")[0].appendChild(frame);
      }
      
      frame.src = "/minimize.jsp?id=" + id + "&minimize=" + minimize;
   }

   var section = document.getElementById(id);
   var header = section.childNodes[0];

   if (minimize)
   {
      addClass(section, "ms");
      addClass(header, "mh");
   }
   else
   {
      removeClass(section, "ms");
      removeClass(header, "mh");
   }
   resizeFooter((navigator.appName).indexOf("Microsoft")!=-1);
}

function addClass(element, className)
{
   removeClass(element, className);
   if (element.className)
      element.className += ' ' + className;
   else
      element.className = className
}

function removeClass(element, className)
{
   var newClassName = '';
   if (element && element.className)
   {
      var a = element.className.split(' ');
      for (var i = 0; i < a.length; i++)
      {
         if (a[i] != className)
         {
            if (i > 0)
               newClassName += ' ';
            newClassName += a[i];
         }
      }
      element.className = newClassName;
   }
}

function selectElementById(id)
{
   var element = document.getElementById(id);
   
   if (element.tagName == "TEXTAREA" || (element.tagName == "INPUT" && element.type == "text"))
   {
      element.select();
      return;
   }   
   else if (window.getSelection)
   {
      var selection = window.getSelection();
      var range = document.createRange();
      
      range.selectNodeContents(element);
      selection.removeAllRanges();
      selection.addRange(range);
   }
   else if (document.selection)
   {
      var range = document.body.createTextRange();
      
      document.selection.empty();
      range.moveToElementText(element);
      range.select();
   }
   else
   {
      alert("This feature is not supported by your browser.");
   }
}

function addBetaFeedbackButtonPremium(url)
{
   var button = document.createElement("A");
   button.href = url;
   button.target = "_blank";
   button.className = "betaFeedback";
   document.getElementById("pageMainHeader").appendChild(button);
}

function addBetaFeedbackButtonExpert(url)
{
   var div = document.createElement("DIV");
   div.className = "betaFeedback";
   
   div.appendChild(document.createTextNode("("));
   
   var button = document.createElement("A");
   button.href = url;
   button.target = "_blank";
   button.appendChild(document.createTextNode("Beta Feedback"));
   div.appendChild(button);

   div.appendChild(document.createTextNode(")"));
   
   document.getElementById("pageMainHeader").appendChild(div);
}

function resizeFooter(isIE)
{
   var spacer = document.getElementById('bodyFooterSpacer');
   var windowHeight;
   var bodyHeight;
   var spacerHeight;
   
  if(isIE)
      windowHeight = document.documentElement.clientHeight;
   else
      windowHeight = window.innerHeight;
   
   bodyHeight = document.body.clientHeight;
   
   spacerHeight = windowHeight - (bodyHeight - spacer.offsetHeight);


   if(spacerHeight > 0)
      spacer.style.height = spacerHeight + 'px';
   else
      spacer.style.height = 0;

}

/******* asyncInclude.js code *********/
function AsyncInclude(url, elementID, callBackFunction, changeCache, browser)
{
   // Ready States
   var UNINITIALIZED = 0;
   var OPEN = 1;
   var SENT = 2;
   var RECEIVING = 3;
   var LOADED = 4;
   
   var xmlHttpRequest = null;

   this.getXMLHttpRequest = function()
   {
      var request = null;
      try
      {
         request = new XMLHttpRequest();
      }
      catch (e)
      {
         try
         {
            request = new ActiveXObject("Msxml2.XMLHTTP");
         }
         catch (e)
         {
            request = new ActiveXObject("Microsoft.XMLHTTP");
         }
      }

      return request;
   }

   function changeFunc()
   {
      return function()
      {
         if (xmlHttpRequest.readyState == LOADED)
         {
            var element = elementID ? document.getElementById(elementID) : null;
            
            if (element)
            {
            var element = document.getElementById(elementID);
            if (element.tagName == 'TEXTAREA')
               element.value = xmlHttpRequest.responseText;
            else
               element.innerHTML = xmlHttpRequest.responseText;

            // copy <script> tags into head, so that they will be executed
            var head = document.getElementsByTagName('head')[0];
            var responseScripts = element.getElementsByTagName('script');
            for (var index = 0; index < responseScripts.length; index++)
            {
               var responseScript = responseScripts[index];

               var script = document.createElement('script');
               script.type = 'text/javascript';
               script.defer = true;
               if (responseScript.src)
                  script.src = responseScript.src;
               if (responseScript.text)
                  script.text = responseScript.text;

               head.appendChild(script);
            }
            }

            // call callBackFunction, if applicable
            if (callBackFunction)
            {
               callBackFunction.apply(callBackFunction, arguments);
            }
         }
      }
   }
   
   this.onReadyStateChange = changeFunc();

   xmlHttpRequest = this.getXMLHttpRequest();
   if (xmlHttpRequest == null)
   {
      document.write('Your browser does not support AJAX!');
      return;
   }
   
   if((!changeCache && typeof(browser) == "undefined")  || (typeof(changeCache) == "undefined" && typeof(browser) == "undefined") || (browser != "IE7" && browser != "IE"))
   {
      xmlHttpRequest.onreadystatechange = this.onReadyStateChange;
      xmlHttpRequest.open("GET", url, true);
      xmlHttpRequest.send(null);
   }
   else  //for IE7
   { 
      xmlHttpRequest.onreadystatechange = this.onReadyStateChange;
      xmlHttpRequest.open("GET", url, false);
      xmlHttpRequest.send(null);
      var date = xmlHttpRequest.getResponseHeader("Date");
      if(date == null || !date)
      {
         var cached = xmlHttpRequest;
         xmlHttpRequest = (typeof(XMLHttpRequest) != "undefined") ? new XMLHttpRequest() : new ActiveXObject("Msxml2.XMLHTTP");
         var ifModifiedSince = cached.getResponseHeader("Last-Modified");
         ifModifiedSince = (ifModifiedSince) ? ifModifiedSince : new Date(0); // January 1, 1970
         xmlHttpRequest.onreadystatechange = this.onReadyStateChange;
         xmlHttpRequest.open("GET", url, false);
         xmlHttpRequest.setRequestHeader("If-Modified-Since", ifModifiedSince);
         xmlHttpRequest.send("");
         if(xmlHttpRequest.status == 304)
         {
            xmlHttpRequest = cached;
         }
      }
   }
}

function AsyncPost(url, elementID, parameters, callBackFunction)
{
   // Ready States
   var UNINITIALIZED = 0;
   var OPEN = 1;
   var SENT = 2;
   var RECEIVING = 3;
   var LOADED = 4;

   var xmlHttpRequest = null;

   this.getXMLHttpRequest = function()
   {
      var request = null;
      try
      {
         request = new XMLHttpRequest();
      }
      catch (e)
      {
         try
         {
            request = new ActiveXObject("Msxml2.XMLHTTP");
         }
         catch (e)
         {
            request = new ActiveXObject("Microsoft.XMLHTTP");
         }
      }

      return request;
   }

   function changeFunc()
   {
      return function()
      {
         if (xmlHttpRequest.readyState == LOADED)
         {
            var element = elementID ? document.getElementById(elementID) : null;
            
            if (element)
            {
               if (element.tagName == 'TEXTAREA')
                  element.value = xmlHttpRequest.responseText;
               else
                  element.innerHTML = xmlHttpRequest.responseText;
            
               // copy <script> tags into head, so that they will be executed
               var head = document.getElementsByTagName('head')[0];
               var responseScripts = element.getElementsByTagName('script');
               for (var index = 0; index < responseScripts.length; index++)
               {
                  var responseScript = responseScripts[index];
   
                  var script = document.createElement('script');
                  script.type = 'text/javascript';
                  script.defer = true;
                  if (responseScript.src)
                     script.src = responseScript.src;
                  if (responseScript.text)
                     script.text = responseScript.text;
   
                  head.appendChild(script);
               }
            }
            
            if (callBackFunction)
            {
               callBackFunction.apply(callBackFunction, arguments);
            }
         }
      }
   }
   
   this.onReadyStateChange = changeFunc();

   xmlHttpRequest = this.getXMLHttpRequest();
   if (xmlHttpRequest == null)
   {
      document.write('Your browser does not support AJAX!');
      return;
   }
   
   xmlHttpRequest.onreadystatechange = this.onReadyStateChange;
   xmlHttpRequest.open("POST", url, true);
   xmlHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlHttpRequest.send(parameters);
}


function submitForm(formObject,url,elementID,submitName,callBackFunction)
{
   var parameters = submitName + "=true";
   for(var i=0; i<formObject.length;i++)
   {
      var element = formObject.elements[i];
      var type = element.type;
      if(type == "select-multiple")
      {
         
         for(var j=0; j<element.length;j++)
         {
           if(element.options[j].selected)
           {
              var value = element.options[j].value;
              value = value.replace(/%/g, "%25");
              value = value.replace(/&/g, "%26");
              
              parameters += "&";
              parameters += element.name;
              parameters += "=";
              parameters += value;
           }
         }
      }
      else if(!(type == "radio" || type == "checkbox") || element.checked)
      {
         var value = element.value;
         value = value.replace(/%/g, "%25");
         value = value.replace(/&/g, "%26");
         
         parameters += "&";
         parameters += element.name;
         parameters += "=";
         parameters += value;
      }
   }
   AsyncPost(url,elementID,parameters,callBackFunction);
}


/******* end asyncInclude.js **********/

/******* Popup Overlay code  **********/

function getScroll()
{
   if (document.documentElement)
      return [document.documentElement.scrollLeft, document.documentElement.scrollTop];
   else if (window.pageXOffset)
      return [window.pageXOffset, window.pageYOffset];
}

var overlayScroll = [0, 0];
 
function showPopupOverlay(prefix, width, height, url, hackFooter, hackOverlay, browser)
{
   var outerWrap = document.getElementById('outerWrap');
   //var outerWrap = document.getElementById('outerWrap');outerBodyWrap
   var pageMain = document.getElementById('pageMain');

   var size = getViewportSize();

   var left = (size.width - width) / 2;
   if (left < 0)
      left = 0;
   var top = (size.height - height) / 2;
   if (top < 0)
      top = 0;


   var background = document.createElement('div');
   background.id = getBackgroundID(prefix);
   background.className = 'popupOverlayBackground';
   background.style.height = size.height + 'px';

   var overlay = document.createElement('div');
   overlay.id = getOverlayID(prefix);
   overlay.className = 'popupOverlay';
   overlay.style.width = width + 'px';
   overlay.style.height = height + 'px';
   if (hackFooter)
   {
      document.getElementById('compFL').style.visibility = 'hidden';

      var selects = document.getElementsByTagName('select');
      
      for (i = 0; i < selects.length; i++)
         selects[i].style.visibility = 'hidden';
   }
   if (hackOverlay)
   {  
      background.style.height = document.body.clientHeight + 'px';
      background.style.width = document.body.clientWidth + 'px';
          var outerBodyWrap = document.getElementById('outerBodyWrap');
          var outerWrap = document.getElementById('outerWrap');

      //outerBodyWrap.style.setProperty("backgroundColor", "grey", "!important");
      //outerBodyWrap.style.setProperty("backgroundColor", "#363f47", "!important");
      //outerBodyWrap.style.border= "10px solid blue";
      outerBodyWrap.style.display= "none";
      outerWrap.style.display= "block";

   }
 
  /* overlay.style.left = left + 'px';
   overlay.style.top = top + 'px';

   var overlayBody = document.createElement('div');
   overlayBody.id = prefix + 'OverlayBody';

   overlay.appendChild(overlayBody);

   outerWrap.parentNode.insertBefore(overlay,outerWrap);
   outerWrap.parentNode.insertBefore(background,outerWrap);

   if (url)
      new AsyncInclude(url, overlayBody.id, null, null, browser);

   if (document.layers)
   {
      window.captureEvents(Event.RESIZE) ;
      window.onresize = function(){popupOverlayOnResize(prefix, hackOverlay);} ;
   }
   else if (document.all)
   {
      window.onresize = function(){popupOverlayOnResize(prefix, hackOverlay);} ;
   }
   else if (window.addEventListener)
   {
      window.addEventListener("resize" , function(){popupOverlayOnResize(prefix, hackOverlay);} , false) ;
   };

   overlayScroll = getScroll();   
   window.scrollTo(0, 0);*/
}

function hidePopupOverlay(prefix, hackFooter)
{
   var background = document.getElementById(getBackgroundID(prefix));
   var overlay = document.getElementById(getOverlayID(prefix));

   overlay.parentNode.removeChild(overlay);
   background.parentNode.removeChild(background);
   
   if (hackFooter)
   {
      document.getElementById('compFL').style.visibility = 'visible';

      var selects = document.getElementsByTagName('select');
      
      for (i = 0; i < selects.length; i++)
         selects[i].style.visibility = 'visible';
   }
   
   window.scrollTo(overlayScroll[0], overlayScroll[1]);
}


function popupOverlayOnResize(prefix, hackOverlay)
{
   var overlay = document.getElementById(getOverlayID(prefix));
   var background = document.getElementById(getBackgroundID(prefix));
   if (!overlay)
      return;

   var size = getViewportSize();

   var left = (size.width - overlay.clientWidth) / 2;
   if (left < 0)
      left = 0;
   var top = (size.height - overlay.clientHeight) / 2;
   if (top < 0)
      top = 0;
      
   background.style.height = size.height + 'px';
   if (hackOverlay)
   {  
      background.style.height = document.body.clientHeight + 'px';
      background.style.width = document.body.clientWidth + 'px';
   }
   overlay.style.left = left + 'px';
   overlay.style.top = top + 'px';
}

function resizePopupOverlay(prefix, width, height, hackOverlay)
{
   var overlay = document.getElementById(getOverlayID(prefix));
   
   if (!overlay)
      return;
      
   overlay.style.width = width + 'px';
   overlay.style.height = height + 'px';
   
   popupOverlayOnResize(prefix, hackOverlay);
}

function resizePopupOverlayToElement(prefix, elementID, hackOverlay)
{
   var element = document.getElementById(elementID);
   
   if (!element)
      return;

   resizePopupOverlay(prefix, element.clientWidth, element.clientHeight, hackOverlay);
}

function getBackgroundID(prefix)
{
   return prefix + 'Background';
}
function getOverlayID(prefix)
{
   return prefix + 'Overlay';
}
 
/** End popupOverlay **/