// Html shown in popup dhtml contact information box
var winBodyTxt = "<table style='width:100%;border-collapse:collapse;color:#000000;background-color:#ADBADA'>";
winBodyTxt += "<tr><td width=33%;font-weight:border:2px solid #FFFFFF;'>Kontakt</td><td style='text-align:center;width=33%;font-weight:border:2px solid #FFFFFF'>Email</td><td style='text-align:center;width=33%;font-weight:border:2px solid #FFFFFF'>Telefon</td></tr>";
winBodyTxt += "<tr><td style='2px;border:2px solid #FFFFFF'>&nbsp;Line Havkrog</td><td style='border:2px solid #FFFFFF'>&nbsp;<a href='mailto:line@havkrog.dk'><span style='color: #042FED'>line@havkrog.dk</span></a></td><td style='border:2px solid #FFFFFF'>&nbsp;3113 6300</td></tr>";
winBodyTxt += "<tr><td style='border:2px solid #FFFFFF'>&nbsp;Kim Havkrog</td><td style='border:2px solid #FFFFFF'>&nbsp;<a href='mailto:kim@havkrog.dk'><span style='color: #042FED'>kim@havkrog.dk</span></a></td><td style='border:2px solid #FFFFFF'>&nbsp;2010 4905</td></tr>";
winBodyTxt += '</table>';
winBodyTxt += "<table style='margin-top:20px;width:100%;border-collapse:collapse;color:#000000;background-color:#ADBADA'>";
winBodyTxt += "<tr><td style='width=38%;font-weight:bold;border:2px solid #FFFFFF;'>&nbsp;Adresse</td><td style='width=27%;font-weight:bold;border:2px solid #FFFFFF;'>&nbsp; </td><td style='font-weight:bold;border:2px solid #FFFFFF;'>&nbsp;Fax</td><td style='font-weight:bold;border:2px solid #FFFFFF;'>&nbsp;Telefon</td></tr>";
winBodyTxt += "<tr><td style='border:2px solid #FFFFFF;vertical-align:top;'>&nbsp;Kronborgvej 3<br>&nbsp;8381 Tilst</td><td style='border:2px solid #FFFFFF;vertical-align:top;'>&nbsp;</span></a></td><td style='border:2px solid #FFFFFF;vertical-align:top;'>&nbsp;7025 6303</td><td style='border:2px solid #FFFFFF;vertical-align:top;'>&nbsp;8624 0344</td></tr>";
winBodyTxt += '</table>';
winBodyTxt += "<table style='margin-top:20px;width:100%;border-collapse:collapse;color:#000000;background-color:#ADBADA'>";
winBodyTxt += "<tr><td style='width=10%;border:2px solid #FFFFFF;'>&nbsp;</td><td style='width=70%;border:2px solid #FFFFFF; text-align:right'><a target='_blank' href='http://maps.google.dk/maps?f=q&hl=da&geocode=&q=Kronborgvej+3,+8381&sll=56.393479,10.203209&sspn=0.068124,0.133896&ie=UTF8&ll=56.196869,10.109138&spn=0.03992,0.10437&z=13&iwloc=addr'><span style='color: #042FED'>Kørselsvejledning</span></a>&nbsp;</td></tr>";
winBodyTxt += '</table>';
//*** 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;
//*****************************************************************************
// 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();
	} 	
}	
//*****************************************************************************
// openContactInfo
//*****************************************************************************
function openContactInfo() {
	destroyWindow('contactPopUp');
	//Define body tekst
//	var winBodyTxt = 'Hey';
	var winId = 'contactPopUp';
	var winTitle = 'Kontaktinfo til hanlab';
	var winHeight = 300;
	var winWidth = 440;
	//half the screen width minus half the new window width (plus 5 pixel borders).
	var winLeft = (window.screen.width/2) - (200 + 10) - 700;
//	var winLeft = -205;
	var winTop = -105;
	var winHeadBgColor = '#26479D';
	var winBodyBgColor = '#FFFFFF';
	var winBorderColor = '#26479D';
	writeDiv(winBodyTxt,winId);
	createWindow(winTitle, winWidth, winHeadBgColor,winBodyBgColor, winId, 0, winLeft, winTop,winBorderColor);
}
//*****************************************************************************
// openContactInfo
//*****************************************************************************
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(str) {
  rv = str.replace(/^\s*(.*?)\s*$/, "$1");
	return rv;
}
//*****************************************************************************
// 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;
}
//*****************************************************************************
// 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;
	}
}
