function controllaSegnalaVideo(){
	if (requiredFieldValidate(new Array("E-mail mittente","E-mail destinatario"), new Array("mittente","destinatario"))){
		if (emailFieldValidate(new Array("E-mail mittente","E-mail destinatario"), new Array("mittente","destinatario"))){	
			Modalbox.show('/includes/segnala_video.asp', {params: Form.serialize('form_segnala_video'), method: 'post'});
		}
	}
	return false;
}
function controllaFormCommento(){
	if (requiredFieldValidate(new Array("Titolo","Commento"), new Array("titolo","commento"))){	
		Modalbox.show('/includes/nuovo_commento.asp', {params: Form.serialize('form_nuovo_commento').replace(/%0A/gi," "), method: 'post'});
	}
	return false;
}
/**
 * COMMON DHTML FUNCTIONS
 * These are handy functions I use all the time.
 *
 * By Seth Banks (webmaster at subimage dot com)
 * http://www.subimage.com/
 *
 * Up to date code can be found at http://www.subimage.com/dhtml/
 *
 * This code is free for you to use anywhere, just keep this comment block.
 */

/**
 * X-browser event handler attachment and detachment
 * TH: Switched first true to false per http://www.onlinetools.org/articles/unobtrusivejavascript/chapter4.html
 *
 * @argument obj - the object to attach event to
 * @argument evType - name of the event - DONT ADD "on", pass only "mouseover", etc
 * @argument fn - function to call
 */
function addEvent(obj, evType, fn){
 if (obj.addEventListener){
    obj.addEventListener(evType, fn, false);
    return true;
 } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
 } else {
    return false;
 }
}
function removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
}

/**
 * Code below taken from - http://www.evolt.org/article/document_body_doctype_switching_and_more/17/30655/
 *
 * Modified 4/22/04 to work with Opera/Moz (by webmaster at subimage dot com)
 *
 * Gets the full width/height because it's different for most browsers.
 */
function getViewportHeight() {
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 

	return window.undefined; 
}
function getViewportWidth() {
	var offset = 17;
	var width = null;
	if (window.innerWidth!=window.undefined) return window.innerWidth; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
}

/**
 * Gets the real scroll top
 */
function getScrollTop() {
	if (self.pageYOffset) // all except Explorer
	{
		return self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		return document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		return document.body.scrollTop;
	}
}
function getScrollLeft() {
	if (self.pageXOffset) // all except Explorer
	{
		return self.pageXOffset;
	}
	else if (document.documentElement && document.documentElement.scrollLeft)
		// Explorer 6 Strict
	{
		return document.documentElement.scrollLeft;
	}
	else if (document.body) // all other Explorers
	{
		return document.body.scrollLeft;
	}
}




var ie = (document.all) ? true : false;

function apriScrivici(id_c,desc){
	hideElements();
	Modalbox.show('/includes/scrivici.asp?id_c='+id_c, {title:'Mailbox - '+desc, width:600, overlayClose:false , afterHide:showElements });
}
function conditionFieldValidate(arrayLabel, arrayCampi, strCondition, strErrorMessage){
	var messaggio="";
	var errore=false;
	for (i=0; i<arrayCampi.length; i++){
		if (arrayCampi[i]!=""){
			strEval="!(window.document.getElementById(arrayCampi[i]).value"+strCondition+")"
			if (eval(strEval)){
				messaggio=messaggio+"- "+arrayLabel[i]+"\n";
				errore=true;
			}
		}
	}
	if (errore==true){
		alert("Attenzione i seguenti campi "+strErrorMessage+":\n" + messaggio);
		return false;
	}else {
		return true;
	}
}
function checkRadioButton(fieldName,strMessage){
	if (isChecked(fieldName)){
		return true;
	}else{
		alert(strMessage);
		return false;
	}
}
/*function checkCercaLettere(){
	sDate=window.document.getElementById("d_cerca").value;
	if (!isDateValid(sDate) && sDate!=""){
		alert("Attenzione inserire una data valida nel formato GG/MM/AAAA");
		return false;
	}
	return true;
}
function checkCercaRubriche(){
	sDate=window.document.getElementById("d_cerca").value;
	if (!isDateValid(sDate) && sDate!=""){
		alert("Attenzione inserire una data valida nel formato GG/MM/AAAA");
		return false;
	}
	return true;
}
function checkScrivici(checkLink){
	if (requiredFieldValidate(new Array("Cognome","Nome","Email","Messaggio"),new Array("cognome","nome","email","messaggio"))){
		if (requiredCheckboxValidate(new Array("Autorizzazione e accettazione condizioni"),new Array("flg_consenso"))){
			if (emailFieldValidate(new Array("E-mail"),new Array("email"))){	
				if (checkLink){
					if (requiredFieldValidate(new Array("Link"),new Array("url_video"))){
						if ($("url_video").value!="Inserire il link del video o documento che desiderate segnalarci"){
							Modalbox.show('/includes/scrivici.asp', {params: Form.serialize('form_scrivici'), method: 'post'});
						}else{
							alert("Attenzione i seguenti campi sono obbligatori:\n- Link");
						}
					}
				}else{
					Modalbox.show('/includes/scrivici.asp', {params: Form.serialize('form_scrivici'), method: 'post'});
				}
			}
		}		
	}
	return false;
}*/
function emailFieldValidate(arrayLabel, arrayCampi){
	var messaggio="";
	var errore=false;
	for (i=0; i<arrayCampi.length; i++){
		if (!isEmail(window.document.getElementById(arrayCampi[i]).value) && arrayCampi[i]!=""){
			messaggio=messaggio+"- "+arrayLabel[i]+"\n";
			errore=true;
		}
	}
	if (errore==true){
		alert("Attenzione i seguenti campi devono contenere una e-mail valida:\n" + messaggio);
		return false;
	}else {
		return true;
	}
}

