var submenuTimeout;

function showSubmenuSlider(top_id)
{
	if(slider = window.document.getElementById("submenu_slider_"+top_id))
	{
		window.clearTimeout(submenuTimeout);

		/* Alle anderen zumachen: */
		navidiv = window.document.getElementById("navi_div");

		submenudivtags = navidiv.getElementsByTagName("div");

		for(i=0; i<submenudivtags.length; i++)
		{
			if(submenudivtags[i].className == "submenu_slider_div")
			{
				submenudivtags[i].style.visibility = "hidden";
				submenudivtags[i].style.display = "none";
			}
		}

		slider.style.visibility = "visible";
		slider.style.display = "block";
	}
}

function hideSubmenuSlider(top_id)
{
	if(slider = window.document.getElementById("submenu_slider_"+top_id))
	{
		submenuTimeout = window.setTimeout("hideSubmenuSliderTimeout("+top_id+")", 200);
	}
}


function hideSubmenuSliderTimeout(top_id)
{
	window.clearTimeout(submenuTimeout);

	slider = window.document.getElementById("submenu_slider_"+top_id);

	slider.style.visibility = "hidden";
	slider.style.display = "none";
}

function checkRegistrationData() {
	//var registration_object = document.getElementById('registrationdata');
	var username = document.getElementsByName('rusername')[0];
	var firstname = document.getElementsByName('firstname')[0];
	var lastname = document.getElementsByName('lastname')[0];
	var usermail = document.getElementsByName('usermail')[0];
	var userpass = document.getElementsByName('userpass')[0];
	var userpass_confirm = document.getElementsByName('userpass_confirm')[0];
	
	var errorcode = 0;
	errorcode += checkObjectValues(username);
	errorcode += checkObjectValues(firstname);
	errorcode += checkObjectValues(lastname);
	errorcode += checkObjectValues(usermail);
	errorcode += checkObjectValues(userpass);
	errorcode += checkObjectValues(userpass_confirm);
	
	var errormessage = "";
	if ( errorcode > 0 ) {
		errormessage = "Die eingefärbeten Felder müssen ausgefüllt sein";
	}
	
	errorcode = 0;
	errorcode += checkPasswordLength(userpass);
	if ( errorcode > 0 ) {
		errormessage += "\nDas Passwort muss mindestes 6 Zeichen lang sein";
	}
	
	errorcode = 0;
	errorcode += checkPasswordEquality(userpass,userpass_confirm);
	if ( errorcode > 0 ) {
		errormessage += "\nDie Passwörter sind nicht gleich";
	}
	
	errorcode = 0;
	errorcode += checkMailValidity(usermail);
	if ( errorcode > 0 ) {
		errormessage += "\nDie Mailaddesse ist ungültig";
	}
	
	if ( errormessage.length > 0 ) {
		alert(errormessage);
	}
	else {
		document.getElementById('registrationdata').submit();
	}
	
}

function checkObjectValues(o) {
	if ( o.value.length == 0 ) {
		o.style.backgroundColor = '#999999';
		return 1;
	}
	else {
		o.style.backgroundColor = '#FFFFFF';
		return 0;
	}
}

function checkPasswordLength(o) {
	if ( o.value.length < 6 ) {
		o.style.backgroundColor = '#999999';
		return 1;
	}
	else {
		return 0;
	}
}

function checkPasswordEquality(o,p) {
	if ( o.value != p.value ) {
		p.style.backgroundColor = '#999999';
		return 1;
	}
	else {
		return 0;
	}
}

function checkMailValidity(o) {
	var mailadress = o.value;
	if ( mailadress.lastIndexOf('.') == -1 || mailadress.lastIndexOf('@') == -1 || mailadress.lastIndexOf('.') < mailadress.lastIndexOf('@') ) {
		o.style.backgroundColor = '#999999';
		return 1;
	}
	else {
		return 0;
	}
}


function set_cookie(my_cookie,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else expires = ""
	document.cookie = my_cookie+"="+value+expires+"; path=/";
}

function read_cookie(my_cookie) {
	var my_cookie_eq = my_cookie + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i< ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') {
			c = c.substring(1,c.length);
		}
		if (c.indexOf(my_cookie_eq) == 0) {
			return c.substring(my_cookie_eq.length,c.length);
		}
	}
	return null
}

var temp_url = null;
var temp_request = null;
var temp_search_val = null;

function accepted_license(license, url) {
	if (read_cookie('acceptLicense') == null) {
		temp_url = url;
		temp_request = null;
		temp_search_val = null;
		
		showPopWin(license, 800, 600, null);
	}
	else {
		window.location.href = url;
	}
}

function search_accepted_license(license, request, search_val) {
	temp_request = request;
	temp_search_val = search_val;
	temp_url = null;
	showPopWin(license, 800, 600, null);
}

function accept_license() {
	set_cookie('acceptLicense', 1, 30);
	hide_eclass_results = 0;
	window.parent.hidePopWin();
	
	if ((temp_url != null)&&(temp_request == null)&&(temp_search_val == null)) {
		window.parent.location.href = '.' + temp_url;
	} else if ((temp_request != null)&&(temp_search_val != null)&&(temp_url == null)) {
		searchResult(temp_request,temp_search_val);
	}
	temp_url = null;
	temp_request = null;
	temp_search_val = null;
}

