window.onload=function() {
           if(document.getElementById("mainMenu"))
    		initializeMenu('mainMenu');

    		if(document.getElementById("tooltip")) {
    			tipobj=document.getElementById("tooltip");
    			document.onmousemove=positiontip;	
                        hidetooltip();
    		}
}
    	
function openShop(){
    theShop=window.open('index.html','shop',"status=1,resizable=1,scrollbars=1,width=780,height=580");
    theShop.focus();
}


function closeWindow(){
	if(confirm('"Sie schliessen das Shop-Fenster\n und verlieren dadurch den Warenkorb. \nWollen Sie das Shop-Fenster schliessen?"'))
		window.close();
}

function changeStartPic(whichPicSrc){
    		document.getElementById('startPic').src=whichPicSrc;
    	}



/*functions from orbiz*/

function changeColor(pic) {
  document.getElementById("picBig").src = pic;
}

function searchHead() {
 document.searchForm.sizeText.value = document.searchForm.size.options[document.searchForm.size.selectedIndex].text;
 document.searchForm.colorText.value = document.searchForm.color.options[document.searchForm.color.selectedIndex].text;
 document.searchForm.arttypesText.value = document.searchForm.arttypes.options[document.searchForm.arttypes.selectedIndex].text;
 document.searchForm.collectionsText.value = document.searchForm.collections.options[document.searchForm.collections.selectedIndex].text;
 return true;
}


 function submitOrderForm() {
  document.orderCard.orderCardForm.value=1;
  document.orderCard.submit();
 }


 function checkOut(link,fp,hascode) {

  var wtr = "";
   
  if(hascode == 1) {
    wtr = document.cart.couponWK.value;
  }

  if(fp == 1) {
       link += "&favoriteArticle=" + document.cart.favoriteArticle.value;
  }
  else { 
    for (var lfp = 0; lfp < fp; lfp++) {
       if(document.cart.favoriteArticle[lfp].checked == true) {
         var prod = document.cart.favoriteArticle[lfp].value;
         link += "&favoriteArticle=" + prod;
       } 
    }
  }

  if(wtr != "") {
    link += "&couponWK=" + wtr;
  }

  location.href = link;
 }


function checkMiscField(page) {
 
 if(page == 1) {
   if(document.billAddress.customerSource.options[document.billAddress.customerSource.selectedIndex].value == document.billAddress.misc.value) {
    document.getElementById("miscField").style.display="inline";
   }
   else { 
    document.getElementById("miscField").style.display="none";
    document.billAddress.freeCustomerSource.value="";
   }
 }
 else {
   if(page == 5) { 
     if(document.catalog.customerSource.options[document.catalog.customerSource.selectedIndex].value == document.catalog.misc.value) {
      document.getElementById("miscField").style.display="inline";
     }
     else { 
      document.getElementById("miscField").style.display="none";
      document.catalog.freeCustomerSource.value="";
     } 
   }
 }
}

function checkAvailability () {
  void window.open('../order/checkAvailability.html','availability','width=550,height=300,scrollbars=yes,resizable=yes').focus();

  var head =  document.getElementById("deliverTime");
  head.firstChild.nodeValue = "Lieferzeit";

  $.getJSON("../order/jason.html", function(jason) {
   $(jason).each(function() {
      var help = "deliver-" + this.artno;
      var help2 = "nodeliver-" + this.artno;

      if(this.size) {
        help = help + this.size;
        help2 = help2 + this.size;
      }

//alert(this.artno);
//alert(this.size);
//alert(this.deliver);
//alert(this.dispo);

     var text =  document.getElementById(help);

     if(document.getElementById(help2)) {
        text = document.getElementById(help2);
     }

     if(this.dispo > 0) {
          text.firstChild.nodeValue = "sofort"; 
     }
     else {

       if(this.deliver == "01") {
            var week = " Woche";
            text.firstChild.nodeValue = this.deliver + " " + week; 
       }

       if(this.deliver == "99") {
        text.firstChild.nodeValue = "z.Zt. keine Lieferzusage"; 
       }

       if(this.deliver != "01" && this.deliver != "00" && this.deliver != "88" && this.deliver != "99") {
          var weeks = " Wochen";
          text.firstChild.nodeValue = this.deliver + " " + weeks; 
       }
       
       if(this.dispo == 0 && this.deliver == "") {
          text.firstChild.nodeValue = "Leider ausverkauft"; 
       }

       if(this.dispo <= 0 && this.deliver < 0) {
          text.firstChild.nodeValue = "Wird nachgeliefert"; 
       }
     }
  });
 });
}

/* end of orbiz */

/*ToolTip functions*/
var offsetxtooltip=-60 //Customize x offset of tooltip
var offsetytooltip=20 //Customize y offset of tooltip
var enabletip=false;



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

function tooltip(thetext){
    if (document.getElementById("tooltip")) {
        tipobj = document.getElementById("tooltip");
	tipobj.innerHTML=thetext;
    }
    	if(thetext == '')
		enalbetip=false;
	else
		enabletip=true;
}
   

function positiontip(E){
if (enabletip){
var curX=E?E.pageX : event.x+ietruebody().scrollLeft;
var curY=E?E.pageY : event.y+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var rightedge=!E? ietruebody().clientWidth-event.clientX-offsetxtooltip : window.innerWidth-E.clientX-offsetxtooltip-20
var bottomedge=!E? ietruebody().clientHeight-event.clientY-offsetytooltip : window.innerHeight-E.clientY-offsetytooltip-20

var leftedge=(offsetxtooltip<0)? offsetxtooltip*(-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=!E? ietruebody().scrollLeft+event.clientX+"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+offsetxtooltip+"px"

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight)
tipobj.style.top=!E? ietruebody().scrollTop+event.clientY-offsetytooltip+"px" : window.pageYOffset+E.clientY-tipobj.offsetHeight-offsetytooltip+"px"
else
tipobj.style.top=curY+offsetytooltip+"px"
tipobj.style.visibility="visible"
}
tipobj.style.visibility="visible"
}

function hidetooltip(){
enabletip=false
tipobj.style.visibility="hidden"
tipobj.innerHTML="";
tipobj.style.left="-1000px"
}


/*End tooltip functions*/


