//functions for selector image highlights
var j = null;
var k = null;

var clickedGroup = null;
var clickedNo = null;
var clickedInst = null;
var clickedKind = null;

function actSel(kind,imgName){
	if (document.images) {
		document[imgName].src = "/lynx_media/" + kind + "/" + imgName + "_on.gif";
	}
}

function inactSel(kind,imgName){
	if (document.images) {
		document[imgName].src = "/lynx_media/" + kind + "/" + imgName + "_off.gif";
	}
}

function choose(kind,chassis,number,instance) {
	if (document.images) {
		if (clickedGroup != null) resetSelection(clickedKind,clickedGroup);
		for (k = 0; k <= number; k++) {
			for (j = 0; j <= instance; j++) {
				if (document[chassis + k + '_' + j]) {
					document[chassis + k + '_' + j].src = "/lynx_media/" + kind + "/" + chassis + k + "_on.gif";
					clickedGroup = chassis;
					clickedNo = number;
					clickedInst = instance;
					clickedKind = kind;
				}
			}
		}
	}
}

function resetSelection(clickedKind,clickedGroup) {
	for (k = 0; k <= clickedNo; k++) {
		for (j = 0; j <= clickedInst; j++) {
			if (document[clickedGroup + k + '_' + j]) {
				document[clickedGroup + k + '_' + j].src = "/lynx_media/" + clickedKind + "/" + clickedGroup + k + "_off.gif";
			}
		}
	}
}

//functions for selector text highlights

function highlight(group,number){
	resetHighlights();
	for (j = 0; j <= number; j++) {
		document.getElementById(group + j).style.color = "#FFFFFF";
		document.getElementById(group + j).style.backgroundColor = "#006A82";
		//document.getElementById(group + j).parentNode.style.textDecoration = "none";
    }
}

function highlight2(group,number){
	resetHighlights();
	for (j = 0; j <= number; j++) {
		document.getElementById(group + j).childNodes[0].style.color = "#FFFFFF";
		document.getElementById(group + j).childNodes[0].style.backgroundColor = "#006A82";
		//document.getElementById(group + j).style.textDecoration = "none";
    }
}

function resetHighlights() {
var selMatrix = document.getElementById("selMatrix");
var clickedHighlights = selMatrix.getElementsByTagName("span");

	for (k = 0; k < clickedHighlights.length; k++) {
		if (clickedHighlights[k].parentNode.parentNode.className == "matrixTDtxt") {
			clickedHighlights[k].style.color = "#000000";
			clickedHighlights[k].style.backgroundColor = "#FFFFFF";
			//clickedHighlights[k].parentNode.className = "inf";
		}
		else return;
	}
}

// Functions for mouseOver effects in left navigation
function hiSnav( level, row )
{
	if( document.getElementById )
	{
		var tmp	=	document.getElementById( 'snav_l'+level+'_'+row );
		if( typeof tmp == "object" )
			tmp.className	=	'l'+level+'_ractive';
	}
}

function loSnav( level, row )
{
	if( document.getElementById )
	{
		var tmp	=	document.getElementById( 'snav_l'+level+'_'+row );
		if( typeof tmp == "object" )
			tmp.className	=	'l'+level+'_ridle';
	}
}

// Functions for mouseOver effects over elements
function hiSt( nr, style )
{
	if( document.getElementById )
	{
		var tmp	=	document.getElementById( 'st'+nr );
		if( typeof tmp == "object" )
		{
			if( typeof( style ) != "undefined" )
				tmp.className	=	style;
			else
				tmp.className	=	'tblcfactive';
		}
	}
}

function loSt( nr, style )
{
	if( document.getElementById )
	{
		var tmp	=	document.getElementById( 'st'+nr );
		if( typeof tmp == "object" )
		{
			if( typeof( style ) != "undefined" )
				tmp.className	=	style;
			else
				tmp.className	=	'tblcont';
		 }
	}
}

// Collapse and expand specs table
var cssDispl = null;
var check = null;