function floatFieldValidate(arrayLabel, arrayCampi){
	var messaggio="";
	var errore=false;
	for (i=0; i<arrayCampi.length; i++){
		if (!isNumberFloat(window.document.getElementById(arrayCampi[i]).value) && arrayCampi[i]!=""){
			messaggio=messaggio + "- " + arrayLabel[i] + "\n";
			errore=true;
		}
	}
	if (errore){
		alert("Attenzione i seguenti campi devono contenere un valore decimale:\n" + messaggio);
	}
	return !errore;
}
function fnMaxLength(s,x){
	if (x!=0){
		if (window.document.getElementById(s).value.length>x){		
			window.document.getElementById(s).value=window.document.getElementById(s).value.substr(0,x);
		}
	}
}
function fnMoney(valor){
	valore=valor.toString();
	money=""
	if (valore!=""){
		valore=valore.replace(",",".");
		money=fnRoundNumber(valore,2).toString();
		money=money.replace(".",",");
		PosVirgola=money.lastIndexOf(",");
		if (PosVirgola==-1){
			money=money + ",00";
		}else{
			money=money + "00";
			money=money.substr(0,PosVirgola+3);
		}
	}
	return money;
}
function getElementsByClassName(className, tag, elm){
	var testClass = new RegExp("(^|\\\\s)" + className + "(\\\\s|$)");
	var tag = tag || "*";
	var elm = elm || document;
	var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
	var returnElements = [];
	var current;
	var length = elements.length;
	for(var i=0; i<length; i++){
		current = elements[i];
		if(testClass.test(current.className)){
			returnElements.push(current);
		}
	}
	return returnElements;
}
function applicaTdHover(TdClassName,TdClassNameHover){
		var rows = document.getElementsByClassName(TdClassName);	
		for (var i = 0; i < rows.length; i++) {
			rows[i].onmouseover = function() {
											 	this.className = TdClassNameHover;
											 }
			rows[i].onmouseout = function() {
												this.className = TdClassName;
											}
		}
	}
function annullaFiltro(objForm){
	window.document.location.href=objForm.action;
}
function hideElements(){
	var elements = (ie) ? document.all : document.getElementsByTagName('*');
	//var tot="";  
	for (i=0; i<elements.length; i++){
		if ((elements[i].nodeName).toString().toLowerCase()=='object' || (elements[i].nodeName).toString().toLowerCase()=='embed' || (elements[i].nodeName).toString().toLowerCase()=='iframe'){
			elements[i].style.visibility="hidden"
		}
		//tot += " " + (elements[i].nodeName).toString().toLowerCase()
	}
	//alert(tot);
}
function intFieldValidate(arrayLabel, arrayCampi){
	var messaggio="";
	var errore=false;
	for (i=0; i<arrayCampi.length; i++){
		if (!isNumberInt(window.document.getElementById(arrayCampi[i]).value) && arrayCampi[i]!=""){
			messaggio=messaggio + "- " + arrayLabel[i] + "\n";
			errore=true;
		}
	}
	if (errore){
		alert("Attenzione i seguenti campi devono contenere un valore intero:\n" + messaggio);
	}
	return !errore;
}
function isChecked(field){
	result=false;
	arrCollection=window.document.getElementsByName(field);
	for (v=0;v<arrCollection.length;v++){
		//alert(arrCollection[i].value + " --- " + arrCollection[i].checked);
		if (arrCollection[v].checked==true){
			result=true;
		}
	}
	return result;
}
function isEmail(inputString) {
	//regular expression per controllo email
	if (inputString=="") return true;
	var email=/^[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,4}$/i;
	return(email.test(inputString));
}

