var bDHTMLSaveEditor;
var bMSIE = true;

function selectRadio(radio, index)
{
  var elem = document.getElementsByName(radio);
  elem[index].checked = true;
}

function selectCheckbox(checkbox, index)
{
  var elem = document.getElementsByName(checkbox);
  if (elem[index].checked == true)
    elem[index].checked = false;
  else
    elem[index].checked = true;
}

function highlight(row, value) { //highlights the row
  var selrow = document.getElementById("SelRow");
  var selrowvalue = selrow.value
  if (selrowvalue != "")
    document.getElementById(selrowvalue).className = "listhighlightno";
  selrow.value = row;
  document.getElementById("RowValue").value=value;
  document.getElementById(row).className = "listhighlight";
}

function showhelp(thehitem) { //This shows the right help item and hides the open one if there is an open one
  var thecurrent = document.frm.currenthelp.value;
  if (thecurrent == thehitem) {
    //this means we are clicking on the open one
    thehelpdiv = document.getElementById(thehitem);
    thehelpdiv.style.display="none";
    document.frm.currenthelp.value = 0;
  }
  else {
    //we need to open a help div
    thehelpdiv = document.getElementById(thehitem);
    thehelpdiv.style.display="block";
    document.frm.currenthelp.value = thehitem;
    //now to hide the open one
    if (thecurrent != 0) { //only hide if it not the first
      thehelpdiv = document.getElementById(thecurrent);
      thehelpdiv.style.display="none";
      //now put the current value into the field
    }
  }
}

function linkSubmit(orderby, orderdirection) {
  document.frm.OrderBy.value = orderby;
  document.frm.OrderDirection.value = orderdirection;
  javascript:document.frm.submit();
}

function preloadImages() {
  if(document.images) {
    if(!document.arrImages)
      document.arrImages = new Array();

    var i, j = document.arrImages.length;
    var args = preloadImages.arguments;

    for(i = 0; i < args.length; i++) {
      if (args[i].indexOf("#") != 0) {
        document.arrImages[j] = new Image;
        document.arrImages[j++].src = args[i];
      }
    }
  }
}

function checkAll(obj, chkobj) {
  if (chkobj.length == undefined) {
    chkobj.checked = obj.checked;
    }
  else {
    for (i = 0; i < chkobj.length; i++) {
      chkobj[i].checked = obj.checked;
      }
    }
}

function swapImgRestore() {
  var i, x, a = document.arrSrc;
  for(i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++)
    x.src = x.oSrc;
}

function swapImage() {
  var i, j= 0, x;
  var a = swapImage.arguments;
  document.arrSrc = new Array;
  for(i = 0; i < (a.length - 2); i += 3)
   if ((x = findObject(a[i])) != null) {
    document.arrSrc[j++] = x;
    if(!x.oSrc)
      x.oSrc = x.src;
    x.src = a[i + 2];
  }
}

function findObject(n, d) {
  var p, i, x;
  if((p = n.indexOf("?")) > 0 && parent.frames.length) {
    document = parent.frames[n.substring(p + 1)].document;
    n = n.substring(0, p);
  }
  if(!(x = document[n]) && document.all)
     x=document.all[n];
  for (i = 0; !x && i < document.forms.length; i++)
    x=document.forms[i][n];
  for(i = 0; !x && document.layers && i < document.layers.length; i++)
    x = findObject(n, document.layers[i].document);
  if(!x && document.getElementById)
    x = document.getElementById(n);
  return x;
}

function centerdialog(thewidth, theheight, thesource) { //takes care of the floating dialog and blocker
  var winWidth, winHeight, dialogiframe, newleft, newtop, theblocker;
  dialogiframe = document.getElementById("thedialog");
  theblocker = document.getElementById("blockerbox");
  theblocker.style.width = document.body.scrollWidth;
  theblocker.style.height = document.body.scrollHeight;
  theblocker.style.display = 'block';
  winWidth = (document.all)?document.body.clientWidth:window.innerWidth;
  if (winWidth <= 0) {
    winWidth = document.documentElement.clientWidth;
  }
  winHeight = (document.all)?document.body.clientHeight:window.innerHeight;
  if (winHeight <= 0) {
    winHeight = document.documentElement.clientHeight;
  }
  newleft = (winWidth - thewidth) / 2 +"px";
  newtop = (winHeight - theheight) / 2 +"px";
  dialogiframe.style.width = thewidth +"px";
  dialogiframe.style.height = theheight +"px";
  dialogiframe.style.left = newleft;
  dialogiframe.style.top = newtop;
  dialogiframe.src = thesource;
  dialogiframe.style.display = 'block';
}

function closedialog() {
  dialogiframe = document.getElementById("thedialog");
  dialogiframe.style.display = 'none';
  theblocker = document.getElementById("blockerbox");
  theblocker.style.display = 'none';
}

function goURL(URL) {
  try {
    location.href = URL;
  }
  catch(e) {
    return false;
  }
}

function showField(fld) {
  document.getElementById(fld).className = "rowvisible";
}

function hideField(fld) {
  document.getElementById(fld).className = "hidden";
}

function checkContact() {
  var Role = document.getElementById("Role");
  if ((Role.value=='2' ) || (Role.value=='3')) {
    document.getElementById("McNameField").className = "rowvisible";
    document.getElementById("McEmailField").className = "rowvisible";
    document.getElementById("McPhoneField").className = "rowvisible";
    document.getElementById("McCompanyField").className = "rowvisible";
    document.getElementById("McSiteField").className = "rowvisible";
  }
  else {
    document.getElementById("McNameField").className = "hidden";
    document.getElementById("McEmailField").className = "hidden";
    document.getElementById("McPhoneField").className = "hidden";
    document.getElementById("McCompanyField").className = "hidden";
    document.getElementById("McSiteField").className = "hidden";
  }
}

