function toggle_content()
{
                             var array          = getElementsByClassName('middle');
                             if(array.length > 0)
                             {
                                                          for(var i=0; i<array.length; i++)
                                                          {
                                                                                       array[i].style.display = ( array[i].style.display == 'block' || array[i].style.display == '' ? 'none' : 'block' );
                                                          }
                             }
                             var array          = getElementsByClassName('frontpagebanner');
                             if(array.length > 0)
                             {
                                                          for(var i=0; i<array.length; i++)
                                                          {
                                                                                       array[i].style.display = ( array[i].style.display == 'block' || array[i].style.display == '' ? 'none' : 'block' );
                                                          }
                             }
                             var array          = getElementsByClassName('combine');
                             if(array.length > 0)
                             {
                                                          for(var i=0; i<array.length; i++)
                                                          {
                                                                                       array[i].style.display = ( array[i].style.display == 'block' || array[i].style.display == '' ? 'none' : 'block' );
                                                          }
                             }
}


function dosearch()
{
var Searchterm = document.getElementById("search_text" );



document.location.href = "/1345.aspx?Search=" + Searchterm.value;

}
function dosearch1()
{
var Searchterm = document.getElementById("findord" );



document.location.href = "/1345.aspx?Search=" + Searchterm.value;

}



function print_glossary()
{
                             $('print_container').innerHTML = $('scroll_container').innerHTML;
                             if(document.all) // Hide bg content if IE
                             {
                                                          toggle_content();
                             }
                             window.print();
                             if(document.all) // Hide bg content if IE
                             {
                                                          toggle_content();
                             }

}



function getSubpageFeed(divid)
{
var DivContainer = document.getElementById(divid);


jQuery.get("/ajax/subpagefeed.aspx", { }, // Ajax call script, sending the letter as a param
	function(data)
	{

DivContainer.innerHTML	= '';

DivContainer.innerHTML = data;

go_sifr();

		});

}


function emailCheck (emailStr) {
	var checkTLD=1; //Check for two/three letter domain?
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) {
		//alert("Email address seems incorrect (check @ and .'s)");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
		//	alert("Ths username contains invalid characters.");
			return false;
		}
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			//alert("Ths domain name contains invalid characters.");
			return false;
		}
	}
	if (user.match(userPat)==null) {
		//alert("The username doesn't seem to be valid.");
		return false;
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				//alert("Destination IP address is invalid!");
				return false;
			}
		}
		return true;
	}
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
	if (domArr[i].search(atomPat)==-1) {
			//alert("The domain name does not seem to be valid.");
			return false;
		}
	}
	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {
		//alert("The address must end in a well-known domain or two letter " + "country.");
		return false;
	}
	if (len<2) {
		//alert("This address is missing a hostname!");
		return false;
	}
	return true;
}

function TilmeldNyhedsbrev()
{
    var newsnavn1 = document.getElementById("newsnavn" );
    var newsmail1 = document.getElementById("newsmail");
    
    var msg = "Du skal udfylde flg. felter:\n\n";
var alertflag = false;

if(newsnavn1.value == "")
{
msg = msg + "- Navn\n";
alertflag = true;
}


if(newsmail1.value == "" )
{
msg = msg + "- E-mail adresse\n";
alertflag = true;
}


if(!emailCheck(newsmail1.value))
{
msg = msg + "- E-mail er ugyldig\n";
alertflag = true;
}


if(alertflag)
{alert(msg );}
else
{
 
 jQuery.post("/globale-elementer/banner/tilmeldningnyhedsbrev.aspx", { navn1: newsnavn1.value, mail1: newsmail1.value}, // Ajax call script, sending the letter as a param
	function(data)
	{
		
 var contTak = document.getElementById("NewsLetterTakkeText" );
 var contIntro = document.getElementById("NewsLetterIntroText" );

var overskrift =   document.getElementById("NyhedsbrevSignupTitle");

if(overskrift){
//overskrift.style.visibility="hidden";
overskrift.innerText = "";

}

if(contTak){
	
contTak.style.display	= 'block';
}


if(contIntro){
	
contIntro.style.display	= 'none';
}

	});
 
 
}

}


