var vis = 1;

var impr = 1;



function fadecontact() {
	   if (vis == 1) {  $(".kontakt").animate({  opacity: 'show'},'normal'); vis=0; }
	   else {  $(".kontakt").animate({  opacity: 'hide'},'normal'); vis=1; }
	
}

function fadeimprint() {
	   if (impr == 1) {  $("#impressum").animate({  opacity: 'show'},'normal'); impr=0; }
	   else {  $("#impressum").animate({  opacity: 'hide'},'normal'); impr=1; }
	
}

function showme(whichone) {
	
  
	if (actual != whichone) {
		if ( $("#"+whichone).css('display') == 'none' ) {
	 		$("#"+actual).animate({  opacity: 'hide'},'normal', function() {
           		$("#"+whichone).animate({
                	opacity: 'show'
            	},
            	'normal');
       		 });
	 	actual = whichone;
		}
	}
	document.title  = "[ bytes in motion GmbH - "+whichone+" ]";
}

function validateFields() {
	themail = document.forms[0].email.value;
	if (document.forms[0].ihrname.value == '' ) {
		alert("Bitte geben Sie einen Namen ein!");
		return;
	}
	
	if (validatemail(themail) !=true ) {
		alert("Bitte geben Sie eine gültige Mailadresse ein!");
		return;
	}
	
	if (document.forms[0].nachricht.value == '' ) {
		alert("Bitte geben Sie eine Nachricht ein!");
		return;
	}
	
	sendmymail();
	
}

function validatemail(mymail) {
	if (!mymail.match(/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i)){
	   return false;
	} else {
		return true;
	}
}

function sendmymail() {
	
	var params = "name=" + encodeURI(document.forms[0].ihrname.value) + "&email="+encodeURI(document.forms[0].email.value)+"&nachricht=" + escape(encodeURI(document.forms[0].nachricht.value));
	
	if (window.XMLHttpRequest) {
   		req = new XMLHttpRequest();
		req.overrideMimeType('text/html');
	} else if (window.ActiveXObject) {
   		req = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	
	req.onreadystatechange = function() {
		
		if(req.readyState == 4 && req.status == 0) {
			vis = 1;
			$(".kontakt").animate({  opacity: 'hide'},'normal', function() {
				document.getElementById('kontakt').innerHTML = theform;
			});
		}
	}
	
	req.open("GET", "http://edgar.bytesinmotion.de/mailer.php?" + params, true);
	
	req.setRequestHeader("Cache-Control", "no-cache");
	req.send();
	var theform = document.getElementById('kontakt').innerHTML;
	document.getElementById('kontakt').innerHTML = "<p>Danke f&uuml;r Ihre Nachricht!</p>";
}