function MM_swapImgRestore() {
  var i,x,a=document.MM_sr; 
  for ( i = 0; a && i<a.length && (x = a[i]) && x.oSrc; i++ )
	x.src = x.oSrc;
}

function MM_preloadImages() {
	var d = document; 
	if ( d.images )
	{
		if ( !d.MM_p )
			d.MM_p = new Array();
		var i, j = d.MM_p.length, a = MM_preloadImages.arguments;
		
		for ( i = 0; i < a.length ; i++ )
			if ( a[i].indexOf("#") != 0 )
			{
				d.MM_p[j] = new Image;
				d.MM_p[j++].src = a[i];
			}
	}
}

function MM_findObj(n, d)
{
	var p,i,x;
	if(!d)
		d=document;
	if ( (p = n.indexOf("?")) > 0 && parent.frames.length )
	{
		d = parent.frames[n.substring(p+1)].document;
		n = n.substring(0,p);
	}
	if ( !(x = d[n]) && d.all )
		x = d.all[n];
	for ( i=0; !x && i < d.forms.length; i++ )
		x = d.forms[i][n];
	for ( i=0; !x && d.layers && i < d.layers.length; i++)
		x = MM_findObj(n,d.layers[i].document);

	if ( !x && d.getElementById )
		x = d.getElementById(n);
	return x;
}

function MM_swapImage() {
	var i, j = 0, x, a = MM_swapImage.arguments;
	document.MM_sr = new Array;
	for ( i = 0; i < (a.length-2); i+=3 )
		if ( (x = MM_findObj(a[i])) != null)
		{
			document.MM_sr[j++]=x;
			if( !x.oSrc )
				x.oSrc = x.src;
			x.src = a[i+2];
		}
}

// Used to retrieve the currently selected radio button,
// and updates the background colors to match the selected item.
function getSelectedRadioButton() {
	var form = document.forms("ItemOrdering");
	var formElements = form.elements;
	var returnRadio = null;
	var tdElement;
	
	for (var i = 0; i < formElements.length; i++) {
		if (formElements[i].type == "radio") {
			tdElement = findNearestParentOfType(formElements[i], "TD");
			if (formElements[i].checked) {
				returnRadio = formElements[i];
				tdElement.style.backgroundColor = "#CCCCDD";
			} else {
				tdElement.style.backgroundColor = "#FFFFFF";
			}						
		}
	}
	return returnRadio;
}

// Moves the selected button's table row up or down.
function moveRow(bUpDown) {
	var radioButton = getSelectedRadioButton();
	
	// traverse up the parent chain until we reach the nearest
	// parent TR element, if there is one
	var pTableRow = findNearestParentOfType(radioButton, "TR");
	
	if (pTableRow != null) {
		var nRowIndex = pTableRow.rowIndex;
	
		var pTable = findNearestParentOfType(pTableRow, "TABLE");
		
		if (pTable != null) {
			if (bUpDown) {
				pTable.rows[nRowIndex].swapNode(pTable.rows[nRowIndex - 1]);
			} else {
				pTable.rows[nRowIndex].swapNode(pTable.rows[nRowIndex + 1]);
			}
		}
	}
	
	// Reset the selection and enable/disable buttons as necessary.
	radioButton.checked = true;
	toggleButtons();			
}

function toggleButtons() {
	var radioButton = getSelectedRadioButton();
	
	// Climb up the hierarchy to find the enclosing <tr>
	var pParentElement = radioButton;
	
	// traverse up the parent chain until we reach the nearest
	// parent TR element, if there is one
	var pTableRow = findNearestParentOfType(radioButton, "TR");
	
	if (pTableRow != null) {
		var nRowIndex = pTableRow.rowIndex;
		
		// If its the first row, disable "Up".
		if (nRowIndex == 0) {
			document.all("UpButton").disabled = true;
		} else {
			document.all("UpButton").disabled = false;
		}
		
		var pTable = findNearestParentOfType(pTableRow, "TABLE");
		
		// If its the last row, disable "Down".
		if (pTable != null) {			
			var numRows = pTable.rows.length;
			
			if (nRowIndex == numRows - 1) {
				document.all("DownButton").disabled = true;
			} else {
				document.all("DownButton").disabled = false;
			}
		}
	}
}

