function popup(url) {
	window.open(url, 'popup', "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=450,height=390,screenX=400,screenY=275");
}

function fading(ele) {
	if(document.getElementById(ele).style.color == 'rgb(255, 255, 255)' || document.getElementById(ele).style.color == '#ffffff') {
		document.getElementById(ele).style.color = '#6498C9';
	} else {
		document.getElementById(ele).style.color = '#FFFFFF';
	}
}

function checkContactForm() {
	if(document.getElementsByName('subject')[0].value == '') {
		alert('Bitte geben Sie einen Betreff an!');
		return false;
	}

	if(document.getElementsByName('message')[0].value == '') {
		alert('Bitte geben Sie eine Nachricht an!');
		return false;
	}
	return true;
}

function validateEmail(email) {
	return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email);
}

function check_form() {
  var rname,constraint,test;
  var errors_empty='', errors_mail='', errors_pwd='';
  var args = check_form.arguments;
  var errMsg = '';
  
  for(var i=1; i<(args.length-1); i+=3) {
	constraint = args [i+1];
	rname = args[i+2];
	val=document.getElementById(args[i]);

	if (val || constraint == 'pwd') {
	  if (constraint == "empty") {
		if ((val=val.value) == "") {
			errors_empty+='- '+rname+' \n';
		}
	  }
	  else if (constraint == "pwd") {
		if(document.getElementById(args[i]+'1').value == '' && document.getElementById(args[i]+'2').value == '') {
			errors_pwd+='\nBitte geben Sie ein Passwort an!\n';
		}
		else if (document.getElementById(args[i]+'1').value != document.getElementById(args[i]+'2').value) {
			errors_pwd+='\nDie Passwörter stimmen nicht überein!\n';
		}
	  }
	}
  }
  
  if (errors_empty != '' || errors_pwd != '') {
	errMsg = 'Bei der Formulareingabe sind Fehler aufgetreten!\n';
	if(errors_empty != '') {
	  errMsg+='\nFolgende Felder müssen noch ausgefüllt werden:\n'+errors_empty;
	}
	if(errors_pwd != '') {
	  errMsg+=errors_pwd;
	}
	alert(errMsg);
	return false;
  } else {
	return true;
  }
}

/**
 * moves a row
 **/
function moveUp(e) {
	var row = e.parentNode.parentNode; // the row to move
	var root = row.parentNode; // the table
	if(root.nodeName != 'TBODY') {
		for(var i=0;i<root.childNodes.length;i+=1) {
			if(root.childNodes[i].nodeName == 'TBODY') {
				root = root.childNodes[i];
			}
		}
	}
	var previous = row.previousSibling; //the previous row
	var clone = row.cloneNode(true); //clone the row to move
	
	if(previous.tagName != 'TR') {
		previous = previous.previousSibling;
	}
	
	if(previous) { // if it's not the first row
		root.insertBefore(clone, previous); // insert the clone
		root.removeChild(row); // remove the cloned row
	}
}

/**
 * moves a row
 **/
function moveDown(e) {
	var row = e.parentNode.parentNode; //the row to move
	var root = row.parentNode; // the table
	var next = row.nextSibling; // the next row
	
	if(next.tagName != 'TR') {
		next = next.nextSibling;
	}
	
	if(next) { // if it's not the last row
		var clone = next.cloneNode(true); // clone the next row
		root.insertBefore(clone, row); // insert the clone
		root.removeChild(next); // delete the cloned row
	}
}

function getHttpObject() {
	try {
		http = new XMLHttpRequest();
	}
	catch(e) {
		try {
			http = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e) {
			try {
				http = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e) {
				http = null;
			}
		}
	}
	return http;
}

function logoutTimer() {
	var http = getHttpObject();
	var ajax_url = "index.php?mod=Ajax&action=checklogin";
	
	http.open("GET", ajax_url, true);
	
	http.onreadystatechange = function() {
		if (http.readyState == 4) {
			if(http.status!=200) {
				alert("Fehler: "+http.status);
			} else {
				if(http.responseText != '') {
					window.open('login.php?popup=1', 'popup', "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=1050,height=700,screenX=400,screenY=275");
				}
			}
		}
	}
	http.send(null);	
}
