// Preload Images
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];}
}


// sets a value for f.e. a textbox
function setValue(id, val){
	var obj;
	obj = getRef(id);

	if (obj != null) obj.value = val;
}

function setInnerHtml(id, html){
	var obj = getRef(id);
	
	if (obj != null) obj.innerHTML = html;
}


function setCSS(id, css){
	var obj = getRef(id);
	
	if (obj != null) obj.className = css;
}


function setStyle(id, style, value){
	var obj = getRef(id);
	
	if (obj != null){
		obj.style[style] = value;
		return true;
	}
	return false;
}

function getStyle(id, style){
	var obj = getRef(id);
	
	if (obj != null){
		return obj.style[style];
	}
	
	return false;
}


// preislisten highlight
var row_preisliste_norm = "#e6e6e6";
var row_preisliste_move = "#99bbff";
var row_preisliste_high = "#6699cc";

function highlight(elem, mode){
	switch(mode){
		case "move":
			if (elem.bgColor != row_preisliste_high) elem.bgColor = row_preisliste_move;
			break;
		case "high":
			if (elem.bgColor == row_preisliste_move){
				elem.bgColor = row_preisliste_high;				
			}else{
				elem.bgColor = row_preisliste_norm;
			}
			break;
		default:
			if (elem.bgColor != row_preisliste_high) elem.bgColor = row_preisliste_norm;
			break;
	}
}

// preislisten anschluss
function anschluss_highlight(elem){
	var obj;
	
	obj = getRef(elem);
	if (obj != null){
		obj.bgColor = "#000000";
	}
}

// rechtes untermenu
function toogleMenuEntry(parentId) {
	var childDiv;
	var i;

	// alle verstecken
	for (i=0; i <= 100; i++) {
		childDiv = document.getElementById('child_div_'+i);
		if ((i != parentId) && childDiv) {
			childDiv.style.display = "none";
		}
	}

	//togglen
	childDiv = document.getElementById('child_div_'+parentId);
	
	if (childDiv != undefined){
		if (childDiv.style.display != "block") {
			childDiv.style.display = "block";
		}else{
			childDiv.style.display = "none";
		}	
	}
}

function open_page(page){
	parent.frames["Inhalt"].location.href = page;
}

function popUp(url) {
	sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,top=0,left=0,width=600,height=480');
}

//Script zum umschalten zwisdchen 2 HTML Elementen (hier Bilder) by jakob
function toggleDisplay(obj1, obj2, view){
	obj1small = getRef(obj1+"small");
	obj2small = getRef(obj2+"small");
	obj1 = getRef(obj1);
	obj2 = getRef(obj2);

	obj2.style.display = "none";
	obj1small.style.display = "none";

	if (navigator.appName == "Netscape"){
		obj1.style.display = view;	
		obj2small.style.display = view;			
	}else{
		obj1.style.display = "block";	
		obj2small.style.display = "block";			
	}	
		
	repaintFix();
}

function getRef(obj){
	return(typeof obj == "string") ? document.getElementById(obj) : obj;
}

function toggleDiv(was) {
	var karteneingabeobj;

	my_obj = getRef(was);
	if (my_obj.style.display == "none") {
		//enablen
		my_obj.style.display = "block";
	} else {
		//disablen
		my_obj.style.display = "none";
	}
	
	return true;
}

function hideDiv(was) {
	my_obj = getRef(was);
	if(my_obj != null) my_obj.style.display = "none";
}

function showDiv(was) {
	my_obj = getRef(was);
	if(my_obj != null) my_obj.style.display = "block";
}

