// JavaScript Document

function impressum(){
	window.open("impressum.html","imp","width=350,height=400,resize=0,scrollbars=1");
}

function search(s){
	var i = document.getElementById("select");
	var d1 = i.options[i.options.selectedIndex].value;
	var d2 = document.getElementById("d1").value;
  	query = "do=3&d1="+escape(d1)+"&d2="+escape(d2)+"&l="+s;
  	xmlhttpAjax(query,"loader.php");	
}


function load_dwn(d1,s){
  	query = "do=4&d1="+escape(d1)+"&l="+s;
  	xmlhttpAjax(query,"loader.php");		
}


function loader(s){
	var i = document.getElementById("select2");
	var d1 = i.options[i.options.selectedIndex].value;
	if (d1 == 0){
		query = "do=8&l="+s;
		xmlhttpAjax(query,"loader.php");
	}else{ 
		query = "do=1&d1="+escape(d1)+"&l="+s;
  		xmlhttpAjax(query,"loader.php");
	}
}

function loader2(s){
	
	var i = document.getElementById("select");
	var d1 = i.options[i.options.selectedIndex].value;

	if (d1 == 0){
		query = "do=7&l="+s;
		xmlhttpAjax(query,"loader.php");
	}else{
		query = "do=5&d1="+escape(d1)+"&l="+s;
	    xmlhttpAjax(query,"loader.php");
	}
}

function loader3(s){
	var i = document.getElementById("select3");
	var d1 = i.options[i.options.selectedIndex].value;
 
  query = "do=6&d1="+escape(d1)+"&l="+s;
  xmlhttpAjax(query,"loader.php");
}


var t = Array();
function f_klick(id){
	if (t[id] != 1) document.getElementById("f"+id).value = "";
	t[id] = 1;
}



function save(lg){
	d1 = document.getElementById("f1").value;		
	d2 = document.getElementById("f2").value;		
	d3 = document.getElementById("f3").value;		
	d4 = document.getElementById("f4").value;		
	d5 = document.getElementById("f5").value;		
	d6 = document.getElementById("f6").value;		
	d7 = document.getElementById("f7").value;			
	
	var i = document.getElementById("select2");
	var d8 = i.options[i.options.selectedIndex].value;

	var i = document.getElementById("select4");
	var d9 = i.options[i.options.selectedIndex].value;
	
	if (!d1 || !d7 || d8 == 0 || d9 == 0 || !t[1] || !t[7]) {
		alert("Please fill all fields!");	
	}else{
	  
	  var query = "l="+lg+"&do=2&d1="+escape(d1)+"&d2="+escape(d2)+"&d3="+escape(d3)+"&d4="+escape(d4)+"&d5="+escape(d5)+"&d6="+escape(d6)+"&d7="+escape(d7)+"&d8="+escape(d8)+"&d9="+escape(d9);
	  xmlhttpAjax(query,"loader.php");		
	}
}


// +--------------------------------------+
// | AJAX - Funktionen					  |
// +--------------------------------------+

function xmlhttpAjax(query,dm){

	var xmlhttp = new ajaxRequest(
        dm,
        function()
        {
            var r = xmlhttp.req;
            if (r.readyState==4)
            {
                if (r.status == 200){
					val = r.responseText;
					eval(val);				
				}
           }
        },
        "POST",
        query,
        ["Content-Type","application/x-www-form-urlencoded"]
    );
    xmlhttp.doRequest();
}


ajaxRequest = function(u,f,m,b,h,s)
{
    this.url      = u;
    this.wState   = f || function() { };
    this.method   = m || "GET";
    this.body     = b || null;
    this.headers  = h || false;
    this.sync     = s || true;
    this.abortReq = false;
    
    this.req = (window.XMLHttpRequest) 
           ?
           new XMLHttpRequest()
           :
           ((window.ActiveXObject)
           ?
           new ActiveXObject("Microsoft.XMLHTTP")
           :
           false
           );
    
    this.doRequest = function()
    {
        this.req.open(this.method,this.url,this.sync);
        if (this.headers)
        {
            for (var i=0; i<this.headers.length; i+=2)
            {
                this.req.setRequestHeader(
                    this.headers[i],this.headers[i+1]
                );
            }
        }
        this.req.onreadystatechange = this.wState;
        (!this.abortReq) ? this.req.send(this.body) : this.req.abort();
    }
}
