var left=0;var maxRegion=413;var sortArray=new Array();var equalDistBoundaries=new Array();var quantileBoundaries=new Array();var classBoundaries=new Array();var min;var max;var selectedDataLeft;var selectedDataRight;var mapCloneRoot=null;var draggingCloneElement=null;var mapRoot=null;var svgMap=null;function fillItems(intStart){var fTypes=document.getElementById('form1').types;var fItems=document.getElementById('form1').items;var a=arItems;var b,c,d,intItem,intType;if(intStart>0){for(b=0;b<a.length;b++){if(a[b][1]==intStart){intType=a[b][0];}}
for(c=0;c<fTypes.length;c++){if(fTypes.options[c].value==intType){fTypes.selectedIndex=c;}}}
if(intType==null){intType=fTypes.options[fTypes.selectedIndex].value}
fItems.options.length=0;for(d=0;d<a.length;d++){if(a[d][0]==intType){fItems.options[fItems.options.length]=new Option(a[d][2],a[d][1]);}
if(a[d][1]==intStart){fItems.selectedIndex=fItems.options.length-1;}}}
function TellMe(evt){var MyDist=evt.target;var MyDistId=MyDist.getAttribute('id');var MyDistID=parseInt(MyDistId);if(draggingElement==null&&MyDistId!='actionIcon'){if(evt.type=="mouseover")
{document.getElementById(MyDistID).setAttributeNS(null,'fill-opacity',.3);var hoverValue=eval('wkr'+MyDistID)[parseInt(selectedData)];var hoverName=eval('wkr'+MyDistID)[0]+"  "+eval('wkr'+MyDistID)[1];document.getElementById('wkr-id').firstChild.data=('Dargestellter Wert: '+hoverValue);document.getElementById('wkr-name').firstChild.data=hoverName;updateTable(MyDistID);window.defaultStatus=hoverName+'   ||   '+document.getElementById('keyHead').firstChild.data+':  '+hoverValue;}
if(evt.type=="mouseout")
{document.getElementById(MyDistID).setAttributeNS(null,'fill-opacity',1);}}}
function statistics(selected){if(Math.abs(selected)!=99){selectedData=selected;var dataCol=Math.floor(selectedData);document.getElementById('option1').selected=true;if(document.getElementById('2maps').checked==true&&document.getElementById('LayoutControl').position[0].checked==true){var clone='c'
selectedDataRight=selectedData}else{var clone=''
selectedDataLeft=selectedData}
var year='';for(i=0;i<arItems.length;i++){if(arItems[i][1]==selectedData){if(arItems[i][0]==1){year=' 2009'};if(arItems[i][0]==2){year=' 2004'};document.getElementById('keyHead').firstChild.data=(arItems[i][2]+year);document.getElementById(425+clone).firstChild.data=(arItems[i][2]+year)}}
for(i=0;i<maxRegion;i++){sortArray[i]=eval('wkr'+(i+1))[dataCol]}
sortArray.sort(function(a,b){return a-b});if(Math.abs(sortArray[0])>75||Math.abs(sortArray[maxRegion-1])>75){min=Math.round(sortArray[0]);max=Math.round(sortArray[maxRegion-1]);}else{min=sortArray[0];max=sortArray[maxRegion-1];}
var quantIncrement=Math.round(maxRegion/5);for(i=0;i<4;i++){quantileBoundaries[i]=sortArray[(i+1)*quantIncrement];}
var increment=(max-min)/5;for(i=0;i<4;i++){if((max-min)<10){equalDistBoundaries[i]=Math.round((min+(i+1)*increment)*10)/10}else{equalDistBoundaries[i]=Math.round(min+(i+1)*increment)}}
var myY1=120*max/(max-min);for(i=0;i<(maxRegion);i++){if(min<0){var myY2=myY1-(sortArray[i]*120/(max-min));document.getElementById('hb'+i).setAttribute('y1',myY1+10);document.getElementById('hb'+i).setAttribute('y2',myY2+10);}else{document.getElementById('hb'+i).setAttribute('y1',130);document.getElementById('hb'+i).setAttribute('y2',130-(sortArray[i]/max*120));}}
document.getElementById('maxTick').firstChild.data=max;if(min<0){tickMin=min}else{tickMin=0}
document.getElementById('minTick').firstChild.data=tickMin;colorMap('default')}
if(selected==-99){window.open('http://www.bundeswahlleiter.de/de/europawahlen/EU_BUND_09/strukturdaten/');fillItems(1)}}
function colorMap(classMethod){if(classMethod=='default'){for(i=0;i<arItems.length;i++){if(arItems[i][1]==selectedData){for(n=0;n<4;n++){classBoundaries[n]=arItems[i][3+n]}}}}
if(classMethod=='quantiles'){for(n=0;n<4;n++){classBoundaries[n]=quantileBoundaries[n]}}
if(classMethod=='equaldistance'){for(n=0;n<4;n++){classBoundaries[n]=equalDistBoundaries[n]}}
var mapVar=Math.floor(selectedData);var colorNr=Math.round((selectedData-mapVar)*10);if(document.getElementById('2maps').checked==true&&document.getElementById('LayoutControl').position[0].checked==true){var clone='c'}else{var clone=''}
for(i=0;i<5;i++){document.getElementById('color'+i).style.backgroundColor=colorScheme[colorNr][i+1];var key=document.getElementById((i+414)+clone);key.setAttributeNS(null,'fill',colorScheme[colorNr][i+1]);}
var frequencies=[0,0,0,0,0];for(i=1;i<(maxRegion+1);i++){var mapPerc=eval('wkr'+i)[mapVar];if(mapPerc<classBoundaries[0]){document.getElementById(i+clone).setAttribute('fill',colorScheme[colorNr][1]);frequencies[0]+=1;}
if(mapPerc>=classBoundaries[0]&&mapPerc<classBoundaries[1]){document.getElementById(i+clone).setAttribute('fill',colorScheme[colorNr][2]);frequencies[1]+=1;}
if(mapPerc>=classBoundaries[1]&&mapPerc<classBoundaries[2]){document.getElementById(i+clone).setAttribute('fill',colorScheme[colorNr][3]);frequencies[2]+=1;}
if(mapPerc>=classBoundaries[2]&&mapPerc<classBoundaries[3]){document.getElementById(i+clone).setAttribute('fill',colorScheme[colorNr][4]);frequencies[3]+=1;}
if(mapPerc>=classBoundaries[3]){document.getElementById(i+clone).setAttribute('fill',colorScheme[colorNr][5]);frequencies[4]+=1;}}
for(i=0;i<5;i++){var tmpFreq='freq'+i;document.getElementById(tmpFreq).firstChild.data=eval(frequencies)[i];}
for(i=0;i<4;i++){document.getElementById('percClass'+i).firstChild.data=classBoundaries[i];document.getElementById('limit'+(i+1)+'a').firstChild.data=classBoundaries[i];document.getElementById((i+420)+clone).firstChild.data=classBoundaries[i];}
document.getElementById('max').firstChild.data=max;document.getElementById('min').firstChild.data=min;document.getElementById(419+clone).firstChild.data=min;document.getElementById(424+clone).firstChild.data=max;for(i=0;i<(maxRegion);i++){if(sortArray[i]<classBoundaries[0]){document.getElementById('hb'+i).setAttribute('stroke',colorScheme[colorNr][1]);}
if(sortArray[i]>=classBoundaries[0]&&sortArray[i]<classBoundaries[1]){document.getElementById('hb'+i).setAttribute('stroke',colorScheme[colorNr][2]);}
if(sortArray[i]>=classBoundaries[1]&&sortArray[i]<classBoundaries[2]){document.getElementById('hb'+i).setAttribute('stroke',colorScheme[colorNr][3]);}
if(sortArray[i]>=classBoundaries[2]&&sortArray[i]<classBoundaries[3]){document.getElementById('hb'+i).setAttribute('stroke',colorScheme[colorNr][4]);}
if(sortArray[i]>=classBoundaries[3]){document.getElementById('hb'+i).setAttribute('stroke',colorScheme[colorNr][5]);}}}
function updateTable(wkr){var district='wkr'+wkr;if(Math.floor(eval(district)[0]/1000)==9){document.getElementById('CDUkopf').firstChild.data='CSU';}else{document.getElementById('CDUkopf').firstChild.data='CDU';}
document.getElementById('cduAKTproz').firstChild.data=eval(district)[4]+'%';document.getElementById('spdAKTproz').firstChild.data=eval(district)[6]+'%';document.getElementById('grueneAKTproz').firstChild.data=eval(district)[8]+'%';document.getElementById('linkeAKTproz').firstChild.data=eval(district)[10]+'%';document.getElementById('fdpAKTproz').firstChild.data=eval(district)[12]+'%';document.getElementById('cduVORPproz').firstChild.data=eval(district)[5]+'%';document.getElementById('spdVORPproz').firstChild.data=eval(district)[7]+'%';document.getElementById('grueneVORPproz').firstChild.data=eval(district)[9]+'%';document.getElementById('linkeVORPproz').firstChild.data=eval(district)[11]+'%';document.getElementById('fdpVORPproz').firstChild.data=eval(district)[13]+'%';}
function newClassInput(){var l1=document.forms['classification'].elements['limit1'].value;var l2=document.forms['classification'].elements['limit2'].value;var l3=document.forms['classification'].elements['limit3'].value;var l4=document.forms['classification'].elements['limit4'].value;classBoundaries=[l1,l2,l3,l4];for(i=0;i<4;i++){classBoundaries[i]=classBoundaries[i].replace(/,/,'.');classBoundaries[i]=classBoundaries[i].replace(/[^0-9\-.]/g,'');}
colorMap('userinput')
document.getElementById('option1').selected=true;}
function buildHistogram(){var histogramLayer=document.getElementById('histogramlines');for(i=0;i<(maxRegion);i++){var newLine=document.createElementNS('http://www.w3.org/2000/svg',"line");newLine.setAttributeNS(null,'id','hb'+i);newLine.setAttributeNS(null,'x1',i+6);newLine.setAttributeNS(null,'y1',100);newLine.setAttributeNS(null,'x2',i+6);newLine.setAttributeNS(null,'y2',50);newLine.setAttributeNS(null,'stroke-width',1.3);newLine.setAttributeNS(null,'stroke','green');histogramLayer.appendChild(newLine);}}
function resultPage(evt){if(draggingElement==null){var MyDist=evt.target;var MyDistID=MyDist.getAttribute('id');if(evt.altKey==1){var myAGS=eval('wkr'+MyDistID)[0];if(myAGS<10000){var myAGSn='0'+myAGS;var myL='0'+Math.floor(myAGS/1000);}else{var myAGSn=myAGS
var myL=Math.floor(myAGS/1000);}
var baseURL='http://www.bundeswahlleiter.de/de/europawahlen/EU_BUND_09/ergebnisse/kreisergebnisse/l';var myURL=baseURL+myL+'/k'+myAGSn+'/';window.open(myURL);}}}
var draggingElement=null;var nMouseOffsetX=0;var nMouseOffsetY=0;function mouseDown(evt){var target=evt.currentTarget;draggingElement=target;if(target){var p=mapRoot.createSVGPoint();p.x=evt.clientX;p.y=evt.clientY;var m=mapRoot.getScreenCTM();p=p.matrixTransform(m.inverse());nMouseOffsetX=p.x-(target.getAttributeNS(null,"dragx"));nMouseOffsetY=p.y-(target.getAttributeNS(null,"dragy"));}}
function mouseMove(evt){var m=mapRoot.getScreenCTM();var p=mapRoot.createSVGPoint();p.x=evt.clientX;p.y=evt.clientY;p=p.matrixTransform(m.inverse());p.x-=nMouseOffsetX;p.y-=nMouseOffsetY;if(draggingElement){draggingElement.setAttributeNS(null,"dragx",p.x);draggingElement.setAttributeNS(null,"dragy",p.y);draggingElement.setAttributeNS(null,"transform","translate("+p.x+","+p.y+")");if(draggingCloneElement){draggingCloneElement.setAttributeNS(null,"transform","translate("+p.x+","+p.y+")");}
document.getElementById('hidden').firstChild.data=parseInt(p.x);}}
function mouseUp(evt){draggingElement=null;nMouseOffsetX=0;nMouseOffsetY=0;}
function toggleHelp(){var helpDiv=document.getElementById('mapHelp');if(helpDiv.style.display=='inline'){helpDiv.style.display='none'}else{helpDiv.style.display='inline'}}
function resetZoom(){svgMap.setAttributeNS(null,"transform","translate( '0, 0')");svgMap.setAttributeNS(null,'dragx',0);svgMap.setAttributeNS(null,'dragy',0);mapRoot.setAttributeNS(null,'viewBox',"-340431 -475036 672623 911401");if(mapCloneRoot){mapCloneRoot.setAttributeNS(null,'viewBox',"-340431 -475036 672623 911401")}
document.getElementById('mapHelp').style.display='none'}
function hookEvent(element,eventName,callback)
{if(typeof(element)=="string")
element=document.getElementById(element);if(element==null)
return;if(element.addEventListener)
{if(eventName=='mousewheel')
{element.addEventListener('DOMMouseScroll',callback,false);}
element.addEventListener(eventName,callback,false);}
else if(element.attachEvent)
element.attachEvent("on"+eventName,callback);}
function MouseWheel(e)
{e=e?e:window.event;var wheelData=e.detail?e.detail*-1:e.wheelDelta/120;scrollZoom(wheelData)}
function scrollZoom(wheeldata){if(wheeldata>0){var scale=0.7}else{var scale=1.3};var myViewBox=mapRoot.getAttributeNS(null,'viewBox');var viewboxes=myViewBox.split(' ');var ulXcorner=parseFloat(viewboxes[0]);var ulYcorner=parseFloat(viewboxes[1]);var myWidth=parseFloat(viewboxes[2]);var myHight=parseFloat(viewboxes[3]);var xCenter=ulXcorner+myWidth/2;var yCenter=ulYcorner+myHight/2;myWidth=myWidth/scale;myHight=myHight/scale;if(myWidth>15000&&myWidth<1000000){ulXcorner=xCenter-myWidth/2;ulYcorner=yCenter-myHight/2;myViewBox=ulXcorner+' '+ulYcorner+' '+myWidth+' '+myHight;mapRoot.setAttributeNS(null,'viewBox',myViewBox)
if(mapCloneRoot){mapCloneRoot.setAttributeNS(null,'viewBox',myViewBox)}}}
function cloneMap(){mapRoot.setAttributeNS(null,'viewBox',"-377799 -525669 747359 1012668");selectedDataRight=selectedData;selectedDataLeft=selectedData;var body=document.getElementById("atlasroot");var mapContainer=document.getElementById('map');mapContainer.setAttributeNS(null,"id","mapLeft");var cloneElement=mapContainer.cloneNode(true);cloneElement.setAttributeNS(null,"id","mapRight");body.insertBefore(cloneElement,mapContainer);for(i=1;i<426;i++){var changeID=document.getElementById(i);changeID.setAttributeNS(null,"id",i+"c");}
var changeCap=document.getElementById('capitals');changeCap.setAttributeNS(null,"id","capitalsc");var changeLB=document.getElementById('laenderboundaries');changeLB.setAttributeNS(null,"id","laenderboundariesc");var rename=document.getElementById('svgroot');rename.setAttributeNS(null,"id","svgCloneRoot")
mapCloneRoot=document.getElementById("svgCloneRoot");var name=document.getElementById('Wahlkreiskarte');name.setAttributeNS(null,"id","WahlkreiskarteClone")
draggingCloneElement=document.getElementById('WahlkreiskarteClone');var radiocontrols=document.getElementById('LayoutControl');radiocontrols.style.display='inline';radiocontrols.position[0].checked=true;moveLeft()}
function moveLeft(){document.getElementById('controlsContainer').style.left='0.5%';left=1;}
function moveRight(){document.getElementById('controlsContainer').style.left='59.5%';left=0;}
function layoutControls(position){if(position=='right'){moveRight()}
if(position=='left'){moveLeft()}
if(position=='hide'){document.getElementById('controlsContainer').style.display='none';document.getElementById('actionIconG').style.display='inline';if(left==1){document.getElementById('LayoutControl').position[0].checked=true;}else{document.getElementById('LayoutControl').position[1].checked=true;}}}
function unhideControls(){document.getElementById('controlsContainer').style.display='inline';document.getElementById('actionIconG').style.display='none';}
function uncloneMap(){mapRoot.setAttributeNS(null,'viewBox',"-340431 -475036 672623 911401");var body=document.getElementById("atlasroot");var mapContainer=document.getElementById('mapRight');body.removeChild(mapContainer);var origMap=document.getElementById('mapLeft');origMap.setAttributeNS(null,"id","map");var radiocontrols=document.getElementById('LayoutControl');radiocontrols.style.display='none';document.getElementById('controlsContainer').style.left='59.5%';statistics(selectedDataLeft);fillItems(0)}
function load(){if(top.location!=location){top.location.href=document.location.href;}
mapRoot=document.getElementById("svgroot");svgMap=document.getElementById('Wahlkreiskarte');hookEvent('Wahlkreiskarte','mousewheel',MouseWheel);for(i=1;i<(maxRegion+1);i++){var ags=eval("wkr"+i)[0];var tmpPath=document.getElementById(ags);tmpPath.setAttributeNS(null,"id",i);}
buildHistogram();var selectedData=2.0
fillItems(selectedData);statistics(selectedData)}