/*
	@author: 	Sauer
	@info: 		toggleZahlungsarten zeigt bzw. versteckt die gewünschten Informationen und Auswahlmöglichkeiten je nach ausgewähltem Radiobutton im Warenkorb->Schritt 3
	@param: 		neu				String			id der neu ausgewählten Zahlungsweise ("va_vorauskasse", etc...)
					redident_bool	boolean			wenn die Seite gereloaded wurde: false
													wenn sich die Einstellung geändert hat: true
*/
function toggleZahlungsarten(neu, resident_bool, versand_id) {
	//setVersandart(false, false);
	hideDiv("va_vorauskasse");
	hideDiv("va_sofortüberweisung");
	hideDiv("va_kreditkarte");
	hideDiv("va_nachnahme");
	hideDiv("va_finanzierung");
	hideDiv("va_leasing");

	hideDiv("va_vorauskasse_infos");
	hideDiv("va_kreditkarte_infos");
	hideDiv("va_nachnahme_infos");
	hideDiv("va_finanzierung_infos");
	hideDiv("va_sofortueberweisung_infos");
	hideDiv("va_leasing_infos");
	hideDiv("finanzausgabe");					// Finanzierungsraten
	hideDiv("leasingausgabe");					// Leasingraten
	hideDiv("laufzeit_div");
	hideDiv("kreditkarten_div");
	showDiv(neu);
	if(neu == "va_sofortüberweisung") neu = 'va_sofortueberweisung';
	showDiv(neu+"_infos");

	laufzeitobj = getRef("laufzeit");
	kartenobj = getRef("cc_typ");
	if(laufzeitobj) laufzeitobj.value = "0";
	if(kartenobj)kartenobj.value = "";

	if(neu == "va_leasing") showDiv("leasingausgabe");
	if(neu == "va_finanzierung") showDiv("laufzeit_div");
	if(neu == "va_kreditkarte") showDiv("kreditkarten_div");
	leasingobj = null;
	
	if(resident_bool) {
		showDiv("header_versandart");
		showDiv("header_infos");
		// Hier wird über 30 radio-buttons (derzeit ca. 20) iteriert und alle ungechecked (relativ dirty-harry)
		for(i=0; i<30;i++){
			my_obj = getRef("versandart_"+i);
			// checked?
			if(my_obj != null) my_obj.checked = (i == versand_id);
			
			//if(my_obj != null) my_obj.checked = false;
		}
	}
}



function swap(div_id){  // DIV Box auf und zu klappen-  by Omar
gurr = new Array("bestellenohnerisiko","datenschutz","lieferzeit","bestellungausland","pickup",
				 "inzahlungnahme","anschrift","umsatzsteueridentnummer","nachnahme","vorauskasse","sofort",
				 "kreditkarte","ratenzahlung","yategosiegel","zahlungsmodalitäten");
for ( keyVar in gurr ) {  //erstmal alle schließen
   document.getElementById(gurr[keyVar]).style.display = 'none';
}
//und dann das jewünscht öffnen:
if(document.getElementById(div_id).style.display == 'inline'){
	document.getElementById(div_id).style.display = 'none';
	}else{
		document.getElementById(div_id).style.display = 'inline';
		}
}	
	
/*
	@author:	Sauer
	@info:		reloadZahlungsarten wird aufgerufen, falls der User im Schritt 4 auf "zurück" klickt oder die Seite sonst reloaded wird
				Die alten Einstellungen werden hier wieder hergestellt
	@param:		alt			String			zuvor Eingestellte Zahlungsweise ("nachnahme", "vorauskasse"...) aus der $_Session
*/
function reloadZahlungsarten(z_alt, v_alt) {
	toggleZahlungsarten("va_"+z_alt, false);
	my_obj_zart = getRef("zahlungsart_"+z_alt);
	my_obj_versand = getRef("versandart_"+v_alt);
	if(my_obj_versand != null) my_obj_versand.checked = true;
	if(my_obj_zart != null) {
		showDiv("header_infos");
		my_obj_zart.checked = true;
	}
	showDiv("va_"+z_alt+"_infos");
}


function repaintFix(obj){ 
	if("undefined" == typeof document.body
	  || "undefined" == typeof document.body.style) return;

	if(obj == null)
		obj == document.body;
	else obj = getRef(obj);
	
	document.body.style.visibility = "hidden";
	document.body.style.visibility = "visible";
}

