var locked;
var boxHeight;

function doNewPassword(id,type) {
	statusX = 0;
	if (!EMail(document.brennraum.forgotEmail.value)) {
		document.brennraum.forgotEmail.style.backgroundColor = "#999999";
		document.brennraum.forgotEmail.value = strMissing;
		statusX = 1;
	}	
	//alert(statusX);
	if (!statusX) {
		boxHeight = $('box').getHeight();
		var url = "index.php";
		var pars = "eID=forgotpassword&action=getPassword&email="+document.brennraum.forgotEmail.value+"&id="+id+"&L="+type;
		$('restorebox').innerHTML = $('box').innerHTML;		
		var myAjax = new Ajax.Request(url, {method: 'get', parameters: pars, onComplete: updateBox});
	}
}

function updateBox(orgRequest) {
	var xmldoc = orgRequest.responseXML;
	xmldoc.getElementsByTagName("data")[0].normalize();
	var result = xmldoc.getElementsByTagName("data")[0].firstChild.data;
	result.evalScripts();
	$('box').update(result);
	$('box').setStyle ({ height: boxHeight+'px' });

	//$('ajaxloader').hide();
	//$('box').show();
}

function showLanguages() {
	if ($("languages"))
		$("languages").appear();
	return true;
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}		


function formFocus(field,active,word) {
	if (active && field.value == word) field.value='';
	else {
		if (field.value == "") field.value=word;
	}
	
}

function newCaptcha() {
	var myTime = new Date();
	$("captcha-img").src = "fileadmin/inc/class.captcha.php?" + myTime.getMilliseconds();
}

function addBookmark(title,url) {
     if (window.sidebar) { // firefox
     window.sidebar.addPanel(title, url, "");
     } else if (document.all) { // IE
     window.external.AddFavorite(url, title);
     } else if (window.opera && window.print) { // opera
     var elem = document.createElement("a");
     elem.setAttribute("href",url);
     elem.setAttribute("title",title);
     elem.setAttribute("rel","sidebar");
     elem.click();
     }
}

function doSearch(stdValue) {
	if ($("searchStr").value && $("searchStr").value != stdValue) {
		document.searchForm.submit();
	}
}

function goto(page) {
	
	if (window.document.KTMEZINE4) {
		if (typeof window.document.KTMEZINE4.SetPage == 'function')  {
			window.document.KTMEZINE4.SetPage(page);
		}
	}

}

function writeCookie(n,w)
{
	e = 60*60*20;
	var a = new Date();
	a = new Date(a.getTime() +e);
	document.cookie = n+'='+w+';';
}

function readCookie(n)
{
	a = document.cookie;
	res = '';
	while(a != '')
	{
		cookiename = a.substring(0,a.search('='));
		cookiewert = a.substring(a.search('=')+1,a.search(';'));
		if (cookiewert == '') {
			cookiewert = a.substring(a.search('=')+1,a.length);
		}
		
		if(n == cookiename) {
			res = cookiewert;
		}
		
		i = a.search(';')+1;
		if (i == 0) {
			i = a.length
		}
		a = a.substring(i,a.length);
	} 
	return(res);
}

function doLogin() {
	var status;
	document.brennraum.logintype.value = 'login';
	if (document.brennraum.register) document.brennraum.register.value = '0';
	document.brennraum.pass.value = MD5(document.brennraum.loginpass.value);
	
	status=0;
	
	if ((document.brennraum.user.value.length=="0") || (document.brennraum.user.value==strMissing)) {
	document.brennraum.user.style.backgroundColor = "#999999";
	document.brennraum.user.value = strMissing;
	status = 1;
	}
	
	if ((document.brennraum.loginpass.value.length=="0") || (document.brennraum.loginpass.value==strMissing)) {
	document.brennraum.loginpass.style.backgroundColor = "#999999";
	status = 1;
	}
	
	document.brennraum.action = document.brennraum.rid.value;
	if (!status) document.brennraum.submit();
		
}

