/*-----------------------------------------------------------------------------------------------------*/
/*------------------------------  FUNZIONE DI ORDINAMENTO DEI MENU ------------------------------------*/
/*-----------------------------------------------------------------------------------------------------*/

function moveUp(element) {
  for(i = 0; i < element.options.length; i++) {
    if(element.options[i].selected == true) {
      if(i != 0) {
        var temp = new Option(element.options[i-1].text,element.options[i-1].value);
        var temp2 = new Option(element.options[i].text,element.options[i].value);
        element.options[i-1] = temp2;
        element.options[i-1].selected = true;
        element.options[i] = temp;
      }
    }
  }
}
function moveDown(element) {
  for(i = (element.options.length - 1); i >= 0; i--) {
    if(element.options[i].selected == true) {
      if(i != (element.options.length - 1)) {
        var temp = new Option(element.options[i+1].text,element.options[i+1].value);
        var temp2 = new Option(element.options[i].text,element.options[i].value);
        element.options[i+1] = temp2;
        element.options[i+1].selected = true;
        element.options[i] = temp;
      }
    }
  }
}
function updateList(list, textBox) {
  textBox.value = '';
  for(i = 0; i < list.options.length; i++) {
    if (i == 0) {
      textBox.value += list.options[i].value;
    } else {
      textBox.value += ',' + list.options[i].value;
    }
  }
}
function swap(list) {
  var j = 0;
  for(i = 0; i < list.options.length; i++) {
    if(list.options[i].selected == true) {
      j++;
      switch (j) {
        case 1:
        var i1 = i;
        var temp = new Option(list.options[i].text, list.options[i].value);
        break;
        case 2:
        var i2 = i;
        var temp2 = new Option(list.options[i].text, list.options[i].value);
        break;
      }
    }
  }
  if (j != 2) {
    alert('Puoi invertire solo 2 elementi per volta');
  } else {
    list.options[i1] = temp2;
    list.options[i1].selected = true;
    list.options[i2] = temp;
    list.options[i2].selected = true;
  }
}
/*
window.onload = function() {
 updateList(document.getElementById('move'), document.getElementById('newList'));
}
*/
/*-----------------------------------------------------------------------------------------------------*/


function removeBreaks(){

var para = document.getElementById("paragraphs").checked;
var nopara = document.getElementById("noparagraphs").checked;
var noBreaksText = document.getElementById("oldText").value;

noBreaksText = noBreaksText.replace(/(\n\r|\n|\r)/gm,"<1br />");

re1 = /<1br \/><1br \/>/gi;
re1a = /<1br \/><1br \/><1br \/>/gi;

if(nopara == 1 || nopara ==  true){
noBreaksText = noBreaksText.replace(re1," ");
}else{
noBreaksText = noBreaksText.replace(re1a,"<1br /><2br />");
noBreaksText = noBreaksText.replace(re1,"<2br />");
}

re2 = /\<1br \/>/gi;
noBreaksText = noBreaksText.replace(re2, " ");

re3 = /\s+/g;
noBreaksText = noBreaksText.replace(re3," ");

re4 = /<2br \/>/gi;
noBreaksText = noBreaksText.replace(re4,"\n\n");
document.getElementById("newText").value = noBreaksText;
}//-------------------------------------------------------------------------------------------------------------------------
function get_number_date(data_string)
{
	var tempo = data_string.split('/');
	return(parseInt(tempo[2]  + tempo[1]  + tempo[0]));
}
//-------------------------------------------------------------------------------------------------------------------------
function checkdateformat(userinput){
var dateformat = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{2}$/
return dateformat.test(userinput) //returns true or false depending on userinput
}
//-------------------------------------------------------------------------------------------------------------------------
function check_mail(oggetto)
{
	if((oggetto=='Indicare una mail') || (oggetto==''))
	return false;
   EmailAddr = oggetto;
   Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
   if (Filtro.test(EmailAddr))
      return true;
   else
	  return false;
  }
//-------------------------------------------------------------------------------------------------------------------------
function Cotrolla_questa_mail(oggetto)
{
   EmailAddr = oggetto;
   Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
   if (Filtro.test(EmailAddr))
      return true;
   else
      {
      alert("Controlla l'indirizzo di e-mail inserito");
      return false;
      }
  }
