/* -- FUNZIONI GENERICHE -- */
function IsNumeric(strString)
{
	var strValidChars = "0123456789.-";
	var strChar;
	var blnResult = true;
	
	if (strString.length == 0) return false;
	for (i = 0; i < strString.length && blnResult == true; i++){strChar = strString.charAt(i);if (strValidChars.indexOf(strChar) == -1){blnResult = false;}}
	return blnResult;
}

function IsEmail(string){ if(string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) { return true; } else { return false; } }

function IsCodFis(string){ if(string.search(/^[a-zA-Z]{6}[0-9]{2}[a-zA-Z][0-9]{2}[a-zA-Z][0-9]{3}[a-zA-Z]$/) != -1) { return true; } else { return false; } }

function IsParIva(string){ if(IsNumeric(string) == true && string.length == 11) { return true; } else { return false; } }

function IsPhone(string){ if(string.search(/^\+?([0-9](\s|\.|\/)?)+$/) != -1) { return true; } else { return false; } }

/* -- LOGIN -- */
function CheckLogin()
{
	if(document.form_login.usr.value == ""){ alert('Username: campo obbligatorio.'); setTimeout('document.form_login.usr.focus()',40);return; }
	if(document.form_login.usr.value != ""){ if (IsEmail(document.form_login.usr.value) == false){ alert('Username: sembra non essere valido.'); setTimeout('document.form_login.usr.focus()',40);return; }	}
	if(document.form_login.pwd.value == ""){ alert('Password: campo obbligatorio.'); setTimeout('document.form_login.pwd.focus()',40);return; }
	document.form_login.submit();
}

function CheckSigla()
{
	var doc_inc = document.register01.inc.options[document.register01.inc.selectedIndex].value;
	
	document.register01.sig.value = "";
	document.register01.sig.className = "FormSizeM FormDis"; document.register01.sig.disabled = true;
	if(doc_inc == "OOAA" || doc_inc == "OOSS" || doc_inc == "OPIS"){
		document.register01.sig.disabled = false; document.register01.sig.className = "FormSizeM";
	}
	
	
	document.register01.ragsoc.value = "";
	document.register01.pariva.value = "";
	document.register01.codfis.value = "";
	document.register01.dip.value = "";
	document.register01.ate.value = "";
	document.register01.com.value = "";
	document.register01.set.value = "";
	document.register01.bil.value = "";
	
	document.register01.ragsoc.className = "FormSizeM FormDis"; document.register01.ragsoc.disabled = true;
	document.register01.pariva.className = "FormSizeM FormDis"; document.register01.pariva.disabled = true;
	document.register01.codfis.className = "FormSizeM FormDis"; document.register01.codfis.disabled = true;
	document.register01.dip.className = "FormSizeM FormDis"; document.register01.dip.disabled = true;
	document.register01.ate.className = "FormSizeM FormDis"; document.register01.ate.disabled = true;
	document.register01.com.className = "FormSizeM FormDis"; document.register01.com.disabled = true;
	document.register01.set.className = "FormSizeM FormDis"; document.register01.set.disabled = true;
	document.register01.bil.className = "FormSizeM FormDis"; document.register01.bil.disabled = true;
	
	if(doc_inc == "RLS" || doc_inc == "RSPP" || doc_inc == "TITIMP"){
		document.register01.ragsoc.disabled = false; document.register01.ragsoc.className = "FormSizeM";
		document.register01.pariva.disabled = false; document.register01.pariva.className = "FormSizeM";
		document.register01.codfis.disabled = false; document.register01.codfis.className = "FormSizeM";
		document.register01.dip.disabled = false; document.register01.dip.className = "FormSizeM";
		document.register01.ate.disabled = false; document.register01.ate.className = "FormSizeM";
		document.register01.com.disabled = false; document.register01.com.className = "FormSizeM";
		document.register01.set.disabled = false; document.register01.set.className = "FormSizeM";
		document.register01.bil.disabled = false; document.register01.bil.className = "FormSizeM";
	}
}

