$(document).ready(function() {	 
	function doSimpleSearch() {
		var strarrchkn = '';
		$("input[id='chknumeric']:checked").each( 
			function() {   
				strarrchkn += '&nhold[]=' + $(this).val();
			}										
		);
		var str_redirect = root_path + '/index.php?mod=product&act=search&network=' + $('#optcategory').val() + '&fprice=' + $('#fprice').val() + '&tprice=' + $('#tprice').val();
		str_redirect += (strarrchkn != '')? strarrchkn : '&nhold[]=';
		str_redirect += '&prefix=';
		str_redirect += $("input[name='prefix']:checked").val();
		if($('#txtkeyword').val().search(/^[0-9\*]+$/)==-1) {
			alert("Xin vui lòng nhập vào từ hoặc cụm từ cần tìm!\nTừ hoặc cụm từ phải là các chữ số từ 0-:-9");
			$('#txtkeyword').get(0).focus();
			return false;
		}
		if($('#txtkeyword').val()!='')
			str_redirect += '&keyword=' + $('#txtkeyword').val() + '#sim_so_dep';
		else 
			str_redirect += '#sim_so_dep';
			
		window.location.href =  str_redirect;
		return false;
	}	
	$("#btnSearch").click(function(){
		doSimpleSearch();
	});
	$('#txtkeyword').keypress(function(e) {  
		var ekcode = (e.keyCode ? e.keyCode : e.which);
		if(ekcode == 13) {	   
			doSimpleSearch();
		}  
	});
	$('a.tk').click(function() { 
		$.blockUI({ message: $('#optionsearch'), css: { width: '500px' } }); 
	}); 

	$('#yes').click(function() { 
		// update the block message 
		$.blockUI({ message: "<h1>Xin vui lòng chờ ...</h1>" }); 
		$.unblockUI(); 
		window.location.href = root_path + '/tim-kiem-sim-so-dep/' + $('#optcategory').val() + '/' + $('#optsimtype').val() + '/' + $('#optprice').val() + '/' + $('#txtkeyword').val() + '/#sim_so_dep';
		return false;
	}); 

	$('#no').click(function() { 
		$.unblockUI(); 
		return false; 
	}); 
	$("a.slink").click(function(){
		var valsearch = $(this).attr('title');
		$('#txtkeyword').val(valsearch);
	});
	$("#sguide").fancybox({
		width : 800,
		height : 600,
		titleShow : false,
		centerOnScroll : true,
		hideOnOverlayClick : false
	});
	function fcallback(id) {
		$("#" + id).
		css({
			background: "",
			width: "auto",
			height: "auto"
		});
	}
	function showYahooSupport() {
		$("#yahoo_result")
		.css({
				background: "url(" + url_images + "/_ajaxloading.gif) no-repeat center center",
				width: "206px",
				height: "150px"
			})
		.fadeIn()
		.load(root_path + '/ajaxtemp/_yahoo_support.html',null,fcallback('yahoo_result'));
	}
	showYahooSupport();
	function showStatistics() {
		$("#statistics_results")
		.css({
				background: "url(" + url_images + "/_ajaxloading.gif) no-repeat center center",
				width: "206px",
				height: "150px"
			})
		.fadeIn()
		.load(root_path + '/ajaxtemp/_statistics.html',null,fcallback('statistics_results'));
	}
	showStatistics();
});