function doRegister() {
	var status;
	document.brennraum.register.value = '1';
	status = 0;
	
	if ((document.brennraum.firstname.value.length=="0") || (document.brennraum.firstname.value==strMissing)) {
	document.brennraum.firstname.style.backgroundColor = "#999999";
	document.brennraum.firstname.value = strMissing;
	status = 1;
	}
	if ((document.brennraum.lastname.value.length=="0") || (document.brennraum.lastname.value==strMissing)) {
	document.brennraum.lastname.style.backgroundColor = "#999999";
	document.brennraum.lastname.value = strMissing;
	status = 1;
	}
	if ((document.brennraum.email.value.length=="0") || (document.brennraum.email.value==strMissing)) {
	document.brennraum.email.style.backgroundColor = "#999999";
	document.brennraum.email.value = strMissing;
	status = 1;
	}
	if(document.brennraum.edituser.value==0){
		document.brennraum.logintype.value = '';
		if ((document.brennraum.password.value.length=="0") || (document.brennraum.password.value==strMissing)) {
		document.brennraum.password.style.backgroundColor = "#999999";
		status = 1;
		}
		if ((document.brennraum.password2.value.length=="0") || (document.brennraum.password2.value==strMissing)) {
		document.brennraum.password2.style.backgroundColor = "#999999";
		status = 1;
		}
	}
	if ((document.brennraum.street.value.length=="0") || (document.brennraum.street.value==strMissing)) {
	document.brennraum.street.style.backgroundColor = "#999999";
	document.brennraum.street.value = strMissing;
	status = 1;
	}
	if ((document.brennraum.no.value.length=="0") || (document.brennraum.no.value==strMissing)) {
	document.brennraum.no.style.backgroundColor = "#999999";
	document.brennraum.no.value = strMissing;
	status = 1;
	}
	if ((document.brennraum.zip.value.length=="0") || (document.brennraum.zip.value==strMissing)) {
	document.brennraum.zip.style.backgroundColor = "#999999";
	document.brennraum.zip.value = strMissing;
	status = 1;
	}
	if ((document.brennraum.city.value.length=="0") || (document.brennraum.city.value==strMissing)) {
	document.brennraum.city.style.backgroundColor = "#999999";
	document.brennraum.city.value = strMissing;
	status = 1;
	}

	if (document.brennraum.sex.selectedIndex==0 || document.brennraum.sex.options[document.brennraum.sex.selectedIndex].value==-1) {
	document.brennraum.sex.style.backgroundColor = "#999999";
	status = 1;
	}

	if (document.brennraum.country.selectedIndex==0 || document.brennraum.country.options[document.brennraum.country.selectedIndex].value==-1) {
	document.brennraum.country.style.backgroundColor = "#999999";
	status = 1;
	}
	
	if (!EMail(document.brennraum.email.value)) {
		document.brennraum.email.style.backgroundColor = "#999999";
		document.brennraum.email.value = strMissing;
		status = 1;
	}	
	
	if (!status) document.brennraum.submit();
		
}

	
function setFirst(strField) {
	document.brennraum[strField].select()
	document.brennraum[strField].style.backgroundColor = "#FFFFFF";
}

function setMenue(strField) {
	document.brennraum[strField].style.backgroundColor = "#FFFFFF";
}
						
function EMail(s) {
  var a = false;
  var res = false;
  if(typeof(RegExp) == 'function')
	{
	var b = new RegExp('abc');
	if(b.test('abc') == true){a = true;}
	}

  if(a == true)
	{
	reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+
					 '(\\@)([a-zA-Z0-9\\-\\.]+)'+
					 '(\\.)([a-zA-Z]{2,4})$');
	res = (reg.test(s));
	}
  else
	{
	res = (s.search('@') >= 1 &&
		   s.lastIndexOf('.') > s.search('@') &&
		   s.lastIndexOf('.') >= s.length-5)
	}
  return(res);
}


function loginbox() {
	if($("loginboxonly").style.display == 'none'){
		$("loginboxonly").style.display = '';
		$("loglink2").style.display = '';
		$("loglink1").style.display = 'none';
	}else{
		$("loginboxonly").style.display = 'none';
		$("loglink2").style.display = 'none';
		$("loglink1").style.display = '';
	}
}
function newpwd(){
	$('back4good').style.display = 'none';
	$('back4bad').style.display = 'none';
	$("solologin").style.display = 'none';
	$("box").style.display = '';
}
function nonewpwd(){
	$("solologin").style.display = '';
	$("box").style.display = 'none';
}
function closeactive(){
	$("activebox").style.display = 'none';
}
function restorepwd(){
	$('box').innerHTML = $('restorebox').innerHTML;
	$('restorebox').innerHTML = '';
	$('back4good').style.display = 'none';
	$('back4bad').style.display = 'none';
}