if (navigator.appName=="Microsoft Internet Explorer") {
	cssDispl = "inline"; 
	}
else { 
	cssDispl = "table-row";
	}

function openTab(cat,number,active) {
var check = active;
	for (i = 0; i <= number; i++) {		
		document.getElementById(cat + '_' + i).style.display = cssDispl;
	}
	check = 1;
}

function closeTab(cat,number,active) {
var check = active;
	for (i = 0; i <= number; i++) {		
		document.getElementById(cat + '_' + i).style.display = "none";
	}
	check = -1;
}

function openAll() {
var rows = document.getElementsByTagName('tr');
	for(var i=0; i<rows.length; i++) {
		rows[i].style.display = cssDispl;
	}
}

// Misc. functions
function addbookmark(text) {
	bookmarkurl=self.location.href;
	bookmarktitle="Lynx - The most personal Personal Computer"; //document.title;
	if (document.all) {
		window.external.AddFavorite(bookmarkurl,bookmarktitle)
	} else {
		alert(text);
	}
}

function switchLayer(visLayer,newLayer) {
	document.getElementById(visLayer).style.display = "none";
	document.getElementById(newLayer).style.display = "inline";
}

function showLayer(layerName) {
	document.getElementById(layerName).style.display = "inline";
}

function hideLayer(layerName) {
	document.getElementById(layerName).style.display = "none";
}

function showInfoPopup(page, title) {
	child = window.open( page, title, "width=650,height=350,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no" );
	setTimeout('child.focus()', 20);
}

function mailpopup(url) {
	F1 = window.open( url, 'Link', "width=650,height=500,resizable=no,scrollbars=auto");
	F1.focus();
}

function showPopup(url, pwidth, pheight) {
	popupWin = window.open( url, 'Link', "width=" + pwidth + ",height=" + pheight + ",resizable=no,scrollbars=auto");
	popupWin.focus();
}

// Functions for forms
function calcMarge(){
	if (document.changeform.surcharge.value==null || document.changeform.surcharge.value=="" || 
			isNaN(document.changeform.surcharge.value)){
		alert(document.changeform.surcharge.value+" ist keine ganze Zahl!");
		document.changeform.surcharge.value=0;
		document.changeform.marge.value=0;
		document.changeform.surcharge.focus();
		return;
	}
	var dSurcharge = parseInt(document.changeform.surcharge.value);
	var dMarge = (dSurcharge*100)/(dSurcharge+100);
	document.changeform.surcharge.value = Math.round(dSurcharge).toString();
	document.changeform.marge.value = Math.round(dMarge).toString();
}
function calcSurcharge(){
	if (document.changeform.marge.value==null || document.changeform.marge.value=="" || 
			isNaN(document.changeform.marge.value)){
		alert(document.changeform.marge.value+" ist keine ganze Zahl!");
		document.changeform.marge.value=0;
		document.changeform.surcharge.value=0;
		document.changeform.marge.focus();
		return;
	}
	var dMarge = parseInt(document.changeform.marge.value);
	if (dMarge>99){
		dMarge = 99;
		document.changeform.marge.value=99;
	}
	var dMarge = parseInt(document.changeform.marge.value);
	var dSurcharge = -(100*dMarge)/(dMarge-100);
	document.changeform.surcharge.value = Math.round(dSurcharge).toString();
	document.changeform.marge.value = Math.round(dMarge).toString();
}

// Functions for Firefox (window size calculation and scrollbars)
var totalWidth = null;
var totalHeight = null;
var availHeight = null;

function winWidth() {
	if (window.innerWidth) {return window.innerWidth;}
	else {return 0;}
}

function winHeight() {
	if (window.innerHeight) {return window.innerHeight;}
	else {return 0;}
}

function resetWin() {
	if (totalWidth != winWidth() || totalHeight != winHeight())
		location.href = location.href;
		setScrollbars();
}

