
//
// ---------- 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;

  // ---
}


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


//
// ---------- 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)
{
//init when DOM is ready (which is much earlier than loading of the whole page)
  addEvent(window, 'DOMContentLoaded', initGeneral);
//  addEvent(window, 'load', initGeneral);
}

