var popUp;
var popUpToolTip;
var _toolTips = "";
function ShowIcon(Tipo, toolTips) {
    if (top.frames['HelpIcon'].document.readyState == "complete") {
        if (toolTips == null)
            toolTips = _toolTips;
        else
            _toolTips = toolTips;
        if (top.frames['HelpIcon'].document.getElementById('HdnHideLogoutButton')==null){
		if (top.frames['WorkArea'].FrameHelpIcon){
	            top.frames['WorkArea'].setHideLogoutButton();
		}
	        top.frames['HelpIcon'].document.getElementById('HelpIcon').SetVariable("toolTip", toolTips);
	}
        if (top.frames['HelpIcon'].document.getElementById('HdnHideLogoutButton') != null) {
            var HideLogoutButton = top.frames['HelpIcon'].document.getElementById('HdnHideLogoutButton').value;
            top.frames['HelpIcon'].document.getElementById('HelpIcon').SetVariable("HideLogoutButton", HideLogoutButton);
        }
        switch (Tipo) {
            case 'N':
                top.frames['HelpIcon'].document.getElementById('HelpIcon').GotoFrame(1);
                break;

            case 'A':
                top.frames['HelpIcon'].document.getElementById('HelpIcon').GotoFrame(2);
                break;

            case 'V':
                top.frames['HelpIcon'].document.getElementById('HelpIcon').GotoFrame(3);
                break;

            case 'B':
                top.frames['HelpIcon'].document.getElementById('HelpIcon').GotoFrame(0);
                break;
        }
    } else {
        setTimeout("ShowIcon("+Tipo+", "+toolTips+")", 500);
    }
}

function ShowHelp (Tipo)
{
	if (top.frames['WorkArea'].CallCreaTreeHelp!=null)
	{
		top.frames['WorkArea'].CallCreaTreeHelp();
	}
	else
	{
		if (top.frames['WorkArea'].HelpWindowInfo!=null)
		{
			top.frames['WorkArea'].HelpWindowInfo();	
		}
	}		
}
function ToolTip(text,x,y)
{
	if (popUpToolTip == null)
	{
		var DIV= document.createElement("DIV");
		StyleDIV(DIV,"#000000 1px solid")
		DIV.style.background = "#FFFFE1";
		StylePopUp(DIV);
		var Height = CalcHeight(text);
		var Width = CalculateWidth(text);
		DIV.style.width = Width;
		DIV.style.height = Height;
		DIV.style.fontSize = "11px";
		DIV.style.lineHeight="12px";
		DIV.style.padding = "1px";
		DIV.innerText= text;
		popUpToolTip = window.createPopup();
		var oPopBody = popUpToolTip.document.body;
		oPopBody.innerHTML=DIV.outerHTML; 
		//popUp.show(x,y + top.frames['HelpIcon'].document.getElementById('HelpIcon').height,iWidth,Height ,top.frames['HelpIcon'].document.getElementById('HelpIcon'));
		popUpToolTip.show(x,y,Width,Height+1,top.frames['HelpIcon'].document.getElementById('popUpHelp'));
	}	
}
function ToolTipClose()
{
	if (popUpToolTip!=null)
	{
		popUpToolTip.hide();
		popUpToolTip=null;	
	}	
}
function CloseSession()
{
    top.activeuserid = undefined;
    top.clientcode = undefined;
	top.frames["WorkArea"].document.getElementById("_StrBtnSesion").click();
}
function CalculateWidth(text)
{
	var Widht;
	var DIV = document.createElement("DIV");
	StylePopUp(DIV);
	DIV.innerText = " " + text;
	DIV.noWrap=true;
	DIV.style.display = "inline";
	DIV.style.visibility = "hidden";
	DIV.style.fontSize= "10px";
	DIV.style.padding = "1px";
	document.body.appendChild(DIV);
	Widht=DIV.offsetWidth;
	document.body.removeChild(DIV);
	return Widht + 4;
}
function CreateHelpPopupWindow(HelpString1,HelpString2,HelpString3,Path)
{
	
	var Nombres = HelpString1.split("|");
	var Ficheros = HelpString2.split("|");
	var Nuevos = HelpString3.split("|");
	var PathCorrecto;
	var MiPath = Path.split("/");
	var i;
	var j;
	var HeightCalc;
	var Height=1;
	var iWidth=325;
	var y=0;
	var x=0;
	
	ShowIcon ("A",_toolTips);
	popUp = window.createPopup();
	var oPopBody = popUp.document.body;
	var Table = document.createElement("TABLE");
	
	PathCorrecto = MiPath[0] + "//" + MiPath[2] + "/" + MiPath[3] + "/"
		
	//PathCorrecto = Path.substring(0,Path.lastIndexOf("/")+1);
	Path = PathCorrecto;
	StylePopUp(Table);
	Table.CellSpacing = 0;
    Table.CellPadding = 0;
	Table.Width="100%"
	
	//Primero creo la etiqueta del recuerde que
	Table.appendChild(PopupTableRow("Recuerde que","Recuerde","","False","True",Path,0,true));
	HeightCalc = CalcHeight("Recuerde que");
	Height = Height + HeightCalc + 5;
	Table.appendChild(PopupTableRow(Nombres[0],Nombres[0],Ficheros[0],"False","True",Path,0,false));
	HeightCalc = CalcHeight(Nombres[0]);
	Height = Height + HeightCalc + 2;

	if ((Ficheros.length > 0)&&(Ficheros[1] != ""))
	{
		//Aņado la etiqueta de consultas asociadas
		Table.appendChild(PopupTableRow("Consultas asociadas","Consultas","","False","False",Path,0,true));	
		HeightCalc = CalcHeight("Consultas asociadas");
		Height = Height + HeightCalc + 5;
		for (i=1;i<=Ficheros.length -1 ;i++)
		{
			if (i<Ficheros.length -1)
			{
				Table.appendChild(PopupTableRow(Nombres[i],Nombres[i],Ficheros[i],Nuevos[i],"False",Path,i,false));
				HeightCalc = CalcHeight(Nombres[i]);
				Height = Height + HeightCalc + 5;
			}
			else
			{
				Table.appendChild(PopupTableRow(Nombres[i],Nombres[i],Ficheros[i],Nuevos[i],"True",Path,i,false));
				HeightCalc = CalcHeight(Nombres[i]);
				Height = Height + HeightCalc + 5;
			}	
		}
	}
	
	var DIV= document.createElement("DIV");
	StyleDIV(DIV,"#cdd2d8 2px solid")
	DIV.style.width=iWidth;
	DIV.style.height=Height;
	DIV.appendChild(Table)
	
	x=-iWidth + (top.frames['WorkArea'].screenLeft + top.frames['WorkArea'].document.body.offsetWidth - top.frames['HelpIcon'].screenLeft); // IE8 Fix
	
	oPopBody.innerHTML=DIV.outerHTML; 
	//popUp.show(x,y + top.frames['HelpIcon'].document.getElementById('HelpIcon').height,iWidth,Height ,top.frames['HelpIcon'].document.getElementById('HelpIcon'));
	popUp.show(x,y + top.frames['HelpIcon'].document.getElementById('HelpIcon').height,iWidth,Height ,top.frames['HelpIcon'].document.getElementById('popUpHelp'));
	
}

