// scroller
	var count=120;
	var scroller;
	window.onload=main;
	function main(){  
		scrollerMove(0);
	}
	function scrollerMove(scrollen){
		if(document.getElementById('scrollerText')){
			var aTags = document.getElementById('scrollerText').getElementsByTagName('a');
			var zeichen=0;
			var zeilen=0;
			for(i=0;i<aTags.length;i++){
				zeichen=aTags[i].firstChild.data.length;
				zeilen += Math.ceil((zeichen+26)/26);
			}		
			
			var hoehe = (zeilen*14)+50;
			document.getElementById('scrollerText').style.height=hoehe+'px';
			
			scroller=document.getElementById('scrollerText');
			
			if(count>-hoehe){
				scroller.style.top=count+'px';
				count--;
			}else{
				count=120;
			}
			if (scrollen==0){
				scrollTime = setTimeout("scrollerMove(0)",50);
			}else{
				clearTimeout(scrollTime);
			}
		}
	}

//setzt die werte von der schnellsuche so, wie es die suche.php braucht
function setValues()
{	
	if(document.schnellsuche.suchenach[0].checked == true)
	{
		document.schnellsuche.stichwort.value=document.schnellsuche.query.value;
	}
	else
	{
		document.schnellsuche.ort.value=document.schnellsuche.query.value;
	}
}

function sucheVal(obj, unique)
{
	if (obj["plz_"+unique].value && isNaN(obj["plz_"+unique].value))
	{
		obj["plz_"+unique].style.color="red";
		alert ('Das ist keine Zahl.');
		return false;
	}
	else
	{
		obj["plz_"+unique].style.color="#5B5959";
	}
	if (obj["plz_"+unique].value && obj["plz_"+unique].value.length < 2)
	{
		obj["plz_"+unique].style.color="red";
		alert ('Bitte geben Sie mindestens die ersten zwei Stellen der Postleitzahl ein.');
		return false;
	}
	else
	{
		obj["plz_"+unique].style.color="#5B5959";
	}
	
	var rx = new RegExp("[^0-9a-zäöüßA-ZÄÖÜ`.,-/ ]");
	if (rx.test(obj["ort_"+unique].value) == true)
	{
		obj["ort_"+unique].style.color = 'red';
		alert('Ihre Eingabe wird nicht akzeptiert.\nBitte verwenden Sie ausschließlich Alphanumerische Zeichen sowie .,-/`');
		return false;
	}
	else
	{
		obj["ort_"+unique].style.color="#5B5959";
	}
	if (rx.test(obj.stichwort.value) == true)
	{
		obj.stichwort.style.color = 'red';
		alert('Ihre Eingabe wird nicht akzeptiert.\nBitte verwenden Sie ausschließlich Alphanumerische Zeichen sowie .,-/`');
		return false;
	}
	else
	{
		obj.stichwort.style.color="#5B5959";
	}
	
	if (obj.umkreis.value && isNaN(obj.umkreis.value))
	{
		obj.umkreis.style.color="red";
		alert ('Das ist keine Zahl.');
		return false;
	}
	else
	{
		obj.umkreis.style.color="#5B5959";
	}
	if (obj.umkreis.value && (obj.umkreis.value<1 || obj.umkreis.value>50))
	{
		obj.umkreis.style.color="red";
		alert ('Bitte wählen Sie einen Umkreis zwischen 1 und 50 KM.');
		return false;
	}
	else
	{
		obj.umkreis.style.color="#5B5959";
	}
	//return false;
}

function mouseoverimg (obj)
{
	obj = document.getElementById(obj);
	if (obj.src.indexOf('_o') == -1)
	{
		file = obj.src.replace(/(\.gif|jpg|jpeg|png)/, '_o$1');
		document.getElementById(obj.id).src = file;
	}
}
function mouseoverimgoff (obj)
{
	obj = document.getElementById(obj);
	if (obj.src.indexOf('_o') > -1)
	{
		file = obj.src.replace(/_o/, '');
		document.getElementById(obj.id).src = file;
	}
}
/* helpBox */
function remove(vater, kind)
{
	var node = document.getElementById(kind);
	document.getElementById(vater).removeChild(node);
}
function winOpen(id, width, height)
{
		 width=width+40;
		 height=height+40;
		 window.open('referenzen.php?id=' + id + '', '', 'width='+ width +',height='+ height +',scrollbars=yes');
}

