$(document).ready(function() {
    var url = window.document.URL.toLowerCase().substr(7, window.document.URL.length - 7); //get the url minus the 'http://' bit
    var site = url.split("/")[1]; //get the second element of the array when the url is split on '/'
    switch (site) {
        case "pages":
            $("#home span").removeClass("menubox1off").addClass("menubox1in");
            break;
        case "ourportfolio":
            $("#ourportfolio span").removeClass("menubox1off").addClass("menubox1in");
            break;
        case "funding":
            $("#funding span").removeClass("menubox1off").addClass("menubox1in");
            break;
        case "plans":
            $("#plans span").removeClass("menubox1off").addClass("menubox1in");
            break;
        case "newsevents":
            $("#newsevents span").removeClass("menubox1off").addClass("menubox1in");
            break;
        case "about":
            $("#about span").removeClass("menubox1off").addClass("menubox1in");
            break;
    }

    var size = new String();
    size = $.cookie('fontsize');
    if (size != null)
        ChangeTextSize(size);
});

function ChangeTextSize(size) {
    $("body").css("font-size", size);
    $.cookie('fontsize', size, { expires: 365, path: '/' });

}

/*Used by the ClassificationDropdown custom field to select all items*/
function CheckAllItems(ParentDivId, isonoroff) {

    if (isonoroff == true) {
        $("#divScrollList" + ParentDivId + " span.checkboxlistitem > :checkbox").attr('checked', false);
        $("#divScrollList" + ParentDivId + " span.checkboxlistunclassified > :checkbox").attr('checked', false);
    }
    else {
        $("#divScrollList" + ParentDivId + " span.checkboxlistitem > :checkbox").attr('checked', false);
        $("#divScrollList" + ParentDivId + " span.checkboxlistunclassified > :checkbox").attr('checked', true);
    }

}


/*Used by the ClassificationDropdown custom field to deselect all items */
function UnCheckAllItems(ParentDivId, isonoroff) {
    if (isonoroff == true) {
        $("#divScrollList" + ParentDivId + " span.checkboxlistitem > :checkbox").attr('checked', false);
        $("#divScrollList" + ParentDivId + " span.checkboxlistselectall > :checkbox").attr('checked', false);
    }
    else {
        $("#divScrollList" + ParentDivId + " span.checkboxlistitem > :checkbox").attr('checked', false);
    }
}
/*Used by the ClassificationDropdown custom field to select an items  */
function UnCheckAllAndUnselected(ParentDivId) {

    // $("span.checkboxlistselectall > :checkbox").attr('checked', false);      //this is ok for one Classification control but
    // $("span.checkboxlistunclassified > :checkbox").attr('checked', false);   // but we may need multiple seelction controls per page
    $("#divScrollList" + ParentDivId + " span.checkboxlistselectall > :checkbox").attr('checked', false);
    $("#divScrollList" + ParentDivId + " span.checkboxlistunclassified > :checkbox").attr('checked', false);

}



/*Used by the custom fields to validate entry and count characters entered */
function validateText(vName, vLength, vCounterName) {
    try {

        var vComments = document.getElementById(vName);
        var Comments = vComments.value;
        var vCounter = document.getElementById(vCounterName);
        var iCount = Comments.length;
        if (iCount > vLength) {
            document.getElementById(vCounterName).innerHTML = "*" + iCount + ' of ' + vLength + '. ';
            $("#" + vCounterName).removeClass("fieldcontrol RowHeader Error");
            $("#" + vCounterName).removeClass("fieldcontrol RowHeader");
            $("#" + vCounterName).addClass('fieldcontrol RowHeader Error');
            return false;
        }
        else {
            document.getElementById(vCounterName).innerHTML = iCount + ' of ' + vLength + '. ';
            $("#" + vCounterName).removeClass("fieldcontrol RowHeader");
            $("#" + vCounterName).removeClass("fieldcontrol RowHeader Error");
            $("#" + vCounterName).addClass('fieldcontrol RowHeader');
        }
    }
    catch (err) {
        txt = "There was an error setting the count.\n\n";
        txt += "Error description: " + err.description + "\n\n";
        txt += "Click OK to continue.\n\n";
        alert(err.description);
        window.status = err.description;
    }

}


function launchEditMode() {


    ////    var vBlueBoxId = -1;
    ////    var vSelected = $('#ctl00_PlaceHolderMain_WebPartManager_EPSRCBlueBoxWebPart1_BlueBoxSelectedItems :selected').map(function() { return $(this).val(); }).get();
    ////    if (vSelected.length > 0) {

    ////        vBlueBoxId = vSelected[0];
    ////    }
    ////    else {
    ////        var vAvailable = $('#ctl00_PlaceHolderMain_WebPartManager_EPSRCBlueBoxWebPart1_BlueBoxAvailableItems :selected').map(function() { return $(this).val(); }).get();
    ////        if (vAvailable.length > 0) {
    ////            vBlueBoxId = vAvailable[0];
    ////        }
    ////    }
    ////    if (vBlueBoxId != -1) {
    ////        var newWindow = window.open('/Lists/BlueBoxItems/EditForm.aspx?ID=' + vBlueBoxId + '&Source=/_layouts/EPSRC/ManageBlueBoxes.aspx', '_blank'); newWindow.focus(); return false;
    ////    }
}




