//-------------------------------------------
// Browser Sniffing...
var IE = (navigator.appName.indexOf("Internet Explorer") > 0) ? true : false;
var NS = (document.getElementById && !document.all) ? true : false;
var OP = (navigator.userAgent.toLowerCase().indexOf("opera")) ? true : false;


//*********************************************
// JQuery - Update Image in <a> Tag...
function doJQueryUpdateImage(elementId, imageUrl)
{
    // Toggle Div...
    $("#" + elementId).children().attr("src", imageUrl);
}

//*********************************************
// JQuery - Toggle <DIV> Element
function doJQuerySlideToggle(elementId, hrefId)
{
    // Toggle Div...
    $("#" + elementId).slideToggle(250);
    
    // Toggle Image...
    var urlCollapse = "http://cdn.freedomspeaks.com/Web/Images/Icon-Collapse.gif";
    var urlExpand = "http://cdn.freedomspeaks.com/Web/Images/Icon-Expand.gif";
    var urlImage = $("#" + hrefId).children().attr("src");
    urlImage == urlCollapse ? doJQueryUpdateImage(hrefId, urlExpand) : doJQueryUpdateImage(hrefId, urlCollapse);
}

//*********************************************
// JQuery - Toggle <DIV> Element
function doJQueryTabOfficials(currentId)
{
    // Hide Tabs...
    $("#pnlFederal").hide();
    $("#pnlState").hide();
    $("#pnlCounty").hide();
    $("#pnlCity").hide();
    
    // Show Tab...
    $("#pnl" + currentId).show();
}
function doJQueryTabSearchType(currentId)
{
    // Hide Tabs...
    $("#pnlOfficials").hide();
    $("#pnlLetters").hide();
    $("#pnlMembers").hide();
    
    // Show Tab...
    $("#pnl" + currentId).show();
}

//*********************************************
// JQuery - Hides Button OnClick Event...
function doHideButtonOnSubmit()
{
    $('.Button').hide();
    $('.ButtonHdn').show(); 
    return true;
}

//*********************************************
// Cookies - Sets Cookie
function setCookie(name, value, expiredays)
{
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie= name + "=" + escape(value) + ((expiredays==null) ? "" : ";expires=" + exdate.toGMTString());
}

//*********************************************
// DOM - Selects All/None of CheckBoxList
function doCheckBoxListSelect(cbl, state)
{    
    var cblTarget = document.getElementById(cbl);
    var cblInput = cblTarget.getElementsByTagName("input");
    for(var i=0; i<cblInput.length; i++) 
    {
        cblInput[i].checked = state;
    }
    return false; 
}  

//*********************************************
// Validation - Comment
var previousCommentLength = "{CurrentLength}";
function doValidateTextBoxComment(src, args)
{
    var isValid = true;
    if (args.Value.length > 1001)
    {
        src.innerHTML = src.innerHTML.replace("{CurrentLength}", args.Value.length);
        src.innerHTML = src.innerHTML.replace(previousCommentLength, args.Value.length);
        previousCommentLength = args.Value.length;
        isValid = false;
    }
    
    args.IsValid = isValid;
}

//*********************************************
// Validation - Comment
var previousCommentLength_250 = "{CurrentLength}";
function doValidateTextBoxCommentFriend(src, args)
{
    var isValid = true;
    if (args.Value.length > 250)
    {
        src.innerHTML = src.innerHTML.replace("{CurrentLength}", args.Value.length);
        src.innerHTML = src.innerHTML.replace(previousCommentLength_250, args.Value.length);
        previousCommentLength = args.Value.length;
        isValid = false;
    }
    
    args.IsValid = isValid;
}

//*********************************************
// Validation - Comment
var previousCommentLength_1000 = "{CurrentLength}";
function doValidateTextBoxCommentLetter(src, args)
{
    var isValid = true;
    if (args.Value.length > 1000)
    {
        src.innerHTML = src.innerHTML.replace("{CurrentLength}", args.Value.length);
        src.innerHTML = src.innerHTML.replace(previousCommentLength_1000, args.Value.length);
        previousCommentLength = args.Value.length;
        isValid = false;
    }
    
    args.IsValid = isValid;
}

//*********************************************
// Validation - CheckBox
function doValidateCheckBox(src, args)
{
    var checkbox = document.getElementById(src.controltovalidate);
    if(checkbox !== null)
    {
        args.IsValid = checkbox.checked;
    }
}

//*********************************************
// Validation - CheckBox in Repeater
function doValidateCheckBoxInRepeater(src, args) 
{
    var ctlIsValid = false;
    var repeater = document.getElementById(src.controltovalidate);
    var items = repeater.getElementsByTagName("input");    
    if ( items !== null ) 
    {
        for ( i = 0; i < items.length; i++ ) 
        {
            if ( items.item(i).checked ) 
            {
                ctlIsValid = true;            
            }
        }
        args.IsValid = ctlIsValid;
    }
}

//*********************************************
// Validation - CheckBoxList
function doValidateCheckBoxList(src, args) 
{
    var ctlIsValid = false;
    var cbl = document.getElementById(src.controltovalidate);
    var items = cbl.getElementsByTagName("input");    
    if ( items !== null ) 
    {
        for ( i = 0; i < items.length; i++ ) 
        {
            if ( items.item(i).checked ) 
            {
                ctlIsValid = true;            
            }
        }
        args.IsValid = ctlIsValid;
    }
}

//*********************************************
// Validation - CheckBoxList in DataList
function doValidateCheckBoxListInDataList(src, args) 
{
    var ctlIsValid = false;
    var datalist = document.getElementById(src.controltovalidate);
    var items = datalist.getElementsByTagName("input");    
    if ( items !== null ) 
    {
        for ( i = 0; i < items.length; i++ ) 
        {
            if ( items.item(i).checked ) 
            {
                ctlIsValid = true;            
            }
        }
        args.IsValid = ctlIsValid;
    }
}