// JavaScript Document

/* TARGET FIX FOR _BLANK WINDOWS ***********************************/

window.onload = function() {
    var links = document.getElementsByTagName('a');
    for (var i=0;i < links.length;i++) {
        if (links[i].className == 'new-window') {
            links[i].onclick = function() {
                window.open(this.href);
                return false;
            };
        }
    }
};

/* HIGHLIGHT ACTIVE INPUT ******************************************/
/*
var currentlyActiveInputRef = false;
var currentlyActiveInputClassName = false;

function highlightActiveInput()
{
	if(currentlyActiveInputRef){
		currentlyActiveInputRef.className = currentlyActiveInputClassName;
	}
	currentlyActiveInputClassName = this.className;
	this.className = 'newsletterHighlighted';
	currentlyActiveInputRef = this;
	if(this.value=='E-Mail Adresse')this.value='';
	
}

function blurActiveInput()
{
	this.className = currentlyActiveInputClassName;
	if(this.value=='')this.value='E-Mail Adresse';
	
}


function initInputHighlightScript()
{
	var tags = ['INPUT','TEXTAREA'];
	
	for(tagCounter=0;tagCounter<tags.length;tagCounter++){
		var inputs = document.getElementsByTagName(tags[tagCounter]);
		for(var no=0;no<inputs.length;no++){
			if(inputs[no].className && inputs[no].className=='doNotHighlightThisInput')continue;
			
			if(inputs[no].tagName.toLowerCase()=='textarea' || (inputs[no].tagName.toLowerCase()=='input' && inputs[no].type.toLowerCase()=='text')){
				inputs[no].onfocus = highlightActiveInput;
				inputs[no].onblur = blurActiveInput;
			}
		}
	}
}

/*


/* NEWSLETTERANMELDUNG **********************************************/

function checkContactform() {
	
	if (document.forms[0].name.value == "") {
        alert("Bitte geben Sie Ihren Vor- und Nachname ein!");
        return false;
        }
		

	if (document.forms[0].nachricht.value == "") {
        alert("Bitte geben Sie Ihre Nachricht ein!");
        return false;
        }
		
	if (document.forms[0].sicherheitscode.value == "") {
        alert("Bitte geben Sie den Sicherheitscode ein!");
        return false;
        }
		
		if (!checkMail() ) {
		return false;
        }

        SafeRequest();
		//return true;
		return false;
}

function checkMail()
{
	var y = document.forms[0].email.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	//if (filter.test(x) && filter.test(y)) return true;
	if (filter.test(y)) return true;
	else alert('Bitte geben Sie eine korrekte Email-Adresse an!');
}



var http = createRequestObject();

function createRequestObject() {
		var xmlhttp;
		try { xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); }
	  catch(e) {
	    try { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
	    catch(f) { xmlhttp=null; }
	  }
	  if(!xmlhttp&&typeof XMLHttpRequest!="undefined") {
	  	xmlhttp=new XMLHttpRequest();
	  }
		return  xmlhttp;
	}
       // if (http != null) {
		function SafeRequest(){
           http.open("POST", "contact_send.php", true);
           http.onreadystatechange = ausgeben;
           http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		   	
			var rnd = Math.random();
			var name = escape(document.getElementById("name").value);
			var email = escape(document.getElementById("email").value);
			var telefon = escape(document.getElementById("telefon").value);
			var sicherheitscode = escape(document.getElementById("sicherheitscode").value);
			var nachricht = escape(document.getElementById("nachricht").value);

			http.send('sicherheitscode='+sicherheitscode+'&name='+name+'&email='+email+'&telefon='+telefon+'&nachricht='+nachricht+'&rnd='+rnd);
        }
        
        function ausgeben() {
           if (http.readyState == 4) {
		      document.getElementById("Loading").style.visibility = "hidden";	
			  document.getElementById("Ausgabe").style.visibility = "visible";	
              document.getElementById("Ausgabe").innerHTML = http.responseText;

           }
		   if (http.readyState == 2) {
		   	  document.getElementById("Loading").style.visibility = "visible";	
              document.getElementById("Loading").innerHTML = "<img src=\"img/icon_loading.gif\">";
			  document.forms[0].submit.disabled = true;

           }
		   if (http.readyState == 1) {
		   	  document.getElementById("Loading").style.visibility = "visible";	
              document.getElementById("Loading").innerHTML = "<img src=\"img/icon_loading.gif\">";
			  document.forms[0].submit.disabled = true;

           }
        }

