//##############################################
// Detektion af browserversion
//##############################################
function spBrowserDetector(){

  this.ver=navigator.appVersion;
  this.agent=navigator.userAgent.toLowerCase();
  this.dom=document.getElementById?1:0;
  this.ns4=(!this.dom && document.layers)?1:0;
  this.op=window.opera;
  this.moz=(this.agent.indexOf("gecko")>-1 || window.sidebar);
  this.ie=this.agent.indexOf("msie")>-1 && !this.op;

  if(this.op){
    this.op5=(this.agent.indexOf("opera 5")>-1 || this.agent.indexOf("opera/5")>-1);
    this.op6=(this.agent.indexOf("opera 6")>-1 || this.agent.indexOf("opera/6")>-1);
    this.op7=this.dom&&!this.op5&&!this.op6 ;//So all higher opera versions will use it
  }
  else if(this.moz){
     this.ns6=(this.agent.indexOf("netscape6")>-1);
     this.ns7 = this.dom&&!this.ns6; //So all higher ns versions will use it
  }
  else if(this.ie){
    this.ie4 = !this.dom && document.all;
    this.ie5 = (this.agent.indexOf("msie 5")>-1);
    this.ie55 = (this.ie5 && this.agent.indexOf("msie 5.5")>-1);
    this.ie6 = this.dom && !this.ie4 && !this.ie5 && ! this.ie55;//So all higher ns versions will use it
  }

  this.mac=(this.agent.indexOf("mac")>-1);
  this.usedom= this.ns6||this.op7;//Use dom creation
  this.reuse = this.ie||this.op7||this.usedom; //Reuse layers
  this.px=this.dom&&!this.op5?"px":"";

  if(this.op){
     this.label = "Opera";
     if(this.op5){this.version = 5;this.showName=this.label+" - Version "+this.version;}
     else if(this.op6){this.version = 6;this.showName=this.label+" - Version "+this.version;}
     else if(this.op7){this.version = 7;this.showName=this.label+" - Version "+this.version+" eller nyere";}
  }

  else if(this.moz || this.ns4){
     this.label = "Netscape";
     if(this.ns4){this.version = 4;this.showName=this.label+" - Version "+this.version;}
     else if(this.ns6){this.version = 6;this.showName=this.label+" - Version "+this.version;}
     else if(this.ns7){this.version = 7;this.showName=this.label+" - Version "+this.version+" eller nyere";}
  }

  else if(this.ie){
     this.label = "Microsoft Internet Explorer";
     if(this.ie4){this.version = 4;this.showName=this.label+" - Version "+this.version;}
     else if(this.ie5){this.version = 5;this.showName=this.label+" - Version "+this.version;}
     else if(this.ie55){this.version = 5.5;this.showName=this.label+" - Version "+this.version;}
     else if(this.ie6){this.version = 6;this.showName=this.label+" - Version "+this.version+" eller nyere";}
  }

  this.browserDetected=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.ns7 ||this.op5 || this.op6 || this.op7);

  return this
}

var spBd = new spBrowserDetector();

/*
function spBrowserWarning(){
  var msg = null;
  if (!spBd.browserDetected)
    msg = "Dette site genkender ikke din browser og vil muligvis ikke vises korrekt.\nVi anbefaler, at du som browser benytter Internet Explorer fra version 5 eller Netscape fra version 6.";
  else if (spBd.ie){
    if(spBd.version<4)
      msg = "Dette site understøtter ikke din browser.\nVi anbefaler, at du opgraderer din browser til version 5 eller senere.";
    else if(spBd.version==4)
      msg = "Sider på dette site vil opleves som 'flimrende' i Internet Explorer version 4.\nVi anbefaler, at du opgraderer til version 5 eller senere.";
  }
  else if (spBd.ns4 || spBd.op){
    msg = "Dette site understøtter ikke din browser.\nVi anbefaler, at du som browser benytter Internet Explorer fra version 5 eller Netscape fra version 6.";
  }

  if (msg != null) alert(msg);
}
*/

function spCheckAll(cntId){
  var cntObj = document.getElementById(cntId);
  var inputCtrls = cntObj.getElementsByTagName("input");
  for(i=0;i<inputCtrls.length;i++){
    if(inputCtrls[i].getAttribute("type")=="checkbox")
      inputCtrls[i].checked = true;
  }
}

function spUncheckAll(cntId){
  var cntObj = document.getElementById(cntId);
  var inputCtrls = cntObj.getElementsByTagName("input");
  for(i=0;i<inputCtrls.length;i++){
    if(inputCtrls[i].getAttribute("type")=="checkbox")
      inputCtrls[i].checked = false;
  }
}


function spSelectRadio(radioName, radioIndex) {
  if (spBd.ns4 || spBd.ie4 || spBd.mac) {
    return;
  } else {
    try {
      var radioButtons = document.getElementsByName(radioName);
      if (radioButtons != null) {
        var radioButton = radioButtons[radioIndex];
        if (radioButton != null) {
          radioButton.checked='checked';
        }
      }
    } catch (e) {
      // ignore
      //alert("fejl\n"+e.name+"\n"+e.message+"\n"+e.description);
    }
  }
}