
function getElement(id) { 
  return document.getElementById ? document.getElementById(id) : document.all ? document.all(id) : null; 
} 

function getRealLeft(id) { 
  var el = getElement(id); 
  if (el) { 
    xPos = el.offsetLeft; 
    tempEl = el.offsetParent; 
    while (tempEl != null) { 
      xPos += tempEl.offsetLeft; 
      tempEl = tempEl.offsetParent; 
    } 
    return xPos; 
  } 
} 

function getRealTop(id) { 
  var el = getElement(id); 
  if (el) { 
    yPos = el.offsetTop; 
    tempEl = el.offsetParent; 
    while (tempEl != null) { 
      yPos += tempEl.offsetTop; 
      tempEl = tempEl.offsetParent; 
    } 
  return yPos; 
  } 
} 

function show_props(obj, objName) {   
  var result = ""   
  for (var i in obj) {      
    result += objName + "." + i + " = " + obj[i] + "<br>"+chr(13)   }   
  return result
}

function dkstring( s ) {
  s = repl( s, '&uuml;',  252 );  // ü
  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 );
  s = repl( s, '&nbsp;', 32 );
  return s;
}

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 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;
}

//---------- default liste 

function deflist() {
  var res = new Array();
  res.add = deflist_add;
  res.clear = deflist_clear;
  return res;
}

function deflist_add( item ) {
  this[this.length] = item;
}

function deflist_clear ( ) {
  this.length = 0;
}

