
window.onresize = function()
{
	sizeBackground();
}
/*
window.onResizeEnd = function()
{
	sizeBackground();
}
*/

function sizeBackground()
{
	//newHeight = document.body.offsetHeight;
	newHeight = getWinHeight();
	pageDim = getPageSizeWithScroll();
	if( pageDim[1] > newHeight )
		{newHeight = pageDim[1];}
	//alert(newHeight);
	document.getElementById('backgroundRepeated').style.height = newHeight + "px";
}

function getPageSizeWithScroll()
{
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
	return arrayPageSizeWithScroll;
}
			
function getWinHeight() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return myHeight;
  //window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );
}

function loadOverlegg(what)
{
	new Effect.Appear('overleggWrapper', {duration:0.4,queue: 'end', from:0.0, to:1.0});
	xajax_overlegg(what);

}
function fadeoutOverlegg()
{
	new Effect.Fade('overleggWrapper', {duration:0.4,queue: 'end', from:1.0, to:0.0});		
}

function loadingLogginn()
{
	//document.getElementById('headLogin').style.backgroundColor = "#53ac6e";
}

function loadingSok()
{

}

function search( sok, id )
{
	var sok = sok.replace(/(<([^>]+)>)/ig,"");
	if( !sok.match('eller artikler'));
	if( sok.length > 2 )
	{
		//alert( sok );
		document.getElementById(id).style.display='';
		xajax_search(sok, id);
	}
}

function selectLagSok(sokId, hideId, displayId )
{
	//document.getElementById(sokId).select();
	document.getElementById(sokId).value = "";
	document.getElementById(hideId).style.display = "none";
	document.getElementById(displayId).style.display = "";
	
}

function lukkLagSok(sokId, hideId, displayId, tekst )
{
	document.getElementById(sokId).value ="Søk: Finn ditt " + tekst;
	document.getElementById(hideId).style.display = "";
	document.getElementById(displayId).style.display = "none";
}


function lagSok(sokId)
{
	// Find the search box in the DOM
	var theElement = document.getElementById(sokId);

	// Create a function for when the user presses a key
	theElement.onkeyup = function(){ search_delay(this); };

}

function search_delay(element)
{
	// Create a function to get the search results
	var func = function() {
	   var sok = element.value.replace(/(<([^>]+)>)/ig,"");
		if( sok.length > 1 )
		{
			if( element.id == "skoleSok" )
			{				
				xajax_sokLag("sok", 1, "skoleSokListe", sok);
			}
			else if( element.id == "studentSok" )
			{
				xajax_sokLag("sok", 2, "studentSokListe", sok);			
			}
		}
	};

	// Check to see if there is already a timeout and if so...
	// ...cancel it and create a new one
	if ( element.zid ) {
		clearTimeout(element.zid);
	}
	element.zid = setTimeout(func,500);
}

function validateRegFrm()
{
	var feil			= "";
	var epost 		= validateInput("epost", 3, document.getElementById('epost').value );
	var passord 	= validateInput("empty", 3, document.getElementById('passord').value );
	
	if( epost && passord )
	{
		document.reg_logginn.submit();
		return true;
	}
	else
	{ 
		if( !epost )
		{
			feil += "Epost-adressen er ikke gyldig\n\n";
		}
		if( !passord )
		{
			feil += "Du har glemt passord\n\n";
		}
		alert( feil );
		return false;
	}	
}

function validateInput(type, length, verdi)
{
	if( type == "text" )
	{
		if( verdi.length > length )
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	else if( type == "number" )
	{
		var numericExpression = /^[0-9]+$/;
		if( verdi.match(numericExpression) && verdi.length > length )
			return true;
		else
			return false;
	}
	else if( type == "empty" )
	{
		
		if( verdi != "")
			return true;
		else
			return false;
	}
	else if( type == "radio" )
	{
		myOption = -1;
		for (i=verdi.length-1; i > -1; i--) 
		{

			if (verdi[i].checked) 
			{
				myOption = i; 
				i = -1;
			}
		}

		if (myOption == -1)
			return false;
		else
			return true;
	}
	else if( type == "epost" )
	{
		if( echeck(verdi) )
			return true;
		else
			return false;
	}
}

function echeck(str)
{

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){

		return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		 return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		 return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		 return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		 return false
	 }

	 if (str.indexOf(" ")!=-1){
		 return false
	 }
	 
	 if( checkDomain(str))
		return true;
	else
		return false;
}