function call(str) {
  return eval(str)
}

function showHideContact(){ //decides whether to show or hide the main contact fields
  var Role = document.getElementById("roleselect");
  if ((Role.value=='2' )) {
    document.getElementById("contactheader").className = "rowvisiblevisible";
    document.getElementById("contactform").className = "rowvisiblevisible";
  }
  else {
    document.getElementById("contactheader").className = "hidden";
    document.getElementById("contactform").className = "hidden";
  }
}

function part(){ //acts when the participation dropdown is used
  var Participate = document.getElementById("participation");
  if ((Participate.value=='1' )) {
    document.getElementById("role").className = "rowvisible";
  }
  else {
    document.getElementById("role").className = "hidden";
  }
if ((Participate.value=='3' )) {
    document.getElementById("reasonheader").className = "rowvisible";
    document.getElementById("reasonform").className = "rowvisible";
  }
  else {
    document.getElementById("reasonheader").className = "hidden";
    document.getElementById("reasonform").className = "hidden";
  }
if ((Participate.value=='4' )) {
    document.getElementById("contactheader").className = "rowvisible";
    document.getElementById("contactform").className = "rowvisible";
  }
  else {
    document.getElementById("contactheader").className = "hidden";
    document.getElementById("contactform").className = "hidden";
  }
}

// JavaScript Document
//<![CDATA[

//*****************************************************************************
// Do not remove this notice.
//
// Copyright 2000-2004 by Mike Hall.
// See http://www.brainjar.com for terms of use.
//*****************************************************************************

//----------------------------------------------------------------------------
// Code to determine the browser and version.
//----------------------------------------------------------------------------

function Browser() {

  var ua, s, i;

  this.isIE    = false;  // Internet Explorer
  this.isOP    = false;  // Opera
  this.isNS    = false;  // Netscape
  this.version = null;

  ua = navigator.userAgent;

  s = "Opera";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isOP = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as Netscape 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }

  s = "MSIE";
  if ((i = ua.indexOf(s))) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
}

var browser = new Browser();

//----------------------------------------------------------------------------
// Code for handling the menu bar and active button.
//----------------------------------------------------------------------------

var activeButton = null;

/* [MODIFIED] This code commented out, not needed for activate/deactivate
   on mouseover.

// Capture mouse clicks on the page so any active button can be
// deactivated.

if (browser.isIE)
  document.onmousedown = pageMousedown;
else
  document.addEventListener("mousedown", pageMousedown, true);

function pageMousedown(event) {

  var el;

  // If there is no active button, exit.

  if (activeButton == null)
    return;

  // Find the element that was clicked on.

  if (browser.isIE)
    el = window.event.srcElement;
  else
    el = (event.target.tagName ? event.target : event.target.parentNode);

  // If the active button was clicked on, exit.

  if (el == activeButton)
    return;

  // If the element is not part of a menu, reset and clear the active
  // button.

  if (getContainerWith(el, "DIV", "menu") == null) {
    resetButton(activeButton);
    activeButton = null;
  }
}

[END MODIFIED] */

function buttonClick(event, menuId) {

  var button;

  // Get the target button element.

  if (browser.isIE)
    button = window.event.srcElement;
  else
    button = event.currentTarget;

  // Blur focus from the link to remove that annoying outline.

  button.blur();

  // Associate the named menu to this button if not already done.
  // Additionally, initialize menu display.

  if (button.menu == null) {
    button.menu = document.getElementById(menuId);
    if (button.menu.isInitialized == null)
      menuInit(button.menu);
  }

  // [MODIFIED] Added for activate/deactivate on mouseover.

  // Set mouseout event handler for the button, if not already done.

  if (button.onmouseout == null)
    button.onmouseout = buttonOrMenuMouseout;

  // Exit if this button is the currently active one.

  if (button == activeButton)
    return false;

  // [END MODIFIED]

  // Reset the currently active button, if any.

  if (activeButton != null)
    resetButton(activeButton);

  // Activate this button, unless it was the currently active one.
  if (button != activeButton) {
    depressButton(button);
    activeButton = button;
  }
  else
    activeButton = null;

  return false;
}

function buttonMouseover(event, menuId) {

  var button;

  // [MODIFIED] Added for activate/deactivate on mouseover.

  // Activates this button's menu if no other is currently active.

  if (activeButton == null) {
    buttonClick(event, menuId);
    return;
  }

  // [END MODIFIED]

  // Find the target button element.

  if (browser.isIE)
    button = window.event.srcElement;
  else
    button = event.currentTarget;

  // If any other button menu is active, make this one active instead.

  if (activeButton != null && activeButton != button)
    buttonClick(event, menuId);
}

function depressButton(button) {

  var x, y;

  // Update the button's style class to make it look like it's
  // depressed.
  if (button.menu.id == 'home')
  {
    button.className += " menuButtonActiveHome";
  }
  else
  {
    button.className += " menuButtonActive";
  }
  // [MODIFIED] Added for activate/deactivate on mouseover.

  // Set mouseout event handler for the button, if not already done.

  if (button.onmouseout == null)
    button.onmouseout = buttonOrMenuMouseout;
  if (button.menu.onmouseout == null)
    button.menu.onmouseout = buttonOrMenuMouseout;

  // [END MODIFIED]

  // Position the associated drop down menu under the button and
  // show it.

  x = getPageOffsetLeft(button);
  y = getPageOffsetTop(button) + button.offsetHeight;

  // For IE, adjust position.

  if (browser.isIE) {
    x += button.offsetParent.clientLeft;
    y += button.offsetParent.clientTop;
  }

  button.menu.style.left = x + "px";
  button.menu.style.top  = y- 2 + "px";
  button.menu.style.visibility = "visible";

  // For IE; size, position and show the menu's IFRAME as well.

  if (button.menu.iframeEl != null)
  {
    button.menu.iframeEl.style.left = button.menu.style.left;
    button.menu.iframeEl.style.top  = button.menu.style.top;
    button.menu.iframeEl.style.width  = button.menu.offsetWidth + "px";
    button.menu.iframeEl.style.height = button.menu.offsetHeight + "px";
    button.menu.iframeEl.style.display = "";
  }
}

