$(document).ready(function() {			
	 $("#formRegID").validationEngine({  
	 validationEventTriggers:"blur",
	 inlineValidation: true,
	 promptPosition: "topRight",
	 success : function() { callRegSuccessFunction() }
	 });  			
});
function callRegSuccessFunction(){

var regParams=$('input').serialize();	
$.ajax({
		type: "POST",
		url: dir+"register.php",
		data: regParams,
		success: function(msg){
			//$.cookie('customer_username', msg);
			addCookie('customer_username',msg);
			alert('register success');
			hide('registerpopcase');
			window.location.reload();
		}
	});

}

function checkLogin(){
	var username = $('#login_username').val();
	var password = $('#login_password').val();
	$.ajax({
		type: "GET",
		url: dir+"login.php",
		data: "username="+username+"&password="+password,
		success: function(msg){
		
			if(msg=='fail'){
				var msgInfos = {title:"Login",styleType:2};
				msgInfos.detail = "The email address or password is incorrect. Please check and try again.";
				alertMeg(msgInfos);
			}else{
				var data = msg.split('|');
				//$.cookie('customer_username', data[1]);
				addCookie('customer_username',data[1]);
				hide('logopopcase');
				window.location.reload();
			}
		}
	});
	
}

$(window).load(function(){

	//if($.cookie('customer_username')!=null){
	if(getCookie('customer_username')&&getCookie('customer_username')!='v'){
	$("#loginImg").css("display","none");
	//$("#logined_id").html($.cookie('customer_username')+' | <a href="" onClick="userLogout()">Logout</span>');
	$("#logined_id").html(getCookie('customer_username')+' | <a href="" onClick="userLogout()">Logout</span>');
	}
});

function userLogout(){

	//$.cookie('customer_username', null);
	deleteCookie('customer_username');
	deleteCookie('customer_email');
	deleteCookie('customer_id');
	window.location.reload();
}



$(window).load(function(){
	$("#searchsite").focus(function(){
		var val = $("#searchsite").val();
		if(val=="Search the site") $("#searchsite").val('');
	});
	$("#searchsite").blur(function(){
		var val = $("#searchsite").val();
		if(val=="") $("#searchsite").val('Search the site');
	});
	//
	$("#submit_searchsite").click(function(e) {
        searchsite_result();
    });
	})

function searchsite_result(){
	var searchsite = $("#searchsite").val();
	if(searchsite=="" || searchsite=="Search the site"){
		$("#searchsite").focus();return;
	}
	var title = encodeURI($("#searchsite").val()).replace(/&/g,'%26').replace(/\+/g,'%2B').replace(/\s/g,'%20').replace(/#/g,'%23');
	window.location.href=dir+"search-site.php?title="+title;
}	


