// ypSlideOutMenu CONFIG
//left, top, width, height
new ypSlideOutMenu("menu1", "down", 45, 45, 140, 200)
new ypSlideOutMenu("menu2", "down", 188, 45, 230, 200)
new ypSlideOutMenu("menu3", "down", 303, 45, 190, 200)
new ypSlideOutMenu("menu4", "down", 445, 45, 150, 200)
ypSlideOutMenu.writeCSS();

function SetPrivate(value){
	if (value == 'Y'){
		document.getElementById('private').options[1].selected = true;
	} else {
		document.getElementById('private').options[0].selected = true;		
	}
} 

function WriteTags() {
   var tag = "$tag";
   var tags = tag.split("|");
   var i = 0;
   var out = '';
   while (i < tags.length) {
	 if (out) {
	   out += ', ';
	 }
	 out = out + '<a href="/adon.pl?act=src&amp;fld=tag&SearchedTxt=' + URLEncode(tags[i]) + '&tmpl=src_generico&nd=5" title="Altri articoli su questo argomento">' + tags[i] + '</a>';
	 ++i;
	 }
   document.getElementById('argomenti').innerHTML = "Argomento: " + out;
}

function InputDel(campo,default_val) {
	if (campo.value == default_val) {
		campo.value = '';
	}	
}

function InputFill(campo,default_val) {
	if (campo.value == '') {
		campo.value= default_val;
	}	
}

function controllo_login(theForm){
	if (theForm.username.value == "" || theForm.username.value == "utente") {
    	alert("Per favore inserire il proprio nome utente.\nGrazie.");
    	theForm.username.focus();
    	return (false);
	}
	if (theForm.password.value == "" || theForm.password.value == "password") {
    	alert("Per favore inserire la propria password.\nGrazie.");
    	theForm.password.focus();
    	return (false);
	}
}

function submit_login(){
	theForm = document.form_login;
	if (theForm.username.value == "" || theForm.username.value == "utente") {
		alert("Per favore inserire il proprio nome utente.\nGrazie.");
		theForm.username.focus();
	} else if (theForm.password.value == "" || theForm.password.value == "password") {
		alert("Per favore inserire la propria password.\nGrazie.");
		theForm.password.focus();
	} else {
		  theForm.submit()
	}		
}

function controllo_ricerca(theForm){
	if (theForm.SearchedTxt.value == "") {
    	alert("Per favore inserire il testo da cercare.\nGrazie.");
    	theForm.SearchedTxt.focus();
    	return (false);
	}
}

function submit_ricerca(theForm){
	if (theForm.SearchedTxt.value == "" || theForm.SearchedTxt.value == "testo ") {
    	alert("Per favore inserire il testo da cercare.\nGrazie.");
    	theForm.SearchedTxt.focus();
	} else {
		  theForm.submit()
	}		
}

function controllo_newsletter(theForm){
	if (theForm.email.value == "") {
		alert("Per favore inserire il proprio indirizzo E-mail");
		theForm.email.focus();
		return (false);
	}	
	else if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(theForm.email.value))) {
		alert("Indirizzo E-Mail non valido, si prega di verificarlo");
		theForm.email.focus();
		return (false);
	}
	else if (theForm.privacy.checked == false) {
		alert("Per iscriversi è necessario acconsentire al trattamento dei dati personali");
		theForm.privacy.focus();
		return (false);
	}
}

function submit_newsletter(theForm){
	if (theForm.email.value == "") {
		alert("Per favore inserire il proprio indirizzo E-mail");
		theForm.email.focus();
		void(0);
	}	
	else if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(theForm.email.value))) {
		alert("Indirizzo E-Mail non valido, si prega di verificarlo");
		theForm.email.focus();
		void(0);
	} 
	else if (theForm.privacy.checked == false) {
		alert("Per iscriversi è necessario acconsentire al trattamento dei dati personali");
		theForm.privacy.focus();
		void(0);
	} else {	
		theForm.submit();	
	}
}

function CheckChars(obj) {
  l_max = 800;
  obj_l = obj.value.length;
//  obj.form.total_chars1.value = obj_l;
  document.getElementById("total_chars").innerHTML = obj_l;	
  if (obj_l <= l_max) {
    return true;
  } else {
    window.alert('Attenzione: il testo supera i '+l_max+' caratteri consentiti');
    obj.value = obj.value.substring(0,l_max);
    document.getElementById("total_chars").innerHTML = '800';
    return false;
  }
}
