// <![CDATA[
$(document).ready(

   function()
     {
     document.getElementById("purchase").disabled=false; 
     $("#purchase").click(function(){
             //someone pressed the order button
             orderquantity = $("#productquantity").attr("value")
             if (isNaN(orderquantity) | orderquantity=='' | orderquantity<=0) return false;
             if (parseInt(orderquantity) > parseInt($("#stock").attr("value")))
                { 
                 alert($("#buyhint1").attr("value") +" "+ $("#stock").attr("value") +" "+ $("#buyhint2").attr("value")+".");
                 return false;
                 }
             document.getElementById("purchase").disabled=true;  
             $("#purchase").fadeTo("slow",0.2);
             $("#spinner").fadeIn("slow");
             document.getElementById("cartview").style.display='block' // make cart visible
             var TS= new Date().getTime()
             attributes = shopGetCurrentAttributes() // getter in attributeselector
             // ajax request
             
             units_id = $("#productid").attr("value")+'-'+attributes.join("-")
             $.get($("#shopurl").attr("title")+"/cart",
           {ts:TS, units_id: units_id,  quantity: orderquantity,productid: $("#productid").attr("value"), add:1 },
           function(response){
              var rs=response.split(':')

              var spanp  = document.createElement( "span" )
                  spanp.setAttribute('id', 'cardproducts');
                  spanp.appendChild(document.createTextNode(rs[0]))

              var spant  = document.createElement( "span" )
                  spant.setAttribute('id', 'cardtotal');
                  spant.appendChild(document.createTextNode(rs[1]))
              
              if (response.length==0) {alert('ERROR')}
              else {
                    $("#cardproducts").replaceWith(spanp);
                    $("#cardtotal").replaceWith(spant);
                    document.getElementById("cardtotaldisplay").style.display='block';
                    document.getElementById("cardbilldisplay").style.display='block';
                    playSound('/++resource++www/buy.wav')
                    $("#purchase").fadeTo("slow",1);
                    $("#spinner").fadeOut("slow");
                    //document.getElementById('spinner').style.visibility='hidden';
                    document.getElementById("purchase").disabled=false; 
                   }
             });
           
         });
  
      }
)
// ]]>


