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

/*
addEvent function found at http://www.scottandrew.com/weblog/articles/cbs-events
*/
function addEvent(obj, evType, fn) {
  if (obj.addEventListener) {
    obj.addEventListener(evType, fn, true);
    return true;
  } else if (obj.attachEvent) {
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    return false;
  }
}

function initGeneral(){
  var i,k;

/*  
  // --- Find all SlideMenu container divs and switch them on (display: block) ---
  var headerInner = document.getElementById('divheaderinner');
  if(headerInner!=undefined){
    var divs = headerInner.getElementsByTagName('div');
    // find the mmContainer divs and set their display style from 'none' (as defined in ypMenu.css) to 'block'
    for (i = 0; i < divs.length; i++) {
      if (/\bmmContainer\b/.test(divs[i].className))  divs[i].style.display = 'block';
    }
  }
*/
  
  // ---
}


// 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, 'TYPO3popup', 'width=300,height=600')
  //   '300x600:status=1,menubar=1,scrollbars=1,resizable=1,location=1,directories=1,toolbar=1,...'
  //                     => window.open(url, 'TYPO3popup', 'width=300,height=600,status=1,menubar=1,scrollbars=1,resizable=1,location=1,directories=1,toolbar=1,...')
  if(target==''){
    location.href = url;
  }else if(target=='_self'){
    self.location.href = url;
  }else if(target=='_parent'){
    parent.location.href = url;
  }else if(target=='_top'){
    top.location.href = url;
  }else{
    var wintarget = 'TYPO3popup';
    if(target=='_blank')  wintarget = '_blank';
    // create open params from special TYPO3 targets
    var winOpenParams = '';
    var regExpResult;
    if( (regExpResult=target.match( /(\d+)x(\d+)(:(\S+))?/ ))!=null ){   // check for Typo3 specific targets like "300x600"
      winOpenParams = "width="+regExpResult[1]+",height="+regExpResult[2];
      if(typeof(regExpResult[4])!='undefined')  winOpenParams += ','+regExpResult[4];
    }
    // open popup window (keep handle in global variable t3PopupWin)
    t3PopupWin = window.open(url, wintarget, winOpenParams);
    // focus popup win
    setTimeout("t3PopupWin.focus();", 100);
  }
    
  return true;
}


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

// Set the following global variables:
// gBrowser, gVersion, gSystem, gNS4

function NextChar(st,findst){
  //Returns 0 if findst is not found, else return charpos following substring.
  //Result is also stored in variable NextCharPos (which is local to outer function block).
  var p=st.indexOf(findst);
  return NextCharPos=(p<0?0:p+findst.length);
}

var NextCharPos;
var UA = navigator.userAgent.toLowerCase();

if (NextChar(UA,'konqueror')){
  gBrowser="konqueror"; gSystem="linux";
}else if(NextChar(UA,'opera')) 
  gBrowser="opera"
else if(NextChar(UA,'webtv'))
  gBrowser="webtv";
else if(NextChar(UA,'icab'))
  gBrowser="icab"
else if(NextChar(UA,'msie'))
  gBrowser="ie"
else if(!NextChar(UA,'compatible')){
  gBrowser="ns"
  gVersion=UA.charAt(8);
}else 
  gBrowser="unknown";

if(!window.gVersion)
  gVersion=UA.charAt(NextCharPos+1);
if(!window.gSystem){
  if(NextChar(UA,'linux'))
    gSystem="linux";
  else if(NextChar(UA,'x11'))
    gSystem="unix";
  else if(NextChar(UA,'mac'))
    gSystem="mac"
  else if(NextChar(UA,'win'))
    gSystem="win"
  else gSystem="unknown";
}

gNS4=(gBrowser=="ns" && gVersion=="4");

//alert(gBrowser + gVersion)

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('/'));

if(document.getElementById && document.createTextNode)
{
  addEvent(window, 'load', initGeneral);
}

