function validate()
{
  	var txt=document.getElementById("txtRicerca");
  	
	if (txt.value=="")
		{
		alert("Specificare un criterio di ricerca");
		txt.focus();
		return (false);
		}

  return (true);
}

function validateEmail()
{

	var txtEmail=document.getElementById('txtEmail');
	
	
	if (!checkEmail(txtEmail.value)||txtEmail.value=="nome@dominio.com")
		{
		alert("Specificare un indirizzo email valido.");
		txtEmail.focus();
		return false;
		}

	if (confirm("Desideri iscriverti alle news, promozioni e newsletter di Teknodigital"))
		document.getElementById('frmEmail').submit();
	else
		return false;
	    	
}
function checkmsg(mymsg)
{
if (mymsg) alert(mymsg);
}

function qta(r,q,id)
{
	url="carrelloupd.asp?Action=EDIT&NroRiga="+r+"&txtQta="+q+"&IdProdotto="+id
	window.location.href=url;
	
}

function elimina(id)
{
var x=window.confirm("ELIMINA PRODOTTO\n\nEliminare il prodotto selezionato dal carrello degli acquisti?")
if (x)  document.location.href='carrelloUpd.asp?Action=DEL&NroRiga='+id;
}

function conferma()
{
var x=window.confirm("CONFERMA ED INVIO ORDINE\n\nProseguendo l'ordine corrente verrà confermato ed inviato a Teknodigital\n\nConfermare ed inviare l'ordine corrente?")
if (x) document.location.href="carrelloOrdine.asp";
}

function CambiaImmagine(optFoto, nomeFoto)
{
	switch (optFoto)
		{
		case "F":
			varNomeFoto=nomeFoto + "_big.jpg";			
			break;
		case "R":
			varNomeFoto=nomeFoto + "_bigRetro.jpg";			
			break;
		default:
			varNomeFoto=nomeFoto + "_big.jpg";			
			break;
		}
	
	document.getElementById('imgProdotto').src='prodotti/' + varNomeFoto;
}

function validateForm(theForm)
{


	//document.getElementById("")
		
	if (document.getElementById("txtNome").value=="")
		{
		alert("Specificare un Nome.");
		document.getElementById("txtNome").focus();
		return (false);
		}

  	if (document.getElementById("txtCognome").value=="")
		{
		alert("Specificare un Cognome.");
		document.getElementById("txtCognome").focus();
		return (false);
	  	}

  	if (document.getElementById("txtIndirizzo").value=="")
		{
		alert("Specificare un Indirizzo.");
		theForm.txtIndirizzo.focus();
		return (false);
	  	}

  	if (document.getElementById("txtCAP").value=="")
		{
		alert("Specificare il Cap.");
		document.getElementById("txtCAP").focus();
		return (false);
	  	}

  	if (document.getElementById("txtCitta").value=="")
		{
		alert("Specificare una Città.");
		document.getElementById("txtCitta").focus();
		return (false);
	  	}
	
  	if (document.getElementById("cbProvincia").value=="")
		{
		alert("Specificare una Provincia.");
		document.getElementById("cbProvincia").focus();
		return (false);
	  	}

  	if (document.getElementById("txtTelefono").value=="")
		{
		alert("Specificare un Telefono.");
		document.getElementById("txtTelefono").focus();
		return (false);
	  	}

  	if (document.getElementById("txtEmail").value=="")
		{
		alert("Specificare un indirizzo email valido.");
		document.getElementById("txtEmail").focus();
		return (false);
	  	}
	  	

	if (!checkEmail(document.getElementById("txtEmail").value))
		{
		alert("Specificare un indirizzo email valido.");
		document.getElementById("txtEmail").focus();
		return false;
		}	  	

  	if (document.getElementById("txtPIVA").value=="")
		{
		alert("Specificare un la partita iva o il codice fiscale.");
		document.getElementById("txtPIVA").focus();
		return (false);
	  	}


	myOption = -1;
	for (i=theForm.optConsegna.length-1; i > -1; i--) {
	if (theForm.optConsegna[i].checked) {
	myOption = i;
	}
	}
	if (myOption == -1) {
	alert("Specificare il tipo di consegna");
	return false;
	}		  	

	myOption = -1;
	for (i=theForm.optTipoPagamento.length-1; i > -1; i--) {
	if (theForm.optTipoPagamento[i].checked) {
	myOption = i;
	}
	}
	if (myOption == -1) {
	alert("Specificare il tipo di pagamento");
	return false;
	}
	

	myOption = -1;
	for (i=theForm.optPrivacy.length-1; i > -1; i--) {
	if (theForm.optPrivacy[i].checked) {
	myOption = i;
	}
	}
	if (myOption == -1) {
	alert("Specificare il consenso per la privacy");
	return false;
	}	
		else
			if (theForm.optPrivacy[1].checked)
				{
				alert("Per poter continuare è necessario fornire il consenso al trattamento dei dati personali");
				return false;
				}

		

		
  return (true);
}

