

function eurizza(a)
{
var cercaquesto = /./g;
s=new String(a);
s=s.replace(cercaquesto,",");
s=s.round(2);
return s
}

function deeurizza(a)
{
s=new String(a);
s=s.replace(",",".");
window.alert(s);
return s
}

function arrotonda(number,X) {
// rounds number to X decimal places, defaults to 2
X = (!X ? 2 : X);
return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}

function prezza(){
						  var ap=document.getElementById('actprice').value;
						  var ftt=document.getElementById('fatcor').value;
						  var x_1=document.getElementById('x1').value;
						  var x_2=document.getElementById('x2').value;
						  var x_3=document.getElementById('x3').value;
						  var cercaquesto = /,/g;
						  ap=ap.replace(cercaquesto,'.');
						  ftt=ftt.replace(cercaquesto,'.');
						  x_1=x_1.replace(cercaquesto,'.');
						  x_2=x_2.replace(cercaquesto,'.');
						  x_3=x_3.replace(cercaquesto,'.');
						  //window.alert(ap);
						  document.getElementById('prezzo1').value=arrotonda( (ap)*(ftt)*(x_1),2 );
						  //Prima della modifica anche i prezzi dei ditte e rivenditori venivano calcolati dal fattore moltiplicativo
							/*	  document.getElementById('prezzo2').value=arrotonda( (ap)*(ftt)*(x_2),2 );
								  document.getElementById('prezzo3').value=arrotonda( (ap)*(ftt)*(x_3),2 );  */
						  //Dopo la modifica avviene al contrario : si calcolano i fattori in base al prezzo che si vuole ottenere.
						  var prezzo_2=document.getElementById('prezzo2').value;
						  var prezzo_3=document.getElementById('prezzo3').value;
						  prezzo_2=prezzo_2.replace(cercaquesto,'.'); //Sostituisco punto con virgola nel prezzo
						  prezzo_3=prezzo_3.replace(cercaquesto,'.'); //Sostituisco punto con virgola nel prezzo
						  document.getElementById('x2').value=( prezzo_2/( (ap)*(ftt) ) );
						  document.getElementById('x3').value=( prezzo_3/( (ap)*(ftt) ) );


						  /*document.getElementById('prezzo1').value=( (ap)*(document.getElementById('fatcor').value)*(document.getElementById('x1').value) );
						  document.getElementById('prezzo2').value=( (ap)*(document.getElementById('fatcor').value)*(document.getElementById('x2').value) );
						  document.getElementById('prezzo3').value=( (ap)*(document.getElementById('fatcor').value)*(document.getElementById('x3').value) );
						  */
						  }
						  
function popitup(url)
{
	if (window.newwindow) {newwindow.close();}
	newwindow=window.open(url,'name','height=400,width=590,scrollbars');
	if (window.focus) {newwindow.focus();}
	return false;
}

function popitup_listino(url)
{
	if (window.newwindow_sizeable) {newwindow_sizeable.close();}
	newwindow_sizeable=window.open(url,'name','scrollbars');
	if (window.focus) {newwindow_sizeable.focus();}
	return false;
}

function popitup_sizeable(url,name,altezza,larghezza)
{
	if (window.newwindow_sizeable) {newwindow_sizeable.close();}
	newwindow_sizeable=window.open(url,'name','height='+altezza+',width='+larghezza);
	if (window.focus) {newwindow_sizeable.focus();}
	return false;
}

function pop_up_msg(pop_up_text)
{
	window.alert("--------------------------------------------------------------\n"+pop_up_text+"\n--------------------------------------------------------------");
}

function registervars()
{
id_cliente=document.order_form_pop.iduser;
data_ordine=document.order_form_pop.data;
}

function provv_calc()
{
var importo=this.form.importo;
var percentuale=this.form.percentuale;
provvigione_euro=importo*percentuale;
return provvigione_euro;
}

function chek_iduser()
{
var complete=true;
var utente=document.forms.order_form.iduser_fake.value;
if ((utente == 0) || (utente == -1))
	{
	alert("Non č stato specificato un cliente valido.\nRiprovare!");
	complete = false;
	}
return complete;
}

