function clearText(thefield)
{
	if (thefield.defaultValue==thefield.value)
	thefield.value = ""
}

function checkEmail (frm) 
{ 
  if (  frm.email.value.match(/^[A-Z0-9_.-]+@[A-Z0-9_.-]+\.[A-Z0-9_]{2,3}$/i) 
    && !frm.email.value.match(/^\.|\.\.|\.@|@\./) ) 
    frm.submit() 
  else 
    alert('Indtastet emailadresse er ikke gyldig...'); 
};

function openWindow(url,w,h) {
	popup=window.open(url,'ny','toolbar=no,copyhistory=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=' + w + ',height=' + h);
        if (!(navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion.substring(0,1)) <4)) 
		{popup.focus();}
}

function validateSearchInput(standardValue, refURL)
{
	var searchBox = document.getElementById("search")
	var searchForm = document.getElementById("searchForm")
	
	if (searchBox.value == "" || searchBox.value == standardValue || searchBox.value.length < 2)
	{	
		if (searchBox.value == standardValue)
		{
			alert("Du mangler at indtaste et søgeord!")
			searchBox.value = "";
			searchBox.focus();
		}
		else if (searchBox.value.length == 0)
		{
			alert('Du mangler at indtaste et søgeord!');
			searchBox.focus();
		}
		else if (searchBox.value.length < 2)
		{
			alert("Du skal minimum indtaste et søgeord på 2 bogstaver!")
			searchBox.select();
			searchBox.focus();
		}
		return false;
	}
	else
	{
		searchForm.action = refURL;
		searchForm.submit();
	}
}

function validateSitemapSearchInput(pageID, pageName, standardValue)
{
	if (document.getElementById("sitemapSearch").value == "" || document.getElementById("sitemapSearch").value == standardValue)
	{
		alert('Du skal indtaste et søgeord!');
		return false;
	}
	else
	{
		top.location.href = "/" + pageID + "-soegning.htm?search=" + document.getElementById("sitemapSearch").value
	}
}

function setImgClass(imgID, action)
{
	if (action == "over")
	{
		document.getElementById(imgID).className = "galleryImgOver";
	}
	else if (action == "out")
	{
		document.getElementById(imgID).className = "galleryImg";
	}
}

function getXMLHTTP() {
    var http_request = false;

    if  (window.XMLHttpRequest) { // Mozilla, Safari, IE7.0+  ...
        http_request = new XMLHttpRequest();
    }
    else if (window.ActiveXObject)  { // IE 6.0-
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                alert("Microsoft.XMLHTTP")
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {
            }
        }
    }
    return http_request;
}

function popPicture(imageId) {
	imageId = imageId.substring(0,imageId.length-4);
	var picWin = window.open("", "picWin", "location=0,toolbar=0,status=0,scrollbars=1");
	picWin.window.moveTo(0,0);
	picWin.window.resizeTo(screen.width,screen.height);
	picWin.document.writeln("<html><head><title>Full size</title></head><body style=\"margin:0; background: #000000\"><table border=\"0\" width=\"100%\" height=\"100%\"><tr><td style=\"vertical-align: middle; text-align: center\">");
	picWin.document.writeln("<img src=\"/images/"+imageId+"/big/full.jpg\" border=\"0\" />");
	picWin.document.writeln("<div style=\"position: absolute; top: 0px; left: 0px; cursor: pointer\" onclick=\"window.close()\"><img src=\"/pictures/gallery/closebutton.png\" border=\"0\" /></div>");
	picWin.document.writeln("</td></tr></table></body></html>");
	
}

var galleryActive = 0;
var locationWhenClickedImage = 0;
var browser=navigator.appName;
browser = browser.toLowerCase();

