var agent = navigator.userAgent.toLowerCase();
var is_ns  = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) 
                && (agent.indexOf('compatible') == -1)));
var is_ie   = (agent.indexOf("msie") != -1);
var LocX=0
var LocY=0

var LocX=0
var LocY=0

var LocXPrev=0;
var LocYPrev=0;

var LocXOffs=0
var LocYOffs=0
bgImage = "url(../Images/General/selBg.jpg)";
bgImageNone="url(../Images/General/none.jpg)";

function fixBlock() 
{
	if (document.layers)
	{
		fBlock=document.fixBlock;
		LocX=window.pageXOffset;
		LocY=window.pageYOffset;
	}
	if (document.all)
	{
		fBlock=document.getElementById('fixBlock');
		LocX=document.body.scrollLeft;
		LocY=document.body.scrollTop;
	}

	if (document.getElementById && is_ns)
	{
		fBlock=document.getElementById('fixBlock');
		LocX=window.pageXOffset;
		LocY=window.pageYOffset;
	}
	if (LocX == LocXPrev && LocY == LocYPrev)
	{
		if(document.getElementById)
		{
			fBlock.style.left= (LocX+LocXOffs);
			fBlock.style.top= (LocY+LocYOffs);
		}
		else
		{}
	}
	else
	{
		LocXPrev = LocX;
		LocYPrev = LocY;
	}
}

function initFixBlock()
{
	if(document.layers||document.all)
	{
		setInterval("fixBlock()",50);
	}
	if(document.getElementById && is_ns)
	{
		document.getElementById("fixBlock").style.position="fixed";
	}
}	

function scrollToVisible(pId)
{
	var xOffset = 0;
	var yOffset = -120;
	var visibleBlock = document.getElementById(pId);
	if (visibleBlock != null)
	{
		window.scrollTo(visibleBlock.offsetLeft + xOffset, visibleBlock.offsetTop + yOffset);
	}
}

function toggleVisible(pId)
{
	if (document.getElementById)
	{
		entryArea=document.getElementById(pId);
		if (entryArea.style.visibility == "hidden")
		{
			entryArea.style.visibility="visible";
		}
		else
		{
			entryArea.style.visibility="hidden";
		}
	}
}

var oldIdPref;

function displSubnav(pElem, pIdPref, pId)
{
	var clearAll = false;
	var first = true
	regExpr = new RegExp(pIdPref);
	if (oldIdPref != null)
	{
		first = false;
		regExprOld = new RegExp(oldIdPref);
		if (oldIdPref == pIdPref)
		{
			clearAll = true;
		}
	}
	for (idx = 0; idx < document.getElementsByTagName(pElem).length; idx++)
	{
		elem = document.getElementsByTagName(pElem)[idx];
		elemId = elem.id;
		if (elemId == pId && !clearAll)
		{
			elem.style.background=bgImage;
		}
		else
		{
			elem.style.background=bgImageNone;
		}
		
		if ((regExpr.test(elemId) && clearAll))
		{
			if (elemId == oldIdPref || elemId == pIdPref)
			{
				elem.style.backgroundColor="#DEDEC6";
			}
			else
			{
				elem.style.display="none";
			}
		}
		if ((!first && regExprOld.test(elemId)))
		{
			if (elemId == oldIdPref || elemId == pIdPref)
			{
				elem.style.backgroundColor="#DEDEC6";
			}
			else
			{
				elem.style.display="none";
			}
		}
		if (regExpr.test(elemId) && !clearAll)
		{
			elem.style.display="block";
			elem.style.backgroundColor="#EFEFD7";
		}
	}
	if (clearAll)
	{
		oldIdPref = null;
	}
	else
	{
		oldIdPref = pIdPref;
	}
}

function displBlocksNot(pElem, pIdPref)
{
	regExpr = new RegExp(pIdPref);
	for (idx = 0; idx < document.getElementsByTagName(pElem).length; idx++)
	{
		elem = document.getElementsByTagName(pElem)[idx];
		elemId = elem.id;
		if (regExpr.test(elemId) && elem.id != "toEdit")
		{
			elem.style.display="none";
		}
	}
}

function toggleBlock(pId)
{
	alert("toggleBlock gets done");
	if (document.getElementById)
	{
		entryBlock=document.getElementById(pId);
		if (entryBlock.style.display == "none")
		{
			entryBlock.style.display="block";
		}
		else if (entryBlock.id != "toEdit")
		{
			entryBlock.style.display="none";
		}
	}
}

