﻿
    /* CountDown */
    
    var cd_seconds;
    var cd_startAt;
    var cd_redirectUrl;
    var cd_container;
    
    function startCountdown(pDisplayContainer, pRedirectUrl, pStartCount)
    { 
    
        cd_container = document.getElementById(pDisplayContainer);
        cd_seconds = pStartCount;
        cd_startAt = pStartCount;
        cd_redirectUrl = pRedirectUrl;
        
        UpdateCounter();             
        
    }
    
    function UpdateCounter()
    {
    
    
        cd_seconds -= 1;
        
        
        if(cd_seconds <= 0)
        {
            window.location = cd_redirectUrl;
            return;
        }
        
        
        cd_container.innerHTML = '<b>' + cd_seconds + '</b>';
        setTimeout("UpdateCounter()", 1000);
        
    }

function EnterKeyAction(pTargetID)
{


    if(event.which || event.keyCode)
    {
        
        if ((event.which == 13) || (event.keyCode == 13))
        {
            var el = document.getElementById(pTargetID);
            el.click();
            return false;
        }
        } else {return true};

}


    function jumpTo(pElementId)
    {
        window.location = '#' + pElementId;
        return false;
    }

    function ShowAlert(pMessage)
    {    
        alert(pMessage);    
    }
    
    function ShowQuestion(pQuestion)
    {
        return confirm(pQuestion);
    }
    
    function toggleClassName(pElementID, pClassName1, pClassName2)
    {   
        var el = document.getElementById(pElementID)
        
        if(el != null)
        {
        
            if(el.className == pClassName1)
            {
                el.className = pClassName2;
                return false;
            }
            
            el.className = pClassName1;
        
        }
        
        return false;

    }

   
    /* buttonPress Handles the following events:
    
        onClick
        onMouseDown
        onMouseUp
        
    */

    function buttonPress(pValidationGroup, pButtonId, pFloat)
    {
    
        /* validate page */

        var isValid = isValidPage(pValidationGroup);
        
        if(isValid)
        {  
            toggleClassName(pButtonId, 'newButton inactive ' + pFloat, 'newButton inactive ' + pFloat);
            toggleClassName('Processing', 'processing', 'processing');
        }
        else
        {
            toggleClassName(pButtonId, 'newButton green ' + pFloat, 'newButton green ' + pFloat);
        }
        
    
    }


    function isValidPage(pValidationGroup) {

        var validationResult = true;
        
        if (typeof (Page_ClientValidate) == 'function') {
            validationResult = Page_ClientValidate(pValidationGroup);
        }

        return validationResult;
    
    }
    
    function validateAndHide(pValidationGroup, pElementToShow, pElementToHide)
    {
        
        if(isValidPage(pValidationGroup))
        {
        
            toggleClassName(pElementToShow, 'hidden', 'shown');
            toggleClassName(pElementToHide, 'hidden', 'shown');
            
            return true;
        
        }
        
        return false;
        
    }
    
    function validateAndToggle(pValidationGroup, pElementID, pClassName1, pClassName2)
    {
    
        if(isValidPage(pValidationGroup))
        {
        
            toggleClassName(pElementID, pClassName1, pClassName2);
            
            return true;
        
        }
        
        return false;
        
    }
    
    function DisableControl(controlId)
    {
      document.getElementById(controlId).disabled = true;
    }
     
    function DisableControl_SetTimeout(controlId,interval)
    {
      setTimeout("DisableControl('" +controlId + "')",interval);
    }

    function disableControl(pElementId, pProgressPanelId, pProgressShowClass)
    {
    
        
        Page_ClientValidate();
        
        if(Page_IsValid)
        {
            
            DisableControl_SetTimeout(pElementId,100);
            
            var el = document.getElementById(pProgressPanelId);
            
            
            if(el != null)
            {
                el.className = pProgressShowClass;
            }
    
        }
        
    }
    
    function toggleWatermark(pTargetID, pWatermarkClass)
    {

        var el = document.getElementById(pTargetID);
        
        if(el != null)
        {
        
            if(el.value == '')
            {
                toggleClassName(pTargetID, pWatermarkClass, '');
            }
            else
            {
                return;
            }
        
        }

    }

    function toggleImage(pElementID, pImageUrl1, pImageUrl2)
    {
    
        
        var el = document.getElementById(pElementID);
        
        if(el != null)
        {
        
            if(el.src == pImageUrl1)
            {
                el.src = pImageUrl2;
                return false;
            }
            
            el.src = pImageUrl1;
        
        }
    
    }

    


function Timer()
{
    this.obj = (arguments.length)?arguments[0]:window;
    return this;
}


Timer.prototype.setInterval = function(func, msec)
{
    var i = Timer.getNew();
    var t = Timer.buildCall(this.obj, i, arguments);
    Timer.set[i].timer = window.setInterval(t,msec);
    return i;
}

Timer.prototype.setTimeout = function(func, msec)
{
    var i = Timer.getNew();
    Timer.buildCall(this.obj, i, arguments);
    Timer.set[i].timer = window.setTimeout("Timer.callOnce("+i+");",msec);
    return i;
}

Timer.prototype.clearInterval = function(i)
{
    if(!Timer.set[i]) return;
    window.clearInterval(Timer.set[i].timer);
    Timer.set[i] = null;
}

Timer.prototype.clearTimeout = function(i)
{
    if(!Timer.set[i]) return;
    window.clearTimeout(Timer.set[i].timer);
    Timer.set[i] = null;
}

Timer.set = new Array();

Timer.buildCall = function(obj, i, args)
{
    var t = "";
    Timer.set[i] = new Array();
    if(obj != window)
    {
        Timer.set[i].obj = obj;
        t = "Timer.set["+i+"].obj.";
    }
    t += args[0]+"(";
    if(args.length > 2)
    {
        Timer.set[i][0] = args[2];
        t += "Timer.set["+i+"][0]";
        for(var j=1; (j+2)<args.length; j++)
        {
            Timer.set[i][j] = args[j+2];
            t += ", Timer.set["+i+"]["+j+"]";
        }
    
    }
    t += ");";    
    Timer.set[i].call = t;
    return t;
}

Timer.callOnce = function(i)
{
    if(!Timer.set[i]) return;
    eval(Timer.set[i].call);
    Timer.set[i] = null;
}

Timer.getNew = function()
{
    var i = 0;
    while(Timer.set[i]) i++;
    return i;
}


