//*** quick browser tests
//*** Anvendes i hide- og show- funktionerne
var ns4 = (document.layers) ? true : false;
var ie4 = (document.all && !document.getElementById) ? true : false;
var ie5 = (document.all && document.getElementById) ? true : false;
var ns6 = (!document.all && document.getElementById) ? true : false;
//*****************************************************************************
// Calculate Top of object
//*****************************************************************************
function getObjTop(objUsed){
	var top = 0;
 	while( objUsed != null ) {
 		top += objUsed.offsetTop;
 		objUsed = objUsed.offsetParent;
 	}
 	return top;
}
//*****************************************************************************
// getBodyHeightWidth
//*****************************************************************************
function getBodyHeightWidth(heightOrWidth){
	if( window.innerHeight && window.scrollMaxY ){ // Firefox 
		pageWidth = window.innerWidth + window.scrollMaxX;
		pageHeight = window.innerHeight + window.scrollMaxY + 38;
	}
	else if( document.body.scrollHeight > document.body.offsetHeight ){ // all but Explorer Mac
		pageWidth = document.body.scrollWidth;
		pageHeight = document.body.scrollHeight;
	}
	else{ // works in Explorer 6 Strict, Mozilla (not FF) and Safari
 		pageWidth = document.body.offsetWidth + document.body.offsetLeft; pageHeight = document.body.offsetHeight + document.body.offsetTop; 
	}
	if(heightOrWidth=='height'){
		return pageHeight;
	}
	else{
		return pageWidth;
	}
}
//*****************************************************************************
// addToFavorites
//*****************************************************************************
function addToFavorites(url) { 
    var title=document.title;
    if (window.sidebar){ //Firefox
			window.sidebar.addPanel(title, url,"");	
		} 
    else{	//Opera
			if( window.opera && window.print ){
		    var mbm = document.createElement('a');
    		mbm.setAttribute('rel','sidebar');
    		mbm.setAttribute('href',url);
    		mbm.setAttribute('title',title);
    		mbm.click();
    	} 
    	else{  //IE
				if(document.all){
					window.external.AddFavorite(location.href, document.title);			
				} 
		}	 
	}	 
}	
//*****************************************************************************
// printPage
//*****************************************************************************
function printPage() {
	window.print();  
}
//*****************************************************************************
// Send to friend
//*****************************************************************************
function emailToFriend(){
	var docTitle = document.title;
	var linkToPage = window.location;
	var winUrl = "/system/email/emailtoafriend.php?title=" + docTitle + "&url=" + linkToPage;
	var winName = 'SendEmailToFriend';
	var winHeight = 295;
  if (window.sidebar){ //Firefox
		winHeight = 310;
	}
	var winWidth = 350;
	var myLeft = (window.screen.width/2) - (winWidth/2 + 10);  //half the screen width minus half the new window width (plus 5 pixel borders).
	var myTop = (window.screen.height/2) - (winHeight/2 + 20);  //half the screen height minus half the new window height (plus title and status bars).
	//Open Email to a friend window
	emailFriendWindow = window.open(winUrl,winName,'left=' + myLeft + ',top=' + myTop + ',width=' + winWidth + ',height=' + winHeight + ',toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0');
	if( !emailFriendWindow || emailFriendWindow.closed ) {
		emailFriendWindow = window.open(winUrl,winName,'left=' + myLeft + ',top=' + myTop + ',width=' + winWidth + ',height=' + winHeight + ',toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0');
	} 
	else{
		emailFriendWindow.focus();
	} 	
}	
//*****************************************************************************
// validEmail
//*****************************************************************************
function validEmail(strEmail) {
	validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
	
	// search email text for regular exp matches
	if (strEmail.search(validRegExp) == -1){
	  return false;
	} 
	return true; 					
}
//*****************************************************************************
// Jump
//*****************************************************************************
function jump(jumpto) {
     location.href=jumpto;
}
//*****************************************************************************
// Actionconfirm
//*****************************************************************************
function actionconfirm(message) {
	okcancel = window.confirm(message);
	return okcancel;
}
//*****************************************************************************
// hidemsg
//*****************************************************************************
function hidemsg(id) {
  	if (ie4 || ie5){
       document.all(id).style.display = 'none';
    }
    else{
      if (ns4){
        document.layers(id).display = 'none';
      }
      else{
        document.getElementById(id).style.display = 'none';
      }
    }
}
//*****************************************************************************
// showmsg
//*****************************************************************************
function showmsg(id) {
  	if (ie4 || ie5){
       document.all(id).style.display = 'block';
    }
    else{
      if (ns4){
        document.layers(id).display = 'block';
      }
      else{
        document.getElementById(id).style.display = 'block';
      }
    }
}
//*****************************************************************************
// togglemsg
//*****************************************************************************
function togglemsg(id) {
  if (document.getElementById){
  	if (document.getElementById(id).style.display == 'block'){
  		document.getElementById(id).style.display = 'none';
  	}
  	else{
  		document.getElementById(id).style.display = 'block';
  	}
  }
  else{
  	if (document.all(id).style.display == 'block'){
  		document.all(id).style.display = 'none';
  	}
  	else{
  		document.all(id).style.display = 'block';
  	}
  }
}
//*****************************************************************************
// checkEnter
//*****************************************************************************
function checkEnter(e){         //e is event object passed from function invocation
	// e gives access to the event in all browsers
	if (!e) var e = window.event;

  //  checkEnter(event);
  if(window.event) // IE
  	{
  	var keynum = e.keyCode
  	}
  else if(e.which) // Netscape/Firefox/Opera
  	{
  	var keynum = e.which
  }

  if(keynum == 13){
    validateandsubmitpage();    //All pages using this script must have a local function with this name
  }
}
//*****************************************************************************
// showmsginline
//*****************************************************************************
function showmsginline(id) {
  if (document.getElementById){
    document.getElementById(id).style.display = 'inline';
  }
  else{
  	if (ie4 || ie5) document.all[id].style.display = 'inline';
  	if (ns4) document.layers[id].display = 'inline';
  }
}
//*****************************************************************************
// Submut form
//*****************************************************************************
function formsubmit() {
  document.forms[0].submit();
}
//*****************************************************************************
// Trim streng for blanke tegn
// Alle blanke fjernes - foran-, bagvedstillede og kun blanke
//*****************************************************************************
function spacetrim(stringToTrim) {
  return stringToTrim.replace(/^\s+|\s+$/g,"");
}
//*****************************************************************************
// Læg  et antal dage til eller træj fra en dato
// actualDate format = dd-mm-yyyy
//*****************************************************************************
function addDate(actualDate,daysToAdd){
	var dateObj = new Date();
	
	var actDay = actualDate.substr(0,2);
	var actMonth = actualDate.substr(3,2);
	if(actMonth == '01'){
		actMonth = '12';
	}
	else{
		actMonth = actMonth - 1;
	}
	var actYear = actualDate.substr(6,4);

	dateObj.setDate(actDay);
	dateObj.setMonth(actMonth); // January = 0
	dateObj.setFullYear(actYear); 
	//Add days to date
	dateObj.setDate(dateObj.getDate()+daysToAdd);	

	//Format result date
	var myDay = dateObj.getDate();
	var myMonth = dateObj.getMonth()+1;
	var myYear = dateObj.getFullYear();

	if(myDay < 10){
		myDay = '0' + myDay;
	}
	if(myMonth < 10){
		myMonth = '0' + myMonth;
	}
	var resultDate = myDay + "-" + myMonth + "-" + myYear;
	return resultDate;
}
//*****************************************************************************
// getTodaysDate
// Returns todays date as dd-mm-yyyy
//*****************************************************************************
function getTodaysDate(){
var today=new Date();
var myDay = today.getDate();
var myMonth = today.getMonth()+1;
var myYear = today.getFullYear();
if(myDay < 10){
	myDay = '0' + myDay;
}
if(myMonth < 10){
	myMonth = '0' + myMonth;
}
strToday = myDay + "-" + myMonth + "-" + myYear;
return strToday
}
//*****************************************************************************
// isDanishString
//*****************************************************************************
function isDanishString(str) {
	if (!str.match(/^[a-z\346\370\3450-9 .,;)(-]+$/i)) {
		return false;
	}
	return true;
}
//*****************************************************************************
// isDate
//*****************************************************************************
function isDate(value) {
  if (!/^\d{2}-\d{2}-\d{4}$/.test(value)) { return false; }
  var parts = value.split("-");
  var day = new Date(+parts[2],parts[1]-1,+parts[0]);
  if (day.getDate() != +parts[0] || day.getMonth() != parts[1]-1) {
    return false;
  }
  return true;
}
//*****************************************************************************
// isNumeric - Returns true if value is numeric
//*****************************************************************************
function isNumeric(strString){
	if(!/\D/.test(strString)){
		return true;		
	} 
	else{
		return false;
	}  
}
//*****************************************************************************
// isHour - Returns true if value is numeric between 00 and 23
//*****************************************************************************
function isHour(sHour){
	var response = true;
	if(!isNumeric(sHour)){
		response = false;		
	}
	else{
		if(sHour < 1 || sHour > 24){
		response = false;		
		}	
	}
	return response;
}
//*****************************************************************************
// isMin - Returns true if value is numeric between 00 and 59
//*****************************************************************************
function isMin(sMin){
	var response = true;
	if(!isNumeric(sMin)){
		response = false;		
	}
	else{
		if(sMin < 0 || sMin > 59){
		response = false;		
		}	
	}	
	return response;
}
//*****************************************************************************
// DateCompare - inputdatoer skal have format dd-mm-yyyy
//*****************************************************************************
function DateCompare(date1,operator,date2){
  //Formater datoer til yymmdd
  var dateA = date1.substr(6,4) + date1.substr(3,2) + date1.substr(0,2);
  var dateB = date2.substr(6,4) + date2.substr(3,2) + date2.substr(0,2);
  var response = false;
  switch (operator){
    case '>':
      if (dateA > dateB){response = true;}
      break;
    case '>=':
      if (dateA >= dateB){response = true;}
      break;
    case '==':
      if (dateA == dateB){response = true;}
      break;
    case '<':
      if (dateA < dateB){response = true;}
      break;
    case '<=':
      if (dateA < dateB){response = true;}
      break;
    default:
        response = false;
    }
  return response;
}
//*****************************************************************************
// Sort on date var en functions
//*****************************************************************************
function dmyOrdA(a, b){
	var dateRE = /^(\d{2})[\/\- ](\d{2})[\/\- ](\d{4})/;
	a = a.replace(dateRE,"$3$2$1");
	b = b.replace(dateRE,"$3$2$1");
	if (a>b) return 1;
	if (a <b) return -1;
	return 0; 
}
function dmyOrdD(a, b){
	var dateRE = /^(\d{2})[\/\- ](\d{2})[\/\- ](\d{4})/;
	a = a.replace(dateRE,"$3$2$1");
	b = b.replace(dateRE,"$3$2$1");
	if (a>b) return -1;
	if (a <b) return 1;
	return 0; 
}
//*****************************************************************************
// dateSort - sort a date array with format dd-mm-yyyy
//*****************************************************************************
function dateSort (myArray,AscDesc){

	if (AscDesc=='D'){
		myArray.sort(dmyOrdD);	
	}
	else{
		myArray.sort(dmyOrdA);	
	}
	return myArray;
}
//***************************************************
//* Set Cookie
//***************************************************
function setCookie(c_name,value,expiredays){
  if (expiredays > 0){
    var exdate=new Date();
    exdate.setTime(exdate.getTime()+(expiredays*24*60*60*1000));
    exdate = exdate.toGMTString();
    document.cookie=c_name + "=" + escape(value) + "; path=/; expires=" +exdate;
  }
  else{
    document.cookie=c_name + "=" + escape(value) + " " + "; path=/";
  }
}
//***************************************************
//* Get Cookie value OR null
//***************************************************
function getCookie(c_name){
	if (document.cookie.length>0)  {
	  c_start=document.cookie.indexOf(c_name + "=")
	  if (c_start!=-1)    {
	    c_start=c_start + c_name.length+1;
	    c_end=document.cookie.indexOf(";",c_start);
	    if (c_end==-1){
			 	c_end=document.cookie.length;
			}
	    return unescape(document.cookie.substring(c_start,c_end));
	  }
	}
	return null;
}
//***************************************************
//* delCookie
//***************************************************
function delCookie(c_name) {
  //Delete cookie takes in some browser first effekt when
  //browser session terminates - therefore we clear content
  //of cookie before deleting it. Reading a cookie with no content
	setCookie(c_name,'',1);
  //delete cookie
  document.cookie = c_name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT" + "; path=/";
}
//***************************************************
//* addEvent
//***************************************************
function addEvent(obj, evType, fn){
 if (obj.addEventListener){
   obj.addEventListener(evType, fn, false);
   return true;
 } else if (obj.attachEvent){
   var r = obj.attachEvent("on"+evType, fn);
   return r;
 } else {
   return false;
 }
}
//***************************************************
//* getObjId
//***************************************************
function getObjId(e){
	var targ
	var id
	if (!e){
		var e = window.event;
	}
	if (e.target){
	  targ = e.target;
	 }
	else if (e.srcElement){
	  targ = e.srcElement;
	}
	if (targ.nodeType == 3){ // defeat Safari bug
   targ = targ.parentNode;
	}
	id=targ.id;
	return id;
}
//***************************************************
//* writeDiv - doesn't work in NS4
//***************************************************
function writeDiv(text,id){
	if (document.getElementById){
		x = document.getElementById(id);
		x.innerHTML = '';
		x.innerHTML = text;
	}
	else if (document.all){
		x = document.all[id];
		x.innerHTML = text;
	}
}
