function setDefValue(boxID,boxVal) {
	if (boxID.value == '') {
		boxID.value = boxVal;
	}
}

function clearDefValue(boxID,boxVal) {
	if (boxID.value== boxVal) {
		boxID.value = '';
	}
}

function mailLink(user,domain) {
	myStr = "<a h" + "ref='mai" + "lto:" + user + "@" + domain + "'>" + user + "@" + domain + "</" + "a>";
	document.write(myStr);
}

function mailLinkExt(user,domain,titel) {
	myStr = "<a h" + "ref='mai" + "lto:" + user + "@" + domain + "'>" + titel + "</" + "a>";
	document.write(myStr);
}

function checkEmail(str) {
	if ((str.indexOf('@') < 0) || (str.indexOf('.') < 0))
	{
		alert('Der er fejl i den indtastede e-mail adresse.\n'+
		'En korrekt e-mail angives som bruger@domæne.land; f.eks. jens@hansen.dk.');
		return false;
	}	
	else {
		return true;
	}
}

function checkEmpty(str,fieldName) {
	var re = /\s/g; //Match any white space including space, tab, form-feed, etc. 
	RegExp.multiline = true; // IE support
	var myStr = str.replace(re, "");
	if (myStr.length == 0) {
		alert('Feltet "'+fieldName+'" manger at blive udfyldt.\n'+
		'Udfyld venligst feltet og prøv igen.');
		return false;
		} 
	else {return true;}
}

function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}


function setCookie(name, value, expires, path, domain, secure)
{
    return document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}