function postForm(theForm)
{
	if (validateForm(theForm)) theForm.submit();
}

function postRivenditore(theForm)
{
	if (validateRivenditore(theForm)) theForm.submit();
}

function postPassword(theForm)
{
	if (validatePassword(theForm)) theForm.submit();
}

function postLogin(theForm)
{
	if (validateLogin(theForm)) theForm.submit();
}

function setPagamento(myDiv)
{

	if (myDiv=='B')
		{
		document.getElementById('divCon').style.display='none';
		document.getElementById('divBon').style.display='block';
		}
		
	else
		{
		document.getElementById('divBon').style.display='none';
		document.getElementById('divCon').style.display='block';

		}
}


function setOn(myCat)
{

	document.cookie = 'catalogo=' + myCat;
	document.location.reload();

}	

function checkEmail(email) {
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(email)) 
	return false;
	else
	return true;
}


function setFocus()
{

	document.getElementById('txtEmail').focus();
}	

function removeEmail()
{

	var txtEmail=document.getElementById('txtEmail');
	
	
	if (!checkEmail(txtEmail.value))
		{
		alert("Specificare un indirizzo email valido.");
		txtEmail.focus();
		return false;
		}

	if (confirm("Desideri rimuovere la tua email"))
		document.getElementById('frmEmail').submit();
	else
		return false;
	    	
}

function validateRivenditore(theForm)
{


	//document.getElementById("")
		
	if (document.getElementById("txtRagione").value=="")
		{
		alert("Specificare una Ragione Sociale.");
		document.getElementById("txtRagione").focus();
		return (false);
		}

	if (document.getElementById("txtNome").value=="")
		{
		alert("Specificare un Nome.");
		document.getElementById("txtNome").focus();
		return (false);
		}

  	if (document.getElementById("txtCognome").value=="")
		{
		alert("Specificare un Cognome.");
		document.getElementById("txtCognome").focus();
		return (false);
	  	}

  	if (document.getElementById("txtIndirizzo").value=="")
		{
		alert("Specificare un Indirizzo.");
		theForm.txtIndirizzo.focus();
		return (false);
	  	}

  	if (document.getElementById("txtCAP").value=="")
		{
		alert("Specificare il Cap.");
		document.getElementById("txtCAP").focus();
		return (false);
	  	}

  	if (document.getElementById("txtCitta").value=="")
		{
		alert("Specificare una Città.");
		document.getElementById("txtCitta").focus();
		return (false);
	  	}
	
  	if (document.getElementById("cbProvincia").value=="")
		{
		alert("Specificare una Provincia.");
		document.getElementById("cbProvincia").focus();
		return (false);
	  	}

  	if (document.getElementById("txtTelefono").value=="")
		{
		alert("Specificare un Telefono.");
		document.getElementById("txtTelefono").focus();
		return (false);
	  	}

  	if (document.getElementById("txtPIVA").value=="")
		{
		alert("Specificare la partita iva.");
		document.getElementById("txtPIVA").focus();
		return (false);
	  	}
	  	
  	if (document.getElementById("txtCF").value=="")
		{
		alert("Specificare un codice fiscale valido.");
		document.getElementById("txtCF").focus();
		return (false);
	  	}	  	

  	if (document.getElementById("txtEmail").value=="")
		{
		alert("Specificare un indirizzo email valido.");
		document.getElementById("txtEmail").focus();
		return (false);
	  	}
	  	

	if (!checkEmail(document.getElementById("txtEmail").value))
		{
		alert("Specificare un indirizzo email valido.");
		document.getElementById("txtEmail").focus();
		return false;
		}	  	


  	if (document.getElementById("txtPassword").value=="")
		{
		alert("Specificare la password per accedere all'aera privata.");
		document.getElementById("txtPassword").focus();
		return (false);
	  	}

	 if (document.getElementById("txtPassword").value.length < 5)
	  {
	    alert("Inserire al minimo 5 caratteri per la password.");
	    document.getElementById("txtPassword").focus();
	    return (false);
	  }
	
	  if (document.getElementById("txtPassword").value.length > 10)
	  {
	    alert("Inserire al massimo di caratteri per la password.");
	    document.getElementById("txtPassword").focus();
	    return (false);
	  }
	
	  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789-";
	  var checkStr = document.getElementById("txtPassword").value;
	  var allValid = true;
	  var validGroups = true;
	  for (i = 0;  i < checkStr.length;  i++)
	  {
	    ch = checkStr.charAt(i);
	    for (j = 0;  j < checkOK.length;  j++)
	      if (ch == checkOK.charAt(j))
	        break;
	    if (j == checkOK.length)
	    {
	      allValid = false;
	      break;
	    }
	  }
	  if (!allValid)
	  {
	    alert("Specificare solo caratteri alfanumerici per la password.");
	    document.getElementById("txtPassword").focus();
	    return (false);
	  }



	myOption = -1;
	for (i=theForm.optPrivacy.length-1; i > -1; i--) {
	if (theForm.optPrivacy[i].checked) {
	myOption = i;
	}
	}
	if (myOption == -1) {
	alert("Specificare il consenso per la privacy");
	return false;
	}	
		else
			if (theForm.optPrivacy[1].checked)
				{
				alert("Per poter continuare è necessario fornire il consenso al trattamento dei dati personali");
				return false;
				}

		

		
  return (true);
}