function resetButton(button) {

  // Restore the button's style class.
  if (button.menu.id == 'home')
  {
    removeClassName(button, "menuButtonActiveHome");
  }
  else
  {
    removeClassName(button, "menuButtonActive");
  }

  // Hide the button's menu, first closing any sub menus.

  if (button.menu != null) {
    closeSubMenu(button.menu);
    button.menu.style.visibility = "hidden";

    // For IE, hide menu's IFRAME as well.

    if (button.menu.iframeEl != null)
      button.menu.iframeEl.style.display = "none";
  }
}

//----------------------------------------------------------------------------
// Code to handle the menus and sub menus.
//----------------------------------------------------------------------------

function menuMouseover(event) {

  var menu;

  // Find the target menu element.

  if (browser.isIE)
    menu = getContainerWith(window.event.srcElement, "DIV", "menu");
  else
    menu = event.currentTarget;

  // Close any active sub menu.

  if (menu.activeItem != null)
    closeSubMenu(menu);
}

function menuItemMouseover(event, menuId) {

  var item, menu, x, y;

  // Find the target item element and its parent menu element.

  if (browser.isIE)
    item = getContainerWith(window.event.srcElement, "A", "menuItem");
  else
    item = event.currentTarget;
  menu = getContainerWith(item, "DIV", "menu");

  // Close any active sub menu and mark this one as active.

  if (menu.activeItem != null)
    closeSubMenu(menu);
  menu.activeItem = item;

  // Highlight the item element.

  item.className += " menuItemHighlight";

  // Initialize the sub menu, if not already done.

  if (item.subMenu == null) {
    item.subMenu = document.getElementById(menuId);
    if (item.subMenu.isInitialized == null)
      menuInit(item.subMenu);
  }

  // [MODIFIED] Added for activate/deactivate on mouseover.

  // Set mouseout event handler for the sub menu, if not already done.

  if (item.subMenu.onmouseout == null)
    item.subMenu.onmouseout = buttonOrMenuMouseout;

  // [END MODIFIED]

  // Get position for submenu based on the menu item.

  x = getPageOffsetLeft(item) + item.offsetWidth;
  y = getPageOffsetTop(item);

  // Adjust position to fit in view.

  var maxX, maxY;

  if (browser.isIE) {
    maxX = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft) +
      (document.documentElement.clientWidth != 0 ? document.documentElement.clientWidth : document.body.clientWidth);
    maxY = Math.max(document.documentElement.scrollTop, document.body.scrollTop) +
      (document.documentElement.clientHeight != 0 ? document.documentElement.clientHeight : document.body.clientHeight);
  }
  if (browser.isOP) {
    maxX = document.documentElement.scrollLeft + window.innerWidth;
    maxY = document.documentElement.scrollTop  + window.innerHeight;
  }
  if (browser.isNS) {
    maxX = window.scrollX + window.innerWidth;
    maxY = window.scrollY + window.innerHeight;
  }
  maxX -= item.subMenu.offsetWidth;
  maxY -= item.subMenu.offsetHeight;

  if (x > maxX)
    x = Math.max(0, x - item.offsetWidth - item.subMenu.offsetWidth
      + (menu.offsetWidth - item.offsetWidth));
  y = Math.max(0, Math.min(y, maxY));

  // Position and show the sub menu.

  item.subMenu.style.left       = x + "px";
  item.subMenu.style.top        = y + "px";
  item.subMenu.style.visibility = "visible";

  // For IE; size, position and display the menu's IFRAME as well.

  if (item.subMenu.iframeEl != null)
  {
    item.subMenu.iframeEl.style.left    = item.subMenu.style.left;
    item.subMenu.iframeEl.style.top     = item.subMenu.style.top;
    item.subMenu.iframeEl.style.width   = item.subMenu.offsetWidth + "px";
    item.subMenu.iframeEl.style.height  = item.subMenu.offsetHeight + "px";
    item.subMenu.iframeEl.style.display = "";
  }

  // Stop the event from bubbling.

  if (browser.isIE)
    window.event.cancelBubble = true;
  else
    event.stopPropagation();
}

function closeSubMenu(menu) {

  if (menu == null || menu.activeItem == null)
    return;

  // Recursively close any sub menus.

  if (menu.activeItem.subMenu != null) {
    closeSubMenu(menu.activeItem.subMenu);
    menu.activeItem.subMenu.style.visibility = "hidden";

    // For IE, hide the sub menu's IFRAME as well.

    if (menu.activeItem.subMenu.iframeEl != null)
      menu.activeItem.subMenu.iframeEl.style.display = "none";

    menu.activeItem.subMenu = null;
  }

  // Deactivate the active menu item.

  removeClassName(menu.activeItem, "menuItemHighlight");
  menu.activeItem = null;
}

// [MODIFIED] Added for activate/deactivate on mouseover. Handler for mouseout
// event on buttons and menus.

function buttonOrMenuMouseout(event) {

  var el;

  // If there is no active button, exit.

  if (activeButton == null)
    return;

  // Find the element the mouse is moving to.

  if (browser.isIE)
    el = window.event.toElement;
  else if (event.relatedTarget != null)
      el = (event.relatedTarget.tagName ? event.relatedTarget : event.relatedTarget.parentNode);

  // If the element is not part of a menu, reset the active button.

  if (getContainerWith(el, "DIV", "menu") == null) {
    resetButton(activeButton);
    activeButton = null;
  }
}

// [END MODIFIED]

