if(typeof(CO) == "undefined") 
  var CO = Class.create();

$CO = function(pE)
{
  pE = $(pE)
  
  try { if(!pE.co) pE.co = {}; }
  catch(exc) {}
  return(pE);
}


function getBrowser()
{
check=[
['window.postMessage',
 'window.XMLHttpRequest&&(document.postMessage||window.external)',
 'document.compatMode',
 '(document.detachEvent||document.contentType)'],
['window.execScript','window.pkcs11','window.opera',
                                  'window.navigator&&window.navigator.vendor'],
[['IE 8','FF 3','Op 9.5','KDE?'],
 ['IE 7','FF 2','Op 9','KDE?'],
 ['IE 6','FF 1.5','Op 8','KDE/Safari 3'],
 ['IE 5x','NN 7','Op 7','KDE/Konqu. 3']]];
var j; var b; for(n=0;n<check[1].length;n++){if(!eval(check[1][n])==0)b=n;}
for(n=check[0].length;n>-1;n--){if(!eval(check[0][n])==0)j=n;}
return((j>-1&&b>-1)?check[2][j][b]:'?lterer Browser o. unbekannt.');
}


function isNull(pX)
{
  if(typeof(pX) == "undefined") return(true);
  if(pX == null) return(true);
  return(false);
}

function nvl(pX,pY)
{
  if(isNull(pX)) return(pY);
  return(pX);
}

$E = function(pExc)
{
  if(typeof(pExc) == "object")
  { 
    console.error(nvl(pExc.msg,"JS-Fehler:")); 
    
    if(!isNull(pExc.code)) console.error(pExc.code); 
    
    var stack = pExc.stack;
    pExc.stack = "CO-Bug ==>";
    
    if(!isNull(stack)) stack = stack.replace(/\n/g,"\n\n");
    
    console.dir(pExc); 
    CO.error(stack);     
  }
  else { console.error(pExc); }
  return(false);
}

$V = function(pElements, pMask)
{ 
	pMask = $(pMask);
	
	if(pMask != null)
	{
	  if(typeof(pElements) == "string") 
	  { pElements = pMask.select("[name="+pElements+"]"); }		
	}
  else
	{
	  if(typeof(pElements) == "string") 
	  { pElements = $$("[name="+pElements+"]"); }
	}
	
  var vArray = [];
  if(!Object.isArray(pElements)){vArray.push(pElements.value);}  
  else { pElements.each(function(pItem){vArray.push(pItem.value);}); }
  return(vArray);
}

$NS = function(pNameSpace)
{ 
  vNSpaces = pNameSpace.split(".");
  
  var vActualNS = self;
  
  vNSpaces.each(
    function(pItem)
    {
      if(isNull(vActualNS[pItem])) 
      vActualNS[pItem] = Class.create();
      vActualNS = vActualNS[pItem];
    });
}


//---
//Firebug, wenn Debug ausgeschalten ist
if (!("console" in window) || !("firebug" in console))
{
    var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
    "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

    window.console = {};
    for (var i = 0; i < names.length; ++i)
        window.console[names[i]] = function() {};
}


function debug(){};
function debugErr(){};
function debugMsg(){};


var vDbgFuncs = ["doLog", "debug", "info", "warn", "error", "dir", "dirxml", 
  "logGroup", "logGroupEnd", "time", "timeEnd", "profile", "profileEnd", "countCalls"];
  
for (var i = 0; i < vDbgFuncs.length; ++i)
    CO[vDbgFuncs[i]] = function() {};


// Umrendern der Buttons ----

self.startList = function()
{
	if (document.all && document.getElementById) // only old browsers!
	{
    inputFields = document.getElementsByTagName("input");
		for (i=0; i< inputFields.length; i++)
		{
			if( inputFields[i].getAttribute("type").toLowerCase() == "submit" 
			||  inputFields[i].getAttribute("type").toLowerCase() == "button")
			{
			  inputFields[i].className += " button";
			}
		}
	}

}

startList();


// Erweiterung des DOM-Baums ----

CO.maxZIndex = 101;

