
function setCookie(name, value, expires) {
    document.cookie = name + "=" + escape(value) + "; path=/" + ((expires == null) ? "" : "; expires=" + expires.toGMTString());
}

function getCookie(name) {

    var dc = document.cookie;
    var cname = name + "=";

    if (dc.length > 0) {
        begin = dc.indexOf(cname);
        if (begin != -1) {
            begin += cname.length;
            end = dc.indexOf(";", begin);
            if (end == -1) end = dc.length;
            return unescape(dc.substring(begin, end));
        }
    }
    return null;
}


$(window).resize(function() { 
	repos($(this)) 
});


// repositions boxes on the webside according to size of screen. 
function repos(w) {
    // Get height of window

    var window_height = w.height();

	if(window_height < 510) {
		$('body').height(510);
		var window_height = w.height();
	} else {
		$('body').height(window_height);
	}


	//var main_height = window_height - $('.footer').height();
	var main_height = $('.outer-wrapper').height() - $('.footer').height();
	$('#supersize').height(main_height);
}


function autoFireLightbox() 
{
	setTimeout(function() 
	{
		if(document.location.hash && $(document.location.hash.substr(1)).rel.indexOf('lightbox')!=-1) 
		{
			myLightbox.start($(document.location.hash.substr(1)));
		}
	},
		250
	);
}
//Event.observe(window, 'load', autoFireLightbox, false);


/*##########*/
/*   LOGIN  */
/*##########*/
function logg_inn()
{
	//document.LOGIN.Submit1.disabled=true;
	var sMeld;
	sMeld = "";
	if (document.LOGIN.user.value == "")
	{sMeld = sMeld + "- Brukernavn må fylles ut.\n";}
	if (document.LOGIN.password.value == "")
	{sMeld = sMeld + "- Passord må fylles ut.\n";}

	if (sMeld == "")
	{
		document.LOGIN.CMD.value="LOGIN";
		document.LOGIN.submit();
	}
	else
	{
		alert(sMeld);
		document.LOGIN.Submit1.disabled=false;
	}
}

function getPassword()
{
	// disable button
	document.FORGOT_PASSWORD.Submit2.disabled = true;

	var sMeld;
	sMeld = "";
	if (document.FORGOT_PASSWORD.email.value == "")
	{sMeld = sMeld + "- E-post må fylles ut.\n";}

	if (sMeld == "")
	{
		document.FORGOT_PASSWORD.CMD.value="GETPASSWORD";
		document.FORGOT_PASSWORD.submit();
	}
	else
	{
		alert(sMeld);
		// button
		document.FORGOT_PASSWORD.Submit2.disabled = false;
	}
}
function viewForgotPassword()
{
	document.getElementById("div_login_box").style.display = "none";
	document.getElementById("div_forgotpassword_box").style.display = "block";
}
/*   END LOGIN  */


/*##########*/
/*   OTHER  */
/*##########*/

/* new on mouse over function */
function over (obj){
	obj.className=obj.className+'_over';
}

/* new on mouse out function */
function out (obj){
	var str=obj.className;
	var pos=str.indexOf("_over")
	obj.className=str.substr(0,pos);
}

// Function that executes function inside input string when enter is pressed.
function doKey(sFunc) {
	if (document.all) {
		whichASC = event.keyCode;
		if(whichASC==13){
			eval(sFunc);
		}       
	}
}

// check search string
function aSearch(){
	if (document.FORM_SEARCH.search.value==''){
		alert('Søkeordet ditt er for kort.');
	}
	else{
		document.FORM_SEARCH.submit();
	}
}

