﻿function Utilities()
{
    this.InitializeHover = function()
    {
        $(function()
        {
            $("img[hover]").each(function(index, domElement) {
                domElement.onmouseover = function()
                {
                    domElement.oldSrc = domElement.src;
                    domElement.src = domElement.getAttribute("hover");
                }
                domElement.onmouseout = function()
                {
                    domElement.src = domElement.oldSrc;
                    domElement.oldSrc = null;
                }
            });
        });
    }
    
    this.GetBaseURL = function()
    {
        var baseTag = $(document).find("head base");
        if (baseTag.length == 1)
            return baseTag.attr("href");
        else
        {
            var path = window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/'));
            return window.location.protocol + "//" + window.location.host + path + "/";
        }
    }
    
    this.ToggleOn = function(id)
    {
        $("#" + id).css("display", "block");     
    }
    
    this.ToggleOff = function(id)
    {
    
        $("#" + id).css("display", "none");
    }
    
    this.Toggle = function(id)
    {
        if(alert($("#" + id).css("display")) == "none")
            $("#" + id).css("display", "block");
        else
            $("#" + id).css("display", "none");
    }
    
    this.ToggleValidatorOn = function(id)
    {
        var validator = document.getElementById(id);
        ValidatorEnable(validator, true);
        validator.style.display = "none";
        
    }
    
    this.ToggleValidatorOff = function(id)
    {
        var validator = document.getElementById(id);
        ValidatorEnable(validator, false);
    }
    
    this.Scroll = function(id) {
        var obj = document.getElementById(id);
        var curleft = curtop = 0;
        if (obj.offsetParent) {
            do {
                curleft += obj.offsetLeft;
                curtop += obj.offsetTop;
            } while (obj = obj.offsetParent);
        }
        window.scrollTo(curleft, curtop);
    }
}

var Utilities = new Utilities();