//*** Place any JavaScript to be loaded in the <head> area here. ***
$(document).ready(function() {

	//Append the InputFocus() and InputBlur() functions to any elements with the class "clearfocus"
	$(".clearpassword").focus(function() { PasswordFocus(this); });
	$(".clearpassword").blur(function() { PasswordBlur(this); });
	$(".clearfocus").focus(function() { InputFocus(this); });
	$(".clearfocus").blur(function() { InputBlur(this); });
	$(".resetfield").each(function() { $(this).val( this.defaultValue ); });

	//preload CSS images
	$.preloadCssImages();
	
	//content background
	$('.content').append('<div class="background"></div>');
	
	//button graphics
	$('a.button').append('<img src="images/button-right.png" class="button-right" alt="" />');
});


//*** Functions ***

function InputFocus(element) {
	if (element.value == element.defaultValue) {
		element.value = "";
		$(element).addClass('filled');
	}
}
function InputBlur(element) {
	if (element.value == "") {
		$(element).removeClass('filled');
		element.value = element.defaultValue;
	}
}
function PasswordFocus(element) {
	if (element.value == element.defaultValue) {
		if ( ! $.browser.msie) { element.type = "password"; }
		element.value = "";
		$(element).addClass('filled');
	}
}
function PasswordBlur(element) {
	if (element.value.length == 0) {
		$(element).removeClass('filled');
		if ( ! $.browser.msie) { element.type = "text"; }
		element.value = element.defaultValue;
	}
}

//Function to make an element, e.g. content area, fill the visible space so a footer appears at the bottom. Wrapper can be a container or body element.
function MakeElementFillVisibleSpace(element_to_adjust, wrapper_element) {
	if (wrapper_element == undefined) { wrapper_element = 'body'; }
	$(element_to_adjust).height('auto');
	if ( $(wrapper_element).height() < $(window).height() ) {
		height_difference = $(window).height() - $(wrapper_element).height();
		new_height = $(element_to_adjust).height() + height_difference;
		$(element_to_adjust).height(new_height);
	}
}

//Make single element the same height as another single element - good for having two columns the same height
function MatchHeight(elementToAdjust, elementToCompare, adjust_offset, compare_offset) {
	if (isNaN(adjust_offset)) {
		adjust_offset=$(elementToAdjust).outerHeight(true) - $(elementToAdjust).height();
	};
	if (isNaN(compare_offset)) {
		compare_offset=$(elementToCompare).outerHeight(true) - $(elementToCompare).height();
	};
	if ( $(elementToAdjust).height()+adjust_offset < $(elementToCompare).height()+compare_offset ) {
		$(elementToAdjust).height( $(elementToCompare).height()+compare_offset-adjust_offset );	//adjust the height of the adjust element to the compare element
	}
}

//get a querystring by name
function querySt(ji) {
	hu = window.location.search.substring(1);
	gy = hu.split("&");
	for (i=0;i<gy.length;i++) {
		ft = gy[i].split("=");
		if (ft[0] == ji) {
			return ft[1];
		}
	}
}
