// JavaScript Document
//Menu
function mostra(element){
	var elem=element;
	document.getElementById(elem).style.visibility = "visible";
 }
 function nascondi(element){
	var elem=element;
	document.getElementById(elem).style.visibility = "hidden";
 }
//Controllo Contatti
function controllaInser(nomeModulo) {
	  if (nomeModulo.nome.value == "") {
				alert("Devi inserire il nome");
				nomeModulo.nome.focus();
				return false;
			}
	   if (nomeModulo.cog.value == "") {
				alert("Devi inserire il cognome");
				nomeModulo.cog.focus();
				return false;
			}
	  if (nomeModulo.mail.value == "") {
				alert("Devi inserire l' e-mail");
				nomeModulo.mail.focus();
				return false;
			}
	   if(!check(nomeModulo.mail.value)){
				alert("Formato e-mail non corretto");
				nomeModulo.mail.focus();
				nomeModulo.mail.select();
				return false;
			}
		if (nomeModulo.note.value == "") {
				alert("Devi inserire il messaggio");
				nomeModulo.note.focus();
				return false;
			}
		if(!nomeModulo.accetto.checked)
		{
			alert("Per poter proseguire bisogna Dare il Consenso spuntando l'apposita casella!");
			nomeModulo.accetto.focus();
			return false;
			}
			
	return true;
}
//Controllo Cerca
function cerca(nomeModulo) {
	  if (nomeModulo.nome.value == "" && nomeModulo.tipo.value == "" && nomeModulo.marca.value == "" && nomeModulo.prezzo.value == "" && nomeModulo.prezzo2.value == "" && nomeModulo.disp.value == "") {
				alert("Devi inserire almeno un valore");
				nomeModulo.nome.focus();
				return false;
			}
	  if (nomeModulo.prezzo.value != "" && nomeModulo.prezzo2.value == "") {
				alert("Devi inserire il secondo limite di prezzo");
				nomeModulo.prezzo2.focus();
				return false;
			}
	  if (nomeModulo.prezzo2.value != "" && nomeModulo.prezzo.value == "") {
				alert("Devi inserire il primo limite di prezzo");
				nomeModulo.prezzo.focus();
				return false;
			}
	 if (nomeModulo.prezzo2.value != ""  && nomeModulo.prezzo.value<=0) {
				alert("Il Prezzo deve essere maggiore di 0");
				nomeModulo.prezzo.focus();
				nomeModulo.prezzo.select();
				return false;
			}
	 if (nomeModulo.prezzo.value != ""  && nomeModulo.prezzo2.value<=0) {
				alert("Il secondo Prezzo deve essere maggiore di 0");
				nomeModulo.prezzo2.focus();
				nomeModulo.prezzo2.select();
				return false;
			}
	 if (nomeModulo.prezzo.value != ""){
		if ((nomeModulo.prezzo.value-nomeModulo.prezzo2.value)>=0) {
				alert("Il secondo Prezzo deve essere  maggiore del primo prezzo");
				nomeModulo.prezzo2.focus();
				nomeModulo.prezzo2.select();
				return false;
				}
	 }
	 if(nomeModulo.disp.value>100){
				alert("La disponibilità deve essere minore di 101");
				nomeModulo.disp.focus();
				nomeModulo.disp.select();
				return false;
			}
	  return true;
	}
// Solo Numeri
function soloNumeri(campo, ev)
{
 var tasto,carattereTasto;

 if (window.event)  //Modello ad eventi IE
   tasto = window.event.keyCode;
 else if (ev)    //Modello ad eventi NN
    tasto = ev.which;
 else		    //Modello ad eventi non supportato
    return true;
 
 carattereTasto = String.fromCharCode(tasto);
  // verifica tasti particolari tipo canc, invio, ...
  
 if ((tasto==null) || (tasto==0) || (tasto==8) || 
     (tasto==9) || (tasto==13) || (tasto==27) )
   return true;
  else if ((("0123456789").indexOf(carattereTasto) > -1))
         {
           window.status = "";
           return true;
         }
       else
         {
           window.status = "Il campo accetta solo numeri"; 
           return false;
         }
}
function check(email) {
var caratteriNonValidi = " /:,;"
			
for (var i=0; i<caratteriNonValidi.length; i++) {
	var noCar = caratteriNonValidi.charAt(i)
	if (email.indexOf(noCar,0) > -1) 
		return false;
			
}

//cerchiamo @
atPos = email.indexOf("@",1)			
if (atPos == -1) 
	return false;

//ci deve essere solo un simbolo @	
if (email.indexOf("@",atPos+1) != -1)  
	return false;

//cerchiamo il .		
dotPos = email.indexOf(".",atPos) 
if (dotPos == -1) 
	return false;

//ci deve essere solo un . (punto) 
if (email.indexOf(".",dotPos+1) != -1) 	
	return false;

//ci devono essere da 2 a 3 caratteri dopo l'ultimo .
if (email.length - dotPos>4 || email.length - dotPos<3) 
	return false;
			
return true;				
}
	/*Ingrandisci Immagine*/	

