var xmlEseguiAjax="";
var spostaexplorer="";
var azioneclick=0;
var mouseYannunci=260;

function OverHand(Id)
{
	document.getElementById(Id).style.cursor="pointer";
}


function LinkOver(Id)
{
	if(document.getElementById(Id).className != "titolo_linkSelezionato")
	{
		document.getElementById(Id).style.cursor="pointer";
		document.getElementById(Id).className="titolo_linkSopra";
	}
}


function LinkOut(Id)
{
	if(document.getElementById(Id).className != "titolo_linkSelezionato")
		document.getElementById(Id).className="titolo_link";
}


function LinkOverClasse(Id, Classe)
{
	document.getElementById(Id).style.cursor="pointer";
	document.getElementById(Id).className=Classe;
}


function LinkOutClasse(Id, Classe)
{
	document.getElementById(Id).className=Classe;
}


function LinkEsterno(link)
{
	if(left(link,5)=="index")
		link+="&ctfn=0";
	newWindow= window.open("","");
	newWindow.location.href = link;
}


function ApriLinkPagina(link)
{
	document.location.href=link;
}


function MostraNascondi(Id)
{
	if(document.getElementById(Id).className=="nascosto")
		document.getElementById(Id).className="block";
	else
		document.getElementById(Id).className="nascosto";
}

function AssegnaUnaClasse(Id, Classe)
{
	document.getElementById(Id).style.cursor="pointer";
	document.getElementById(Id).className=Classe;
}



function specialcharsForm(Form, Campo, NuovoCampo)
{
	document.getElementById(NuovoCampo).value=htmlEncode(document.getElementById(Campo).value, false, false);
	document.forms[Form].submit();
	return true;
}


function specialcharsCampo(Campo, NuovoCampo)
{
	document.getElementById(NuovoCampo).value=htmlEncode(document.getElementById(Campo).value, false, false);
}




function calcolatempo()
{
	var myDate=new Date();
	return myDate.getTime();
}


function millisecondi()
{
	var myDate=new Date();
	ms1=myDate.getTime();
	zeit = new Date(); 
	ms2 = (zeit.getHours() * 24 * 60 * 1000) + (zeit.getMinutes() * 60 * 1000) + (zeit.getSeconds() * 1000) + zeit.getMilliseconds(); 
	return ms1 + "-" + ms2;
}



function left(str, n)
{
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}


function right(str, n)
{
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}



function mid(str, inizio, lunghezza)
{
	return String(str).substring(inizio-1, inizio-1+lunghezza);
}



var browser="";
if(navigator.appName=="Microsoft Internet Explorer")
{	
	versione=navigator.appVersion.toLowerCase();
	if(versione.indexOf("msie 6.0") > -1)
		browser="IE6";
}



function verifica_password(Password) 
{	
	if(Password.indexOf("0")==-1 && Password.indexOf("1")==-1 && Password.indexOf("2")==-1 && Password.indexOf("3")==-1 && Password.indexOf("4")==-1 && Password.indexOf("5")==-1 && Password.indexOf("6")==-1 && Password.indexOf("7")==-1 && Password.indexOf("8")==-1 && Password.indexOf("9")==-1)
		return false;
	else
		return true;
}		


function invertidata(data)
{
	if(data != '')
	{
		var anno = data.substr(6,4);
		var mese = data.substr(3,2);
		var giorno = data.substr(0,2);
		return anno + '/' + mese + '/' + giorno;
	}
	else
		return '';
}



function ripristinadata(data)
{
	if(data != '')
	{
		var anno = data.substr(0,4);
		var mese = data.substr(5,2);
		var giorno = data.substr(8,2);
		return giorno + '/' + mese + '/' + anno;
	}
	else
		return '';
}


function cerca_caratterispeciali(stringa)
{
	var controllo=false;
	if(stringa.search("&")!= -1)
		controllo=true;
	if(stringa.search("\\\\")!= -1)
		controllo=true;
	if(stringa.search('"')!= -1)
		controllo=true;
	if(stringa.search("'")!= -1)
		controllo=true;
	if(stringa.search("%")!= -1)
		controllo=true;
	return controllo;
}



function controllanickname(stringa)
{
	var controllo=false;
	if(stringa.search("'")!= -1)
		controllo=true;
	if(stringa.search("%")!= -1)
		controllo=true;
	if(stringa.search("&")!= -1)
		controllo=true;
	if(stringa.search("/")!= -1)
		controllo=true;
	if(stringa.search("\\\\")!= -1)
		controllo=true;
	if(stringa.search(":")!= -1)
		controllo=true;
	if(stringa.search('"')!= -1)
		controllo=true;
	if(stringa.search('\\*')!= -1)
		controllo=true;
	if(stringa.search('\\?')!= -1)
		controllo=true;
	if(stringa.search('\\|')!= -1)
		controllo=true;
	if(stringa.search('<')!= -1)
		controllo=true;
	if(stringa.search('>')!= -1)
		controllo=true;
	return controllo;
}



