function sl(id) { return document.getElementById(id); }
 
function a(){
ajax("name","n_meldung");}

//id = current element {Value einlesen}
//col = mysql col {check value in this col}
//div update platz {response update}

function ajax(id,div){
	var h=null;
	var para ='wert='+encodeURIComponent(sl(id).value);
	
	if (window.XMLHttpRequest) {
	h = new XMLHttpRequest();
	} else if (window.ActiveXObject)
	{h = new ActiveXObject("Microsoft.XMLHTTP");}
	if (h != null)
	{
	h.open("POST", "functions.php", true);
	h.setRequestHeader(
      "Content-Type",
      "application/x-www-form-urlencoded");
	h.send(para);
	}
	//ajax event
	h.onreadystatechange = function(){
	if(h.readyState<4){
	sl('n_meldung').innerHTML= '<img src="http://www.arabic-keyboard.org/arabic-names/i/ajax.gif" height="20" width="20">';
	}
	if (h.readyState==4)
	{	
	var a=h.responseText;
	sl(div).innerHTML= a;
	}
	}
}

function check_post(){
	var h=null;
	var para ='name='+encodeURIComponent(sl('name').value)+'&area='+encodeURIComponent(sl('area').value)+'&sex='+encodeURIComponent(sl('sex').value)+'&nickname='+encodeURIComponent(sl('nickname').value);
	
	if (window.XMLHttpRequest) {
	h = new XMLHttpRequest();
	} else if (window.ActiveXObject)
	{h = new ActiveXObject("Microsoft.XMLHTTP");}
	if (h != null)
	{
	h.open("POST", "checkpost.php", true);
	h.setRequestHeader(
      "Content-Type",
      "application/x-www-form-urlencoded");
	h.send(para);
	}
	//ajax event
	h.onreadystatechange = function(){
	if(h.readyState<4){
	sl('error').innerHTML='<img src="http://www.arabic-keyboard.org/arabic-names/i/ajax.gif" height="20" width="20">';
	}
	if (h.readyState==4)
	{	
	var a=h.responseText;
	sl('error').style.display="block";
	sl('error').innerHTML= a;
	}
	}
}
function currentYPosition() {
	if (self.pageYOffset)
		 return self.pageYOffset;
	if (document.documentElement && document.documentElement.scrollTop)
		return document.documentElement.scrollTop;
	if (document.body.scrollTop)
		 return document.body.scrollTop;
	return 0;
}
function elmYPosition(eID) {
	var elm  = sl(eID);
	var y    = elm.offsetTop;
	var node = elm;
	while (node.offsetParent && node.offsetParent != document.body) {
		node = node.offsetParent;
		y   += node.offsetTop;
	} return y;
}
function smoothScroll(eID) {
	var startY   = currentYPosition();
	var stopY    = elmYPosition(eID);
	var distance = stopY > startY ? stopY - startY : startY - stopY;
	if (distance < 100) {
		scrollTo(0, stopY); return;
	}
	var speed = Math.round(distance / 20000);
	var step  = Math.round(distance / 100);
	var leapY = stopY > startY ? startY + step : startY - step;
	var timer = 0;
	if (stopY > startY) {
		for ( var i=startY; i<stopY; i+=step ) {
			setTimeout("window.scrollTo(0, "+leapY+")", timer * speed);
			leapY += step; if (leapY > stopY) leapY = stopY; timer++;
		} return;
	}
	for ( var i=startY; i>stopY; i-=step ) {
		setTimeout("window.scrollTo(0, "+leapY+")", timer * speed);
		leapY -= step; if (leapY < stopY) leapY = stopY; timer++;
	}
}
function m(a){
	a.style.color ="#222";
		sl('se').style.visibility="hidden";

}

var timeout    = 300; //dropdown hide
var closetimer = 0;
var ddmenuitem = 0;
var ok=0;
function jsddm_open()
{  jsddm_canceltimer();
   jsddm_close();
    ddmenuitem = $(this).find('ul').css('visibility', 'visible');
}
function jsddm_close()
{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}
function jsddm_timer()
{  closetimer = window.setTimeout(jsddm_close, timeout);}
function jsddm_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}

$(document).ready(function() {		

		$('#nav > li').bind('mouseover', jsddm_open);
		$('#nav > li').bind('mouseout',  jsddm_timer);   

});


