function chk_form(frm){
	
	for(var i = 0; i < frm.elements.length; i++){
		
		//alert(frm.elements[i].name+':'+frm.elements[i].required);
		
		switch(frm.elements[i].required){
			case 'TEXT':
				if(!chk_txt(frm.elements[i],frm.elements[i].msg)) return false;
			break;
			case 'DATE':
				if(!chk_date(frm.elements[i],frm.elements[i].msg)) return false;
			break;
			case 'EMAIL':
				if(!chk_email(frm.elements[i],frm.elements[i].msg)) return false;
			break;
			case 'CHECK':
				if(!chk_checkbox(frm.elements[i],frm.elements[i].msg)) return false;
			break;
			case 'RADIO':
				if(!chk_radiobutton(frm.elements[i],frm.elements[i].msg)) return false;
			break;
		}
	}
	
}


function conferma(messaggio, url){
	if(confirm(messaggio))
		window.location.href = url;
}

function chk_txt(o,v){
	if(o.value.search('[a-zA-Z0-9]') == -1){
		if(arguments.length==1) alert('Campo ' + o.name + ' errato');
		else if(arguments.length==2) alert(v);
		o.focus();
		return false;
	}
	return true;
}

function chk_int(o,m){
	if(!o.value || o.value.search('[^0-9]') != -1){
		if(arguments.length==1) alert('Campo ' + o.name + ' errato');
		else if(arguments.length==2) alert(m);	
		o.focus();
		return false;
	}
	return true;
}

function chk_data(o,m){
	
	if(!o.value || o.value.search('[0-9]{2}+/.[0-9]{2}+/.[0-9]{4}') == -1){
		if(arguments.length==1) alert('Campo ' + o.name + ' errato');
		else if(arguments.length==2) alert(m);	
		o.focus();
		return false;
	}
	return true;	
}


//togliere http!!!
function chk_url(o){
	if(o.value.search('[a-z]+://[a-zA-Z0-9]+\.[a-zA-Z0-9]+') == -1){
		alert('Campo ' + o.name + ' errato');
		o.focus();
		return false;
	}
	return true;
}
function chk_url1(o,m){
	if(o.value.search('[a-zA-Z0-9]+\.[a-zA-Z0-9]+') == -1){
		if(arguments.length==2){
			alert(m);
			o.focus();
		}
		return false;
	}
	return true;
}

function azzera(url){
	window.location.href = url;
}
function chk_email(o,d){
	if(o.value.search("^[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-.]?[0-9a-zA-Z])*\\.[a-zA-Z]{2,4}$") == -1){
		alert(d);
		o.focus();
		return false;
	}
	return true;
}
function chk_select(o,d){
	if(!o[o.selectedIndex].value || !o.selectedIndex){
		alert(d);
		o.focus();
		return false;
	}
	return true;
}

//////////////////////////////////////////////////////////////////////////

function chk_aut(){
	if(!document.contatti.check_privacy.checked){
		alert("E' necessario fornire il proprio consenso e aver preso visione dell'informativa");
	     document.contatti.focus();
	     return false;
	}else{
	 return(true);
	}
}

function chk_aut2(){
	if(!document.iscrizione.autorizzazione.checked){
		alert("E' necessario fornire il proprio consenso e aver preso visione dell'informativa");
	    document.contatti.focus();
		return false;
	}else{
		return true;
	}
}



function chk_form_contatti(){
	with(document.contatti){
		if(
         chk_txt(nome,"Inserisci il tuo nome") &&
         chk_txt(cognome,"Inserisci il tuo cognome") &&
         chk_email(email,"Inserisci un'email valida") &&
		 //chk_txt(messaggio,"Inserisci un messaggio!") &&
         chk_aut() ){
			return true;
		}
		return false;
	}
}

		
	
function chk_ordine(count, pagamento0, pagamento1, pagamento2){
	
	document.carrello2.codicesconto.value = document.carrello.codicesconto.value;
	
	var pagamento = '';
	var checked = '';
	
	if(pagamento0 == true) checked = 0;
	else if(pagamento1 == true) checked = 1;
	else if(pagamento2 == true) checked = 2;
	
	if(checked !== '') pagamento = document.carrello.pagamento[checked].value;
	else pagamento = '';
	
	//alert(pagamento);
	
	document.carrello2.pagamento.value = pagamento;
	
	var ordine = parseInt(count);
	if(ordine > 0 && pagamento !== '') return true;
	else if(!ordine) alert("Impossibile inviare l'ordine: il carrello  vuoto");
	else alert("attenzione, devi scegliere un metodo di pagamento");
	
	return false;
	
}

function invioricerca(){
	if (event.keyCode ==13) {			
		document.location.href='index.php?page_id=17&amp;prod_ricerca='+document.getElementById('ricerca').value
	}
}





function chk_form_iscrizione(){
	with(document.iscrizione){
		if(
		 chk_txt(nome,"Inserisci il nome") &&
		 chk_txt(cognome,"Inserisci il cognome") &&
         chk_email(email,"Inserisci un'email valida") &&
         //chk_txt(ragsoc,"Inserisci la ragione sociale") &&
		 //chk_txt(piva,"Inserisci la partita iva") &&
		 chk_txt(indirizzo,"Inserisci l'indirizzo") &&
		 chk_int(cap,"Inserisci il cap") &&
		 chk_txt(citta,"Inserisci la citt") &&
		 chk_txt(provincia,"Inserisci la provincia") &&
		 chk_txt(stato,"Inserisci lo stato") &&
		 chk_txt(telefono,"Inserisci il numero di telefono") &&
		 //chk_data(data_nascita,"Inserisci una corretta data di nascita") &&
         chk_aut2() ){
			return true;
		}
		return false;
	}
}	