function SubmitExtendedContactForm(type)
{
var ExtendedFormName = document.getElementById("ExtendedFormName" );
var ExtendedFormEmail= document.getElementById("ExtendedFormEmail" );
var ExtendedFormTlf= document.getElementById("ExtendedFormTlf" );
var ExtendedFormMessage= document.getElementById("ExtendedFormMessage" );

var msg = "Du skal udfylde flg. felter:\n\n";
var alertflag = false;

if(ExtendedFormName.value == "")
{
msg = msg + "- Navn\n";
alertflag = true;
}
if(ExtendedFormTlf.value == "")
{
msg = msg + "- Telefon\n";
alertflag = true;
}

if(ExtendedFormEmail.value == "")
{
msg = msg + "- E-mail adresse\n";
alertflag = true;
}


if(ExtendedFormMessage.value == "")
{
msg = msg + "- Besked\n";
alertflag = true;
}



if(alertflag)
{alert(msg );}
else
{
if(type==1)
{
var ExtendedFormContainer = document.getElementById("ExtendedFormContainer");

jQuery.post("/ajax/kontaktformular.aspx", { navn: ExtendedFormName.value, message: ExtendedFormMessage.value, email: ExtendedFormEmail.value, tlf: ExtendedFormTlf.value}, // Ajax call script, sending the letter as a param
	function(data)
	{
		

ExtendedFormContainer.innerHTML	= '';

ExtendedFormContainer .innerHTML = data;
		});

}
else
{
jQuery.post("/ajax/kontaktformular.aspx", { navn: ExtendedFormName.value, message: ExtendedFormMessage.value, email: ExtendedFormEmail.value, tlf: ExtendedFormTlf.value}, // Ajax call script, sending the letter as a param
	function(data)
	{
		

alert(data);	
tween_call_me('call_me_container');
	});

}



}





}

/**
*
* arrowBlackToBlue set hovers on all .arrowBlack elements (if mac, we change background position as well)
*/
function arrowBlackToBlue()
{
	var arr_blues	= getElementsByClassName('arrowBlue');
	var arr_blacks	= getElementsByClassName('arrowBlack');
	for(var j=0; j<arr_blacks.length; j++)
	{
		arr_blacks[j].onmouseover = function()
		{
			this.className = 'arrowBlue';	
		}
		arr_blacks[j].onmouseout = function()
		{
			this.className = 'arrowBlack';	
		}
		// Set new background position if on mac :/
		if(navigator.platform.indexOf("Mac") != -1)
		{
			arr_blacks[j].style.backgroundPosition = '0px 2px';
		}
	}
	for(var j=0; j<arr_blues.length; j++)
	{
		arr_blues[j].onmouseover = function()
		{
			this.className = 'arrowBlue';	
		}
		arr_blues[j].onmouseout = function()
		{
			this.className = 'arrowBlack';	
		}
		// Set new background position if on mac :/
		if(navigator.platform.indexOf("Mac") != -1)
		{
			arr_blues[j].style.backgroundPosition = '0px 2px';
		}
	}
}


function findPrevDetail(currid)
{


var previd = 0;

for (i=0;i<portfoliolist.length;i++)
{


if(portfoliolist[i] == currid)
{
break;
}
previd = portfoliolist[i];



}




if(previd == 0)
{
previd = portfoliolist[portfoliolist.length-1];

}
return previd;
}

function findNextDetail(currid)
{


var nextid = 0;

for (i=0;i<portfoliolist.length;i++)
{


	if(portfoliolist[i] == currid)
	{
		if(portfoliolist.length == (i+1))
		{
			nextid= portfoliolist[0];
		}
		else
		{	
			nextid = portfoliolist[i+1];
		}


	}



}





return nextid;


}

