//<![CDATA[
var IE = document.all;
var obj;
// =============================================================================
window.onDomReady = initReady;
function initReady(fn) {
	if(document.addEventListener) {
	  document.addEventListener("DOMContentLoaded", fn, false);
	} else {
	  document.onreadystatechange = function(){readyState(fn)}
	}
}
function readyState(func) {
	if(document.readyState == "interactive" || document.readyState == "complete") {
		func();
	}
}
window.onDomReady(onReady);
function onReady() {
	vfStart();
	if(document.getElementById('MapG')) Mapload();
}
// =============================================================================

function vfStart() {
	// All blur
	vsLinks = document.getElementsByTagName('a');
	for(i = 0; i < vsLinks.length; i++){
		vsLinks[i].onfocus = vfLinkBlur;
	}

	vsSpan = document.getElementsByTagName('span');
	for(i = 0; i < vsSpan.length; i++){
		if(vsSpan[i].id.substring(0, 7) =='HyperID') {
			vsSpan[i].onmouseover = ShowHyperBox;
			vsSpan[i].onmouseout = HideHyperBox;
		}
	}
	document.getElementById('HyperBox').onmouseout = HideHyperBox;
	document.getElementById('HyperBox').onmouseover = ShowActiveHyperBox;
	
	// Routeneingabe 
	if(document.getElementById('fromAddress')) {
		document.getElementById('fromAddress').onkeyup = ChangeHG;
		document.getElementById('fromAddress').onblur = ChangeHG;
		document.getElementById('btnRoute').onclick = RouteOK;
	}
	// Sucheingabe
	document.getElementById('InpSearch').onkeyup = ChangeHG;
	document.getElementById('InpSearch').onblur = ChangeHG;
	document.getElementById('BtnSearch').onclick = StringOK;
	
	
	// Newsletter Jintergrundgrafik - Eingabe
	if(document.getElementById('nlMail')) {
		document.getElementById('nlMail').onkeyup = ChangeHG;
		document.getElementById('nlMail').onblur = ChangeHG;
		document.getElementById('BtnNLetter').onclick = MailOK;
	}
	// Startbildschirm Bildüberblendung
	if(document.getElementById('FadeDiv')) BlendStart();
	
	if(document.getElementById('ContentR')) {
		if(document.getElementById('ContentR').offsetHeight < document.getElementById("Text").offsetHeight - 30) {
			document.getElementById('ContentR').style.height = document.getElementById("Text").offsetHeight - 30 + "px";
		}
	}
}

function vfLinkBlur(evt) {
	this.blur();
}

function ChangeHG(evt) {
	if(this.value == "") {
		this.style.backgroundPosition = "0 0";
	} else {
		this.style.backgroundPosition = "0 -22px";
	}
}

function RouteOK() {
	var x = trim(document.getElementById('fromAddress').value);
	var LenStr = x.length;
	if(LenStr == 0) {
		document.getElementById('fromAddress').focus();
		return false;
	}
}
function StringOK() {
	var x = trim(document.getElementById('InpSearch').value);
	var LenStr = x.length;
	if(LenStr == 0) {
		document.getElementById('InpSearch').value = "";
		return false;
	}
	else if(LenStr < 3) {
		alert("Der Suchbegriff sollte mindestens 3 Zeichen enthalten!");
		document.getElementById('InpSearch').focus();
		return false;}
}
function MailOK() {
	var x = trim(document.getElementById('nlMail').value);
	var LenStr = x.length;
	if(LenStr == 0) {
		document.getElementById('nlMail').value = "";
		return false;
	}	else {
		var a = false;
		var res = false;
		if(typeof(RegExp) == 'function') {
		  var b = new RegExp('abc');
		  if(b.test('abc') == true){a = true;}
		}
		if(a == true) {
			reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+
			                 '(\\@)([a-zA-Z0-9\\-\\.]+)'+
			                 '(\\.)([a-zA-Z]{2,4})$');
			res = (reg.test(x));
		} else {
			res = (x.search('@') >= 1 &&
			       x.lastIndexOf('.') > x.search('@') &&
			       x.lastIndexOf('.') >= x.length - 5)
		}
		if(!res) {
			alert("Fehler \n\nGeben Sie bitte eine gültige eMail-Adresse an.");
			document.getElementById('nlMail').focus();
		}
		return res;
	}
}