/* -- REGISTRAZIONE -- */
function register01()
{

	if(document.register01.eml.value == ""){ alert('eMail: campo obbligatorio.'); setTimeout('document.register01.eml.focus()',40);return; }
	if(document.register01.eml.value != ""){ if (IsEmail(document.register01.eml.value) == false){ alert('eMail: sembra non essere valido.'); setTimeout('document.register01.eml.focus()',40);return; }	}
	
	if(document.register01.eml_cnf.value == ""){ alert('Conferma eMail: campo obbligatorio.'); setTimeout('document.register01.eml_cnf.focus()',40);return; }
	if(document.register01.eml_cnf.value != ""){ if (IsEmail(document.register01.eml_cnf.value) == false){ alert('Conferma eMail: sembra non essere valido.'); setTimeout('document.register01.eml_cnf.focus()',40);return; }	}
	
	if(document.register01.eml.value != document.register01.eml_cnf.value){ alert('eMail e Conferma eMail: sembrano non essere uguali.'); setTimeout('document.register01.eml.focus()',40);return; }
	
	if(document.register01.nom.value == ""){ alert('Nome: campo obbligatorio.'); setTimeout('document.register01.nom.focus()',40);return; }
	if(document.register01.cog.value == ""){ alert('Cognome: campo obbligatorio.'); setTimeout('document.register01.cog.focus()',40);return; }
	//if(document.register01.sex.options[document.register01.sex.selectedIndex].value == ""){ alert('Sesso: selezionare un valore.'); setTimeout('document.register01.sex.focus()',40);return; }
	
	var doc_inc = document.register01.inc.options[document.register01.inc.selectedIndex].value;
	
	if(doc_inc == ""){ alert('Incarico: selezionare un valore.'); setTimeout('document.register01.inc.focus()',40);return; }
	
	/* CAMPI OBBLIGATORI PER PRIMA CATEGORIA DI INCARICO */
	if(doc_inc == "OOAA" || doc_inc == "OOSS" || doc_inc == "OPIS")
	{
		if(document.register01.sig.value == ""){ alert('Sigla: campo obbligatorio.'); setTimeout('document.register01.sig.focus()',40);return; }
	}
	
	/* CAMPI OBBLIGATORI PER PRIMA SECONDA DI INCARICO */
	if(doc_inc == "RLS" || doc_inc == "RSPP" || doc_inc == "TITIMP")
	{
		if(document.register01.ragsoc.value == ""){ alert('Ragione Sociale: campo obbligatorio.'); setTimeout('document.register01.ragsoc.focus()',40);return; }
		if(document.register01.pariva.value == ""){ alert('Partita IVA: campo obbligatorio.'); setTimeout('document.register01.pariva.focus()',40);return; }
		if(document.register01.pariva.value != "" && IsParIva(document.register01.pariva.value) == false){ alert('Partita IVA: deve contenere un valore numerico di 11 cifre.'); setTimeout('document.register01.pariva.focus()',40);return; }
		if(document.register01.codfis.value == ""){ alert('Codice Fiscale: campo obbligatorio.'); setTimeout('document.register01.codfis.focus()',40);return; }
		if(document.register01.codfis.value != "" && IsParIva(document.register01.codfis.value) == false && IsCodFis(document.register01.codfis.value) == false){ alert('Codice Fiscale: sembra non essere valido.'); setTimeout('document.register01.codfis.focus()',40);return; }
		//if(document.register01.dip.value == ""){ alert('Numero dipendenti: campo obbligatorio.'); setTimeout('document.register01.dip.focus()',40);return; }
		if(document.register01.dip.value != "" && IsNumeric(document.register01.dip.value) == false){ alert('Numero dipendenti: deve contenere valori numerici.'); setTimeout('document.register01.dip.focus()',40);return; }
		//if(document.register01.ate.value == ""){ alert('Codice Ateco: campo obbligatorio.'); setTimeout('document.register01.ate.focus()',40);return; }
		if(document.register01.com.value == ""){ alert('Comparto produttivo: campo obbligatorio.'); setTimeout('document.register01.com.focus()',40);return; }
		if(document.register01.set.value == ""){ alert('Settore: campo obbligatorio.'); setTimeout('document.register01.set.focus()',40);return; }
		if(document.register01.bil.value == ""){ alert('Indicare Ente Bilaterale: campo obbligatorio.'); setTimeout('document.register01.bil.focus()',40);return; }
	}
		
	
	
	//if(document.register01.ind.value == ""){ alert('Indirizzo: campo obbligatorio.'); setTimeout('document.register01.ind.focus()',40);return; }
	if(document.register01.cap.value == ""){ alert('Cap: campo obbligatorio.'); setTimeout('document.register01.cap.focus()',40);return; }
	if(document.register01.cap.value != "" && IsNumeric(document.register01.cap.value) == false){ alert('Cap: deve contenere valori numerici.'); setTimeout('document.register01.cap.focus()',40);return; }
	//if(document.register01.cit.value == ""){ alert('Cittą: campo obbligatorio.'); setTimeout('document.register01.cit.focus()',40);return; }
	if(document.register01.prv.options[document.register01.prv.selectedIndex].value == ""){ alert('Provincia: selezionare un valore.'); setTimeout('document.register01.prv.focus()',40);return; }
	if(document.register01.naz.options[document.register01.naz.selectedIndex].value == ""){ alert('Nazione: selezionare un valore.'); setTimeout('document.register01.naz.focus()',40);return; }
	//if(document.register01.tel.value == ""){ alert('Telefono: campo obbligatorio.'); setTimeout('document.register01.tel.focus()',40);return; }
	if(document.register01.tel.value != ""){ if (IsPhone(document.register01.tel.value) == false){ alert('Telefono: sembra non essere valido.'); setTimeout('document.register01.tel.focus()',40);return; }	}
	
	if(document.register01.cgc[0].checked == false){ alert('Condizioni Generali di Contratto: accettare la clausola.'); setTimeout('document.register01.cgc[0].focus()',40);return; }
	if(document.register01.trd[0].checked == false){ alert('Trattamento Dati: accettare la clausola.'); setTimeout('document.register01.trd[0].focus()',40);return; }
	
	document.register01.submit();
}