//----------------------------------------------------------------------------
// Code to initialize menus.
//----------------------------------------------------------------------------

function menuInit(menu) {

  var itemList, spanList;
  var textEl, arrowEl;
  var itemWidth;
  var w, dw;
  var i, j;

  // For IE, replace arrow characters.

  if (browser.isIE) {
    menu.style.lineHeight = "2.5ex";
    spanList = menu.getElementsByTagName("SPAN");
    for (i = 0; i < spanList.length; i++)
      if (hasClassName(spanList[i], "menuItemArrow")) {
        spanList[i].style.fontFamily = "Webdings";
        spanList[i].firstChild.nodeValue = "4";
      }
  }

  // Find the width of a menu item.

  itemList = menu.getElementsByTagName("A");
  if (itemList.length > 0)
    itemWidth = itemList[0].offsetWidth;
  else
    return;

  // For items with arrows, add padding to item text to make the
  // arrows flush right.

  for (i = 0; i < itemList.length; i++) {
    spanList = itemList[i].getElementsByTagName("SPAN");
    textEl  = null;
    arrowEl = null;
    for (j = 0; j < spanList.length; j++) {
      if (hasClassName(spanList[j], "menuItemText"))
        textEl = spanList[j];
      if (hasClassName(spanList[j], "menuItemArrow"))
        arrowEl = spanList[j];
    }
    if (textEl != null && arrowEl != null) {
      textEl.style.paddingRight = (itemWidth
        - (textEl.offsetWidth + arrowEl.offsetWidth)) + "px";
      // For Opera, remove the negative right margin to fix a display bug.
      if (browser.isOP)
        arrowEl.style.marginRight = "0px";
    }
  }

  // Fix IE hover problem by setting an explicit width on first item of
  // the menu.

  if (browser.isIE) {
    w = itemList[0].offsetWidth;
    itemList[0].style.width = w + "px";
    dw = itemList[0].offsetWidth - w;
    w -= dw;
    itemList[0].style.width = w + "px";
  }

  // Fix the IE display problem (SELECT elements and other windowed controls
  // overlaying the menu) by adding an IFRAME under the menu.

  if (browser.isIE) {
    var iframeEl = document.createElement("IFRAME");
    iframeEl.frameBorder = 0;
    iframeEl.src = "javascript:;";
    iframeEl.style.display = "none";
    iframeEl.style.position = "absolute";
    iframeEl.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)";
    menu.iframeEl = menu.parentNode.insertBefore(iframeEl, menu);
  }

  // Mark menu as initialized.

  menu.isInitialized = true;
}

//----------------------------------------------------------------------------
// General utility functions.
//----------------------------------------------------------------------------

function getContainerWith(node, tagName, className) {

  // Starting with the given node, find the nearest containing element
  // with the specified tag name and style class.

  while (node != null) {
    if (node.tagName != null && node.tagName == tagName &&
        hasClassName(node, className))
      return node;
    node = node.parentNode;
  }

  return node;
}

function hasClassName(el, name) {

  var i, list;

  // Return true if the given element currently has the given class
  // name.

  list = el.className.split(" ");
  for (i = 0; i < list.length; i++)
    if (list[i] == name)
      return true;

  return false;
}

function removeClassName(el, name) {

  var i, curList, newList;
var tempList = new Array();
  if (el.className == null)
    return;

  // Remove the given class name from the element's className property.

  newList = new Array();
  curList = el.className.split(" ");
  for (i = 0; i < curList.length; i++)
    if (curList[i] != name)
  {
     tempList[i] = curList[i];
   newList[i] = tempList[i];
  }
  el.className = newList.join(" ");
}

function getPageOffsetLeft(el) {

  var x;

  // Return the x coordinate of an element relative to the page.

  x = el.offsetLeft;
  if (el.offsetParent != null)
    x += getPageOffsetLeft(el.offsetParent);

  return x;
}

function getPageOffsetTop(el) {

  var y;

  // Return the x coordinate of an element relative to the page.

  y = el.offsetTop;
  if (el.offsetParent != null)
    y += getPageOffsetTop(el.offsetParent);

  return y;
}


//]]>

function createwin(newpage) {
  window.open(newpage, "mblastwin", "height=580,scrollbars=yes,menubar=no,toolbar=no,location=no,resizable=yes,width=780,top=10,left=10");
}


function showMsgBox(divMsgBox) {
  var x = document.body.offsetWidth;
  var y = document.body.offsetHeight;
  divMsgBox.style.posLeft = document.body.scrollLeft + x / 2 - 200;
  divMsgBox.style.posTop = document.body.scrollTop + y / 2 - 50;
  divMsgBox.style.display = "block";
  var divEkit = document.getElementById("divEkit");
  if (divEkit != null)
    divEkit.style.visibility = "hidden";

}

function showHideLayers() {
  var i, p, v, obj;
  var args = showHideLayers.arguments;
  for (i = 0; i < (args.length - 2);  i += 3)
    if ((obj = findObj(args[i])) != null) {
      v = args[i + 2];
      if (obj.style) {
        obj = obj.style;
        v= (v == 'show')?'visible':(v=='hide')?'hidden':v;
      }
      obj.visibility=v;
    }
}

function locateLogo()
{
  var therow = document.thelist.selitem.value;//gets the hidden field value
  var e;
  var r = null;
  eval ("e = document.thelist.r"+ therow);
  if (e.parentNode && e.parentNode.parentNode) {
      r = e.parentNode.parentNode;
    }
    else if (e.parentElement && e.parentElement.parentElement) {
      r = e.parentElement.parentElement;
    }
  if (r.className == "listhighlight") {
    parent.closedialog();
  }
  else {
    alert("Please select logo")
  }
}

function findObj(theObj, theDoc) {
  var p, i, foundObj;
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length) {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++)
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  return foundObj;
}

