
//
// ---------- FUNCTIONS ----------
//

function initGeneral(){
  var i,k;
  addToolTips();
}


// add event listeners to JSToolTip enabled tags (abbr>, <acronym>, class="jstooltip")
function addToolTips(){
//  var tts = $$('abbr', 'acronym', '.jstooltip');
  var tts = $$('.jstooltip');
  tts.each(function(tt, i){
    var ttId = encodeURI(tt.innerHTML);
    if(ttId!='' && $('jsTThead_'+ttId)!=null){
      tt.observe('mouseover', showToolTip);
      tt.observe('mouseout',  UnTip);
    }else{
      tt.removeClassName('jstooltip');
    }
  });
}


// Show JSToolTip using wz_tooltip lib
function showToolTip(){
  var ttId = encodeURI(this.innerHTML);
  var ttHead = $('jsTThead_'+ttId);
  var ttType = ttHead.up().classNames().toArray()[1];
  switch(ttType){
    case 'jsTTtype_Bubble': 
      // Tip('Some text');
      TagToTip('jsTTcont_'+ttId, FADEIN, 500, FADEOUT, 1000, BALLOON, true, ABOVE, true, BALLOONIMGPATH, '/fileadmin/templates/digilog/js/wz_tooltip/tip_balloon_DL/', OFFSETX, -16, TITLEBGCOLOR, '#674620');
      break;
    case 'jsTTtype_Box': 
      TagToTip('jsTTcont_'+ttId, FADEIN, 500, FADEOUT, 1000, BGCOLOR, '#efe7de', BORDERCOLOR, '#874600', SHADOW, true, SHADOWCOLOR, '#173A3D', SHADOWWIDTH, 3, TITLEBGCOLOR, '#674620', TITLE, ttHead.innerHTML);
      break;
    case 'jsTTtype_BoxStatic': 
      TagToTip('jsTTcont_'+ttId, FADEIN, 500, FADEOUT, 1000, BGCOLOR, '#efe7de', BORDERCOLOR, '#874600', SHADOW, true, SHADOWCOLOR, '#173A3D', SHADOWWIDTH, 3, STICKY, 1, CLOSEBTN, true, CLICKCLOSE, true, TITLEBGCOLOR, '#674620', TITLE, ttHead.innerHTML);
      break;
  }
}



// Clear the default input of an input text field when it receives focus. Save the original input in this.orgValue.
function defaultInputFocus(me){
  if(me.orgValue==undefined)  me.orgValue=me.value;
  if(me.value==me.orgValue)  me.value='';
}
// Restore the original value of an input text field when it looses focus and nothing has been entered.
function defaultInputBlur(me){
  if(trim(me.value)=='')  me.value=me.orgValue;
}


function trim(st){
  return st.replace(/^\s*(.*\S)?\s*$/, '$1');
}


function InsertFlash(flashURL, w, h, version){
  if(version=='')  version='6,0,0,0';
  document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+w+'" height="'+h+'" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+version+'">');
  document.write('<param name="allowScriptAccess" value="sameDomain" />');
  document.write('<param name=movie value="'+flashURL+'" />');
  document.write('<param name="quality" value="high" />');
  document.write('<param name="wmode" value="opaque" />');  // this allows DHTML elements in front of Flash and prevents screenreaders (like JAWS) from getting stuck of Flash
  document.write('<embed src="'+flashURL+'" type="application/x-shockwave-flash" quality="high" width="'+w+'" height="'+h+'" wmode="opaque" allowScriptAccess="sameDomain" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>');
  document.write('</object>');
}


function linkTileTo(url, target){
  // ie does not honor the <base href=...> tag in JS, so we have to add the base ourselves
  if(url.indexOf('http://')==-1){
    var b = document.getElementsByTagName('base');
    if (b && b[0] && b[0].href){
      if (b[0].href.substr(b[0].href.length-1) == '/' && url.charAt(0) == '/')  url=url.substr(1);
      url = b[0].href + url;
    }
  }
  
  // target can have one of these patterns:
  //   ''                => no target (use location.href to load new url in same window!)
  //   '_self'           => self.location.href (effect is same as above)
  //   '_parent'         => parent.location.href
  //   '_top'            => top.location.href
  //   '_blank'          => window.open(url, '_blank')
  //   '300x600'         => window.open(url, '_blank', 'width=300,height=600')
  //   '300x600:status=1,menubar=1,scrollbars=1,resizable=1,location=1,directories=1,toolbar=1'
  //                     => window.open(url, '_blank', 'width=300,height=600,status=1,menubar=1,scrollbars=1,resizable=1,location=1,directories=1,toolbar=1')
  if(target==''){
    location.href = url;
  }else{
    var winOpenParams = '';
    var regExpResult;
    if( (regExpResult=target.match( /(\d+)x(\d+)(:(.*))?/ ))!=null ){   // check for Typo3 specific targets like "300x600"
      winOpenParams = "width="+regExpResult[1]+",height="+regExpResult[2];
      if(regExpResult[4]!='')  winOpenParams+=","+regExpResult[4];
    }
    // open popup win
    t3PopupWin = window.open(url, 't3PopupWindow', winOpenParams);
    // focus popup win
    setTimeout("t3PopupWin.focus();", 100);
  }
    
  return true;
}


//
// ---------- MAIN ----------
//

gURL = self.location.toString();
gURLnoquery = gURL.slice(0, gURL.indexOf('?')<0 ? gURL.length+1 : gURL.indexOf('?') );
gURLfile = gURLnoquery.slice(gURLnoquery.lastIndexOf('/')+1);
gURLpath = gURLnoquery.slice(0,gURLnoquery.lastIndexOf('/'));

//Event.observe(window, 'load', initGeneral);  // not working here:   window.observe('load', initGeneral);
// funktioniert bei IE erst ab Prototype 1.6.1! Sonst zu früh für JSToolTip
document.observe('dom:loaded', initGeneral);  // init when DOM is ready - which is much earlier than loading of the whole page (incl. images!)
