/**
 * Modul urceny pro otevirani dalsich oken.
 *
 * dpendencies: CommonFunctions, CrossBrowser
 *
 */
var grOpenWindow = new function (){
  this.inListenerPriority = 980;

  function FindChild(irElement, isTagName, isClassName){
    lrResult = null;
    if(irElement){
      for(var i=0;i<irElement.childNodes.length;i++){
        lrNode = irElement.childNodes.item(i);
        if(lrNode.nodeType == CrossBrowser.GetNodeType('ELEMENT_NODE')){
          if(  ((isTagName == null) || (lrNode.tagName.toLowerCase() == isTagName))
             &&((isClassName == null) || (lrNode.className = isClassName)))
            lrResult = lrNode;
          else
            lrResult = FindChild(lrNode, isTagName, isClassName);
          if(lrResult != null)
            break;
        }
      }
    }
    return lrResult;
  }
  
  this.CapturedClick = function(irElement, inPriority) {
    var lbResult = false;
    switch(irElement.className){
      case 'ExtWindow':
        if(irElement.tagName.toLowerCase() != 'a')
          irElement = FindChild(irElement, 'a', null)
        if(irElement != null)
          this.OpenExtWindow(irElement);
        break;
      case 'HelpWindow':
        this.OpenHelpWindow(irElement);
        break;
    }
    return lbResult;
  }

  this.init = function() {
    if (!CrossBrowser.IsUndefined(grOnClickEventManager)) {
      grOnClickEventManager.addListener(this, null, null, 'ExtWindow', this.inListenerPriority);
      grOnClickEventManager.addListener(this, null, 'a', 'HelpWindow', this.inListenerPriority);
    }
  }

 /**
  * Open next one window
  */
  this.OpenExtWindow = function(irEvent){
    winHelp = window.open(irEvent.href, 'popup', 'menubar=yes,toolbar=yes,location=yes,status=yes,resizable=yes,scrollbars=yes,width=750,height=550,left=0,top=0');
    winHelp.focus();
  }

 /**
  * Open window with a help
  */
  this.OpenHelpWindow = function(irEvent){
    winHelp = window.open(irEvent.href, 'help', 'menubar=no,toolbar=no,location=no,status=no,resizable=yes,scrollbars=yes,width=750,height=550,left=0,top=0');
    winHelp.focus();
  }
}

CrossBrowser.addEventListener(window, 'load', function(){grOpenWindow.init()}, false);