function ToggleChilddiv(parentId) {
	childdiv = document.getElementById('win_'+parentId);
	var left= 0;

	
    childdiv.style.left = 0;

    for (i=1;i<=5;i++) {
        if (i != parentId) {
            if (document.getElementById("win_" + i)) {
                document.getElementById("win_" + i).style.left= -5000;
            }
        }
    }
}

	/* Menu Animation, Quelle: www.crossbrowser.com */
	
	function xGetElementById(e){
	  if(typeof(e)=='string') {
		if(document.getElementById) e=document.getElementById(e);
		else if(document.all) e=document.all[e];
		else e=null;
	  }
	  return e;
	}
	
	function xGetComputedStyle(e, p, i){
	  if(!(e=xGetElementById(e))) return null;
	  var s, v = 'undefined', dv = document.defaultView;
	  if(dv && dv.getComputedStyle){
		s = dv.getComputedStyle(e,'');
		if (s) v = s.getPropertyValue(p);
	  }
	  else if(e.currentStyle) {
		v = e.currentStyle[p];
	  }
	  else return null;
	  return i ? (parseInt(v) || 0) : v;
	}
	
	function xCamelize(cssPropStr){
	  var i, c, a = cssPropStr.split('-');
	  var s = a[0];
	  for (i=1; i<a.length; ++i) {
		c = a[i].charAt(0);
		s += a[i].replace(c, c.toUpperCase());
	  }
	  return s;
	}
	
	function xAnimateCss(sEleId, sCssProp, iTarget, uTotalTime){
	  units = 'px'; // only supports integer pixel values for now
	  var ele = xGetElementById(sEleId);
	  var startValue = parseInt(xGetComputedStyle(ele, sCssProp)) || 0;
	  var disp = iTarget - startValue; // total displacement
	  var freq = Math.PI / (2 * uTotalTime); // frequency
	  var startTime = new Date().getTime();
	  var tmr = setInterval(
		function() {
		  var elapsedTime = new Date().getTime() - startTime;
		  if (elapsedTime < uTotalTime) {
			var f = Math.abs(Math.sin(elapsedTime * freq));
			ele.style[xCamelize(sCssProp)] = Math.round(f * disp + startValue) + units;
		  }
		  else {
			clearInterval(tmr);
			ele.style[xCamelize(sCssProp)] = iTarget + units;
		  }
		}, 10
	  );
	}
	
	/* Menu auf und zu klappen */
	function toggleMenuHeaderNoFX(parentId, elemscnt){
	  childDiv = document.getElementById('child_div_'+parentId);

		closeDisabledMenus(parentId);

	  if (childDiv.style.display == "none") {
		childDiv.style.display = "";
	  } else {
		childDiv.style.display = 'none';
	  }
	}
	
	function closeDisabledMenus(parentId){
		for (i=0;i<=20;i++) {
			if (i != parentId) {
				if (document.getElementById("child_div_" + i)) {
					document.getElementById("child_div_" + i).style.display = "none";
				}
			}
		}		
	}
	
	function toggleMenuHeader(parentId, elemscnt) {
	  childDiv = document.getElementById('child_div_'+parentId);
	
	  if (childDiv.style.display == "none") {
		childDiv.style['height'] = 1;
		childDiv.style.display = "";
		xAnimateCss('child_div_'+parentId, 'height', elemscnt*15, 500);	// ausklappen
	  } else {
		xAnimateCss('child_div_'+parentId, 'height', 1, 500);			// einklappen
		setTimeout("getRef('child_div_"+parentId+"').style.display = 'none'", 500);
	  }
	
		closeDisabledMenus(parentId);
	}
	
	function MenuHeaderOver(parentId) {
	  headerImage = document.getElementById('header_'+parentId);
	  headerImage.src = document.getElementById('header_img_mouse_'+parentId).value;
	}
	

/*		AB HIER: TOOLTIP 	*/

var offsetxpoint=-60; //Customize x offset of tooltip
var offsetypoint=20; //Customize y offset of tooltip
var ie=document.all;
var ns6=document.getElementById && !document.all;
var enabletip=false;
var tipobj;

