
/*
isDate(xField, xMsg)
isEMail(xField, xMsg)
isRequired(xField, xMsg)
isSelectionRequired(xField, xMsg)
isNumeric(xField, xMsg)
isAtLeast (xField, xLen, xMsg)
Activate()
DeActivate()
ReActivate()
CenterMe()
isRadioSelected(buttonGroup, xMsg)
copyTo(obj)
popupform(myform, windowname)
ApriPopUp(parmUrl, parmNome, parmFormato)
SetSize(parmFormato)
isChecked(xField, xMsg)
*/
function isDate(xField, xMsg){
	// Funzione che verifica se il campo xField è di tipo dato
	tmpDate = new Date(xField.value);
	if (tmpDate=='NaN'){
		if(xMsg!='')
			alert(xMsg);
		return false;
	}
	else
		return true;
}
function isEMail(xField, xMsg){
	// Funzione che verifica se il campo xField è di tipo EMail
	pos = xField.value.indexOf('@');
	if(pos < 1 || pos > xField.value.length - 3){
		if(xMsg!='')
			alert(xMsg);
		return false;
	}								
	else
		return true;
}
function isRequired(xField, xMsg){
	// Funzione che verifica se il campo xField è valorizzato
	if (xField.value == '' || xField.value==' '){
		if(xMsg!='')
			alert(xMsg);
		return false;
	}								
	else
		return true;
}
function isSelectionRequired(xField, xMsg){
	// Funzione che verifica se il campo xField (di tipo select) ha un valore selezionato
	if (xField.selectedIndex == 0){
		if(xMsg!='')
			alert(xMsg);
		return false;
	}								
	else
		return true;
}
function isNumeric(xField, xMsg){
	// Funzione che verifica se il campo xField è di tipo numerico
	if (parseFloat(ReplaceVP(xField.value))!=ReplaceVP(xField.value)){
		if(xMsg!='')
			alert(xMsg);
		return false;
	}								
	else
		return true;
}
function isAtLeast (xField, xLen, xMsg){
	// Funzione che verifica se il campo xField è lungo almento xLen caratteri
	if (xField.value.length < xLen){
		if(xMsg!='')
			alert(xMsg);
		return false;
	}								
	else
		return true;
}
function Activate(){
	// Funzione che imposta il focus sulla pagina
	document.SullaPagina = 1;
}
function DeActivate(){
	// Funzione che rileva la perdita del focus su di un campo
	document.SullaPagina = 0;
	setTimeout("ReActivate()", 400);
}
function ReActivate(){
	// Funzione che se rileva la perdita del focus sulla pagina ce lo riporta
	if(document.SullaPagina==0){
		document.SullaPagina = 1;
		window.focus();		
	}
}
function CenterMe(){

	// Funzione per la centratura dei pop-up	
	var windowW = window.outerWidth;
	var windowH = document.body.clientWidth;
	
	if (document.all){
		 windowW=document.body.offsetWidth;
		 windowH=document.body.offsetHeight ;		
	}
	var windowX = Math.ceil( (window.screen.width  - windowW) / 2 );
	var windowY = Math.ceil( (window.screen.height - windowH) / 2 );

	/*tmt_Resize_WindowX = 800;
	tmt_Resize_WindowY = 550;
	self.resizeTo(tmt_Resize_WindowX,tmt_Resize_WindowY);*/
	self.moveTo(windowX,windowY);
}


function isRadioSelected(buttonGroup, xMsg){   
	// Funzione che rileva la selezione di un radio all'interno del suo gruppo
	var resValue = false;
 	if (buttonGroup[0]) {
  	for (var i=0; i<buttonGroup.length; i++) {
    	if (buttonGroup[i].checked) {
        resValue = true;
      }
    }
  }
	else {
  	if (buttonGroup.checked) { resValue = true; }
   }
   if(!resValue && xMsg != '')
	 	alert(xMsg);
   return resValue;
}
	
function copyTo(obj)
{
 if (obj.type == "text") var oControlRange = obj.createTextRange()
  else{var oControlRange = document.body.createTextRange();
       oControlRange.moveToElementText(obj);}
  oControlRange.execCommand("copy");
}

function popupform(myform, windowname)
{
	// Funzione che fa aprire in un pop-up il submit di una form, va messa alla fine della validazione dei dati
	if (! window.focus)return true;
	window.open('', windowname, 'height=100,width=300,scrollbars=no');
	myform.target=windowname;
	return true;

}

function ApriPopUp(parmUrl, parmNome, parmFormato){
	// Funzione di apertura pop-up standardizzato
	if (parmNome =='')
		parmNome = 'Pop';
	switch (parmFormato.toUpperCase()){
		case '01':
			altezza = 180;
			larghezza = 350;
			break;
		case '02':
			altezza = 280;
			larghezza = 340;
			break;
		case '03':
			altezza = 400;
			larghezza = 570;
			break;
		case '04':
			altezza = 300;
			larghezza = 420;
			break;
		case '05':
			altezza = 250;
			larghezza = 420;
			break;
		case '06':
			altezza = 530;
			larghezza = 420;
		case '07':
			altezza = 560;
			larghezza = 420;
			break;
		default:
			altezza = 300;
			larghezza = 520;
	}
	xW = window.open(parmUrl,parmNome,'status=yes,scrollbars=yes,resizable=yes,width=' + larghezza + ',height=' + altezza);
	xW.focus();
}
function SetSize(parmFormato){
	switch (parmFormato.toUpperCase()){
		case '01':
			altezza = 180;
			larghezza = 350;
			break;
		case '02':
			altezza = 290;
			larghezza = 350;
			break;
		case '03':
			altezza = 400;
			larghezza = 570;
			break;
		case '04':
			altezza = 160;
			larghezza = 335;
			break;
		case '05':
			altezza = 250;
			larghezza = 420;
			break;
		case '06':
			altezza = 530;
			larghezza = 420;
			break;
		case '07':
			altezza = 340;
			larghezza = 420;
			break;
		default:
			altezza = 300;
			larghezza = 520;
	}
	self.resizeTo(larghezza, altezza);
CenterMe();
}
function isChecked(xField, xMsg){
	// Funzione che verifica se il campo xField è di tipo numerico
	if (!xField.checked){
		if(xMsg!='')
			alert(xMsg);
		return false;
	}								
	else
		return true;
}

function Replace(stOrigine, chrConfronto, chrSostituzione) {

	temp = "" + stOrigine; 
	
	while (temp.indexOf(chrConfronto)>-1) {
	pos= temp.indexOf(chrConfronto);
	temp = "" + (temp.substring(0, pos) + chrSostituzione + temp.substring((pos + chrConfronto.length), temp.length));
	}
	return temp;
}
function ReplaceVP(stValore){
	return Replace(stValore, ',', '.')
}
function ReplacePV(stValore){
	return Replace(stValore, '.', ',')
}
