/* developed by apt as - 2001 - christopher@apt.no */
window.onresize = refresh;
var menu = false;
var content = "";
var arrStyle = new Array();

function checkAddToList(myForm){
	
	var strEmail = myForm.elements['newsletter'].value;
	
	if(notValidMailFormat(strEmail)){
		alert('Epostadressen er ikke gyldig.');
		return false
	}
	return true;
}


function notValidMailFormat(email){
	// function: validates an email to format: x@x.xx
	// returns : boolean
	
	var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
	var check=/@[\w\-]+\./;
	var checkend=/\.[a-zA-Z]{2,3}$/;

	if(((email.search(exclude) != -1)||(email.search(check)) == -1)||(email.search(checkend) == -1)){
		return true;
	} else {
		return false;
	}
}


function vote(myForm,myId){
	// function : handle vote-box
	var i;
	var val = "";
	var url;
	for(i=0;i<myForm.elements[myForm.elements[0].name].length;i++){
		if(myForm.elements[i].checked){
			val = myForm.elements[i].value;
			break;
		}
	}
	if(val.length >0){
		url = myForm.action + '&res='+myId+'&answer='+val;
		location.href = url;
	}
}
function sendOrder(myForm){
	// function: submits form
	// returns : nothing
	
	myForm.submit();
}

function searchIt(myForm){
	location.href = 'src.php?str='+escape(myForm.elements['searchstr'].value);
}
function setStyle(){
	// function: write browseradapted styletags
	var str = '';
		if(document.all || document.getElementById){
			str = 'input,textarea {border: 1px solid #c3d1d5;}';
			if(navigator.platform.indexOf("Mac")!= -1){
				str += 'li	{margin-left:5px;}';
			}
		}else if(document.layers){
			str  = '.blueheader{text-indent: 0px;}.blackheader{text-indent: 0px;}';
			str += '.darkblueheader{text-indent: 0px;}.brownheader{text-indent: 0px;}';
			str += '.darkheader{text-indent: 0px;}.redheader{text-indent: 0px;}';
			str += '.greenblueheader{text-indent: 0px;}li	{margin-left:0px;}';
		}
		
	document.write('<style>'+str+'</style>');	
}

function swapIt(name,pic){		
	document.images[name].src = '../elements/'+pic;	
}

function stat(txt){
	// function: set windowstatus
	// returns : true	
	var str = '';
	if(txt){str = txt};
	window.status = str;
	return true;
}
function refresh(){
	// function: reloads the window if it's resized
	goBig(document.forms[0],'comment');
	window.location.reload(true);
}
function goBig(myForm,field){
	// function: save value from inputfield to global variable
	parent.comment_text = myForm.elements[field].value;	
}
function fillBig(myForm,field){
	// function: retrieve value from global variable and fill into textfield
	myForm.elements[field].value = parent.comment_text;
	parent.comment_text = '';	
}

function sendComment(myForm,myReturnUrl){
	// function: alter action on the form and check that something is submitted
	// returns : nothing;
	
	if(myForm.elements['comment'].value.length >2){
		myForm.elements['return'].value = myReturnUrl;		
		myForm.submit();
	}else{		
		alert('Fint om du skriver litt mer..');
	}
}
function showMenu(item){
	// function: show menu
	// returns : false if menu isn't loaded
	// calls   : hideMenu()
	
	hideMenu();
	
	// check if menu is loaded	
	if(content){ 
		if(document.getElementById){ // ie 5.0, nn6
		
			document.getElementById('menubg'+item).style.visibility = 'visible';
			// opera-fix
			for(var j=0;j<content[item].length;j++){
				document.getElementById('menu'+item+'_'+j).style.visibility = 'visible';
			}
			document.getElementById('bg').style.visibility = 'visible';
			document.getElementById('bgtop').style.visibility = 'visible';
			
		}else if(document.layers){ // ns 4.x
		
			tmp = eval("document.layers.menubg"+item);
			tmp.visibility = 'show';
			document.layers.bg.visibility = 'show';
			document.layers.bgtop.visibility = 'show';
			
		}else if(document.all){ // ie 4.x
		
			document.all(item).style.visibility = 'visible';
			document.all('bg').style.visibility = 'visible';
			
		}
	}
	return false;
}

function hideMenu(){
	// function: hide menu
	// returns : nothing
	// calls   : hideBg()
	
	var i;
	if(menu){
		for(i=0;i<content.length;i++){
			if(document.getElementById){ // ie 5.x.nn6
				document.getElementById('menubg'+i).style.visibility = 'hidden';
				// opera-fix
				for(var j=0;j<content[i].length;j++){
					document.getElementById('menu'+i+'_'+j).style.visibility = 'hidden';
				}
			
			}else if(document.layers){ // nn 4.x
				tmp = eval('document.layers.menubg'+i);
				tmp.visibility = 'hide';
			
			}else if (document.all){ // ie 4.x
				document.all('menubg'+i).style.visibility = 'hidden';
			}
		}
		hideBg();
	}
}

function hideBg(){
	// function: hide the closing backgroundlayers
	// returns : nothing
	
	if(document.getElementById){ // ie 5.x,nn6
		document.getElementById('bg').style.visibility = 'hidden';
		document.getElementById('bgtop').style.visibility = 'hidden';
		
	}else if(document.layers){ // nn 4.x
		document.layers.bg.visibility = 'hide';
		document.layers.bgtop.visibility = 'hide';
		
	}else if(document.all){ // ie 4.x
		document.all('bg').style.visibility = 'hidden';
		document.all('bgtop').style.visibility = 'hidden';
	}
}

function hiLite(obj,color){
	// function: change background-color in a layer
	// returns : nothing
	
	if((document.getElementById)||(document.all)){
		obj.style.backgroundColor = color;
	} else if(document.layers){
		obj.document.bgColor = color;
	}
}