function conferma_carrello()
{
del_sel='';pay_sel='';
mydelivery1 = document.getElementById('delivery1').checked;
mydelivery2 = document.getElementById('delivery2').checked;
mydelivery3 = document.getElementById('delivery3').checked;
mydelivery4 = document.getElementById('delivery4').checked;
if ((mydelivery1&&mydelivery2&&mydelivery3&&mydelivery4)==false) {del_sel='NESSUNA CONSEGNA SELEZIONATA';}
if (mydelivery1==true) {del_sel='Ririro a mano presso il laboratorio Magojet';}
if (mydelivery2==true) {del_sel='Posta Prioritaria';}
if (mydelivery3==true) {del_sel='Corriere espresso';}
if (mydelivery4==true) {del_sel='Cinisello a domicilio';}
mypayment1 = document.getElementById('payment1').checked;
mypayment2 = document.getElementById('payment2').checked;
mypayment3 = document.getElementById('payment3').checked;
if (mypayment1==true) {pay_sel='Contante';}
if (mypayment2==true) {pay_sel='Carta di credito';}
if (mypayment3==true) {pay_sel='Bonifico bancario anticipato';}

delivery_payment="E' stato selezionato il seguente tipo di consegna:\n # "+del_sel+"\ned il seguente tipo di pagamento:\n # "+pay_sel+"\n"; 
return delivery_payment;
}

function conferma(usatesto)
{
var testo= new Array(8);
testo[0]="Si desidera archiviare la provvigione inserendola tra le pagate? \n\n(non sarā possibile annullare la operazione)";
testo[1]="OPERAZIONE ALTAMENTE SCONSIGLIATA \n\nSi desidera eliminre definitivamente il cliente dall'archivio? \n\n(non sarā possibile annullare la operazione)";
testo[2]="CONFERMA ORDINE \n\nSi desidera confermare presente carrello, convertendolo in un ordine?\n\n(non sarā possibile annullare l'operazione)";
testo[3]="CONFERMA RIMOZIONE \n\nSi desidera confermare la rimozione?\n\n(non sarā possibile annullare l'operazione)";
testo[4]="CONFERMA AVVENUTA SPEDIZIONE \n\nSi desidera confermare il presente ordine come 'Spedito'?\n\n(non sarā possibile annullare l'operazione)";
testo[5]="CONFERMA MODIFICA FATTORE PROVVIGLIONALE \n\nSi desidera salvare la modifica al presente fattore provvigionale?";
testo[6]="CONFERMA INVIO NEWSLETTER\n\nSi desidera inviare la Newsletter selezionata?\n\nVerrā creato un report di invio, eventualmente\nsovrascrivendo il precedente.";
testo[7]="CONFERMA NASCONDI PER SEMPRE \n\nSi desidera confermare l'occultamento irreversibile della selezione dall'area di Amministrazione?\n\n(non sarā possibile annullare l'operazione)";
testo[8]="CONFERMA CAMBIO VISIBILITA' \n\nSi desidera confermare il cambio di visibilitā?\n\n(l'operazione č reversibile)";


var risposta=window.confirm(testo[usatesto]);
return risposta;
}

function trbg(src,colore) 
{
	if (browser.isIE == true) 
	{ 
	//document.all[src].style.cursor = 'hand';
	document.all[src].bgColor = colore; 				
	}
	else
	{
	myass = document.getElementById(src);
	myass.style.backgroundColor = colore;
	//myass.style.cursor='pointer';	
	}
}


function payment_release(numerovoce)
{
	if (numerovoce=='1')
	{
	//window.alert("Hai ciclo:"+numerovoce);
	mylukyass = document.getElementById('payment1');//contante
	mylukyass.disabled=false;
	mylukyass.checked=true;
	mylukyass = document.getElementById('payment2');//Carta di credito
	mylukyass.disabled=true;
	mylukyass = document.getElementById('payment3');//Bonifico
	mylukyass.disabled=true;
	mylukyass = document.getElementById('payment4');//Contrassegno
	mylukyass.disabled=true;	
	}
	if (numerovoce=='2')
	{
	//window.alert("Hai ciclo:"+numerovoce);
	mylukyass = document.getElementById('payment1');
	mylukyass.disabled=true;
	mylukyass = document.getElementById('payment2');
	//mylukyass.disabled=false; disabilitato perchč il pagamento con la Carta di Credito non č attivo
	mylukyass = document.getElementById('payment3');
	mylukyass.disabled=false;
	mylukyass.checked=true;//pagamento predefinito se non ritira a mano / consegna a domicilio
	mylukyass = document.getElementById('payment4');
	mylukyass.disabled=false;	
	}
	if (numerovoce=='3')
	{
	//window.alert("Hai ciclo:"+numerovoce);	
	mylukyass = document.getElementById('payment1');
	mylukyass.disabled=true;
	mylukyass = document.getElementById('payment2');
	//mylukyass.disabled=false; disabilitato perchč il pagamento con la Carta di Credito non č attivo
	mylukyass = document.getElementById('payment3');
	mylukyass.disabled=false;
	mylukyass.checked=true;
	mylukyass = document.getElementById('payment4');
	mylukyass.disabled=false;	
	}
	if (numerovoce=='4')
	{
	//window.alert("Hai ciclo:"+numerovoce);
	mylukyass = document.getElementById('payment1');
	mylukyass.disabled=false;
	mylukyass.checked=true;
	mylukyass = document.getElementById('payment2');
	mylukyass.disabled=true;
	mylukyass = document.getElementById('payment3');
	mylukyass.disabled=true;
	mylukyass = document.getElementById('payment4');
	mylukyass.disabled=true;	
	}
}



