$(document).ready(function() {

    SetMinDocHeight();

    $('.kpmgsearch').defaultvalue('Search KPMG.com');

    //remove rules borders on advanced data grid (career search)
    $('table.AdvGridTable table').attr('rules', '')

    //remove blue font on filter text (career search)
    $('span.ColumnTextLeftNOBold font').replaceWith($('span.ColumnTextLeftNOBold font').text())



    //fix padding on module table (above module content)
    $('#Table1').attr('cellspacing', '0').attr('cellpadding', '0');

    //fix registration form elements
    if (!jQuery.support.boxModel) {
        $('#_ctl0__ctl0__ctl0_lblErrorMessage').css('display', 'block').css('color', 'black').css('font-weight', 'bold').text('* Mandatory');
    } else {
        $('#_ctl0__ctl0__ctl0_lblErrorMessage font').attr('color', 'black').css('font-weight', 'bold').css('text-align', 'right').css('color', 'black').text('* Mandatory');
    }

    $('#_ctl0__ctl0__ctl0_pnlSurvey span.SubHead span.NormalRed').css('color', 'black');
    $('table.t3table h1').css('width', '100%');
    $('#_ctl0__ctl0__ctl0_tFormCreator').css('margin-top', '16px');

    $("#_ctl0__ctl0__ctl0_pnlSurvey input[type='text']").width(142);
});

function searchText(e, searchBoxClientID)
{
	var keynum = 0;
	if(window.event) //IE
	{
		keynum = window.event.keyCode;
	} else if(e.which) //Netscape/FF/Opera
	{
		keynum = e.which;
	}
	if (keynum == 13)
	{
		doSearch(searchBoxClientID);
		return false;
	}
}

function doSearch(searchBoxClientID)
{
	var searchUrl = "http://www.kpmg.com/Global/Pages/Results.aspx";
	var query = document.getElementById(searchBoxClientID).value;
	document.location.href = searchUrl + "?k=" + query;
}

/// set the space under the left nav menu to be white
function SetLeftNavSpace()
{
	var column1 = $('div#column1').height();
	var column2 = $('div#column2').height();
	var column3 = $('div#column3').height();
	var max = 0;
	var newHeight = 24;
	
	if(column1 > max)
	{ max = column1; }
	
	if(column2 > max)
	{ max = column2; }
	
	if(column3 > max)
	{ max = column3; }
	
	newHeight = max - $('table.menu-width').height() + $('td.leftNavFooterCell').height();

	$('td.leftNavFooterCell').height(newHeight);
}

function SetMinDocHeight() {
    var pageHeight, windowHeight, col1Height, col2Height, col3Height, longestColHeight, longestCol;
    pageHeight = parseInt($('#mainwrapper').height());
    windowHeight = parseInt($(window).height());
    col1Height = parseInt($('#column1').height());
    col2Height = parseInt($('#column2').height());
    col3Height = parseInt($('#column3').height());

    longestColHeight = col1Height;
    longestCol = '#column1';

    if (col2Height > longestColHeight) {
        longestColHeight = col2Height;
        longestCol = '#column2';
    }
    if (col3Height > longestColHeight) {
        longestColHeight = col3Height;
        longestCol = '#column3';
    }

    //alert('pageHeight: ' + pageHeight + ' windowHeight: ' + windowHeight + ' longestColHeight: ' + longestColHeight);

    if (pageHeight < windowHeight) {
        $(longestCol).height(longestColHeight + windowHeight - pageHeight);

        SetLeftNavSpace();
    }
}