function ingrandisci(name){
	 var nome=name;
	 msg=open(nome,"DisplayWindow","toolbar=no,directories=no,menubar=no,width=800,height=600");
}
/*****Scroll*******/
function getObj(){
	return document.getElementById("corpoInterno");
}
var contat=0;
var num=0;
var tempSu=0;
function partiSu(){
	  if(!tempSu){
		tempSu=setInterval("scorriSu()",1);
		}	
	}
function blockSu(){
	if(tempSu)
		clearInterval(tempSu);
	tempSu=0;
}
function scorriSu(){  
  var elemento=getObj();
  var altezzaScroll=document.getElementById("corpoInterno").clientHeight;
  var altezzaAz=document.getElementById("corpo").clientHeight;
 if((altezzaScroll-altezzaAz)>contat)
	{ 
	  	  num=num-1;	
		  elemento.style.top=num+"px";	
		  contat=contat+1;
	  }
}
var tempGiu=0;
function partiGiu(){
	  if(!tempGiu){
		tempGiu=setInterval("scorriGiu()",1);
		}	
	}
function blockGiu(){
	if(tempGiu)
		clearInterval(tempGiu);
	tempGiu=0;
}
function scorriGiu(){  
 var elemento=getObj();
	if(num!=0){
	contat=contat-1;
	num=num+1;	
	elemento.style.top=num+"px";
	}
}
function paginaSuc(){  
  var elemento=getObj();
  var altezzaScroll=document.getElementById("corpoInterno").clientHeight;
  var altezzaAz=document.getElementById("corpo").clientHeight;
 if(altezzaAz<altezzaScroll){
  if((altezzaScroll-(altezzaAz+contat))>altezzaAz)
	{ 
	         num=num-altezzaAz;	
		     elemento.style.top=num+"px";	
		     contat=contat+altezzaAz;
	} 
	else{
		  num=num-(altezzaScroll-(altezzaAz+contat));
		  elemento.style.top=num+"px";
		  contat=contat+(altezzaScroll-(altezzaAz+contat));
		}
 }
  }
function paginaPre(){  
  var elemento=getObj();
  var altezzaScroll=document.getElementById("corpoInterno").clientHeight;
  var altezzaAz=document.getElementById("corpo").clientHeight;
  if((contat-altezzaAz)>0)
	{ 
	      num=num+altezzaAz;	
		  elemento.style.top=num+"px";	
		  contat=contat-altezzaAz;
	}
	else{
		num=0;
		contat=0;
		elemento.style.top=num+"px";
		}
}
/*Preventivo*/
function arrotonda(cifra)
{
 var temp =  Math.round(cifra * 100);
 temp = temp / 100;
 return temp; 
}


function calcola()
{
 with (document.ordine)
  {
   totaleN.value = arrotonda(prezzo.value * quantita.value);
   tasse.value = arrotonda(totaleN.value * 0.20); 
  
     /*for (i=0; i < spedizione.length; i++)
   if (spedizione[i].checked)
         costoSpedizione = parseFloat(spedizione[i].value);*/
   totale.value = arrotonda(parseFloat(totaleN.value) + parseFloat(tasse.value));
     
  }
}
function seleziona(element){
	element.select();
	}
/*News*/
var IDP=0;
function parti(){
	if(!IDP)
	  IDP=setInterval("muoviA()",70);
}
function getObj(){
	return document.getElementById("new");
}

var x=180;
var c=0;
var top=180;
var contat=0;

function muoviA(){
var elemento=getObj();
var altezza=document.getElementById("new").clientHeight;
if((altezza+180)==contat)
	{  
		contat=0;
		x=180;
		}
else{
	elemento.style.left=0+"px";
	elemento.style.top=x+"px";
	contat++;
	x--;
	}
}
function block(){
	if(IDP)
		clearInterval(IDP);
	IDP=0;
}
/*****************/