function check_registrationform()
{
	/*var suffix=document.forms.users.categoria_f.value;
	var name=document.forms.users.name+(suffix).value;
	var pwd=document.forms.users.pwd.value;
	var pwd_conf=document.forms.users.pwd_conf.value;
	var mailaddr=document.forms.users.mailaddr.value;*/
	var suffix=document.getElementById('categoria_f').value;
	var name=document.getElementById('name'+suffix).value;
	var pwd=document.getElementById('pwd'+suffix).value;
	var pwd_conf=document.getElementById('pwd_conf'+suffix).value;
	var mailaddr=document.getElementById('mailaddr'+suffix).value;
	var privacy_=document.getElementById('privacy1').checked;
	var messaggio='';


	if (privacy_==false)
	{	
		messaggio=messaggio+"NON E' STATO ESPRESSO IL CONSENSO AL TRATTAMENTEO DEI DATI SENSIBILI!\nLA REGISTRAZIONE NON POTRA' AVVENIRE.\n\n";
		complete = false;
	}
	if (pwd=='')
	{	
		messaggio=messaggio+"Il campo 'password' č vuoto. \n";
		complete = false;
	}
	if (pwd!=pwd_conf)
	{	
		messaggio=messaggio+"La 'password' inserita non coincide con quella di conferma. \n";
		complete = false;
	}
	if (mailaddr=='')
	{	
		messaggio=messaggio+"Il campo 'mail' č vuoto. \n";
		complete = false;
	}	
	if (messaggio=='')
	{
		complete = true;
	}
	if (messaggio!='')
	{
		window.alert(messaggio+"\nRIPROVARE!");
		messaggio='';
	}
return complete;
}

function check_update()
{
	var pwd=document.forms.users.pwd.value;
	var pwd_conf=document.forms.users.pwd_conf.value;
	var messaggio='';
	var complete;
	
	if (pwd=='')
	{	
		messaggio=messaggio+"Il campo 'password' č vuoto. \n";
		complete = false;
	}
	if (pwd_conf=='')
	{	
		messaggio=messaggio+"Il campo 'conferma password' č vuoto. \n";
		complete = false;
	}	
	if (pwd!=pwd_conf)
	{	
		messaggio=messaggio+"La 'password' inserita non coincide con quella di conferma. \n";
		complete = false;
	}
	if (messaggio=='')
	{
		complete=window.confirm("Confermate la modifica della vostra password in:\n"+document.forms.users.pwd.value+" - (per conferma: "+document.forms.users.pwd_conf.value+")\n\PREMERE 'OK' PER PROSEGUIRE");
	}
	if (messaggio!='')
	{
		window.alert(messaggio+"\nRIPROVARE!");
		messaggio='';
	}
return complete;
}

function check_users_agent_and_categoria()
{
	var name=document.forms.users.name.value;
	var pwd=document.forms.users.pwd.value;
	var pwd_conf=document.forms.users.pwd_conf.value;
	var mailaddr=document.forms.users.mailaddr.value;
	var idagent=document.forms.users.idagent.value;
	var idmk=document.forms.users.idmk.value;
	var messaggio='';

	if (name=='')
	{	
		messaggio=messaggio+"Il campo 'nome' č vuoto. \n";
		complete = false;
	}
	if (pwd=='')
	{	
		messaggio=messaggio+"Il campo 'password' č vuoto. \n";
		complete = false;
	}
	if (pwd!=pwd_conf)
	{	
		messaggio=messaggio+"La 'password' inserita non coincide con quella di conferma. \n";
		complete = false;
	}
	if (mailaddr=='')
	{	
		messaggio=messaggio+"Il campo 'mail' č vuoto. \n";
		complete = false;
	}			
	if (idagent<=0)
	{	
		messaggio=messaggio+"Non č stato specificato un agente valido.\n";
		complete = false;
	}
	if (idmk < 0)
	{
		messaggio=messaggio+"Non č stata specificata una categoria valida.\n";
		complete = false;
	}		
	if (messaggio=='')
	{
		complete = true;
	}
	if (messaggio!='')
	{
		window.alert(messaggio+"\nRIPROVARE!");
		messaggio='';
	}
return complete;
}