function validdate(value,danish){
  var err=0
  var psj=0;
  var a = value.replace(/\//gi, "-")
  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<1900) 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 extractword( value, no,delim ) {
  value = value.toString();
  first = -1;
  if (!delim) 
    delimiter = ','
  else
    delimiter = delim;
    
  if (no > 0) {
    for (var i = 0; i < no; i++ ) 
      first = value.indexOf( delimiter, first+1 );
    if (first == -1) return '';
  }
  tmp = value.substring( first+1 );  
  first = tmp.indexOf( delimiter);
  if (first != -1) 
    tmp = tmp.substring( 0,first );
//  alert(tmp);  
  return tmp;
}

function asdate(adate) {
  var y = adate.getFullYear();
  var m = adate.getMonth() + 1;
  var d = adate.getDate();
  return d + '/' + m + '-' + y;
}

function expand_date( value ) {
  if (value == '') return '';
  
  var datework = new Date();
  value = value.replace(/\//gi, "-")
  if(value.indexOf('-') == -1) {
    if(value.length < 3) {
      value += '-'+(datework.getMonth()+1)+'-'+datework.getFullYear();
    } else {
      if(value.length < 5) {
        var t = value;
        value = t.substring(0,2) + '-' + t.substring(2,4) + '-' + datework.getFullYear();
      } else {
        // Skrevet fuldt ud uden - 
        var t = value;
        value = t.substring(0,2) + '-' + t.substring(2,4) + '-' + t.substring(4,10);
      }
    } 
  }
  
  var list = value.split('-');
  var y = asint(list[list.length-1]);
  if (y > 50 && y < 100 ) y += 1900
  if (y < 51) y += 2000  
  list[list.length-1] = y;
  value = list.join('-');
  return value;
}

function newwin(url,left,top,width,height,name,resizeable) {
  if (!name) var name = "_blank"
	if (!resizeable) var resizeable = "yes"
  if (screen) {
    left = (screen.width/2)-(width/2+10)
    top  = (screen.height/2)-(height/2+20)
  }
  var win = window.open(url,name,'toolbar=no,resizable='+resizeable+',width='+ width +',height='+ height +',left='+left+',top='+top+',scrollbars=yes');
  win.focus();
}

function newwindow(url,left,top,width,height,name) {
  if (!name) var name = "_blank"
  window.open(url,name,'toolbar=no,resizable=no,width='+ width +',height='+ height +',left='+left+',top='+top+',scrollbars=yes');
}

function trim(s) {   
  s = repl(s, String.fromCharCode(160), 32);
  while (s.length > 0 && s.charAt(0) == ' ')
    s = s.substring(1);
  while (s.length > 0 && s.charAt(s.length-1) == ' ')
    s = s.substring(0, s.length-2);
  return s;  
}

function paramtext(s, list) {   
  var result = s
  var i = 1
  for (var i = 0; i <= list.length-1;i++) {
    result = result.replace('%' + (i+1) + '%', list[i]);
  }
  return dkstring(result)
}

function ifthen( bool, truestr, falsestr) {
  if (bool) return truestr;
  return falsestr;
}


function writespan(name, text) {
  try {
    var ele = getElement(name)
    ele.innerHTML = text;
  }
  catch (e) {
    alert( 'HTML element : ' + Name + ' not found');
  }
}

function inurl( text ) {
  if (window.location.href.toLowerCase().indexOf(text.toLowerCase()) == -1)
    return false
  else
    return true;  
}

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 str2date( value,danish ) {
  var a=value.replace(/\//gi,'-');
  value=a
  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 = asint(a.substring(pos2+1, 255))// year
  
  if (f > 50 && f < 100 ) f += 1900
  if (f < 51) f += 2000
  
  return new Date( f, b-1, dag );
}

function error( msg, field ) {
  alert (dkstring( msg ));                                 
  if (field) { 
    field.focus();
    field.select();
  }
  return false;
}

/* 23-1-2003 */
function togglelayer( name ) {
 var cur = eval(name);
 if (cur.style.display == 'none')
   cur.style.display = 'block'
 else
   cur.style.display = 'none';
}

function isfloat(str) {
  if (str == '') return false;
  var valid = "0123456789,."
  var ok = true;
  var temp;
  var count = 0;
  for (var i=0; i<str.length; i++) {
    temp = "" + str.substring(i, i+1);
    if (valid.indexOf(temp) == "-1") ok = false;
    if (temp == '.' || temp == ',') count++;
  }
  if (count > 1) ok = false;
  
  return ok;
}

function isundefined(cur) {
  return (typeof(cur)=="undefined")
}


function addday( d ) {
  if (d > 0) {
    for (var i = 0; i < d; i++) this.setDate(this.getDate() + 1);
  } else {
    for (var i = 0; i > d; i--) this.setDate(this.getDate() - 1);
  }
}

Date.prototype.addday = addday;

function justerdato(field, nodays) {
  var form = document.forms[0];
  var fld = eval( 'form.' + field );
  fld.value = expand_date(fld.value);
  if (!validdate(fld.value, true)) {
    error('ugyldig dato')
  } else {
    var d = str2date(fld.value,true);
    d.addday(nodays);
    fld.value = asdate(d,'d-m-Y');
  }
}


function gettime_milliseconds() {
  var d = new Date();
  var h, m, s, ms
  h  = d.getHours();
  m  = d.getMinutes();
  s  = d.getSeconds();
  ms = d.getUTCMilliseconds();
  return h * 1000 * 60 * 60 +
         m * 1000 * 60 +
         s * 1000 +
         ms
}

function chr(val) {
  return String.fromCharCode(val); 
}

function toggle_layer( ele ) {
  var e = getElement(ele);
	if (e.style.display == 'block' || e.style.display == '')
	  e.style.display = 'none'
	else
	  e.style.display = 'block';
		
}

function hideElement(ele) {
  var e = getElement(ele);
  e.style.display = 'none'
}

function padleft(value, len, filler) {
  while (value.toString().length < len) value = filler + value.toString();
  return value;
}

function getsearchvalue( name ) {
  var dc     = self.location.search;
  dc = '&'+dc.substring( 1, dc.length )+'&';
  dc = dc.replace( /\+/gi,' ');

  var cname  = name + '=';
  var clen   = dc.length;
  var cbegin = 0;
  while (cbegin < clen ) {
    var vbegin = cbegin + cname.length;
  if (dc.substring( cbegin, vbegin ) == cname) {
    var vend = dc.indexOf( "&", vbegin );
    if (vend == -1) vend = clen;
    return unescape (unescape( dc.substring(vbegin,vend)));
  }
  cbegin = dc.indexOf( "&", cbegin)+1;
  if (cbegin == 0) break;
  }
  return '';
}

function dml(val) {
  var list = val.split(','); var res = ''; for (var i = 0; i < list.length; i++) { res += String.fromCharCode(parseInt(list[i])+1); } document.write(res);
}

function dmlconvert(ele) {
  val = ele.href;
  if (val.indexOf(',') != -1) {
    while (val.indexOf('/') > -1) {
      val = val.substring(val.indexOf('/')+1);
    }
    var list = val.split(','); 
    var res = ''; 
    for (var i = 0; i < list.length; i++) { 
      res += String.fromCharCode(parseInt(list[i])+1); 
    } 
    ele.href = res;
  }
}

function urldecode(value)
{
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = value;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
     if (ch == "+") {
         plaintext += " ";
       i++;
     } else if (ch == "%") {
      if (i < (encoded.length-2) 
          && HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
          && HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
        plaintext += unescape( encoded.substr(i,3) );
        i += 3;
      } else {
        alert( 'Bad escape combination near ...' + encoded.substr(i) );
        plaintext += "%[ERROR]";
        i++;
      }
    } else {
       plaintext += ch;
       i++;
    }
  } // while
   return plaintext;
}

function followlink(cururl,target) {
  if (cururl.indexOf('javascript:') == -1) {
    if (!isundefined(target) && target != '')
      window.open(cururl,target)
    else
      location.href = cururl;
  } else {
    eval(cururl.split('javascript:')(1));
  }
}

function window_height () {
  if (document.all)
    return document.body.offsetHeight
  else if (document.layers)
    return window.innerHeight;
  return 600;  
} 

var onWindowLoadList = new deflist();
onWindowLoadList.show = function (){
  for (var i = 0; i < onWindowLoadList.length; i++) {
    eval(onWindowLoadList[i]);
  }
}
if (window.onload != null) {
  var __oldonload = window.onload;
  try {
    onWindowLoadList.add(__oldonload());
  } catch (e) {
  }
}
window.onload = onWindowLoadList.show;

function URLEncode( plaintext )
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for
	return encoded;
}

function URLDecode(encoded )
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   return plaintext;
}


function GoogleTrackPageView(url){
  try {
    pageTracker._trackPageview(url);
    
  }
  catch(e) {
  }
}              

