
// Hotfix - Kartentooltip fuer Dealer Serach (17.08.2009 - enobis GmbH ML - Support ANF-1281-YMVPG3)
var ns4=(document.layers)?true:false;
var ns6=(navigator.userAgent.indexOf("Gecko")!=-1)?true:false;
var mac=(navigator.appVersion.indexOf("Mac")!=-1)?true:false;
var mac45=(navigator.appVersion.indexOf("MSIE 4.5")!=-1)?true:false;
var opra=(navigator.userAgent.indexOf("Opera")!=-1)?true:false;
var IEDtD=0; if((document.all&&document.compatMode=="CSS1Compat")||(mac&&document.doctype&&document.doctype.name.indexOf(".dtd")!=-1))IEDtD=1;
if(ns6||ns4)mac=false;
function getMouseXY(e)
{
	if(ns4||ns6)
	{
		MouseX=e.pageX;MouseY=e.pageY;
	}
	else
	{
		MouseX=event.clientX;MouseY=event.clientY;
	}
	if(!opra&&document.all)
	{
		MouseX=MouseX+document.body.scrollLeft;
		MouseY=MouseY+document.body.scrollTop;
		//if(IEDtD)MouseY=MouseY+sy;
	}
	if (document.getElementById('toltip')) { if (document.getElementById('toltip').parentNode.tagName != 'BODY') document.body.appendChild(document.getElementById('toltip'));}
	return true;
};
document.onmousemove=getMouseXY;
// Ende: Hotfix - Kartentooltip fuer Dealer Serach (17.08.2009 - enobis GmbH ML - Support ANF-1281-YMVPG3)

opra=(navigator.userAgent.indexOf("Opera")!=-1)?true:false
ie55=((navigator.appVersion.indexOf("MSIE 6.0")!=-1||navigator.appVersion.indexOf("MSIE 5.5")!=-1))?true:false;
if(ie55&&opra)ie55=false;
var gWorkingXmlDoc = new ActiveXObject("Microsoft.XMLDOM");
var test1=this["LoginChecker_AlreadyLoadedInHtmlPage"] === undefined ? false : true;
//alert("Test1=" + test1);
if(test1==false){LoginChecker();}
window.setTimeout('LoginChecker()', 60000);					