function fnesistecarrello()
{
var esistecarrello;
esistecarrello=1;
}

function conferma_carrello_old()
{
if (esistecarrello=='1') 
	{
	var avvenuta_conferma=window.confirm("ATTENZIONE\n\nIl logout determinerā la chiusura della sessione ma non cancellerā il contenuto dell'eventuale carrello aperto.\nSarā possibile confermare l'ordine in un secondo momento.\n\nSi desidera uscire senza confermare l'ordine?");
	}
if (esistecarrello=='0')
	{
	avvenuta_conferma=false;
	}	
return avvenuta_conferma;
}

function log_out()
{
var avvenuta_conferma=window.confirm("ATTENZIONE\n\nIl logout determinerā la chiusura della sessione ma non cancellerā il contenuto del carrello.\nSarā pertatno possibile confermare l'ordine in un secondo momento.\n\nSi desidera uscire senza confermare l'ordine?");
return avvenuta_conferma;
}

function check_brand()
{
if (document.forms.product_form.idbrand.value==0)
	{
	window.alert("ATTENZIONE\n\nIl marchio selezionato per il presente prodotto non č valido.\n\nSelezionarne uno dall'eleco a tendina.");
	return false;
	}
return true;
}

function showPrivacy(page)
{
win_terms_ids=window.open(page,"Termini_e_Condizioni","toolbar=no,location=no,alwaysRaised=yes,z-lock=yes,resizable=no,status=no,menubar=no,scrollbars=yes,width=450,height=346,screenX=50,screenY=0,left=50,top=0");
win_terms_ids.focus();
}


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];}
}

function round_ai_50cc(prezzo)
{
var prezzo,prezzo_round;
prezzo_round=Math.round(prezzo);
if ( (prezzo-prezzo_round)>0 ) {prezzo=Math.round(prezzo)+0.50;} else {prezzo=Math.round(prezzo);}
return prezzo;
}

function calcolatore()
{
var fc,b,p1,p2,p3,p1ar,p2ar,p3ar,mk1,mk2,mk3; 
p1=document.forms.product_form.price1;
p2=document.forms.product_form.price2;
p3=document.forms.product_form.price3;
p1ar=document.forms.product_form.price1ar;
p2ar=document.forms.product_form.price2ar;
p3ar=document.forms.product_form.price3ar;

mk1=document.forms.product_form.markup1;
mk2=document.forms.product_form.markup2;
mk3=document.forms.product_form.markup3;

b=document.forms.product_form.actprice_;
fc=document.forms.product_form.fatcor_;

p1.value=b.value*fc.value*mk1.value;
p2.value=b.value*fc.value*mk2.value;
p3.value=b.value*fc.value*mk3.value;
p1ar.value=round_ai_50cc(p1.value);
p2ar.value=round_ai_50cc(p2.value);
p3ar.value=round_ai_50cc(p3.value);
//alert(p1.value+' '+p2.value+' '+p3.value);
}

function getdiv(name)
{
			return (document.layers&&document.layers[name])?document.layers[name]:(document.all&&document.all[name]&&document.all[name].style)?document.all[name].style:document[name]?document[name]:(document.getElementById(name)?document.getElementById(name).style:0); 
}
function display_layer(iddellayer)
{
			/*write_div();*/ //document.write("<p>Testo provvisorio</p>");
			var winH=(window.innerHeight)?window.innerHeight+window.pageYOffset:document.body.clientHeight;
			var winW=(window.innerWidth)?window.innerWidth+window.pageXOffset:document.body.offsetWidth;
			var px="px";
			var idiv=null;
			var mastW=339;
			var mastH=400;
			
			idiv=getdiv(iddellayer);
			
			ns4=(document.layers)?true:false;
			
			if(ns4) { px=""; }
			//idiv.left=((winW/2)-(mastW/2))+px;
			//idiv.top=((winH/2)-(mastH/2))+px;
			
			//CON UNA SOLA FINESTRA DI POPUP
			idiv.left=((winW/2)-(mastW/2))+px;
			//CON IL SECONDO POPUP
			//idiv.left=((winW/2)-(mastW/2)+130)+px;
			
			//idiv.top=((winH/2)-(mastH/2))+px;
			idiv.top=50+px;			
			idiv.width=mastW+px;
			idiv.height=mastH+px;
			//Disbilitare questo comando per non far comparire il livello
			idiv.visibility=ns4?"show":"visible";
			
			//window.alert("window.innerHeight:"+winH+"\nwindow.innerWidth:"+winW);
			//document.write('<div id="master" name="master" style="position:absolute; left:'+((winW/2)-50)+'px; top:'+((winH/2)-50)+'px; width:100px; height:100px; z-index:1>ciao</div>');

}	


