// =================================================================================================================
//
//    FUNCIONS JAVASCRIPT COMUNS
//
// =================================================================================================================

   
   var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);
   var NSX = (navigator.appName == "Netscape");
   var IE4 = (document.all) ? true : false;


   function go() {
	box = document.forms[0].s1;
	destination = box.options[box.selectedIndex].value;
	if (destination) location.href = destination;
   }

	function clipFloat(num,dec){ 
		var t=num+""; 
		alert(t);
		if (t.indexOf(".") > 0) {
			//num = parseFloat(t.substring(0,(t.indexOf(".")+dec+1))); 
			num = t.substring(0,(t.indexOf(".")+dec+1));
			alert(num);
			num = num.replace(".",",");
		} else {
			//num = parseFloat(t+".00"); 
			num = t+",00"; 
		}
		alert(num);
		return (num) 
	} 
 
 	function clipFloat2(num){ 
		var t=num+""; 
		//alert(t);
		var ent = t.slice(0, t.length -4);
		//alert(ent);
		var dec = t.slice(t.length -4, t.length -2);
		//alert(dec);
		if (ent =="") ent = "0";
		num = ent + "," + dec;
		//alert(num);
		return (num) 
	} 

 
   function actualitza_preus(box,prod,preu,tipus,pes_mitja){

   	    unitats = box.options[box.selectedIndex].value;
   	    // així treballem amb sencers i el float del javascript no posa .999999999
   	    if (tipus==3) {
   	       preu_total = parseInt(unitats * preu*100) * parseInt(pes_mitja*100);
   	    } else {
   	       preu_total = parseInt(unitats*100) * parseInt(preu*100);
   	    }   
		//preu_total = preu_total / 10000;
		preu_total = clipFloat2(preu_total);
   	    //preu_total = preu_total.toFixed(2)
		//preu_total = clipFloat(preu_total,2);

   	    input_field = "import["+prod+"]";
   	    document.getElementById(input_field).value = preu_total;

   }

   function afegeix_cistella(producte){

        select = "sel_unitats["+producte+"]";
        box = document.getElementById(select);
	unitats = box.options[box.selectedIndex].value;

	//iframe = "iframe_cistella.php?addp="+producte+"&addu="+unitats+"&accio=1";
	iframe = "iframe_cistella.php?addp="+producte+"&addu="+unitats;

	if (IE4) {
		  document.iframe_cistella.location.href=iframe;
	} else {
		  //top.origen.location.href=ausel; // no funciona a edticool.com
		  window.iframe_cistella.location.href=iframe;
	}
   }
   
   
   function afegeix_cistella_rapida(producte){

        select = "sel_unitats["+producte+"]";
        box = document.getElementById(select);
	unitats = box.options[box.selectedIndex].value;
	
	pagina = "?addp="+producte+"&addu="+unitats;
	
	document.location.href=pagina;
	//self.parent.location.href=pagina;
	
   }