﻿

function initImgMap() {

	$('#map_wrapper ul li').hide();
	$('#mapcontent li').hide();
	
	var $contentLi = $('#mapcontent li');
	
	var activeMapId = '';
	//get current active
	if($('.map_small').length > 0) {
		
		var params = document.location.href.split('?');
		
		if(params[1] != undefined) {
			var h = params[1].split('mapId=');
			h[1] = h[1].replace(/#/g, "");
			activeMapId = h[1];
			
		} else {
			activeMapId = 0;
		}
		
		$('#hover_img' + activeMapId).show();
		$($contentLi[activeMapId]).show();
		
		//click behavior
		$('#map_areas > area').click(function () {
			
			//hide all
			$('#mapcontent li').hide();
			$('#map_wrapper ul li').hide();
			
			//show active hover
			$('#hover_' + $(this).attr('id')).show();
			
			//show active content
			activeMapId = $(this).attr('id').substring(3, $(this).attr('id').length);
			$($contentLi[activeMapId]).show();
		});
	}	
	
	$('#map_areas > area').hover(
		function() {
			
			if(activeMapId != '' && $(this).attr('id') != ('img'+activeMapId)) {
				$('#hover_' + $(this).attr('id')).show();
				
			} else if(activeMapId == '') {
				$('#hover_' + $(this).attr('id')).show();
			}
			
		},
		function() {
		
			if(activeMapId != '' && $(this).attr('id') != ('img'+activeMapId)) {
				$('#hover_' + $(this).attr('id')).hide();
				
			} else if(activeMapId == '') {
				$('#hover_' + $(this).attr('id')).hide();
			}
		}
	);
	
}


function toggleInfo() {
	$('.field_help').hide();
	
	$('#kev_form :input').focus(function() {
		$('.field_help').hide();
		$(this).siblings('.field_help').show();
	});
	
	/*$('#kev_form :radio').change(function() {
		$('.field_help').hide();
		$(this).siblings('.field_help').show();
	});*/
	
	$(document).bind('click', function(e) {
		var $clicked = $(e.target);
		
		// if click somewhere else close everything
		if (! $clicked.siblings().hasClass("field_help")) {
			$('.field_help').hide();
		}
	});
}


/*---- begin Funktionen übernommen ------------------------------------------------------------------------------------------------------------------*/
var CATEGORIES = [["Bilanzgruppe", "02n20000000DTSKAA4"],["Datenmanagement", "02n20000000DWVRAA4"],["KEV", "02n20000000DaSLAA0"],["Lastabwurf", "02n20000000DUy3AAG"],["MKF", "02n20000000CxmNAAS"],["Netznutzung", "02n20000000Cxp2AAC"]]
var RELATIONS = {"02n20000000DTSKAA4": [["Fahrplan Anmeldung", "02n20000000DV8XAAW"],["Informationen/Auskunft", "02n20000000DTSPAA4"],["Techn. Hilfe/Kundendienst", "02n20000000DTSLAA4"],["Verrechnung", "02n20000000DTSMAA4"],["Vertragsmanagement", "02n20000000DTSUAA4"]],"02n20000000CxmNAAS": [["Informationen/Auskunft", "02n20000000CxnzAAC"],["Reklamationen", "02n20000000CxsRAAS"],["Techn. Hilfe/Kundendienst", "02n20000000Cxo0AAC"],["Verrechnung", "02n20000000CxsVAAS"],["Vertragsmanagement", "02n20000000Cxo4AAC"]],"02n20000000DWVRAA4": [["Informationen/Auskunft", "02n20000000DWVSAA4"],["Verrechnung", "02n20000000DWVhAAO"]],"02n20000000DaSLAA0": [["Information/Auskunft", "02n20000000DaSQAA0"]],"02n20000000DUy3AAG": [["Informationen/Auskunft", "02n20000000DUy8AAG"]],"02n20000000Cxp2AAC": [["Informationen/Auskunft", "02n20000000CxqeAAC"],["Verrechnung", "02n20000000Cxs7AAC"]]}
var CATEGORY = '';
var THEME = '';
var TRANSLATIONS = {'selector_category_default': '&minus;&minus; Bitte Kategorie auswählen &minus;&minus;', 'selector_theme_default': '&minus;&minus; Bereich auswählen (optional) &minus;&minus;'};



function initialize() {
    var selector_category = document.getElementById("selector_category");
    var option;
    option = document.createElement('option');
    option.innerHTML = TRANSLATIONS['selector_category_default'];
    option.setAttribute('value', '');
    selector_category.appendChild(option);
    for (var i = 0; i < CATEGORIES.length; i++) {
        option = document.createElement('option');
        option.innerHTML = CATEGORIES[i][0];
        option.setAttribute('value', CATEGORIES[i][1]);
        if (CATEGORY && CATEGORIES[i][1] == CATEGORY) {
            option.setAttribute('selected', 'selected');
            select(CATEGORY);
        }
        selector_category.appendChild(option);
    }
}

function select(value) {
    CATEGORY = value;
    var selector_theme = document.getElementById("selector_theme");
    selector_theme.innerHTML = '';
    var option;
    option = document.createElement('option');
    option.innerHTML = TRANSLATIONS['selector_theme_default'];
    option.setAttribute('value', '');
    selector_theme.appendChild(option);
    var activate = false;
    if (value != "") {
        for (var i = 0; i < RELATIONS[value].length; i++) {
            option = document.createElement('option');
            option.innerHTML = RELATIONS[value][i][0];
            option.setAttribute('value', RELATIONS[value][i][1]);
            if (THEME && RELATIONS[value][i][1] == THEME) {
                option.setAttribute('selected', 'selected');
            }
            selector_theme.appendChild(option);
            activate = true;
        }
    }
    if (activate && value != "") {
        if (selector_theme.getAttribute('disabled')) {
            selector_theme.removeAttribute('disabled');
        }
    } else {
        selector_theme.setAttribute('disabled', 'disabled');
        selector_theme.innerHTML = '';
    }
}

function change(value) {
    // remember theme
    THEME = value;
}
/*---- end Funktionen übernommen ------------------------------------------------------------------------------------------------------------------*/



$(document).ready(function() {
  
	$('#print').click(function() {
		window.print();
	});
	
	if($('#map_wrapper')) {
		initImgMap();
	}
	
	if($('#kev_form')) {
		toggleInfo();
	}
	
 });



    
