

function prendiElementoDaId(id_elemento) {
 var elemento;
 if(document.getElementById)
  elemento = document.getElementById(id_elemento);
 else
  elemento = document.all[id_elemento];
 return elemento;
}

function isEmail(string) {
if (string.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) != -1)
return 1;
else
return 0;
}
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}


function controllo(nome_form,tab,ag)
{
	/* si aggiunge una nuova if quando si inserisce una nuova tabella */
//alert('ok');
	if(tab=='prodotti') 
	{	visualizzazione_fk=document.forms[nome_form].visualizzazione_fk.value;
		codice=document.forms[nome_form].codice.value;
		titolo=document.forms[nome_form].titolo.value;
		magazzino_fk=document.forms[nome_form].magazzino_fk.value;
		categoria_fk=document.forms[nome_form].categoria_fk.value;
		sottocategoria_fk=document.forms[nome_form].sottocategoria_fk.value;
		designer_fk=document.forms[nome_form].designer_fk.value;
		sconto=document.forms[nome_form].sconto.value;
		prezzo=document.forms[nome_form].prezzo.value;
		
		
		if(visualizzazione_fk=="")
		{
			alert("Inserire il visualizzazione del prodotto ");
			document.forms[nome_form].visualizzazione_fk.focus();
		return;
		}
		else if(codice=="")
		{
			alert("Inserire il codice del prodotto ");
			document.forms[nome_form].codice.focus();
		return;
		}
		else if(titolo=="")
		{
			alert("Inserire il titolo del prodotto ");
			document.forms[nome_form].titolo.focus();
		
		return;
		}
		else if(magazzino_fk=="")
		{
			alert("Inserire il tipo maglia in magazzino del prodotto ");
			document.forms[nome_form].magazzino_fk.focus();
		return;
		}
		else if(categoria_fk=="")
		{
			alert("Inserire il categoria del prodotto ");
			document.forms[nome_form].categoria_fk.focus();
		return;
		}
		
		
		else if(prezzo<=0||prezzo=="")  
		{
			alert("Il prezzo inserito \u00E8 errato ");
			document.forms[nome_form].prezzo.focus();
		return;
		}
		
	}
	else if(tab=='magazzino')  /* codice */ 
	{	
		codice=document.forms[nome_form].codice.value;
		
		
		
		if(codice=="")
		{
			alert("Inserire il codice del prodotto "+tab+" ");
			document.forms[nome_form].codice.focus();
			return;
		}
		
	
	} /* nome */ 
	else if(tab=='designer'||tab=='sottodesigner'||tab=='gallery')
	{
	 nome=document.forms[nome_form].nome.value;
		
		if(nome=="")
		{
			alert("Inserire il nome");
			document.forms[nome_form].nome.focus();
			return;
		}
	}
	else /* id e nome_it e nome_en */ 
	if(tab=='categorie'||tab=='sottocategorie'
	||tab=='colour') 
	{	
		id=document.forms[nome_form].id.value;
		nome_it=document.forms[nome_form].nome_it.value;
		nome_en=document.forms[nome_form].nome_en.value;
	
		if(id=="")
		{
			alert("Inserire l'id");
			document.forms[nome_form].id.focus();
			return;
		}
		else
		if(nome_it==""&&nome_en=="")
		{
			alert("Inserire il nome");
			document.forms[nome_form].nome_it.focus();
			return;
		}
	}
	else /* id e nome */
	if(tab=='size'){
	
		id=document.forms[nome_form].id.value;
		nome=document.forms[nome_form].nome.value;
	
		if(id=="")
		{
			alert("Inserire l'id");
			document.forms[nome_form].id.focus();
			return;
		}
		else
		if(nome=="")
		{
			alert("Inserire il nome");
			document.forms[nome_form].nome.focus();
			return;
		}
	}
	
	
		
	if(ag!='') tag_ag='&ag='+ag;
	else tag_ag='';
	document.forms[nome_form].action="pannello.php?pg=ope.php"+tag_ag;
	document.forms[nome_form].submit();
	//alert('fine');
	return true;
}

