﻿/* Toogle text in search field functions
---------------------------------------------------------------- */

function focusField(f,txt){

	// Declare variable
	var field = document.getElementById(f.id);
	
	// Clean field, markup if text is not the same as original
	if(field.value==txt && field.value=='Søg'){
		field.value = '';
	}else{
		field.select();
	}

}

function blurField(f,txt){

	// Declare variable
	var field = document.getElementById(f.id);
	
	// Restore field if not text is original
	if(field.value==''){
		field.value = txt;
	}

}

/* Link function
---------------------------------------------------------------- */

function goToUrl(popup,url){

	// If popup is true, then open in popup, else open normal
	if(url){
		if(popup){
			window.open(url);
		}else{
			location.href = url;
		}
	}

}

/* Drop down
---------------------------------------------------------------- */

function showDrop(f){
	document.getElementById(f.id + '_cont').style.display = 'block';
}

function hideDrop(f,sec){
	if(sec=='dates'){
		setTimeout("document.getElementById('period_cont').style.display = 'none'", 200);
	}else if(sec=='cats'){
		setTimeout("document.getElementById('category_cont').style.display = 'none'", 200);
	}
}

function setPeriod(f,from,to,per){
	document.getElementById('period').value = f;
	document.getElementById('from').value = from;
	document.getElementById('to').value = to;
	document.getElementById('PeriodVal').value = per;
}

function setCategory(f){
	if(f){
		location.href = f;
	}
}

function valSubscribe(f){
	var execute = true;
	if(f.name.value=='' || spaceFilter.test(f.name.value)){
		execute = false;
	}
	if(f.email.value=='' || !checkEmail(f.email.value)){
		execute = false;
	}
	if(!execute){valSubError('missing');}
	return execute;
}
function valSubError(f){
	// Declare
	var statok = document.getElementById('status_ok');
	var statunok = document.getElementById('status_un_ok');
	var staterr = document.getElementById('status_error');
	var statmis = document.getElementById('status_missing');
	// Reset
	statok.style.display = 'none';
	statunok.style.display = 'none';
	staterr.style.display = 'none';
	statmis.style.display = 'none';
	// Which
	if(f=='ok'){statok.style.display = 'block';}
	if(f=='unsub_ok'){statunok.style.display = 'block';}
	if(f=='error'){staterr.style.display = 'block';}
	if(f=='missing'){statmis.style.display = 'block';}
}