Element.addMethods(
{
  
coHide: function(pElement) { pElement.addClassName("invisible"); },

coShow: function(pElement) { pElement.removeClassName("invisible"); },


coToggle: function(pElement, pOptions)
{
  var vOptions = 
  {
    mImg: null
  , onExpand :  function(){}
  , onCollapse: function(){}
  , mExpandIcon:  "expand"
  , mCollapsIcon: "collaps"
  };
  
  pOptions = Object.extend(vOptions, pOptions);
  
  var vImg = $(pOptions.mImg);
  
  if(vImg && (vImg.nodeName != "IMG"))
  {
    vImg = vImg.down("img");
  }
  
  if(pElement.hasClassName("invisible"))
  { 
    pElement.removeClassName("invisible"); 
    if(vImg){vImg.coToggleImg(pOptions.mCollapsIcon);} 
    pOptions.onExpand.call(pOptions.mImg);
  }
  else
  { 
    pElement.addClassName("invisible"); 
    if(vImg){vImg.coToggleImg(pOptions.mExpandIcon);}     
    pOptions.onCollapse.call(pOptions.mImg);
  }
  return(pElement);
},

coSetImg: function(pElement, pImg)
{
  pImg = new CO.Image(pImg);
  if(pElement.nodeName == "IMG")
    pElement.replace(pImg.get());
  else
    pElement.select("img").each(function(pItem){pItem.replace(pImg.get());});
  return(pElement);
},

coToggleImg: function(pElement, pImg1, pImg2)
{
  if(isNull(pImg2)){ pElement.coSetImg(pImg1); return; }
  pImg1 = new CO.Image(pImg1); pImg2 = new CO.Image(pImg2);
  
  if(pElement.nodeName == "IMG")
  {
    if(pImg1.compare(pElement)) pElement.coSetImg(pImg2);
    else pElement.coSetImg(pImg1);
    return; 
  }
  
  pElement.select("img").each(function(pItem)
  {
    if(pImg1.compare(pItem)) pItem.coSetImg(pImg2);
    else pItem.coSetImg(pImg1);
  });
},

coDisable: function(pElement)
{
  if(!pElement.hasClassName("disabled"))
  {
    
    pElement.addClassName("disabled");
    
    $CO(pElement).co.onclicksave = pElement.getAttribute("onclick");
    pElement.setAttribute("onclick", "return(false);");
    
    try{ pElement.blur(); } catch(exc){}
    try{ pElement.disabled = true; } catch(exc){}
  }
  
  return(pElement);
},

coEnable: function(pElement)
{
  pElement.removeClassName("disabled");
  
  if(typeof($CO(pElement).co.onclicksave) != "undefined")
    pElement.setAttribute("onclick", $CO(pElement).co.onclicksave);
  
  try{ pElement.disabled = false; } catch(exc){}
  
  return(pElement);
},

getName: function(pElement)
{
  var vName = "noname";
  
  $$("label[for='"+pElement.id+"']").each(
  function(pItem)
    {
      vName = pItem.innerHTML; 
    });
  
  return(vName);
},

addMsg: function(pElement, pMsg, pType, pOptions)
{
  if(isNull($CO(pElement).co.msgs)) pElement.co.msgs = [];
  var vMsg = CO.msg.addMsg(pMsg, pType, pElement, pOptions);
  pElement.co.msgs.push(vMsg);
  
  return(vMsg);
},

addFatal:     function(pElement, pMsg, pOptions){ return(pElement.addMsg(pMsg, CO.MsgType.fatal,   pOptions)); },
addError:     function(pElement, pMsg, pOptions){ return(pElement.addMsg(pMsg, CO.MsgType.error,   pOptions)); },
addWarning:   function(pElement, pMsg, pOptions){ return(pElement.addMsg(pMsg, CO.MsgType.warning, pOptions)); },
addInfo:      function(pElement, pMsg, pOptions){ return(pElement.addMsg(pMsg, CO.MsgType.info,    pOptions)); },

removeMsgs: function(pElement)
{
  $CO(pElement);
  
  if(typeof(pElement.co.msgs) == "undefined") return;
  
  pElement.co.msgs.each(function(pItem){pItem.remove()});
  
  pElement.co.msgs = [];
},


removeMsg: function(pElement, pMsgObj)
{
  if(typeof(pElement.msgs) == "undefined")
    return(pElement);
  
  if(typeof(pMsgObj) == "undefined")
  {
    while(vItem = pElement.msgs.pop())
    {
      vItem.remove();
    }
  }
  else
  {
    pElement.msgs = pElement.msgs.without(pMsgObj);
    pMsgObj.remove();
  }
  
  return(pElement);
},
  
addOverlay: function(element, pOverlayName)
{
  return(CO.Overlay.create(pOverlayName, element));
},

delOverlay: function(element, pOverlayName)
{
  return(CO.Overlay.remove(pOverlayName, element));
},

//callback: function(element, pUrl, pOptions) { new CO.CBUrl(pUrl, nvl(pOptions, {})).callback(element); },
callback: function(element, pUrl, pOptions){if(isNull(pOptions)) pOptions = {}; pOptions.cbCaller = element;  CO.Callback.request(pUrl, pOptions); },


coFire: function(element, pEvent)
{

  if(document.createEventObject){ var evt = document.createEventObject(); return element.fireEvent('on'+pEvent,evt) }
  else { var evt = document.createEvent("HTMLEvents"); evt.initEvent(pEvent, true, true ); return !element.dispatchEvent(evt); }

},

coGetElementsByName: function(parent, html_name)
{
  var found_children = new Array();
  
  var all_elements = document.getElementsByName(html_name);
  
  function hasParent(element)
  {
    if(element.parentNode == parent)
    {
      return(true);
    }
    if(element.parentNode == document.body)
    {
      return(false);
    }
    return hasParent(element.parentNode);
  }
  
  for (var i=0; i < all_elements.length; i++)
  {
    if(hasParent(all_elements[i]))
    {
      found_children.push(all_elements[i]);
    }
  }

  return(found_children);
},

coSetValue: function(element, pValue)
{
  element.value = pValue;
  if(element.defaultValue != pValue) $(element).coFire("change");
},

/**
 * Erlaubt es mittels JS den RequiredValidator ein- bzw. auszuschalten.
 *
 * @author Dva
 * @date   06.02.2009
 */
coRequired: function( pElement, pRequired )
{
  var _element_ = pElement;
  
  // workaround for IE
  if ( ( Prototype.Browser.IE ) && ( ( pElement.type == "select-one" ) || ( pElement.type == "select-multiple" ) ) )
    _element_ = $( pElement.parentNode.id );

  if ( pRequired )
  {
    if ( !_element_.hasClassName( "MaskRequired" ) )
    {
      // if the element type is one of checkbox-group, radiobutton-group or select-(one,many)
      // instantiate an new NofMOptionsValidator instead of an RequiredValidator
      if ( ( pElement.type == "checkbox-group" )
        || ( pElement.type == "radiobutton-group" )
        || ( pElement.type == "select-one" )
        || ( pElement.type == "select-multiple" )
         )
      {
        var vMaskId       = gVC.getMaskIdForHTMLElement( pElement );
        var vInputElement = eval( "$(\"" + vMaskId + "\")." + pElement.co.name );
        gVC.add( new CO.NofMOptionsValidator( pElement.id, vInputElement, 1 ) );
      }
      else
      {
        gVC.add( new CO.RequiredValidator( pElement ) );
      }
      pElement.observe( "blur", function( pEvent ) { gVC.validate( pElement.id ); } );
      _element_.addClassName( "MaskRequired" );
    }
  }
  else
  {
    if ( _element_.hasClassName( "MaskRequired" ) )
    {
      gVC.removeValidator( pElement.id );
      pElement.stopObserving( "blur", function( pEvent ) { gVC.validate( pElement.id ); } );
      _element_.removeClassName( "MaskRequired" );
    }
  }
}
});


//Event-Funktionen ----
CO.observe  = function(pObj, pType, pOptions, pFunction)
{  
  
  if((pObj == "undefined") || (pObj == null))
  {
    CO.logGroup("Element existiert nicht! Typ:"+pType+"-Event");
      CO.error(pFunction);      
    CO.logGroupEnd();  
    return;
  }

  try
  {
  if(Object.isArray(pObj))
  { pObj.each(function(pElem){ CO.observe(pElem, pType, pOptions, pFunction); }); 
  }
  else
  { Event.observe(pObj, pType, function(pEvent){CO.handle(pEvent, pType, pObj, pOptions, pFunction);}); 
  }
  }
  catch(exc)
  {
    /* alert("bind error: "+pObj);  */
  }

}

CO.checkKey = function(pEvent, pOptions)
{
  vFullfilled = true;
  
  if(pOptions.key == -1)  //anyKey
  {
    if((pEvent.keyCode != 16) && (pEvent.keyCode != 17) && (pEvent.keyCode != 18))
      return(true);
  }

  if(!pOptions.alt)  {pOptions.alt   = false;}
  if(!pOptions.shift){pOptions.shift = false;}
  if(!pOptions.strg) {pOptions.strg  = false;}
  
  if(pOptions.alt   != pEvent.altKey)  { vFullfilled = false; }
  if(pOptions.shift != pEvent.shiftKey){ vFullfilled = false; }
  if(pOptions.strg  != pEvent.ctrlKey) { vFullfilled = false; }
  
  if(pOptions.key)
    if(pOptions.key != pEvent.keyCode){ vFullfilled = false; }
  
  return(vFullfilled);
}

CO.isSubmitAllowed = function( pElement )
{
  vFullfilled = true;

  if ( pElement.readAttribute("type") == "submit" )
  {
    if ( isNull(pElement.pParentMask) 
    || isNull( pElement.pParentMask.pSubmitAllowed) 
    || (! pElement.pParentMask.pSubmitAllowed) )
    { vFullfilled = false; }
  }
  
  return(vFullfilled);
}

CO.handle = function(pEvent, pType, pThis, pOptions, pFunction)
{
  try{ if($(pThis).hasClassName("disabled")) return; } catch(exc){}

  vFullfilled = true;
  
  if(pType == "keydown")
  {
    vFullfilled = CO.checkKey(pEvent, pOptions);
  }

  if ( pType == "click" )
  {
    vFullfilled = CO.isSubmitAllowed( $(pThis) );
  }
  
  if(vFullfilled)
  {
    if(pType == "keydown")
    {
      if(pOptions.key == -1) //anyKey
      {
        pFunction.call(pThis, pEvent, {alt: pEvent.altKey, shift: pEvent.shiftKey, strg: pEvent.ctrlKey, key: pEvent.keyCode});
        return;
      }  
    }
  
    if(pOptions.tempThis)
    {
      pFunction.call(pOptions.tempThis, pEvent, pOptions);
      return;
    }
    else
    { 
      pFunction.call(pThis, pEvent, pOptions); 
    }
  }
}


