﻿function showValidationSummary(validationToolTipID)
{
    var tooltip = $find(validationToolTipID); 

    if (g_validationSummaryToolTipPopupElementStatus == "hidden")
    {
        if (pscIsExpanded)
        {
            tooltip.set_position(Telerik.Web.UI.ToolTipPosition.TopCenter);
            tooltip.set_offsetX(-7);
            tooltip.set_offsetY(-95);
            tooltip.set_skin("advSrch");
        }
        else
        {
            tooltip.set_position(Telerik.Web.UI.ToolTipPosition.MiddleRight);
            tooltip.set_offsetX(-7);
            //tooltip.set_offsetY(-95);
            tooltip.set_skin("pscErr");
        }
        tooltip.show();
        
        if(!pscIsExpanded){
            var validationTooltip = tooltip._popupElement.parentNode;
            validationTooltip.style.marginTop = "-25px";
            if(!browser){
                getBrowserInfo();        
            } else {
                browser = window.browser;
            }
            if ((browser != "Internet Explorer") || (browser == "Internet Explorer" && version == "8")) {
                validationTooltip.style.marginLeft = "160px";
            }
        }
    }
    
    return false;
}

function validationSummaryToolTip_OnBeforeShow(sender, eventArgs)
{
    g_validationSummaryToolTipPopupElementObject = sender._popupElement;

    if (typeof(setPscTarget) == 'function')
    {
        if (g_pscContainerObject)
            growIframe(g_pscContainerObject, 450, 0);
    }
}

function validationSummaryToolTip_OnShow(sender, eventArgs)
{
    sender._popupElement.style.zIndex = "100002";
    createToolTipCallOut(sender._popupElement);
        
    if (browser == "Internet Explorer" && version == "6")
    {
        var targetControl = sender._targetControl.parentNode;
    
        targetControl.style.position = "absolute";
        targetControl.style.dipslay = "block";
        
        sender._popupElement.style.top = "0px";
        
        var ifrm = makeFrame(sender._popupElement.parentNode, "validationTooltipIframe");
        
        ifrm.style.position = "absolute";
        ifrm.style.zIndex = "7999";
        ifrm.style.width = sender._popupElement.offsetWidth - 5 + "px";
        ifrm.style.height = sender._popupElement.offsetHeight - 20 + "px";

        if (pscIsExpanded)
        {
            ifrm.style.top = targetControl.offsetTop + "px";
        }
        else
        {
            ifrm.style.top = "20px";
        }
        
        ifrm.style.left = sender._popupElement.offsetLeft + "px";
        ifrm.style.filter = 'Alpha(opacity=0)';
        
    }
    
    placePsc();
}

function validationSummaryToolTip_OnHide(sender, eventArgs)
{
    if (sender._popupElement)
    {
        removeFrame(sender._popupElement.parentNode, "validationTooltipIframe");
    }

    g_validationSummaryToolTipPopupElementObject = null;
    
    g_validationSummaryToolTipPopupElementStatus = "hidden";
    
    placePsc();
}

function createToolTipCallOut(tooltipPopupElement)  
{  
    var calloutDivWrapper = null;
    var calloutDup = null;
    calloutDivWrapper = document.getElementById("rtCalloutWrapper");

    //make sure it's the target div
    if (calloutDivWrapper && calloutDivWrapper.parentNode.id == tooltipPopupElement.id)
    {
        calloutDup = calloutDivWrapper.childNodes[0];
    }
    else
    {

        if (tooltipPopupElement)
        {
            // Determine the DIV element of the callout.  
            var calloutDiv = null;  
            var childDivs = tooltipPopupElement.getElementsByTagName("DIV");  

            for(var i=0, length=childDivs.length; i<length; i++)  
            {  
                var childDiv = childDivs[i];  
                if(childDiv.className.indexOf("rtCallout") > -1)  
                {  
                    calloutDiv = childDiv;  
                    break;  
                }  
            }  
        }

        if(calloutDiv)  
        {
            calloutDivWrapper = document.createElement("div");
            calloutDivWrapper.setAttribute("id", "rtCalloutWrapper");

            calloutDup = calloutDiv.cloneNode(true);
            calloutDup.style.visibility = "visible";
            var calloutParent = calloutDiv.parentNode;
            
            calloutDivWrapper.appendChild(calloutDup);
            
            calloutParent.insertBefore(calloutDivWrapper, calloutDiv);
            
            calloutDiv.style.display = "none";
            
            //calloutParent.removeChild(calloutDiv);
        }
    }

    if (calloutDup)
    {
        //get position of tooltip to determine which way to point the callout  
        var arrowDir =0;  
        var classArr = calloutDup.className.split(' ');  
        var classPos = classArr[classArr.length-1];
        
        if(classPos.toLowerCase().indexOf("rtcallouttopright") >= 0){  
            //control position is "BottomXXX" in ESPC.ascx, triangle points to the side (GuestNames.aspx)
            arrowDir = 3;  
        } else if(classPos.toLowerCase().indexOf("rtcallouttop") >= 0){  
            //control position is "BottomXXX" in ESPC.ascx, triangle points up  
            arrowDir = 1;  
        } else if(classPos.toLowerCase().indexOf("rtcalloutbottom") >= 0){  
            //control position is "TopXXX" in ESPC.ascx, triangle points down  
            arrowDir = 2;  
        } else {  
            //triangle points to the side, orientation controlled by css
            arrowDir = 3;  
        }  
        
        var callOutDivs = '';

        if(arrowDir == 1) 
        {
            for(i = 1; i <= 12; i++){
                callOutDivs = callOutDivs + "<div style=width:" + i + "px; class=callOutDiv></div>";
            }        
        } 
        else if(arrowDir == 2)
        {
            for(i = 12; i > 0; i--){
                callOutDivs = callOutDivs + "<div style=width:" + i + "px; class=callOutDiv></div>";
            }
        } 
        else 
        {
            for(i = 1; i <= 8; i++){
                callOutDivs = callOutDivs + "<div style=width:" + i + "px; class=callOutDiv></div>";
            }   
            for(i = 8; i > 0; i--){
                callOutDivs = callOutDivs + "<div style=width:" + i + "px; class=callOutDiv></div>";
            }        
        }

        calloutDup.innerHTML = callOutDivs;  
    }
}  

function showPrompt(ToolTipID)
{
    var tooltip = $find(ToolTipID); 
    tooltip.show();
    return false;
}

function prefilledToolTip_OnShow(sender, eventArgs){
    sender._popupElement.style.zIndex = "100002";
    createToolTipCallOut(sender._popupElement);

}

