var map = null;
var geocoder = null;
var markers = new Array();
var marker_texts = new Array();
var markerId = new Array();
  
function loadGMapAnfahrt() {
  map = new GMap2(document.getElementById("mapAnfahrt"));
  map.setCenter(new GLatLng(52.380714, 8.6257), 14);
  map.addControl(new GSmallMapControl()); 
  var infoText = "<div style='height: 220px;'><b>Harting KGaA</b><br /><img src='/images/logoGoogleMapPopup.jpg' width='200' /><br /><br />Marienwerderstraße 3<br />D - 32339 Espelkamp<br /><br />Telefon: +49 5772 47-0<br />Telefax: +49 5772 47-400<br /><a href='mailto:info@HARTING.com' class='email'>E-Mail senden</a><br class='all' /><br />";
  infoText += '<a href="http://maps.google.de/maps?f=d&source=s_d&saddr=&daddr=Marienwerder+Stra%C3%9Fe+3,+32339+Espelkamp&hl=de&geocode=&mra=ls&sll=52.382175,9.756846&sspn=0.009784,0.01929&ie=UTF8&ll=52.380871,8.625168&spn=0.019568,0.038581&z=15" class="extern2" target="_blank" title="zum Routenplaner">zum Routenplaner</a></div>';
  addMarker(map,52.380714,8.6257,"",infoText,"HARTING Holding");
  

}

function centerMap() {
  map.panTo(new GLatLng(52.388828,8.628345));
}

function addMarker(map,lat,lng,address,info_text,titlename) {
  var iconBase = new GIcon();
  iconBase.image = "/images/pin.gif";
  iconBase.iconSize = new GSize(47,70);
  iconBase.iconAnchor = new GPoint(10,70);
  iconBase.infoWindowAnchor = new GPoint(23,70);
	//Koordinaten oder Adresse?
  if (lat!="" && lng!="") {
    point = new GLatLng(lat,lng);
		marker = new GMarker(point,{icon:iconBase,title:titlename});
		if (info_text != "") {
			GEvent.addListener(marker, "click", function() {
				marker.openInfoWindowHtml(info_text);
				window.setTimeout("centerMap()",100);
     	});
    }

    map.addOverlay(marker);
    markers[markers.length]=marker;
    marker_texts[marker_texts.length] = info_text;
  } else if (address!="") {
    geocoder.getLatLng(
      address,
      function(point) {
        if (!point) {
        	show = false;
        } else {
          marker = new GMarker(point,{icon:newIconBase,title:short});
          if (show) {
      			if (info_text != "") {
      				GEvent.addListener(marker, "click", function() {
      					marker.openInfoWindowHtml(info_text);
      					pointLng = point.lng();
      					pointLat = point.lat() + 0.1;
    					  map.setCenter(new GLatLng(pointLat,pointLng), map.getZoom());
        	  	});
      			}
            map.addOverlay(marker);
            markers[markers.length]=marker;
            marker_texts[marker_texts.length] = info_text;
      	  }
  			  map.setCenter(point, map.getZoom());
        }
      }
    );
  }
}

function imgChange(bild,source) {
	eval('document.getElementsByName("' + bild + '")[0].src = ' + source + '.src;');
}

function imglo(bild) {
	eval('document.getElementsByName("' + bild + '")[0].src = ' + bild + 'lo.src;');
}

function imghi(bild) {
	eval('document.getElementsByName("' + bild + '")[0].src = ' + bild + 'hi.src;');
}

function goTo(ziel) {
	if (ziel != "#" && ziel != "") {
		window.location.href = ziel;
	}
}

function randunten() {
	if (screen.width > 1024) {
		document.getElementById("portalcontentmain").style.marginBottom = "80px";
	}
}

var menuopen = "";
var aktivmenu = "";
var aktiv="";

function aufklappen(ebene) {
	window.clearTimeout(aktiv);
	if (menuopen != "") zuklappen(menuopen);
	menuopen = ebene;
	if (document.getElementById(ebene)) {
		document.getElementById(ebene).style.visibility = "visible";
		if (document.getElementById(ebene.substr(3,ebene.length-3)).className != "mainactive") {
			document.getElementById(ebene.substr(3,ebene.length-3)).className = "mainhigh";
		}
	}
}

function checkMenu(ebene) {
	aktiv = window.setTimeout("zuklappen('"+ebene+"')",1000);
}

function zuklappen(ebene) {
	if (document.getElementById(ebene.substr(3,ebene.length-3)).className != "mainactive") {
		document.getElementById(ebene.substr(3,ebene.length-3)).className = "main";
	}
	if (document.getElementById(ebene)) {
		document.getElementById(ebene).style.visibility = "hidden";
	}
}

function popup(page, width, height) {
    if (width=='') width=570;
    if (height=='') height=685;
	zoomwindow = window.open(page, "Zoom", "width="+width+",height="+height+",left=0,top=0,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no");
}

function zoom(page, width, height) {
    page = page + "&width="+width+"&height"+height;
    if (width=='') width=570;
    if (height=='') height=685;
    //if (zoomwindow) zoomwindow.close();    
	  zoomwindow = window.open(page, "Zoom", "width="+width+",height="+height+",left=0,top=0,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no");
}

