$(document).ready(function(){

	//HOME
	if ( $("div#Wrapper div#swf_model").length > 0 ) {
		var meta = $("div#swf_model").metadata();
		if ( meta.flashvars.path_xml == undefined ) meta.flashvars.path_xml = "";

		$("div#Wrapper div#swf_model").flash({
				src: meta.swf, width: meta.width, height: meta.height,
				wmode: "transparent", menu: "false", 
				flashvars: { path_xml: meta.flashvars.path_xml, pathSWF:"flash/" }
			}, { version: 8 }
		);
	}


	if ( $("form#frmSearch").length > 0 ) {
		$("form#frmSearch").each(function() {

			// handle submissions without filling any field
			$(this).submit(function () {
				var validationError = false;

				$("form#frmSearch div span.error").each( function() { $(this).empty(); });


				// for each field validate value
				$("form#frmSearch input[type=text], form#frmSearch input[type=hidden], form#frmSearch input[type=password], form#frmSearch select, form#frmSearch textarea").each( function(){

					if ($(this).attr("class")) {
						if (!validateField(this)) {
							validationError = true;

							$(this).parent().parent().children("th").addClass("error");
						}
					}

				});

				// Key Search
				if ( $("form#frmSearch input#search").hasClass("focus") ) {
					$("form#frmSearch input#search").next("span").removeClass().addClass("error").html("Please enter a keyword");
					validationError = true;
				}

				return !validationError;

			});

		});

		// for each field validate value
		$("form#frmSearch input[type=text], form#frmSearch input[type=hidden], form#frmSearch input[type=password], form#frmSearch select, form#frmSearch textarea").each( function(){

			$(this).focus( function() {
				$(this).select();
				if ( !$(this).hasClass("focus") ) $(this).addClass("focus");
			});
			$(this).blur( function() {
				$(this).parent().parent().children("th").removeClass("error");
				//$("form#frmJoinUs label#err"+$(this).attr("id") ).empty();
				$(this).next("span").empty();

				if ( $(this).hasClass("focus") ) $(this).removeClass("focus");
			});
		});

	}


});