function loadGalleryImg(imageID, galleryID, imageURL, imageHeight, imageWidth, orderID) 
{
	galleryActive = 1;
	    
	  locationWhenClickedImage = 0;    
	if (typeof window.pageYOffset == "number") locationWhenClickedImage = window.pageYOffset;
	else if (document.documentElement && document.documentElement.scrollTop)
		locationWhenClickedImage = document.documentElement.scrollTop;
	else if (document.body && document.body.scrollTop) 
		locationWhenClickedImage = document.body.scrollTop; 
	else if (window.scrollY) locationWhenClickedImage = window.scrollY;
  		
	document.getElementById("galleryImg").src="/pictures/standard/clear.gif";
	http_request = getXMLHTTP();
	
	// Kontrollerer XML paa klienten
	if (!http_request){
	alert(NoXMLHTTP);
	return false;
	}

	var strURL = "/includes/pages/module_gallery_load.asp?imgID=" + imageID + "&galleryID=" + galleryID + "&orderID=" + orderID + "&noCache=" + Math.random(); + "";
	http_request.onreadystatechange = function() 
	{
		if (http_request.readyState == 4) 
		{
			if (http_request.status == 200) 
			{
				orgImgWidth = imageWidth;
				orgImgHeight = imageHeight;
				var galleryImage = document.getElementById("galleryImg");
				var galleryImageHolder = document.getElementById("galleryTemplateInnerBox");
				var imgDescription = document.getElementById('imgDescription');
				var imgDescriptionContainer = document.getElementById("imgDescriptionContainer");
				var imgNavigation = document.getElementById("imgNavigation")
				imgNavigation.innerHTML = "";
				
				galleryImage.style.display = "none";
				document.getElementById("galleryTemplateBlackbox").style.display = "block";

				 var screenWidth;
				 var screenHeight;
				 
				 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
				 
				 if (typeof window.innerWidth != "undefined")
				 {
				      screenWidth = window.innerWidth;
				      screenHeight = window.innerHeight;
				 }
				 
				// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
				
				 else if (typeof document.documentElement != "undefined"
				     && typeof document.documentElement.clientWidth !=
				     "undefined" && document.documentElement.clientWidth != 0)
				 {
				       screenWidth = document.documentElement.clientWidth;
				       screenHeight = document.documentElement.clientHeight;
				 }
				 
				 // older versions of IE
				 
				 else
				 {
				       screenWidth = document.getElementsByTagName("body")[0].clientWidth;
				       screenHeight = document.getElementsByTagName("body")[0].clientHeight;
				 }				

				var splitResult = http_request.responseText.split("|||"); // Split funktion
				theDescription = splitResult[1];
				if (theDescription != "") {
					if (theDescription.length > 100) {
						imgNavigation.style.textAlign = "left";	
						imgDescHeight = 110;
					} else {
						imgNavigation.style.textAlign = "center";	
						imgDescHeight = 40;
					}
					imgNavigation.style.display = "block";
					imgNavigation.style.height = imgDescHeight + "px";
					imgNavigation.innerHTML = theDescription;
				} else {
					imgNavigation.style.height = "";
					imgNavigation.style.display = "none";
					imgNavigation.innerHTML = "";
					imgDescHeight = 0;
				}
				
				orgScreenWidth = screenWidth;
				orgScreenHeight = screenHeight;
				screenWidth = screenWidth-250;
				screenHeight = screenHeight-100-imgDescHeight;

				//galleryImage.src = imageURL;
				galleryImage.src = "/includes/pages/module_gallery_getImg.asp?name=" + imageURL + "&maxWidth=" + screenWidth + "&maxHeight=" + screenHeight;
				imgWidth = orgImgWidth;
				imgHeight = orgImgHeight;
				var newWidth = imgWidth;
				var newHeight = imgHeight;		
				if (newWidth > screenWidth || newHeight > screenHeight) {
					if (newWidth > screenWidth) {
 						newWidth = screenWidth;
 						newHeight = parseInt((screenWidth/imgWidth)*imgHeight);
					} else {
						if (newHeight > screenHeight) {
							newHeight = parseInt(screenHeight);
							var diff = (newHeight-screenHeight);
							newWidth = ((imgWidth/imgHeight))*newHeight;
						}
					}
				if (newHeight > screenHeight) {
					var diff = (newHeight-screenHeight);
					newHeight = parseInt((screenHeight/imgHeight)*newHeight);
					newHeight = screenHeight;
					newWidth = newWidth - ((imgWidth/imgHeight)*diff);
				}					

					galleryImage.style.width = newWidth + "px";
					galleryImage.style.height = newHeight + "px";
					galleryImage.alt = "Klik her for at se billedet i fuld størrelse";
					galleryImage.onclick = new Function("popPicture('"+imageURL+"')");
					galleryImage.style.cursor = "pointer";							
				} else {
					newWidth = imgWidth;
					newHeight = imgHeight;
					galleryImage.style.width = newWidth + "px";
					galleryImage.style.height = newHeight + "px";					
					galleryImage.alt = "";
					galleryImage.onclick = "";
					galleryImage.style.cursor = "default";
				}

				if (splitResult[0] != "")
				{ imgDescriptionContainer.style.display = "block";imgDescription.innerHTML = splitResult[0];}
				else
				{ imgDescriptionContainer.style.display = "none"; }
				galleryImageHolder.style.width = newWidth + 20 + "px";
				galleryImageHolder.style.height = newHeight + 35 + imgDescHeight + "px";
				
				document.getElementById("galleryTemplateBlackbox").style.height = orgScreenHeight+locationWhenClickedImage + "px";
				galleryImageHolder.style.display = "block";
				galleryImage.style.display = "block";
				if (browser == "netscape") {
					galleryImageHolder.style.top = parseInt((orgScreenHeight-(galleryImageHolder.offsetHeight))/2)+ locationWhenClickedImage + "px";
				} else {
					galleryImageHolder.style.top = parseInt((orgScreenHeight-(galleryImageHolder.offsetHeight))/2)+ locationWhenClickedImage + "px";
				}
				galleryImageHolder.style.left = parseInt((orgScreenWidth-galleryImageHolder.offsetWidth)/2) + "px";
					
			}
		}
	}

	http_request.open('GET', strURL, true);
	http_request.send(null);
}

function reloadMe() {
	if(galleryActive==0) {
		location.href=location.href;
	}
}