function conta_attivi(nome_form)
{
var n_el=0;
var c_value="";
		 for (var l=0; l < document.forms[nome_form].campi.length; l++)
			{
			if (document.forms[nome_form].campi[l].checked)
				{c_value = c_value + document.forms[nome_form].campi[l].value + ";";
				n_el++;
				}
				
			}
if(c_value=="")
	{alert("Selezionare i campi da eliminare ");
	return false; 
	}
else
	{
		if(n_el>1) elem="gli elementi";
		else elem="l\'elemento";
		
		
		
		if(confirm("Sei sicuro di dover eliminare "+elem+" selezionato?"))
		{
		document.forms[nome_form].id.value=c_value;	 
		document.forms[nome_form].action = "pannello.php?pg=ope.php";
		
		
		return true;
		}
	}
}
function controlla_ordine(nome_form)
{

    nome_s=document.forms[nome_form].nome_s.value;
	cognome_s=document.forms[nome_form].cognome_s.value;
	co_s=document.forms[nome_form].co_s.value;
    indirizzo_s=document.forms[nome_form].indirizzo_s.value;
	cap_s=document.forms[nome_form].cap_s.value;
	
	citta_s=document.forms[nome_form].citta_s.value;
	
	provincia_s=document.forms[nome_form].provincia_s.value;
	
	nazione_s=document.forms[nome_form].nazione_s.value;
	
	telefono_s=document.forms[nome_form].telefono_s.value;
	
	campi_s=document.forms[nome_form].campi_s.value;
	

	copia_dati_f=document.forms[nome_form].copia_dati_f.value;
	
	nome_f=document.forms[nome_form].nome_f.value;
	cognome_f=document.forms[nome_form].cognome_f.value;
		

    indirizzo_f=document.forms[nome_form].indirizzo_f.value;
	
	cap_f=document.forms[nome_form].cap_f.value;
	citta_f=document.forms[nome_form].citta_f.value;
	provincia_f=document.forms[nome_form].provincia_f.value;
	
	codice_fiscale_f=document.forms[nome_form].codice_fiscale_f.value;
	p_iva_f=document.forms[nome_form].p_iva_f.value;
	telefono_f=document.forms[nome_form].telefono_f.value;

    if(campi_s==0)
	{
		if(nome_s=='')
		{alert("Inserire il campo nome ");
		 document.forms[nome_form].nome_s.focus();return 0;
		}
		else
		if(cognome_s=='')
		{alert("Inserire il campo cognome ");
		 document.forms[nome_form].cognome_s.focus();return 0;
		}
		else
		if(indirizzo_s=='')
		{alert("Inserire il campo indirizzo ");
		 document.forms[nome_form].indirizzo_s.focus();return 0;
		}
		else
		if(cap_s==''||document.forms[nome_form].cap_s.value.length!=5||isNaN(cap_s))
		{alert("Inserire il campo CAP ");
		 document.forms[nome_form].cap_s.focus();return 0;
		}
		else
		if(citta_s=='')
		{alert("Inserire il campo citta ");
		 document.forms[nome_form].citta_s.focus();return 0;
		}
		else
		if(provincia_s==''||document.forms[nome_form].provincia_s.value.length<2)
		{alert("Inserire il campo provincia ");
		 document.forms[nome_form].provincia_s.focus();return 0;
		}
		else
		if(telefono_s==''||document.forms[nome_form].telefono_s.value.length>15||isNaN(telefono_s))
		{alert("Inserire il campo telefono ");
		 document.forms[nome_form].telefono_s.focus();return 0;
		}
		else
		if(nazione_s=='') {alert("Inserire il campo Nazione nelle spedizioni");
		document.forms[nome_form].telefono_f.focus();return 0;
		}
		else{
		if(nazione_s.toLowerCase()=='italia'||nazione_s.toLowerCase()=='it'||nazione_s.toLowerCase()=='ita'||nazione_s.toLowerCase()=='italy')
						document.forms[nome_form].action = "index.php?pg=ordina.php&interno=1";
		else{alert("Ti invieremo il costo della spedizione prima di concludere l'ordine");
			
			}
	
	}
	}
		
	if(nome_f!='')
	{
	if(nome_f=='')
	{alert("Inserire il campo nome per la fattura ");
	 document.forms[nome_form].nome_f.focus();return 0;
	}
	else
	if(cognome_f=='')
	{alert("Inserire il campo cognome per la fattura ");
	 document.forms[nome_form].cognome_f.focus();return 0;
	}
	else
	if(indirizzo_f=='')
	{alert("Inserire il campo indirizzo per la fattura ");
	 document.forms[nome_form].indirizzo_f.focus();return 0;
	}
	else
	if(cap_f==''||document.forms[nome_form].cap_f.value.length!=5||isNaN(cap_f))
	{if(cap_f=='') alert("Inserire il campo CAP per la fattura ");
	if(isNaN(cap_f)) alert("Campo CAP per la fattura Errato!");
	 document.forms[nome_form].cap_f.focus();return 0;
	}
	else
	if(citta_f=='')
	{alert("Inserire il campo citta per la fattura ");
	 document.forms[nome_form].citta_f.focus();return 0;
	}
	else
	if(provincia_f==''||document.forms[nome_form].provincia_f.value.length<2)
	{alert("Inserire il campo provincia per la fattura");
	 document.forms[nome_form].provincia_f.focus();return 0;
	}
	else
	if(codice_fiscale_f=='')
	{alert("Inserire il campo codice fiscale per la fattura ");
	 document.forms[nome_form].codice_fiscale_f.focus();return 0;
	}
	else
	if(p_iva_f=='')
	{alert("Inserire il campo partita iva per la fattura ");
	 document.forms[nome_form].p_iva_f.focus();return 0;
	}
	else
	if(telefono_f==''||document.forms[nome_form].telefono_f.value.length>13||isNaN(telefono_f))
	{if(telefono_f=='') 	alert("Inserire il campo telefono per la fattura ");
	if(isNaN(telefono_f)) alert("Campo telefono per la fattura Errato!");
	 document.forms[nome_form].telefono_f.focus();return 0;
	}
	
	}
	
	
	document.forms[nome_form].action = "index.php?pg=ordina.php&preventivo=42356594654";
	document.forms[nome_form].submit();
	return 1;
}


