﻿///Counts the Character and Restrict to the maximum charcter that can be entered into a textbox.
///sourceTextBox (Source Text Box)
///displayControl (Control where you want to diplay remaing characters count)
///maxLength (Maximum number of Character that can be entered into the Source Text Box.)
function CountCharactersGeneral(sourceTextBox, displayControl, maxLength)
{
    if(sourceTextBox != null && displayControl != null)    
    {		
        sourceTextBox = document.getElementById(sourceTextBox);             
        displayControl = document.getElementById(displayControl);                
        if(sourceTextBox != null)                
        {                    
            var len = sourceTextBox.value.length                   
            if (len<=maxLength) //if entered charcters less than the Maximum Limit.                    
            {                        
                //Shows Number of characters Remaining                         
                displayControl.innerHTML = maxLength -len + " Character(s) remaining.";                    
            }                    
            else                    
            {                        
                sourceTextBox.value = sourceTextBox.value.substring(0, maxLength);                        
                return false;                    
            }               
        }    
    }
}

//Disable the control that submits the form
function submitFormOnce(sender) {
    if (sender.disabled == false) {
        sender.disabled = true;
        return true;            //added to replace document.aspnetForm.submit(); for cross browser support
    } else {
        return false;
    }
}

function checkForEnter(str) {
    if (window.event.keyCode == 13) {
        return false;
        top.window.location = 'search.aspx?search=' + str;
    }
}

//Confirms that the button action is t/f
function confirmClick(sMsg) {
    if (confirm(sMsg)) {
        //alert('Action confirmed!');
        document.aspnetForm.action = '';
        document.aspnetForm.submit();
    } else {
        //alert('** Block Action **');
        return false;
    }
}


function CheckOnOff(rdoId,gridName)
{
    var rdo = document.getElementById(rdoId);
    /* Getting an array of all the “INPUT” controls on the form.*/
    var all = document.getElementsByTagName('input');
    for(i=0;i<all.length;i++)
    {  
        /*Checking if it is a radio button, and also checking if the
        id of that radio button is different than “rdoId” */
        if(all[i].type=='radio' && all[i].id != rdo.id)
        {
            var count=all[i].id.indexOf(gridName);
            if(count!=-1)
            {
               all[i].checked=false;
            }
        }
     }
     rdo.checked=true;/* Finally making the clicked radio button CHECKED */
}

function Redirect(sURL){
    location.href=sURL;
}


/*
************************************************
***** SiFR UPDATES WHEN AJAX ON PAGES **********
************************************************
*/

// must be called when the body loads from each page that wishes to refresh the SiFR
function load() {
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
}

// handles every end ajax request on pages where the handler has been registered
function EndRequestHandler(sender, args) {
    if (args.get_error() == undefined)
        InitSIFR();
    else
        alert("There was an error" + args.get_error().message);
}



$(document).ready(function() {

    $(".sel-menu-item").hover(
    function() {
        $(this).addClass($(this).attr("data-class"));
    },
    function() {
        $(this).removeClass($(this).attr("data-class"));
    });

    $(".sel-menu-item").mousedown(
    function() {
        $(this).addClass($(this).attr("data-classout"));
    });

    $(".sel-menu-item").mouseup(
    function() {
    $(this).removeClass($(this).attr("data-classout"));
    });



    // fetch all the buttons and use the same ref
    var wb = $(".white-bar-new-light-green");

    if ($.browser.msie && $.browser.version.substr(0, 1) < 7) {

        $(".white-bar-new-light-green").each(function() {
            $(".content", this).width($(this).width() - 5);
        });
    }

    $(wb).click(function() {
        try {
            $.sound.play("gfx/sounds/button.mp3", { timeout: 2000 });

        }
        catch (ex) {
            alert(ex);
        }
    });

    function toggleHover(item) {
        $(".content", item).toggleClass("content-h");
        $(".left", item).toggleClass("left-h");
    }

    function toggleDown(item) {
        $(".content", item).toggleClass("content-d");
        $(".left", item).toggleClass("left-d");
    }

    // mouse hover
    $(wb).hover(function() { toggleHover($(this)); }, function() { toggleHover($(this)); });
    $(wb).mousedown(function() { toggleDown($(this)); });
    $(wb).mouseup(function() { toggleDown($(this)); });

    // only embed the sound if required
    if ($(".white-bar-new-light-green").length) {
        // load the sound

    }

});


/* CHARACTER COUNT */
function limitChars(textarea, limit, infodiv) {

    var text = textarea.value;
    var textlength = text.length;
    var info = document.getElementById(infodiv);

    if (textlength > limit) {
    info.innerHTML = 'You cannot write more then ' + limit + ' characters!';
    textarea.value = text.substr(0, limit);
    return false;
    }
    else {
    info.innerHTML = 'You have ' + (limit - textlength) + ' characters left.';
    return true;
    }
   
}