//*********************************************************************
//***************	FUNZIONI DI UTILITA

//*********************************************************************
//***	openPopup
// apertura popup
openPopup.newWindow=null;
function openPopup(theURL,winName,features, myWidth, myHeight, isCenter) { //v3.0
	if((openPopup.newWindow!=null)&&(!openPopup.newWindow.closed)){
		//alert('closing...'+openPopup.newWindow.closed);
		//openPopup.newWindow.close();
		openPopup.newWindow.focus();
		openPopup.newWindow.location=theURL;
	}else{
	 	if(window.screen)if(isCenter)if(isCenter=="true"){
	    var myLeft = (screen.width-myWidth)/2;
	    var myTop = (screen.height-myHeight)/2;
	    features+=(features!='')?',':'';
	    features+='left='+myLeft+',top='+myTop;
	   }
//	   alert(features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
	 	openPopup.newWindow=window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
	 	
		openPopup.newWindow.opener=window;
//		alert(features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight)
	}
}	//	end function openPoUp
//*********************************************************************


//
//
function hasNoValue(value){
	var bRet;
	var s = value.replace(/\s*/,'');
	
	if(s=='')bRet=true;
	else bRet=false;
	
	return bRet
}

//
//
function checkSelect(slc){
	var sRet='';
	sRet = slc.options[slc.selectedIndex].value;
	return sRet;
}

//
//
function checkRadio(rdo){
	var bRet=false;
	for(var i=0;i<rdo.length;i++){
		if(rdo[i].checked){
			bRet=true;
			break;
		}
	}
	return bRet;
}

//*********************************************************************
//***	checkRegular
// utilizzata per verificare il match con una regular expression
function checkRegular(regS,value){
	var re=new RegExp(regS);
	return re.test(value)
}	// end function checkRegular
//*********************************************************************


//*********************************************************************
//*** isEmail
// true - email formalmente valida
// false - email non valida

function isEmail(str){
  
  var re = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i
  return re.test(str);
}
//*********************************************************************
//*** isNumeric
// true - email formalmente valida
// false - email non valida
function isNumeric(value){
	return checkRegular('^[0-9]+$',value);
}	// end function isEmail
//*********************************************************************

//*********************************************************************
//*** isDecimal
// true - email formalmente valida
// false - email non valida
function isDecimal(value){
	return checkRegular('^[0-9]+([.,]{0,1}[0-9]+)*$',value);
}	// end function isEmail
//*********************************************************************

//*********************************************************************
//*** chkSelectedSelect (IN: oggetto select, riferimento per non selezionata)
// true - select selezionata
// false - select non selezionata
function chkSelectedSelect(oSlc,sRef){
	if(oSlc!=null){
		var cSel = oSlc.options[oSlc.selectedIndex].value;
		return cSel!=sRef;
	}else{
		return false;
	}
}	// end function isEmail
//*********************************************************************


//*********************************************************************
//*** formatValueIT (IN: float)
// 
// ritorna il valore formattato con due decimali come stringa
function formatValueIT(f){
//	alert('formatValue: IN - ' +f);
	var s,pi,pf,sf;
	s = f+'';
	
	if(f!=null&&s!=''){
		pi=parseInt(s.substring(0,(s.indexOf('.')>0 ?s.indexOf('.') : s.length)),10);
		pf=Math.round((f-pi)*100);
		if(pf<10)sf='0'+(pf+'');
		else sf=pf+'';
		return pi+','+sf;
	}else{
		return '0,00';
	}
}//

function getFloat(s){
	var fRet;
	if(isDecimal(s)){
		fRet = parseFloat(s.replace(",","."));
	}else{
		fRet = 0.0;
	}
	return fRet;
}

function setSelectValue(oSlc, val){
	if(oSlc!=null)
		for(var i=0; i<oSlc.options.length; i++)
			if(oSlc.options[i].value==(val+'')){
				oSlc.options[i].selected = true;
				break;
			}
}

function setRadioButton(oRdo, val){
	if(oRdo!=null)
		for(var i=0; i<oRdo.length; i++)
			if(oRdo[i].value==(val+'')){
				oRdo[i].checked = true;
				break;
			}
}

function getValidDateITA(str){
	var ss;
	var d;
	var m;
	var y;
	var bTmp;
	var sRet;

	if(str!=null){
		if(str.indexOf('/')>=0)	ss=str.split('/');
		if(str.indexOf('-')>=0)	ss=str.split('-');
	}
	
	if(ss!=null){
		d = parseInt(ss[0], 10);
		m = parseInt(ss[1], 10);
		y = parseInt(ss[2], 10);
		if(isNaN(d)||isNaN(m)||isNaN(y)){
			bTmp = false;
		}else{
			bTmp =  (d>0 && d<32) && (m>0 && m<13) && (y>1900 && y<2100);
		}
	}else{
		bTmp = false
	}

	if(bTmp){
		var dta = new Date(y,m-1,d);
		d=dta.getDate();
		m=dta.getMonth()+1;
		y=dta.getFullYear();
		sRet = (d<10?'0':'') + d + '/' + (m<10?'0':'') + m + '/' + y;
	}else{
		sRet = '';
	}
	return sRet;
}
