function trim(s) {
	
 return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
 
}

function numero(campo) {

  numero = campo;
  if (isNaN(numero)||(numero == null) || (numero.length == 0)) {
   alert("Controllare i dati.");
   return false;
   //break;
   } else {
   	// verifico se esistono duplicati
    //return true;
  }
}

function controlla() {
 
 var arrayDiElem = document.getElementById('numingioco').getElementsByTagName('input');
 lun = arrayDiElem.length; //individuo la lunghezza dell'array 
 //alert(lun);
 for (n=0;n<=lun;n++) {
  numero = trim(arrayDiElem[n].value);
  //alert(numero);
  if (isNaN(numero)||(numero == null) || (numero.length == 0)) { 
   alert("Controllare i dati. Non sono stati inseriti tutti i numeri.");
   return false;
   //break;
   } else {
   	// verifico se esistono duplicati
    //return true;
    for (m=n+1;m<lun;m++) {
    	if (numero == trim(arrayDiElem[m].value)) {
    		alert("Controllare i dati. Il numero "+numero+" e' stato inserito piu' volte.");
        return false;
        //break;
    	}
    }
  }
 }
}

function ResetForm(which){
 var pass=true
 var first=-1
 if (document.images){
   for (i=0;i<which.length;i++){
      var tempobj=which.elements[i]
      if (tempobj.type=="text"){
        eval(tempobj.value="")
        if (first==-1) {first=i}
      }
   else if (tempobj.type=="checkbox") {
     eval(tempobj.checked=0)
     if (first==-1) {first=i}
     }
   }
 }
 which.elements[first].focus()
 return false
}

function isEmpty(s)
{
   return ((s == null) || (s.length == 0))
}

function isChecked(s)
{
   return ((s == null) || (s == false))
}

