// JavaScript Document

function showObject(id) {
//alert(id);
	if(id != 0){
		if(document.getElementById(id).style.visibility == "hidden"){
			document.getElementById(id).style.visibility = "visible";
			document.getElementById(id).style.display = 'block';			
				
			document.getElementById(id+"_mostra").style.visibility = "visible";
			document.getElementById(id+"_mostra").style.display = 'block';
			document.getElementById(id+"_nascondi").style.visibility = "hidden";
			document.getElementById(id+"_nascondi").style.display = 'none';								

		}else{
			document.getElementById(id).style.visibility = "hidden";
			document.getElementById(id).style.display = 'none';	
			document.getElementById(id+"_nascondi").style.visibility = "visible";
			document.getElementById(id+"_nascondi").style.display = 'block';
			document.getElementById(id+"_mostra").style.visibility = "hidden";
			document.getElementById(id+"_mostra").style.display = 'none';	
		}
	}
	return;
}
function openProductCard(id){
	window.open("./card.asp?id="+id,"Dettagli_Prodotto",'scrollbars=yes,width=450,height=350');

}
function openSpeseSpedizione(){
	window.open("./spese_spedizione.asp","Spese_Spedizione",'scrollbars=yes,width=450,height=300');
}
	
function closeWindow() { //v2.0
	window.close();
}	
	
	
function addPackage() { //v2.0	

	document.form1.addPackage.value=parseInt(document.form1.addPackage.value) + 1;
	document.form1.action="personalize.asp";
	document.form1.submit();
}		

function finalize_addPackage() { //v2.0	

	document.form1.action="index.asp";
	document.form1.submit();
}	

function finalize_order() { //v2.0	
var string = document.form1.listId.value;
	listId = string.split(",");
	var flag = false;
	for (i in listId) {
		if (listId[i] != "0"){
			if (document.getElementById(listId[i]).value != "0") {
				document.form1.action="report.asp";
				document.form1.submit();
				return true;
			}else{
				flag = true;
			}
		}
	}
	if (flag){
		alert("Bisogna inserire la quantità di almeno una voce");				
		return false;
	}
return false;	
}	

function sendOrder() { //v2.0	
	if((validate('all'))&&(validate('all_consegna'))&&(validate('email_rip'))&&(validate('pagamento'))){
		if(document.form1.email_store.value==''){
			if((validate_field('mail',document.form1.email))&&(validate_field('mail',document.form1.email_rip))){
				document.form1.action="send_order.asp";
				document.form1.submit();								
			}
		}else{
			document.form1.action="send_order.asp";
			document.form1.submit();			
		}
	}
	return false;
}	
function updateView(theForm){
//alert(document.form1.query_result_list.value);
//alert(document.form1.id_iscritto.value + "-" +document.form1.query_result_list.value)
showObject(document.form1.id_iscritto.value);
showObject(document.form1.query_result_list.value);
document.form1.id_iscritto.value = document.form1.query_result_list.value;
}