function checkDomain(nname)
{
	var arr = new Array(
	'.com','.net','.org','.biz','.coop','.info','.museum','.name',
	'.pro','.edu','.gov','.int','.mil','.ac','.ad','.ae','.af','.ag',
	'.ai','.al','.am','.an','.ao','.aq','.ar','.as','.at','.au','.aw',
	'.az','.ba','.bb','.bd','.be','.bf','.bg','.bh','.bi','.bj','.bm',
	'.bn','.bo','.br','.bs','.bt','.bv','.bw','.by','.bz','.ca','.cc',
	'.cd','.cf','.cg','.ch','.ci','.ck','.cl','.cm','.cn','.co','.cr',
	'.cu','.cv','.cx','.cy','.cz','.de','.dj','.dk','.dm','.do','.dz',
	'.ec','.ee','.eg','.eh','.er','.es','.et','.fi','.fj','.fk','.fm',
	'.fo','.fr','.ga','.gd','.ge','.gf','.gg','.gh','.gi','.gl','.gm',
	'.gn','.gp','.gq','.gr','.gs','.gt','.gu','.gv','.gy','.hk','.hm',
	'.hn','.hr','.ht','.hu','.id','.ie','.il','.im','.in','.io','.iq',
	'.ir','.is','.it','.je','.jm','.jo','.jp','.ke','.kg','.kh','.ki',
	'.km','.kn','.kp','.kr','.kw','.ky','.kz','.la','.lb','.lc','.li',
	'.lk','.lr','.ls','.lt','.lu','.lv','.ly','.ma','.mc','.md','.mg',
	'.mh','.mk','.ml','.mm','.mn','.mo','.mp','.mq','.mr','.ms','.mt',
	'.mu','.mv','.mw','.mx','.my','.mz','.na','.nc','.ne','.nf','.ng',
	'.ni','.nl','.no','.np','.nr','.nu','.nz','.om','.pa','.pe','.pf',
	'.pg','.ph','.pk','.pl','.pm','.pn','.pr','.ps','.pt','.pw','.py',
	'.qa','.re','.ro','.rw','.ru','.sa','.sb','.sc','.sd','.se','.sg',
	'.sh','.si','.sj','.sk','.sl','.sm','.sn','.so','.sr','.st','.sv',
	'.sy','.sz','.tc','.td','.tf','.tg','.th','.tj','.tk','.tm','.tn',
	'.to','.tp','.tr','.tt','.tv','.tw','.tz','.ua','.ug','.uk','.um',
	'.us','.uy','.uz','.va','.vc','.ve','.vg','.vi','.vn','.vu','.ws',
	'.wf','.ye','.yt','.yu','.za','.zm','.zw');
	
	var mai = nname;
	var val = true;
	
	var dot = mai.lastIndexOf(".");
	var dname = mai.substring(0,dot);
	var ext = mai.substring(dot,mai.length);
		
	if(dot>2 && dot<57)
	{
		for(var i=0; i<arr.length; i++)
		{
		  if(ext == arr[i])
		  {
		 	val = true;
			break;
		  }	
		  else
		  {
		 	val = false;
		  }
		}
		if(val == false)
		{
		  	// alert("Your domain extension "+ext+" is not correct");
			 return false;
		}
	}
	else
	{
	 //alert("Your Domain name is too short/long");
	 return false;
	}	
	
	return true;
}

function toggleOrdre(ordreId)
{
	var element = document.getElementById(ordreId);
	if( element.style.display == "none" )
		element.style.display = "";
	else
		element.style.display = "none";

}