/* -- USER - MODIFICA PROFILO -- */
function userEdit()
{
	if(document.userEdit.edt_usr.value == ""){ alert('eMail: campo obbligatorio.'); setTimeout('document.userEdit.edt_usr.focus()',40);return; }
	if(document.userEdit.edt_usr.value != ""){ if (IsEmail(document.userEdit.edt_usr.value) == false){ alert('eMail: sembra non essere valido.'); setTimeout('document.userEdit.edt_usr.focus()',40);return; }	}
	
	if(document.userEdit.edt_cnf.value == ""){ alert('Conferma eMail: campo obbligatorio.'); setTimeout('document.userEdit.edt_cnf.focus()',40);return; }
	if(document.userEdit.edt_cnf.value != ""){ if (IsEmail(document.userEdit.edt_cnf.value) == false){ alert('Conferma eMail: sembra non essere valido.'); setTimeout('document.userEdit.edt_cnf.focus()',40);return; }	}
	
	if(document.userEdit.edt_usr.value != document.userEdit.edt_cnf.value){ alert('eMail e Conferma eMail: sembrano non essere uguali.'); setTimeout('document.userEdit.edt_usr.focus()',40);return; }
	
	if(document.userEdit.edt_sex.options[document.userEdit.edt_sex.selectedIndex].value == ""){ alert('Sesso: selezionare un valore.'); setTimeout('document.userEdit.edt_sex.focus()',40);return; }
	
	if(document.userEdit.edt_res_nom.value == ""){ alert('Nome: campo obbligatorio.'); setTimeout('document.userEdit.edt_res_nom.focus()',40);return; }
	if(document.userEdit.edt_res_cog.value == ""){ alert('Cognome: campo obbligatorio.'); setTimeout('document.userEdit.edt_res_cog.focus()',40);return; }
	if(document.userEdit.edt_res_ind.value == ""){ alert('Indirizzo: campo obbligatorio.'); setTimeout('document.userEdit.edt_res_ind.focus()',40);return; }
	if(document.userEdit.edt_res_cap.value == ""){ alert('Cap: campo obbligatorio.'); setTimeout('document.userEdit.edt_res_cap.focus()',40);return; }
	if(document.userEdit.edt_res_cap.value != "" && IsNumeric(document.userEdit.edt_res_cap.value) == false){ alert('Cap: deve contenere valori numerici.'); setTimeout('document.userEdit.edt_res_cap.focus()',40);return; }
	if(document.userEdit.edt_res_cit.value == ""){ alert('Cittą: campo obbligatorio.'); setTimeout('document.userEdit.edt_res_cit.focus()',40);return; }
	if(document.userEdit.edt_res_prv.options[document.userEdit.edt_res_prv.selectedIndex].value == ""){ alert('Provincia: selezionare un valore.'); setTimeout('document.userEdit.edt_res_prv.focus()',40);return; }
	if(document.userEdit.edt_res_naz.options[document.userEdit.edt_res_naz.selectedIndex].value == ""){ alert('Nazione: selezionare un valore.'); setTimeout('document.userEdit.edt_res_naz.focus()',40);return; }
	if(document.userEdit.edt_res_tel.value == ""){ alert('Telefono: campo obbligatorio.'); setTimeout('document.userEdit.edt_res_tel.focus()',40);return; }
	if(document.userEdit.edt_res_tel.value != ""){ if (IsPhone(document.userEdit.edt_res_tel.value) == false){ alert('Telefono: sembra non essere valido.'); setTimeout('document.userEdit.edt_res_tel.focus()',40);return; }	}
	
	if(
		 document.userEdit.edt_spe_nom.value != "" || 
		 document.userEdit.edt_spe_cog.value != "" || 
		 document.userEdit.edt_spe_ind.value != "" || 
		 document.userEdit.edt_spe_cap.value != "" || 
		 document.userEdit.edt_spe_cit.value != "" || 
		 document.userEdit.edt_spe_prv.value != "" || 
		 document.userEdit.edt_spe_naz.value != "" || 
		 document.userEdit.edt_spe_tel.value != ""
		 )
	{
		if(document.userEdit.edt_spe_nom.value == ""){ alert('Nome: campo obbligatorio.'); setTimeout('document.userEdit.edt_spe_nom.focus()',40);return; }
		if(document.userEdit.edt_spe_cog.value == ""){ alert('Cognome: campo obbligatorio.'); setTimeout('document.userEdit.edt_spe_cog.focus()',40);return; }
		if(document.userEdit.edt_spe_ind.value == ""){ alert('Indirizzo: campo obbligatorio.'); setTimeout('document.userEdit.edt_spe_ind.focus()',40);return; }
		if(document.userEdit.edt_spe_cap.value == ""){ alert('Cap: campo obbligatorio.'); setTimeout('document.userEdit.edt_spe_cap.focus()',40);return; }
		if(document.userEdit.edt_spe_cap.value != "" && IsNumeric(document.userEdit.edt_spe_cap.value) == false){ alert('Cap: deve contenere valori numerici.'); setTimeout('document.userEdit.edt_spe_cap.focus()',40);return; }
		if(document.userEdit.edt_spe_cit.value == ""){ alert('Cittą: campo obbligatorio.'); setTimeout('document.userEdit.edt_spe_cit.focus()',40);return; }
		if(document.userEdit.edt_spe_prv.options[document.userEdit.edt_spe_prv.selectedIndex].value == ""){ alert('Provincia: selezionare un valore.'); setTimeout('document.userEdit.edt_spe_prv.focus()',40);return; }
		if(document.userEdit.edt_spe_naz.options[document.userEdit.edt_spe_naz.selectedIndex].value == ""){ alert('Nazione: selezionare un valore.'); setTimeout('document.userEdit.edt_spe_naz.focus()',40);return; }
		if(document.userEdit.edt_spe_tel.value == ""){ alert('Telefono: campo obbligatorio.'); setTimeout('document.userEdit.edt_spe_tel.focus()',40);return; }
		if(document.userEdit.edt_spe_tel.value != ""){ if (IsPhone(document.userEdit.edt_spe_tel.value) == false){ alert('Telefono: sembra non essere valido.'); setTimeout('document.userEdit.edt_spe_tel.focus()',40);return; }	}
	}

	document.userEdit.submit();
}