function cambia_immagine(pg,tab,id,ope,nm_form,sigla_id,img2)
{

document.forms[nome_form].action="upload.php?pg="+pg+"&tab="+tab+"&id="+id+"&ope="+ope+"&ese=ope.php&nm_form="+nm_form+"&sigla_id="+sigla_id+"&img="+img2+"&userfile=uf_"+sigla_id;
document.forms[nome_form].submit();
}

function conta(field)
{
var campi;
n=0;
for (i = 0; i < field.length; i++)
	if(field[i].checked) 
	{if(n==0)campi=field[i].value;
	else campi =campi+";"+field[i].value ;
	n++;
	}
alert(campi);
}

function checkAll(field)
{
for (i = 0; i < field.length; i++)
	field[i].checked = true ;
}

function uncheckAll(field)
{
for (i = 0; i < field.length; i++)
	field[i].checked = false ;
}

function elimina(campo)
{
n_el=0;
id = new Array(); //viene creato l'array
for (i = 0; i < campo.length; i++)
if(campo[i].checked) 
{
	id[n_el]=campo[i].value;
	n_el++;
}
if(n_el==0) id=0;

location.href = "index.php";
 //?pg=elimina.php&ope=ele&id='+id;

}

function test(pEvent){
 //alert(pEvent.keyCode);
}



