﻿var pagereloaddata = "";
var pagereloadtitle = "";

$(function(){
	// $("#btnsearch").click(function(){
		// SearchInProducts()
	// })
	// $("#q").keypress(function(e){
		// if(e.which == 13)
			// SearchInProducts()
	// })
})

function SearchInProducts(){
	q = $.trim($("#q").val())
	if (q.length > 2 && q != "جستجو"){
		if (pagereloaddata == ""){
			pagereloaddata = $(".page-content").html()
			pagereloadtitle = document.title
		}
	}
	else{
		$("#q").focus()
		return false
	}

	$.ajax({
		type: 'POST',
		data: "q=" + escape(q),
		url: "searchproducts.asp",
		error: function(XHRObject, options, errorThrown) {
			alert(XHRObject.responseText)
		},
		beforeSend: function() {
			if (!$.browser.msie)
				$("#btnsearch, #q").attr("disabled", "disabled")
			$(".pageheader-content h1").html("لطفا منتظر باشید ...")
		},
		success: function(resultback) {
			$(".page-content tr").not(":first-child").remove()
			$(".page-content").children("tbody").append(resultback)
		},
		complete: function() {
			if (!$.browser.msie)
				$("#btnsearch, #q").removeAttr("disabled")
			$(".pageheader-content h1").html("نتیجه جستجو برای " + q)
			document.title = "نتیجه جستجو برای " + q
		}
	});
	
	return false;
}

function reloadpageback(){
	$(".page-content").html(pagereloaddata)
	document.title = pagereloadtitle
}
