function newwindow( url,left,top,width,height,params,name ) {
  if (!name) name = "_blank";
  if (!params) curparams = 'scrollbars=yes,toolbar=yes,location=yes,status=yes,titlebar=yes'
  window.open( url,name,'toolbar=no,resizable=yes,width='+ width +',height='+ height +',left='+left+',top='+top+','+curparams);
}

function newwin(url,width,height) {
  if (screen) {
    var left = (screen.width/2)-(width/2+10)
    var top  = (screen.height/2)-(height/2+20)
  } else {
    var left = 100
    var top = 100
  }
  window.open(url,"_blank",'toolbar=no,resizable=yes,width='+ width +',height='+ height +',left='+left+',top='+top+',scrollbars=yes');
}


function error(elem, text) {
   window.alert(dkstring(text));
   elem.select();
   elem.focus();
   return false;
}

function iePlus(version,futureVersions) {
  var pos = navigator.userAgent.indexOf('MSIE');
  if (pos > -1) {
    bVer = navigator.userAgent.substring(pos + 5);
    var pos = bVer.indexOf(';');
    var bVer = parseInt(bVer.substring(0,pos));
    if (futureVersions)
      return bVer >= version
    else
      return bVer == version;
  } else 
    return false;
}

function setOpacity(ele,value) {
  if(!ele.style) ele = getElement(ele);
	ele.style.opacity = value/10;
	ele.style.filter = 'Alpha(opacity=' + value*10 + ')';
}

function getScrollInfo() {
  var x,y;
  if (self.pageYOffset) {
 	  x = self.pageXOffset;
   y = self.pageYOffset;
  } else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict
   	 x = document.documentElement.scrollLeft;
    y = document.documentElement.scrollTop;
  } else if (document.body) { // all other Explorers
  	x = document.body.scrollLeft;
  	y = document.body.scrollTop;
  } else {
    x=0;
    y=0;
  }
  return {"left" : x, "top" : y};
}

function getElement(id) { 
  return document.getElementById ? document.getElementById(id) : document.all ? document.all(id) : null; 
} 

function repl(str, sch, newval) {
  var t = '';
  var x = str.indexOf(sch); 
  while(x != -1) {
    t  = str.substring(0, x);
    t += String.fromCharCode(newval);
    t += str.substring(x + sch.length);
    str = t;
    x = str.indexOf(sch); 
  }
  
  return str; 
}


function dkstring(s) {
  s = repl(s, '&Aring;',  197);  // AA
  s = repl(s, '&AElig;',  198);  // AE
  s = repl(s, '&Oslash;', 216); // OE
  s = repl(s, '&aring;',  229 ); // aa
  s = repl(s, '&aelig;',  230); // ae
  s = repl(s, '&oslash;', 248); // oe
  
  s = repl(s, '&#197;', 197);
  s = repl(s, '&#198;', 198);
  s = repl(s, '&#216;', 216);
  s = repl(s, '&#229;', 229);
  s = repl(s, '&#230;', 230);
  s = repl(s, '&#248;', 248);
  
  return s;
}

function isinteger(str) {
  if (str == '') return false;
  var re = new RegExp("^[0-9]{1,4}$");
  return re.test(str);
}

function asint( value ) {
  if (!value) return 0;
  if (value == '') return 0;
  value = value.toString();
  if (isposint(value)) {
    if (value.charAt( 0 ) == '0') {
      do
        value = value.substring( 1, value.length );
      while ( value.charAt( 0 ) == '0');
    }
    if (value == '') return 0;
    return parseInt( value, 10 );
  }
  return 0;
}

function isposint( val ) {
  if (!val) return false;
  val = val.toString();
  for (var i = 0; i < val.length; i++) {
    var ch = val.charAt( i );
  if (ch < "0" || ch > "9" ) {
    return false;
  }  
  }
  return true;
}

function validdate(value,danish){
  var err=0
  var psj=0;
  a=strreplace(value,'/','-');
  value=a
  
  // skal vaere 2 bindestreger
  
  
  pos1 = value.indexOf( '-' );
  if (pos1 == -1) return false;
  pos2 = value.indexOf( '-', pos1+1 );
  if (pos2 == -1) return false;
  
  if (!danish) {
    b = a.substring(0, pos1)// month
    dag = a.substring(pos1+1, pos2)// day
  } else {
    dag = a.substring(0, pos1)// day
    b = a.substring(pos1+1, pos2)// month
  }  
    
  f = a.substring(pos2+1, 255)// year


    if (isNaN(b) || isNaN(dag) || isNaN(f)) {
      err=1
    }
  

  //basic error checking
  if (b<1 || b>12) err = 1
  if (dag<1 || dag>31) err = 1
  if (f>99 && f<1950) err = 1
  if (f<100) f = parseFloat(f)+2000;
  
  //advanced error checking

  // months with 30 days
  if (b==4 || b==6 || b==9 || b==11){
    if (dag==31) err=1
  }

  // february, leap year
  if (b==2){
    // feb
    var g=parseInt(f/4)
    if (isNaN(g)) {
      err=1
    }

    if (dag>29) err=1
    if (dag==29 && ((f/4)!=parseInt(f/4))) err=1
  }

  if (err==1)
    return false
  else
   return true;
}

function strreplace( str, sch, newval ) {
  var t = '';
  var x = str.indexOf( sch ); 
  while( x != -1) {
    t  = str.substring( 0, x);
    t += newval;
    t += str.substring( x + sch.length );
    str = t;
    x = str.indexOf( sch ); 
  }
  return str; 
}
