
function showDiv(id){
	document.getElementById(id).style.visibility = "visible";	
}

function hideDiv(id){
	document.getElementById(id).style.visibility = "hidden";	
}


function step1Verbrauch(verbrauch){
	if(verbrauch == "indiv"){
		showDiv('indivVerb');
	}
	else{
		hideDiv('indivVerb');
	}	
}

var blzOK;
var blzFocus;

var plzOK;
var plzFocus;
var plz;

var evuFocus;
var evu;

function createXMLHttpRequest() {
	var ua;
    
	if(window.XMLHttpRequest) {
    	try {
    		ua = new XMLHttpRequest(); 
    	} 
    	catch(e) {
    		ua = false;
   		}
    } else if(window.ActiveXObject) {
    	try {
			ua = new ActiveXObject("Microsoft.XMLHTTP");
    	} 
  		catch(e) {
    		ua = false;
    	}
   	}
    	return ua;
}

var req = createXMLHttpRequest();

function sendRequest(check) {
	req.open('get', 'db_query.php?step=' + step + '&check=' + check);
	req.onreadystatechange = handleResponse;
	req.send(null);
}

function handleResponse() {
  	
	if(req.readyState == 4) {
		var response = req.responseText;
		
		if(step == "blz"){

			if(response.indexOf("error") == -1) {
				document.getElementById("blzOK").value = 1;
				document.getElementById("bank").innerHTML = response;
				document.getElementById("bank").style.color = "black";
			}else{
				document.getElementById("blzOK").value = 0;
				document.getElementById("blz").style.backgroundColor = "red";
				document.getElementById("bank").firstChild.data = "BLZ nicht vorhanden";
				document.getElementById("bank").style.color = "red";
			}
		}
		
		if(step == "plz"){

			//if(response.indexOf("error") == -1) {
			if (response != '') {
				document.getElementById("arrow").innerHTML = response;
				document.getElementById("arrow").style.color = "white";
				//document.getElementById("button-slide").innerHTML = "<a href='javascript:document.forms.calForm.submit()' tabindex='3'>JETZT VERGLEICHEN</a>";
				$("#JSButton").css("display", "inline");
				$("#noButton").css("display", "none");
			}else{
				document.getElementById("arrow").firstChild.data = "Ort nicht vorhanden";
				document.getElementById("arrow").style.color = "red";
			}
		}

		if(step == "plz2"){

			if(response.indexOf("error") == -1) {
				
				document.getElementById("arrow").innerHTML = response;
				document.getElementById("arrow").style.color = "black";
			}else{
				document.getElementById("arrow").firstChild.data = "Ort nicht vorhanden";
				document.getElementById("arrow").style.color = "red";
			}
		}
		
		if(step == "plz3"){

			if(response.indexOf("error") == -1) {
				document.getElementById("ort").innerHTML = response;
				document.getElementById("ort").style.color = "black";
			}else{
				document.getElementById("ort").firstChild.data = "Ort nicht vorhanden";
				document.getElementById("ort").style.color = "red";
			}
		}

		if(step == "evu_edit"){
			if(response.indexOf("error") == -1) {
				
				document.getElementById("anbieter_auswahl").innerHTML = response;
				document.getElementById("anbieter_auswahl").style.display = "block";
			}
		}
		
		if(step == "auswahl_produkte") {
			if(response.indexOf("error") == -1){
				document.getElementById("produkt_auswahl").innerHTML = response;
				document.getElementById("produkt_auswahl").style.display = "block";
			}
		}
		if(step == "auswahl_produkte_layer") {
			if(response.indexOf("error") == -1){
				document.getElementById("produkt_auswahl").innerHTML = response;
				document.getElementById("produkt_auswahl").style.display = "block";
			}
		}
		
	}
}

function stepAuswahl(evu_nr){
//	var Nr = evu_nr+"";
//	var splitz = Nr.split('.');
//	if(splitz[1].length < 5){
//		evu_nr = splitz[0]+"."+splitz[1]+"0";
//	}
	step="auswahl_produkte";
	sendRequest(evu_nr);
}

function stepAuswahlLayer(evu_nr){
	var Nr = evu_nr+"";
	var splitz = Nr.split('.');
	if(splitz[1].length < 5){
		evu_nr = splitz[0]+"."+splitz[1]+"0";
	}
	step="auswahl_produkte_layer";
	sendRequest(evu_nr);
}