function tween_call_me(el_id)
{
	if(el_id)
	{
		var elem	= $(el_id);
		var end		= ( parseInt(elem.style.height) > 0 ? 0 : 200 );
		elem.style.height	= ( !elem.style.height ? 0 + 'px' : elem.style.height );
		elem.style.display	= 'block';
		JSTweener.addTween(elem.style, {
				time: 0.5,
				transition: 'easeOutQuart',
				height: end,
				suffix: {
					height: 'px'
				}
		});
	}
}
function show_submenu(el_id,this_el)
{
	if(el_id)
	{
		// Toggle submenu containers
		var arrSubs	= getElementsByClassName('submenu');
		for(var i=0; i<arrSubs.length; i++)
		{
			arrSubs[i].style.display = ( $(el_id) == arrSubs[i] ? 'block' : 'none' );
		}

		// Show background
		$("level_2").className = "shown";

		// Toggle 1st level menu items
		var array	= getElementsByClassName('active','div',$('level_1'));
		for(var i=0; i<array.length; i++)
		{
			array[i].className = "item";
		}

		// Mark selected as active
		$(this_el).className = "active";
	}
}

function scroll_this(scrollHeight,areaHeight)
{
	$('scrollbar').style.display	= 'block';

	var intervalScrollID;
	var intervalSpeed		= 10; // Miliseconds between each scroll update on arrow press
	var scrollSpeed			= 5; // Pixel to scroll on arrow press
	var mousePosition		= {x: 0, y: 0}
	var scrollHeight		= ( !scrollHeight ? 259 : scrollHeight ); // Height of the scrollbar area
	var areaHeight			= ( !areaHeight ? 286 : areaHeight ); // height of the visible content area
	var containerHeight		= $('scroll_container').offsetHeight; // Total height of the content to scroll
	var offsetContainerY	= $('scroll_container').offsetTop; // Start "_y pos" of the scroll container
	$('scroll_handle').style.height	= ( (areaHeight/containerHeight) * scrollHeight) + 'px'; // Set new handle height
	var handleHeight		= $('scroll_handle').offsetHeight;
	var offsetHandleY		= 11;
	var minHandleY 			= offsetHandleY;
	var maxHandleY 			= scrollHeight - $('scroll_handle').offsetHeight + offsetHandleY;

	if (!$('scroll_handle').style.top) $('scroll_handle').style.top = offsetHandleY+'px';
	if (!$('scroll_container').style.top) $('scroll_container').style.top = $('scroll_container').offsetTop+'px';

	$('scroll_handle').onmousedown = function(e)
	{
		e = e || event;
		mousePosition.x = e.clientX;
		mousePosition.y = e.clientY;

		var ox,ux	= 0;
		var oy,uy	= 0;
		var t	= $('scroll_handle');
		var u	= $('scroll_container');
		while(t.offsetParent) // Find the "absolute Y pos of the handle"
		{
			ox += t.offsetLeft;
			oy += t.offsetTop;
			t = t.offsetParent;
	
			ux += u.offsetLeft;
			uy += u.offsetTop;
			u = u.offsetParent;
		}

		document.onmousemove = function(e)
		{
			e = e || event;
			var xdiff = mousePosition.x-e.clientX;
			var ydiff = mousePosition.y-e.clientY;
			var new_y = (parseInt($('scroll_handle').style.top)-ydiff);

			if(new_y <= minHandleY)
			{
				$('scroll_handle').style.top	= offsetHandleY + 'px';
				$('scroll_container').style.top	= '0px';
			}
			else if(new_y > maxHandleY)
			{
				$('scroll_handle').style.top = maxHandleY + 'px';
				$('scroll_container').style.top	= (areaHeight-containerHeight) + 'px';
			}
			else
			{
				var percentHandleMove	= ((new_y-offsetHandleY)/(scrollHeight-handleHeight))*100; // How many % the handle have moved down
				var containerMoveY		= (containerHeight-areaHeight) * (percentHandleMove/100);
				$('scroll_handle').style.top	= new_y + 'px'; // Reposition the handle
				$('scroll_container').style.top	= -(containerMoveY) + 'px';
			}
			mousePosition.x = e.clientX;
			mousePosition.y = e.clientY;

			
				window.scroll(0,1);	
					}
		document.onmouseup = function() { document.onmousemove = function(){}; }
	}

	// Arrows
	$('scroll_down').onmousedown = function()
	{
		clearInterval(intervalScrollID);
		intervalScrollID	= setInterval("scroll_down("+scrollSpeed+","+areaHeight+","+containerHeight+","+offsetContainerY+","+minHandleY+","+maxHandleY+")",intervalSpeed);
	};
	$('scroll_down').onmouseup = function()
	{
		clearInterval(intervalScrollID);
	};
	$('scroll_up').onmousedown = function()
	{
		clearInterval(intervalScrollID);
		intervalScrollID	= setInterval("scroll_up("+scrollSpeed+","+areaHeight+","+containerHeight+","+offsetContainerY+","+minHandleY+","+maxHandleY+")",intervalSpeed);
	};
	$('scroll_up').onmouseup = function()
	{
		clearInterval(intervalScrollID);
	};
}

