var xmlHTTP;
var req=null;
function getXMLHTTP(){
    xmlHttp=null;
    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;
            }
        }
    }
    return xmlHttp;
}
        
function checkforready(){
if(req.readyState == 4) {
    if(req.status != 200) {
        document.getElementById("left").innerHTML="<font color=\"red\">Fehler!</font>";
        return false;
    }
    document.getElementById("left").innerHTML=req.responseText;
    }
}

function generateQueryString(formname){
    var querystring='';
    var i;
    for(i=0;i<document.forms[formname].length;i++)
    {
        switch(document.forms[formname].elements[i].type)
        {
            case 'text':
                querystring+=document.forms[formname].elements[i].name+'='+document.forms[formname].elements[i].value+'&';
                break;
                
            case 'checkbox':
                if(document.forms[formname].elements[i].checked)
                {
                    querystring+=document.forms[formname].elements[i].name+'='+document.forms[formname].elements[i].value+'&';
                }
                break;
                
            case 'submit':
            case 'reset':
                break;
            
            default:
                querystring+=document.forms[formname].elements[i].name+'='+document.forms[formname].elements[i].value+'&';
                break;
        }
    }
    return querystring;
}

function checkforreadycontact(){
if(req.readyState == 4) {
    if(req.status != 200) {
        document.getElementById("returnmessage").innerHTML="<font color=\"red\">"+nichtVerschickt+"</font>";
        return false;
    }
    document.getElementById("returnmessage").innerHTML="<font color=\"green\">"+erfolgreichVerschickt+"</font>";
    }
}

function sendContactForm(){
    
    req=null;
    req=getXMLHTTP();
    req.onreadystatechange = checkforreadycontact;
    req.open("GET", "../../../Scripts/MailForm.php?"+generateQueryString("kontakt"), true);
    req.send(null);
}

function checkContactForm(){
    var fm=document.getElementById("kontakt");
    if(fm.Firma.value=='' || fm.Anrede.value=='' || fm.Nachname.value=='' || fm.Strasse.value=='' || fm.Ort.value=='' || fm.Land.value=='' || fm.Email.value=='' || fm.text.value=='')
    {
        tooltip(kontaktMeldung,540,490);
        return false;
    }
    else
    {
        sendContactForm();
        return false;
    }
}


function checkforreadypre(){
if(req.readyState == 4) {
    if(req.status != 200) {
        document.getElementById("returnmessage").innerHTML="<font color=\"red\">"+nichtVerschickt+"</font>";
        return false;
    }
    document.getElementById("returnmessage").innerHTML="<font color=\"green\">"+erfolgreichVerschickt+"</font>";
    }
}

function sendPreForm(){
    
    req=null;
    req=getXMLHTTP();
    req.onreadystatechange = checkforreadycontact;
    req.open("GET", "../../../Scripts/PreForm.php?"+generateQueryString("pre"), true);
    req.send(null);
}

function checkPreForm(){
    var fm=document.getElementById("pre");
    if(fm.Name.value=='' || fm.Email.value=='')
    {
        tooltip(preMeldung,400,580);
        return false;
    }
    else
    {
        sendPreForm();
        return false;
    }
}

function checkWinForm(){
    var fm=document.getElementById("win");
    if(fm.Firma.value=='' || fm.Branche.value=='' || fm.Anrede.value=='' || fm.Nachname.value=='' || fm.Strasse.value=='' || fm.Ort.value=='' || fm.Land.value=='' || fm.Email.value=='' || fm.Agree.checked==false)
    {
        tooltip(meldung,580,480);
        return false;
    }
    else
    {
        sendWinForm();
        return false;
    }
}

function sendWinForm(){
    
    req=null;
    req=getXMLHTTP();
    req.onreadystatechange = checkforreadywin;
    req.open("GET", "../../../Scripts/WinForm.php?"+generateQueryString("win"), true);
    req.send(null);
}

function checkforreadywin(){
if(req.readyState == 4) {
    if(req.status != 200) {
        if(req.status == 404)
        {
            tooltip(mailexists,580,480);
            return false;
        }
        else
        {
            document.getElementById("returnmessage").innerHTML="<font color=\"red\">"+nichtVerschickt+"</font>";
            return false;
        }
        
    }
    window.location.href='ende.html';
    document.getElementById("returnmessage").innerHTML="<font color=\"green\">"+erfolgreichVerschickt+"</font>";
    }
}

/** begin Tooltip-Code */


// position of the tooltip relative to the mouse in pixel //
var offsetx = -200;
var offsety =  10;

function newelement(newid)
{ 
    if(document.createElement)
    { 
        var el = document.createElement('div'); 
        el.id = newid;     
        with(el.style)
        { 
            display = 'none';
            position = 'absolute';
        } 
        el.innerHTML = '&nbsp;'; 
        document.body.appendChild(el); 
    } 
} 
var ie5 = (document.getElementById && document.all); 
var ns6 = (document.getElementById && !document.all); 
var ua = navigator.userAgent.toLowerCase();
var isapple = (ua.indexOf('applewebkit') != -1 ? 1 : 0);
function getmouseposition(e)
{
    if(document.getElementById)
    {
        var iebody=(document.compatMode && 
        	document.compatMode != 'BackCompat') ? 
        		document.documentElement : document.body;
        pagex = (isapple == 1 ? 0:(ie5)?iebody.scrollLeft:window.pageXOffset);
        pagey = (isapple == 1 ? 0:(ie5)?iebody.scrollTop:window.pageYOffset);
        mousex = (ie5)?event.x:(ns6)?clientX = e.clientX:false;
        mousey = (ie5)?event.y:(ns6)?clientY = e.clientY:false;

        var lixlpixel_tooltip = document.getElementById('tooltip');
        lixlpixel_tooltip.style.left = (mousex+pagex+offsetx) + 'px';
        lixlpixel_tooltip.style.top = (mousey+pagey+offsety) + 'px';
    }
}
function tooltip(tip,top,left)
{
    if(!document.getElementById('tooltip')) newelement('tooltip');
    var lixlpixel_tooltip = document.getElementById('tooltip');
    lixlpixel_tooltip.style.zIndex=900;
    lixlpixel_tooltip.innerHTML = tip+"<br /><br /><input type=\"button\" value=\"OK\" onclick=\"javascript: tooltipexit();\">";
    lixlpixel_tooltip.style.display = 'block';
    lixlpixel_tooltip.style.background='#AAAAAA';
    lixlpixel_tooltip.style.left = left+'px';
    lixlpixel_tooltip.style.top = top+'px';
    //getmouseposition();
}
function tooltipexit()
{
    document.getElementById('tooltip').style.display = 'none';
}

/* ende tooltip code */