function updateCharactersRemaining(fldID, maxLength) {
var fld = document.getElementById(fldID );
var fldInf = document.getElementById(fldID + 'Inf');

  if(fld.value.length > maxLength )
    setTextToElt(fldInf, '0');
  else
    setTextToElt(fldInf, maxLength - fld.value.length);
}

function limitTEXTAREALength(fldID, maxLength){
var fldTEXTAREA = document.getElementById(fldID );

  if(fldTEXTAREA.value.length > maxLength ){
    fldTEXTAREA.value = fldTEXTAREA.value.substring(0, maxLength);
    updateCharactersRemaining(fldID, maxLength);
  }
  return false;
}

function treeCheck(el) {
  if(el.checked)
    treeCheckParent(el.value);
  else {
    treeUncheckChild(el.value);
    treeUncheckSingleParent(el.value);
  }
}

function clsTree() {
  this.elements = document.all["CheckedDetails"];
  this.list = new Array();
  this.top = new clsNode(null, 0, null, "");
  this.list.push(this.top);
  this.chosen = document.getElementById("DivChosenDetails");
  var f = document.frm.elements['MaxCheckNum'];
  if (f != null) this.maxchecks = f.value;
  else this.maxchecks = 0;
  this.currchecks = 0;
}

function add(nodeId, prntId, name) {
  for(var i = this.list.length - 1; i >= 0 ; i--) {
    var prnt = this.list[i];
    if (prnt.id == prntId) {
      if (typeof this.elements.length != "undefined") {
      	var el = this.elements[this.list.length - 1];
      }
      else {
        var el = this.elements
      };
      var newNode = new clsNode(prnt, nodeId,  name, el);
      prnt.children.push(newNode);
      this.list.push(newNode);
      return;
    }
  }
}

function check(el) {
  if(el.checked) {
    this.calcChosen();
    if (this.maxchecks != 0 && this.currchecks > this.maxchecks) {
      this.currchecks--;
      alert('There is a limit to the number of categories that you may select.  You are not allowed to select more than ' + this.maxchecks + ' categories here.');
      el.checked = false;
      return;
    }
    this.checkParent(el.value);
  }
  else {
    this.uncheckChild(el.value);
    this.uncheckSingleParent(el.value);
  }
  this.displayChosen();
}

function checkParent(id) {
  for (var i = 0; i < this.list.length; i++){
    var n = this.list[i];
    if (n.id == id) {
      var p = n.prnt;
      while(p) {
        if(p.elem)
          p.elem.checked = true;
        p = p.prnt;
      }
      return;
    }
  }
}

function uncheckChild(id) {
  for(var i = 0; i < this.list.length; i++) {
    var n = this.list[i];
    if (n.id == id) {
      this.uncheckSubTree(n);
      return;
    }
  }
}

function uncheckSubTree(n) {
  if (n.children.length == 0)
    this.currchecks--;
  else
    for(var i = 0; i < n.children.length; i++) {
      var child = n.children[i];
      if (child.elem.checked) {
        child.elem.checked = false;
        this.uncheckSubTree(child);
      }
    }
}

function uncheckSingleParent(id) {
  for(var i = 0; i < this.list.length; i++) {
    var n = this.list[i];
    if (n.id == id) {
      this.uncheckParent(n);
      return;
    }
  }
}

function uncheckParent(n) {
    var p = n.prnt;
  if (p) {
    for(var i = 0; i < p.children.length; i++) {
      if (p.children[i].elem && p.children[i].elem.checked)
      return;
    }
    if (p.elem)
      p.elem.checked = false;
    this.uncheckParent(p);
  }
}

function displayChosen() {
  if(this.chosen != null) {
    this.chosen.innerHTML = "";
    this.chosen.style.display = "none";
    addChosenCategory(this.top, this.chosen);
    this.chosen.style.display = "inline";
  }
}

function calcChosen() {
  var checked = false;
  this.currchecks = 0;
  for(var i = 1; i < this.list.length; i++) {
    var n = this.list[i];
    checked = false;
    if (n.elem.checked) {
      if (n.children.length == 0)
        this.currchecks++;
      else {
        for (var j = 0; j < n.children.length; j++)
          if (n.children[j].elem.checked) {
            checked = true;
            break;
          }
        if (!checked)
          this.currchecks++;
      }
    }
  }
  return;
}


function addChosenCategory(n, p) {
  var e = null;
  if (n.name != null && n.name != "") {
    e = document.createElement("DIV");
    e.style.fontSize = "8pt";
    e.style.marginLeft = "18px";
    if (n.elem.type == "hidden")
    {
      e.innerHTML = "<img border=0 height=16 width=16 src=\"/images/hier_t_lst.gif\"><img border=0 height=16 width=16 src=\"/images/hier_fold.gif\">&nbsp;" + n.name + "";
    }
    else {
      e.innerHTML = "<img border=0 height=16 width=16 src=\"/images/hier_t_lst.gif\"><img border=0 height=16 width=16 src=\"/images/hier_fold.gif\">&nbsp;<a href=\"#HD" + n.id + "\">" + n.name + "</a>";
    }
    p.appendChild(e);
    if ((p.id == "DivChosenDetails" && p.childNodes.length > 1) || (p.id != "DivChosenDetails" && p.childNodes.length > 4)) {
      if (p.childNodes[p.childNodes.length - 2].childNodes[0].tagName == "IMG")
        p.childNodes[p.childNodes.length - 2].childNodes[0].src = "/images/hier_t.gif";
      p.childNodes[p.childNodes.length - 2].style.backgroundImage = "url(/images/hier_line.gif)";
      p.childNodes[p.childNodes.length - 2].style.backgroundRepeat = "repeat-y";
    }
    if (p.id != "DivChosenDetails") {
      if (e.childNodes[1].tagName == "IMG")
        p.childNodes[1].src = "/images/hier_fold_open.gif";
    }
  }
  else {
    e = p;
  }
  for(var i = 0; i < n.children.length; i++) {
    if (n.children[i].elem) {
      if ((n.children[i].elem.type == "hidden" && n.children[i].elem.name == "CheckedDetails") || (n.children[i].elem.type == "checkbox" && n.children[i].elem.checked))
        addChosenCategory(n.children[i], e);
    }
  }
}