// lieferzeiten (tooltip)-popup
function lieferzeit(pid, lieferstatus){
	var htmltext;

	if (lieferstatus > 0){
		htmltext = '<iframe frameborder="0" scrolling="no" width="95%" height="95%" src="/ac/popups/lieferstatus_variationen.php?lieferstatus='+lieferstatus+'"></iframe>';		
		if (typeof ddrivetip != "undefined") ddrivetip(htmltext, '220', '140');		
	}else{
		htmltext = '<iframe frameborder="0" scrolling="no" width="95%" height="95%" src="/ac/popups/lieferstatus_variationen.php?pid='+pid+'"></iframe>';
		if (typeof ddrivetip != "undefined") ddrivetip(htmltext, '260', '300');		
	}
}

// bild vorschau
function imagepreview(img){
	var htmltext;
	
	htmltext = '<table width="100%" height="100%" border="0" cellpadding="5" cellspacing="0"><tr><td align="center" valign="middle"><img border="0" src="'+img+'" alt="Productimage"></td></tr></table>';

	if (typeof ddrivetip != "undefined") ddrivetip(htmltext, '130', '130');
}
// Tooltip mit Text
function tooltip(htmltext, breite, hoehe){
	if(typeof breite == "undefined") breite = '130'; 
	if(typeof hoehe == "undefined") hoehe = '15';
	if (typeof ddrivetip != "undefined") ddrivetip(htmltext, breite, hoehe);
}

function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thewidth, theheight){
	if (tipobj == null) tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : "";
	if (tipobj == null)	return false;
	if (ns6||ie){
		if (typeof thewidth != "undefined") tipobj.style.width = thewidth+"px";
		if (typeof theheight != "undefined") tipobj.style.height = theheight+"px";
		if (thewidth == "") tipobj.style.width = thewidth;
		if (theheight == "") tipobj.style.height = theheight;

		tipobj.innerHTML = thetext;
		enabletip = true;
		return false
	}
}


function positiontip(e){
	if (enabletip){
		var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
		var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
		//Find out how close the mouse is to the corner of the window
		var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
		var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20
		var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000

		//if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rightedge<tipobj.offsetWidth)
			//move the horizontal position of the menu to the left by it's width
			tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
		else if (curX<leftedge)
			tipobj.style.left="5px"
		else
			//position the horizontal position of the menu where the mouse is positioned
			tipobj.style.left=curX+offsetxpoint+"px"
		
		//same concept with the vertical position
		if (bottomedge<tipobj.offsetHeight)
			tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
		else
			tipobj.style.top=curY+offsetypoint+"px"
		tipobj.style.display="block"
	}
}

function hideddrivetip(){
	if (tipobj == null) tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : "";
	if (tipobj == null)	return false;
	if (ns6||ie){
		enabletip = false;
		tipobj.style.display = "none";
		tipobj.style.left = "-1000px";
		tipobj.style.backgroundColor = '';
		tipobj.style.width = '';
	}
}

document.onmousemove=positiontip;

//---- Rentservice Funktionen

// Menu Funktionen
function open_box(boxid){ 	//boxid = hersteler
 var box = document.getElementById(boxid);
 var btna = boxid.substring(0,boxid.lastIndexOf("_box")) + "_pic";
 var btn = document.getElementById(btna);
 box.style.top = absTop(btn) + btn.offsetHeight - 5 + "px";
 box.style.left = absLeft(btn) + 10 + "px";
 box.style.display = "inline";
}

function close_box(boxid){
 var box = document.getElementById(boxid); 
 if (box) box.style.display = "none";
} 

function absLeft(el) {
 return (el.offsetParent)? 
 el.offsetLeft+absLeft(el.offsetParent) : el.offsetLeft;
}
  
  
function absTop(el) {
 return (el.offsetParent)? 
 el.offsetTop+absTop(el.offsetParent) : el.offsetTop;
}
  
function lightup(trid){
 var morry = document.getElementById(trid).cells.length;
  document.getElementById(trid).cells[0].className = "liste_bild2";
  document.getElementById(trid).cells[1].className = "liste_name2";
  document.getElementById(trid).cells[2].className = "liste_btn2";
}

function lightdown(trid){
 var morry = document.getElementById(trid).cells.length;
  document.getElementById(trid).cells[0].className = "liste_bild";
  document.getElementById(trid).cells[1].className = "liste_name";
  document.getElementById(trid).cells[2].className = "liste_btn";
}
