
// ***********************************************************************************************************
// popupWin
// Opens A Popup Window centered on the screen
// ***********************************************************************************************************
function popupWin(theURL,winName,features,wsize,hsize) {    
	LeftPosition = (screen.width / 2) - (wsize / 2);
	TopPosition = (screen.height / 2) - (hsize / 2);
    features=features+',height='+hsize+',width='+wsize+',top='+TopPosition+',left='+LeftPosition;
    window.open(theURL,winName,features);
}

// ***********************************************************************************************************
// popWin
// Opens A Popup Window
// ***********************************************************************************************************
function popWin(theURL,winName) {    
    window.open(theURL,winName);
}



// UpperCase 
// use example: onchange="uppercase(this)"
function uppercase(field){
	field.value = field.value.toUpperCase();
}


function trim(sValue){
	return sValue.replace(/^\s*(.*?)\s*$/g, "$1");
}

function checkText(nomeForm,nomeCampoDato,nomeCampoTesto,messaggio, testo) {
	var fDato=eval (nomeForm+nomeCampoDato );
	var fTesto=eval (nomeForm+nomeCampoTesto );
	if (trim(fDato.value)!="" 
		&& trim(fTesto.value)==""){
			self.alert(messaggio);
			fTesto.value=testo;
			fTesto.focus();
	}
}


// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}