function setScrollbars() {
	if ("confLeft" != null && "confRight" != null) {
		if (window.innerHeight) {
			totalHeight = winHeight();
			availHeight = totalHeight - 283;
			document.getElementById('confLeft').style.maxHeight = availHeight;
			document.getElementById('confRight').style.maxHeight = availHeight;
		}
		else {return 0;}
	}
}

if (!window.totalWidth && window.innerWidth) {
	window.onresize = resetWin;
}

// Functions for mouseOver effects in configuration table
var rowstyles	=	Array();

function hiRow( row, iColStart, iColEnd )
{
	if( document.getElementById )
	{
		var tmp	=	document.getElementById( 'row'+row );
		if( typeof tmp == "object" )
			activateRowStyles( row, iColStart, iColEnd );
	}
}

function loRow( row, iColStart, iColEnd )
{
	if( document.getElementById )
	{
		var tmp	=	document.getElementById( 'row'+row );
		if( typeof tmp == "object" )
			restoreRowStyles( row, iColStart, iColEnd );
	}
}

function activateRowStyles( row, iColStart, iColEnd )
{
	for( var i=iColStart; i <= iColEnd ; i++ )
	{
		var cell	=	document.getElementById( 'r'+row+'c'+i );
		if(cell!=null && typeof cell == "object" )
		{
			rowstyles[i]	=	cell.className;
			cell.className	=	'tblcfactive';
		}
	}
}

function restoreRowStyles( row, iColStart, iColEnd ) {
  for( var i=iColStart; i <= iColEnd ; i++ ) {
    var cell= document.getElementById( 'r'+row+'c'+i );
    if(cell!=null && typeof cell == "object" )
      cell.className= rowstyles[i];
  }
}


//kalkuliert Preis durch angabe der Haendlermagre
function calcProdPrice(ID,optPrice,taxrate){
	var ek=document.getElementById("ek_preis").innerHTML;
	ek=ek.replace(/ EUR/,"");
        ek=ek.replace(/\./,"");
        ek=ek.replace(/,/,".");
	ek=parseFloat(ek);
	var marge=document.getElementById("percentage").value;
	marge=marge.replace(/,/,".");
	marge=parseFloat(marge);
	var vk=ek*(1+(marge/100))
	var endP=vk*taxrate;
	var tax=endP-vk;
	vk=vk.toFixed(2);
	tax=tax.toFixed(2);
	endP=endP.toFixed(2);
	document.getElementById("endval").value=endP;
	document.getElementById("MWST").innerHTML=tax.replace(/\./,',')+" EUR";
	document.getElementById("vk_preis").innerHTML=vk.replace(/\./,',')+" EUR";
	document.getElementById("totPrice").innerHTML=endP.replace(/\./,',')+" EUR";
}
//Kalkuliert Marge durch angabe vom zielpreis
function calcMargin(ID,optPrice,taxrate){
	var ziel=document.getElementById("endval").value;
	ziel=ziel.replace(/\./,"");
	ziel=ziel.replace(/,/,".");
	ziel=parseFloat(ziel);
	var vk=ziel/taxrate;
	var ek=document.getElementById("ek_preis").innerHTML;
	ek=ek.replace(/ EUR/,"");
	ek=ek.replace(/\./,"");
	ek=ek.replace(/,/,".");
	ek=parseFloat(ek);
	var marge=((vk/ek)-1)*100;
	var tax=ziel-vk;
	tax=tax.toFixed(2);
	vk=vk.toFixed(2);
	ziel=ziel.toFixed(2);
	marge=marge.toFixed(2);
	document.getElementById("percentage").value=marge;
	document.getElementById("vk_preis").innerHTML=vk.replace(/\./,',')+" EUR";
	document.getElementById("totPrice").innerHTML=ziel.replace(/\./,',')+" EUR";
	document.getElementById("MWST").innerHTML=tax.replace(/\./,',')+" EUR";
}

//MouseOver Effekte für Handelswareseiten
function MM_findObj(n, d) {
    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_showHideLayers() {
    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; }
  }