﻿
function ProperCase(ID) {
    try 
    {
        //alert('ProperCase: ID: ' + ID);
        var t = document.getElementById(ID);
        if (t != null) {
            //alert('ID: ' + ID + ': Not NULL');
            var PC;
            var s = t.value;
            
            // Get the Sentence Case
            PC = s.toLowerCase().replace(/(^\s*\w|[\.\!\?]\s*\w)/g, function(c) { return c.toUpperCase() });
            //PC = s.toLowerCase().replace(/^(.)|\s(.)/g,
            //  function($1) { return $1.toUpperCase(); });
                       
            // Set the Value
            t.value = PC;
 
            
            // Hidden Input
            var h = document.getElementById(ID + 'Value');
            if (h != null) 
            {
                h.value = t.value;
            }


            // Reset the SpellChecker
            try {
                if (UltimateSpellAsYouTypes[ID] != null) 
                {
                    UltimateSpellAsYouTypes[ID].Restart(false);
                }
            }
            catch (e) {
                //Silent
                //alert('ProperCase: Silent: err: ' + e.description);
            }

            // Call SetTextBoxValue to save the text to a Hidden input
            SetTextBoxValue(ID);
        }
    }
    catch (err) {
        alert('ProperCase: err: ' + err.description);
        throw err;
    }
    //return;
}


function BlurTextBox(ID, BackColor, ForeColor, FF) 
{

    try 
    {
    
        // Set the TextboxValue
        SetTextBoxValue(ID);

        if (FF == false) 
        {
            // Textbox
            var t = document.getElementById(ID);

            if (t != null) {
                t.style.backgroundColor = BackColor;
                t.style.color = +ForeColor;
            }
        }

        // SpellChecker iFrame
        var i = document.getElementById(ID + "usayti");

        if (i != null) {
            i.style.backgroundColor = BackColor;
            i.style.color = ForeColor;
            if (i.contentWindow.document.body != null) 
            {
                i.contentWindow.document.body.style.backgroundColor = BackColor;
                i.contentWindow.document.body.style.color = ForeColor;
            }
        }
    }
    catch (err) {
        alert('BlurTextBox: err: ' + err.description);
        throw err;
    }
    
}

function FocusTextBox(ID, BackColor, ForeColor, FF) 
{
    try
    {
        // Set the TextboxValue
        SetTextBoxValue(ID);
        
        //iFRAME
        //usayti

        if (FF == false) 
        {
            var t = document.getElementById(ID);

            if (t != null) {
                //t.style.backgroundColor = ForeColor;
                //t.style.color = +BackColor;

                t.style.backgroundColor = ForeColor;
                t.style.color = BackColor;
            }
        }
        
        // SpellChecker iFrame
        var i = document.getElementById(ID + "usayti");

        if (i != null) {
            i.style.backgroundColor = ForeColor;
            i.style.color = BackColor;

            if (i.contentWindow.document.body != null) 
            {
                i.contentWindow.document.body.style.backgroundColor = ForeColor;
                i.contentWindow.document.body.style.color = BackColor;
            }
        }
    }
    catch (err) {
        alert('FocusTextBox: err: ' + err.description);
        throw err;
    }    

}



function SetTextBoxValue(ID) 
{
    try
    {
        // var to store the Value from the textbox
        var Value;

        var t = document.getElementById(ID);
        //alert('SetTextBoxValue: ID: ' + ID);

        if (t != null) {
            //alert('SetTextBoxValue: != null');
            Value = t.value;
        }

        // Hidden Input
        var h = document.getElementById(ID + 'Value');
        if (h != null) 
        {
            h.value = Value;
            //alert('SetRatingControlValue: h.value: ' + h.value);
        }

        // Required Div
    //    var d = document.getElementById(ID + 'Required');
    //    if (d != null) 
    //    {
    //        if (Value != "") {
    //            // Hide the Div if the Value > 0
    //            d.style.display = "none";
    //        }
    //        else
    //        {
    //            // Show the Div if the Value.Len == 0
    //            d.style.display = "";
    //        }
    //    }
    //
    }
    catch (err) 
    {
        alert('SetTextBoxValue: err: ' + err.description);
        throw err;
    }
    return;
}


//function SetFocus(ID, HasMask) 
function SetFocus(ID) 
{
    try
    {
        var t = document.getElementById(ID);
        if (t != null) 
        {
            if (t.disabled == false) 
            {
                t.focus();
            }
        }
    }
    catch (err) 
    {
        alert('SetFocus: err: ' + err.description);
        throw err;
    }
    return;

}


if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();