function CalcHeight(text)
{
	var MiHeight;
	var DIV = document.createElement("DIV");
	StylePopUp(DIV);
	DIV.style.width=188;
	DIV.style.fontSize="10px";
	DIV.style.padding = "1px";
	DIV.innerText = text;
	DIV.style.display = "inline";
	DIV.style.visibility = "hidden";
	document.body.appendChild(DIV);
	MiHeight=DIV.offsetHeight;
	document.body.removeChild(DIV);
	return MiHeight;
}

function StyleDIV(obj,style)
{
	obj.style.borderRight = style;
	obj.style.borderLeft = style;
	obj.style.borderTop = style;
	obj.style.borderBottom = style;
	obj.style.background = "#F8F9FA";
	obj.style.fontsize="8px";
}

function PopupTableRow(Text,value,inputText,Nuevo,Recuerde,Path,Posicion,Title)
{
	var Image = document.createElement("IMG");
	var ImageTDImg = document.createElement("IMG");
	var TR = document.createElement("TR");
	var TDImg = document.createElement("TD");
	var TD = document.createElement("TD");
	var TD0 = document.createElement("TD");
	var Div =document.createElement("DIV");
	var Bullet = document.createElement("IMG");
	var TextoParseado;
	var PathParseado;
	var TDHeight;
	Image.src= Path + "commonimages/Nuevo.gif";
	Bullet.src= Path + "commonimages/bullet_rojo.gif";
	ImageTDImg.src= Path + "commonimages/IconHelps.gif";
	TD.id = "TD" + value;
	TD.id = "TD0" + value;
	TD0.Width="12%";
	TD.style.cursor = "default";
	TD0.style.cursor = "default";					
	TRStyle(TR);
	
	if (inputText != "")				
	{
		TD.onmouseover="this.parentElement.style.background='#E0E3E6';";
		TD.onmouseout = "this.parentElement.style.background='#F8F9FA';";
		TD0.onmouseover="this.parentElement.style.background='#E0E3E6';";
		TD0.onmouseout = "this.parentElement.style.background='#F8F9FA';"; 
		TD.style.cursor = "hand";
		TD0.style.cursor = "hand";
		TD.style.color = "#000000";

		if (Recuerde == 'False')
		{
			TD.style.backgroundImage="url(" + Path + "commonimages/Dotted.gif)";
			TD.style.backgroundRepeat="repeat-x";
			TD.style.backgroundPosition="bottom";	
			TD0.style.backgroundImage="url(" + Path + "commonimages/Dotted.gif)";
			TD0.style.backgroundRepeat="repeat-x";
			TD0.style.backgroundPosition="bottom";	
		}
		
		TextoParseado=PonerBarras(inputText);
		PathParseado=PonerBarras(Path);
		TD.onClick = "parent.execScript('LoadHelpDocument(\"" + TextoParseado + "\",\"" + PathParseado + "\",\"" + Nuevo + "\",\"" + Posicion + "\");', 'javascript');";
		TD0.onClick = "parent.execScript('LoadHelpDocument(\"" + TextoParseado + "\",\"" + PathParseado + "\",\"" + Nuevo + "\",\"" + Posicion + "\");', 'javascript');";
		if (Nuevo!='False')
		{
			TD0.style.color = "#750909"; //TD0.style.color = "#760809"; Modificado MFP 14/04/2005
			TD0.style.fontWeight="bold";
			TD0.align = "center";
		}
		else
		{
			TD0.innerText=" ";		
		}
	}	
	else
	{
		TD0.style.fontWeight="bold";
		TDImg.style.background = "#cdd2d8";
		TD.style.background = "#cdd2d8";
		TD0.style.background = "#cdd2d8";
		TD.style.color = "#3c4550";
		TD.style.fontWeight="bold";
		TD.style.fontSize="11px";
	}
	
	TD.innerText = Text;
	if ((inputText != "")&&(Recuerde == "False"))
	{	
		TDHeight = CalcHeight(TD.innerText);
		TD.height = TDHeight + 5;
		TD0.height = TDHeight + 5;
	}
	
	if (Nuevo!='False')
	{
		TD0.appendChild(Image);
	}
	
	//Coloca las imagenes en los titulos
	if (Title == true)
	{
		TDImg.appendChild(ImageTDImg);
		
	}
	else {
	
	Bullet.style.marginLeft = "8px";
	//Bullet.style.marginTop = "5px";
	TDImg.appendChild(Bullet);
	//TDImg.style.verticalAlign = "top";
	}
	Div.noWrap = true;
	TD.appendChild(Div);
	
	TR.appendChild(TDImg);
	TR.appendChild(TD);
	TR.appendChild(TD0);
	return TR;
}
function PonerBarras(Texto)
{
	var contador;
	var RetornoIndex;
	
	RetornoIndex=Texto.indexOf(String.fromCharCode(92));
	
	while (RetornoIndex != -1)
	{
		Texto = Texto.replace(String.fromCharCode(92),"/");
		RetornoIndex=Texto.indexOf(String.fromCharCode(92));
	}
	return Texto;
}

