//-------------------------------------------------------------------------------------------------------------------------
function check_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
      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 del_to_multiline(oggetto)
{
if (oggetto.selectedIndex != -1 )
  oggetto.options.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;
}


