$(document).ready(function(){
    $('div#page-title, div#right-column, #nav>li>ul').children().andSelf().each(function(){$(this).html($(this).html().replace(/The Teleworker/g, '<em>The Teleworker</em>'))});

    $("input[name^='government']").blur(function(){
        checkInputs();
    });

    $("input[name^='government']").click(function(){
        checkInputs();
    });

    $("#government-form table tbody tr td").click(function() {
        var gradeStep = $('#grade_step').val();
        if($('#grade_step').val())
            $('#'+gradeStep).css('background', '');
        $(this).css( "background", "#9EC487" );
        $('#grade_step').val($(this).attr('id')) ;
    });

    if($('#grade_step').val()) {
        var gradeStep = $('#grade_step').val();
        $('#'+gradeStep).css('background', '#9EC487');
    }

});

/**
 * Printer friendly window popup
 */
function PrintThisPage() {
    var sOption = 'toolbar=no,location=no,directories=no,menubar=yes,scrollbars=yes,width=800,height=600';
    var phref = (location.href.lastIndexOf('/')===(location.href.length-1))?location.href+'?print':location.href+'/?print';
    var printwindow = window.open(phref, '', sOption);
    printwindow.focus();
}

/**
 * URL munging functions.
 */
var BaseURL = getBaseURL();
// Handle search box clicks
$(document).ready(function () {
    var input = $('#search')
    var strDefaultText = input.val();
    input.bind('focus', function () {
        if (this.value == strDefaultText) this.value = '';
    });
    input.bind('blur', function () {
        if (this.value == '') this.value = strDefaultText;
    });
});

function getBaseURL() {
    var url = location.href;  // entire url including querystring - also: window.location.href;
    var baseURL = url.substring(0, url.indexOf('/', 14));

    if (baseURL.indexOf('http://localhost') != -1) {
        // Base Url for localhost
        var url = location.href;  // window.location.href;
        var pathname = location.pathname;  // window.location.pathname;
        var index1 = url.indexOf(pathname);
        var index2 = url.indexOf("/", index1 + 1);
        var baseLocalUrl = url.substr(0, index2);

        return baseLocalUrl + "/";
    }
    else {
        // Root Url for domain name
        return baseURL + "/";
    }
}

function checkInputs() {
  if ($("input[name='government']:checked").val() == 1) {
    $("#government-form").show();
    $("#agency").show();
    $("#org").hide();
  } else if ($("input[name='government']:checked").val() == 0) {
    $("#government-form").hide();
    $("#agency").hide();
    $("#org").show();
  }
}