function OpenHelpWindow(HelpString1,HelpString2,HelpString3,Path)
{
	var Nombres = HelpString1.split("|");
	var Ficheros = HelpString2.split("|");
	var Nuevos = HelpString3.split("|");
	
	LoadHelpDocument(Ficheros[0], Path,Nuevos[0],0)
}


function LoadHelpDocument(a, Path,Nuevo,Posicion)
{
	var LaURL;
	
	if (Nuevo=='True')
	{
		var StringNuevos = top.frames["WorkArea"].HelpFiles3.split("|");
		var String2;
		var i;
		StringNuevos[Posicion]="False";
		for (i=0;i<=StringNuevos.length-1 ;i++)
		{
			if (i==0)
			{
				String2 = StringNuevos[i];
			}
			else
			{
				String2 += "|" + StringNuevos[i];
			}	
		}
		top.frames["WorkArea"].HelpFiles3 = String2;
	}
		
	if (popUp != null)	
		popUp.hide();
	//window.open(a);
	LaURL = Path + "a3supportpages/A3HelpVisor.htm?url=" + a + "&nuevo=" + Nuevo;
	window.open(LaURL, "AyudasWeb","menubar=no, toolbar=no, resizable=yes, location=no, status=no");
}

function StylePopUp(obj)
{
	obj.style.fontSize="xx-small";
	obj.style.fontFamily="Arial,Verdana,'Microsoft Sans Serif'";
	obj.style.color="#3c4550";
}

function TRStyle(obj)
{
       obj.style.background="#F8F9FA";
       obj.style.backgroundImage="url(..\commonimages\Dotted.gif)";
       obj.style.backgroundRepeat="repeat-x";
       obj.style.backgroundPosition="top";
}

//Pasa el email por parametro de una pagina a otra	
function RecuperaURL()
{
	datos=document.location.search.substring(1,document.location.search.length);
	//page = datos.substring(datos.indexOf("=")+1,datos.lenght);
	//window.frames("WorkArea").location.href=page;
	
	window.frames["WorkArea"].location.href="HelpWorkArea.aspx?" + datos;
}

function LockBar()
{
   top.frames['HelpIcon'].document.getElementById('HelpIcon').SetVariable("locked", 1);	
}

function UnlockBar()
{
   top.frames['HelpIcon'].document.getElementById('HelpIcon').SetVariable("locked", 0);
}

	