function loadXMLString(xmlFile)
{
	gWorkingXmlDoc.async = "false";
	gWorkingXmlDoc.validateOnParse = "false";
	gWorkingXmlDoc.onreadystatechange = verify;
	var xPE = gWorkingXmlDoc.parseError;
	
	try{gWorkingXmlDoc.load(xmlFile);return gWorkingXmlDoc.xml; }
	catch(e){return false; }	
}
function verify()
{// 0 Object is not initialized, 1 Loading object is loading data, 2 Loaded object has loaded data, 3 Data from object can be worked with, 4 Object completely initialized, 
	if (gWorkingXmlDoc.readyState != 4){return false;}
}			
function LoginChecker()
{	
	var checkOutXml = new ActiveXObject("Microsoft.XMLDOM"); // xml-objekt initialisieren
	//var checkOutUrl = "http://localweb/Westfalia/LoginTimer/SAP_Abfrage.html";
	var checkOutUrlSAP = "http://pgd.sap.gea-it.de:8881/sap/bc/bsp/sap/zpor/InternetPortalLoginStatusCMS.htm"; 	
	
	var myURL = window.document.location.href;
	var UrlParts = myURL.split("/");	
	var UrlCountryCode = UrlParts[3] + "/" + UrlParts[4];
	var checkOutUrlExtranet = "http://" + UrlParts[2] + "/checkloginstatus.aspx"; 
	
	var funcValueExtranet =loadXMLString(checkOutUrlExtranet);
	if(funcValueExtranet != false)
	{
		checkOutXml.loadXML(funcValueExtranet);
		var UsernameExtranet = checkOutXml.selectSingleNode("//html/body/p").text;	
		if(UsernameExtranet=="InternetUser"){UsernameExtranet="not logged in!";}
		var funcValueSAP=loadXMLString(checkOutUrlSAP);
		//alert(UsernameExtranet);
		
		if(UsernameExtranet=="not logged in!")
		{
			//alert("not logged on to extranet!");
			//check login-status in SAP:
			
			if(funcValueSAP != false)
			{
				checkOutXml.loadXML(funcValueSAP);
				var TST1 = checkOutXml.selectSingleNode("//html/body/p").text;
												
				if(TST1.length < 1)
					{
						//alert("funcValueSAP=" + funcValueSAP);
						
						if(parent.document.getElementById("spanLogin")){if (window.document.getElementById("divLogin.Msg").style.visibility != "visible"){alert("Sie wurden ausgeloggt, weil ein Timeout stattgefunden hat. Bitte melden Sie sich erneut an!");}}
						
						//we cannot try new logon, because we need to logon to SAP, first (need of user-interaction) ;-(
						if(parent.document.getElementById("divLogin")) //only if new version of PT published!
						{	
							if(parent.document.getElementById("spanLogin")) //only if user is being shown that he is logged in
							{					
								var oldHref = window.document.getElementById("divLogin.a").href;	
								var newHref = oldHref.replace("/logout.aspx", "/Login_SAP.aspx");
								window.document.getElementById("divLogin.a").href = newHref;
								window.document.getElementById("divLogin.a").setAttribute("target", "_self", 0);								
								window.document.getElementById("divLogin.a").innerHTML="<img src='/sysimages/b_schluessel.gif' width='20' height='11' alt='Login' border='0'><img src='/sysimages/b_pfeil_r.gif' width='7' height='7' alt='Login' border='0'>Login"					
								window.document.getElementById("divLogin.Msg").style.visibility="visible";
							}
						}						
					}	
				else
					{
						//try logon to extranet:
						//alert("try logon to extranet!");
						var checkOutUrlExtranetLogin = "http://" + UrlParts[2] + "/" + UrlCountryCode + "/functions/Login_SAP.aspx";
						//alert(checkOutUrlExtranetLogin);
						var funcValueExtranet =loadXMLString(checkOutUrlExtranetLogin);
						//alert(funcValueExtranet);
						//check, if logon was successful:
						funcValueExtranet =loadXMLString(checkOutUrlExtranet);
						checkOutXml.loadXML(funcValueExtranet);
						UsernameExtranet = checkOutXml.selectSingleNode("//html/body/p").text;
						if(UsernameExtranet=="InternetUser"){UsernameExtranet="not logged in!";}
						if(UsernameExtranet=="not logged in!")
						{
							//logon failed, so bring up message:
														
							if(parent.document.getElementById("spanLogin")){if (window.document.getElementById("divLogin.Msg").style.visibility != "visible"){alert("Sie wurden ausgeloggt, weil ein Timeout stattgefunden hat. Bitte melden Sie sich erneut an!");}}
							
							if(parent.document.getElementById("divLogin")) //only if new version of PT published!
							{	
								if(parent.document.getElementById("spanLogin")) //only if user is being shown that he is logged in
								{					
									var oldHref = window.document.getElementById("divLogin.a").href;	
									var newHref = oldHref.replace("/logout.aspx", "/Login_SAP.aspx");
									window.document.getElementById("divLogin.a").href = newHref;
									window.document.getElementById("divLogin.a").setAttribute("target", "_self", 0);
									window.document.getElementById("divLogin.a").innerHTML="<img src='/sysimages/b_schluessel.gif' width='20' height='11' alt='Login' border='0'><img src='/sysimages/b_pfeil_r.gif' width='7' height='7' alt='Login' border='0'>Login"					
									window.document.getElementById("divLogin.Msg").style.visibility="visible";
								}
							}							
						}
					}								
			} //if funcValueSAP != false		
		}// if UsernameExtranet=="not logged in!"		
	}// if funcValueExtranet != false		
	//activate timer for next check:
	window.setTimeout('LoginChecker()', 60000);			
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}
/*
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
*/
function schliessen(){
	window.close();
}
function printMe()
	{self.print()
	}