function clsNode(prnt, id, name, elem) {
  this.children = new Array();
  this.id = id;
  this.name = name;
  this.prnt = prnt;
  this.elem = elem;
}

clsTree.prototype.add = add;
clsTree.prototype.check = check;
clsTree.prototype.checkParent = checkParent;
clsTree.prototype.uncheckChild = uncheckChild;
clsTree.prototype.uncheckSingleParent = uncheckSingleParent;
clsTree.prototype.uncheckSubTree = uncheckSubTree;
clsTree.prototype.uncheckParent = uncheckParent;
clsTree.prototype.displayChosen = displayChosen;
clsTree.prototype.calcChosen = calcChosen;

function is_Empty(fld) {
  if (fld.value == null || fld.value == "")
    return true;
  return false;
}
function validateurl(fld) {
  var surl;
  var pass = true;
  if (is_Empty(fld)) {
    return true;
  }
  if (pass) {
    var surl = fld.value;
    if (surl.indexOf('http://',0) == 0)
      surl = surl.substring(7);
    if ((surl.length < 4) || (surl.indexOf('.',0) < 1)) pass = false;
  }
  if (!pass) {
    alert('Error: URL is incomplete or contains invalid values.');
    if (!fld.disabled)
      fld.focus();
  }
  return pass;
}
function validateEmailNotRequired(fld) {
  if (is_Empty(fld)) {
    return true;
  }
  return validateEmail(fld);
}
function validateEmail(fld) {
  var pass = true;
  var emailPat = /^(.+)@(.+)$/;
  var specialChars = "\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
  var validChars = "\[^\\s" + specialChars + "\]";
  var quotedUser = "(\"[^\"]*\")";
  var ipDomainPat = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
  var atom = validChars + '+';
  var word = "(" + atom + "|" + quotedUser + ")";
  var userPat = new RegExp("^" + word + "(\\." + word + ")*$");
  var domainPat = new RegExp("^" + atom + "(\\." + atom +")*$");
  var matchArray = fld.value.match(emailPat);
  pass = (matchArray != null);
  if (pass) {
    var user = matchArray[1];
    for (i = 0; i < user.length; i++) {
      if (user.charCodeAt(i) > 127)
        pass = false;
    }
  }
  if (pass) {
    var domain = matchArray[2];
    for (i = 0; i < domain.length; i++) {
      if (domain.charCodeAt(i) > 127)
        pass = false;
    }
  }
  if (pass)
    pass = (user.match(userPat) != null);
  if (pass) {
    var atomPat = new RegExp("^" + atom + "$");
    var domArr = domain.split(".");
    var len = domArr.length;
    for (i = 0; i < len; i++) {
      if (domArr[i].search(atomPat )== -1)
        pass = false;
    }
  }
  if (pass)
    pass = (len >= 2);

  if (!pass) {
    alert('Error: "Email address" is incomplete or contains invalid values.');
    if (!fld.disabled)
      fld.focus();
  }
  return pass;
}

function updateCharactersRemaining(fldID, maxLength) {
var fld = document.getElementById(fldID );
var fldInf = document.getElementById(fldID + 'Inf');

  if(fld.value.length > maxLength )
    setTextToElt(fldInf, '0');
  else
    setTextToElt(fldInf, maxLength - fld.value.length);
}

function limitTEXTAREALength(fldID, maxLength){
var fldTEXTAREA = document.getElementById(fldID );

  if(fldTEXTAREA.value.length > maxLength ){
    fldTEXTAREA.value = fldTEXTAREA.value.substring(0, maxLength);
    updateCharactersRemaining(fldID, maxLength);
  }
  return false;
}

function updateRatingTotal(ratingQ)
{ var total = 0;
  var elts, eltWeight;
  var ratingList = document.getElementById(ratingQ+'WList');
  var items = ratingList.value.split(",")
  for (var i=0; i < items.length; i++) {
    elts = document.getElementsByName(items[i]);
    eltWeight = document.getElementById(items[i]+'W');
    for (var j=0; j < elts.length; j++) {
      if (elts[j].checked){
        total = total + elts[j].value*eltWeight.value/100;
      }
    }
  }
  var ratingTotal = document.getElementById(ratingQ+'Total');
  setTextToElt(ratingTotal,total.toFixed(2));
}

function setTextToElt(elt, contentText){
var newText ;
  newText = document.createTextNode(contentText);

  while (elt.childNodes.length > 0 )
    elt.removeChild(elt.lastChild);

  elt.appendChild(newText);
}

function selectCheckbox(chkBox) {
  var elem = document.getElementById(chkBox);
  elem.checked = !elem.checked;
}

function selectRadio(radio, index) {
  var elem = document.getElementsByName(radio);
  elem[index].checked = true;
}

function isOtherSelected(fld, otherfld) {
  this.fld = document.getElementById(fld);
  this.otherfld = document.getElementById(otherfld);

  if (this.fld.value == "[Other]")
    this.otherfld.style.display = 'inline';
  else
    this.otherfld.style.display = 'none';
}

function setOrderVars(orderby, orderdirection) {
  document.frm.OrderBy.value = orderby;
  document.frm.OrderDirection.value = orderdirection;
  javascript:document.frm.submit();
}