var flashVersion = 0;
function getFlashVersion() {
	var maxFlashVersion = 25;
	var minFlashVersion = 6;
	var agent = navigator.userAgent.toLowerCase(); 

	// NS3 needs flashVersion to be a local variable
	if (((agent.indexOf("mozilla/3") != -1) && (agent.indexOf("msie") == -1)) || ((agent.indexOf("msie") != -1) && (agent.indexOf("mac") != -1))) {
		flashVersion = 0;
		return flashVersion;
	}
   
	// NS3+, Opera3+, IE5+ Mac (support plugin array):  check for Flash plugin in plugin array
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		var flashPlugin = navigator.plugins['Shockwave Flash'];
		if (typeof flashPlugin == 'object') { 
			for (var i = maxFlashVersion; i >= minFlashVersion; i--) {
				if (flashPlugin.description.indexOf(i + '.') != -1) {
					flashVersion = i;
					break;
				}
			}
		}
	}
	// IE4+ Win32:  attempt to create an ActiveX object using VBScript
	else if ((agent.indexOf("msie") != -1) && (parseInt(navigator.appVersion) >= 4) && (agent.indexOf("win") != -1) && (agent.indexOf("16bit") == -1)) {
		var doc = '<scr' + 'ipt language="VBScript"\> \n';
		doc += 'On Error Resume Next \n';
		doc += 'Dim obFlash \n';
		doc += 'For i = '+maxFlashVersion+' To '+minFlashVersion+' Step -1 \n';
		doc += '   Set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash." & i) \n';
		doc += '   If IsObject(obFlash) Then \n';
		doc += '      flashVersion = i \n';
		doc += '      Exit For \n';
		doc += '   End If \n';
		doc += 'Next \n';
		doc += '</scr' + 'ipt\> \n';
		document.write(doc);
	} else flashVersion = -1;
	return flashVersion;
}

function insertFlashObject(id,src,width,height,name,bgcolor,imgsrc) {
	if (bgcolor.length == 0) bgcolor = '#ffffff';
	var canDo=0;
	if (getFlashVersion() >= 6) canDo = 1;
	if (canDo!=1) {
		if (imgsrc && imgsrc.length > 0) {
			document.write('<img src="'+imgsrc+'" border="0" alt="" />');
		}
	} else {
		document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+width+'" height="'+height+'" align=""');
		if (id.length > 0) document.write(' id="'+id+'"');
		if (name.length > 0) document.write(' name="'+name+'"');
		document.write('>\n');
		document.write('<param name="movie" value="'+src+'" />');
		document.write('<param name="menu" value="false" />');
		document.write('<param name="quality" value="high" />');
		document.write('<param name="scale" value="noborder" />');
		document.write('<param name="wmode" value="transparent" />');
		document.write('<param name="bgcolor" value="'+bgcolor+'" />');
		if ((id.length == 0) && (name.length > 0)) id = name;
		document.write('<embed src="'+src+'" menu="false" quality="high" scale="noborder" bgcolor="'+bgcolor+'" width="'+width+'" height="'+height+'" name="'+id+'" align="" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="transparent"></embed>');
		document.writeln('</object>');
	}
}

function showDiv(container) {
	document.getElementById(container+"off").style.display = "none";
	document.getElementById(container).style.display = "block";
}

function hideDiv(container) {
	document.getElementById(container).style.display = "none";
	document.getElementById(container+"off").style.display = "block";
}

function searchNavi(ul, group, query, text, classname, spanId) {
   
  var span = document.createElement('span');
  span.id = spanId;
  
  var link = document.createElement('a');
  link.href = '?make=find&localsearch=1&group='+group+'&query='+query;
  link.className = classname;  
  link.appendChild(document.createTextNode(text));
  link.appendChild(span);
  
  var li = document.createElement('li');
  li.appendChild(link);
  
  ul.appendChild(li);
}

function advancedContactFormStart() {
	var toggle = 'slow';
		
	if (cfPage == 2) {
		$("#cfAddress").css("display", "none");
		$("#cfBack").css("display", "inline");
	} else {
		$("#cfQuestions").css("display", "none"); 
		$("#cfSubmit").val(cfValueNext);
	}
	
	$("#cfSubmit").click(function() {		

		if ($("#cfQuestions").css("display") == 'block') return true;
		else {
			var cfError = false;
			if (typeof cfRequired == 'object') {
				for (var key in cfRequired) {
					$("#"+key).removeClass("error");
					var value = jQuery.trim($("#"+key).val());
					switch (cfRequired[key]) {
						case 'email':							
							if (!/(.*)@(.*)(\.)(.*)/i.test(value)) {
								cfError = true;
								$("#"+key).addClass("error");								
							}
							break;							
						default:
							if (!value) {
								cfError = true;
								$("#"+key).addClass("error");
							}
							break;
					}
				}
			}

			if (!cfError) {
				$("#cfAddress").slideToggle(1);			
				$("#cfQuestions").slideToggle(toggle, function() { 
					$("#cfSubmit").val(cfValueSubmit);
					$("#cfBack").css("display", "inline");
				} );
			}
			return false;
		}
	});
	
	$("#cfBack").click(function() {		
		$("#cfSubmit").val(cfValueNext);
		$("#cfBack").css("display", "none");
		$("#cfAddress").slideToggle(toggle);
		$("#cfQuestions").slideToggle(1);
		
		return false;
	});
}