function validate_field(choose,field){
		switch(choose){
			case 'number' :
 
				var x=field.value
				if (x != "") {
					var anum=/(^\d+$)|(^\d+\.\d+$)/
					if (anum.test(x))
						return true;
					else{
						alert("Il valore deve essere un numero")
						field.value = 0
						return false;
					}
				}
				return true;
				break;
			case 'mail' :
				var x=field.value
				var anum=/(\w+\@\w+\.\w+)/
				if (anum.test(x))
					return true;
				else{
					alert("l'email non e' in un formato valido")
					return false;
				}
			break	
		}
}
function validate(choose){
	switch(choose){
		case 'email_store' : 
			if (document.form1.email_store.value != ''){
				document.form1.nome.disabled="true";
				document.form1.cognome.disabled="true";
				document.form1.indirizzo.disabled="true";
				document.form1.cap.disabled="true";
				document.form1.stato.disabled="true";
				document.form1.provincia.disabled="true";
				document.form1.localita.disabled="true";
				document.form1.telefono.disabled="true";				
				document.form1.email.disabled="true";
				document.form1.email_rip.disabled="true";
				document.form1.iva.disabled="true";			
				document.form1.news.disabled="true";			
				return false;
			}
			if (document.form1.email_store.value == ''){
				document.form1.nome.disabled="";
				document.form1.cognome.disabled="";
				document.form1.indirizzo.disabled="";
				document.form1.cap.disabled="";
				document.form1.stato.disabled="";
				document.form1.provincia.disabled="";
				document.form1.localita.disabled="";
				document.form1.telefono.disabled="";				
				document.form1.email.disabled="";
				document.form1.email_rip.disabled="";
				document.form1.iva.disabled="";		
				document.form1.news.disabled="";							
				return false;				
			}
			break;
		case 'email_rip' : 
			if (document.form1.email.value != document.form1.email_rip.value){
				alert ('Controllare la correttezza della mail');
				return false;
			}
			return true;
		case 'nazione' : 
			if (document.form1.stato.value != 'Italia'){
				document.form1.provincia.disabled="true";
				return false;
			}else{
				document.form1.provincia.disabled="";
			}
			return true;			
		case 'stato_consegna' : 
			if (document.form1.stato_consegna.value != 'Italia'){
				document.form1.provincia_consegna.disabled="true";
				return false;
			}else{
				document.form1.provincia_consegna.disabled="";
			}
			return true;						
		case 'all':
			msg = '';		
			if(document.form1.email_store.value==''){
				if (document.form1.nome.value==''){
					msg = msg + "Il campo Nome è necessario\n";
				}
				if (document.form1.cognome.value==''){
					msg = msg + "Il campo Cognome o Ragione Sociale è necessario\n";
				}
				if (document.form1.indirizzo.value==''){
					msg = msg + "Il campo Indirizzo è necessario\n";
				}
				if (document.form1.cap.value==''){
					msg = msg + "Il campo Cap è necessario\n";
				}
				if (document.form1.stato.value==''){
					msg = msg + "Il campo Nazione è necessario\n";
				}
				if (document.form1.stato.value == 'Italia'){
					if (document.form1.provincia.value==''){
						msg = msg + "Il campo Provincia è necessario\n";
					}
				}
				if (document.form1.localita.value==''){
					msg = msg + "Il campo Localita è necessario\n";
				}
				if (document.form1.telefono.value==''){
					msg = msg + "Il campo Telefono è necessario\n";
				}
				if (document.form1.email.value==''){
					msg = msg + "Il campo E-mail è necessario\n";
				}
				if (document.form1.iva.value==''){
					msg = msg + "Il campo Codice Fiscale o Partita Iva è necessario\n";
				}			
			}
			if (msg != ''){
				alert(msg);
				return false;
			}
			return true;
			case 'all_consegna':
				if ((document.form1.nome_consegna.value!='')||(document.form1.cognome_consegna.value!='')||(document.form1.indirizzo_consegna.value!='')||(document.form1.cap_consegna.value!='')||
					(document.form1.stato_consegna.value!='')||(document.form1.provincia_consegna.value!='')||(document.form1.localita_consegna.value!='')){
					msg = '';
					if (document.form1.nome_consegna.value==''){
						msg = msg + "Il campo Nome per consegna è necessario\n";
					}
					if (document.form1.cognome_consegna.value==''){
						msg = msg + "Il campo Cognome o Ragione Sociale per consegna è necessario\n";
					}
					if (document.form1.indirizzo_consegna.value==''){
						msg = msg + "Il campo Indirizzo per consegna è necessario\n";
					}
					if (document.form1.cap_consegna.value==''){
						msg = msg + "Il campo Cap per consegna è necessario\n";
					}
					if (document.form1.stato_consegna.value==''){
						msg = msg + "Il campo Nazione per consegna è necessario\n";
					}
					if (document.form1.stato_consegna.value == 'Italia'){
						if (document.form1.provincia_consegna.value==''){
							msg = msg + "Il campo Provincia per consegna è necessario\n";
						}
					}
					if (document.form1.localita_consegna.value==''){
						msg = msg + "Il campo Localita per consegna è necessario\n";
					}
					if (msg != ''){
						alert(msg);
						return false;
					}					
				}				
				return true;
			case 'pagamento' :
				if ((document.getElementById('bonifico').checked==false) && (document.getElementById('contrassegno').checked==false)){
					alert ("scegliere il tipo di pagamento");
					return false;
				}
				return true;
	}
		   
}

function checkLocation() {
	xx=window.width;
	yy=window.pageYOffset;
	document.getElementById("object1").style.right=(xx)+"px"
	document.getElementById("object1").style.top=(yy+50)+"px"
	setTimeout("checkLocation()",10);
}
function replaceChar(IDfield,out,add,allStr){
	str = document.getElementById(IDfield).value;
	if (allStr){
		document.getElementById(IDfield).value = str.replace(/out/g,add);
	}else{
		document.getElementById(IDfield).value = str.replace(out,add);
	}
//alert (document.getElementById(IDfield).value); 

}


<!--

function request_confirm(str){
var where_to= confirm(str);
if (where_to== true)
 {
   document.form1.submit();
 }
else
 {
  return false;
  }

}


function get_check_value(id_checkbox)
{
document.form1.submit();
return true;
/*var c_value = "";
if(!document.getElementById(id_checkbox)){
		alert("Nessun elemento selezionato");
		return "";
}
alert (document.getElementById(id_checkbox).length);
var radioLength = document.getElementById(id_checkbox).length;
if(radioLength == undefined)
	if(document.getElementById(id_checkbox).checked){
		alert ("non è definito");
		alert (document.getElementById(id_checkbox).value)
		return document.getElementById(id_checkbox).value;
	}
	else
		return "";
for (var i=0; i < document.getElementById(id_checkbox).length; i++)
{
alert( document.getElementById(id_checkbox)[i].value);
if (document.getElementById(id_checkbox)[i].checked)
  {
  alert( document.getElementById(id_checkbox)[i].value);
  c_value = c_value +";"+ document.getElementById(id_checkbox)[i].value ;
  }
}
return "";*/
   

}

//-->

