function CloseDiv(DivName,  SrcImage, Reset)
{
	if (Reset == 1)
	{
		CloseDiv(DivName,  SrcImage, Reset);
		CloseDiv(DivName,  SrcImage, Reset);
	}

	MyDiv = document.all[DivName];
	MyImg = document.all[SrcImage];

	if (MyDiv.style.display=='none')
	{
		MyDiv.style.display = "inline";
		MyImg.src = MyImg.src.replace('open', 'close');
	}
	else
	{
		MyImg.src = MyImg.src.replace('close', 'open');
		MyDiv.style.display = "none";
	}
}

function ProcUserAction (HtmlObject, Action)
{
	return;
}

function GoIFrame(DivName, IFrameName, Url, win, Layer2Open,ResizeWidth)
{
	var winObj;

	if( win )
	{
		if( typeof(win)=='object' )
			winObj = win;
		else
			winObj = document.all[win];
	}
	
	if( winObj && typeof(winObj)=='object' )
		DivFrame = winObj.document.all[DivName];
	else
		DivFrame = document.all[DivName];
    
//alert("DivFrame:"+DivFrame);

	if( ResizeWidth )
		DivFrame.style.width=ResizeWidth;

	if (DivFrame.XMCache==1 && DivFrame.XMUrl == Url && DivFrame.style.display=='none')
	{
		DivFrame.style.display = 'inline';
		alert('Estoy cacheando');
	}
	else
	{
		TxtFrame = "<iframe id=\""+IFrameName+"\" name=\""+IFrameName+"\" src='"+Url+"' height=\"100%\" width=\"100%\" frameborder=\"auto\"></iframe>";
		DivFrame.innerHTML = TxtFrame;
		DivFrame.XMCache = 1;
		DivFrame.XMUrl = Url;
		DivFrame.style.display = 'inline';
	}
	
	if( Layer2Open )
		if( document.all[Layer2Open].style.display=='none' )
			document.all[Layer2Open].style.display='inline';
}


function XSiteGo2URL(URL,FrameName,WindowName)
{
	var frameObj, winObj, Action, winAction;
//alert('sin nada');
	if( WindowName )
	{
		if( window.name!=WindowName )
		{
			if( parent.name==WindowName )
				winObj = parent;
			else
			{
				for(var i=0;i<window.frames.length;i++)
				{
					if( window.frames[i].name==WindowName )
					{
						winObj = window.frames[i];
						break;
					}
				}
			}
		}
	}
	else
		winObj = window;
	
	if( FrameName )
		frameObj = winObj.frames[i].location=URL;
	else
		if( winObj )
			winObj.location = URL;
		else
			this.location = URL;
		
	Action = "Cambiar URL desde "+window.location+" a "+URL;
	Action+= " Target ";
	if( FrameName ) winAction = " Frame: "+FrameName+";";
	if( WindowName ) winAction+= " Ventana: "+WindowName;
	if( winAction ) Action+= winAction;
	else Action+= " misma ventana";

	
	if( frameObj )
		ProcUserAction(frameObj,Action);
	else
		ProcUserAction(winObj,Action);
}

var ImagesName = "BtnMenuImg";
var SelectedMenuBtnIndex = new Array( "Left","Top");
var SelectedMenuBtn = new Array( new Array(), new Array() );


function CheckBtn2Swap(Position,BtnName,Src)
{
	for( var i=0; i<SelectedMenuBtnIndex.length; i++)
		if( SelectedMenuBtnIndex[i]==Position )
			PositionInd = i;

	if( BtnName == SelectedMenuBtn[PositionInd][0] )
		return;
	else
		MM_swapImage(BtnName+ImagesName+Position,'',Src,1);
}

// Activa un Botón del menu y cambia la URL de un Frame dentro de una Div dada
// 	Position 	-> Posición donde se encuenta el menu
//	BtnName		-> Prefijo del Nombre del botón a Activar (ej. XApps, para armar XAppsBtnMenuImg)
//	Src			-> Nuevo Src del botón
//	Url			-> Dirección Web para actualizar en el IFrame
//	DivName		-> Nombre de la Layer donde se encuentra el IFrame
//	IFrameName	-> Nombre del IFrame
//	Win			-> Nombre de la ventana donde buscar el IFrame
//	Layer2Open	-> Layer que deberá ser abierta al activar el botón	
function ActivateAndGo(Position,BtnName,Src,Url,DivName,IFrameName,Win,Layer2Open,ResizeWidth)
{
	for( var i=0; i<SelectedMenuBtnIndex.length; i++)
		if( SelectedMenuBtnIndex[i]==Position )
			PositionInd = i;

	var SelectedLeftMenuBtn = SelectedMenuBtn[PositionInd][0];
	var SelectedLeftMenuBtnSrc = SelectedMenuBtn[PositionInd][1];

	if( SelectedLeftMenuBtn==BtnName )
	{
		if( Url && DivName && IFrameName )
			GoIFrame(DivName,IFrameName,Url, Win, Layer2Open,ResizeWidth);
		return;
	}
	else
	{
		var TmpSrc = document.getElementById(BtnName+ImagesName+Position).src;
		var F2Ind = TmpSrc.indexOf('_f2',0);
		if( F2Ind > 0 )
		{
			var DotInd = TmpSrc.lastIndexOf('.');
			TmpSrc = TmpSrc.substring(0,F2Ind)+TmpSrc.substring(DotInd,TmpSrc.length);
		}
		document.getElementById(BtnName+ImagesName+Position).src = Src;
		if( SelectedLeftMenuBtn && SelectedLeftMenuBtnSrc )
			document.getElementById(SelectedLeftMenuBtn+ImagesName+Position).src = SelectedLeftMenuBtnSrc;
			
		SelectedMenuBtn[PositionInd][0] = BtnName;
		SelectedMenuBtn[PositionInd][1] = TmpSrc;

		if( Url && DivName && IFrameName )
			GoIFrame(DivName,IFrameName,Url, Win, Layer2Open,ResizeWidth);
	}
}

function ShowErrorLayer(SpecialDivName)
{
	var DivName = "PageErrorLayer";
	if( SpecialDivName ) DivName = SpecialDivName;
	
	if( !document.getElementById( DivName ) ) return;
	
	Url = "/operativa/index.php?Action=ShowError";
	RefreshAjaxDiv(DivName, Url);
	document.getElementById( DivName ).style.display="inline";
}