CO.Page = Class.create();

CO.Page.setSubTitle = function(pString, pWindow)
{
  
}

CO.Page.reload = function()
{ 
  CO.Page.disable();
  location.reload();   
}

CO.Page.loadUrl = function(pUrl)
{
  CO.Page.disable();
  
  if(typeof(pUrl) == "string") location.href = pUrl;
  else location.href = pUrl.get();
}

CO.Page.existsScript = function(pScript)
{
  var vReg = new RegExp("\n", "gi");
  pScript = pScript.replace(vReg, "");

  pScript = new CO.Url(pScript).getBase();
  
  
  if(isNull(CO.Page.mScripts))
  {
    CO.Page.mScripts = [];  
    $$("script").each(
      function(pItem)
      { 
        if(!isNull(pItem.src))
        { 
          CO.Page.mScripts.push(new CO.Url(pItem.src).getBase());
        }
      });
  }
  
  var vExists = false;
  
  CO.Page.mScripts.each(
    function(pItem)
    { 
      if(pItem.indexOf(pScript) != -1) { vExists |= true; }
    });
  
  return(vExists);
}

// Page loader ---

CO.Page.$load = false;
CO.Page.loadCount = 0;

CO.Page.loading = function()
{
  if(!CO.Page.$load){ CO.Page.$load = new Element("div", {"class": "pageLoading"}).update("Loading"); $(document.body).insert({top: CO.Page.$load}); }
  CO.Page.loadCount++;
  CO.Page.$load.style.display = "block";
}

CO.Page.loaded = function()
{
  if(!CO.Page.$load || CO.Page.loadCount==0) return;
  if(CO.Page.loadCount-- == 1) CO.Page.$load.style.display = "none";
}

// Page disable ---

CO.Page.$disable = false;
CO.Page.disableCount = 0;

CO.Page.disable = function()
{
  if(!CO.Page.$disable){ CO.Page.$disable = new Element("div", {"class": "pageDisabled"}); $(document.body).insert({top: CO.Page.$disable}); }
  CO.Page.disableCount++;
  CO.Page.$disable.style.display = "block";
}

CO.Page.enable = function()
{
  if(!CO.Page.$disable || CO.Page.disableCount==0) return;
  if(CO.Page.disableCount-- == 1) CO.Page.$disable.style.display = "none";
}



CO.Page.fixMasks = function(pTimout)
{
  // Firefox 2 only
  if(getBrowser() == "FF 2")
  {
    if(isNull(pTimout)) { window.setTimeout("CO.Page.fixMasks(true)", 1); return; }
    
    $$("div.MaskBackground").each(
      function(pItem)
      {
        if(pItem.style.tableLayout == "fixed")
          pItem.style.tableLayout = "auto";
        else
          pItem.style.tableLayout = "fixed";
      });
  }
}

CO.Page.fixButtons = function( pHiddenFields )
{
    var ButtonS = document.getElementsByTagName("button");
    var noSubmitButtons = 0;
    var vHiddenS = new Object();
    var parent_node;

    if( isNull(self.gNoAutoSubmit) )
    {
        for (buttonIndex=ButtonS.length-1; (buttonIndex >= 0 ) && (noSubmitButtons <= 2); buttonIndex--)
        {
            if ( ButtonS[buttonIndex].getAttribute("type").toLowerCase() == "submit" )
            {
                noSubmitButtons++;
            }
        }
    }
    
    if ( noSubmitButtons >= 2 || (! isNull(self.gNoAutoSubmit)) )
    {
        CO.info('do it!');
        for ( buttonIndex= ButtonS.length - 1; buttonIndex >= 0 ; buttonIndex-- )
        {
            if ( ButtonS[buttonIndex].getAttribute("type").toLowerCase() == "submit" )
            {
                
                if ( isNull( pHiddenFields ) || pHiddenFields )
                {
                    parent_node = ButtonS[buttonIndex];

                    while( (! isNull(parent_node)) && parent_node.tagName != "FORM" )
                    {
                        parent_node = parent_node.parentNode;
                    }
                    
                    if ( ( ! isNull(parent_node) ) && ( parent_node.tagName == "FORM" ) )
                    {
                        vHiddenS[ButtonS[buttonIndex].getAttribute("name")] = parent_node;
                    }

                }
                
                if ( isNull(ButtonS[buttonIndex].getAttribute("onClick")) )
                {
                    ButtonS[buttonIndex].setAttribute("onClick", "try{ $('" + ButtonS[buttonIndex].getAttribute("name") + "').value = '" + ButtonS[buttonIndex].getAttribute("value") + "'; } catch(e){return($E(e) );}" );                
                }
                else
                {
                    ButtonS[buttonIndex].setAttribute("onClick", "try{ $('" + ButtonS[buttonIndex].getAttribute("name") + "').value = '" + ButtonS[buttonIndex].getAttribute("value") + "'; } catch(e){return($E(e) );}; " + ButtonS[buttonIndex].getAttribute("onClick") );                
                }
                
                ButtonS[buttonIndex].removeAttribute("name");
                ButtonS[buttonIndex].removeAttribute("value");                
                ButtonS[buttonIndex].setAttribute("type","button");    
                ButtonS[buttonIndex].Type = "button";


                
                
                
            }
        }
        
        if ( isNull( pHiddenFields ) || pHiddenFields )
        {
            for( var vHidden in vHiddenS )
            {
                var vHiddenInput = document.createElement("input");
                
                // doesnt work in IE! :-( copy the element could be an option.
                //$("button1x").replace(new Element("button", {"type": "button", "id": $("button1x").id}));
                vHiddenInput.setAttribute( "type", "hidden" );
                    
                vHiddenInput.setAttribute( "id", vHidden );                
                vHiddenInput.setAttribute( "name", vHidden );

                vHiddenS[vHidden].appendChild( vHiddenInput );             
            }
            

        }        
    }
}

//Text-Component ----
CO.Text = Class.create(
{  
  initialize: function(pText)
  {
    this.mText = pText;
    this.mReplaceText = pText;
  },
  
  replace: function(pLabel, pValue)
  {
    if(typeof(pLabel) != "string") pLabel = pLabel.get();
    
    var vReg = new RegExp("%"+pLabel+"%", "gi");
    this.mReplaceText = this.mReplaceText.replace(vReg, pValue);
    
    return(this);
  },
  
  get: function()
  {
    vTemp = this.mReplaceText;
    this.mReplaceText = this.mText;
    
    return(vTemp);
  } 
});