function restituiscititolo(LinguaSito, TitIta, TitEng)
{
	if(LinguaSito=="ITA")
		return 'title="'+TitIta+'"';
	else
		return 'title="'+TitEng+'"';
}



function erroriform(stringaerrore)
{	
	var MessageBoard;
	MessageBoard = document.getElementById("MessageBoard");
	MessageBoard.style.display = "block";	
	MessageBoard.innerHTML = stringaerrore;
}



function disableSelection(target)
{
	if (typeof target.onselectstart!="undefined")
		target.onselectstart=function(){return false;}
	else if (typeof target.style.MozUserSelect!="undefined")
	{
		target.onmousedown=function(){return false;}
		target.style.MozUserSelect="none";
	}
	else
		target.onmousedown=function(){return false;}
	target.style.cursor = "default";
}



function enableSelection(target)
{
	if (typeof target.onselectstart!="undefined")
		target.onselectstart=function(){return true;}
	else if (typeof target.style.MozUserSelect!="undefined")
	{
		target.onmousedown=function(){return true;}
		target.style.MozUserSelect="text";
	}
	else
		target.onmousedown=function(){return true;}
	target.style.cursor = "auto";
}



function aggiungimese()
{
	if(document.Calendario.Mese.value=="")
	{	
		document.Calendario.Mese.value ='<%=month(date())%>';
		document.Calendario.Anno.value ='<%=year(date())%>';
	}
	mese=parseInt(document.Calendario.Mese.value)+1;
	anno=parseInt(document.Calendario.Anno.value);
	if(mese==13)
	{
		document.Calendario.Anno.value = anno+1;
		mese=1;
	}
	document.Calendario.Mese.value = mese;
	document.Calendario.submit();
	return true;
}



function sottraimese()
{
	if(document.Calendario.Mese.value=="")
	{	
		document.Calendario.Mese.value ='<%=month(date())%>';
		document.Calendario.Anno.value ='<%=year(date())%>';
	}
	mese=parseInt(document.Calendario.Mese.value)-1;
	anno=parseInt(document.Calendario.Anno.value);
	if(mese==0)
	{
		document.Calendario.Anno.value = anno-1;
		mese=12
	}
	document.Calendario.Mese.value = mese;
	document.Calendario.submit();
	return true;
}



function ricercaveloce()
{
	var controllo=true;
	var Link="?Search=1";
	specialcharsCampo('Rveltitle2', 'Rveltitle');
	
	document.getElementById("Rveltitle2").style.backgroundColor = "#ffffff";
	Titolo = document.getElementById("Rveltitle2").value;
	
	if(Titolo=="" || Titolo==null)
	{
		controllo=false;
		document.getElementById("Rveltitle2").style.backgroundColor = "#fb7";
	}
	else if(Titolo.length > 40 || Titolo.length < 2)
	{
		controllo=false;
		document.getElementById("Rveltitle2").style.backgroundColor = "#fb7";
	}
	
	Titolo = document.getElementById("Rveltitle").value;
	if(Titolo!="")
		Link+="&title=" + encodeURIComponent(Titolo);
	
	if (controllo==true)
		document.location.href = Link;
}



function LinkRicercaImmagini(Parola)
{
	Parola=htmlEncode(Parola, false, false);
	document.location.href="index.asp?Search=3&ParoleChiave="  + encodeURIComponent(Parola);
}


function CampoTmceVuoto(Messaggio)
{	
	if(Messaggio == "" || Messaggio == "-" || Messaggio == "<p>-</p>" || Messaggio == "<p>&nbsp;</p>" || Messaggio == "<p>&nbsp;&nbsp;</p>" || Messaggio == "<p>&nbsp;</p><p>&nbsp;</p>")
		return false;
	else
		return true;
}	


function CampoNonCorretto(NomeCampo, TestoIta, TestoEng)
{
	errMessage="";
	if (NomeCampo !="")
		document.getElementById(NomeCampo).style.backgroundColor = "#fb7";
	if(LinguaSito=="ITA")
		errMessage = "Il campo <span class='grassetto'>"+TestoIta+"</span> non &egrave; corretto.<br/>";
	else
		errMessage = "The field <span class='grassetto'>"+TestoEng+"</span> is not correct.<br/>";
	return errMessage;
}


function CampoObbligatorio(NomeCampo, TestoIta, TestoEng)
{
	errMessage="";
	if (NomeCampo !="")
		document.getElementById(NomeCampo).style.backgroundColor = "#fb7";
	if(LinguaSito=="ITA")
		errMessage = "Il campo <span class='grassetto'>"+TestoIta+"</span> &egrave; obbligatorio.<br/>";
	else
		errMessage = "The field <span class='grassetto'>"+TestoEng+"</span> is necessary.<br/>";
	return errMessage;
}



