var http_request = false;

function makeRequest(url,parameters)
{
 http_request = false;
 if (window.XMLHttpRequest)
 {
  http_request = new XMLHttpRequest();
  if (http_request.overrideMimeType)
  {
   http_request.overrideMimeType('text/html');
  }
 }
 else if (window.ActiveXObject)
 {
  try
  {
   http_request = new ActiveXObject("Msxml2.XMLHTTP");
  }
  catch(e)
  {
   try
   {
    http_request = new ActiveXObject("Microsoft.XMLHTTP");
   }
   catch(e)
   {}
  }
 }
 if (!http_request)
 {
  alert('Cannot create XMLHTTP instance');
  return false;
 }

 http_request.onreadystatechange = alertContents;
 http_request.open('GET',url+parameters,true);
 http_request.send(null);
}

function initNab()
{
 document.getElementById("prcmsg").style.display = "none";
 document.getElementById("sccmsg").style.display = "block";
 document.forms.con.reset();
}

function nab()
{
	setTimeout("initNab()",5000);
}

function alertContents()
{
 if (http_request.readyState == 4)
 {
  if (http_request.status == 200)
  {
   document.getElementById("prcmsg").style.display = "block";
   if (http_request.responseText.indexOf("error") != -1)
   {
    document.getElementById("errmsg").innerHTML = "";
    document.getElementById("errmsg").innerHTML += "<strong>Fehler:</strong><br /><br />";
    document.getElementById("prcmsg").style.display = "none";
    document.getElementById("sccmsg").style.display = "none";
    document.getElementById("errmsg").style.display = "block";
  	 if (http_request.responseText.indexOf(":5") != -1)
   	{
    	document.getElementById("errmsg").innerHTML += "<strong>Bitte best&auml;tigen Sie, dass Sie unser Angebot nutzen m&ouml;chten, und machen Sie einen Terminvorschlag!</strong><br />";
     document.getElementById("lbest").style.color = "#ff0000";
   	}
    if (http_request.responseText.indexOf(":1") != -1)
    {
     document.getElementById("errmsg").innerHTML += "Wir m&ouml;chten Sie kennenlernen, <strong>bitte geben Sie Ihren Namen an!</strong><br />";
     document.getElementById("lname").style.color = "#ff0000";
    }
    if (http_request.responseText.indexOf(":2") != -1)
    {
     document.getElementById("errmsg").innerHTML += "Wie sollen wir Ihnen antworten? <strong>Bitte geben Sie Ihre korrekte E-Mail-Adresse an!</strong><br />";
     document.getElementById("lmail").style.color = "#ff0000";
    }
    if (http_request.responseText.indexOf(":3") != -1)
    {
     document.getElementById("errmsg").innerHTML += "<strong>Schicken Sie uns eine kurze Nachricht</strong>, damit wir wissen, was wir f&uuml;r Sie tun k&ouml;nnen!<br />";
     document.getElementById("ltext").style.color = "#ff0000";
    }
  	 else if (http_request.responseText.indexOf(":4") != -1)
   	{
    	document.getElementById("errmsg").innerHTML = "<strong>Allgemeiner Fehler:</strong><br /><br />Es tut uns leid, Ihre E-Mail konnte nicht verschickt werden. Bitte versuchen Sie es zu einem sp&auml;teren Zeitpunkt noch einmal, oder rufen Sie doch einfach kurz an!";
   	}
   }
   else if (http_request.responseText.indexOf("success") != -1)
   {
    document.getElementById("errmsg").style.display = "none";
    document.getElementById("errmsg").innerHTML = "";
    nab();
   }
  }
  else
  {
   document.getElementById("errmsg").innerHTML = "<strong>Serverfehler:</strong><br /><br />Es tut uns leid, Ihre E-Mail konnte nicht verschickt werden. Bitte versuchen Sie es zu einem sp&auml;teren Zeitpunkt noch einmal, oder <a href=\"../kontakt\" style=\"color:#ff0000; text-decoration:underline; font-weight:normal;\">rufen Sie doch einfach kurz an</a>!";
   document.getElementById("prcmsg").style.display = "none";
   document.getElementById("sccmsg").style.display = "none";
   document.getElementById("errmsg").style.display = "block";
  }
 }
}

