﻿var Timer;
var TotalSeconds;
var URL;

function CreateTimer(TimerID, Time, RedirectPage) {
    URL = RedirectPage;
    Timer = document.getElementById(TimerID);
    TotalSeconds = Time;
    
    UpdateTimer()
    window.setTimeout("Tick()", 1000);
}

function Tick() {
  if (TotalSeconds <= 0) {
        window.location = URL;
        return;
    }

    TotalSeconds -= 1;
    UpdateTimer()
    window.setTimeout("Tick()", 1000);
}

function UpdateTimer() {
    Timer.innerHTML = TotalSeconds;
}


    function ToggleMenu(itemName) {
            document.cookie = "menuitem" + "=" + itemName + ";"
            if (document.getElementById(itemName)) {
                var elm = document.getElementById(itemName);
                var i, others = document.getElementById('SectionMenu');
                for (i = 0; i < others.childNodes.length; i++) {
                    var other = others.childNodes[i];
                    if ((other.className == 'MenuGroup') && (other != elm)) other.style.display = 'none';
                }
                if (elm.style.display == 'block') elm.style.display = 'none';
                else elm.style.display = 'block';
                return false;
            }
            else {
                RemoveCookie();
            }

        }
        function OpenMenuItem(subCat, section) {
            var i, menuelms = document.getElementById('SectionMenu');
            for (i = 0; i < menuelms.childNodes.length; i++) {
                var menuelm = menuelms.childNodes[i];
                if ((menuelm.className == 'MenuGroup') && (menuelm.id == 'SubCat' + subCat.toString())) {
                    menuelm.style.display = 'block';
                    for (j = 0; j < menuelm.childNodes.length; j++) {
                        var subelm = menuelm.childNodes[j];
                        if ((subelm.className == 'MI') && (subelm.id == 'Section' + section.toString())) {
                            subelm.style.className = 'MIS';
                            break;
                        }
                    }
                    break;
                }
            }
            return false;
        }
        function getName() {
            if (document.cookie) {
                index = document.cookie.indexOf("menuitem");
                if (index != -1) {
                    namestart = (document.cookie.indexOf("=", index) + 1);
                    nameend = document.cookie.indexOf(";", index);
                    if (nameend == -1) { nameend = document.cookie.length; }
                    YouWrote = document.cookie.substring(namestart, nameend);
                    return YouWrote;
                }
            }
        }
        function addLoadEvent(func) {
            var oldonload = window.onload;
            if (typeof window.onload != 'function') {
                window.onload = func;
            } else {
                window.onload = function() {
                    if (oldonload) {
                        oldonload();
                    }
                    func();
                }
            }
        }
        function RemoveCookie() {
            document.cookie = "menuitem" + "=1; expires=Monday, 04-Apr-2000 05:00:00 GMT";
        }
        addLoadEvent(function() {
            if (getName()) {
                ToggleMenu(getName());
            }
            else {
            }
        });

        // open the client email with the specified address
        function sendEmail2(encodedEmail) {
            // do the mailto: link
            location.href = "mailto:" + decodeEmail(encodedEmail);
        }

        // display the email address in the statusbar
        function displayStatus(encodedEmail) {
            window.status = "mailto:" + decodeEmail(encodedEmail);
        }

        // clear the statusbar message
        function clearStatus() {
            window.status = "";
        }

        // return the decoded email address
        function decodeEmail(encodedEmail) {
            // The encodedEmail is a string that contains the email address.
            // Each character in the email address has been converted into 
            // a two digit number (hex / base16). This function converts the
            // series of numbers back into the real email address.

            // holds the decoded email address
            var email = "";

            // go through and decode the email address
            for (i = 0; i < encodedEmail.length; ) {
                // holds each letter (2 digits)
                var letter = "";
                letter = encodedEmail.charAt(i) + encodedEmail.charAt(i + 1)

                // build the real email address
                email += String.fromCharCode(parseInt(letter, 16));
                i += 2;
            }

            return email;
        }

        function resize_ddl(ddlname) {
        //This is to resize ddl to view long strings in IE
        var ddl_width = ddlname.style.width;
                  
        if (!ddlname.options.value) {
            //do nothing
            } else {//ddlname.style.width='auto'};     
        }
        }
        
    function DisableValidators(flag)
    {
       for (i = 0; i < Page_Validators.length; i++)
       {
       Page_Validators[i].enabled = flag;             
       }
    }

    function EnableVal()
    {
         DisableValidators(true);
         Page_ClientValidate();  
    if(!Page_IsValid)
    {
        DisableValidators(false);
    }
    return Page_IsValid;
    }
                   
   var milisec=0 
 var seconds=30 
function display(){ 

 document.getElementById('redirectcountdown').value='30' 
  if (milisec<=0){ 
    milisec=9 
    seconds-=1 
 } 
 if (seconds<=-1){ 
    milisec=0 
    seconds+=1 
 } 
 else 
    milisec-=1 
    document.getElementById('redirectcountdown').value=seconds+"."+milisec 
    setTimeout("display()",100) 
} 
    
  
  
    

