/**

 * Java Script Funktionen

 *

 * Copyright 2004 by DACHCOM digital AG.

 * All rights reserved.

 *

 * Author: Walter Canal, wcanal@dachcomdigital.com

 * Version 1.0, 29.01.2004

 *

 * History:

 *  1.0 29.01.2004	wcanal	initial relase

 *

 */

function getScrollingPosition()      
{      
 var position = [0, 0];      
     
 if (typeof window.pageYOffset != 'undefined')      
 {      
   position = [      
       window.pageXOffset,      
       window.pageYOffset      
   ];      
 }      
     
 else if (typeof document.documentElement.scrollTop      
     != 'undefined' && document.documentElement.scrollTop > 0)      
 {      
   position = [      
       document.documentElement.scrollLeft,      
       document.documentElement.scrollTop      
   ];      
 }      
     
 else if (typeof document.body.scrollTop != 'undefined')      
 {      
   position = [      
       document.body.scrollLeft,      
       document.body.scrollTop      
   ];      
 }      
     
 return position;      
} 


function mouse_pos(evt)
{
    if(!evt) evt = window.event;
    var pos = { left: evt.clientX, top:evt.clientY };
/*
    var b = (window.document.compatMode && window.document.compatMode == "CSS1Compat") ?
    window.document.documentElement : window.document.body || null;
alert(window.pageYOffset);*/
var b = getScrollingPosition();
    if (b)
    {
        pos.left += b[0];
        pos.top +=  b[1];
    }
    return pos;
} 

// File-Download

function openFile(id) {

	document.location.href = '/admin/include/downloadFile.php?action=d&id='+id;

}

function toggleDiv(divid) {

	if(document.getElementById(divid).style.visibility=='hidden' || document.getElementById(divid).style.visibility=='') {
		document.getElementById(divid).style.visibility = 'visible';
	}
	else {
		document.getElementById(divid).style.visibility = 'hidden';
	}
}

function showLegendDiv(event) {
	
	var mpos = mouse_pos(event);
	var divid = 'legend';
		
	var toppos = mpos.top - 283;
	document.getElementById(divid).style.top = toppos + 'px';
	document.getElementById(divid).style.visibility = 'visible';
	
	//document.getElementById(divid).style.left = mpos.left;
	
}

function showMovie(event,theMovie) {
	
	if (theMovie)
		var aTheMovie = theMovie.split(';');
		
	var mpos = mouse_pos(event);
	var divid = 'movie';
	var moviecontainerdivid = 'moviecontainer';
	var themoviedivid = 'themovie';
		
	var toppos = mpos.top - 83;
	
	document.getElementById(divid).style.top = toppos + 'px';
	if (aTheMovie[1]) {
		var divWidth = parseInt(aTheMovie[1]) + 30;
		document.getElementById(divid).style.width = divWidth + 'px';
	}
	document.getElementById(divid).style.visibility = 'visible';
	document.getElementById(moviecontainerdivid).innerHTML = '<div id="themovie"><div id="themovie"><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /><br /><br /></div>';
	
	var flashvars = {};
	var params = {};
	var attributes = {};
	attributes.id = "movieobj";
	swfobject.embedSWF(aTheMovie[0], themoviedivid, aTheMovie[1], aTheMovie[2], "9.0.0", "/flash/expressInstall.swf", flashvars, params, attributes);
	
	//swfobject.embedSWF(aTheMovie[0], themoviedivid, aTheMovie[1], aTheMovie[2], "9.0.0");
	
}

function closeMovie() {
	
	var divid = 'movie';
	var moviecontainerdivid = 'moviecontainer';
	var themoviedivid = 'themovie';
	
	document.getElementById(moviecontainerdivid).innerHTML = '<div id="themovie"></div>';
	document.getElementById(divid).style.visibility = 'hidden';
	
}


var totalPrice = 0;

function setSelectValues(form, obj) {
	var chbox = eval("form."+obj+"_chbox");
	var sel   = eval("form."+obj+"_select");
	var textf = eval("document.getElementById('"+obj+"_text')");

	if (sel.selectedIndex > 0) {
		chbox.checked = true;
		setTotal('min', textf.firstChild.nodeValue);
		setTotal('add', sel.value);
		textf.firstChild.nodeValue = sel.value;
		window.frames['basket'].document.location.href="basket.php?obj="+obj+"&val="+sel.selectedIndex;
	}
	else {
		setTotal('min', textf.firstChild.nodeValue);
		textf.firstChild.nodeValue = "0.00";
		chbox.checked = false;
		window.frames['basket'].document.location.href="basket.php?obj="+obj+"&val="+sel.selectedIndex;
	}
}

function setCheckboxValues(form, obj) {
	var chbox = eval("form."+obj+"_chbox");
	var sel   = eval("form."+obj+"_select");
	var textf = eval("document.getElementById('"+obj+"_text')");

	if (sel.selectedIndex > 0) {
		sel.selectedIndex = 0;
		setTotal('min', textf.firstChild.nodeValue);
		textf.firstChild.nodeValue = "0.00";
		window.frames['basket'].document.location.href="basket.php?obj="+obj+"&val="+sel.selectedIndex;
	}
	else {
		sel.selectedIndex = 1;
		setSelectValues(form, obj);
		window.frames['basket'].document.location.href="basket.php?obj="+obj+"&val="+sel.selectedIndex;
	}
}


function setTotal(mat, val) {
	val = val*100;
	if (mat == 'add') {
		totalPrice = (totalPrice)+(val);
	}
	else if (mat == 'min') {
		totalPrice = (totalPrice)-(val);
	}
	document.getElementById('total_text').firstChild.nodeValue = Zahlformat(totalPrice/100);
}

function checkValues(form) {
	if (document.getElementById('total_text').firstChild.nodeValue == '0.00') {
		var selectedProducts = window.frames['basket'].selectedProducts;
		for (var i=0; i < selectedProducts.length; i++) {
			if (selectedProducts[i][0] != '') {
				eval("form."+selectedProducts[i][0]+"_select.selectedIndex = "+selectedProducts[i][1]);
				setSelectValues(form, selectedProducts[i][0]);
			}
		}
	}
}


function Zahlformat(zahl) {
	var sZahl = String(Math.round(zahl*100));
	
	if (sZahl == 0) {
		return ("0.00");
	}
	
	sZahl = sZahl.substring(0, sZahl.length-2) + "." + sZahl.substring(sZahl.length-2, sZahl.length);
	
	if ("." == sZahl.substring(0,1)) {
		sZahl= "0" + sZahl;
	}
	
	var fZahl=sZahl.split(".");
	
	sZahl = fZahl[0];
	
	if (zahl>=1000000) {
		sZahl=sZahl.substring(0,sZahl.length-6)+"'"+sZahl.substring(sZahl.length-6,999);
	}
	
	if (zahl>=1000) {
		sZahl=sZahl.substring(0,sZahl.length-3)+"'"+sZahl.substring(sZahl.length-3,999);
	}
	
	return(sZahl + "." + fZahl[1]);
}