function findNearestParentOfType(element, strType) {
	while ( (element != null) &&
			(element.tagName != strType) )
	{
		element = element.parentElement;
	}
	
	// if we found a table row, return it.
	if ( (element != null) && 
		(element.tagName == strType) )
	{
		return element;
	} else {
		return null;
	}
}

function setOrderAndSubmit() {
	// Find the table and list the order.
	var table = document.all("tblItems");
	
	for (var i = 0; i < table.rows.length; i++) {
		// Retrieve the corresponding hidden element for the row.
		var thisHiddenElement = document.forms("ItemOrdering").item(String(i));
		
		// Set the value of the hidden element.
		thisHiddenElement.value = table.rows[i].id;
	}
	
	// Now submit the form.
	document.forms("ItemOrdering").submit();
}

function onCancel() {
	window.close();
}

function CenteredPopUpWindow(url,width,height,target) {
	if (document.all)
		var xMax = screen.width, yMax = screen.height;
	else
		if (document.layers)
			var xMax = window.outerWidth, yMax = window.outerHeight;
		else
			var xMax = 640, yMax=480;
	var xOffset = (xMax - width)/2, yOffset = (yMax - width)/2;		
	var sFeatures="height="+height+",width="+width+",center=yes,titlebar=no,menubar=no,toolbar=no,location=no,resizable=no,status=no";
	sFeatures+=",left="+xOffset+",top="+yOffset;
	window.open(url, target, sFeatures);
}

function changeMenu(nSpanNumber, nDivPos){
	var killMenu
	for	(i=0;i<arrHiddenMenus.length;i++){
		arrHiddenMenus[i].style.left=-200
	}
	arrHiddenMenus[nSpanNumber].style.left = nDivPos
	clearTimeout(killMenu)
	killMenu = window.setTimeout("deleteMenu()", 1500);		
}

function deleteMenu(){
	for(i=0;i<arrHiddenMenus.length;i++){
		arrHiddenMenus[i].style.left=-200
	}
}

function showDiv(divName)
{
	var divs = document.getElementsByTagName("div");
	var id;
	if (ht != null)
	{
		for ( count = 0; count < divs.length; count++ )
		{
			if ( divs.item(count).id != divName )
			{
				if (ht[divs.item(count).id + 'TD'] != null)
				{	
					divs.item(count).style.display = "none";
					ht[divs.item(count).id + 'TD'] = 0;
					document.getElementById(divs.item(count).id + 'TD').className = "MainHPMenu"
				}
			}
			else
			{
				divs.item(count).style.display = "inline";
				ht[divs.item(count).id + 'TD'] = 1;
				document.getElementById(divs.item(count).id + 'TD').className = "MainHPMenuSelected"
			}
		}
	}
}

function setDivHeight(divName)
{
	var myWidth = 0;
	var myHeight = 0;
	
	if( typeof( window.innerWidth ) == 'number' ) 
	{
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
	{
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
	{
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	
	//MARCO 20060614
	//DETECTAR FIREFOX
	if(navigator.userAgent.indexOf("Firefox")!=-1)
	{
		//myHeight = myHeight - 288; //ffox
		myHeight = myHeight - 161; //ffox
	}
	else
	{
		myHeight = myHeight - 161;  //ie
	}
		
	//myHeight = myHeight - 156; //old
	//myHeight = myHeight - 226; //ie
	//myHeight = myHeight - 288; //ffox
	
	var element = document.getElementById(divName);
	
	if (element != null)
		element.style.height = myHeight;
}

function disableRightClick(message)
{
	function click(e) 
	{
		if (document.all)
		{
			if (event.button == 2)
			{
				alert(message);
				return false;
			}
		}
		if (document.layers)
		{
			if (e.which == 3)
			{
				alert(message);
				return false;
			}
		}
	}

	if (document.layers)
	{
		document.captureEvents(Event.MOUSEDOWN);
	}
	document.onmousedown=click;
}