// Create scroll functions to be called in a setInterval()
function move_handle(scrollSpeed,areaHeight,containerHeight,offsetContainerY,minHandleY,maxHandleY,newTop)
{
	var percentContainer	= ((offsetContainerY - newTop)/(containerHeight-areaHeight))*100; // How many % the container has moved
	percentContainer		= ( percentContainer > 100 ? 100 : percentContainer );
	var handleMoveY			= maxHandleY * (percentContainer/100);
	handleMoveY				= ( handleMoveY < minHandleY ? minHandleY : handleMoveY );
	handleMoveY				= ( handleMoveY > maxHandleY ? maxHandleY : handleMoveY );
	$('scroll_handle').style.top	= handleMoveY + 'px';
}
function scroll_down(scrollSpeed,areaHeight,containerHeight,offsetContainerY,minHandleY,maxHandleY)
{
	// Move container
	var maxTop	= areaHeight - containerHeight;
	var newTop	= parseInt($('scroll_container').style.top) - scrollSpeed;
	newTop		= ( newTop < maxTop ? maxTop : newTop );
	$('scroll_container').style.top	= newTop + 'px';

	// Move handle
	move_handle(scrollSpeed,areaHeight,containerHeight,offsetContainerY,minHandleY,maxHandleY,newTop);

	
		window.scroll(0,1);	
	
}
function scroll_up(scrollSpeed,areaHeight,containerHeight,offsetContainerY,minHandleY,maxHandleY)
{
	// Move container
	var newTop	= parseInt($('scroll_container').style.top) + scrollSpeed;
	newTop		= ( newTop > offsetContainerY ? offsetContainerY : newTop );
	$('scroll_container').style.top	= newTop + 'px';

	// Move handle
	move_handle(scrollSpeed,areaHeight,containerHeight,offsetContainerY,minHandleY,maxHandleY,newTop);

	
		window.scroll(0,1);	
	
}

function show_glossary_content_item(id)
{


jQuery.get("/ajax/show_glossary_content.aspx", { letter: id}, // Ajax call script, sending the letter as a param
	function(data)
	{
		$('glossary_content').innerHTML = data;
		if($('scroll_container').offsetHeight > 286)
		{
			scroll_this(259,286); // Set scroll if needed (we need display block before we can register an offsetHeight!)
		}
		else
		{
			$('scrollbar').style.display = 'none';
		}
		go_sifr();
	});

}