function deleteCookie(name, path, domain) {
	if ( getCookie(name)) document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function areAllChecked(field,myCaller) {
	field = document.getElementsByName(field);
	var allChecked = true;
	for (i = 0; i < field.length; i++) {
		allChecked = allChecked && field[i].checked;
	}
	return allChecked;
}

function checkAll(field)
{
	field = document.getElementsByName(field);
	for (i = 0; i < field.length; i++)
		field[i].checked = true ;
}

function uncheckAll(field)
{
	field = document.getElementsByName(field);
	for (i = 0; i < field.length; i++)
		field[i].checked = false ;
}

function loadXMLDoc(dname) 
{
	var xmlDoc;
	if (window.XMLHttpRequest) {
	  xmlDoc=new window.XMLHttpRequest();
	  xmlDoc.open("GET",dname,false);
	  xmlDoc.send("");
	  return xmlDoc.responseXML;
	  }
	// IE 5 and IE 6
	else if (ActiveXObject("Microsoft.XMLDOM")) {
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async=false;
		xmlDoc.load(dname);
		while (xmlDoc.readyState != 4)
		{
			xmlDoc.waitForResponse(200);
		}
		return xmlDoc;
	}
	alert("Fejl under indhentning af dokument.");
	return null;
}

// dialogObject og dialog popups
function openDialog(myID,myTitle,mySrc,myWidth,myHeight,myPlace	) {
	var IE=document.all;
	var dialogArea = document.getElementById('dialogArea');
	
	if (dialogArea) {
		// højde og bredde
		if (!myWidth) {myWidth = 300}
		if (!myHeight) {myHeight = 200}
		// placering midt på siden
		var iWidth = (!IE)?window.innerWidth:document.documentElement.clientWidth; 
		var iHeight = (!IE)?window.innerHeight:document.documentElement.clientHeight;

		// alm. javascript
//		iWidth = Math.round((iWidth-myWidth)/2)+document.body.scrollLeft;
//		iHeight = Math.round((iHeight-myHeight)/2)+document.body.scrollTop;

		// xhtml strict
		iWidth = (IE)?Math.round((iWidth-myWidth)/2)+document.documentElement.scrollLeft:Math.round((iWidth-myWidth)/2)+window.pageXOffset;
		iHeight = (IE)?Math.round((iHeight-myHeight)/2)+document.documentElement.scrollTop:Math.round((iHeight-myHeight)/2)+window.pageYOffset;
		
		var thisDialog = document.getElementById(myID);
		var changePlace = false;
		var myHeader = 	'<a href=\"JavaScript:closeDialog(\''+myID+'\');\">'+
		'<img src=\"/gfx/boxes/box-close-big-o.gif\" width=\"10\" height=\"10\" hspace=\"2\" vspace=\"2\" border=\"0\" alt=\"luk dialogvinduet\" align=\"right\"></a>'+
		'<font class=\"orange\">'+myTitle+'</font><div class=\"hr\"><hr /></div>';

		if (!thisDialog) {
			dialogArea.innerHTML = dialogArea.innerHTML + '<div id=\"'+myID+'\" style=\"visibility: visible; position: absolute; top: '+iHeight+'px; left: '+iWidth+'px; width: '+myWidth+'px; height: '+myHeight+'px; z-index: 1001;\" class=\"dialogBox\">'+
			'</div>'; 
			var thisDialog = document.getElementById(myID);
			changePlace = true;
		}
		
		// opdater og vis dialogboksen
		var thisStyle = thisDialog.style;
		thisStyle.visibility = 'visible';
		thisStyle.zIndex = '1001';
		thisStyle.width = myWidth+'px';
		thisStyle.height = myHeight+'px';
		// placering på siden
		if (changePlace) {
			if (myPlace) {
				var myLeft = getOffset(myPlace,'left');
				var myTop = getOffset(myPlace,'top');
				if (IE) {
					thisStyle.left = (myLeft-Math.round(myWidth/3))+'px';
					thisStyle.top = (myTop)+'px';
				} else {
					thisStyle.left = (myLeft-Math.round(myWidth/3))+'px';
					thisStyle.top = (myTop)+'px';
				}
			}
			else {
				thisStyle.left = iWidth+'px';
				thisStyle.top = iHeight+'px';
			}
		}
		thisDialog.innerHTML = myHeader;
	
		// opdater indhold
		if (mySrc) {
			var re = new RegExp("[\.](asp)[\?]");
			if (re.test(mySrc)) {
				// mySrc er et link til fil; opret iframe med dokumentet
				thisDialog.innerHTML = thisDialog.innerHTML+
				'<iframe frameborder=\"0\" width=\"'+(myWidth-2)+'\" height=\"'+(myHeight-30)+'\" src=\"'+
				mySrc+'\" class=\"borderless\" scrolling=\"no\"></iframe>'; 				
			}
			else {
				// mySrc er en string; fremvis
				thisDialog.innerHTML = thisDialog.innerHTML+'<br>'+mySrc;
			}
			// fade out main tekst
			changeOpac(60,'mainSiteArea');
		}
	}
	return false;
}

function closeDialog(myObj) {
	var myObj = document.getElementById(myObj);
	var IE = document.all;
	if (myObj) {
		myObj.style.visibility = 'hidden';
		myObj.style.zIndex = '-100';
		myObj.innerHTML = '';
		// fade tilbage tekst
		changeOpac(100,'mainSiteArea');
 		document.getElementById('mainSiteArea').style.removeAttribute('filter');
 	}
}

function closeDialog(myObj) {
	var myObj = document.getElementById(myObj);
	var IE = document.all;
	if (myObj) {
		myObj.style.visibility = 'hidden';
		myObj.style.zIndex = '-100';
		myObj.innerHTML = '';
		// fade tilbage tekst
		changeOpac(100,'mainSiteArea');
 		document.getElementById('mainSiteArea').style.removeAttribute('filter');
 	}
}


function flip(id,on,str) {
	showL = document.getElementById('textlayer');
	id = document.getElementById(id);
	if (on) { 
		showL.style.visibility = 'visible';
		showL.innerHTML = str;
		showL.style.pixelLeft = getOffset(id,'left')+15;
		showL.style.pixelTop = getOffset(id,'top')+2;
	}
	else { 
		showL.innerHTML = "";
		showL.style.visibility = 'hidden';
		
		}
}

function getOffset(obj, dim) {
	if(dim=="left") {
		oLeft = obj.offsetLeft; 
		while(obj.offsetParent!=null) { 
		oParent = obj.offsetParent ;
		oLeft += oParent.offsetLeft ;
		obj = oParent ;
	}
		return oLeft
	}else if(dim=="top"){
		oTop = obj.offsetTop;
		while(obj.offsetParent!=null) {
		oParent = obj.offsetParent;
		oTop += oParent.offsetTop;
		obj = oParent ;
	}
		return oTop;
	}else{
		alert("Error: invalid offset dimension '" + dim + "' in getOffset()");
		return false;
	}

} 

function getElementHeight(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.clip.height;
	} else {
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if (op5) { 
			xPos = elem.style.pixelHeight;
		} else {
			xPos = elem.offsetHeight;
		}
		return xPos;
	} 
}


function jConfirmDialog(strDialogText, strDialogTitle, formId) {
  jConfirm(strDialogText, strDialogTitle, function(result){
    if (result) {
      $("form[name='"+formId+"']").submit();
    } else {
      return false;
    }
  });
}

function doOverlib(myText) {
	return overlib(myText,CSSCLASS,CENTER,BELOW,WIDTH,200,FGCLASS,'overlibFGlight',BGCLASS,'overlibBG',1,DELAY,100);
}

