// JavaScript Document
$(document).ready(function(){
	$("#searchclick").click( function () {
		content = $("#q").val();
		if ($.trim(content) == '') {
			alert("Bạn chưa điền nội dung tìm kiếm.");
		}
		else {
			content = encodeURIComponent(content);
			window.location=hostname + 'product/search/' + content + '.html';
		}
	});
	$("#q").keypress(function(e) {
		if(e.which == 13) {
			content = $("#q").val();
			if ($.trim(content) == '') {
				alert("Bạn chưa điền nội dung tìm kiếm.");
			}
			else {
				content = encodeURIComponent(content);
				window.location=hostname + 'product/search/' + content + '.html';
			}
		}					  
	});
	$("#gopage").keypress(function(e) {
		if( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57) && e.which!=13) {
			return false;
			//break;
		}					  
	});
	$("#butgoto").click( function () {
		if ($("#gopage").val() != '') {
			localhref = window.location.href;
			localhref = localhref.replace(/p[0-9]+.html/,'');
			lenlocal = localhref.length;
			if (localhref[lenlocal-1] != '/') {
				localhref = localhref + '/';	
			}
			if (placemain == 'true') {
				window.location=hostname + 'main/' + 'p' + $("#gopage").val() + '.html';
			}
			else {
				window.location=localhref + 'p' + $("#gopage").val() + '.html';
			}
		}
		else {
			alert("Bạn vui lòng điền số trang cần đến.");
		}
	});
});
