//
// variabili
//
// change this to where you store the blank.gif image
var blank = "blank.gif";

topedge = 150;  // location of news box from top of page
leftedge = 50;  // location of news box from left edge
boxheight = 150;  // height of news box
boxwidth = 200;  // width of news box
scrollheight = 400; // total height of all data to be scrolled

topedge2 = 150;  // location of news box from top of page
leftedge2 = 290;  // location of news box from left edge
boxheight2 = 150;  // height of news box
boxwidth2 = 200;  // width of news box
scrollheight2 = 400; // total height of all data to be scrolled


//
// funzioni JavaScript usate nel sito
//

function openNewWindow(url_,width_,height_)
{
	popwindow= window.open (url_, "msf","location=1,status=0,scrollbars=0,width=" + width_ + ",height=" + height_);
	popwindow.moveTo(0,0);
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' deve essere un\'indirizzo e-mail.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' deve essere un numero.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' deve essere un numero tre '+min+' e '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' e richiesto.\n'; }
  } if (errors) alert('Si sono verificati i seguenti errori:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
 
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_jumpMenuGo(selName,targ,restore){ //v3.0
  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}


function scrollnews2(cliptop2) {
	if (document.layers) {
		newsDiv2 = document.news2;
		newsDiv2.clip.top = cliptop2;
		newsDiv2.clip.bottom = cliptop2 + boxheight2;
		newsDiv2.clip.left = 0;
		newsDiv2.clip.right = boxwidth2 + leftedge2;
		newsDiv2.left = leftedge2;
		newsDiv2.top = topedge2 - cliptop2;
	}
	else {
		newsDiv2 = news2.style;
		newsDiv2.clip = "rect(" + cliptop2 + "px " + (boxwidth2 + leftedge2) + "px " + (cliptop2 + boxheight2) + "px 0px)";
		newsDiv2.pixelLeft = leftedge2;
		newsDiv2.pixelTop = topedge2 - cliptop2;
	}
	cliptop2 = (cliptop2 + 1) % (scrollheight2 + boxheight2);
	newsDiv2.visibility='visible';
	setTimeout("scrollnews2(" + cliptop2 + ")", 32);
}


function scrollnews(cliptop) {
	if (document.layers) {
		newsDiv = document.news;
		newsDiv.clip.top = cliptop;
		newsDiv.clip.bottom = cliptop + boxheight;
		newsDiv.clip.left = 0;
		newsDiv.clip.right = boxwidth + leftedge;
		newsDiv.left = leftedge;
		newsDiv.top = topedge - cliptop;

		}
	else {
		newsDiv = news.style;
		newsDiv.clip = "rect(" + cliptop + "px " + (boxwidth + leftedge) + "px " + (cliptop + boxheight) + "px 0px)";
		newsDiv.pixelLeft = leftedge;
		newsDiv.pixelTop = topedge - cliptop;
		}
	cliptop = (cliptop + 1) % (scrollheight + boxheight);
	newsDiv.visibility='visible';
	setTimeout("scrollnews(" + cliptop + ")", 32);
}



function MachakFull(Ie,other){
//Copyright © 1999 m.milicevic machakjoe@netscape.net jjooee@tip.nl
	x=screen.availWidth;
	y=screen.availHeight;
	target = parseFloat(navigator.appVersion.substring(navigator.appVersion.indexOf('.')-1,navigator.appVersion.length));
	if((navigator.appVersion.indexOf("Mac")!=-1) &&(navigator.userAgent.indexOf("MSIE")!=-1) &&(parseInt(navigator.appVersion)==4))
		window.open(other,"sub",'scrollbars=yes');
	if (target >= 4)
	{
		if (navigator.appName=="Netscape")
			{
				var MachakFull=window.open(other,"MachakFull","scrollbars=yes",'width='+x+',height='+y+',top=0,left=0');
				MachakFull.moveTo(0,0);
				MachakFull.resizeTo(x,y);
			}
		if (navigator.appName=="Microsoft Internet Explorer")
			window.open(Ie,"MachakFull","fullscreen=yes");
	}
	else window.open(other,"sub","scrollbars=yes");
}


function FDK_StripChars(theFilter,theString)
{
	var strOut,i,curChar

	strOut = ""
	for (i=0;i < theString.length; i++)
	{		
		curChar = theString.charAt(i)
		if (theFilter.indexOf(curChar) < 0)	// if it's not in the filter, send it thru
			strOut += curChar		
	}	
	return strOut
}


function FDK_Trim(theString)
{
 var i,firstNonWhite

 if (FDK_StripChars(" \n\r\t",theString).length == 0 ) return ""

	i = -1
	while (1)
	{
		i++
		if (theString.charAt(i) != " ")
			break	
	}
	firstNonWhite = i
	//Count the spaces at the end
	i = theString.length
	while (1)
	{
		i--
		if (theString.charAt(i) != " ")
			break	
	}	

	return theString.substring(firstNonWhite,i + 1)

}


function FDK_AddToValidateArray(FormName,FormElement,Validation,SetFocus)
{
    var TheRoot=eval("document."+FormName);
 
    if (!TheRoot.ValidateForm) 
    {
        TheRoot.ValidateForm = true;
        eval(FormName+"NameArray = new Array()")
        eval(FormName+"ValidationArray = new Array()")
        eval(FormName+"FocusArray = new Array()")
    }
    var ArrayIndex = eval(FormName+"NameArray.length");
    eval(FormName+"NameArray[ArrayIndex] = FormElement");
    eval(FormName+"ValidationArray[ArrayIndex] = Validation");
    eval(FormName+"FocusArray[ArrayIndex] = SetFocus");
 
}


function FDK_ValidateNumChars(FormElement,Required,Minimum,Maximum,StripSpaces,ErrorMsg)     {	
	var theString = FormElement.value;
	var MinLength = Minimum;
	var MaxLength = Maximum;
	var msgInvalid = ErrorMsg;

	if (FDK_StripChars(" \n\r",theString).length == 0 && !Required)	{
       return "";
    }
	
	theString = FDK_Trim(theString);

	if (StripSpaces)      {
		theString = FDK_StripChars(" \n\r",theString);
    }
		
	if (MinLength > 0 && theString.length < MinLength)     {
		return msgInvalid;
    }
		
	if (MaxLength > 0 && theString.length > MaxLength)      {
		return msgInvalid;
	}

	// we passed the tests
	FormElement.value = theString;

	return "";
}


function FDK_AddNumCharsValidation(FormName,FormElementName,Required,Minimum,Maximum,StripSpaces,SetFocus,ErrorMsg)  {
  document.Form1.controllo8000.value=document.Form1.TestoLnContenuto.value
  var ValString = "FDK_ValidateNumChars("+FormElementName+","+Required+","+Minimum+","+Maximum+","+StripSpaces+","+ErrorMsg+")";
  FDK_AddToValidateArray(FormName,eval(FormElementName),ValString,SetFocus)
}


function emailnascosta(nome,dominio,testo,titolo,testo2,oggetto) { //funzione per nascondere l'email agli spammer
	at="@";
	testo=nome+""+at+""+dominio;
	document.write("<a href='mailto:"+testo+"?Subject="+oggetto+"' title='"+titolo+"' class='txtgreybold2'>"+testo2+"<\/a>");
}


function rollovercheck(categoria,immagine){	
	if (categoria.checked!=true)
	{
		immagine.src="/admin/Next.gif";
		categoria.checked=true;
	}
	else
	{
		immagine.src="/admin/Previous.gif";
		categoria.checked=false;
	}
}

function check_email(e) {
	ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
	for(i=0; i < e.length ;i++){
		if(ok.indexOf(e.charAt(i))<0){ 
			return (false);
		}	
	} 
	if (document.images) {
		re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
		re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		if (!e.match(re) && e.match(re_two)) {
			return (-1);		
		} 
	}
}

function getRefererParam(strParamName) {
  var strReturn = "";
  var strHref = document.referrer;
  if ( strHref.indexOf("?") > -1 ) {
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ) {
      if ( aQueryString[iParam].indexOf(strParamName + "=") > -1 ) {
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return strReturn;
} 

//
// Per tracciare con GA i click al pulsante "Share" di FB (e non solo...)
// http://www.google.com/support/analytics/bin/answer.py?hl=en-uk&answer=55527
//
function recordOutboundLink(link, category, action) {
  try{
    var pageTracker = _gat._getTracker("UA-1705018-1");
    pageTracker._trackEvent(category, action);
    setTimeout('document.location = "' + link.href + '"', 100)
  } catch(err) {}
}


//
// Per nascondere o visualizzare un elemento della pagina
// Argomenti:
//	szDivId: ID dell'elemento
//	iState: 1 visible, 0 hidden
//
// http://www.technofundo.com/tech/js/showhide.html
//
function toggleBox(szDivID, iState) // 
{
    if(document.layers)	   //NN4+
    {
	   document.layers[szDivID].display = iState ? "block" : "none";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
		obj.style.display = iState ? "block" : "none";
    }
    else if(document.all)	// IE 4
    {
		document.all[szDivID].style.display = iState ? "block" : "none";
    }
}

function showPopupVideo(videoID,width,height) {

		$( "#dialog:ui-dialog" ).dialog( "destroy" );

		$( "#"+videoID ).dialog({
				height: height,
				width: width,
				modal: true,
				closeOnEscape: true,
				resizable: false,
				closeText: 'chiudi'
		});
}

