jQuery(document).ready(function($) {

	var contentH = $("#mainContent").height();
	var setMinH = contentH + 400;
	var winH = $(window).height();

	if (winH >= setMinH) {
		$("#specialGfx, .ImageFix").css({ 'height': winH });
	} else {
		$("#specialGfx, .ImageFix").css({ 'height': setMinH });
	}

	$(window).resize(function() {
		var resH = $(window).height();
		if (resH >= setMinH) {
			$("#specialGfx, .ImageFix").css({ 'height': resH });
		} else {
			$("#specialGfx, .ImageFix").css({ 'height': setMinH });
		}
	});

	/*
	$("#nav ul").hide();
	$("#nav li:has(ul)").each(function() {
	$(this).children("ul").slideUp(400);
	});
	*/

	$("#nav li.p1:has(ul)").click(function(event) {
		if (this == event.target) {
			var current = this;
			$("#nav li:has(ul)").each(function() {
				if (this != current) $(this).children("ul").slideUp(400);
			});
			$("ul:first", $(this)).slideToggle(400);
		}
	});

	$("#nav li.p2:has(ul)").click(function(event) {
		if (this == event.target) {
			var current = this;
			$("li.p2:has(ul)").each(function() {
				if (this != current) $(this).children("ul").slideUp(400);
			});
			$("li.p3:has(ul)").each(function() {
				if (this != current) $(this).children("ul").slideUp(400);
			});
			$("ul:first", $(this)).slideToggle(400);
		}
	});

	$("#nav li.p3:has(ul)").click(function(event) {
		if (this == event.target) {
			var current = this;
			$("li.p3:has(ul)").each(function() {
				if (this != current) $(this).children("ul").slideUp(400);
			});
			$("li.p4:has(ul)").each(function() {
				if (this != current) $(this).children("ul").slideUp(400);
			});
			$("ul:first", $(this)).slideToggle(400);
		}
	});

	$("#nav li.p4:has(ul)").click(function(event) {
		if (this == event.target) {
			var current = this;
			$("li.p4:has(ul)").each(function() {
				if (this != current) $(this).children("ul").slideUp(400);
			});
			$("ul:first", $(this)).slideToggle(400);
		}
	});

	//$("#nav li.open").click();
});

function IsEmpty(o, show_error) {
	if (o.val().length == 0) {
		if (show_error) o.addClass('ui-state-error');
		return true;
	}
	return false;
}

function IsEMail(o) {
	return checkRegexp(o, /^(\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+[;,]{0,1}\s?)+$/);
}

function IsPhone(o) {
	return checkRegexp(o, /^\d{6,}$/);
}

function checkRegexp(o, regexp) {

	if (!(regexp.test(o.val()))) {
		o.addClass('ui-state-error');
		/*updateTips(n);*/
		return false;
	} else {
		return true;
	}
}