/**
*
* Ajax call to show content. Sending the letter as a $_GET param to file
*/
function show_glossary_content(letter,this_el)
{
	letter	= ( !letter ? '1222' : letter); // 1st run'



	// Get all letters and mark "in-active"
	arrLetter	= getElementsByClassName('letter');
	for(var i=0; i<arrLetter.length; i++)
	{
		arrLetter[i].className = 'letter';
	}

	this_el	= ( !this_el ? arrLetter[0] : this_el ); // 1st run
	this_el.className = 'letter active'; // Mark selected
	
	jQuery.get("/ajax/show_glossary_content.aspx", { letter: letter }, // Ajax call script, sending the letter as a param


	function(data)
	{
		$('glossary_content').innerHTML = data;
		if($('scroll_container').offsetHeight > 286)
		{
			scroll_this(259,286); // Set scroll if needed (we need display block before we can register an offsetHeight!)
		}
		else
		{
			$('scrollbar').style.display = 'none';
		}
		go_sifr();
	});
}

/**
*
* Opens the glossery popup
*/
function popup_glossary()
{
	if($('id33'))
	{
		$('view_content').innerHTML	= '';
		$('id33').style.display		= 'none'; // Hide detail view
	}
	$('contact').style.display	= 'none'; // Hide contact
	$('glossary').style.display	= 'block'; // Show glossary
	$('glossary').style.height	= ($('footer').offsetTop - $('glossary').offsetTop) + 'px'; // Cover w/ white at the bottom
	show_glossary_content(); // Show the 1st letter content
	hover_close_btn();

	// Avoid (FF) bug on mac that may show "background-content" through the popup

	
		window.scroll(0,1);
	$('print_container').innerHTML = '';  
}

/**
*
* Opens the contact popup
*/
function popup_contact()
{
	if($('id33'))
	{
		$('view_content').innerHTML	= '';
		$('id33').style.display		= 'none'; // Hide detail view
	}

	$('glossary_content').innerHTML	= '';
	$('glossary').style.display		= 'none'; // Hide glossary
	$('contact').style.display		= 'block'; // Show contact
	$('contact').style.height		= ($('footer').offsetTop - $('contact').offsetTop) + 'px'; // Cover w/ white at the bottom

	go_sifr();
	hover_close_btn();


		window.scroll(0,1);	
	$('print_container').innerHTML = '';  
}

function popup_list_detail(detailID)
{

	$('glossary_content').innerHTML	= '';
	$('glossary').style.display		= 'none'; // Hide the glossary popup
	$('contact').style.display		= 'none'; // Hide the contact popup
	$('id33').style.display 		= 'block';
	$('id33').style.height			= ($('footer').offsetTop - $('page').offsetTop) + 'px'; // Cover w/ white at the bottom



	jQuery.get("/ajax/portfolio_list_detail.aspx", { detailID: detailID }, // Ajax call script, sending the detailID as a param


	function(data)
	{
$('view_content').innerHTML = data;
		if($('scroll_container').offsetHeight > 220)
		{
			scroll_this(202,220); // Set scroll if needed (we need display block before we can register an offsetHeight!)
		}
		else
		{
			$('scrollbar').style.display = 'none';
		}
		go_sifr();
		hover_close_btn();
	});

	// Avoid (FF) bug on mac that may show "background-content" through the popup

	
		window.scroll(0,1);	
	$('print_container').innerHTML = '';  
}

function show_detail_image(url)
{
	if(url)
	{
		$('large_image').innerHTML = '<img src="'+url+'" alt="" title="" />';
	}
}

/**
*
* Prints the detail popup window
*/
function print_detail_view()
{
	createCSS('.list','display:none;','print');
	createCSS('h1','display:none;','print');
	createCSS('#view_content h1','display:block;','print');
	window.print();
	createCSS('.list','display:block;','screen');
	createCSS('h1','display:block;','screen');
}

/**
*
* Assign eventHandlers specific elements for id 2.2.2 news list
*/
function hover_news_item()
{
	var array = getElementsByClassName('news_headline');
	if(array.length)
	{
		for(var i=0; i<array.length; i++)
		{
			array[i].onmouseover = function()
			{
				$('hover_line').style.top	= (this.offsetTop + this.offsetHeight) + 'px';
				$('hover_line').className	= 'shown';
			}
			array[i].onmouseout = function()
			{
				$('hover_line').className	= 'hidden';
			}
		}
	}

	var array = getElementsByClassName('news_text');
	if(array.length)
	{
		for(var i=0; i<array.length; i++)
		{
			array[i].onmouseover = function()
			{
				$('hover_line').style.top	= (this.offsetTop + this.offsetHeight) + 'px';
				$('hover_line').className	= 'shown';
			}
			array[i].onmouseout = function()
			{
				$('hover_line').className	= 'hidden';
			}
		}
	}
}