// -----------------------------B- functions for country menu: -B---------------------------------------------------
function init(xid)
{
	xid.toString;
	if(document.all || document.layers || document.getElementById)
	{
			active=document.all ?
				document.getElementById(xid).style :
					document.layers ?
						document[xid] :
							document.getElementById(xid).style;
	}
	return active;		
}
	
var box = null;

//show and hide the languageboxes for countries

function languagebox(language,nr,country)
{
	if (box != null)
	{
		box.visibility = 'hidden';
	}
	box=init(language);				// setting object for browser
	box.backgroundColor="#e3eff2";
	box.filter = "alpha(opacity=90, finishopacity=0, style=50)"
	box.border="1px solid #000000";
	box.visibility = 'visible';
	box.bgColor = '#dddddd';
	
	
	if (document.all)
	{
		innerWidth = document.body.offsetWidth; 
		//innerHeight = window.offsetHeight;
	}
	box.left = Math.max(20, (innerWidth - 960)/2) + 90;
//	box.top = 332 + nr * 18;
	box.top = 350 + nr * 15;
	checkUrl(document.getElementById(language)); // workaround to change urls that should point to old site
}


//hide selectbox for countries

function countryboxclose(countries,status)
{
	if (box != null)
	{
		box.visibility = 'hidden';
		box.left = -400;
	}
	box=init(countries);				// setting object for browser
	box.left = -400;
	box.visibility = 'hidden';
	box = null;
}


//show selectbox for countries

function countryboxopen(countries,status)
{
	box=init(countries);				// setting object for browser
	if (document.all)
	{
		innerWidth = document.body.offsetWidth; 
		//innerHeight = window.offsetHeight;
	}
	box.left = Math.max(20, (innerWidth - 960)/2) ;			// countriebox left (absolute)
	box.top = 347;								// countriebox top (absolute)
	box.bgColor = '#e2f1f1';		// countriebox backgroundColor, it must be equal to color in the StyleSheet
	box.backgroundColor="#e1ffdf";
	box.backgroundColor="silver";
	box.filter = "alpha(opacity=95, finishopacity=0, style=50)"
	box.border="1px solid #000000";
	box.visibility = 'visible';	// countriebox visibility
	box = null;									// delete var box
	checkUrl(document.getElementById(countries)); // workaround to change urls that should point to old site
}

function checkUrl(box)
{
          var myConfiguration = "/be/de|http://www.westfalia.com/hq/de, ";
                myConfiguration += "/be/nl|http://www.westfalia.com/nl/nl, ";
	myConfiguration += "/ro/ro|http://www.westfalia.ro, ";
              	myConfiguration += "/nz/en|http://www.westfaliasurge.co.nz, ";
	myConfiguration += "/se/sv|http://www.westfaliasurge.se, ";
	myConfiguration += "/lu/de|http://www.westfalia.com/de/de ";


		
	var myCombination = myConfiguration.split(", ");
	for (var n=0; n<myCombination.length; n++)
		{var tmp = myCombination[n].split("|");
		var mySearchPhrase = tmp[0];
		var myTarget = tmp[1]; var exiter = 0;
		while (box.innerHTML.indexOf(mySearchPhrase) > -1)
			{var elemToChange = gimmeElem(box, "href", mySearchPhrase);
			if (elemToChange)
				{elemToChange.setAttribute("href", myTarget);
				}
			pruef(exiter);
			exiter++; if (exiter>99) break;
			}
		}
	}


function gimmeElem(startObj, att, attMatch, notToSearchObj)
	{if (startObj.children.length > 0)
		{// search all childs
		for (var n=0; n<startObj.children.length; n++)
			{if (startObj.children(n).getAttribute(att))
				{if (startObj.children(n).getAttribute(att).indexOf(attMatch) > -1)
					{return startObj.children(n);
					}
				}
			if (startObj.children(n).children.length > 0 && startObj != notToSearchObj)
				{var children;
				if (children = gimmeElem(startObj.children(n), att, attMatch, startObj))
					{return children;}
				}
			}
		}
	return false;
	}

function pruef(par)
	{if (document.getElementById("pruefer"))
		{document.getElementById("pruefer").innerHTML += (par + "<br>");
		}
	}

// -----------------------------E- functions for country menu: -E---------------------------------------------------

