//*********************************************************************
//***************	FUNZIONI DI UTILITA

//detect frame
if (top.location != location){
	top.location = location
}

//*********************************************************************
//***************	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;
	   }
	 	openPopup.newWindow=window.open(theURL,'',features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
		openPopup.newWindow.opener=window;
		//alert(features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight)
	}
}	//	end function openPoUp
//*********************************************************************


//*********************************************************************
//***	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(value){
 value = value.replace(/\s/g,'');
 return checkRegular('^(.+)@(.+)[\.]([a-zA-Z]{2,4})$',value);
} 



//*********************************************************************



//*********************************************************************
//*** isEmpty
// true - valore vuoto o di soli spazi
// false 
function isEmpty(value){
	var s = value.replace(/\s*/,'');
	return (s=='');
}	// end function isEmpty
//*********************************************************************

//*********************************************************************
//*** isInteger
// true - la stringa è un intero
// false 
function isInteger(value){
	return !(isNaN(parseInt(value, 10)));
}	// end function isInteger
//*********************************************************************

//*********************************************************************
//*** isFloat
// true - valore è un numero decimale
// false 
function isFloat(value){
	return !(isNaN(parseFloat(value, 10)));
}	// end function isFloat
//*********************************************************************

//*********************************************************************
//*** getInteger
// true - valore è un numero decimale
// false 
function getInteger(value){
	var i = parseInt(value, 10);
	if(isNaN(i))return 0;
	else return i;
}	// end function getInteger
//*********************************************************************

//*********************************************************************
//*** getFloat
// true - valore è un numero decimale
// false 
function getFloat(value){
	var f = parseFloat(value);
	if(isNaN(f))return 0.0;
	else return f;
}	// end function isFloat
//*********************************************************************


//*********************************************************************
//*** 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 
//*********************************************************************


// imposta il campo selezionato dal calendario in popup

function returnCalendarDta(tipoData, dtaObj){
	var myForm = document.forms['frmSearch'];
	var txtObj;
	switch (tipoData.toLowerCase()){
		case "dtabgn":
			txtObj = myForm.dtaInizio;
			break;
		case "dtaend":
			txtObj = myForm.dtaFine;
			break;
	}
	txtObj.value = dtaObj.getDate()+'/'+(dtaObj.getMonth()+1)+'/'+dtaObj.getFullYear();
}

// per cambiare link da flash di infotraffic
function infoGoDetail(keyAutostrada,codiceEvento){
	//alert(keyAutostrada);
	var ch = '';
	if (keyAutostrada == 'A32'){
		ch = '40.1.2.1';
	}
	else{
		ch = '40.2.2.1';
	}
	location.href = 'home.aspx?ch=' + ch + '&ce=' + codiceEvento
}


function swapImage(prefix,totImage,imgID){
	var vt = document.getElementById(imgID)
	vt.src = prefix +  rand(totImage) + '.jpg'; 
}


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 setRadioValue(oRdo, val){
	if(oRdo!=null)
	for(var i=0; i < oRdo.length; i++)
		if(oRdo[i].value==(val+'')){
			oRdo[i].checked = true;
			break;
		}
}

function addZeri(val,nZeri){
	var sRet;
	if ((val+'').length >= nZeri){
		sRet = val+'';
	}	
	else{
		sRet = val;
		for(var i=0;i<nZeri-(val+'').length;i++){
			sRet = '0' + sRet;
		}	
	}
	
	return sRet 
}


function getSelectValue(slc){
	return slc.options[slc.selectedIndex].value
}


function isCheckboxChecked(oRdo){
	var bRet = false
	if(oRdo!=null && isArray(oRdo)){
		for(var i=0; i < oRdo.length; i++){
			if(oRdo[i].checked){
				bRet = true
				break;
			}
		}	
	}	
	if(oRdo!=null && !isArray(oRdo)){
		if(oRdo.checked){
			bRet = true
		}	
	}
	return bRet	
}

function numberCheckboxChecked(oRdo){
	var iRet = 0
	if(oRdo!=null && isArray(oRdo)){
		for(var i=0; i < oRdo.length; i++){
			if(oRdo[i].checked){
				iRet ++;

			}
		}	
	}	
	if(oRdo!=null && !isArray(oRdo)){
		if(oRdo.checked){
			iRet = 1
		}	
	}
	return iRet	
}

function isArray(obj){return(typeof(obj.length)=="undefined")?false:true;}