<!--
/*
  - Give Credit Where Its Due -
  Please acknowledge this article and its author, 
at
  least in code comments, when using this code.

  Author: Justin Whitford
  Source: www.evolt.org

  Thank you.
*/

/*
  filtery(pattern, list)
  pattern: a string of zero or more characters by 
which to filter the list
  list: reference to a form object of type, select

  Example:
  <form name="yourForm">
    <input type="text" name="yourTextField" 
onchange="filtery(this.value,this.form.yourSelect)
">
    <select name="yourSelect">
      <option></option>
      <option value="Australia">Australia</option>
       .......
*/
function filtery(pattern, list){
  /*
  if the dropdown list passed in hasn't
  already been backed up, we'll do that now
  */
  if (!list.bak){
    /*
    We're going to attach an array to the select 
object
    where we'll keep a backup of the original 
dropdown list
    */
    list.bak = new Array();
    for (n=0;n<list.length;n++){
      list.bak[list.bak.length] = new Array(list[n].value, list[n].text);
    }
  }

  /*
  We're going to iterate through the backed up 
dropdown
  list. If an item matches, it is added to the 
list of
  matches. If not, then it is added to the list of 
non matches.
  */
  match = new Array();
  nomatch = new Array();
  for (n=0;n<list.bak.length;n++){
    
	if(list.bak[n][1].toLowerCase().indexOf(pattern.toLowerCase())!=-1){
      match[match.length] = new Array(list.bak[n][0], list.bak[n][1]);
    }else{
      nomatch[nomatch.length] = new Array(list.bak[n][0], list.bak[n][1]);
    }
  }

  /*
  Now we completely rewrite the dropdown list.
  First we write in the matches, then we write
  in the non matches (questa seconda parte č omessa per accorciare la lista)
  */
  //clearselect(list)

  for (n=0;n<match.length;n++){
    list[n].value = match[n][0];
    list[n].text = match[n][1];
  }
  
  while (list.options[n]!= null){ 
  	list.options[n] = null //cancella la riga
    //list[n+match.length].value = null; //questo codice svuota la riga ma non la cancella!
    //list[n+match.length].text = null;
  }

  /*
  for (n=0;n<nomatch.length;n++){
    list[n+match.length].value = nomatch[n][0];
    list[n+match.length].text = nomatch[n][1];
  }
  */




  /*
  Finally, we make the 1st item seleted - this
  makes sure that the matching options are
  immediately apparent
  */
  list.selectedIndex=0;
}
// -->


function init_swap_plusminus_images() {
	
  var aryImages = new Array(2);

  aryImages[0] = "../img/plus.gif";
  aryImages[1] = "../img/minus.gif";

  for (i=0; i < aryImages.length; i++) {
    var preload = new Image();
    preload.src = aryImages[i];
  }
}

function swap_images(idimg_to_swap, imgIndex) {
	//window.alert(idimg_to_swap+"-"+imgIndex);

		var myImage = new Array(2);
		myImage[0] = new Image() 
		myImage[0].src = "http://www.magojet.com/img/plus.gif" 
		myImage[1] = new Image() 
		myImage[1].src = "http://www.magojet.com/img/minus.gif" 

		//ATTENZIONE: funziona sol con i tag <img> e NON con gli <input type=img> !!!!
		document.images[idimg_to_swap].src = myImage[imgIndex].src
}

function explodeimplode(divid, idimg_to_swap) {
//window.alert(idimg_to_swap);	
  if (document.getElementById(divid).style.display == 'none') 
	  { 
	  document.getElementById(divid).style.display = 'block';
	  swap_images(idimg_to_swap, 1);
	  //window.alert("0 "+divid+" "+imagename+" "+varname);			  
	  return false;
	  }
	  else
	  {
	  document.getElementById(divid).style.display = 'none';
	  swap_images(idimg_to_swap, 0);
	  //window.alert("1 "+divid+" "+imagename+" "+varname);			  
	  return false;
	  }
	  
}