// JavaScript Document

function addFavoriti(url, titolo) {
	if( window.sidebar && window.sidebar.addPanel ) {
		if (navigator.userAgent.lastIndexOf("Netscape") != -1) {
			window.sidebar.addPanel( titolo, url, '' );
		} else {
			window.sidebar.addPanel( titolo, url, '' );
		}
	} else {
		window.external.AddFavorite( url, titolo );
	}
}




function openPopup(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


function pulisciText(el) {
  if (el.defaultValue==el.value) el.value = ""
}
function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

function CalcolaTotaleOrdine(p) {
	var tx=document.tsform.tipospedizione.value
	//var pos=tx.indexOf(":");
	
	tipopag=tx.substr(3,1);
	if (tx.substr(3,1)=="B") document.invioordine.tipopaglettera.value="B";
	if (tx.substr(3,1)=="C") document.invioordine.tipopaglettera.value="C";
	if (tx.substr(3,1)=="A") document.invioordine.tipopaglettera.value="A";
	posdp=tx.indexOf(":");
	posdescrz=tx.lastIndexOf(":");
	posdescrz2=tx.lastIndexOf("#");
	document.invioordine.tipopag.value=tx.substr(posdescrz+1,posdescrz2-posdescrz-1);
	document.invioordine.idspese.value=tx.substr(posdescrz2+1);
	tx=tx.substr(0,posdp);

	var spese = Number(tx);
	document.invioordine.importospese.value="€. " + spese +",00";
	document.invioordine.spese.value=spese;

	var totale=p+spese;

	
	totale=""+totale;
	ultimopunto=totale.indexOf(".");

	var text="";
	for (var i=0;i<totale.length;++i) {
		text=text+totale.substr(totale.length-1-i,1);
	}
	
	if (text.indexOf(".")==-1) {
		text="00,"+text;
	}
	
	if (text.substr(2,1)==".") {
	text=text.substr(0,2)+","+text.substr(3);
	}
	if (text.substr(1,1)==".") {
	text="0"+text.substr(0,1)+","+text.substr(2);
	}
	
	var giusto="";
	for (var i=0;i<text.length;++i) {
		giusto=giusto+text.substr(text.length-i-1,1);
	}
	totale=giusto;
	//alert(roundNumber(giusto.replace(',','.'),2));
	document.invioordine.totaleordine.value=roundNumber(giusto.replace(',','.'),2);
	document.invioordine.totale.value="€. " + roundNumber(giusto.replace(',','.'),2);
}

function submitForm() { 

	if (confirm("\nL'ordine sarà inviato. \n\n Riceverete una conferma automatica d'ordine.\n\n Confermi l'invio?")) 
		{return true; }
	else {
		alert("\nHai interrotto l'invio"); 
		return false; }
}


//----------------------------------------------------------------------------------
//Highlight form element- © Dynamic Drive (www.dynamicdrive.com)
//For full source code, 100's more DHTML scripts, and TOS,
//visit http://www.dynamicdrive.com
var highlightcolor="#E5E5E5"
var ns6=document.getElementById&&!document.all
var previous=''
var eventobj

//Regular expression to highlight only form elements
var intended=/INPUT|TEXTAREA|SELECT|OPTION/

//Function to check whether element clicked is form element
function checkel(which){
if (which.style&&intended.test(which.tagName)){
if (ns6&&eventobj.nodeType==3)
eventobj=eventobj.parentNode.parentNode
return true
}
else
return false
}

//Function to highlight form element
function highlight(e){
eventobj=ns6? e.target : event.srcElement
if (previous!=''){
if (checkel(previous))
previous.style.backgroundColor=''
previous=eventobj
if (checkel(eventobj))
eventobj.style.backgroundColor=highlightcolor
}
else{
if (checkel(eventobj))
eventobj.style.backgroundColor=highlightcolor
previous=eventobj
}
}
//----------------------------------------------------------------------------------