function get(obj)
{
 var getstr="?subpage=" + subpage + "&";
 for (i=0;i<obj.childNodes.length;i++)
 {
  if (obj.childNodes[i].tagName == "INPUT")
  {
   if (obj.childNodes[i].type == "hidden")
   {
    getstr+=obj.childNodes[i].name+"="+obj.childNodes[i].value+"&";
   }
  }
 }
 makeRequest('/wp-content/themes/blattwerk/submit.php',getstr);
}

 document.write('<div id="errmsg"></div>');
 document.write('<div id="prcmsg"></div>');
	document.write('<form method="post" name="con" id="con" action="javascript:get(document.getElementById(\'con\'));">');
 document.write('<div id="sccmsg"><strong>Vielen Dank!</strong><br /><br />Ihre E-Mail wurde verschickt, wir werden uns schnellstm&ouml;glich bei Ihnen melden!</div>');
 if (subpage == "14")
 {
	 document.write('<input type="hidden" name="posted" value="1" />');
	 document.write('<input type="hidden" name="tmpname" value="" />');
	 document.write('<input type="hidden" name="tmpmail" value="" />');
	 document.write('<input type="hidden" name="tmptext" value="" />');
	 document.write('<label id="lname" for="cname">Name</label><br />');
	 document.write('<input id="cname" name="cname" tabindex="1" onchange="document.forms.con.tmpname.value = this.value;" /><br />');
	 document.write('<label id="lmail" for="cmail">E-Mail</label><br />');
	 document.write('<input id="cmail" name="cmail" tabindex="2" onchange="document.forms.con.tmpmail.value = this.value;" /><br />');
	 document.write('<label id="ltext" for="ctext">Nachricht</label><br />');
	 document.write('<textarea id="ctext" name="ctext" tabindex="3" onchange="document.forms.con.tmptext.value = this.value;"></textarea>');
	 document.write('<button class="btn" value="Senden" tabindex="4" onclick="document.forms.con.submit();" />');
	}
	else if (subpage == "128")
	{
	 document.write('<form method="post" name="con" id="con" action="javascript:get(document.getElementById(\'con\'));">');
	 document.write('<input type="hidden" name="posted" value="1" />');
	 document.write('<input type="hidden" name="tmpname" value="" />');
	 document.write('<input type="hidden" name="tmpcorp" value="" />');
	 document.write('<input type="hidden" name="tmpmail" value="" />');
	 document.write('<input type="hidden" name="tmploc" value="" />');
	 document.write('<input type="hidden" name="tmpbest" value="" />');
	 document.write('<input type="hidden" name="tmpday" value="" />');
	 document.write('<input type="hidden" name="tmpmon" value="" />');
	 document.write('<input type="hidden" name="tmpyear" value="" />');
	 document.write('<input type="hidden" name="tmphr" value="" />');
	 document.write('<input type="hidden" name="tmpmin" value="" />');
	 document.write('<input type="hidden" name="tmpfon" value="" />');
	 document.write('<input type="hidden" name="tmpmob" value="" />');
	 document.write('<input type="hidden" name="tmptext" value="" />');
	 document.write('<input type="hidden" name="tmpqb" value="" />');
	 document.write('<div class="l">');
	 document.write('<label for="ctext" id="ltext">Was haben Sie bisher<br />f&uuml;r Ihre Kommunikation getan?</label><br />');
	 document.write('<textarea style="margin-bottom:15px;" name="ctext" id="ctext" tabindex="1" onchange="document.forms.con.tmptext.value=this.value;"></textarea>');
	 document.write('<label for="cqb">Wo sind Sie in der &Ouml;ffentlichkeit<br />in Erscheinung getreten?</label><br />');
	 document.write('<textarea name="cqb" id="cqb" tabindex="2" onchange="document.forms.con.tmpqb.value=this.value;" style="margin-bottom:15px;"></textarea><br />');
	 document.write('*: Pflichtfelder');
	 document.write('</div>');
	 document.write('<div class="m">');
	 document.write('<input type="radio" class="rad" name="cbest" id="cbest" onclick="document.forms.con.tmpbest.value=\'1\';" tabindex="3" />');
	 document.write('<label for="cbest" id="lbest"><strong>Ja, ich will Ihr Angebot nutzen.*</strong></label><br />');
	 document.write('<div class="date label">');
	 document.write('<label for="cday" class="app" id="lapp">Terminvorschlag:</label>');
	 document.write('</div>');
	 document.write('<div class="date">');
	 document.write('<input class="s" value="tt" name="cday" id="cday" maxlength="2" onfocus="if (this.value==\'tt\') { this.value = \'\'; }" onblur="if (this.value==\'\') { this.value = \'tt\'; }" onchange="document.forms.con.tmpday.value=this.value;" tabindex="4" />');
	 document.write('</div>');
	 document.write('<div class="date">');
	 document.write('<input class="s" value="mm" name="cmon" id="cmon" maxlength="2" onfocus="if (this.value==\'mm\') { this.value = \'\'; }" onblur="if (this.value==\'\') { this.value = \'mm\'; }" onchange="document.forms.con.tmpmon.value=this.value;" tabindex="5" />');
	 document.write('</div>');
	 document.write('<div class="date">');
	 document.write('<input class="s" value="jj" name="cyear" id="cyear" maxlength="2" onfocus="if (this.value==\'jj\') { this.value = \'\'; }" onblur="if (this.value==\'\') { this.value = \'jj\'; }" onchange="document.forms.con.tmpyear.value=this.value;" tabindex="6" />');
	 document.write('</div>');
	 document.write('<div class="date label">');
	 document.write('<label for="ctime" class="app" id="lapp">Uhrzeit:</label>');
	 document.write('</div>');
	 document.write('<div class="date">');
	 document.write('<input class="s" value="hh" name="chr" id="chr" maxlength="2" onfocus="if (this.value==\'hh\') { this.value = \'\'; }" onblur="if (this.value==\'\') { this.value = \'hh\'; }" onchange="document.forms.con.tmphr.value=this.value;" tabindex="7" />');
	 document.write('</div>');
	 document.write('<div class="date">');
	 document.write('<input class="s" value="mm" name="cmin" id="cmin" maxlength="2" onfocus="if (this.value==\'mm\') { this.value = \'\'; }" onblur="if (this.value==\'\') { this.value = \'mm\'; }" onchange="document.forms.con.tmpmin.value=this.value;" tabindex="8" />');
	 document.write('</div>');
	 document.write('<div class="divider clearfix"></div>');
	 document.write('<input type="radio" class="rad" name="cbest" id="cbest" onclick="document.forms.con.tmpbest.value=\'2\';" tabindex="9" />');
	 document.write('<label for="capp"><strong>Gute Idee, aber Hamburg ist mir zu weit entfernt.</strong> Rufen Sie mich bitte zur&uuml;ck, um einen Termin im meiner Stadt zu vereinbaren:</label><br />');
	 document.write('<div class="clearfix" style="margin-top:20px;"></div>');
	 document.write('<label for="cfon">Festnetz</label><br />');
	 document.write('<input class="m" name="cfon" id="cfon" onchange="document.forms.con.tmpfon.value=this.value;" tabindex="10" /><br />');
	 document.write('<label for="cmob">Mobil</label><br />');
	 document.write('<input class="m" name="cmob" id="cmob" onchange="document.forms.con.tmpmob.value=this.value;" tabindex="11" /><br />');
	 document.write('</div>');
	 document.write('<div class="r">');
	 document.write('<div style="margin-bottom:10px;"><strong>Ihre Kontaktdaten:</strong></div>');
	 document.write('<label for="cname" id="lname">Name*</label><br />');
	 document.write('<input class="m" name="cname" id="cname" onchange="document.forms.con.tmpname.value=this.value;" tabindex="12" /><br />');
	 document.write('<label for="ccorp">Unternehmen</label><br />');
	 document.write('<input class="m" name="ccorp" id="ccorp" onchange="document.forms.con.tmpcorp.value=this.value;" tabindex="13" /><br />');
	 document.write('<label for="cmail" id="lmail">E-Mail*</label><br />');
	 document.write('<input class="m" name="cmail" id="cmail" onchange="document.forms.con.tmpmail.value=this.value;" tabindex="14" /><br />');
	 document.write('<label for="cloc">Anschrift</label><br />');
	 document.write('<input class="m" name="cloc" id="cloc" onchange="document.forms.con.tmploc.value=this.value;" tabindex="15" /><br />');
	 document.write('<button class="btn" value="Senden" tabindex="13" onclick="document.forms.con.submit();" />');
	 document.write('</div>');
	}
		document.write('<div class="clearfix"></div>');
	 document.write('</form>');
