﻿function DisableButtonAfterClickWithSubmit(button) {
    button.style.display = "none";
    setTimeout("ShowButtonAfterTimeOut(" + button + ")", 4000);
    document.forms[0].submit();
}

///Start NWDS_Textbox
function countDisplay(tbb, lbll) {

    var lbl = document.getElementById(lbll);

    var tb = document.getElementById(tbb);
    
     if (tb.value.length > tb.getAttribute("maxlength"))
     {
         tb.value = tb.value.substring(0, tb.getAttribute("maxlength"));
      }
        lbl.innerHTML = (tb.getAttribute("maxlength") - tb.value.length);
    
    if (lbl.innerHTML.toString() == "0") {
        lbl.style.color = "FF0000";
    }
    else {
        lbl.style.color = "000000";
    }


}

function textCounter(field, countfield, maxlimit) {
    var output = document.getElementById(countfield);
    if (output == null) { return; }

    if (field.value.length > maxlimit)
        field.value = field.value.substring(0, maxlimit);
    else
        output.value = maxlimit - field.value.length;
}
//END NWDS_Textbox functions

function DisableButtonAfterClick(button) {
    if (button) {
        button.style.visibility = "hidden";
    }
}
function HideButtonAfterClick(button) {
    if (button) {
        button.style.visibility = "hidden";
        setTimeout("ShowButtonAfterDisable('" + button.id + "');", 6000);
    }
}

function ShowButtonAfterDisable(buttonId) {
    if (buttonId) {
        var button = document.getElementById(buttonId);
        if (button) {
            button.style.visibility = "visible";
        }
    }
}

var MiscObject;


function DisableButtonAfterClickById(buttonID) {
    var button = document.getElementById(buttonID);
    button.style.display = "none";
    setTimeout("ShowButtonAfterTimeOut(" + button + ")", 4000);
    document.forms[0].submit();
}

function ShowButtonAfterTimeOut(button)
{
    button.style.display = "";
}



///START Print Functions By Chad
var HeaderPrintScript = "<style type='text/css' media='print'> #btnPrint{display: none; } #divPrintButton{display:none;} </style>";
var HeaderPrintSaveScript = "<style type='text/css' media='print'> #btnSave{display: none; } #btnPrint{display: none; } #divPrintButton{display:none;}</style>";

var PrintScript = "<div id='divPrintButton' style='padding: 0px 0px 0px 0px; margin: 0px 0px 0px 0px; background-color: #ccc; width: 100%; text-align: right;'><A id='btnPrint' style='padding-right: 20px;' HREF='javascript:window.print()' title='Click here to print this page.'>Print Page</A></div>"

var PrintSaveTxtScript =
"<div id='divPrintButton' style='padding: 0px 0px 0px 0px; margin: 0px 0px 0px 0px; background-color: #ccc; width: 100%; text-align: right;'>" +
    "<A id='btnPrint' style='padding-right: 20px;' HREF='javascript:window.print()' title='Click here to print this page.'>Print Page</A>" +
    "<A id='btnSave' style='padding-right: 20px;' HREF='javascript:window.save()' title='Click here to save this page.'>Save Page</A>" +
"</div>"


function PrintPopup() {

    var controlToPrint = document.getElementById("printMe").innerHTML;
    win2 = window.open("");  //open blank window and write to it
    win2.document.open();  //open document stream
    win2.document.write(HeaderPrintScript + PrintScript + controlToPrint);
    win2.document.close();
}

function PrintPopup(controlId) {

    var controlToPrint = document.getElementById(controlId).innerHTML;
    win2 = window.open("");  //open blank window and write to it
    win2.document.open();  //open document stream
    win2.document.write(HeaderPrintScript + PrintScript + controlToPrint);
    win2.document.close();
}

function PrintSavePopup(controlId) {

    var controlToPrint = document.getElementById(controlId).innerHTML;
    win2 = window.open("");  //open blank window and write to it
    win2.document.open();  //open document stream
    win2.document.write(HeaderPrintSaveScript + PrintSaveTxtScript + controlToPrint);
    win2.document.close();
}
///End Print Functions By Chad
function ToggleById(controlId) 
{
    var el = document.getElementById(controlId);
    if (el) {
        el.style.display = el.style.display = 'none' ? '' : 'none';
    }
}