//-------------------------------------------------------------------------------------------------------------------------
function Leggionline(oggetto)
{
 window.open(oggetto.value,'')
}
//-------------------------------------------------------------------------------------------------------------------------
function EmailValida(oggetto)
{ 
  var s=oggetto.value;
  if ((s.indexOf('@'))>1)
    return (  s.indexOf('.' ,(s.indexOf('@'))   )+1)
  else
    return(0)
}
//-------------------------------------------------------------------------------------------------------------------------
function newFin(X,Y,Nome,Loc)
{
  window.open(Loc,Nome,'scrollbar=no,resizable=no,height='+Y+',width='+X+',toolbar=no,status=no,menubar=no');	
}
//-------------------------------------------------------------------------------------------------------------------------
 function pieno(oggetto)
  {
    return (oggetto.value!='')
  }
//-------------------------------------------------------------------------------------------------------------------------
function CoerenzaPsw(psw,confpsw)
{
return (psw.value==confpsw.value)
}
//-------------------------------------------------------------------------------------------------------------------------

function leggiCookie(Name)
{
  var search = Name + "=" 
   if (document.cookie.length > 0) 
     { // Esistono i Cookie
      offset = document.cookie.indexOf(search)
      if (offset != -1)
       { // Esiste il mio cookie ?
         offset += search.length
         end = document.cookie.indexOf(";", offset)
         if (end == -1)
           end = document.cookie.length
         return unescape(document.cookie.substring(offset, end))
       }
     }
}


//-------------------------------------------------------------------------------------------------------------------------
function setCookie(name, value)
{
  document.cookie = name + "=" + escape(value);
}
//----------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------
function check_vai(oggetto,href,valcook)
{

if (valcook=='true') 
  if (!(confirm('Attenzione si sta per abbandonare una pagina senza memorizzarne le modifiche \nContinuare ugualmente ?')))
    oggetto.href='javascript:void(0)'
  else
    {
      oggetto.href=href;
      setCookie('mod','false')
    }
else
  oggetto.href=href

}

//------------------------------------------------------------------------------------------------------------------------------
function check_vai_bottone(href,targ,valcook)
{

if (valcook=='true') 
  if (!(confirm('Attenzione si sta per abbandonare una pagina senza memorizzarne le modifiche \nContinuare ugualmente ?')))
    return(0)
  else
    {
      setCookie('mod','false');
	  window.open(href,targ);
    }
else
  window.open(href,targ);
}



//--------------------------------------------------------------------------------------------------------------------------
function SwapImg(op,sogg)
{
 if ( leggiCookie('mod')=='false' )
  {
   document.operazione.src='Immagini/'+ op +'.gif';
   document.soggetto.src='Immagini/'+ sogg +'.gif'
  } 
}
//--------------------------------------------------------------------------------------------------------------------------
function getXY()
{
  if (document.body && document.body.clientWidth)
  {
    orgw = document.body.clientWidth;
    orgh = document.body.clientHeight;
  }
  else if (window.outerWidth)
  {
    orgw = window.outerWidth;
    orgh = window.outerHeight;
  }
}
//--------------------------------------------------------------------------------------------------------------------------
function getX()
{
  if (document.body && document.body.clientWidth)
    return(document.body.clientWidth)
  else if (window.outerWidth)
    return(window.outerWidth)
}
//--------------------------------------------------------------------------------------------------------------------------
function getY()
{
  if (document.body && document.body.clientWidth)
    return(document.body.clientHeight)
  else if (window.outerWidth)
    return(window.outerHeight)
}
//--------------------------------------------------------------------------------------------------------------------------
function OnMouse(img, el, ancor, el1, stile, action) {
	if ( action=='over' ) {
		el.className=stile + 'over';
		el1.className=stile + 'over';
		ancor.className=stile + 'over';
		if (img!='') img.className='vison'
	} else {
		el.className=stile;
		el1.className=stile;
		ancor.className=stile;
		if (img!='') img.className='visoff';
	}
}
//----------------------------
//RIDEMENSIONAMENTO DEL TESTO

function setFontSize(size) {
var bod = document.getElementsByTagName("body")[0];
var percentuale = "60%"; // default
if (size == 1) percentuale = "60%";
if (size == 2) percentuale = "75%";
if (size == 3) percentuale = "90%";
bod.style.fontSize = percentuale;
}
//------------------------------------------------------------------------------------

var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		return false
	}
return true
}