function maskKeyPress(fldName, objEvent, strMask) {
  var strWrong = "";
  var reKeyboardChars = /[\x00\x08\x0D\x10\x11\x1B]/;
  var fldW = document.getElementById(fldName + 'Warning');

  if (bMSIE){
    strWrong = String.fromCharCode(objEvent.keyCode);
  } else {
    strWrong = String.fromCharCode(objEvent.which);
  }

  if (strMask.indexOf(strWrong) < 0 && !reKeyboardChars.test(strWrong) ) {
    setTextToElt(fldW,'\''+strWrong+'\' is not allowed here. Please enter numerals (0-9).');
    return false;
  }
  setTextToElt(fldW,'');
  return true;
}

function getInvalidChars(strValue, strMask) {
  var strWrong = "";
  for (i = 0; i < strValue.length; i++) {
   var c = strValue.charAt(i);
    if (strMask.indexOf(c) < 0)
      strWrong += c;
  }
  return strWrong;
}

function maskChange(fldName, objEvent, strMask) {
  var objInput;
  var strWrong = "";
  var fldW = document.getElementById(fldName + 'Warning');

  if (bMSIE)
    objInput = objEvent.srcElement;
  else
    objInput = objEvent.target;

  strWrong = getInvalidChars(objInput.value, strMask);
  if (strWrong.length > 0 ) {
    setTextToElt(fldW,'\''+strWrong+'\' is not allowed here. Please enter numerals (0-9).');
    objInput.value = objInput.validValue || "";
  } else {
    objInput.validValue = objInput.value;
    setTextToElt(fldW,'');
  }
}

function maskPaste(fldName, objEvent, strMask) {
  var strPasteData = window.clipboardData.getData("Text");
  var objInput = objEvent.srcElement;
  var strWrong = "";
  var fldW = document.getElementById(fldName + 'Warning');


  strWrong = getInvalidChars(strPasteData, strMask);
  if (strWrong.length > 0 ) {
    setTextToElt(fldW,'\''+strWrong+'\' is not allowed here. Please enter numerals (0-9).');
    objInput.value = objInput.validValue || "";
    return false;
  } else {
    setTextToElt(fldW,'');
    return true;
  }
}

