﻿function autoHideMsg(controlId, msg, isError, displayTime) {
    var control = document.getElementById(controlId);
    if (control != null) {
        control.style.display = '';
        if (isError) {
            control.innerHTML = "<span class='errMsg'>" + msg + "</span>";
        } else {
            control.innerHTML = "<span class='okMsg'>" + msg + "</span>";
        }
        var time = displayTime;
        if (time == null) time = 2000;
        setTimeout("document.getElementById('" + controlId + "').style.display = 'none';", time);
    }
}    


var _obj_activevalidationsummary=null;
function saveLocalValidationSummary(validationsummaryid){
       // alert("save validation summary id = " + validationsummaryid);    
_obj_activevalidationsummary = document.getElementById(validationsummaryid);
}

function gotoActiveSummary(){
   // alert("goto active summary.");    
    if (_obj_activevalidationsummary != null)    {       
         var coors = findPos(_obj_activevalidationsummary);        
         window.scrollTo(coors[0],coors[1]-60);       
          _obj_activevalidationsummary = null;   
     }
}

function scrolltoValidationSummaryScript(){
    //    alert("ValidationSummary registration on server code behind.");
    if (typeof (ValidatorOnSubmit) == "function") {
        var isValidated = ValidatorOnSubmit();
        if (!isValidated) {
            gotoActiveSummary();
            return false;
        }
        return true;
    }
}

function findPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        do {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
    }
    return [curleft, curtop];
}

function OpenRadWindow(url, windowName) {
    var oWnd = window.radopen(url, windowName);
    oWnd.center();

}


var tipImageType = { "processing": 0, "updated": 1 };

function showTip(element, imageType, msg) {
    //debugger;
    if (element) {
        var lc = $("tipContainer");
        if (lc) {
            hideTip();
            if (imageType) {
                switch (imageType) {
                    case tipImageType.processing:
                        $("tipImg").src = "/images/icon_processing.gif";
                        break;
                    case tipImageType.updated:
                        $("tipImg").src = "/images/icon_updated.gif";
                        break;
                }
            } else { $("tipImg").src = "/images/icon_processing.gif"; }
            if (msg) { $("tipMsg").update(msg); } else { $("tipMsg").update('processing, please wait...'); }

            lc.style.top = getY(element) + 5 + "px";
            if ((getX(element) + element.offsetWidth + 5 + lc.getWidth()) >= document.documentElement.scrollWidth) {
                //show on left
                lc.style.left = getX(element) - lc.getWidth() + $(element).getWidth() + "px";
                lc.style.top = getY(element) + $(element).getHeight() + 5  + "px";
            }
            else {
                //show on right
                lc.style.left = getX(element) + element.offsetWidth + 5 + "px";
                lc.style.top = getY(element) + 5 + "px";
            }
            
            
            lc.show();
        }
    }
    
}

function hideTip() {
    var lc = $("tipContainer");
    if (lc) {
        lc.hide();
    }
}


function updateTip(imageType, msg) {
    var lc = $("tipContainer");
    {
        if (lc && lc.visible() ) {
            if (imageType) {
                switch (imageType) {
                    case tipImageType.processing:
                        $("tipImg").src = "/images/icon_processing.gif";
                        break;
                    case tipImageType.updated:
                        $("tipImg").src = "/images/icon_updated.gif";
                        break;
                }
            }
            if (msg) { $("tipMsg").update(msg); }
        }
    }
}

function fadeTip() {
    var lc = $("tipContainer");
    if (lc) {
        lc.fade();
    }
}

function getY(oElement) {
    var iReturnValue = 0;
    while (oElement != null) {
        iReturnValue += oElement.offsetTop;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}

function getX(oElement) {
    var iReturnValue = 0;
    while (oElement != null) {
        iReturnValue += oElement.offsetLeft;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}


function SetMouseOverImage(img, imgSrc, className) {
    var arVersion = navigator.appVersion.split("MSIE")
    var version = parseFloat(arVersion[1])

    if (((version = 5.5) && (document.body.filters)) || ((version = 6.0) && (document.body.filters))) {

        img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + imgSrc + "', sizingMethod='image')";
        img.src = "/images/xspacer.gif";

    }
    else {
        img.src = imgSrc;
    }

    if (className != '') {
        img.className = className;
    }
}