/**
*
* Assign eventHandlers for all closeBTNs
*/
function hover_close_btn()
{
	var array = getElementsByClassName('close');
	if(array.length > 0)
	{
		for(var i=0; i<array.length; i++)
		{
			array[i].onmouseover = function()
			{
				var newImgURL	= globalImageURL + 'close.btn.hover.gif';
				this.childNodes[0].src = newImgURL;
			}
			array[i].onmouseout = function()
			{
				var newImgURL	= globalImageURL + 'close.btn.gif';
				this.childNodes[0].src = newImgURL;
			}
		}
	}
}

/**
*
* Assign eventHandlers specific elements for id 3.2 list view
*/
function show_list_view()
{
	var array = getElementsByClassName('show_list_view');
	if(array.length)
	{
		for(var i=0; i<array.length; i++)
		{
			array[i].onmouseover = function()
			{
				var extraOffset	= ( this.className == 'image show_list_view' ? 0 : 7 );
				$('hover_line').style.top	= (this.offsetTop + this.offsetHeight + extraOffset) + 'px';
				$('hover_line').className	= 'shown';
			}
			array[i].onmouseout = function()
			{
				$('hover_line').className	= 'hidden';
			}
		}
	}
}

/**
*
* Reposition elements in search page (id 0.2.3) if on a mac (css won't do, 2/3 pixel jug)
*/
function reposistion_search_page()
{
	if(navigator.platform.indexOf("Mac") != -1)
	{
		if(navigator.userAgent.indexOf("Safari") != -1 && $('search_line'))
		{
			$('search_line').style.top	= ( $('search_line').offsetTop - 1) + 'px';
			$('submit_023').style.top	= ( $('submit_023').offsetTop - 1) + 'px';
			$('submit_023').style.left	= 13 + 'px';
			$('input_023').style.top 	= ( $('input_023').offsetTop - 2) + 'px';
		}
		else if(navigator.userAgent.indexOf("Firefox") != -1 && $('search_line'))
		{
			$('search_line').style.top	= ( $('search_line').offsetTop - 1) + 'px';
			$('submit_023').style.top	= ( $('submit_023').offsetTop - 1) + 'px';
			$('submit_023').style.left	= 15 + 'px';
		}
	}
}

/**
*
* Reposition elements in portfolio submenu (id 3.1.1) if on a mac (css won't do, 2/3 pixel jug)
*/
function reposition_id311_item()
{
	var array = getElementsByClassName('subitem');
	if(navigator.platform.indexOf("Mac") != -1 && array.length > 0)
	{
		for(var i=0; i<array.length; i++)
		{
			array[i].style.paddingTop	= '4px';
			array[i].style.height 		= '16px';
		}
	}
}

function reposition_searchfield()
{
	if(navigator.platform.indexOf("Mac") != -1)
	{
		$('search_line_top').style.top 	= '1px';
		$('search_value').style.top 	= '-2px';
		$('search_text').style.top 		= '0px';
		$('search_submit').style.top 	= '1px';
	}
}

function focus_searchfield()
{
	$('search_value').style.top = -20 + 'px';
	$('search_text').value = '';
	$('search_text').focus();
}
function focus_searchvalue(newTop)
{
	if($('search_text').value == '')
	{
		$('search_value').style.top = newTop + 'px';
	}

}

// Activate sifr
go_sifr();

// Add onLoad events
addLoadEvent(hover_news_item);
addLoadEvent(reposistion_search_page);
addLoadEvent(reposition_id311_item);
addLoadEvent(show_list_view);
addLoadEvent(reposition_searchfield);
