function check_field(){

	if ((document.getElementById('campo_nome').value == "")||
		  (document.getElementById('campo_cognome').value == "")||
		  (document.getElementById('campo_email').value == "")||
		  (document.getElementById('campo_nazione').value == "")||
		  (document.getElementById('campo_titolo').value == "")||
		  (document.getElementById('campo_url').value == "http://")||
		  (document.getElementById('campo_username').value == "")||
		  (document.getElementById('campo_password').value == "")){
				alert('Attenzione!\nI campi contrassegnati con l\'asterisco sono obbligatori.');
				return false;
			}else{
				validazione = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
				if (!validazione.test(document.getElementById('campo_email').value)){
					alert('Attenzione!\nFormato email non valido.');
					document.getElementById('campo_email').style.border="1px solid #ff0000";
					document.getElementById('campo_email').focus();
					return false;
				}else{
					if (document.getElementById('checkbox_terms').checked == false){
						alert('Attenzione!\nLa registrazione è possibile solo accettando le Condizioni generali di utilizzo del servizio.\nTorna indietro e spunta la casella corrispondente');
						document.getElementById('checkbox_terms').style.border="1px solid #ff0000";
						document.getElementById('checkbox_terms').focus();
						return false;
					}
				}
			}
	}


function check_email(){
validazione = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	if(document.getElementById('id_nome').value ==''){
		alert("ATTENZIONE!\nDevi compilare il campo relativo al tuo nome.");
		return false;
	}
	if (!validazione.test(document.getElementById('rec_email').value)){
		alert('Attenzione!\nFormato email non valido.');
		return false;
	}
}

function check_field_update(){

	if ((document.getElementById('campo_nome').value == "")||
		  (document.getElementById('campo_cognome').value == "")||
		  (document.getElementById('campo_email').value == "")||
		  (document.getElementById('campo_nazione').value == "")||
		  (document.getElementById('campo_titolo').value == "")||
		  (document.getElementById('campo_url').value == "http://")||
			(document.getElementById('campo_url').value == "")){
				alert('Attenzione!\nI campi contrassegnati con l\'asterisco sono obbligatori.');
				return false;
			}else{
				validazione = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
				if (!validazione.test(document.getElementById('campo_email').value)){
					alert('Attenzione!\nFormato email non valido.');
					document.getElementById('campo_email').style.border="1px solid #ff0000";
					document.getElementById('campo_email').focus();
					return false;
				}
			}
}

function check_field_post(){

	if ((document.getElementById('campo_categoria').value == "")||
		  (document.getElementById('campo_titolo').value == "")||
			(/^\s+$/.test(document.getElementById('campo_titolo').value))||
		  (document.getElementById('campo_blog').value == "")||
			(/^\s+$/.test(document.getElementById('campo_blog').value))||
		  (document.getElementById('campo_url_blog').value == "")||
			(/^\s+$/.test(document.getElementById('campo_url_blog').value))||
		  (document.getElementById('campo_permalink').value == "")||
			(/^\s+$/.test(document.getElementById('campo_permalink').value))){
				alert('Attenzione!\nI campi contrassegnati con l\'asterisco sono obbligatori.');
				return false;
			}
}

function check_textarea(){
var max_length = 250;
var campo = document.getElementById('campo_descrizione').value.length;
if (campo >= max_length){
	alert("La descrizione del post può contenere massimo " + max_length + " caratteri.");
	document.getElementById('campo_descrizione').value = document.getElementById('campo_descrizione').value.substring(0,max_length);
	}

var testo = document.getElementById('campo_descrizione');
var x;

var words = new Array();
words[0] = "http:";
words[1] = "www";


for (x in words){
	
	if(testo.value.toLowerCase().match(words[x])){
		var pos = testo.value.indexOf(words[x]);
		alert("Attenzione! Non è possibile inserire url o indirizzi internet nella descrizione.");
		testo.value = testo.value.substring(0,pos);
		
	}
}

}

function clear_form(){

	document.getElementById('campo_nome').value = "";
	document.getElementById('campo_cognome').value = "";
	document.getElementById('campo_email').value = "";
	document.getElementById('campo_nazione').value = "Italia";
	document.getElementById('campo_titolo').value = "";
	document.getElementById('campo_url').value = "http://";
	document.getElementById('campo_username').value = "";
	document.getElementById('campo_password').value = "";
	document.getElementById('field1').value = "";
	document.getElementById('field2').value = "";
	document.getElementById('field3').value = "";
	document.getElementById('field4').value = "";
	document.getElementById('field5').value = "";
	document.getElementById('field6').value = "http://";

}

function check_psw(){

	if ((document.getElementById('new_psw_rec').value == "")){
				alert('Attenzione!\nDevi inserire la nuova password.');
				return false;
	}
}

function crea_codice(){

	var codice_box = document.getElementById('codice');
	var collez = document.box.a;
	var tipologia = ""; 
	for (var i=0; i<collez.length; i++) { 
  	if(collez[i].checked){
			tipologia = collez[i].value;
		} 
	}
	var lungh = document.getElementById('lengh_box').value;
	var lungh_fr = parseFloat(lungh)+10;
	var numero = document.getElementById('qta').value;
	var alt_fr = parseFloat(numero)*75;
	var color_back = document.getElementById('back_color').value;
	var color_border = document.getElementById('border').value;
	var color_link = document.getElementById('link').value;
	var color_link_over = document.getElementById('link_over').value;
	var color_testo = document.getElementById('testo').value;
	
	if((tipologia == "")||
	   (lungh == "")||
		 (numero == "")||
		 (color_back == "")||
		 (color_border == "")||
		 (color_link == "")||
		 (color_link_over == "")||
		 (color_testo == "")){
				alert("ATTENZIONE! Tutti i parametri devono essere presenti!");
				return false;
			}else{
				codice_box.value = "<iframe src=\"http://www.dicevi.com/plugins/box/box.php?tp="+tipologia+"&qt="+numero+"&lun="+lungh+"&clb="+color_back.substr(1)+"&clbo="+color_border.substr(1)+"&cll="+color_link.substr(1)+"&cllo="+color_link_over.substr(1)+"&clt="+color_testo.substr(1)+"\" height=\""+alt_fr+"\" width=\""+lungh_fr+"\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\" vspace=\"0\" hspace=\"0\" scrolling=\"no\"></iframe>";
			}
}

function reset(){

document.getElementById('codice').value = "";
document.getElementById('tipo').value = "last";
document.getElementById('lengh_box').value = 160;
document.getElementById('qta').value = 3;
document.getElementById('back_color').value = "#FFFFFF";
document.getElementById('border').value = "#EEEEEE";
document.getElementById('link').value = "#4A7596";
document.getElementById('link_over').value = "#70B0E0";
document.getElementById('testo').value = "#959595";
document.getElementById('sample_id').style.backgroundColor = "#FFFFFF";
document.getElementById('sample_id2').style.backgroundColor = "#EEEEEE";
document.getElementById('sample_id3').style.backgroundColor = "#4A7596";
document.getElementById('sample_id4').style.backgroundColor = "#70B0E0";
document.getElementById('sample_id5').style.backgroundColor = "#959595";

}

function toggleLayer( whichLayer ){
var elem, vis;
if( document.getElementById ){ 										// this is the way the standards work
	elem = document.getElementById( whichLayer );
}
else if( document.all ){ 												// this is the way old msie versions work
	elem = document.all[whichLayer];
}
else if( document.layers ){ 											// this is the way nn4 works
  elem = document.layers[whichLayer];
}
	vis = elem.style;
// if the style.display value is blank we try to figure it out here
if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined){
  vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
}
vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}