//---------------------------------------------------------------------------------------------------------------------------
function add_to_multiline(sorg,dest)
{

 for (var i=0;i< dest.options.length;i++)
  if (sorg.value == dest.options[i].value)
    return; 
 if (sorg.selectedIndex != -1)
  {
   var elem= document.createElement("OPTION")
   elem.text=sorg.options[sorg.selectedIndex].text;
   elem.value=sorg.value;
   dest.options.add(elem);
  }
 else{
  //alert(sorg.selectedIndex);
  alert('Seleziona prima un valore');
 }
}
//---------------------------------------------------------------------------------------------------------------------------
function add_inputText_to_multiline(sorg,dest)
{

 for (var i=0;i< dest.options.length;i++)
   if (sorg.value == dest.options[i].value)
     return; 
 if (sorg.value!='')
 {
   var elem= document.createElement("OPTION")
   elem.text=sorg.value;
   elem.value=sorg.value;
   dest.options.add(elem);
 }  

}
//---------------------------------------------------------------------------------------------------------------------------
function add_inputText_and_Description_to_multiline(sorg,dest,description)
{

 for (var i=0;i< dest.options.length;i++)
   if (sorg.value == dest.options[i].value)
     return; 
 if (sorg.value!='')
 {
   var elem= document.createElement("OPTION")
   elem.text=description;
   elem.value=sorg.value;
   dest.options.add(elem);
 }  

}

//----------------------------------------------------------------------------------------------------------------------------

function del_to_multiline(oggetto)
{
if (oggetto.selectedIndex != -1 )
  oggetto.remove(oggetto.selectedIndex)
else
 alert('Seleziona prima un valore');
}
//-----------------------------------------------------------------------------------------------------------------------------
function multiline_to_str(objselect,objstr)
{

var i;
var temp='';
 for (i=0;i< objselect.options.length;i++)
   if (objselect.options[i].value !='')
     temp = temp + objselect.options[i].value + '¤';

 objstr.value=temp;
}
//------------------------------------------------------------------------------------------------------------------------------
function Ordina_Elenco(nomemodulo,id_modulo,sceltaordinamento)
{
 var ordinamento, str_lcl;
 
 switch (sceltaordinamento) {
 	case ('Menu'):
		 str_lcl = 'Sei sicuro di volere ordinare '+ nomemodulo +' in modo personalizzato ?';
		 if (confirm(str_lcl)) {
			 parent.frames.frame_basso.location='/Amministrazione/Ordinamento/mod_ordinamento_menu.asp?T='+ id_modulo;
		 }else
		   return(0);
	break;
 	case ('Moduli'):
		 str_lcl = 'Sei sicuro di volere ordinare '+ nomemodulo +' in modo personalizzato ?';
		 if (confirm(str_lcl)) {
			 parent.frames.frame_basso.location='/Amministrazione/Ordinamento/mod_ordinamento_moduli.asp?T='+ id_modulo;
		 }else
		   return(0);
	break;
 	case ('A'):
		 str_lcl= 'Sei sicuro di volere ordinare '+ nomemodulo +' in modo alfabetico ?';
		 if (confirm(str_lcl)) {
			 // <![CDATA[
			   var myAjax = new Ajax.Request("/amministrazione/Ordina/DB_Ordina.asp", {method:'get',parameters:'Tipo_ord='+ sceltaordinamento +'&ID_Modulo='+ id_modulo});
			 // ]]>
			 parent.frames.frame_alto.location=parent.frames.frame_alto.location;
		 }else
		   return(0);
	break;
 	case ('D'):
		str_lcl = 'Sei sicuro di volere ordinare '+ nomemodulo +' in relazione alla data di pubblicazione ?';
		 if (confirm(str_lcl)) {
			 // <![CDATA[
			   var myAjax = new Ajax.Request("/amministrazione/Ordina/DB_Ordina.asp", {method:'get',parameters:'Tipo_ord='+ sceltaordinamento +'&ID_Modulo='+ id_modulo})
			   parent.frames.frame_alto.location=parent.frames.frame_alto.location;
			 // ]]>
		 }else
		   return(0);
		 
	break;
 	case ('P') :
		str_lcl = 'Sei sicuro di volere ordinare '+ nomemodulo +' in modo personalizzato ?';
		 if (confirm(str_lcl)) 
		 	{
				parent.frames.frame_basso.location = '/amministrazione/ordina/ordina.asp?ID_Modulo='+id_modulo+'&TipoOrdine='+ sceltaordinamento;
			}
		 else
		   return(0);
	break;
	
 }
}
