/*--------------------------------------------------------------*/
/* FUNCTION:	popup_center									*/
/* DESCRIPTION: apre una finestra centrata						*/
/*--------------------------------------------------------------*/
function popup_center(page, name, width, height, resizable, scrollbars)
{
	var posX = (window.screen.width/2)-(width/2)
	var posY = (window.screen.height/2)-(height/2)
	var popup;
	
	paramw = "width=" + width + ",height=" + height + ",location=0,menubar=0,resizable="+resizable+",scrollbars="+scrollbars+",status=0,titlebar=0,toolbar=0,z-lock=0,screenX=" + posX + ",screenY=" + posY + ",left=" + posX + ",top=" + posY + " ,resizable=" + resizable
	popup = window.open(page,null,paramw)
	popup.focus();
}
/*----------------------------------------------------*/	
/* FUNCTION     : Trim		   	                      */
/* DESCRIPTION  : esegue il trim della stringa	      */
/* PARAMETERS					                      */
/*----------------------------------------------------*/
function Trim(str)
{
	while(str.substr(0,1)==' ')
		str=str.substr(1)
	while(str.substr(str.length-1)==' ')
		str=str.substr(0,str.length-1)	
	return str
}
/*----------------------------------------------------*/	
/* FUNCTION     : CheckEmail						  */
/* DESCRIPTION  : esegue il controllo della mail      */
/* PARAMETERS					                      */
/*----------------------------------------------------*/
function CheckEmail(ValoreInput)
{
var tc = false;
var tp = false;
var pc = -1;
var pp = -1;

        for (var i=0; i<= ValoreInput.length; i++)
                {
                if (ValoreInput.charAt(i) == "@")
                        {
                        tc = true;
                        pc = i;
                        }
                else
                        {
                        if (ValoreInput.charAt(i) == ".")
                                {
                                tp = true;
                                pp = i;
                                }
                        }
                }
        if ((tc && tp) && (pc < pp))
                return true
        else
                return false
}
/*----------------------------------------------------*/	
/* FUNCTION     : IsDate	                          */
/* DESCRIPTION  : Check if data is a data and		  */
/*				 return true else return false		  */
/* PARAMETERS                                         */
/*     data      : (IN) string to check			      */
/*----------------------------------------------------*/
function IsDate(data)
{
	var dataVect,dataObj;
	
	dataVect=data.split("/")
	if (dataVect.length!=3)
			return false
	else 
		{
			
			if (dataVect[0].length!=1 && dataVect[0].length!=2)
				return false
				
			if (dataVect[1].length!=1 && dataVect[1].length!=2)
				return false
			
			if (dataVect[2].length!=4)
				return false
						
			//oggetto data considera i mesi da 0 a 11
			dataVect[1]-=1
			dataObj=new Date(dataVect[2],dataVect[1],dataVect[0])
			if (dataObj.getDate()==dataVect[0] && dataObj.getMonth()==dataVect[1] && dataObj.getFullYear()==dataVect[2] )
				 return true
			else return false
		}	
}
/*---------------------------------------------------------------*/	
/* FUNCTION     : CompareDate	     							 */
/* DESCRIPTION  : compare two date							 	 */
/* PARAMETERS												     */
/*	  data1		: data to compare								 */
/*	  data2		: data to compare								 */
/*	RETURN VALUES												 */
/*				: 0  if data1=data2								 */	
/*				: 1  if data1>data2								 */	
/*				: -1 if data1<data2								 */	
/*---------------------------------------------------------------*/
 function CompareDate(data1,data2)
 {
	var Vect1,Vect2;
	var i;
	
	Vect1=data1.split("/")
	Vect2=data2.split("/")
	
	for (i=0;i<Vect1.length;i++)
		Vect1[i]=parseInt(DelZero(Vect1[i]))
	
	for (i=0;i<Vect2.length;i++)
		Vect2[i]=parseInt(DelZero(Vect2[i]))
		
	if 	(Vect1[0]==Vect2[0] && Vect1[1]==Vect2[1] && Vect1[2]==Vect2[2])
		return 0
		
	if 	(Vect1[2]>Vect2[2] || (Vect1[2]==Vect2[2] && Vect1[1]>Vect2[1]) || (Vect1[2]==Vect2[2] && Vect1[1]==Vect2[1] && Vect1[0]>Vect2[0]))
		 return 1
	else return -1		
 }	
/*---------------------------------------------------------------*/	
/* FUNCTION     : DelZero										 */
/* DESCRIPTION  : Delete all char = "0" to the left of str		 */
/* PARAMETERS												     */
/*	  str	: (IN) string to delete								 */
/*---------------------------------------------------------------*/
function DelZero(str)
{
	while(str.charAt(0)=='0')
		str=str.substr(1)
		
	if (str=="")
		return parseInt("0")
	else
		return parseInt(str)
}
 
