function stop_error()
{
	return true;
}
window.onerror = stop_error;

var ajax_c = 1;
function ajax_special(count)
{
	if(count != 1)
	{
		if(ajax_c != count)
		{
			ajax_c = ajax_c+1;
		}
		else
		{
			ajax_c = 1;
		}
		zget('/php/special_ajax.php?id='+ajax_c,'sp');
		aktiv = window.setTimeout("ajax_special("+count+")", 7000);
	}
}

function nurzahlen(el)
{
  var val = el.value.replace(/[^\.^,\d]/g, '');
  el.value = val;
}

function ajax_stop(count)
{
	 window.clearTimeout(aktiv);
	 aktiv = window.setTimeout("ajax_special("+count+")", 7000);
	 return false;
}

function zaehle(id, ziel)
{ 
	var count = 140-document.getElementById(id).value.length;
	if(count < 0) count = 0;
	document.getElementById(ziel).innerHTML = 'Noch '+count+' Zeichen';
}

function check_email_1()
{
	email = document.getElementById("form_email");
	var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	if(email.value == "")
	{
		document.getElementById('form_email_image').innerHTML = '<img src="/design/img/red.png" alt="fehler" />';
	}
	else if (!filter.test(email.value)) 
	{
		document.getElementById('form_email_image').innerHTML = '<img src="/design/img/red.png" alt="fehler" />';
	}
	else
	{
		z2(email.value);
		if(check_status == "n")
		{
			document.getElementById('form_email_image').innerHTML = '<img src="/design/img/red.png" alt="fehler" />';
		}
		else if(check_status == "j")
		{
			document.getElementById('form_email_image').innerHTML = '<img src="/design/img/green.png" alt="korrekt" />';
		}
	}
	window.setTimeout("check_email_1()", 1000);
	return false;
}

function check_pw_1()
{
	pw = document.getElementById("form_pw").value;
	if(pw == "")
	{
		document.getElementById('form_pw_image').innerHTML = '<img src="/design/img/red.png" alt="fehler" />';
	}
	else if(pw.length < 4 && pw.length != 0)
	{
		document.getElementById('form_pw_image').innerHTML = '<img src="/design/img/red.png" alt="fehler" />';
	}
	else
	{
		document.getElementById('form_pw_image').innerHTML = '<img src="/design/img/green.png" alt="korrekt" />';
	}
	return false;
}

function check_pw2_1()
{
	pw = document.getElementById("form_pw2").value;
	if(pw == "")
	{
		document.getElementById('form_pw2_image').innerHTML = '<img src="/design/img/red.png" alt="fehler" />';
	}
	else if(pw.length < 4 && pw.length != 0)
	{
		document.getElementById('form_pw2_image').innerHTML = '<img src="/design/img/red.png" alt="fehler" />';
	}
	else if(pw != document.getElementById("form_pw").value)
	{
		document.getElementById('form_pw2_image').innerHTML = '<img src="/design/img/red.png" alt="fehler" />';
	}
	else if(pw == document.getElementById("form_pw").value)
	{
		document.getElementById('form_pw2_image').innerHTML = '<img src="/design/img/green.png" alt="korrekt" />';
	}
	
	return false;
}

function z(text) 
{
  var xmlHttp = null;
  var random = Math.random();
  // Mozilla, Opera, Safari sowie Internet Explorer 7
  if (typeof XMLHttpRequest != 'undefined') {
      xmlHttp = new XMLHttpRequest();
  }
  if (!xmlHttp) {
      // Internet Explorer 6 und älter
      try {
          xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
      } catch(e) {
          try {
              xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
          } catch(e) {
              xmlHttp  = null;
          }
      }
  }
  if (xmlHttp) {
      xmlHttp.open('GET', '/php/check_nick.php?check='+text+'&r='+random, true);
      xmlHttp.onreadystatechange = function () {
          if (xmlHttp.readyState == 4) {
              check_status =  (xmlHttp.responseText);
          }
      };
      xmlHttp.send(null);
  }
}

