﻿// JScript File
var ConfigServicos = {
AbreinfInativo : function (e, idProdserv, idCliente, tipoProdserv)
{
	var x, y;

    if (!e) var e = window.event;
    if (e.pageX || e.pageY)
    {
	    x = e.pageX;
	    y = e.pageY;
    }
    else if (e.clientX || e.clientY)
    {
	    x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
	    y = e.clientY + document.body.scrollTop  + document.documentElement.scrollTop;
    }
    
    x -= 290; //put the div inside the pointer
    y -= 5; //put the div inside the pointer
    
    var div = ConfigServicos.CreateDivElement();
    div.style.visibility = "visible";
    div.style.left = (x + "px");
    div.style.top  = (y + "px");
    div.innerHTML = "Carregando, aguarde..."; //we can change this to put one image saying "loading" instead
	PageMethods.CarregarInfInativo(idProdserv, idCliente, tipoProdserv, ConfigServicos.Success, ConfigServicos.Fail);		
}
,
Success : function (r)
    {
        ConfigServicos.WriteData(r);     
    },

    Fail : function (p0)
    {
        //TODO: Add some error handling here.
        alert("Ocorreu um erro.\n" + p0);
    },
	
	// public static void HideExtendedInformation( )
    HideExtendedInformation : function (event)
    {
        if (!event) event = window.event;
    
        try
        {
            if (event.explicitOriginalTarget) // Gecko
            {
                if (event.explicitOriginalTarget.tagName == "DIV")
                {
                    setTimeout('ConfigServicos.ReallyHideExtendedInformation()',500);
                }
            }
            if (event.srcElement && event.toElement) // IE4+
            {        
                if (
                    !(
                           (event.srcElement.tagName == "DIV" && event.toElement.tagName == "UL") 
                        || (event.srcElement.tagName == "DIV" && event.toElement.tagName == "LI")
                        || (event.srcElement.tagName == "DIV" && event.toElement.tagName == "A")
                        || (event.srcElement.tagName == "DIV" && event.toElement.tagName == "TABLE")
                        || (event.srcElement.tagName == "DIV" && event.toElement.tagName == "TD")
                        || (event.srcElement.tagName == "TABLE" && event.toElement.tagName == "TD")
                        || (event.srcElement.tagName == "TABLE" && event.toElement.tagName == "DIV")
                        || (event.srcElement.tagName == "TD" && event.toElement.tagName == "TABLE")
                        || (event.srcElement.tagName == "TD" && event.toElement.tagName == "TD")
                        || (event.srcElement.tagName == "TD" && event.toElement.tagName == "DIV")
                        || (event.srcElement.tagName == "UL" && event.toElement.tagName == "DIV")
                        || (event.srcElement.tagName == "UL" && event.toElement.tagName == "LI")
                        || (event.srcElement.tagName == "UL" && event.toElement.tagName == "A")
                        || (event.srcElement.tagName == "LI" && event.toElement.tagName == "DIV")
                        || (event.srcElement.tagName == "LI" && event.toElement.tagName == "UL")
                        || (event.srcElement.tagName == "LI" && event.toElement.tagName == "LI")
                        || (event.srcElement.tagName == "LI" && event.toElement.tagName == "A")
                        || (event.srcElement.tagName == "A" && event.toElement.tagName == "DIV") 
                        || (event.srcElement.tagName == "A" && event.toElement.tagName == "UL") 
                        || (event.srcElement.tagName == "A" && event.toElement.tagName == "LI") 
                        || (event.srcElement.tagName == "A" && event.toElement.tagName == "A")
                    )
                )
                {
                    setTimeout('ConfigServicos.ReallyHideExtendedInformation()',500);
                    if (event.cancelBubble) event.cancelBubble = true;
                    //alert(event.srcElement.tagName + " -> " + event.toElement.tagName);
                }
                else
					{
						//alert("nao - " + event.srcElement.tagName + " -> " + event.toElement.tagName);
					}
            }
        }
        catch(ex)
        {
            setTimeout('ConfigServicos.ReallyHideExtendedInformation()',500);            
        }
    },
    
    // public static void ReallyHideExtendedInformation( div )
    ReallyHideExtendedInformation : function (div)
    {
        var div = $get("inativo");
        if (div) div.style.visibility = "hidden";
    },

    // public static void WriteData( String data )
    WriteData : function (data)
    {
        var div = $get("inativo");
        div.innerHTML = data;
    },
    
    CreateDivElement : function()
    {
        if (document.getElementById('inativo')) return document.getElementById('inativo');
    
        var div = document.createElement('div');
        
        div.onmouseout = ConfigServicos.HideExtendedInformation;
        
        div.id = 'inativo';
        div.className = 'showOptions';
        div.style.position = 'absolute';
        
        document.body.appendChild(div);
        
        return div;
    }


}