// Ausgelagerte Funktion gemäß Tridion-Empfehlung - (30.07.2008 - ML (enobis), Thorsten Stresow)

var theSelectedItem = "";
		function nav_select(itemID)
		{						
			if(document.getElementById(itemID + "_selector").innerHTML=="+")
			{
				document.getElementById(itemID + "_selector").innerHTML="-";
				var classNames = document.getElementById(itemID).className;					
				if(classNames.indexOf("nav_inactive") > -1){classNames=classNames.replace("nav_inactive","nav_active");}
				else{classNames = classNames + " nav_active"}	
				document.getElementById(itemID).className = classNames + " nav_active";
			}
			else if(document.getElementById(itemID + "_selector").innerHTML=="-")
			{
				document.getElementById(itemID + "_selector").innerHTML="+";
				var classNames = document.getElementById(itemID).className;										
				if(classNames.indexOf("nav_active") > -1){classNames=classNames.replace("nav_active","nav_inactive");}
				else{classNames = classNames + " nav_inactive"}						
				document.getElementById(itemID).className = classNames;																			
			}			
		}
			function CheckURL_forSelection()
			{
				var x=window.location.href;
				if(x.indexOf("?")> -1)
				{
					var y=x.split("?");				
					var z=y[1].indexOf("selectedItem"); 
					if(z > -1)
					{
						var z2=y[1].length; 
						var z3= z2-z;
						var z4=y[1].substr(z, z3);
						var z5="";
												
						if(z4.indexOf("&")> -1){z5=z4.split("&");z4=z5[0]}
						z5=z4.split("=");						
						
						theSelectedItem=z5[1];
						var z6=z5[1].split(".");						
						var i2="";
						var var1="<span style='color: #009966 !important'>";
						var var1b="</span>";
						
						for(var i = 0; i < z6.length; i++)
						{
							i2 +=z6[i];
							var itemID="nav_item_" + i2;
							nav_select(itemID);	
							//alert(itemID);				
							i2 +=".";
							if(i == z6.length-1)
							{
							  var var2=document.getElementById(itemID).innerText;
							  var var3 = var1 + var2 + var1b;			
							  var var4 = document.getElementById(itemID).innerHTML;			 
							  document.getElementById(itemID).innerHTML = var4.replace(var2, var3);							  
							  document.getElementById(itemID).style.fontWeight="bold";							
							}
						}
					}					
				}
			}

		function mouseOver(itemID)
		{
			if(itemID != "a_" + theSelectedItem)
			{
				document.getElementById(itemID).style.fontWeight="bold";
				document.getElementById(itemID).style.color="green";
			}
		}

		function mouseOut(itemID)
		{
			if(itemID != "a_" + theSelectedItem)
			{
				document.getElementById(itemID).style.fontWeight="normal";
				document.getElementById(itemID).style.color="black";
			}
		}	


function imgswap(path,picId)
{
	document.getElementById(picId).src = path;
}
// set Favorite
function setFavorite()
{
	if (document.all)
	{
		readURLa = document.location.href;
		if (readURLa.indexOf(".aspx") > 0)
		{
			cutURL = readURLa.indexOf(".aspx") + 5;
		}
		else
		{
			if (readURLa.indexOf(".asp")> 0 )
			{
				cutURL = readURLa.indexOf(".asp") + 4;
			}
			else
			{
				cutURL = readURLa.length
			}
		}
		readURL = readURLa.substring(0,cutURL);
		window.external.AddFavorite(readURL, 'WestfaliaSurge - '+ document.title);
		
	}
	else
	{
		alert('For Bookmark us: Please press CRTL-D');
	}
}

//-->
// Fenster öffnen **********************************************************
function NAV_OpenFenster(datei,fenstername,weite,hoehe)
	{
	Eigenschaften = window.open(datei, fenstername,"width="+weite+",height="+hoehe+", top=0,left=0,scrollbars");
	Eigenschaften.focus();
	return false;
	}

function NAV_OpenBlankFenster(url)
	{
	Eigenschaften = window.open(url, "_blank");
	Eigenschaften.focus();
	return false;
	}