function scrollFrame(pId)
{
	toScroll = document.getElementById(pId);
	alert(toScroll.contentWindow.name);
 	toScroll.contentWindow.scrollTo(0, 40);
}

function setClass(pElem, pClass)
{
	pElem.className = pClass;
}

function linkTo(pLink)
{
	window.location.href=pLink;
}

// ********* start functions for index ********* 
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_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_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.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];}
}

// ********* end functions for index ********* 

// ********* start open image window ********* 

// Set the horizontal and vertical position for the popup

PositionX = 100;
PositionY = 100;

// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)

defaultWidth  = 150;
defaultHeight = 50;

// Do not edit below this line...
// ================================

var optPop='scrollbars=yes,resizable=yes,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;

function popUpWindow(imageTitle,imageURL)
{
	imgWin=window.open('about:blank','',optPop);
	with (imgWin.document)
	{
		writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');
		writeln('<sc'+'ript>');
		writeln('function reSizeToImage(){');
		writeln('width=document.images[0].width;');
		writeln('if ((opener.document.body.clientHeight-100) > document.images[0].height){');
		writeln('height=(document.images[0].height);}');
		writeln('else{height=(opener.document.body.clientHeight-100);}');
		writeln('window.resizeTo(width+50,height+100);}');
		writeln('function doTitle(){document.title="'+imageTitle+'";}');
		writeln('</sc'+'ript>');
		writeln('</head><body bgcolor=#FFFFFF onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">')
		writeln('<div style="text-align: center; padding-top: 25px">');
		writeln('<img name="Spezialwaagen" src='+imageURL+' alt="Spezialwaagen"><br>');
		writeln('<a href="javascript:top.window.close()">');
		writeln('Fenster schliessen');
		writeln('</a></div></body></html>');
		close();		
	}
}
// ********* end open image window ********* 

// ********* start open print window ********* 
function openWindowPrint(fileURL)
{
	var popUpWidth = screen.width-200;
	var popUpHeight = screen.height-200;
	var optPop="dependent=yes,scrollbars=yes,resizable=yes,width=" + popUpWidth + ",height=" + popUpHeight + ",left=100,top=100";
	window.open(fileURL, "Printview", optPop);
}
// ********* end open print window ********* 

// ********* start open pdf window ********* 
function openWindowPdf(fileURL, scaleName)
{
	var popUpWidth = screen.width-200;
	var popUpHeight = screen.height-200;
	var optWindow="dependent=yes,scrollbars=yes,resizable=yes,width=" + popUpWidth + ",height=" + popUpHeight + ",left=100,top=100";
	window.open(fileURL, "Datasheet", optWindow);
}
// ********* end open pdf window ********* 

// ********* start open produzent window ********* 
function openWindowProduz(fileURL, scaleName)
{
	var popUpWidth = screen.width-100;
	var popUpHeight = screen.height-100;
	var optWindow="dependent=yes,scrollbars=yes,resizable=yes,width=" + popUpWidth + ",height=" + popUpHeight + ",left=100,top=100";
	window.open(fileURL, "Produkte Info", optWindow);
}
// ********* end open produzent window ********* 

// ********* start modify and check search input ********* 

function checkData(){
	var searchstr = document.form_search.swinp.value.replace(/Waage/, "waage");
	searchstr = searchstr.replace(/Waaage/, "waage");
	searchstr = searchstr.replace(/waaage/, "waage");
	searchstr = searchstr.replace(/waagen/, "waage");
	searchstr = searchstr.replace(/waage/, "waage ");
//	searchstr = searchstr.replace(/ä/, "&auml;");
//	searchstr = searchstr.replace(/ö/, "&ouml;");
//	searchstr = searchstr.replace(/ü/, "&uuml;");
	document.form_search.sw.value = searchstr;
	if (document.form_search.sw.value != "Suche"
		&& document.form_search.sw.value.length!=0){	
		for(var i=0;i<document.form_search.sw.value.length;i++){
			if (document.form_search.sw.value.charAt(i)!=" "){	
				return true;
			}
			else{
				alert("Bitte geben sie einen Suchbegriff ein");
				document.form_search.swinp.focus();
				return false;
			}
		}
	}
	else{
		alert("Bitte geben sie den gewünschten Suchbegriff ein");
		document.form_search.swinp.focus();
		return false;
	}
}

// ********* End modify and check search input ********* 