function hideGalleryView()
{
	document.getElementById("galleryTemplateInnerBox").style.display = "none";
	document.getElementById("galleryTemplateBlackbox").style.display = "none";
	galleryActive = 0;
}


function checkGuestbook(frm) 
{
	var send,varAlert;
	varAlert = "";

	if (frm.name.value == "") {
		varAlert = varAlert + "- Du skal indtaste dit navn!\n";
		send = false;
	}
	if (frm.message.value == "") {
		varAlert = varAlert + "- Du har ikke skrevet noget indlæg!";
		send = false;
	}
	if (send == false) { 
		alert("Der opstod følgende fejl:\n\n" + varAlert);
	}
	else {
		document.getElementById('secure').value = "passed";
		frm.submit()
	}
}
function standardTopMenu(menuId){
	document.getElementById('textLink'+menuId).className='topMenuHref';
	document.getElementById('txtDiv_id'+menuId).className='tMenuTxtDiv';
	document.getElementById('button_id'+menuId+'_left').style.background='url(/pictures/bg/button_left.jpg) top left no-repeat';
	document.getElementById('button_id'+menuId+'_repeat').style.background='url(/pictures/bg/button_repeat.jpg) top left repeat-x';
	document.getElementById('button_id'+menuId+'_right').style.background='url(/pictures/bg/button_right.jpg) top right no-repeat';	
}
function standardTopMenuOver(menuId){
	document.getElementById('textLink'+menuId).className='topMenuHrefOver';
	document.getElementById('txtDiv_id'+menuId).className='tMenuTxtDivOver';
	document.getElementById('button_id'+menuId+'_left').style.background='url(/pictures/bg/button_left_over.jpg) top left no-repeat';
	document.getElementById('button_id'+menuId+'_repeat').style.background='url(/pictures/bg/button_repeat_over.jpg) top left repeat-x';
	document.getElementById('button_id'+menuId+'_right').style.background='url(/pictures/bg/button_right_over.jpg) top right no-repeat';	
}

function vmsOut(menuId,menuColor,menuDecoration,menuTxtMargin){
	document.getElementById('vms'+menuId).style.color=menuColor;
	document.getElementById('vms'+menuId).style.textDecoration=menuDecoration;
	document.getElementById('vms_txtDiv'+menuId).style.padding=menuTxtMargin;

}
function vmsOver(menuId,menuColor,menuDecoration,menuTxtMargin){
	document.getElementById('vms'+menuId).style.color=menuColor;
	document.getElementById('vms'+menuId).style.textDecoration=menuDecoration;
	document.getElementById('vms_txtDiv'+menuId).style.padding=menuTxtMargin;

}

function checkNewsletter(e)
{
	err=0,str="Der opstod følgende fejl:\n\n";
	
	mai = /^[0-9a-z\.\_\-]+\@[0-9a-z\.\_\-]{1,}\.[a-z]{2,4}$/;
	nav = /^[\wæøå\s.]+$/i
	var errorField = "";
	
	if(!nav.test(e.name.value)){
	str += (e.name.value.length>0)?"- Det indtastede navn er ikke gyldigt!\n":"- Du mangler at indtaste et navn i feltet!\n"
	err++
	if(errorField == "") {
		errorField = "name";
	}
	} else {
		document.getElementById("namelabel").innerHTML = "&nbsp;*";	
	}
	
	if(!mai.test(e.email.value)){
	str += (e.email.value.length>0)?"- Den indtastede e-mail er ikke gyldig!\n":"- Du mangler at indtaste et e-mail i feltet!\n"
	err++
	if(errorField == "") {
		errorField = "email";
	}
	} else {
		document.getElementById("emaillabel").innerHTML = "&nbsp;*";
	}
	
	if(e.firma.value.length==0){
	str += "- Du mangler at indtaste dit firmanavn!\n"
	err++
	if(errorField == "") {
		errorField = "firma";
	}
	} else {
		document.getElementById("firmalabel").innerHTML = "&nbsp;*";
	}
	
	
	if(e.postnr.value.length==0){
	str += "- Du mangler at indtaste postnr!\n"
	err++
	if(errorField == "") {
		errorField = "postnr";
	}
	} else {
		document.getElementById("postnrlabel").innerHTML = "&nbsp;*";
	}
	if(e.by.value.length==0){
	str += "- Du mangler at indtaste by!\n"
	err++
	if(errorField == "") {
		errorField = "by";
	}
	} else {
		document.getElementById("bylabel").innerHTML = "&nbsp;*";
	}
	
	
	if(e.stilling.value.length==0){
	str += "- Du mangler at indtaste din stilling!\n"
	err++
	if(errorField == "") {
		errorField = "stilling";
	}
	} else {
		document.getElementById("stillinglabel").innerHTML = "&nbsp;*";
	}
	
	if(err>0)
	{
		alert(str);
		document.getElementById(errorField).focus();
		document.getElementById(errorField+"label").innerHTML = "&nbsp;*";
		return false
	}
	else
	{
		document.getElementById('newsletter_validation').value = "yes";
		e.submit();
	}
}