function step3BLZ(blz) {	
	if(blzFocus == 1) {
		if(blz.length == 8) {
			step = "blz";
			sendRequest(blz);
		}
	}
}



function step3EVU(evu_edit, plz) {	
	if(evuFocus == 1) {
		if(evu_edit.length > 2) {
			step = "evu_edit";
			sendRequest(evu_edit + "&plz="+plz);
		}
	}
}

function closeEvuList(){
	document.getElementById("anbieter_auswahl").style.display="none";
}


function addEvu(evu) {
	document.getElementById("anbieterdiv").value = evu;
	document.getElementById("anbieter_auswahl").style.display="none";	
}


function getOrt(plz) {
	if(plzFocus == 1) {
		if(plz.length == 5) {
			step = "plz";
			sendRequest(plz);
		}
	}
}

function getOrt2(plz) {
	if(plzFocus == 1) {
		if(plz.length == 5) {
			step = "plz2";
			sendRequest(plz);
		}
	}
}

function getOrt3(plz) {
	if(plzFocus == 1) {
		if(plz.length == 5) {
			step = "plz3";
			sendRequest(plz);
		}
	}
}

function changeText(v)
{
	if(v == "tv") 
	{
		document.email.text.value = "Hallo,\n\nich habe gerade im Internet zur ESD AG gewechselt.\n\nDas ging ganz einfach und ab sofort spare ich jeden Monat viel Geld. Nat�rlich wollte ich auch Dich �ber diese M�glichkeit informieren.\n\nKlick doch einfach auf den Link unten und schau Dir das mal an.\n\nLink: http://www.stromwechsel.de/\n\nLiebe Gr��e";
		if(document.all) signs = (2000-283);
		else signs = (2000-275);
		document.getElementById("signs").firstChild.data = signs;
	}
	else 
	{
		document.email.text.value = "";
		signs = 2000;
		document.getElementById("signs").firstChild.data = signs;
	}
}


function newWindowAGB(esd){
	var pdf;
	pdf = "agb_"+esd+".pdf";
	F1 = window.open('/'+pdf,'AGB','toolbar=no,width=768,height=500,resizable=no,top=40,scrollbars=yes');
}

function newWindowPrivacy(){
	F1 = window.open('/privacy','Privacy','toolbar=no,width=768,height=500,resizable=no,top=40,scrollbars=yes');
}

function newWindowKonditionen(){
	F1 = window.open('/konditionen','Konditionen','toolbar=no,width=768,height=500,resizable=no,top=40,scrollbars=yes');
}

function newWindowEnergiemix(){
	F1 = window.open('/tarifmix','Tarifmix','toolbar=no,width=768,height=500,resizable=no,top=40,scrollbars=yes');
} 



function showEmpfehlungMail(){
	document.getElementById("maildiv").style.visibility = "visible";
}

function showChangeVerbrauch(){
	document.getElementById("verbrauchdiv").style.visibility = "visible";
}

function showChangeAnbieter(){
	var el = $("#anbieterdiv"); 
	el.attr("readonly", "");
	el.css("color", "#000");
}

function showChangeAnbieterLayer(){
	var el = $("#anbieterdiv2");
	el.css("display","block");
	el.attr("readonly", "");
	el.css("color", "#000");
}

function changeVR(id, verbrauch, btn, img){
	document.getElementById(id).value = verbrauch;	
	if(!img.match(/_active/)){
		var t = img.split("img");
		var l = (t.length-1);
		var tmp = t[l].split(".");
		nimg = 'img'+tmp[0]+'_active.'+tmp[1];
		document.getElementById(btn).src = nimg;
		this.changeBtn(btn);
	}	
}

function changeBtn(btn){
	for(var i=1; i<=4; i++){
		btn_id = 'btn'+i;
		btnsrc = document.getElementById(btn_id).src;
		if(btn != btn_id && btnsrc.match(/_active/)){
			var t = btnsrc.split("img");
			var l = (t.length-1);
			var tmp = t[l].split("_active");
			nimg = 'img'+tmp[0]+''+tmp[1];
			document.getElementById(btn_id).src = nimg;
		}
	}
}

$(document).ready(function(){
	$(":radio").click( function() {
		if ($("#radio1:checked").val() == "1") {
			$("ul#call").show();
		} else {
			$("ul#call").hide();
		}
	});
});
