var default_search_str = '';
$(document).ready(
	function () {
		if (!($.browser.msie && ($.browser.version == 7 || $.browser.version == 6))) {
			$('.corners').corner("round 5px");
		}

		default_search_str = $("#search_box").val();
		$("#search_box").bind('click', function (e) {
				if ($("#search_box").val() == default_search_str) {
					$("#search_box").val('');
				}
			}
		);
		$("#search_box").bind('blur', function (e) {
			if ($("#search_box").val() == '') {
				$("#search_box").val(default_search_str);
			}
		}
		);

		addHover($('div#languages li'), '#eee', '#fff');
		$('div#languages li.selected').unbind();

		addHover($('ul#left_menu li'), '#0b5cb8', '#186bc9');
		$('ul#left_menu li.selected').unbind();

		addHover($('ul#top_menu li'), '#666', '#333');
		$('ul#top_menu li.selected').unbind();

		addHover($('ul#city_menu li'), '#479203', '#53ad02');
		$('ul#city_menu li.selected').unbind();

		addHover($('ul#type_menu li'), '#666', '#333');
		$('ul#type_menu li.selected').unbind();

		$('form.validate').bind('submit',
			function (e) {
				message = $(this).attr('rel');
				labels = $(this).find('label.mandatory');
				len = labels.length;
				for(i = 0; i < len; i++) {
					id = $(labels[i]).attr('for');
					field = $(labels[i]).html();
					if ($('#' + id).val().length < 1) {
						alert(message + ' ' + field);
						return false;
					}
				}
			}
		);
		$('form.validateQuiz').bind('submit',
			function (e) {
				message = $(this).attr('rel');
				labels = $(this).find('label.mandatory');
				len = labels.length;
				for(i = 0; i < len; i++) {
					radioGroup = $(labels[i]).attr('for');
					field = $(labels[i]).html();
					if ($("input[name='" + radioGroup + "']:checked").length == 0) {
						alert(message + ' ' + field);
						return false;
					}
				}
			}
		);
		$('form.validateCV').bind('submit',
			function (e) {
				message = $(this).attr('rel');
				labels = $(this).find('label.mandatory');
				len = labels.length;
				for(i = 0; i < len; i++) {
					if ($(labels[i]).hasClass('checkbox')) {
						checkboxGroup = $(labels[i]).attr('for');
						field = $(labels[i]).html();
						if ($("input[rel='" + checkboxGroup + "']:checked").length == 0) {
							alert(message + ' ' + field);
							return false;
						}
					} else {
						id = $(labels[i]).attr('for');
						field = $(labels[i]).html();
						if ($('#' + id).val().length < 1) {
							alert(message + ' ' + field);
							return false;
						}
					}
				}
			}
		);

	}
);
function addHover(target, hoverColor, outColor){
	target.hover(
			function (e) {
				$(this).css('background-color', hoverColor);
			},
			function (e) {
				$(this).css('background-color', outColor);
			}
	);
}
