$(document).ready(function(){

	//globale function
	
		function isNWModus()
		{
			var nw = false;
			if($dataObject.pmode == "PMODE_PREV" || $dataObject.pmode == "PMODE_PW" || $dataObject.pmode == "PMODE_SOLOPW")
			{
				nw = true;
			}	
			return nw;
		}

	//Probefahrt____________________________
	//_______________________________________
	
	
	//Elemente ausblenden
//	$("#programmtext").css("display", "none");
//	$("#noprogram").css("display", "none"); //bild das angezeigt wird, wenn kein händler vorhanden
//	$("#btn_vereinbaren").css("display", "none");
//	$("#form_probe").css("display", "none");
	$("#loader").css("display", "none");
	$("#haendlerliste").css("display", "none");

	
	//Teilnahmebedingungen verstecken
	$("#teilnahmebed").css("display","none");
	
	//Map highlighten
	/*$(function() {
		$('.imagemap').maphilight();
	 });*/
	
	//händlerprogramm anzeigen
	function handlerClicked(id){	
		
		showHaendlerInfo(id);
		
	}
	
	function showHaendlerInfo(id)
	{
		for(var i=0; i < $akt_haendler.length; i++)
		{
			if($akt_haendler[i][0] == id)
			{
				$("#haendler_daten").html($akt_haendler[i][1]);

			}
		}	

	}
	
	//Map Elemente klicken
	$("#bundesland").text("");
	
	$("#map_ooe").click(function(e){	
		loadHaendler("Oberösterreich",e.target.id);	
	});
	$("#map_sbg").click(function(e){	
		loadHaendler("Salzburg",e.target.id);	
	});
	$("#map_ktn").click(function(e){	
		loadHaendler("Kärnten",e.target.id);	
	});
	$("#map_vbg").click(function(e){	
		loadHaendler("Vorarlberg",e.target.id);	
	});
	$("#map_w").click(function(e){	
		loadHaendler("Wien",e.target.id);	
	});
	$("#map_noe").click(function(e){	
		loadHaendler("Niederösterreich",e.target.id);	
	});
	$("#map_stm").click(function(e){	
		loadHaendler("Steiermark",e.target.id);	
	});
	$("#map_bgl").click(function(e){	
		loadHaendler("Burgenland",e.target.id);	
	});
	$("#map_tir").click(function(e){	
		loadHaendler("Tirol",e.target.id);	
	});
	
	function loadHaendler(name,id)
	{	
		//ausgewähltes bundesland ausgeben
		$("#bundesland").html("<h2>"+name+"</h2>");
//		$("#haendler").value = "";
//		$("#haendler_daten").html("");
//		$("#noprogram").css("display", "none");
//		$("#programmtext").css("display", "none");
//		$("#programmtext_empty").css("display", "block");
//		$("#btn_vereinbaren").css("display", "none");
		$("#haendlerliste").css("display", "block");
		
		
		$akt_haendler = new Array();
							  
		
		//loader einblenden
		$("#loader").toggle();
		//reqeust senden
		$.ajax({
			type: "GET",
			url: "webservices/tom_proxy_xml.php?mode=list-org_entity&id="+$customer_id+"&hash="+$customer_hash+"&customer_id="+$customer_id+"&region="+encodeURIComponent(name),
			dataType: "xml",
			success: function(xml) {
				//loader ausblenden
				$("#loader").toggle();
				haendler_html = '<option value="">Bitte wählen...</option>';
				$(xml).find('result').each(function(){
					$(xml).find('org_entity').each(function(){
						
						var haendler_id = $(this).find('customer_number').text();
						var tom_haendler_id =  $(this).find('org_entity_id').text();
						var des = $(this).find('description').text();
						var zip = $(this).find('zip').text();
						var street = $(this).find('street').text();
						var city = $(this).find('city').text();
						var email = $(this).find('email').text();
						
						haendler_html += "<option id='haendler_opt_"+haendler_id+"' value='"+tom_haendler_id+"'>"+des+" ("+zip+" "+city+")</option>";
					
						var temp = new Array(haendler_id,"<span class='blue'><b>"+ des+"</b></span><br />"+street+", " +zip+ " " +city+"<br /><a href='mailto:"+email+"'>"+email+"</a>");
						$akt_haendler.push(temp);
						
					});
				});
				$("#haendler").html(haendler_html);
				$("#haendler").attr('selectedIndex', 0);
				$.uniform.update(); 
				$("#haendler_daten").html("");

				
				//händleroptionen klickbar machen
				$('#haendler').change(function(){
					 
					var optionId = $(this).find('option:selected').attr('id');
					
					
					 if(typeof optionId == "undefined")
					 {
						$("#haendler_daten").html(""); 
					 }
					 else
					 {
						  handlerClicked(optionId.split("haendler_opt_")[1]);
					 }
					 
					 $.uniform.update(); 
				});
				
				$('#haendler').hover(function(){
					 $.uniform.update(); 
				});
				$('#haendler').mouseover(function(){
					 $.uniform.update(); 
				});
				$('#haendler').mouseout(function(){
					 //$.uniform.update();
				});
				$('#haendler').click(function(){
					 $.uniform.update(); 
				});
				$('#haendler').hover(function(){
					 $.uniform.update(); 
				});


				
			}
		});

	}
	
	//probefahrtsformular anzeigen
	$("#btn_vereinbaren").click(function(e){
		$("#form_probe").css("display", "block");
		$("#program").css("display", "none");
	});
	
	//teilnahmebedingungen probefahrt anzeigen
	$("#tn_btn").click(function(e){
		
		$("#teilnahmebed").toggle();
		$.uniform.update(); 

		
		if(isNWModus())
		{
			$("#tn_text_pp_zusatz_pf").html($tn_premiumpromotions);

		}
		else
		{
			$("#tn_text_pp_zusatz_pf").html("");

		}
	});
	

	
	//agb zurück button
	$("#btn_zurueck").click(function(e){

		$("#teilnahmebed").toggle();

	});
	
	$("#probefahrt").change(function(e){
		
		$("#feedback").css("display", "none");
		
		if($(this).attr('checked') == "checked")
		{
			$("#infomaterial").css("display","none"); 	
		}
		else
		{
			$("#infomaterial").css("display","block"); 	
		}
	});


});
