/*La funzione converte il comando Return
 *con la funzione di TAB.*/
function convertEnterKey(obj,form)
{ 
	var nextTabIndex=0;
	if (window.event.keyCode == 13)
		{ 
		nextTabIndex = obj.tabIndex + 1;
		for(var i=0;i<form.elements.length;i++)
			{
			if(form.elements(i).tabIndex==nextTabIndex && form.elements(i).disabled!=true)
				{
					form.elements(i).focus();
					break;
				}
			}
		}
}
/*
 * La funzione effettua il confronto tra due date.
 * Se la prima è maggiore della seconda ritorna 1
 * Se la prima è uguale alla seconda ritorna 0
 * Se la prima è minore della seconda ritorna -1
 */
function confrontoDate(first,second){
	var ret			=-1;
	var firstDate	= new Date(first);
	var secondDate	= new Date(second);
							                        
	if ( firstDate.getTime() > secondDate.getTime()){ 
		ret= 1;
	} else if (firstDate.getTime() == secondDate.getTime()){
		ret= 0;
	}
	return ret;
}
/*  -----------------------------20/10/2001------------------------------------------
	Questa funzione formatta una stringa contenuto in un oggetto(es. Casella di Testo)
	nel formato "gg/mm/aaaa".Se nella stringa non sono presenti i caratteri "/"
	provvederà la funzione stessa a concatenarli.Viene fatto un ulteriore controllo
	sulla validità della stringa ottenuta in input.
 */

function FormatDate ( oField )
{
     var cDate = oField.value.replace( /[\W\D\s]/gi, '' ); 
     if( cDate.length == 8 || cDate.length == 10)
        {
          var cDay = cDate.substring(0,2);   // estrazione giorno
          var cMonth = cDate.substring(2,4); // estrazione mese
          var cYear = cDate.substring(4);    // estrazione anno
          if( cDay.match(/^([0-2]?\d|3[01])$/) && cMonth.match(/^(0?\d|1[0-2])$/) && cYear.match(/^[1-9]\d\d\d$/) ) 
			{
			   oField.value = cDay+'/'+cMonth+'/'+cYear; 
			   if ( parseInt(cYear) < 1800 )
					{	
						oField.focus();
						alert ( 'Inserire una data con un anno valido' ); 
						return false;					
					}
			} 
          else
            { 
               oField.focus();
               alert ( 'Inserire una data valida!' ); 
               return false;
            }     
        } 
      else 
            { 
			  if( cDate.length != 0 )
			  {            
				oField.focus();
				alert ( 'Inserire la data nel formato gg/mm/aaaa!' ); 
				return false;
              }
            }

      if ( cDay == '00' || cMonth == '00')
	{
            oField.focus();
            alert ( 'Inserire una data valida!' ); 
            return false;
	}

      return true;
}
/*La funzione consente l'immissione
* di caratteri numerici 0-9 e dei caratteri*/
function soloNumeri(){
	if	(window.event.keyCode < 48 || window.event.keyCode>57){
			
		window.event.keyCode=0;
	}
}

/*La funzione consente l'immissione
* di caratteri numerici 0-9-, e dei caratteri*/
function KeyCodeImporti(){
	if	(window.event.keyCode < 48 || window.event.keyCode>57){
		if (window.event.keyCode != 44)	{
			window.event.keyCode=0;
		}
	}
}


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 controllaCampo(campoform,lunghezza)
{
         if (campoform.value.length < lunghezza)
             return campoform;   
            
         return false;
            
}

	function checkVirgole(stringa)
	{
	    var app='';
	    var x=0;
	    var numero=0;
	    
	    var pippo = stringa.toString();
	    
		for ( x=0; x<pippo.length; x++ )
			{
			  if ( pippo.substr(x,1) == ',' )
				  { numero = numero + 1; }
			}
		
		if ( numero > 1 )
			{ return false; }
			

		if ( pippo.substr(0,1) == ',' )
			{ return false; }			
		
		if ( pippo.substr(pippo.length-1,1) == ',' )
			{ return false; }			
			
		return true;	
	}

/*La funzione controlla il formato di un campo prezzo*/
function checkImporto(importo)
{
	var status = true;
	var lunghezza   = importo.value.length;
	var wimporto     = importo.value;
        
	var senza_virgole = importo.value.replace(/,/g,'');

	// se il numero delle virgole è maggiore di 1 è errore
	if ( ( lunghezza - senza_virgole.length ) > 1 )
		{
             	alert ('Importo errato');
	     	status = false;
		}

	// se il primo e ultimo carattere è una virgola errore
	if ( status == true )
		{
		if ( Left(wimporto,1) == ',' || Right(wimporto,1) == ',' )
			{
             		   alert ('Importo errato');
	     		   status = false;
			}
		}
	return status;
}

/*La funzione disabilita i tasti F5-F11-BackSpace*/
function handlePress(key) 
	{
	   //  BACKSPACE = 8
	   //  F11       = 122
	   //  F5        = 116
	   
	   var codice = window.event.keyCode;
	   // alert ( codice );
	   if ( codice == 8 )
	   {
	        var app='';
	        var tag='';
	            tag=document.activeElement.tagName;
	            if ( tag == 'INPUT' || tag == 'TEXTAREA' )
					{
					}
				else
				    {	
					  window.event.returnValue=false; 					
					}
	   }
		if ( codice == 122 || codice == 116 )
			{
				event.keyCode=0; 	
				window.event.returnValue=false; 						
			}
	}

var dropboxleft=10 //set left position of box (in px)
var dropboxtop=100 //set top position of box (in px)
var dropspeed=10 //set speed of drop animation (larger=faster)

//Specify display mode. 3 possible values are:
//1) "always"- This makes the fade-in box load each time the page is displayed
//2) "oncepersession"- This uses cookies to display the fade-in box only once per browser session
//3) integer (ie: 5)- Finally, you can specify an integer to display the box randomly via a frequency of 1/integer...
// For example, 2 would display the box about (1/2) 50% of the time the page loads.

var displaymode="always"

///Don't edit beyond here///////////
if (parseInt(displaymode)!=NaN)
var random_num=Math.floor(Math.random()*displaymode)
var ie=document.all
var dom=document.getElementById

function initboxv2(){
	if (!dom&&!ie)
	return
	crossboxcover=(dom)?document.getElementById("dropinboxv2cover") : document.all.dropinboxv2cover
	crossbox=(dom)?document.getElementById("dropinboxv2"): document.all.dropinboxv2
	scroll_top=(ie)? truebody().scrollTop : window.pageYOffset
	crossbox.height=crossbox.offsetHeight
	crossboxcover.style.height=parseInt(crossbox.height)+"px"
	crossbox.style.top=crossbox.height*(-1)+"px"
	crossboxcover.style.left=dropboxleft+"px"
	crossboxcover.style.top=dropboxtop+"px"
	crossboxcover.style.visibility=(dom||ie)? "visible" : "show"
	dropstart=setInterval("dropinv2()",50)
}

function dropinv2(){
		
	scroll_top=(ie)? truebody().scrollTop : window.pageYOffset
		
	if (parseInt(crossbox.style.top)<0){
		crossboxcover.style.top=scroll_top+dropboxtop+"px"
		crossbox.style.top=parseInt(crossbox.style.top)+dropspeed+"px"
	}
	else{
		clearInterval(dropstart)
		crossbox.style.top=0
	}
}

function dismissboxv2(){
	if (window.dropstart) clearInterval(dropstart)
	crossboxcover.style.visibility="hidden"
}

function truebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}	