/**
 * SEARCH BOX
 */
jQuery(document).ready(function($) {
	$("#searchinput").blur(function(){
		$('#searchtips').fadeOut();
	});
});

function procSearchKeyUp(str) {
	if (str.length == 0) {
		$('#searchtips').fadeOut();
	} else {
		$.post("/ajax/searchsuggest", {search: ""+str+""}, function(data) {
			
			if ($('#searchinput').val() == str) { 
			$('#searchtips').fadeIn(50);
			$('#searchtips').html(data);
			} else if ($('#searchinput').val() == "") {
				$('#searchtips').fadeOut();
			}
		});
	}
    
}

/**
 * PROMPTS!
 */
$(function() {
	$('#ens_dialog').dialog({
		autoOpen: false,
		width: 600,
		modal:true,
		bgiframe:true,
		buttons: {
			"Ok": function() { 
				$(this).dialog("close"); 
			}
		}
	});
});
$(function() {
	$('#gen_dialog').dialog({
		autoOpen: false,
		width: 600,
		modal:true,
		bgiframe:true,
		buttons: {
			"Ok": function() { 
				$(this).dialog("close"); 
			}
		}
	});

	//hint for the search textbox
	$('#searchinput').hint();
});


function newsletterSub() {
	$.post("/ajax/newslettersub", {email: $("#footerensub").val()},
	function(data) {
		var msg = "";
		if (data == 1) {
			
			msg = "Your email address was submitted successfully. Thank you!";
			$("#footerensub").val("");
		} else if (data == 2) {
			msg = "Please provide a valid email address.";
		} else {
			msg = "An Error has occurred. Please try again, we are sorry for the inconvenience.";
		}
		$('#ens_dialog').html(msg);
		$("#ens_dialog").dialog('open');
	});
}