function isEmail(str) {

  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

function checkOrdine(){

	msg = checkOrd();
	if (msg=="NO_ERRORE"){
		return true;
	}else if (msg=="CONF"){ 
		return confirm('Per poter utilizzare SystemPack415 occorre avere SuperEnalotto System Plus o System. Procedere con l\'ordine?');
	}else { 
		alert(msg);
		return false;
	}
}

function checkOrd(){
        msg = new String();
        msg ="NO_ERRORE";

		if ((document.getElementById('ordine').SYSTEM_PLUS.checked == false)&&(document.getElementById('ordine').SYSTEM.checked == false)
		&&(document.getElementById('ordine').STUDIOSYSTEM_STANDARD.checked == false)&&(document.getElementById('ordine').PACK_415.checked == true)){
		   msg="CONF";
		}	                
    if (isEmail(document.getElementById('ordine').email.value) == false){
		   msg="Inserire un indirizzo e-mail valido.";
		}
		if ( isEmpty(document.getElementById('ordine').provincia.value) ) {
			msg="Il campo Provincia non e' stato compilato.";
		}
		if ( isEmpty(document.getElementById('ordine').cap.value) ) {
			msg="Il campo CAP non e' stato compilato.";
		}		
		if ( isEmpty(document.getElementById('ordine').citta.value) ) {
			msg="Il campo Citta' non e' stato compilato.";
		}
		if ( isEmpty(document.getElementById('ordine').indirizzo.value) ) {
			msg="Il campo Indirizzo non e' stato compilato.";
		}
		if ( isEmpty(document.getElementById('ordine').cognome.value) ) {
			msg="Il campo Cognome non e' stato compilato.";
		}
		if ( isEmpty(document.getElementById('ordine').realname.value) ) {
			msg="Il campo Nome non e' stato compilato.";
		}
		if ((document.getElementById('ordine').SYSTEM_PLUS.checked == false)&&(document.getElementById('ordine').SYSTEM.checked == false)&&(document.getElementById('ordine').CRUCISYSTEM.checked == false)&&(document.getElementById('ordine').FASTSYSTEM.checked == false)
		&&(document.getElementById('ordine').FINDSYSTEM.checked == false)&&(document.getElementById('ordine').PACK_415.checked == false)&&(document.getElementById('ordine').STUDIOSYSTEM_STANDARD.checked == false)
		&&(document.getElementById('ordine').STUDIOSYSTEM_PROFESSIONAL.checked == false)&&(document.getElementById('ordine').CRUCI_PLUS.checked == false)){
		   msg="Non e' stato selezionato alcun prodotto.";
		}
	
	 return msg;
    }
   
function checkContatto(){

	msg = checkCont();
	if (msg=="NO_ERRORE"){
		return true;
	}else{ 
		alert(msg);
		return false;
	}
}

function checkCont(){
        msg = new String();
        msg ="NO_ERRORE";               

    stripHTML(document.getElementById('contatto').messaggio);
       
		if ( isEmpty(document.getElementById('contatto').messaggio.value) ) {
			msg="Non e' stato compilato il testo del messaggio.";
		}		
		if ( isEmpty(document.getElementById('contatto').oggetto.value) ) {
			msg="Il campo Oggetto non e' stato compilato.";
		}
		if ( (document.getElementById('contatto').categoria.value=="scegli") ) {
			msg="Non e' stata selezionata la Categoria del messaggio.";
		}		
    if (isEmail(document.getElementById('contatto').email.value) == false){
		   msg="Inserire un indirizzo e-mail valido.";
		}
		
	 return msg;
    }   
    
function controllacond(){

	msg = checkcond();
	if (msg=="NO_ERRORE"){
		return true;
	}else{ 
		alert(msg);
		return false;
	}
}   
    
function checkcond(){
	
    msg = new String();
    msg ="NO_ERRORE";
    var selezionate = 0;        
    
    if (document.sistcond.pari.checked == true){
		   selezionate = selezionate +1;
		}
    if (document.sistcond.somma.checked == true){
		   selezionate = selezionate +1;
		}
    if (document.sistcond.distanza.checked == true){
		   selezionate = selezionate +1;
		}
    if (document.sistcond.interruzioni.checked == true){
		   selezionate = selezionate +1;
		}
    if (document.sistcond.consecutivita.checked == true){
		   selezionate = selezionate +1;
		}
    if (document.sistcond.simmetrie.checked == true){
		   selezionate = selezionate +1;
		}
		if (selezionate>3) {
		   msg="Non e' possibile selezionare piu' di tre condizioni.";
		}	
		if (selezionate<1) {
		   msg="Occorre selezionare almeno una condizione.";
		} 
	 return msg;
    }    
    
function pr2(filename) {window.open(filename,'','menubar=yes,location=no,toolbar=no,status=no,scrollbars=yes,resizable=no')}    

function stripHTML(){
var re= /<\S[^><]*>/g
for (i=0; i<arguments.length; i++)
arguments[i].value=arguments[i].value.replace(re, "")
}

function checknums_old() {
 var inputs=document.getElementsByTagName('input');
 for (var i=0;i<inputs.length;i++)
    {
      if(inputs[i].value==3) {	   
	   //inputs[i].setAttribute("value",'1'); 
	   alert(inputs[i].value);  
      }
    }  
}

function checknums() {
 var inputs=document.getElementsByTagName('input');
 var combinazioni=document.getElementById('numcomb').value;
 var numeri=combinazioni*6;
 for (var i=0;i<=numeri;i++)
    {
     if ((inputs[i].type=="text")&&(isNaN(inputs[i].value)||(inputs[i].value == null) || (inputs[i].value.length == 0))) { 
     alert("Controllare i dati. Non sono stati inseriti tutti i numeri.");
     return false;
     //break;
     }
    }  
}

function resettaForm() {
 var inputs=document.getElementsByTagName('input');
 for (var i=0;i<=inputs.length;i++)
    {
     if (inputs[i].type=="text") { 
     inputs[i].value="";
     //return false;
     //break;
     }
    }  
}