var BlendCountIMG, BlendCountIMGHG;
function FullSize(Picture, PicHeight, PicWidth, Obj) {
	ScrollPosition();
	ScrnY();
	var PicHgW = PicWidth + 8;
	var PicHgH = PicHeight + 38;
	var ImgMarginX	= parseInt(-PicHgW / 2);
	var ImgMarginY	= parseInt(-PicHgH / 2);
	var ShMarginX		= parseInt(-PicHgW / 2 + 10);
	var ShMarginY		= parseInt(-PicHgH / 2 + 10);
	SetOpacity('SCRD', 0);
	SetOpacity('IMGhg', 0);
	SetOpacity('IMGShadow', 0);
	document.getElementById('SCR').style.top			=  ScrollPosY + 'px';
	document.getElementById('SCR').style.display	= 'block';
	document.getElementById('SCRD').style.top			=  ScrollPosY + 'px';
	document.getElementById('SCRD').style.height	=  ScrnHeight + 'px';
	document.getElementById('SCRD').style.display	= 'block';
	document.getElementById('IMGhg').style.display= 'block';
	document.getElementById('IMGhg').style.width	= PicHgW + 'px';
	document.getElementById('IMGhg').style.height	= PicHgH + 'px';
	document.getElementById('IMGhg').style.margin	= ImgMarginY + 'px 0 0 ' +  ImgMarginX + 'px';
	document.getElementById('IMGShadow').style.display= 'block';
	document.getElementById('IMGShadow').style.width	= PicHgW + 'px';
	document.getElementById('IMGShadow').style.height	= PicHgH + 'px';
	document.getElementById('IMGShadow').style.margin = ShMarginY + 'px 0 0 ' +  ShMarginX + 'px';
	document.getElementById('SCRIMG').src = Picture;
	document.getElementById('ImgText').innerHTML = ucfirst(document.getElementById(Obj).alt);
	BlendCountIMG	= 0;
	BlendCountIMGHG = 0;
	BlendAct = 1;
	StartOn();
}

function SetOpacity(obj, opacity) {
 var objkt = document.getElementById(obj);
 opacity = (opacity == 100)?99.999:opacity;
 if(IE) {
 	objkt.style.filter = "alpha(opacity:"+opacity+")";
 } else {
	 objkt.style.KHTMLOpacity = opacity/100;
	 objkt.style.MozOpacity = opacity/100;
	 objkt.style.opacity = opacity/100;
	}
}

function StartOn() {
	if(BlendAct == 1) {
		BlendCountIMG = BlendCountIMG + 10;
		BlendCountIMGHG = BlendCountIMGHG + 3;
		if(BlendCountIMG < 101) {
			SetOpacity('IMGhg', BlendCountIMG);
			SetOpacity('IMGShadow', BlendCountIMGHG);
			SetOpacity('SCRD', BlendCountIMGHG);
			var Blend = window.setTimeout("StartOn()", 30)
		}
	} else {
		StartOff();
	}
}
function PictureOff() {
	BlendAct = 2;
	StartOff();
}
function StartOff() {
	BlendCountIMG = BlendCountIMG - 10;
	BlendCountIMGHG = BlendCountIMGHG - 3;
	if(BlendCountIMG > 1) {
			SetOpacity('IMGhg', BlendCountIMG);
			SetOpacity('IMGShadow', BlendCountIMGHG);
			SetOpacity('SCRD', BlendCountIMGHG);
			var Blend = window.setTimeout("StartOff()", 30)
	} else {
		BlendAct = 0;
		document.getElementById("SCR").style.display = "none";
		document.getElementById("SCRD").style.display = "none";
		document.getElementById("IMGShadow").style.display = "none";
		document.getElementById("SCRIMG").src = "images/gla-blank.gif";
	}
}
// ===
var ScrnHeight, ScrnWidth;
function ScrnY() {
	if (self.innerHeight) {
		ScrnHeight = self.innerHeight;
		ScrnWidth = self.innerWidth;
	}	else if (document.documentElement && document.documentElement.clientHeight) {
		ScrnHeight = document.documentElement.clientHeight;
		ScrnWidth = document.documentElement.clientWidth;
	}	else if (document.body) {
		ScrnHeight = document.body.clientHeight;
		ScrnWidth = document.body.clientWidth;
	}
}
// ===
var ScrollPosY;
function ScrollPosition() {
	if (typeof window.pageYOffset != 'undefined') {
		ScrollPosY = window.pageYOffset;
	}
	else if (typeof document.compatMode != 'undefined' &&
		document.compatMode != 'BackCompat') {
		ScrollPosY = document.documentElement.scrollTop;
	}
	else if (typeof document.body != 'undefined') {
		ScrollPosY = document.body.scrollTop;
	}
}

function trim(s) {
	while (s.substring(0,1) == ' ') {
		s = s.substring(1,s.length);
	}
	while (s.substring(s.length-1,s.length) == ' ') {
		s = s.substring(0,s.length-1);
	}
	return s;
}

