var sep = "mma123amm";
var mouseX, mouseY;
var prefix="&#105;&#110;&#102;&#111;";
var domaine = "&#109;&#45;&#97;&#116;&#108;&#97;&#115;&#46;&#110;&#101;&#116;";

function $(id){return document.getElementById(id);}
function Ajx(){
	this.url="";
	this.param="";
	this.method="POST";
	this.onOk=null;
	this.onEr= function(msg){
		return alert(msg);
		}
}

Ajx.prototype.makeQuery = function(){
	if(!this.url){
		this.onEr("Es wurde kein URL angegeben.");
		return false;
		}
	
	if(!this.method){
		this.method = "POST";
		} else {
		this.method = this.method.toUpperCase();
		}
		
	var _this = this;
	var xhr = getXMLHttpRequest();
	
	if(!xhr){
		this.onEr("Es konnte kein XMLHttpRequest-Objekt erstellt werden.");
		return false;
		}
	
	switch (this.method) {
    case "GET": xhr.open(this.method, this.url+"?"+this.param, true);
                xhr.onreadystatechange = readyStateHandler;
                xhr.send(null);
                break;
    case "POST": xhr.open(this.method, this.url, true);
                 xhr.onreadystatechange = readyStateHandler;
                 xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                 xhr.send(this.param);
                 break;
  				 }  

	function readyStateHandler(){
		if(xhr.readyState < 4){
			return false;
			}
		if(xhr.status == 200 || xhr.status == 304){
			if(_this.onOk){
				_this.onOk(xhr.responseText, xhr.responseXML);
				} 
			} else {
			if(_this.onEr){
				_this.onEr("["+xhr.status+" "+xhr.statusText+"] Es trat ein Fehler bei der Datenbertragung auf.");	
				}
			}
	}
}

function getXMLHttpRequest(){
  if (window.XMLHttpRequest) {
    return new XMLHttpRequest();
  	} else if (window.ActiveXObject) {
    try {   
		return new ActiveXObject("Msxml2.XMLHTTP");
    	} catch(e) {
		try {        
        return new ActiveXObject("Microsoft.XMLHTTP");  
		} catch (e) {
        return null;
        }
    }
  }
  return false;
}


//-------------------------------------------------------------------------------------------------
function weedList(id, zuType, zuFeld){
	
	if (zuFeld == "nondefinie"){
		if($('ns').checked == true) {
			var feld = $('ns').id;
		} else if($('na').checked == true){
			var feld = $('na').id;
		} else {
			var feld = $('nf').id;
		}
	} else {
	var feld = zuFeld;
	}
	
	with(new Ajx()){
		url="ajax/ajax_weed.php";
		onOk = function handelOk(txt,xml){
			$('list').innerHTML=txt;
			}
		onEr = function handelEr(){
			$('list').innerHTML="loading ...";
			}
		param = "zuid="+id+"&zutype="+zuType+"&zufeld="+feld;
		makeQuery();
	}
}

//-------------------------------------------------------------------------------------------------
function weedContent(id, zuType, zuFeld){
	with(new Ajx()){
		url="ajax/ajax_weed.php";
		onOk = function handelOk(txt,xml){
				temp = txt.split(sep);
				$('fiche_ns').innerHTML = temp[0];
				$('cont').innerHTML = temp[1];
				}
		onEr = function handelEr(){
				$('fiche_ns').innerHTML = 'chargement en cours ...';
				}
		param = "id="+id+"&zutype="+zuType;
		makeQuery();
	}
}
//-------------------------------------------------------------------------------------------------
function getMousePos(e){
if (!e)
var e = window.event||window.Event;
if('undefined'!=typeof e.pageX){
			mouseX = e.pageX;
			mouseY = e.pageY;
			}
			else
			{
			mouseX = e.clientX + document.body.scrollLeft;
			mouseY = e.clientY + document.body.scrollTop;
			}
}
			
if(window.Event && document.captureEvents)
document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMousePos;
			
//-------------------------------------------------------------------------------------------------
function ajaxDico(motEx){
	with(new Ajx()){
			
	var Left =  mouseX;
	var Top =  mouseY;
		url="ajax/ajax_weed.php";
		onOk = function handelOk(txt,xml){
				with($('dico')){
				style.visibility = 'visible';
				style.left = Left;
				style.top = Top - 70;
				innerHTML = txt;				
				}
				}
		onEr = function handelEr(){
				with($('dico')){
				style.visibility = 'visible';
				style.left = Left;
				style.top = Top - 70;
				innerHTML = 'mot en cours ...';
				}
				}
		param = "mot_ex="+motEx+"&zutype=zudico";
		makeQuery();
	}
}
//-------------------------------------------------------------------------------------------------

//-------------------------------------------------------------------------------------------------
/*function contactFormValidation(nom,prenom,email,mes){
	var msg="";
	if(!isEmail(email)){ msg .="Email incorrect. Veuillez verifier !!! ";}
	if(!isEmpty(nom)){ msg .="Le champs Nom est vide. Veuillez remplir !!! ";}
	if(!isEmpty(prenom)){ msg .="Le champs prenom est vide. Veuillez remplir !!! ";}
	if(!isEmpty(mes)){ msg .="Le champs Message est vide. Veuillez remplir !!! ";}
	if(msg.lenght != 0){
	alert(msg);
	return false;
	}
}*/