//CO.IMGPATH = "https://moco.tugraz.at/dev/img/";
//Text-Component ----
CO.Image = Class.create(
{
  initialize: function(pSrc, pAlt, pOptions)
  {
    if(typeof(pSrc) == "string") this.mSrc  = pSrc;
    else {this.mSrc = nvl(pSrc.mSrc, pSrc.src); pOptions = nvl(pSrc.mOptions, {});}
   
    this.mPath = this.mSrc;
    
    if(this.mPath.search(/\//) == -1)
      this.mPath = CO.IMGPATH+this.mPath;
    
    this.mOptions = {"src": this.mPath, "alt": nvl(pAlt, " ")};
    this.mOptions = Object.extend(this.mOptions, pOptions);
    
    return(this);
  },
  
  compare: function(pImg)
  {
    
    pImg = new CO.Image(pImg);
    if(this.mSrc.search(new RegExp(pImg.mSrc)) != -1) return(true);
    if(pImg.mSrc.search(new RegExp(this.mSrc)) != -1) return(true);
    
    return(false);
  },
  
  get: function()
  { return(new Element("img", this.mOptions)); }  
});


CO.Tools = Class.create();

CO.Tools.cloneOptions = function(pSrcSelectbox, pDestSelectbox, pIncludeOriginalValue)
{
  if(!$(pSrcSelectbox) || !$(pDestSelectbox)) return;
  if($(pSrcSelectbox) == $(pDestSelectbox)) return;
  if($CO(pDestSelectbox).co.isCloned) return;
  $CO(pDestSelectbox).co.isCloned = true;

  if(pIncludeOriginalValue)
  {
    var vValue = $F(pDestSelectbox);
    var vOriginalOption = $(pDestSelectbox).options[$(pDestSelectbox).selectedIndex].innerHTML;
    
    $(pDestSelectbox).update($(pSrcSelectbox).innerHTML);
    
    if(vValue)
    {
      $(pDestSelectbox).insert({top : new Element("option", {"value" : vValue}).update(vOriginalOption)});          
    }
    
    $(pDestSelectbox).options[0].setAttribute("selected", "true");
    $(pDestSelectbox).selectedIndex = 0;
  }
  else
  {
    $(pDestSelectbox).update($(pSrcSelectbox).innerHTML);
  }
}       

CO.Tools.coToggle = function(pElement, pOptions)
{
  pElement = [pElement].flatten();
  
  var vOptions = 
  {
    mImg: null
  , onExpand :  function(){}
  , onCollapse: function(){}
  , mExpandIcon:  "expand"
  , mCollapsIcon: "collaps"
  };
  
  pOptions = Object.extend(vOptions, pOptions);
  
  var vImg = $(pOptions.mImg);
  
  if(vImg && (vImg.nodeName != "IMG"))
  {
    vImg = vImg.down("img");
  }
  
  var vInvisible = pElement.first().hasClassName("invisible");
  
  if(vInvisible)
  {
    if(vImg){vImg.coToggleImg(pOptions.mCollapsIcon);} 
    pOptions.onExpand.call(pOptions.mImg);
    pElement.each(function(elem){ elem.removeClassName("invisible"); });
  }
  else
  {
    if(vImg){vImg.coToggleImg(pOptions.mExpandIcon);}     
    pOptions.onCollapse.call(pOptions.mImg);
    pElement.each(function(elem){ elem.addClassName("invisible"); });
  }

  return(pElement);
}

CO.Tools.deleteEmptyArrays = function(pObject)
{
  var vObject = {};

  Object.keys(pObject).each(
   function(pItem)
   {
     var x = pObject[pItem];
     
     if(x.size == undefined)
     {
       vObject[pItem] = pObject[pItem];
     }
     else
     {
       
       if(x.size() != 0)
       { 
         vObject[pItem] = pObject[pItem];
       } 
     }
   });

  return(vObject);
}

CO.Tools.scrollTo = function(pName)
{
  var vDest = null;

  if($(pName)) vDest = $(pName);
  else vDest = $$("[name="+pName+"]")[0]; 
  
  if(!isNull(vDest)) { if(vDest.focus){ vDest.focus(); } vDest.scrollTo();  window.scrollBy(0, -100); window.scrollTo(0, window.pageYOffset); } 
}

CO.Tools.pixelToEm = function(pixels, el)
  {
    if(typeof(el) == "undefined") el = document.body;
  
  	var tdiv = document.createElement("div");
  	tdiv.style.height = "1em";
  	tdiv.style.position = "absolute";
  	tdiv.style.top = "-1000px";
  	el.appendChild(tdiv);
  	var emValue = tdiv.offsetHeight;
  	el.removeChild(tdiv);
  	var value = pixels/emValue;
  	
  	/*
  	if (Prototype.Browser.IE)
  	  return Math.round(value*100*1.15)/100;
    */
    return Math.round(value*100)/100;
  };

CO.Tools.strToNodes = function(pNodesStr)
{
  var vReg = new RegExp(" ", "gi");
  pNodesStr = pNodesStr.replace(vReg, "");
  var vNodesStrs = pNodesStr.split(",");
  vNodes = [];

  for(var i = 0; i < vNodesStrs.length; ++i)
  {
    vItem = vNodesStrs[i];
    try { vItem = eval(vItem); } catch(exc){}
    
    if(typeof(vItem) == "string")
    { 
      if($(vItem)) vNodes.push($(vItem));
      else CO.error("CO.Tools.strToNodes undefined: "+vItem); 
    }
    else
    {
      if(Object.isArray(vItem)) 
        vNodes = vNodes.concat(vItem);
      else
        vNodes.push(vItem);
    }
  }
  
  return(vNodes);  
}

CO.Tools.joinFunc = function(pFunc1, pFunc2)
{
  if(isNull(pFunc1)) return(pFunc2);
  return(function(){pFunc1(); pFunc2()});
}
  
CO.Window = Class.create();

CO.Window.mBaseUnit = 14;

CO.Window.typeTiny        = {height: 24, width: 32};
CO.Window.typeSmall       = {height: 30, width: 40};
CO.Window.typeNarrow      = {height: 60, width: 45};
CO.Window.typeSmallNarrow = {height: 30, width: 45};
CO.Window.typeNormal      = {height: 45, width: 60};
CO.Window.typeWide        = {height: 45, width: 75};
CO.Window.typeVeryWide    = {type: "VERYWIDE"};
CO.Window.typeFullScreen  = {type: "FULL"};
CO.Window.typeForm        = {type: "FORM"};
CO.Window.typeUser  	  = {type: "USER"};
CO.Window.typeMini  	  = {type: "MINI"};


CO.WIN = function(pAnchor, pType, pCustom)
{
  var vObj  = $(pAnchor);
  var vHref = "";
  
  var vID = "";
  
  if(pCustom && pCustom.name) vID = pCustom.name;
  if(pAnchor.name) vID = pAnchor.name;
  
  var vType = nvl(pType, CO.Window.typeNormal);
  if(typeof(pType) == "string") vType = CO.Window["type"+pType];
  
  var vHref = "";
  
  if(typeof(pAnchor) == "string")
  {
    var vObj  = $(document.body);
    vHref = pAnchor;
  }
  else
  {
    vHref = pAnchor.href;
    
    if(pAnchor.type) 
    { 
      var vUrl = CO.Url.get(pAnchor);
      
      if(!vType.overlay && !vType.destination || getBrowser() == "IE 6")
      {
        // neues normales Fenster
        CO.Url.update(pAnchor);
        vHref = pAnchor.href;
        pCustom = vUrl.getOptions();
        pCustom.parameters = {};
      }
      else
      {        
        pCustom = vUrl.getOptions();
        vHref = vUrl.mBase;
      }
    }
  }
 
  vType.name = vID;
  
  CO.Window.open.apply(vObj, [vHref, vType, pCustom]) ; 
  return(false);
}

CO.OV = function(pAnchor, pType, pHeight, pWidth)
{
  var vType = CO.Window.typeNormal;
  
  if(typeof(pType) == "string") 
    vType = CO.Window["type"+pType];

  vType.overlay = true;
  
  if(pHeight) vType.height = pHeight;
  if(pWidth)  vType.width = pWidth;
  
  CO.WIN(pAnchor, vType);
  return(false);
}

CO.INS = function(pAnchor, pDestinationId, pOnCloseJS)
{
  var vType = {destination: pDestinationId, onclose: pOnCloseJS}
  CO.WIN(pAnchor, vType);
  return(false);
}

var vInsertCount = 1;
var vWindowPosCount;

CO.Window.open = function(pUrl, pType, pCustom)
{
  if(typeof(pUrl) == 'object') pUrl = pUrl.get();
  if(typeof(pType)   == "udefined") pType   = {};
  if(typeof(pCustom) == "udefined") pCustom = {};
  
  var vThis = this;
  
  var vOptions = 
  {
      locationBar: false
    , statusbar:   true
    , toolbar:     false
    , menubar:     false
    
    , scrollbars: true    
    , resizable:  true
    
    , name: "COWindow" + new Date().getTime()   
    
    , overlay:    false
    
    , height: 45
    , width:  60
    , left:   20
    , top:    20
    
    , type: ""
  };
  
  
  // CO.Window.close = function(pCaller){ $(pCaller).fire("window:close"); };
  
  vOptions = Object.extend(vOptions, pType);
  vOptions = Object.extend(vOptions, pCustom);
  
  
  // Insertionmodus
  if(typeof(vOptions.destination) != "undefined")
  {
    var vDest = $(vOptions.destination);
    if(vDest == null){vDest = eval(vOptions.destination);}
    
    vOptions.destination = vDest;
    
    var vDiv = new Element('div', {"id": "idInsert"+vInsertCount});
    
    vDiv.observe("nav:update", function(pEvent){ CO.Window.handleNavEvent(vDiv, pEvent); });
    vDiv.observe("window:close", function(pEvent)
    { 
      if(typeof(vOptions.onclose) != "undefined") vOptions.onclose();
      try{vDiv.remove();} catch(exc){}
      
     	if(vDiv && $CO(vDiv).co.onCloseFunction)
     	  $CO(vDiv).co.onCloseFunction.call();
      
      Event.stop(pEvent); 
    });
    
    vDiv.observe("window:runInOpener", function(pEvent)
    { 
      pEvent.memo.apply(vThis, [pEvent.memo.mValue]);
      Event.stop(pEvent); 
    });
    
    vOptions.destination.update(vDiv);
    
    vOptions.destination = vDiv;
    
    vInsertCount++;
    vOptions.cbCaller = $(vOptions.destination);
    vOptions.subPageNode = vDiv;
    vOptions.requestHeaders = {"Accept": "CALLBACK_INS"};

    CO.Callback.request(pUrl, vOptions);
    
    return;
  }
  
  
  // Fuer folgende Typen gibts keinen Overlaymodus
  if(vOptions.type == "VERYWIDE") vOptions.overlay = false;
  if(vOptions.type == "FORM")     vOptions.overlay = false;

  var vHeight = vOptions.height * CO.Window.mBaseUnit;
  var vWidth  = vOptions.width  * CO.Window.mBaseUnit;    
  
  
  if(getBrowser() == "IE 6")
    vOptions.overlay = false;
  
  if(vOptions.overlay)
  {
    CO.Page.disable();

		var vWindow = $(document.body).addOverlay("idOverlayWindow");
		
		vWindow.observe("window:close", function(pEvent)
		{ 
		  if(typeof(vOptions.onclose) != "undefined") vOptions.onclose();
      CO.Page.enable();
     	var vClosedOV = $(document.body).delOverlay("idOverlayWindow");
     	
     	if(vClosedOV && $CO(vClosedOV).co.onCloseFunction)
     	  $CO(vClosedOV).co.onCloseFunction.call();
     	
		  Event.stop(pEvent); 
		});
		
    vWindow.observe("window:runInOpener", function(pEvent)
    { 
      pEvent.memo.apply(vThis, [pEvent.memo.mValue]);
      Event.stop(pEvent); 
    });
  
    vWindow.addClassName("overlayWindow");
    
    vWindow.update(CO.Window.template);

    var vVieport = document.viewport.getDimensions();
  
    // Anpassung wenn der Bildschrim sehr klein
    vLeft = (vVieport.width / 2) - (vWidth / 2);
    vTop  = (vVieport.height / 2) - (vHeight / 2);
    
    if(vOptions.type == "FULL") { vLeft = 20; vTop  = 20; }
    
    if(typeof(CO.msg) != "undefined")
    {
      vMsgTop = CO.msg.getSize();
      if(vTop <= vMsgTop) vTop = vMsgTop+20;
    }
    
    if(vLeft < 0) vLeft = 0;
    if(vTop  < 0) vTop  = 0;
    
    if(vLeft+vWidth > vVieport.width)  vWidth  = vVieport.width - vLeft;
    if(vTop+vHeight  > vVieport.height) vHeight = vVieport.height - vTop;
  
    if(vOptions.type == "FULL")
    {
      vWindow.setStyle({top: vTop+"px", left: vLeft+"px", bottom: "20px", right: "20px", height:"auto", width:"auto", position: "fixed"});
    }
    else if(vOptions.type == "USER")    	    	
   	{
     	//vWindow.setStyle({margin: "auto"}); 
     	vWindow.setStyle({marginLeft: (-vOptions.width/2)+"em", marginTop: (-vOptions.height/2)+"em" , top: "", left: "", bottom: "" ,right: "", height: vOptions.height+"em", width: vOptions.width+"em", position: "fixed", top: "50%", left: "50%"});       	
    }
    else if(vOptions.type == "MINI")    	    	
    {
    	vWindow.setStyle({top: "0", left: "0", bottom: "0" ,right: "0", height: "", width: "", position: "fixed", visibility: "hidden" }); 
      vOptions.onCustomComplete = CO.Tools.joinFunc(vOptions.onCustomComplete, CO.Window.updateOverlayMini);
    }
    else
		{
   		vWindow.setStyle({top: vTop+"px", left: vLeft+"px", height: vHeight+"px", width: vWidth+"px", position: "fixed"});       	
    }
    
    if(vOptions.type != "FULL")
      vOptions.onCustomComplete = CO.Tools.joinFunc(vOptions.onCustomComplete, CO.Window.setDragable);
    
    vOptions.subPageNode = vWindow;
    vOptions.requestHeaders = {"Accept": "CALLBACK_OV"};
    
    CO.Callback.request(pUrl, vOptions);
  }
  else
  {
    // Anpassung f?r spezielle Fenstertypen
    if(vOptions.type == "FORM")     { vHeight = 1024;               vWidth  = 1280; }   
    if(vOptions.type == "FULL")     { vHeight = screen.height;      vWidth  = screen.width; }   
    if(vOptions.type == "VERYWIDE") { vHeight = 0.75*screen.height; vWidth  = 0.95*screen.width; }      
    
    if(vOptions.position == "center")
    {
      var vWin = {left: top.screenX, top: top.screenY, width: top.outerWidth, height: top.outerHeight};
      
      if(Prototype.Browser.IE)
        var vWin = {left: top.screenLeft, top: top.screenTop, width: top.document.body.clientWidth, height: top.document.body.clientHeight};
        
      vOptions.left = ( top.screenX + Math.ceil(( top.outerWidth - pWidth )/2));
      pTop = ( top.screenY + Math.ceil(( top.outerHeight - pHeight )/2));      
    }
   else
   {
     if(vOptions.type != "FULL")
     {
       if(!vWindowPosCount)
       {
       	 if(opener && opener.vWindowPosCount)
       	   vWindowPosCount = opener.vWindowPosCount;
       	 else
       	   vWindowPosCount = 1;
       }
       
       if(!vOptions.position)
         vOptions.position = (vWindowPosCount++ % 6)+1;

       vOptions.left = 20*vOptions.position;
       vOptions.top  = 20*vOptions.position;
     }
   }
    
    var toStr = function(pName, pValue)
    {
      vValStr = pValue;
      if(pValue === true) {vValStr = "YES";}
      if(pValue === false){vValStr = "NO";}
      return(pName+"="+vValStr);
    }
    
    if(vOptions.onCustomCreate) vOptions.onCustomCreate();
    
    var vNewWindow = 
      window.open(
        pUrl, vOptions.name , 
        toStr("height",     vHeight) + "," +
        toStr("width",      vWidth) + "," +
        toStr("left",       vOptions.left) + "," +
        toStr("top",        vOptions.top)  + "," +
        toStr("location",   vOptions.locationBar) + "," +
        toStr("menubar",    vOptions.menubar)     + "," +
        toStr("resizable",  vOptions.resizable)   + "," +
        toStr("scrollbars", vOptions.scrollbars)  + "," +
        toStr("status",     vOptions.statusbar)   + "," +
        toStr("toolbar",    vOptions.toolbar));
    
    
    CO.Window.openWindows[vOptions.name] = {mWindow: vNewWindow, mOpener: vThis};
    
    vNewWindow.vRealOpener = vThis;
    
    navigator[vOptions.name] = vNewWindow;

    if(vOptions.onCustomComplete) vOptions.onCustomComplete();
    if(vOptions.onCustomSuccess) vOptions.onCustomSuccess();
    
    vNewWindow.focus();
    return(vNewWindow);
  }
}

CO.Window.setDragable = function()
{
  new Draggable($("idOverlayWindowContent").up(), { handle: $("idOverlayWindowTitle"), starteffect: null, endeffect: null, snap:CO.Window.snapViewport, onStart: CO.Window.clearMargin});  
}

CO.Window.snapViewport = function(x,y,draginfo) 
{
  var elem = draginfo.element;
  
  var vMaxX  = document.viewport.getWidth()-200;
  var vMaxY = document.viewport.getHeight()-200;
  
  x = x+elem.style.marginLeft;
  
  return[
    x<vMaxX ? (x > 0 ? x : 0 ) : vMaxX,
    y<vMaxY ? (y > 0 ? y : 0) : vMaxY];
}

CO.Window.clearMargin = function(elem)
{
  elem = elem.element;
  elem.style.display = "none";
  elem.style.marginLeft = "";
  elem.style.left = elem.offsetLeft;
  elem.style.marginTop = "";
  elem.style.top = elem.offsetTop;
  elem.style.display = "block";
}

CO.Window.updateOverlayMini = function()
{
  var vWinCont  = $("idOverlayWindowContent");
  var vWinTable = vWinCont.down("table");
  
  var vHeight = vWinTable.clientHeight + 40;
  var vWidth = vWinTable.clientWidth + 50;
  
  if( vHeight > document.viewport.getHeight() ) vHeight = document.viewport.getHeight() - 40;
	if( vWidth > document.viewport.getWidth() )	  vWidth = document.viewport.getWidth() - 50;  		
	
	vWinCont.up().setStyle({ visibility: "visible" , marginLeft: (-vWidth/2)+"px", marginTop: (-vHeight/2)+"px" , height: vHeight+"px", width: vWidth+"px", bottom: "", right: "", position: "fixed", top: "50%", left: "50%"});
}

CO.Window.openWindows = [];

$(document.body).observe("window:close", function(pEvent)
{ 
  if(window.opener == null){ history.back(); return(true); } window.close();
});

$(document.body).observe("window:runInOpener", function(pEvent)
{ 
  var vRealOpener = window.opener.document.body;
  
  if(!isNull(window.opener.CO.Window.openWindows[window.name])) 
    vRealOpener = window.opener.CO.Window.openWindows[window.name].mOpener;
  
  if(!isNull(window.opener)){ window.opener.CO.Window.eval(vRealOpener, pEvent.memo); Event.stop(pEvent); }
});

CO.Window.eval = function(pThis, pFunction)
{
  eval("newFunc = "+pFunction+";");
  newFunc.apply($(pThis), [pFunction.mValue]);
}

CO.Window.close  = function(element)
{ 
  if(isNull(element)) { element = document.body; }
   
  if(Object.isArray(element))
  {
    element.each(function(pItem){ CO.Window.close(pItem); })
  }
  
  $(element).fire("window:close"); 
}

CO.Window.runInOpener  = function(element, pFunction, pValue)
{
  if(isNull(element)) return(false);
  pFunction.mValue = pValue;
  $(element).fire("window:runInOpener", pFunction);
  return(true);
}

try
{
if($("idWindowTemplate") != null)
  CO.Window.template = $("idWindowTemplate").innerHTML;
//$("idWindowTemplate").remove();
}
catch(exc){}

CO.Window.register = function(pElement)
{
  pElement = $(pElement);
  pElement.observe("window:close", function(pEvent){ CO.Window.handleWindowEvent(pElement, pEvent); });
  pElement.observe("nav:update",   function(pEvent){ CO.Window.handleNavEvent(pElement, pEvent); });  
}

CO.Window.handleWindowEvent = function(pElement, pEvent)
{
  
}

CO.Window.handleNavEvent = function(pElement, pEvent)
{
  if(typeof($CO(pElement).co.navi) == "undefined")
  {
    var vNavis = pElement.select(".nav");
    if(vNavis.length == 0) { CO.error("Menue nicht gefunden"); return;}
    $CO(pElement).co.navi = new CO.Navigation(vNavis[0]);
  }
  
  try { pEvent.memo.call($CO(pElement).co.navi); }
  catch(exc){ CO.warn("Fehler bei Menueauruf"); CO.dir(exc); }
  
  Event.stop(pEvent);
}

CO.Window.register(document.body);

//Event.observe(window, "unload", function(){  gVC.removeAllValidators(); } );


CO.Navigation = Class.create(
{
  initialize: function(pNavBox)
  {    
    var vReg = new RegExp("\n", "gi");
    
    this.mNavBox = $(pNavBox);
    this.mNav = [];

    function getText(pObj)
    {
      vInner = null;

      while($(pObj) != null)
      { 
        vInner = $(pObj);
        pObj = $(pObj).firstDescendant();
      }
      
      return(vInner.innerHTML.replace(vReg, ""));
    }
    
    vSections = new Hash();

    this.mNavBox.select(".coNavSection").each(
      function(pSection)
      {
        vSections.set(getText(pSection), pSection);
      });
    
    this.mSections = vSections;  

    var vNav = new Hash();
    var vGroupName = "nogroup";
    var vEntries   = new Hash();

    this.mNavBox.select(".coNavGroup").each(
      function(pGroup)
      {
        vGroupName = getText(pGroup);
        vNav.set(vGroupName, pGroup);
        pGroup.mEntries = new Hash();
        vEntries = pGroup.mEntries;
        
        pGroup.select("a").each(
          function(pEntry)
          {
            var vEntryName = getText(pEntry);
            vEntries.set(vEntryName, pEntry);
          });
      });
    
    this.mNav = vNav;

    return(this);
  },
  
  debug: function()
  {
    this.mNav.each(
      function(pGroup)
      { 
        CO.info("Gruppe: ", pGroup);
        pGroup.value.mEntries.each(function(pEntry){ CO.info("pEntry: ", pEntry); });
      });
  },
  
  hide: function(pGroup, pEntry) {this.mNav.get(pGroup).mEntries.get(pEntry).coHide();},
  show: function(pGroup, pEntry) {this.mNav.get(pGroup).mEntries.get(pEntry).coShow();},
  
  hideGroup: function(pGroup) {this.mNav.get(pGroup).coHide();},
  showGroup: function(pGroup) {this.mNav.get(pGroup).coShow();},
  
  hideSection: function(pSection)
  {
    pSection = this.mSections.get(pSection);
    pSection.coHide()

    var vGroup  = pSection.next();
    
    while(vGroup.hasClassName("coNavGroup"))
    {
      vGroup.coHide();
      vGroup = vGroup.next(); 
      if(vGroup == null) break;       
    }      
  },
  showSection: function(pSection)
  {
    pSection = this.mSections.get(pSection);
    pSection.coShow();
    
    var vGroup  = pSection.next();
    
    while(vGroup.hasClassName("coNavGroup"))
    {
      vGroup.coShow();
      vGroup = vGroup.next(); 
      if(vGroup == null) break;       
    }    
  },
  
  enable:  function(pGroup, pEntry) {this.mNav.get(pGroup).mEntries.get(pEntry).coEnable();},
  disable: function(pGroup, pEntry) {this.mNav.get(pGroup).mEntries.get(pEntry).coDisable();},
  
  select:   function(pGroup, pEntry) { this.deselect(pGroup); this.mNav.get(pGroup).mEntries.get(pEntry).coDisable().addClassName("selected");},
  deselect: function(pGroup, pEntry) { var vEntry = this.mNav.get(pGroup).mEntries.get(pEntry); if(vEntry.hasClassName("selected")){ vEntry.coEnable().removeClassName("selected");} },
  deselect: function(pGroup) { this.mNav.get(pGroup).mEntries.each(function(pItem){ if(pItem.value.hasClassName("selected")){ pItem.value.coEnable().removeClassName("selected");} });},
  
  
  fix:   function(){ this.unfix(); vDiv = this.mNavBox.up(); vDiv.style.height = vDiv.offsetHeight+"px";  this.mNavBox.setStyle({position: "fixed", zIndex: "1", right: "0px", top:"0px", border: "3px solid green"}); CO.msg.layout();},
  unfix: function(){ this.mNavBox.setStyle({position: "static", right: "", border: "", top:""});  CO.msg.layout();}
});

var gNoCacheCount = 0;



CO.Url = Class.create(
{
  initialize: function(pUrl)
  {
    this.mOptions = {};
    this.setBase(pUrl);
    return(this);
  },
  
  setBase: function(pUrl)
  {
    // url kommt hier encoded rein
    var vBaseQuery = pUrl.split("?");

    this.mBase = vBaseQuery[0];    
    this.mParams = new Hash();
	
    this.mHash = "";
	
	this.mSerializeForm = "";
	this.mSerializeInput = "";
	

    if(vBaseQuery[1]) 
    { 
      this.mHash = vBaseQuery[1].split("#")[1]; 
      vBaseQuery[1] = vBaseQuery[1].split("#")[0];
      this.setParams(nvl(vBaseQuery[1],"").toQueryParams());
    }
    
    return(this);  
  },
  
  addParam: function(pName, pValue)
  { 
    if(isNull(this.mParams.get(pName)))
    {
      return(this.setParam(pName, pValue));
    }
    else 
    {
      var vArray = [];
      
      if(Object.isArray(this.mParams.get(pName)))
        vArray = this.mParams.get(pName);
      else
        vArray.push(this.mParams.get(pName));
      
      vArray.push(pValue);
      
      this.setParam(pName, vArray);
    }
    
    return(this);
  },
  setOptions: function(pOptions) { this.mOptions = pOptions; return(this); },  
  getBase:  function() { return(this.mBase); },
  setParam: function(pName, pValue){ this.mParams.set(pName, nvl(pValue,"")); return(this); },
  setParams:function(pObject) { this.mParams = this.mParams.merge(pObject); return(this); },
  delParam: function(pName) { this.mParams.unset(pName); return(this); },
  getParam: function(pName){ return(this.mParams.get(pName)); },
  setHash:  function(pValue) { this.mHash = pValue; return(this); },
  getHash:  function() { return(this.mHash); },
  delHash:  function() { this.mHash = ""; return(this); },
  setNoCache: function()
  {
    var vSegments = this.mBase.split("/NC_");
    if(!isNull(vSegments[1])) this.mBase = vSegments[0];
    
    this.mBase += "/NC_"+Math.round(Math.random()*10000);
    return(this);
  },  
  
  compare: function(pUrl)
  {
    if(this.mBase != pUrl.mBase) return(false);
    if(this.mQuery.size() != pUrl.mQuery.size()) return(false);
    var vIsSame = true;
    this.mQuery.each(function(pItem){ if(pUrl.mQuery.get(pItem.key) != pItem.value)  vIsSame |= false; });
    return(vIsSame);
  },
  
  get: function()
  {
    var vUrl = this.mBase;
    if(params = Object.toQueryString(this.mParams)) { vUrl += (vUrl.include('?') ? '&' : '?') + params; }
	
	if( this.mSerializeForm ) 
	{ 
		if ( FormSerialized = Form.serialize($(this.mSerializeForm),false) )
		{ vUrl += (vUrl.include('?') ? '&' : '?') + FormSerialized; }
	}
	
	if( this.mSerializeInput ) 
	{ 
		if ( InputSerialized = Form.serializeElements($(this.mSerializeInput).select("input,select,textarea"),false) )
		{ vUrl += (vUrl.include('?') ? '&' : '?') + InputSerialized; }
	}	
	
    if(this.mHash) { vUrl += "#"+this.mHash; }
    return(vUrl); // muss wieder encoded raus
  },
  
  serializeMask: function( pMaskId )
  {
	this.mSerializeForm = pMaskId;
	return this;
  },
  
  serializeInput: function( pMaskId )
  {
	this.mSerializeInput = pMaskId;
	return this;
  },
  
  updateDestination: function( pElementId )
  {
    var vJSUrl = new CO.Url(this.get());

    if(this.mOptions.parameters)
    {
      vJSUrl.setParams(this.mOptions.parameters);
    }
    
    if( $( pElementId ).readAttribute("type") == "button" ) 
    {
      $( pElementId ).up("Form").writeAttribute("action", vJSUrl.get() );
    }
    else
    {
      $( pElementId ).writeAttribute("href", vJSUrl.get() );
    }
  },
  
  getOptions: function()
  {
    var vOptions = {};
    if(!isNull(this.mOptions))    { vOptions = this.mOptions; }
        
    if(isNull(vOptions.parameters)) { vOptions.parameters = {}; }
    
    Object.extend(vOptions.parameters, this.mParams.toObject());
        
    if(this.mHash != "")
    {
      var vOnSuccessSave = vOptions.onCustomSuccess;
      if(isNull(vOnSuccessSave)) vOnSuccessSave = function(){}
      
      var vHash = this.mHash;
      
      vOptions.onCustomSuccess = 
       function(pTransport, pOptions)
       { 
         vOnSuccessSave(pTransport, pOptions);
         CO.Tools.scrollTo(vHash);
       }

    };

    return(vOptions);
  },
  
  callback: function(pCaller)
  {
    var vOptions = this.getOptions();
    if(!isNull(pCaller)) { vOptions.cbCaller = pCaller; }
    CO.Callback.request.call(pCaller, this.mBase, vOptions);
    return(this);
  }
  
});

CO.urls = [];

CO.Url.get = function(pAnchor)
{
  if(pAnchor.type) return(CO.urls[pAnchor.type]().setBase(pAnchor.href));
  return(new CO.Url(pAnchor.href));
}

CO.Url.update = function(pAnchor)
{  
  CO.Url.get(pAnchor).updateDestination(pAnchor);
}


CO.CB = function(pAnchor)
{
  CO.Url.get(pAnchor).callback(pAnchor);
}



CO.CBUrl = Class.create(CO.Url, 
{
  initialize: function($super, pUrl, pOptions) 
  {
    if(typeof(pOptions) == "string") { this.mOptions = pOptions.evalJSON(); }
    if(typeof(pOptions) == "object") { this.mOptions = pOptions; }
    if(isNull(this.mOptions)) { this.mOptions = {}; }
    
    if(typeof(pUrl) == "object") $super(pUrl.get()); else $super(pUrl);
    
    return(this);
  },

  getUrl: function() { return(this.mBase); }
});
 
 
CO.Overlay = Class.create();

CO.Overlay.create = function(pOverlayName, element, pStyle)
{
  if(!$(element)) { element = $(document.body); }
  if(isNull(pStyle)) pStyle = {};
    
  var vElementStyle = {};
  var vOverlaySyle  = { zIndex: CO.maxZIndex++, position: "absolute" };
  
  var vDiv = new Element("div");
    
  var vPosition    = Position.cumulativeOffset(element);       
  var vDimensions  = element.getDimensions();       
  vDimensions.left = vPosition[0];
  vDimensions.top  = vPosition[1];

  if(isNull(pStyle.top))  pStyle.top  = 0;
  if(isNull(pStyle.left)) pStyle.left = 0;
    
  if (element == $(document.body))
  {
    if (Prototype.Browser.IE6)
    {
      vElementStyle =
      {         
          left:   "0px"
        , top:    "0px"
        , width:  "100%"            
        , height: document.documentElement.clientHeight
      };
    }
    else
    {
      if (Prototype.Browser.IE7)
      {
        vElementStyle =
        {         
            left:   "0px"
          , top:    "0px"
          , right:  "0px"
          , bottom:  "0px"          
          , position: "fixed"          
        };
      }
      else
      {
        vElementStyle =
        {         
            left:   "0px"
          , top:    "0px"
          , right:  "0px"
          , bottom:  "0px"
          , position: "fixed"            
        };          
      }          
    }
  }
  else
  { 
    vElementStyle =
    {     
        left:   (parseInt(vDimensions.left)   + parseInt(pStyle.left)) + "px"
      , top:    (parseInt(vDimensions.top)    + parseInt(pStyle.top)) + "px"
      , width:  (parseInt(vDimensions.width)) + "px"
      , height: (parseInt(vDimensions.height)) + "px"
    };
  }
   
  if(isNull(element.overlaylist)) element.overlaylist = new Hash();
  var vArray = nvl(element.overlaylist.get(pOverlayName), []);
  
  if(vArray.last()) { vArray.last().style.display = "none"; }

  vArray.push(vDiv);
  element.overlaylist.set(pOverlayName,vArray);
  
  
  vElementStyle = Object.extend(pStyle, vElementStyle);
  
  vDiv.setStyle(Object.extend(vOverlaySyle, vElementStyle));
  
  //$("pageContent").setStyle({position : "relative" });
  $(document.body).insert({top: vDiv});
  
  vDiv.setStyle({ margin: "0px"});  // redraw           
  
  return(vDiv);    
}

CO.Overlay.exists = function(pOverlayName, element)
{
  if(!$(element)) { element = $(document.body); }
  if(isNull(element.overlaylist)) return(false);
  var vArray = nvl(element.overlaylist.get(pOverlayName), []);
  if(vArray.last()) { return(true); }
  return(false);
}

CO.Overlay.get = function(pOverlayName, element)
{
  if(!$(element)) { element = $(document.body); }
  if(isNull(element.overlaylist)) return(false);
  var vArray = nvl(element.overlaylist.get(pOverlayName), []);
  if(vArray.last()) { return(true); }
  return(false);
}

CO.Overlay.remove = function(pOverlayName, element)
{
  if(!$(element)) { element = $(document.body); }
  
  if(isNull(element.overlaylist)) return(false);      
  var vArray = nvl(element.overlaylist.get(pOverlayName), []);      

  if(vArray.last()) 
  { 
    var vClosedOV = vArray.pop().remove();

    if(vArray.last()) 
    {         
      vArray.last().style.display = "block"; 
    }
    
    element.overlaylist.set(pOverlayName,vArray);
    
    return(vClosedOV);
  }
  
  return(false);
}

CO.Upload = Class.create();

CO.Upload.insert = function(pUrl, pDst, pType, pHTML)
{
  pUrl = new CO.Url(pUrl).get();
  
  if(self.tinymce && self.tinymce.insertUpload)
  {
    tinymce.insertUpload(pUrl, pType, pHTML);
    return;
  }
  
  if($(pDst))
  {
    $(pDst).value = pUrl;
  }
  
  if($(pDst+"ImgSrc"))
  {
    $(pDst+"ImgSrc").src = pUrl;
  }
  
  if($(pDst+"Anchor"))
  {    
    $(pDst+"Anchor").href = pUrl;
    $(pDst+"Anchor").onclick = "CO.Window.open(this);";
    $(pDst+"Anchor").innerHTML = "Download";
  }
  
  if($(pDst+"AnchorBox"))
  {    
    $(pDst+"AnchorBox").insert({bottom: new Element("a", {"href": pUrl, "onclick": "CO.Window.open(this);" , "value" : "Download"})});
  }
}


$NS("Text");
$NS("Icon");

self.Text.mMsgLayerGoTo = new CO.Text(" [gehe zu %ELEMENTNAME%]");
self.Icon.mIconError = new CO.Image( "../common/icon/msg_error_small.gif", "", "");
self.Icon.mIconAttention = new CO.Image("../common/icon/attention.png", "", "" );



function resetAnchors()
{
var vMainContainer = $$(".maincontent")[0];

if(typeof(vMainContainer) != "undefined")
{
$$(".maincontent")[0].select("a").each(
function(pItem)
{    
 
  if(pItem.onclick)
    return;
  
  var vFileName = pItem.href;
  var vOpenInWindow = false;

  var vItemhost = pItem.host.split(":").first();
  
  
   
  if(location.host != vItemhost)
  {
    if(vFileName.toUpperCase().indexOf("MAILTO:") >= 0)
    {
      vOpenInWindow = false;
    }
    else
    {
      vOpenInWindow = true;
    }
    
    if(vOpenInWindow)
    {
      pItem.observe('click', function(event){ event.preventDefault(); CO.Window.open(this.href); })
    }
    
    return;
  }
 

  var vExtension = vFileName.split(".").pop();

  

  if(vExtension.length == 3)
  {
    if(vExtension == "htm" || vExtension == "php")
      vOpenInWindow = false;
    else
      vOpenInWindow = true;
  }
  
  if(vFileName.toUpperCase().indexOf("MAILTO:") > 0)
  {
    vOpenInWindow = false;
  }
  
 
  if(vOpenInWindow)
  {
    pItem.setAttribute("onclick", "CO.Window.open(this.href); return(false);");
  }

  }

);
}
}

