/**
 * 
 */
var mail1 = "i nz f o-anz f_r za ge@b e st%i_m zme z.zd e";
var mail2 = "su %ppz ort-a_nz f%r  azg e@b e sztz i_m me . d zez";
var mail3 = "a% gaz% _ta_% swzrzy%m_ @_ yz% ah_o% zzo.zd %e";
var mail4 = " _t%ho %mz a_zs@ zs_% o%% _lz%ti _%.z%d _e %";


/**
 * Nochmal nachfragen
 */
function ban(url){
	confirmBefore(url, "Wollen Sie dieses Element wirklich entfernen?")
}
function archive(url){
	confirmBefore(url, "Wollen Sie dieses Element wirklich archivieren?")
}
/**
 * Nochmal nachfragen
 */
function confirmBefore(url,question){
	var confirmed = window.confirm(question);
	if (confirmed){
		location.href = url;
	}
}

function loadMe(){
	if (document.getElementById("mail1") != null){
		document.getElementById("mail1").onmouseover=resolveMail;
	}
	if (document.getElementById("mail2") != null){
		document.getElementById("mail2").onmouseover=resolveMail;
	}
	if (document.getElementById("mail3") != null){
		document.getElementById("mail3").onmouseover=resolveMail;
	}
	if (document.getElementById("mail4") != null){
		document.getElementById("mail4").onmouseover=resolveMail;
	}

	if (document.getElementById("subAreas") != null){
		document.getElementById("subAreas").onclick=submitSubAreas;
	}
	if (document.getElementById('loginName') != null){
		document.getElementById('loginName').focus();
	}
	if (document.getElementById("onlyNotAnswered") != null){
		document.getElementById("onlyNotAnswered").onclick=submitNotAnswered;
	}
	if (document.getElementById("alsoArchived") != null){
		document.getElementById("alsoArchived").onclick=submitAlsoArchived;
	}
}

function submitNotAnswered() {
	if (document.getElementById('onlyNotAnsweredForm') != null){
		document.getElementById('onlyNotAnsweredForm').submit();
	}
}
function submitAlsoArchived() {
	if (document.getElementById('alsoArchivedForm') != null){
		document.getElementById('alsoArchivedForm').submit();
	}
}

function submitSubAreas(){
	if (document.getElementById('includeSubForm') != null){
		document.getElementById('includeSubForm').submit();
	}
}



function resolveMail(){
	elementId = this.id;
	mail = "";
	if (elementId == "mail1")
		mail = cleanMail(mail1);
	if (elementId == "mail2")
		mail = cleanMail(mail2);
	if (elementId == "mail3")
		mail = cleanMail(mail3);
	if (elementId == "mail4")
		mail = cleanMail(mail4);
	
	
	var element = document.getElementById(elementId) 
	while (element.childNodes.length > 0){
		element.removeChild(element.childNodes[0]);
	}
	
	var newAnchor = document.createElement("a");
	var newText = document.createTextNode(mail);
	newAnchor.appendChild(newText);
	newAnchor.setAttribute("href", "mailto:"+mail);
	element.appendChild(newAnchor);
	element.onmouseover=null;
	
}

function cleanMail(mailString){
	var orig = mailString.replace(/[\ %_]/,"");
	while (orig != mailString){
		orig = mailString;
		mailString = mailString.replace(/[z\ -%_]/,"");
	}
	return mailString;
}