function isNumberFloat(inputString){
	if (inputString=="-") return false;
	n=inputString.indexOf(",")
	m=inputString.lastIndexOf(",");
	s=inputString.indexOf("-");
	t=inputString.lastIndexOf("-");
	if (n==m && s==t) {
		if (s!=0 && inputString.charAt(s)=="-"){
			return false;
		}
		for (x=0; x<inputString.length; x++){
			if (isNaN(inputString.charAt(x)) && inputString.charAt(x)!="," && inputString.charAt(x)!="-"){
				return false;
			}
		}
		return true;
	}
	return false;
}
function isNumberInt(inputString){
	s=inputString.indexOf("-");
	t=inputString.lastIndexOf("-");
	if (s==t) {
		if (s!=0 && inputString.charAt(s)=="-"){
			return false;
		}		
		for (x=0; x<inputString.length; x++){
			if (isNaN(inputString.charAt(x))){
				return false;
			}
		}

		return true;
	}
	return false;
}
function lenghtFieldValidate(arrayLabel, arrayCampi, arrayLength){
	var messaggio="";
	var errore=false;
	for (i=0; i<arrayCampi.length; i++){
		if ((window.document.getElementById(arrayCampi[i]).value).length>arrayLength[i] && arrayCampi[i]!=""){
			messaggio=messaggio+"- "+arrayLabel[i]+": al massimo "+arrayLength[i]+" caratteri\n";
			errore=true;
		}
	}
	if (errore==true){
		alert("Attenzione i seguenti campi sono limitati a un certo numero di caratteri:\n" + messaggio);
		return false;
	}else {
		return true;
	}
}
function optionFieldValidate(form, option, arrayLabel, arrayCampi){
	for (i=0; i<arrayCampi.length; i++){
		if (window.document.forms[form][option][i].checked==true){
			break;
		}
	};	
	if (window.document.getElementById(arrayCampi[i]).value==""){
		alert("Attenzione il campo " + arrayLabel[i] + " deve essere riempito.");
		return false;
	}		
	return true;
}
function positiveFieldValidate(arrayLabel, arrayCampi){
	var messaggio="";
	var errore=false;
	for (i=0; i<arrayCampi.length; i++){
		if (window.document.getElementById(arrayCampi[i]).value<0 && arrayCampi[i]!=""){
			messaggio=messaggio + "- " + arrayLabel[i] + "\n";
			errore=true;
		}
	}
	if (errore){
		alert("Attenzione i seguenti campi devono contenere un valore maggiore o uguale a zero:\n" + messaggio);
	}
	return !errore;
}

function pulisciCampo(objCampo,sValoreIniziale){
	if (objCampo.value==sValoreIniziale) objCampo.value='';
}
function radioFieldValidate(arrayLabel, arrayCampi){
	var messaggio="";
	var errore=false;
	for (i=0; i<arrayCampi.length; i++){
		
		if (!isChecked(arrayCampi[i]) && arrayCampi[i]!=""){
			messaggio=messaggio+"- "+arrayLabel[i]+"\n";
			errore=true;
		}
		
	}
	if (errore==true){
		alert("Attenzione la selezione di un\'opzione dai seguenti campi è obbligatoria:\n" + messaggio);
		return false;
	}else {
		return true;
	}
}
function requiredCheckboxValidate(arrayLabel, arrayCampi){
	var messaggio="";
	var errore=false;
	for (i=0; i<arrayCampi.length; i++){
		if (!isChecked(arrayCampi[i]) && arrayCampi[i]!=""){
			messaggio=messaggio+"- "+arrayLabel[i]+"\n";
			errore=true;
		}
	}
	if (errore==true){
		alert("Attenzione i seguenti campi sono obbligatori:\n" + messaggio);
		return false;
	}else {
		return true;
	}
}

function requiredFieldValidate(arrayLabel, arrayCampi){
	var messaggio="";
	var errore=false;
	for (i=0; i<arrayCampi.length; i++){
		if (arrayCampi[i]!=""){
			if (window.document.getElementById(arrayCampi[i]).value==""){
				messaggio=messaggio+"- "+arrayLabel[i]+"\n";
				errore=true;
			}
		}
	}
	if (errore==true){
		alert("Attenzione i seguenti campi sono obbligatori:\n" + messaggio);
		return false;
	}else {
		return true;
	}
}
function rotatedFieldValidate(arrayLabel, arrayCampi){
	var messaggio="";
	var errore=true;
	for (i=0; i<arrayCampi.length; i++){
		messaggio=messaggio+"- "+arrayLabel[i]+"\n";
		if (window.document.getElementById(arrayCampi[i]).value!=""){
			errore=false;
		}
	}
	if (errore==true){
		alert("Attenzione uno dei seguenti campi deve essere riempito:\n" + messaggio);
		return false;
	}else {
		return true;
	}
}

function showElements(){
	var elements = (ie) ? document.all : document.getElementsByTagName('*');
	for (i=0; i<elements.length; i++){
		if ((elements[i].nodeName).toString().toLowerCase()=='object' || (elements[i].nodeName).toString().toLowerCase()=='embed' || (elements[i].nodeName).toString().toLowerCase()=='iframe'){
			elements[i].style.visibility="visible"
		}
	}
}