/* -- USER - MODIFICA PASSWORD -- */

function userPassword()
{
	if(document.userPassword.pwd_new.value == ""){ alert('Nuova Password: campo obbligatorio.'); setTimeout('document.userPassword.pwd_new.focus()',40);return; }
	if((document.userPassword.pwd_new.value).length < 6){ alert('Nuova Password: deve essere di almeno 6 caratteri.'); setTimeout('document.userPassword.pwd_new.focus()',40);return; }

	if(document.userPassword.pwd_cnf.value == ""){ alert('Conferma Nuova Password: campo obbligatorio.'); setTimeout('document.userPassword.pwd_cnf.focus()',40);return; }
	if(document.userPassword.pwd_new.value != document.userPassword.pwd_cnf.value){ alert('Nuova Password e Conferma Nuova Password: sembrano non essere uguali.'); setTimeout('document.userPassword.pwd_new.focus()',40);return; }
	
	document.userPassword.submit();
}

/* -- USER - DETTAGLIO ORDINE -- */
function userOrderDetail(string)
{
	document.userOrderDetail.id_ord.value = string;
	document.userOrderDetail.submit();
}


/* -- USER - DETTAGLIO ORDINE IMMAGINE -- */
function userImagesBack()
{
	document.userImages.action = "user_order.php";
	document.userImages.submit();
}

function userImagesConfirm(string)
{
	document.userImages.action = "user_images.php";
	document.userImages.img_cnf.value = string;
	document.userImages.submit();
}