/*
HTMLEncode - Encode HTML special characters.
Copyright (c) 2006 Thomas Peri, http://www.tumuski.com/
*/
function htmlEncode(source, display, tabs)
{
	function special(source)
	{
		var result = '';
		for (var i = 0; i < source.length; i++)
		{
			var c = source.charAt(i);
			if (c < ' ' || c > '~')
			{
				c = '&#' + c.charCodeAt() + ';';
			}
			result += c;
		}
		return result;
	}
	
	function format(source)
	{
		// Use only integer part of tabs, and default to 4
		tabs = (tabs >= 0) ? Math.floor(tabs) : 4;
		
		// split along line breaks
		var lines = source.split(/\r\n|\r|\n/);
		
		// expand tabs
		for (var i = 0; i < lines.length; i++)
		{
			var line = lines[i];
			var newLine = '';
			for (var p = 0; p < line.length; p++)
			{
				var c = line.charAt(p);
				if (c === '\t')
				{
					var spaces = tabs - (newLine.length % tabs);
					for (var s = 0; s < spaces; s++)
					{
						newLine += ' ';
					}
				}
				else
				{
					newLine += c;
				}
			}
			// If a line starts or ends with a space, it evaporates in html
			// unless it's an nbsp.
			newLine = newLine.replace(/(^ )|( $)/g, '&nbsp;');
			lines[i] = newLine;
		}
		
		// re-join lines
		var result = lines.join('<br />');
		
		// break up contiguous blocks of spaces with non-breaking spaces
		result = result.replace(/  /g, ' &nbsp;');
		
		// tada!
		return result;
	}

	var result = source;
	
	// ampersands (&)
	result = result.replace(/\&/g,'&amp;');

	// less-thans (<)
	result = result.replace(/\</g,'&lt;');

	// greater-thans (>)
	result = result.replace(/\>/g,'&gt;');
	
	if (display)
	{
		// format for display
		result = format(result);
	}
	else
	{
		// Replace quotes if it isn't for display,
		// since it's probably going in an html attribute.
		result = result.replace(new RegExp('"','g'), '&quot;');
	}

	// special characters
	result = special(result);
	
	// tada!
	return result;
}





function URLEncode (clearString) 
{
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}



function URLDecode (encodedString) 
{
  var output = encodedString;
  var binVal, thisString;
  var myregexp = /(%[^%]{2})/;
  while ((match = myregexp.exec(output)) != null
             && match.length > 1
             && match[1] != '') {
    binVal = parseInt(match[1].substr(1),16);
    thisString = String.fromCharCode(binVal);
    output = output.replace(match[1], thisString);
  }
  return output;
}



function trim(o)
{
	var re=/^(\s*)([\w\W]*[^\s])(\s*)$/;
	var rs=re.exec(String(o));
	return rs != null ? rs[2] : "";
}





function rimuoviamp(stringa)
{
	result=stringa
	for(f=0; f<result.length ; f++)
		result = result.replace('&amp;', "&");
	return result;
}





function isDateValid(theDate) {
	var re=/^([0-9]{1,2})\/([0-9]{1,2})\/([1-2][0-9]{3})$/;
	var res;
	var anno=theDate.substring(6);
	if ((res = re.exec(theDate)) != null) {
		var d = res[1]-0;
		var m = res[2]-0;
		var y = res[3]-0;
		var ly = (y % 4 == 0) && (y % 100 != 0) || (y % 400 == 0);
		var maxDay;
		
		switch (m) {
			case 1:
			case 3:
			case 5:
			case 7:
			case 8:
			case 10:
			case 12:
				maxDay = 31;
				break;
			case 4:
			case 6:
			case 9:
			case 11:
				maxDay = 30;
				break;
			case 2:
				if (ly)
					maxDay = 29;
				else
					maxDay = 28;
				break;
			default:
				return false;
				break;
		}
		if (1<=d && d<=maxDay)
		{	
			if (anno>=1900)
				return true;
			else
				return false;
		}
		else
			return false;	
	}
	else
		return false;
}



function checkMail(mail)
{
	var re=/^[-a-zA-Z0-9_.]+@[-a-zA-Z0-9_.]+[-a-zA-Z0-9_.]+\.([-a-zA-Z0-9_.]{2,3}|info|name)$/;

	var res;
	if ((res = re.exec(mail)) != null) 
		return true;	
	else
		return false;
}




function tmicejvscript()
{
	//	invalid_elements : "a,div"
	tinyMCE.init({
		// General options
		mode : "textareas",
		theme : "advanced",
		plugins : "safari,advhr,emotions,searchreplace,nonbreaking,paste,fullscreen",

		// Theme options
		theme_advanced_buttons1 : "code,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,fontsizeselect,|,fullscreen",
		theme_advanced_buttons2 : "undo,redo,|,bullist,numlist,|,outdent,indent,blockquote,|,forecolor,backcolor,|,advhr,removeformat,|,charmap,emotions,|,search,replace",
		theme_advanced_buttons3 : "",
		convert_urls : false,
		paste_auto_cleanup_on_paste : true,
		paste_remove_spans: true,
		paste_remove_styles: true,
		paste_remove_styles_if_webkit: true,
		paste_convert_middot_lists : true,
		paste_strip_class_attributes : "all",
		paste_use_dialog : false,
		paste_convert_headers_to_strong : false,
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : false
	});
}