// Configure pop links

var popupLinkConfig = new Array;

// Usage: popupLinkConfig["classname"] = new Array ( "targetname", "width=550,height=350,scrollbars=yes,resizable=yes,status=yes,toolbar=yes,location=yes,menubar=yes");
popupLinkConfig["pop-help"] = new Array ( "help", "width=620,height=500,scrollbars=yes,resizable=yes");
popupLinkConfig["pop-change"] = new Array ( "change", "width=550,height=400,scrollbars=no,resizable=no");
popupLinkConfig["pop-login"] = new Array ( "login", "width=500,height=250,scrollbars=no,resizable=no");
popupLinkConfig["pop-edit"] = new Array ( "edit", "width=600,height=550,scrollbars=yes,resizable=no");
popupLinkConfig["pop-manage"] = new Array ( "manage", "width=400,height=750,scrollbars=yes,resizable=yes");

// JavaScript functions called at window load
window.onload = function() {
	initPopupLinks();
	setTall();
}

window.onresize = function() {
	setTall();
}

function initPopupLinks()
{
  if (!document.getElementsByTagName) return true;
  var pageLinks = document.getElementsByTagName("a");
  for (var i = 0; i < pageLinks.length; i++) 
  {
    if (((pageLinks[i].className != null) && 
         (pageLinks[i].className != "")) ||
        ((pageLinks[i].parentNode.className != null) && 
         (pageLinks[i].parentNode.className != "")))
    {
      var linkClass = " " + pageLinks[i].className + " ";
      if ((linkClass == "  ") && (pageLinks[i].parentNode.className != ""))
      {
        linkClass = " " + pageLinks[i].parentNode.className + " ";
      }
      for (var theKey in popupLinkConfig) 
      {
        if (linkClass.indexOf(" " + theKey + " ") > -1)
        {
          if ((pageLinks[i].target == "") || (pageLinks[i].target == null))
          {
            pageLinks[i].target = (popupLinkConfig[theKey][0] != "") ? popupLinkConfig[theKey][0] : theKey;
          }
          pageLinks[i].settings = popupLinkConfig[theKey][1];
          pageLinks[i].onclick = popUp;
        }
      }
    }
  }
  return true;
}

function popUp()
{
  newWin = window.open(this.href, this.target, this.settings);
  newWin.focus();
  return false;
}

// Column height balancing by Paul@YellowPencil.com and Scott@YellowPencil.com
function setTall() {
	if (document.getElementById) {

		// Check to see that the right column exists. If not, exit without doing anything.
		var column;
		column=document.getElementById('col-right');
		if (!column) {
			return false;
		}
		
		// the divs array contains references to each column's div element.  
		// Replace 'center' 'right' and 'left' with your own.  
		// Or remove the last one entirely if you've got 2 columns.  Or add another if you've got 4!
		
		var divs = new Array(
		document.getElementById('col-left'),
		document.getElementById('col-right')
		);
		
		// Let's determine the maximum height out of all columns specified
		
		var maxHeight = 0;
		for (var i = 0; i < divs.length; i++) {
			if (divs[i].offsetHeight > maxHeight) maxHeight = divs[i].offsetHeight;
		}
		
		// Let's set all columns to that maximum height
		for (var i = 0; i < divs.length; i++) {
			divs[i].style.height = maxHeight + 'px';

			// Now, if the browser's in standards-compliant mode, the height property
			// sets the height excluding padding, so we figure the padding out by subtracting the
			// old maxHeight from the new offsetHeight, and compensate!  So it works in Safari AND in IE 5.x
			if (divs[i].offsetHeight > maxHeight) {
				divs[i].style.height = (maxHeight - (divs[i].offsetHeight - maxHeight)) + 'px';
			}
		}
	}
}

// Utility to prevent default button event from firing from within multi-line text boxes in FireFox.
// Pass in the client ID of any multi-line text box that resdies within a panel that has a default button set

function PreventSubmitOnEnter(controlId) {

    try {
        if (!document.all) {
            var obj = $get(controlId);
           
            if (obj.addEventListener) { 
                obj.parentNode.addEventListener("keypress",
                    function(e) {
                        if (e && e.keyCode && e.keyCode==13) {
                            e.stopPropagation();
                        }
                    }, false); 
            } 
        }
    } catch (e) {}
}
