// JavaScript Document

//Do Inputs
$(document).ready(function() {
	$("#sidebar_search").keyup(function (e) {
    		if(e.keyCode == 13) {
      		  $("#sidebar_form_search").submit();
   			}
	});
	$("#sidebar_password").keyup(function (e) {
    		if(e.keyCode == 13) {
      		  $("#sidebar_form_signin").submit();
   			}
	});
	$("#sidebar_email").keyup(function (e) {
    		if(e.keyCode == 13) {
      		  $("#sidebar_form_signin").submit();
   			}
	});
	$("input").focus(function () {
		if($(this).attr("default") == $(this).val()) {
			$(this).val("");
		}
		$(this).next("span").fadeIn(1000);
	});
	$("input").blur(function () {
		if($(this).val() == "") {
			var reVal = $(this).attr("default");
			$(this).val(reVal);
		}
		$(this).next("span").fadeOut(500);
	});
	$("textarea").focus(function () {
		$(this).next("span").fadeIn(1000);
	});
	$("textarea").blur(function () {
		$(this).next("span").fadeOut(500);
	});
	
	$("#Keyword").keypress(function(e)
    {
            code= (e.keyCode ? e.keyCode : e.which);
            if (code == 13) checkSearchForm()
            
	});
});

//COUNTER
jQuery.fn.countdown=function(options){if(!options)options='()';if(jQuery(this).length==0)return false;var obj=this;if(options.seconds<0||options.seconds=='undefined')
{if(options.callback)eval(options.callback);return null;}
window.setTimeout(function(){jQuery(obj).html(String(options.seconds));--options.seconds;jQuery(obj).countdown(options);},1000);return this;}

//DO NOTIFICATION
var doNotify_run = 0;
function doNotify(text,type,redir,nocountdown) {
	if(doNotify_run == 0) {
	doNotify_run = 1;
	if(type==1) {
		class_type = "green";
	}
	if(type==2) {
		class_type = "red";
	}
	$("#note_box_foot").fadeTo("slow",0.8);
	if(nocountdown==1) {
		$("#note_box").html(text);
	} else {
		$("#note_box").html(text + "<br><span id='note_box_foot' class='text_mini_white'>Closing in <span id='note_box_timer'>3</span> seconds. <span id='note_box_redir'></span></span>");
		$("#note_box_timer").countdown({seconds: 3});
	}
	$("#note_box").removeClass();
	$("#note_box").addClass(class_type);
	
	//If Countdown is true
	if(redir == null || redir == "undefined" || redir == '') {
		if(nocountdown==1) {
			$("#note_box").slideDown(500);
		} else {
			$("#note_box").slideDown(500).delay(3000).slideUp(500,function() { doNotify_run = 0; });
		}
	} else {
		if(nocountdown==1) {
			$("#note_box").slideDown(500);
		} else {
			$("#note_box_redir").html("Redirecting...");
			$("#note_box").slideDown(500).delay(3000).slideUp(500,function () { $("#container").slideUp(500,function() { window.location.href=redir; doNotify_run = 0; })});
		}
	}
	}
}

//SHOW LOADER
function loaderShow(ele) {
	$("#" + ele).slideDown(1000);
}

//HIDE LOADER
function loaderHide(ele) {
	$("#" + ele).slideUp(1000);
}