Array.prototype.contains = function (obj) {
	for (var i=0;i<this.length;i++) {
		if (this[i] == obj) return true
	}
	return false;
}
/**
 * call2call popup and Handler
 */
var Call2callWin=null;
function openCall2callWin(id) {  
	if(Call2callWin && !Call2callWin.closed)
		Call2callWin.close();
		
	var width=540;
	var height=420;
	var left = (screen.availWidth - width) / 2;
	var top = (screen.availHeight - height) / 2;
	Call2callWin = open('call2call.php?id=' + id + '', '', 'width=' + width +',height=' + height +',left=' + left + ',top=' + top +',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=yes');
}

var Call2Call = function (prefixInput, phoneNumberInput) {
	var that = this;
	this.validInput = false;
	this.errorDisplay = document.getElementById('phoneNumberError');
	this.errorMessage = {
		value:'',
		flush:function () {
			this.value = '';
		}
	};
	
	prefixInput.onkeydown = phoneNumberInput.onkeydown = function (e) {
		return that.keyCheck(e);
	};
	prefixInput.onkeyup = phoneNumberInput.onkeyup = function (e) {
		while (this.value.match(/[^0-9]/)) {
			this.value = this.value.replace(/[^0-9]/, '');
		}
		var valid = that.keyCheck(e);
		that.errorMessage.flush();
		that.displayError();
		return 
	};

	/**
	 * check keydown event for digits and ctrl-keys (bksp...)
	 * 
	 * @param object	event
	 */
	this.keyCheck = function (e) {
		e = e ? e : window.event;
		var valid = false;
		this.errorMessage.flush();
		if (!e) return true;
		var keycode = e.which ? e.which : e.keyCode;
		
		var otherValid = [8, 9, 10, 16, 13, 18, 37, 39, 46, 116];
	
		// Zahlen
		if ((47 < keycode && keycode < 58) || (95 < keycode && keycode < 107) || otherValid.contains(keycode))
			valid = true;
		else that.errorMessage.value = 'Bitte nur Zahlen';
		
		this.displayError();
		return valid==true ? true : false;
	}
	
	this.validCall = function () {
		var prefixValue = prefixInput.value;
		var phoneNumberValue = phoneNumberInput.value;
		var premiumRatePrefixes = ['+', '00','010','011','012','013','0137','0138','014','015','016','017','018','019','031','0500','0501','0600','0601','0700','0701','0800','0801','0900','110','112','116116','11','0902','0310','0311','032'];
		var prefix = new RegExp(/^0[0-9]{2,}$/);
		var phoneNumber = new RegExp(/^[0-9]{3,}$/);
		
		while (premiumRatePrefixes.length > 0) {
			if (prefixValue.indexOf(premiumRatePrefixes.pop()) == 0) {
				this.errorMessage.value = 'Keine Auslands-, Mehrwert- oder Handyvorwahlen, bitte.';
				this.displayError();
				return false;
			}
		}
		var valid = (prefix.test(prefixValue) && phoneNumber.test(phoneNumberValue)) ? true : false
		this.errorMessage.value = valid == true ? '' : 'Nummer enthält ungültige Zeichen oder zu kurz (min. 3)';
		this.displayError();
		return valid ? true : false;
	}
	
	/**
	 * onsubmit
	 */
	prefixInput.form.onsubmit = function () {
		var valid = that.validCall();
		/**
		 * hier passierts
		 */
		if (valid) {
			document.getElementById('throbber').style.display = 'block';
			document.getElementById('telStatusError').style.display = 'none';
			document.getElementById('telStatusOK').style.display = 'none';
			document.getElementById('serviceError').style.display = 'none';
			
			var call2callAjax = new httpRequest();
			
			/* init */
			call2callAjax.init( function (response,status) {
				document.getElementById('throbber').style.display = 'none';
				if(status == true) {
					response = eval('('+response+')');
					if (typeof response.call_error == 'undefined') {
						if (response.call_user == false || response.call_customer == false) {
							document.getElementById('telStatusError').style.display = 'block';
						} else {
							document.getElementById('telStatusOK').style.display = 'block';
							var duration = parseInt(document.getElementById('c2cCountdown').firstChild.data);
							var third = Math.floor(duration/3);
							var countdownInterval = window.setInterval( function () {
								if (document.getElementById('c2cCountdown').firstChild.data == 1) window.clearInterval(countdownInterval);
								duration --;
								if (duration == third*2) {
									document.getElementById('c2cCountdown').style.color = 'yellow';
								}
								if (duration == third) {
									document.getElementById('c2cCountdown').style.color = 'red';
								}
								document.getElementById('c2cCountdown').firstChild.data = duration;
							}, 1000);
						}
					} else {
						document.getElementById('serviceError').style.display = 'block';
					}
				} else {
					if (response.ajax_error) {
						document.getElementById('serviceError').style.display = 'block';
					} else {
						document.getElementById('telStatusError').style.display = 'block';
					}
				}
			});
			call2callAjax.responseIsXML=false;
			var kdID = document.Call2CallForm.kdID.value;
			var Ortsnetz1 = document.Call2CallForm.Ortsnetz1.value;
			var Nummer1 = document.Call2CallForm.Nummer1.value;
			
			/* fire */
			call2callAjax.load('ajax.php?action=getCallData&Ortsnetz1='+Ortsnetz1+'&Nummer1='+Nummer1+'&kdID='+kdID);
			
		} else {
			that.errorMessage.value = 'Nummer ist ungültig.'
			that.displayError();
		}
		return false;
	}
	
	/**
	 * displays an errormessage
	 * to flush, flush the errormessage.value and call
	 */
	this.displayError = function () {
		this.errorDisplay.firstChild.data = this.errorMessage.value;
	}
}


