var marked_row = new Array;
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor) {
	var theCells = null;
	if((thePointerColor == '' && theMarkColor == '') || typeof (theRow.style) == 'undefined') {
		return false
	}
	if( typeof (document.getElementsByTagName) != 'undefined') {
		theCells = theRow.getElementsByTagName('td')
	} else if( typeof (theRow.cells) != 'undefined') {
		theCells = theRow.cells
	} else {
		return false
	}
	var rowCellsCnt = theCells.length;
	var domDetect = null;
	var currentColor = null;
	var newColor = null;
	if( typeof (window.opera) == 'undefined' && typeof (theCells[0].getAttribute) != 'undefined') {
		currentColor = theCells[0].getAttribute('bgcolor');
		domDetect = true
	} else {
		currentColor = theCells[0].style.backgroundColor;
		domDetect = false
	}
	if(currentColor == '' || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
		if(theAction == 'over' && thePointerColor != '') {
			newColor = thePointerColor
		} else if(theAction == 'click' && theMarkColor != '') {
			newColor = theMarkColor;
			marked_row[theRowNum] = true
		}
	} else if(currentColor.toLowerCase() == thePointerColor.toLowerCase() && ( typeof (marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
		if(theAction == 'out') {
			newColor = theDefaultColor
		} else if(theAction == 'click' && theMarkColor != '') {
			newColor = theMarkColor;
			marked_row[theRowNum] = true
		}
	} else if(currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
		if(theAction == 'click') {
			newColor = (thePointerColor != '') ? thePointerColor : theDefaultColor;
			marked_row[theRowNum] = ( typeof (marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum]) ? true : null
		}
	}
	if(newColor) {
		var c = null;
		if(domDetect) {
			for( c = 0; c < rowCellsCnt; c++) {
				theCells[c].setAttribute('bgcolor', newColor, 0)
			}
		} else {
			for( c = 0; c < rowCellsCnt; c++) {
				theCells[c].style.backgroundColor = newColor
			}
		}
	}
	return true
}

function viewHideObj(idDiv, mode) {
	if(!$(idDiv))
		return false;
	$(idDiv).style.display = mode
}

function hideAllObj(radiceDiv) {
	if(radiceDiv == "")
		return false;
	var allDiv = $A($$('div'));
	allDiv.each(function(s, index) {
		if(s.id.indexOf(radiceDiv) >= 0)
			$(s).style.display = 'none'
	})
}

function hideComponentiDescr(oInput) {
	var allDivComp = $A($$('div'));
	allDivComp.each(function(s, index) {
		if(s.id.indexOf("componente_") >= 0)
			$(s).style.display = 'none'
	});
	$("componente_" + oInput.value).style.display = 'inline'
}

function askConfirmation(operazione, link) {
	var msgElimina = "Sei sicuro di voler eliminare definitivamente questo record?";
	var go = false;
	if(operazione != "elimina" || (operazione == "elimina" && confirm(msgElimina)))
		go = true;
	if(go)
		document.location = link
}

function thumbLoad(targetName, imageFile) {
	$(targetName).src = $(imageFile).value;
	$(targetName).setStyle({
		display : 'inline'
	})
}

function manageCheckAll(radiceIdCheckbox, operation) {
	var allInput = $A($$('input'));
	allInput.each(function(i, index) {
		if(i.type == "checkbox" && !i.disabled && i.id.indexOf(radiceIdCheckbox) >= 0) {
			if(operation && !i.checked)
				i.checked = true;
			if(!operation && i.checked)
				i.checked = false
		}
	})
}

function PopupCenter( pageURL, title, w, h, view, fullWidth, fullHeight ) 
{
	var left = ( view == "orizzontale" || view == "orizzontale&verticale" ) ? (screen.width / 2) - (w / 2) : 0;
	var top = ( view == "verticale" || view == "orizzontale&verticale" ) ? (screen.height / 2) - (h / 2) : 0;
	var w = ( fullWidth ) ? screen.width : w;
	var h = ( fullHeight ) ? screen.height - 100 : h;
	
	var targetWin = window.open(pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
}

