    var showaddtobasket_pic = 0;
    var showaddtobasket_joint = 0;

    // getElementById egyszerűsítve
    function $div(id) { return document.getElementById(id); }

    // láthatóvá tesz egy divet
    function showDiv(_id) {
      $div(_id).style.display = 'block';
    }

    // elrejt egy divet
    function hideDiv(_id) {
      $div(_id).style.display = 'none';
    }

    if (navigator.appName.indexOf("Internet Explorer") > -1) { isIE = true; } else { isIE = false; }


    function IsNumeric(sText)
    {
       var ValidChars = "0123456789";
       var IsNumber=true;
       var Char;

       if (sText.length == 0) return false;
       for (j = 0; j < sText.length && IsNumber == true; j++)  {
          Char = sText.charAt(j);
          if (ValidChars.indexOf(Char) == -1)
          {
             IsNumber = false;
          }
       }
       return IsNumber;
    }

    /************************************/
    // Kosár kezelés
    function AddToBasket(artworkID, productID) {
       maxpiece = $("maxpiece_"+ artworkID + "_"+ productID).value;
//       piece = $("basket_"+ artworkID + "_"+ productID).selectedIndex + 1;
       piece = $("basket_"+ artworkID + "_"+ productID).value;
       if (IsNumeric(piece) == false) {
         alert('This is not a valid number!');
         $("basket_"+ artworkID + "_"+ productID).focus();
         return;
       }
       if (piece > maxpiece) {
         alert('Sajnos nem all rendelkezesre a kert termekszam!');
         return;
       }
       $("maxpiece_"+ artworkID + "_"+ productID).value = maxpiece - piece;

       new ajax ('/ajax.php', {
           postBody: 'action=addtobasket&artworkID='+artworkID + '&productID=' + productID + '&piece='+piece,
           update: $('resultdiv'),
           onComplete: UpToDateBasket
        });
	alert("We added the product to your basket!");
        return true;
    }

    function AddToWholesaleBasket(artworkID, productID) {
       maxpiece = $("maxpiece_"+ artworkID + "_"+ productID).value;
       piece = $("basket_"+ artworkID + "_"+ productID).value;
       if (IsNumeric(piece) == false) {
         alert('This is not a valid number!');
         $("basket_"+ artworkID + "_"+ productID).focus();
         return;
       }
       new ajax ('/ajax.php', {
           postBody: 'action=addtobasket&artworkID='+artworkID + '&productID=' + productID + '&piece='+piece,
           update: $('resultdiv'),
           onComplete: UpToDateBasket
        });
	alert("We added the product to your basket!");
        return true;
    }

    function AddToWizardBasket() {
       piece = $("wizardpiece").value;
       myartworkID = $("basketartworkID").value;
       myproductID = $("basketproductID").value;
       myjoint = $("basketjoint").value;

       if (IsNumeric(piece) == false) {
         alert('This is not a valid number!');
         $("wizardpiece").focus();
         return;
       }

       new ajax ('/ajax.php', {
           postBody: 'action=addtowizardbasket&artworkID='+ myartworkID + '&productID=' + myproductID + '&joint=' + myjoint + '&piece='+piece,
           update: $('resultdiv'),
           onComplete: UpToDateBasket
        });

	alert("We added the product to your basket!");
        return true;
    }

    function UpToDateBasket() {
    
       new ajax ('/ajax.php', {
           postBody: 'action=uptodatebasket',
           update: $('resultdiv'),
           onComplete: BasketFinalize
        });
    }

    function BasketFinalize() {
           $('basketcontent').innerHTML =  $('resultdiv').innerHTML;
    }

    function clearBasket() {

//           if (document.getElementById("nodeid").innerHTML == "272") {
//             document.getElementById("basketdetailed").style.display = "none";
//             document.getElementById("nobasket").style.display = "block";
//           }

           new ajax ('/ajax.php', {
           postBody: 'action=clearbasket',
           update: $('resultdiv'),
           onComplete: UpToDateBasket
        });

    }


    function hideLargePicture() {
        document.getElementById("overlay").style.display = "none";
        document.getElementById("overlaybigpicture").style.display = "none";
    }

    function showLargePicture(src, title) {

		  var myWidth = 0, myHeight = 0;
		  if( typeof( window.innerWidth ) == 'number' ) {
		    //Non-IE
		    myWidth = window.innerWidth;
		    myHeight = window.innerHeight;
		  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		    //IE 6+ in 'standards compliant mode'
		    myWidth = document.documentElement.clientWidth;
		    myHeight = document.documentElement.clientHeight;
		  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		    //IE 4 compatible
		    myWidth = document.body.clientWidth;
		    myHeight = document.body.clientHeight;
		  }
		
		
		  var scrOfX = 0, scrOfY = 0;
		  if( typeof( window.pageYOffset ) == 'number' ) {
		    //Netscape compliant
		    scrOfY = window.pageYOffset;
		    scrOfX = window.pageXOffset;
		  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		    //DOM compliant
		    scrOfY = document.body.scrollTop;
		    scrOfX = document.body.scrollLeft;
		  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		    //IE6 standards compliant mode
		    scrOfY = document.documentElement.scrollTop;
		    scrOfX = document.documentElement.scrollLeft;
		  }
		


          scrollWidth = document.body.scrollWidth;
          scrollHeight = document.body.scrollHeight;


        document.getElementById("overlay").style.width = scrollWidth  + "px";
        document.getElementById("overlay").style.height = scrollHeight + "px";
		titletext = "<div class='titletext'>"+ title +"</div>";
		closetext = "<div class='imagesclose'><a href='javascript:hideLargePicture()' style='color:#666; text-decoration:none;'>close</a></div>";
		document.getElementById("overlaybigpicture").innerHTML = titletext + closetext + "<img src='/"+ src +"' width='600' border='0' style='cursor:pointer; cursor:hand;' onclick='hideLargePicture()' />";
        document.getElementById("overlaybigpicture").style.top = Math.round((myHeight - 600) / 2) + scrOfY + "px";
        document.getElementById("overlaybigpicture").style.left = Math.round((myWidth - 600) / 2) + "px";

        document.getElementById("overlay").style.display = "block";
        document.getElementById("overlaybigpicture").style.display = "block";
     }
     
     
    function wizard_changeProduct(productID, type) {
	$("basketproductID").value = productID; 

       $('miniartworks').innerHTML = "Please wait, loading...";
       new ajax ('/ajax.php', {
           postBody: 'action=getwizardartwork&productID=' + productID + '&type='+ type,
           update: $('resultdiv'),
           onComplete: wizard_changeProduct_end
        });

       new ajax ('/ajax.php', {
           postBody: 'action=getwizardartworkprice&productID=' + productID,
           update: $('wizardprice')
        });


    }
    function wizard_changeProduct_end() {
	$('miniartworks').innerHTML = $('resultdiv').innerHTML;
	$('previewcover').innerHTML = "<img src='/images/blank_cover.jpg' width='357' height='300' />"
	showaddtobasket_pic = 0;
 	showAddToBasket();
    }

  
    function wizard_changeArtwork(artworkID, digit, type) {
	$("basketartworkID").value = artworkID; 

	$('previewcover').innerHTML = "<img src='/files/wizardproduct/"+ digit + type +".jpg' height='300' />"
	showaddtobasket_pic = 1;
	showAddToBasket();
    }

    function showAddToBasket() {
	if ((showaddtobasket_joint == 1) && (showaddtobasket_pic == 1)) {
	  $('wizardbasket').style.display = 'block';
        } else {
	  $('wizardbasket').style.display = 'none';
        }
    }

    function wizard_changeJoint(joint) {
	$('previewjoint').innerHTML = "<img src='/files/joint/"+ joint.value +".jpg' height='300' width='50' />"
	showaddtobasket_joint = 1;
	showAddToBasket();
	$("basketjoint").value = joint.value; 
    }
     
     