/*********************************************
/      routenplaner
/********************************************/
function routeVal()
{
	var plzValue = document.route.szip.value;
	if (document.route.sstreet.value == "Strasse und Nr.") 
	{
		document.route.sstreet.value = '';
	}
	if (document.route.scity.value == "-Ort-") 
	{
		document.route.scity.value = "";
	}
	if (document.route.szip.value == "" || document.route.szip.value == "PLZ" || isNaN(document.route.szip.value) == true) 
	{
		alert ("Bitte geben Sie eine Start PLZ ein.");
		document.route.szip.value == "";
		document.route.szip.focus();
		return false;
	}
	
	else 
	{
		var plz = document.route.szip.value.length;
		if (document.route.szip.value != "" && plz < 5)
		{
			var eingabe = confirm('Die Eingabe einer nicht vollständigen PLZ kann zu unerwarteten Ergebnissen führen.\n\nTrotzdem fortfahren?');
			if (eingabe == true)
			{
				document.route.szip.value = plzValue;
				return true;
			}
			else
			{
				return false;
			}
		}
		return true;
	}
}
/** XMLHttpRequest Wrapper
 */
function httpRequest() {
	var http_request = false;
	this.method = 'GET';
	this.asynchron = true;
	this.send = null; // set send to key-value pairs (urlencoded and escaped? QUERY_STRING)
	this.responseIsXML = true;
	var that = this;
	
	/**
	 * Initialize HTTpRequest
	 * 
	 * @param reference		Function that handles the response
	 */
	this.init = function (handler) {
		if (window.XMLHttpRequest) {
			http_request = new XMLHttpRequest();
			http_request.overrideMimeType ? http_request.overrideMimeType('text/xml') : false; // fuer IE 7
		}
		else if (window.ActiveXObject) { // IE
			http_request = new ActiveXObject('Microsoft.XMLHTTP');
		}
		http_request.onreadystatechange = function () {
			if (http_request.readyState == 4) {
				try {
					if (http_request.status) {
						throw true;
					} else {
						throw false;
					}
				} catch (e) {
					if (e == true) {
						var response = that.responseIsXML == false ? http_request.responseText : http_request.responseXML;
						http_request.status == 200 ? handler(response, true) : handler(response, false);
					} else {
						handler({ajax_error:true}, false);
					}
				}
			}
		}
	}
	
	/**
	 * Fire the Request
	 * 
	 * @param string	url to load with parameters
	 */
	this.load = function(url) {
		if (this.method == 'POST') {
			http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		}
		http_request.open(this.method, url, this.asynchron);
		http_request.send(this.send);
	}
}