/* -- USER - FORGET PASSWORD -- */
function userForget()
{
	if(document.userForget.eml.value == ""){ alert('eMail: campo obbligatorio.'); setTimeout('document.userForget.eml.focus()',40);return; }
	if(document.userForget.eml.value != ""){ if (IsEmail(document.userForget.eml.value) == false){ alert('eMail: sembra non essere valido.'); setTimeout('document.userForget.eml.focus()',40);return; }	}
	
	document.userForget.submit();
}


/* -- ESHOP -- */
function eShop01(string)
{
	document.eShop01.cat.value = string;
	document.eShop01.submit();
}

function eShop02(string)
{
	document.eShop02.prd.value = string;
	document.eShop02.submit();
}

function eShop03()
{
	if(document.eShop03.col.options[document.eShop03.col.selectedIndex].value == ""){ alert('Colore: selezionare un valore.'); setTimeout('document.eShop03.col.focus()',40);return; }
	document.eShop03.submit();
}

function eShop03Back()
{
	document.eShop03.action = "eShop_02.php";
	document.eShop03.submit();
}


/* -- CARRELLO -- */
function cart01QtySave(val){ if (IsNumeric(val.value)) { old_value = val.value; } else { old_value = 1; }}
function cart01QtyCheck(obj){ if(!IsNumeric(obj.value)){ obj.value = old_value; }}

function cart01Delete(string)
{
	document.cart01.operation.value = 'DELETE_' + string;
	document.cart01.submit();
}

function cart01Empty()
{
  if (confirm("Se premuto OK tutti gli elementi del carrello verranno rimossi. Procedo?"))
	{
		document.cart01.operation.value = 'EMPTY';
		document.cart01.submit();
	}
}

function cart01Update()
{
	document.cart01.operation.value = 'UPDATE';
	document.cart01.submit();
}

function cart04()
{
	if(document.cart04.shipto_typ.value == "R")
	{
		document.cart04.shipto_nom.value = document.cart04.ind_res_nom.value;
		document.cart04.shipto_cog.value = document.cart04.ind_res_cog.value;
		document.cart04.shipto_rag.value = document.cart04.ind_res_rag.value;
		document.cart04.shipto_ind.value = document.cart04.ind_res_ind.value;
		document.cart04.shipto_cap.value = document.cart04.ind_res_cap.value;
		document.cart04.shipto_cit.value = document.cart04.ind_res_cit.value;
		document.cart04.shipto_prv.value = document.cart04.ind_res_prv.value;
		document.cart04.shipto_naz.value = document.cart04.ind_res_naz.value;
		document.cart04.shipto_tel.value = document.cart04.ind_res_tel.value;
		document.cart04.shipto_not.value = document.cart04.note.value;
	}
	
	if(document.cart04.shipto_typ.value == "S")
	{
		document.cart04.shipto_nom.value = document.cart04.ind_spe_nom.value;
		document.cart04.shipto_cog.value = document.cart04.ind_spe_cog.value;
		document.cart04.shipto_rag.value = document.cart04.ind_spe_rag.value;
		document.cart04.shipto_ind.value = document.cart04.ind_spe_ind.value;
		document.cart04.shipto_cap.value = document.cart04.ind_spe_cap.value;
		document.cart04.shipto_cit.value = document.cart04.ind_spe_cit.value;
		document.cart04.shipto_prv.value = document.cart04.ind_spe_prv.value;
		document.cart04.shipto_naz.value = document.cart04.ind_spe_naz.value;
		document.cart04.shipto_tel.value = document.cart04.ind_spe_tel.value;
		document.cart04.shipto_not.value = document.cart04.note.value;
	}
	
	if(document.cart04.pagamento[0].checked == false && document.cart04.pagamento[1].checked == false){ alert('Metodo di pagamento: selezionare un valore.'); setTimeout('document.cart04.pagamento[0].focus()',40);return; }
	document.cart04.submit();
}

function cart04SetRes()
{
	document.cart04.shipto_typ.value = "R";
	elem1 = document.getElementById("tab_res"); elem1.className = "res_on";
	elem2 = document.getElementById("tab_spe"); elem2.className = "spe_of";
	tabl1 = document.getElementById("cart04_table_res"); tabl1.className = "display_on";
	tabl2 = document.getElementById("cart04_table_spe"); tabl2.className = "display_of";
}

function cart04SetSpe()
{
	document.cart04.shipto_typ.value = "S";
	elem1 = document.getElementById("tab_res"); elem1.className = "res_of";
	elem2 = document.getElementById("tab_spe"); elem2.className = "spe_on";
	tabl1 = document.getElementById("cart04_table_res"); tabl1.className = "display_of";
	tabl2 = document.getElementById("cart04_table_spe"); tabl2.className = "display_on";
}