function validatePassword(theForm)
{

  	if (document.getElementById("txtEmail").value=="")
		{
		alert("Specificare un indirizzo email valido.");
		document.getElementById("txtEmail").focus();
		return (false);
	  	}
	  	

	if (!checkEmail(document.getElementById("txtEmail").value))
		{
		alert("Specificare un indirizzo email valido.");
		document.getElementById("txtEmail").focus();
		return false;
		}	  	


		
  return (true);
}

function validateLogin(theForm)
{

  	if (document.getElementById("txtEmail").value=="")
		{
		alert("Specificare un indirizzo email valido.");
		document.getElementById("txtEmail").focus();
		return (false);
	  	}
	  	

	if (!checkEmail(document.getElementById("txtEmail").value))
		{
		alert("Specificare un indirizzo email valido.");
		document.getElementById("txtEmail").focus();
		return false;
		}	  	


  	if (document.getElementById("txtPassword").value=="")
		{
		alert("Specificare la password per accedere all'aera privata.");
		document.getElementById("txtPassword").focus();
		return (false);
	  	}

	 if (document.getElementById("txtPassword").value.length < 5)
	  {
	    alert("Inserire al minimo 5 caratteri per la password.");
	    document.getElementById("txtPassword").focus();
	    return (false);
	  }
	
	  if (document.getElementById("txtPassword").value.length > 10)
	  {
	    alert("Inserire al massimo di caratteri per la password.");
	    document.getElementById("txtPassword").focus();
	    return (false);
	  }
	
	  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789-";
	  var checkStr = document.getElementById("txtPassword").value;
	  var allValid = true;
	  var validGroups = true;
	  for (i = 0;  i < checkStr.length;  i++)
	  {
	    ch = checkStr.charAt(i);
	    for (j = 0;  j < checkOK.length;  j++)
	      if (ch == checkOK.charAt(j))
	        break;
	    if (j == checkOK.length)
	    {
	      allValid = false;
	      break;
	    }
	  }
	  if (!allValid)
	  {
	    alert("Specificare solo caratteri alfanumerici per la password.");
	    document.getElementById("txtPassword").focus();
	    return (false);
	  }
		
  return (true);
}