function dragStart(event, id) {
  var el;
  var x, y;

  // If an element id was given, find it. Otherwise use the element being clicked on.
  dragObj.elNode = document.getElementById(id);

  // Get cursor position with respect to the page.
  if (bMSIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  else {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Save starting positions of cursor and element.
  dragObj.cursorStartX = x;
  dragObj.cursorStartY = y;
  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);

  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;

  // Update element's z-index.
  dragObj.elNode.style.zIndex = ++dragObj.zIndex;

  // Capture mousemove and mouseup events on the page.
  if (bMSIE) {
    document.attachEvent("onmousemove", dragGo);
    document.attachEvent("onmouseup", dragStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  else {
    document.addEventListener("mousemove", dragGo,   true);
    document.addEventListener("mouseup",   dragStop, true);
    event.preventDefault();
  }
}

function dragGo(event) {
  var x, y;

  // Get cursor position with respect to the page.
  if (bMSIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  else {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Move drag element by the same amount the cursor has moved.
  dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
  dragObj.elNode.style.top  = (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";

  if (bMSIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  else
    event.preventDefault();
}

function dragStop(event) {
  // Stop capturing mousemove and mouseup events.
  if (bMSIE) {
    document.detachEvent("onmousemove", dragGo);
    document.detachEvent("onmouseup", dragStop);
  }
  else {
    document.removeEventListener("mousemove", dragGo, true);
    document.removeEventListener("mouseup",   dragStop, true);
  }
}

function logopicklist(el) {
  var gu = document.getElementById('gu')
  centerdialog("600","400","/portal/picklogo.asp?FieldName=" + el + '&gu=' + gu.value)
}

function createWinFromField(fld, nme) {
  var surl = fld.value;
        if (surl.indexOf('http://',0) != 0)
          surl = "http://" + surl
  window.open(surl, "url", "height=500,scrollbars=yes,menubar=yes,toolbar=yes,location=yes,width=780,resizable=yes,top=10,left=10");
}

function createhelpwin(newpage, jumpto) {
  mblasthelp = window.open(newpage, "_blank", "height=560,scrollbars=yes,menubar=no,toolbar=no,location=no,resizable=yes,width=760,top=30,left=30");
}

function linkField(fieldName) {
  var elt = document.getElementById(fieldName + '.Linked');
  elt.value = 1;
  this.fld = document.getElementById(fieldName + 'LDIV');
  this.fld.style.display = 'block';
  this.fld = document.getElementById(fieldName + 'LDIVU');
  this.fld.style.display = 'none';
}

function unlinkField(fieldName) {
  var elt = document.getElementById(fieldName + '.Linked');
  elt.value = 0;
  this.fld = document.getElementById(fieldName + 'LDIV');
  this.fld.style.display = 'none';
  this.fld = document.getElementById(fieldName + 'LDIVU');
  this.fld.style.display = 'block';
}

function updateCharactersRemaining(fld, maxLength) {
  fld.blur;

var fldInf = document.getElementById(fld.name + 'Inf');

  if(fld.value.length > maxLength )
    setTextToElt(fldInf, '0');
  else
    setTextToElt(fldInf, maxLength - fld.value.length);

  fld.focus;
}

function limitTEXTAREALength(fld, maxLength){
  if(fld.value.length > maxLength ){
    fld.value = fld.value.substring(0, maxLength);
    updateCharactersRemaining(fld, maxLength);
  }
  return false;
}

// login timeout routines
var loginTimeout;
var sessionLimit = 1000*60*60; // 60 minutes

function setLoginTimeout() {
  loginTimeout = window.setTimeout(mBLAST.showLoginWindow, sessionLimit);
}

var loginxmlHTTP;

function login() {

  window.clearTimeout(loginTimeout);
  var loginErr = document.getElementById('loginError');
  loginErr.innerHTML = '';
  loginErr.style.display = "none";

  var loginUID = document.getElementById('PopLoginUID').value;
  var loginPWD = document.getElementById('PopLoginPWD').value;
  var loginBrandID = document.getElementById('LoginBrandID').value;
  loginxmlHTTP = false;

  /*@cc_on @*/
  /*@if (@_jscript_version >= 5)
  // JScript gives us Conditional compilation, we can cope with old IE versions.
  // and security blocked creation of the objects.
   try {
     loginxmlHTTP = new ActiveXObject("Msxml2.XMLHTTP");
   } catch (e) {
     try {
       loginxmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");
     } catch (E) {
          loginxmlHTTP = false;
        }
  }
  @end @*/
  if (!loginxmlHTTP && typeof XMLHttpRequest != 'undefined') {
    try {
      loginxmlHTTP = new XMLHttpRequest();
    } catch (e) {
      loginxmlHTTP = false;
      }
    }
  if (!loginxmlHTTP && window.createRequest) {
    try {
      loginxmlHTTP = window.createRequest();
    } catch (e) {
      loginxmlHTTP = false;
      }
  }

  loginxmlHTTP.open("GET", '/ws/sessionlogin.asp?u=' + loginUID + '&p=' + loginPWD + '&b=' + loginBrandID);
  loginxmlHTTP.onreadystatechange = loginResponse;
  loginxmlHTTP.send(null);

}

function loginResponse() {
  if (loginxmlHTTP.readyState == 4) {
    if (loginxmlHTTP.responseText == "") {
      loginTimeout = window.setTimeout(mBLAST.showLoginWindow, sessionLimit);
      mBLAST.hideLoginWindow();
    }
    else {
      var loginErr = document.getElementById('loginError');
      loginErr.innerHTML = loginxmlHTTP.responseText;
      loginErr.style.display = "block";
    }
  }
}

function checkLoginStatus() {

  window.clearTimeout(loginTimeout);
  var loginBrandID = document.getElementById('LoginBrandID').value;

  loginxmlHTTP = false;

  /*@cc_on @*/
  /*@if (@_jscript_version >= 5)
  // JScript gives us Conditional compilation, we can cope with old IE versions.
  // and security blocked creation of the objects.
   try {
     loginxmlHTTP = new ActiveXObject("Msxml2.XMLHTTP");
   } catch (e) {
     try {
       loginxmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");
     } catch (E) {
          loginxmlHTTP = false;
        }
  }
  @end @*/
  if (!loginxmlHTTP && typeof XMLHttpRequest != 'undefined') {
    try {
      loginxmlHTTP = new XMLHttpRequest();
    } catch (e) {
      loginxmlHTTP = false;
      }
    }
  if (!loginxmlHTTP && window.createRequest) {
    try {
      loginxmlHTTP = window.createRequest();
    } catch (e) {
      loginxmlHTTP = false;
      }
  }

  loginxmlHTTP.open("GET", '/cd/ws/checklogin.asp?b=' + loginBrandID + '&r=' + Math.random(), false);
  loginxmlHTTP.send(null);

  if (loginxmlHTTP.responseText == "") {
    return false;
  }
  else {
    return true;
  }
}

function showLoginWindow() {
  var lw = document.getElementById('loginWindow');
  showWindow(lw);
  document.getElementById('PopLoginUID').value = "";
  document.getElementById('PopLoginPWD').value = "";
  createMask();
}

function hideLoginWindow() {
  var lw = document.getElementById('loginWindow');
  lw.style.display = "none";
  removeMask();
}

function showSubmitWindow() {
  var sw = document.getElementById('submitWindow');
  if (sw) {
    showWindow(sw);
    document.getElementById('submitSpinner').innerHTML = "<img src='/images/spinner.gif' border='0' align='middle'>";
    createMask();
  }
}

function hideSubmitWindow() {
  var sw = document.getElementById('submitWindow');
  sw.style.display = "none";
  removeMask();
}

function showWindow(wn) {
  var wth = 0;
  var hgt = 0;

  if (window.innerWidth) {
    wth = window.innerWidth;
    hgt = window.innerHeight;
  }
  else if (document.documentElement && document.documentElement.clientWidth) {
    wth = document.documentElement.clientWidth;
    hgt = document.documentElement.clientHeight;
  }
  else if (document.body) {
    wth = document.body.clientWidth;
    hgt = document.body.clientHeight;
  }

  wn.style.display = "block";
  wn.style.left = (wth - wn.offsetWidth) / 2 + document.body.scrollLeft;
  wn.style.top = (hgt - wn.offsetHeight) / 2 + document.body.scrollTop;
}

var maskElement;

function createMask() {
	if (!document.getElementById("maskWin")) {
    maskElement = document.createElement("iframe");
    maskElement.src = "javascript:void(0);"
    maskElement.id = "maskWin";
    maskElement.style.width = document.body.scrollWidth;
    maskElement.style.height = document.body.scrollHeight;
    maskElement.className = "cssMask";
    document.body.appendChild(maskElement);
	}
	maskElement.style.display = "block";
}

function removeMask() {
	maskElement.style.display = "none";
}
// end of login timeout routines

function showFieldHelp(fld) {
  if (document.getElementById(fld).style.display == 'block') {
    document.getElementById(fld).style.display = 'none';
  }
  else {
    document.getElementById(fld).style.display = 'block';
  }
}

function initializePage() {
  if (window.initFrm) {
	  initFrm();
  }
  if(window.Form) {
    Form.initDefaultButton();
  }
  if (window.refreshJSUploadFrames) {
    refreshJSUploadFrames();
  }
}

function CheckFlash()
{
  var bres = false;
  var ver = deconcept.SWFObjectUtil.getPlayerVersion();

  if (ver['major'] >= 9)  bres = true;

  return bres;
}