function startElFlashById(elId) {
    var el = document.getElementById(elId);
    if (el) {
        setInterval("doBlink('" + elId + "')", 1000)
    }
}
function doElFlashById(elId) {
    var el = document.getElementById(elId);
    if (el) {
        obj.style.visibility = obj.style.visibility == "" ? "hidden" : "";
    }
}


function ForceMaxLength(textbox, maxLength) {
    if (textbox.value.length > maxLength) {
        textbox.value = textbox.value.substring(0, maxLength);
    }
}
function NumbersOnly(el)//Or just use (onkeyup="numbersOnly(this)") in element
{ el.value = el.value.replace(/[^0-9]/g, ""); }

function NumbersOnlyById(controlId)//Or just use (onkeyup="numbersOnly(this)") in element
{
    var el = document.getElementById(controlId)
    if(el)
        el.value = el.value.replace(/[^0-9]/g, "");
}

function numbersonly(myfield, e, dec) {
    var key;
    var keychar;

    if (window.event)
        key = window.event.keyCode;
    else if (e)
        key = e.which;
    else
        return true;
    keychar = String.fromCharCode(key);

    // control keys
    if ((key == null) || (key == 0) || (key == 8) ||
    (key == 9) || (key == 13) || (key == 27))
        return true;

    // numbers
    else if ((("0123456789").indexOf(keychar) > -1))
        return true;


    // decimal point jump
    else if (dec && (keychar == ".")) {
        myfield.form.elements[dec].focus();
        return true;
    }
    else
        return false;
}

///////////////////////////////
//MISC FUNCTIONS
///////////////////////////////



var clockId = 0;
function CheckClock() {
    updateClock(); 
    clockId = setInterval('updateClock()', 1000)
}
function updateClock() {
    var clock =  document.getElementById("clock");

    if (clock) {//check if clock exists on page
        clock.style.visibility = "visible";
        var currentTime = new Date();

        var currentHours = currentTime.getHours();
        var currentMinutes = currentTime.getMinutes();
        var currentSeconds = currentTime.getSeconds();

        // Pad the minutes and seconds with leading zeros, if required
        currentMinutes = (currentMinutes < 10 ? "0" : "") + currentMinutes;
        currentSeconds = (currentSeconds < 10 ? "0" : "") + currentSeconds;

        // Choose either "AM" or "PM" as appropriate
        var timeOfDay = (currentHours < 12) ? "AM" : "PM";

        // Convert the hours component to 12-hour format if needed
        currentHours = (currentHours > 12) ? currentHours - 12 : currentHours;

        // Convert an hours component of "0" to "12"
        currentHours = (currentHours == 0) ? 12 : currentHours;

        // Compose the string for display
        var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay;

        // Update the time display
        clock.firstChild.nodeValue = currentTimeString;
    }
    else {
        clearInterval(clockId);
    }
}
///////////////////////////////
//END MISC FUNCTIONS
////////////////////////////////

///////////////////////////////
//TELERIK JAVASCRIPT FUNCTIONS
////////////////////////////////
function GetRadWindow() {
var browserName=navigator.appName; 
    var oWindow = null;
    if(browserName=="Microsoft Internet Explorer")
    {
    if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
    }
    return oWindow;
}

function CloseRadWindow() {
    var oWindow = GetRadWindow();
    if (oWindow != null)
        oWindow.Close();
        //else
    //close();
    //location.reload();

    var frameEl = window.frameElement;
    // if we are inside a frame, then change it's URL to 'http://mozilla.org/'
    if (frameEl)
        frameEl.src = 'http://mozilla.org/';
}

function OnClientClose() {
        var oWindow = GetRadWindow();
        if (oWindow != null)
            oWindow.Close();
        //else
        //close();
        //location.reload();
        var frameEl = window.frameElement;
        // if we are inside a frame, then change it's URL to 'http://mozilla.org/'
        if (frameEl)
            frameEl.src = 'http://mozilla.org/';

}

function OnClientCloseReload(radWindow) {
    var oWindow = GetRadWindow();
    if (oWindow != null)
        oWindow.Close();
    else
        close();
    location.reload();
}

function openWin() {
    var oWnd = radopen("Dialog1.aspx", "RadWindow1");
}

function GoToSmsProHome() {
    var smsProHome = "http://" + window.location.host;
    if (window.location.pathname.substring(1, 4) == 'sms') {
        smsProHome = smsProHome + '/sms'
    }
    //override the redirect back to this page
    smsProHome = smsProHome + '/Default.aspx?i=0'
    window.location = smsProHome;
}