// =============================================================================
// Googleplaner ===

	var  Firma, TName, Str, Ort, map;

	function Route(Firma, TName, Str, Ort) {
		document.getElementById('toAddress').value = Str + ", " + Ort;
		ScrollPosition();
		ScrnY();
		var PicHgW = parseInt(ScrnWidth / 100 * 90);
		var PicHgH = parseInt(ScrnHeight / 100 * 90);
		var ImgMarginX = parseInt(-PicHgW / 2);
		var ImgMarginY = parseInt(-PicHgH / 2);
		var ShMarginX  = parseInt(-PicHgW / 2 + 8);
		var ShMarginY  = parseInt(-PicHgH / 2 + 8);
		var CloseTop   = PicHgH - 23;
		var CloseLeft  = PicHgW - 23;
		document.getElementById('SCR').style.top      =  '0' + ScrollPosY + 'px';
		document.getElementById('SCR').style.left     =  '0';
		
		document.getElementById('IMGhg').style.width  = PicHgW + 'px';
		document.getElementById('IMGhg').style.height = PicHgH + 'px';
		document.getElementById('IMGhg').style.margin = ImgMarginY + 'px 0 0 ' +  ImgMarginX + 'px';
		document.getElementById('IMGShadow').style.width  = PicHgW + 'px';
		document.getElementById('IMGShadow').style.height = PicHgH + 'px';
		document.getElementById('IMGShadow').style.margin = ShMarginY + 'px 0 0 ' +  ShMarginX + 'px';
		document.getElementById('SCRIMG').style.height   = PicHgH - 10 + "px";
		document.getElementById('SCRIMG').style.width    = PicHgW - 308 + "px";
		
		document.getElementById('Planer').style.position = 'absolute';
		document.getElementById('Planer').style.width = 292 + 'px';
		document.getElementById('Planer').style.height = PicHgH - 10 + 'px';
		document.getElementById('Planer').style.top  = '4px';
		document.getElementById('Planer').style.left  = PicHgW - 298 + 'px';
		document.getElementById('directions').style.height  = PicHgH - 80 + "px";
		
		document.getElementById('SCR').style.display  = 'block';
		document.getElementById('IMGShadow').style.display= 'block';
		document.getElementById('IMGhg').style.display= 'block';
		document.getElementById('Planer').style.display  = 'block';
		load(Firma, TName, Str, Ort);
	}
	function initialize() {
		if (GBrowserIsCompatible()) {
			map = new GMap2(document.getElementById('SCRIMG'));
			geocoder = new GClientGeocoder();
			showAddressMap("'" + Str + ", " + Ort + '"');
		}
	}

	function MapOff () {
		GUnload();
		document.getElementById("SCR").style.display = "none";
		document.getElementById('Planer').style.display  = 'none';
		document.getElementById('fromAddress').value = "";
		Mapload();
	}
// =============================================================================
	function ShowHyperBox(evt) {
		var HID = this.id;
		var Ind = HID.substr(7) - 1;
		var elm = document.getElementById(HID);
		var y = getAbsoluteY(elm);
		var x = getAbsoluteX(elm);

		document.getElementById("HyperBox").style.left = x - 103 + Math.floor(document.getElementById(HID).offsetWidth / 2) + "px";
//		document.getElementById("HelpText").innerHTML = HText;
		document.getElementById("HelpText").innerHTML = HText[Ind];
		document.getElementById("HyperBox").style.visibility = "hidden";
		document.getElementById("HyperBox").style.display = "block";
		document.getElementById("HyperBox").style.top = y + 4 - document.getElementById("HyperBox").offsetHeight + "px";		
		document.getElementById("HyperBox").style.visibility = "visible";
	}
	function HideHyperBox() {
		document.getElementById("HyperBox").style.display = "none";
	}
	function ShowActiveHyperBox() {
		document.getElementById("HyperBox").style.display = "block";
	}
	
function getAbsoluteX (elm) {
   var x = 0;
   if (elm && typeof elm.offsetParent != "undefined") {
     while (elm && typeof elm.offsetLeft == "number") {
       x += elm.offsetLeft;
       elm = elm.offsetParent;
     }
   }
   return x;
}

function getAbsoluteY(elm){
   var y = 0;
   if (elm && typeof elm.offsetParent != "undefined") {
     while (elm && typeof elm.offsetTop == "number") {
       y += elm.offsetTop;
       elm = elm.offsetParent;
     }
   }
   return y;
}
function ucfirst(str) { 
    var firstLetter = str.substr(0, 1); 
    return firstLetter.toUpperCase() + str.substr(1); 
} 
//]]>