function z2(text) 
{
  var xmlHttp = null;
  var random = Math.random();
  // Mozilla, Opera, Safari sowie Internet Explorer 7
  if (typeof XMLHttpRequest != 'undefined') {
      xmlHttp = new XMLHttpRequest();
  }
  if (!xmlHttp) {
      // Internet Explorer 6 und älter
      try {
          xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
      } catch(e) {
          try {
              xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
          } catch(e) {
              xmlHttp  = null;
          }
      }
  }
  if (xmlHttp) {
      xmlHttp.open('GET', '/php/check_email.php?check='+text+'&r='+random, true);
      xmlHttp.onreadystatechange = function () {
          if (xmlHttp.readyState == 4) {
              check_status =  (xmlHttp.responseText);
          }
      };
      xmlHttp.send(null);
  }
}

function check_nick()
{
	text = document.getElementById("form_login").value;
	
	var str = text;
	var okay = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,ä,ü,ö,ß,0,1,2,3,4,5,6,7,8,9,0,.,-,_".split(","); 
	for(var i=0;i<okay.length;i++) while(str.toLowerCase().indexOf(okay[i])!=-1) str=str.toLowerCase().replace(okay[i],"") 
	if(str!='')
	{
		document.getElementById('form_nick').innerHTML = '<font color="red">Nickname enthält Sonder- oder Leerzeichen</font>';
		document.getElementById('form_nick_image').innerHTML = '<img src="/design/img/red.png" alt="fehler" />';
	}
	else if(text == "")
	{
		document.getElementById('form_nick').innerHTML = 'Beispiel: Max-Mustermann';
		document.getElementById('form_nick_image').innerHTML = '<img src="/design/img/red.png" alt="fehler" />';
	}
	else if(text.length < 4 && text.length != 0)
	{
		document.getElementById('form_nick').innerHTML = 'Nickname zu kurz';
		document.getElementById('form_nick_image').innerHTML = '<img src="/design/img/red.png" alt="fehler" />';
	}
	else
	{
		z(text);
		if(check_status == "j")
		{
			document.getElementById('form_nick').innerHTML = '<font color="green">Nickname ist verfügbar</font>';
			document.getElementById('form_nick_image').innerHTML = '<img src="/design/img/green.png" alt="korrekt" />';
		}
		else if(check_status == "n")
		{
			document.getElementById('form_nick').innerHTML = '<font color="red">Nickname leider belegt</font>';
			document.getElementById('form_nick_image').innerHTML = '<img src="/design/img/red.png" alt="fehler" />';
		}
	}
	window.setTimeout("check_nick()", 1000);
	return false;
}

function check_sex()
{
	if(document.getElementById("sex_w").checked == true || document.getElementById("sex_m").checked == true)
	{
		document.getElementById('form_sex_image').innerHTML = '<img src="/design/img/green.png" alt="korrekt" />';
	}
	else
	{
		document.getElementById('form_sex_image').innerHTML = '<img src="/design/img/red.png" alt="falsch" />';
	}
	return false;
}

function check_gb()
{
	t = document.getElementById("g_tag").value;
	m = document.getElementById("g_monat").value;
	j = document.getElementById("g_jahr").value;
	
	if(t != "" && m != "" && j != "")
	{
		document.getElementById('form_gb_image').innerHTML = '<img src="/design/img/green.png" alt="korrekt" />';
	}
	else
	{
		document.getElementById('form_gb_image').innerHTML = '<img src="/design/img/red.png" alt="falsch" />';
	}
	
	return false;
}

function zget(text, docid) 
{
  var xmlHttp = null;
  var random = Math.random();
  // Mozilla, Opera, Safari sowie Internet Explorer 7
  if (typeof XMLHttpRequest != 'undefined') {
      xmlHttp = new XMLHttpRequest();
  }
  if (!xmlHttp) {
      // Internet Explorer 6 und älter
      try {
          xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
      } catch(e) {
          try {
              xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
          } catch(e) {
              xmlHttp  = null;
          }
      }
  }
  if (xmlHttp) {
      xmlHttp.open('GET', text+"?"+random, true);
      xmlHttp.onreadystatechange = function () {
          if (xmlHttp.readyState == 4) {
              html =  (xmlHttp.responseText);
			  document.getElementById(docid).innerHTML = html;
			  return false;
		  }
      };
      xmlHttp.send(null);
  }
}

function ajax_fotos(id)
{
	zget('/verwaltung/eventfotos/?show=edit&do=ajax_fotos&id='+id,'anzahlfotos');
	window.setTimeout('ajax_fotos('+id+')', 500);
}
