/* the object popupLink handles all popup links of the page */

var popupLink = {

addEvent: function(elm, evType, fn, useCapture)
{
  // cross-browser event handling for IE5+, NS6+ and Mozilla/Gecko
  if (elm.addEventListener)
  {
    elm.addEventListener(evType, fn, useCapture);
    return true;
  } else if (elm.attachEvent)
  {
    var r = elm.attachEvent('on' + evType, fn);
  } else
  {
    elm['on' + evType] = fn;
  }
},

winPopup: function(popupUrl, wName, popupPar)
{
  if ( popupUrl != '' && wName != '' )
  {
    try
    {
      window.open(popupUrl, '' + wName + '', '' + popupPar + '');
      return true;
    } catch(e)
    {
      // don't use characters like "-" (because MSIE don't like that) use "_" instead of "-"
      // alert("wrong character in target attribute!");
      window.open(popupUrl, 'popupWin', '' + popupPar + '');
      return true;
    }
  } else
  {
    window.open(popupUrl);
    return true;
  }
  return false;
},

handleLink: function(e) 
{
  var el;
  el = window.event && window.event.srcElement ? window.event.srcElement : e && e.target ? e.target : false;
  if (!el)
    return;
  
  // prevent stupid event handling of some browsers
  while(el != document.body && el.nodeName.toLowerCase() != 'a' )
    el = el.parentNode;
  
  if(el.nodeName.toLowerCase() != 'a')
    return null;
  
  isPopup = false;
  
  // is there a target attribute? the value of the target is not empty? there is a href attribute?
  if (el.target && el.target != '' && el.href)
  {
    // don't use for the links target characters like "-" (because MSIE don't like that) use "_" instead of "-"
    // set wName to "popupWin" if no "_" was found
    var wName = el.target.indexOf("_") != -1 ? el.target.substring(0, el.target.indexOf("_")) : "popupWin";
    var pWidth = el.target.indexOf("_") != -1 && el.target.indexOf("x") != -1 ? el.target.substring(el.target.indexOf("_")+1, el.target.indexOf("x")) : "600";
    var pHeight = el.target.indexOf("x") != -1 ? el.target.substring(el.target.indexOf("x")+1, el.target.length) : "400";
    
    // build the popup window parameter
    var popupPar = 'width=' + pWidth + ',height=' + pHeight + ',top=0,left=0,resizable=no,scrollbars=no,menubar=no,toolbar=no,status=no,location=no';
    
    if ( popupLink.winPopup(el.href, wName, popupPar) )
      isPopup = true;
	  
	if ( popupLink02.winPopup(el.href, wName, popupPar) )
      isPopup = true;
  // there is no target attribute or its empty
  // open a new browser window
  } else if (el.href)
  {
    if ( popupLink.winPopup(el.href, '', '') )
      isPopup = true;
  }
  if ( isPopup )
  {
    if (window.event)
    {
      window.event.cancleBubble = true;
      window.event.returnValue = false;
    }
    if (e && e.stopPropagation && e.preventDefault)
    {
      e.stopPropagation();
      e.preventDefault();
    }
  }
},

cancelClickSafari: function()
{
  return false;
},

init: function()
{
  if (!document.getElementsByTagName)
    return;
  var all_popuplinks = document.getElementsByTagName('a');
  for (var i = 0; i < all_popuplinks.length; i++)
  {
    var plink = all_popuplinks[i];
    // set an aventListener only if the css class name 'popuplink' will be found
    if ( plink.className && (' ' + plink.className + ' ').indexOf(' popuplink ') != -1 )
    {
      popupLink.addEvent(plink, 'click', popupLink.handleLink, false);
      plink.onclick = popupLink.cancelClickSafari;
      if ( !plink.title && plink.firstChild && plink.firstChild.nodeValue )
        plink.title = plink.firstChild.nodeValue;
    }
  }
}

};

popupLink.addEvent(window, 'load', popupLink.init, false);