var dateFormat = function () {
	var	token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,
		timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
		timezoneClip = /[^-+\dA-Z]/g,
		pad = function (val, len) {
			val = String(val);
			len = len || 2;
			while (val.length < len) val = "0" + val;
			return val;
		};

	// Regexes and supporting functions are cached through closure
	return function (date, mask, utc) {
		var dF = dateFormat;

		// You can't provide utc if you skip other args (use the "UTC:" mask prefix)
		if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) {
			mask = date;
			date = undefined;
		}

		// Passing date through Date applies Date.parse, if necessary
		date = date ? new Date(date) : new Date;
		if (isNaN(date)) throw SyntaxError("invalid date");

		mask = String(dF.masks[mask] || mask || dF.masks["default"]);

		// Allow setting the utc argument via the mask
		if (mask.slice(0, 4) == "UTC:") {
			mask = mask.slice(4);
			utc = true;
		}

		var	_ = utc ? "getUTC" : "get",
			d = date[_ + "Date"](),
			D = date[_ + "Day"](),
			m = date[_ + "Month"](),
			y = date[_ + "FullYear"](),
			H = date[_ + "Hours"](),
			M = date[_ + "Minutes"](),
			s = date[_ + "Seconds"](),
			L = date[_ + "Milliseconds"](),
			o = utc ? 0 : date.getTimezoneOffset(),
			flags = {
				d:    d,
				dd:   pad(d),
				ddd:  dF.i18n.dayNames[D],
				dddd: dF.i18n.dayNames[D + 7],
				m:    m + 1,
				mm:   pad(m + 1),
				mmm:  dF.i18n.monthNames[m],
				mmmm: dF.i18n.monthNames[m + 12],
				yy:   String(y).slice(2),
				yyyy: y,
				h:    H % 12 || 12,
				hh:   pad(H % 12 || 12),
				H:    H,
				HH:   pad(H),
				M:    M,
				MM:   pad(M),
				s:    s,
				ss:   pad(s),
				l:    pad(L, 3),
				L:    pad(L > 99 ? Math.round(L / 10) : L),
				t:    H < 12 ? "a"  : "p",
				tt:   H < 12 ? "am" : "pm",
				T:    H < 12 ? "A"  : "P",
				TT:   H < 12 ? "AM" : "PM",
				Z:    utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
				o:    (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
				S:    ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10]
			};

		return mask.replace(token, function ($0) {
			return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
		});
	};
}();

// Some common format strings
dateFormat.masks = {
	"default":      "ddd mmm dd yyyy HH:MM:ss",
	shortDate:      "m/d/yy",
	mediumDate:     "mmm d, yyyy",
	longDate:       "mmmm d, yyyy",
	fullDate:       "dddd, mmmm d, yyyy",
	shortTime:      "h:MM TT",
	mediumTime:     "h:MM:ss TT",
	longTime:       "h:MM:ss TT Z",
	isoDate:        "yyyy-mm-dd",
	isoTime:        "HH:MM:ss",
	isoDateTime:    "yyyy-mm-dd'T'HH:MM:ss",
	isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"
};

// Internationalization strings
dateFormat.i18n = {
	dayNames: [
		"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
		"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
	],
	monthNames: [
		"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
		"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
	]
};

// For convenience...
Date.prototype.format = function (mask, utc) {
	return dateFormat(this, mask, utc);
};

var dates = {
    convert:function(d) {
        // Converts the date in d to a date-object. The input can be:
        //   a date object: returned without modification
        //  an array      : Interpreted as [year,month,day]. NOTE: month is 0-11.
        //   a number     : Interpreted as number of milliseconds
        //                  since 1 Jan 1970 (a timestamp)
        //   a string     : Any format supported by the javascript engine, like
        //                  "YYYY/MM/DD", "MM/DD/YYYY", "Jan 31 2009" etc.
        //  an object     : Interpreted as an object with year, month and date
        //                  attributes.  **NOTE** month is 0-11.
        return (
            d.constructor === Date ? d :
            d.constructor === Array ? new Date(d[0],d[1],d[2]) :
            d.constructor === Number ? new Date(d) :
            d.constructor === String ? new Date(d) :
            typeof d === "object" ? new Date(d.year,d.month,d.date) :
            NaN
        );
    },
    compare:function(a,b) {
        // Compare two dates (could be of any type supported by the convert
        // function above) and returns:
        //  -1 : if a < b
        //   0 : if a = b
        //   1 : if a > b
        // NaN : if a or b is an illegal date
        // NOTE: The code inside isFinite does an assignment (=).
        return (
            isFinite(a=this.convert(a).valueOf()) &&
            isFinite(b=this.convert(b).valueOf()) ?
            (a>b)-(a<b) :
            NaN
        );
    },
    inRange:function(d,start,end) {
        // Checks if date in d is between dates in start and end.
        // Returns a boolean or NaN:
        //    true  : if d is between start and end (inclusive)
        //    false : if d is before start or after end
        //    NaN   : if one or more of the dates is illegal.
        // NOTE: The code inside isFinite does an assignment (=).
       return (
            isFinite(d=this.convert(d).valueOf()) &&
            isFinite(start=this.convert(start).valueOf()) &&
            isFinite(end=this.convert(end).valueOf()) ?
            start <= d && d <= end :
            NaN
        );
    }
}
