errors = new Array();

function addError(error) {
	errors.push(error);
}

function showErrors() {
	errorString = "";
	for(message in errors) {
		errorString += errors[message]+"\n";
	}
	if(errorString != "") {
		alert(errorString);
	}
}

function popUp(href, type) {
	switch(type) {
		case "help":
		case "statusreport":
		case "test_report":
			width = 600;
			height = 540; break;
		case "gmaps":
			width = 710;
			height = 520; break;
		case "contactdata":
			width = 720;
			height = 480; break;
		case "emailreminder":
		case "password":
			width = 320;
			height = 200; break;
		case "export":
		    width = 570;
			height = 600; break;
		case "description":
		case "comments":
			width = 570;
			height = 520; break;
		case "statistic":
			width = 600;
			height = 560; break;
		case "pdf_replace":
			width = 340;
			height = 240; break;
		case "gallery":
			width=880;
			height=780;
	}

	window.open(href, '','width='+width+',height='+height+',left='+300+',top='+100+',screenX='+200+',screenY='+200+', resizable=0, scrollbars=1');

}

function paramRedirect(url, getParam, id) {
	if(id != 0 && id != '') {
		getParam = (typeof getParam != "object") ? new Array(getParam) : getParam;
		id = (typeof id != "object") ? new Array(id) : id;;
		var i=0;
		var ext = "";
		for(var param in getParam) {
			ext += "&"+getParam[param]+"="+id[i];
			i++;
		}
		self.location.href = url+ext;
	} else {
		self.location.href = url;
	}
}

function submitChangeForm(){
	document.getElementById("changeForm").submit();
}

function submitForm(){
	document.getElementById("filterform").submit();
}

function skipValidation() {
	var skip = document.createElement("input");
	skip.name = "skip";
	skip.type = "hidden";
	skip.value = 1;
	document.getElementById("changeForm").appendChild(skip);
	document.getElementById("changeForm").submit();
}

function skipAllFunctions() {
	var skipAll = document.createElement("input");
	skipAll.name = "skipAll";
	skipAll.type = "hidden";
	skipAll.value = 1;
	document.getElementById("changeForm").appendChild(skipAll);
	skipValidation();
}

function selectRights(selectedGroup) {
	
	skipValidation();
}

function applyRightChange(myId, selectMeId) {
	var select = document.getElementById("user_group");
	var selectedGroup = select.value;
	
	if(!selectedGroup.match(/\*$/)) {
		var opt = document.createElement("option");
		if(selectedGroup.length == 0) {
			opt.text = "Gruppe* ";
		} else {
			opt.text = selectedGroup+"* ";	
		}
		opt.selected = true;
		select.appendChild(opt);
	}

	var me = document.getElementById(myId);
	var selectMe = document.getElementById(selectMeId);
	
	if(me.checked) { 
		selectMe.checked = true; 
	}
}

function deselect(id) {
	document.getElementById(id).checked = false;
}

function select(id) {
	document.getElementById(id).checked = true;
}

function checkForNewGroup() {
	var groupInput = document.getElementById("user_group");
	var groupName = groupInput.value;
	
	
	if(groupName.match(/\*$/)) {
		var newName = prompt("Bitte wählen Sie einen Namen für die neue Gruppe",
					groupName.substr(0, groupName.length-1)+"_neu");		

		if( newName ) {
			var groupOutput = document.createElement("input");
			groupOutput.type = "hidden";
			groupOutput.name = "new_group";
			groupOutput.value = newName;
			document.getElementById("changeForm").appendChild(groupOutput);
		} else {
			
			var opt = document.createElement("option");
			opt.value = groupName;
			opt.text = groupName;
			opt.selected = true;			
			groupInput.appendChild(opt);
			return false;
		}
	}
}

function confirmDeletion(what) {
	if(!confirm("Wollen Sie "+what+" wirklich löschen?")) {
		return false;
	}
	return true;
}

function toggleSpotLight() {
	var spot = document.getElementById("spotlight");
	
	spot.style.display = (spot.style.display!="block") ? "block" : "none";
	
}

function applySpotlight(params, value) {
	if(value != "") {
		self.location.href = params+"&spotlight[use]=1&spotlight[value]="+value;
	}
}
