function validateKeyUp(e) {
	if (typeof e == "undefined") {
		e = window.event;
	}
	
	if (e.keyCode == 13) {
		document.formLogin.submit();
	}
}

var ciffer = /^\d*$/; 
function tvingCifre(feltObj){

	if (ciffer.test(feltObj.value)) {
		// alt er ok
	} else {
		var til = "";
		var fra = feltObj.value;
		for (var i=0; fra.length>i; i++ ) 
			if ( ciffer.test( fra.charAt(i) ) )
				til += fra.charAt(i);
		feltObj.value = til;
	}
}

function validateEmail(email){
	if (email.length == 0){
		return false;
	}
	found = false;
	for (i=0; i < email.length; i=i+1) {
		if (email.charAt(i) == "@") {
			var num = i;
			found = true;
		}
	} //slut for
	if (found == false) {
	  return false;
	} else {
		//@fundet på plads num.
		num++;
		komma1found = false;
		for (num; num < email.length; num++){
			if(email.charAt(num) == "."){
				komma1found = true;
				var num2 = num;
			}
		}
		if (komma1found == false){
			return false;
		} else {
			//tester for tegn efter komma.
			var t = email.length -3;
			if (num2 > t){
				return false;
			}
		}
	}
	return true;
}//end function

function popupHelp(helpId){
	var url = "help.php?helpId="+helpId;
	window.open(url,"PopUpHelp"+helpId,"width=20,height=20,left=20,top=20,toolbar=no,location=no,directories=no,status=no,scrollbars=yes");
}
function validateNyhedsbrev(){
	var f = document.forms.formNewsletter;

	if (f.email.value == "Indtast e-mail..." || f.email.value == ""){
		alert("Indtast venligst e-mail");	
		return false;
	}

	if (! validateEmail(f.email.value)){
		alert("Den indtastede e-mail er ikke korrekt. \nPrøv venligst igen.");	
		f.email.focus();
		return false;
	}

	return true;
}

var nlFirst = true;
function nlRemText(){
	if (nlFirst){
		document.forms.formNewsletter.email.value = "";
		nlFirst = false;
	}
}


function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
   // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
   // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
   // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
   // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

function fadeOut(objId,opacity) {
  if (document.getElementById) {
	obj = document.getElementById(objId);
	if (opacity >= 10) {
	  setOpacity(obj, opacity);
	  opacity -= 10;
	  window.setTimeout("fadeOut('"+objId+"',"+opacity+")", 50);
	} 
  }
}

function fadeOutAndRedir(objId,opacity,url) {
  if (document.getElementById) {
	obj = document.getElementById(objId);
	if (opacity >= 5) {
	  setOpacity(obj, opacity);
	  opacity -= 5;
	  window.setTimeout("fadeOutAndRedir('"+objId+"',"+opacity+",'"+url+"')", 100);
	} else {
		setOpacity(obj, 0);
		document.location.href = url;
	}
  }
}

function fadeIn(objId,opacity) {
  if (document.getElementById) {
	obj = document.getElementById(objId);
	if (obj != null){
		if (opacity <= 100) {
		
		  setOpacity(obj, opacity);
		  opacity += 10;
		  window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
		}
	}
  }
}


var ciffer = /^\d*$/; 
function tvingCifre(feltObj){

	if (ciffer.test(feltObj.value)) {
		// alt er ok
	} else {
		var til = "";
		var fra = feltObj.value;
		for (var i=0; fra.length>i; i++ ) 
			if ( ciffer.test( fra.charAt(i) ) )
				til += fra.charAt(i);
		feltObj.value = til;
	}
}

function validateEmail(email){
	if (email.length == 0){
		return false;
	}
	found = false;
	for (i=0; i < email.length; i=i+1) {
		if (email.charAt(i) == "@") {
			var num = i;
			found = true;
		}
	} //slut for
	if (found == false) {
	  return false;
	} else {
		//@fundet på plads num.
		num++;
		komma1found = false;
		for (num; num < email.length; num++){
			if(email.charAt(num) == "."){
				komma1found = true;
				var num2 = num;
			}
		}
		if (komma1found == false){
			return false;
		} else {
			//tester for tegn efter komma.
			var t = email.length -3;
			if (num2 > t){
				return false;
			}
		}
	}
	return true;
}//end function

	function RandomNum(nr) {
	return parseInt((Math.random() * nr) + 1);
}

function popUpWin(popupPage,pWidth, pHeight) {	
	window.open(popupPage,"PopUp"+RandomNum(10),"width="+pWidth+",height="+pHeight+",left=20,top=20,toolbar=no,location=no,directories=no,status=no,scrollbars=yes");
}

function popupHelp(helpId){
	var url = "help.php?helpId="+helpId;
	window.open(url,"PopUpHelp"+helpId,"width=20,height=20,left=20,top=20,toolbar=no,location=no,directories=no,status=no,scrollbars=yes");
}

/*
function getOffsetTop(element, top) {
	if (top == null)
		top = null;
		
	alert(element.tagName);
	top += parseInt(element.offsetTop);
	
	alert(element.offsetTop + " / " + top);
	if (element != document.body) {
		top += getOffsetTop(element.parentNode, top);
	}
	
	return top;
}
*/

var showingProfilPopup = false;
var popupProfilId = -1;

function profilPopup(event, link, profilId) {
	if (event == null)
		event = window.event;
	if (showingProfilPopup && popupProfilId == profilId) {
		profilPopupLuk();
		return;
	}

	var elem = link;
	var xPos = elem.offsetLeft;
	var tempEl = elem.offsetParent;
  	while (tempEl != null) {
  		xPos += tempEl.offsetLeft;
		tempEl = tempEl.offsetParent;
  	}

	var yPos = elem.offsetTop;
	tempEl = elem.offsetParent;
	while (tempEl != null) {
  		yPos += tempEl.offsetTop;
		tempEl = tempEl.offsetParent;
  	}

	var profilPopupDiv = document.getElementById("profilPopup");

	xPos -= 234;
	if (navigator.appName.indexOf("Internet Explorer") == -1) {
		xPos += 20;
	}
	yPos += 8;
	
	profilPopupDiv.style.left = xPos + "px";
	profilPopupDiv.style.top = yPos + "px";

	var profilData = arrProfiler[profilId];

	var popupProfilTekstTd = document.getElementById("popupProfilTekst");
	popupProfilTekstTd.innerHTML = "<strong>" + profilData["brugernavn"] + "</strong><br><br>" + profilData["profilTekst"] + "<br>" + 
									"<div align=\"right\">[<a href=\"javascript:profilPopupLuk();\">Luk</a>]&nbsp;&nbsp;&nbsp;</div>";

	var popupProfilLink = document.getElementById("popupProfilLink");
	popupProfilLink.setAttribute("href", "profil.php?profilId=" + profilId);

	var popupProfilPostLink = document.getElementById("popupProfilPostLink");
	popupProfilPostLink.setAttribute("href", "profil.php?action=compose&profilId=" + profilId);

	var popupProfilBillede = document.getElementById("popupProfilBillede");
	popupProfilBillede.src = profilData["profilBillede"];
	
	profilPopupDiv.style.display = "block";

	showingProfilPopup = true; 
	popupProfilId = profilId;
}

function profilPopupLuk() {
	var profilPopupDiv = document.getElementById("profilPopup");
	profilPopupDiv.style.display = "none";
	showingProfilPopup = false;
}

function trim(str) {

	return str.replace(/^\s+|\s+$/g, '') ;

}