// ypSlideOutMenu CONFIG
//left, top, width, height
new ypSlideOutMenu("menu1", "down", 45, 45, 160, 170)
new ypSlideOutMenu("menu2", "down", 120, 45, 250, 200)
new ypSlideOutMenu("menu3", "down", 255, 45, 185, 200)
new ypSlideOutMenu("menu4", "down", 325, 45, 195, 200)
new ypSlideOutMenu("menu5", "down", 405, 45, 190, 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;
  }
}

function URLEncode(s)
{
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = s;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	
	return encoded;
};

function URLDecode(s)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = s;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   
   return plaintext;
};

