$(document).ready(function() {
	
	// 设置上一页、下一页信息
	var curpage = parseInt($("#curpage").text());
	var totalpage =  parseInt($("#totalpage").text());
	
	var number=$().getParmByUrl("Number") == undefined ? "" : "Number="+$().getParmByUrl("Number")+"&";
	if(curpage==1)
	{
		if(curpage!=totalpage && totalpage!=0)
		{
			$(".prepage").html(prePage);
			curpage = curpage+1;
			var page = "page="+curpage+"&";
			var urlPara = number;
			urlPara += page;
			if(urlPara.substring(urlPara.length-1,urlPara.length) == "&")
			{
				urlPara = urlPara.substring(0,urlPara.length-1);
			}
			$(".nextpage").html("<a href='" + baseUrl + urlPara + "'>"+nextPage +"</a>");

		}
		else
		{
			$(".prepage").html(prePage);
			$(".nextpage").html(nextPage);
		}
	}
	else if(curpage!=1 && curpage!=totalpage)
	{
		var curpage1=curpage-1
		var curpage2=curpage+1
		var page1 = "page="+curpage1+"&";
		var page2 = "page="+curpage2+"&";
		var urlPara1 = number;
		urlPara1 += page1;
		var urlPara2 = number;
		urlPara2 += page2;
		if(urlPara1.substring(urlPara1.length-1,urlPara1.length) == "&")
		{
			urlPara1 = urlPara1.substring(0,urlPara1.length-1);
			
		}
		if(urlPara2.substring(urlPara2.length-1,urlPara2.length) == "&")
		{
			urlPara2 = urlPara2.substring(0,urlPara2.length-1);
		}
		$(".prepage").html("<a href='" + baseUrl + urlPara1 + "'>"+prePage +"</a>");
		$(".nextpage").html("<a href='" + baseUrl + urlPara2 + "'>"+nextPage +"</a>");
	}
	else
	{
		$(".nextpage").html(nextPage);
		curpage = curpage-1;
		var page = "page="+curpage+"&";
		var urlPara = number;
		urlPara += page;
		if(urlPara.substring(urlPara.length-1,urlPara.length) == "&")
		{
			urlPara = urlPara.substring(0,urlPara.length-1);
		}
		$(".prepage").html("<a href='" + baseUrl + urlPara + "'>"+prePage +"</a>");
	}
	
	//设置每个到商品详细页面的链接wang
//	var s_cid = '0';
//	var s_ordersort = '1';
//	var currentUrl = window.location.toString().toLowerCase();
//	if(extend == '')
//	{
//	    s_cid = $().getParmByUrl("CatID") == undefined ? "0" : $().getParmByUrl("CatID");
//	    s_ordersort = $().getParmByUrl("OrderSort") == undefined ? "1" : $().getParmByUrl("OrderSort");
//	}
//	else
//	{
//	    var startID = currentUrl.lastIndexOf('_') + 1;
//	    var endID = currentUrl.lastIndexOf('.');
//	    s_cid = currentUrl.substring(startID,endID);
//	}
//	
//	var productType = '';
//	if(currentUrl.indexOf('commendproducts') != -1)
//	{
//	    productType = '&productType=Commend';
//	}
//	if(currentUrl.indexOf('hotproducts') != -1)
//	{
//	    productType = '&productType=Hot';
//	}
//	if(currentUrl.indexOf('newproducts') != -1)
//	{
//	    productType = '&productType=New';
//	}
//	if(currentUrl.indexOf('specialproducts') != -1)
//	{
//	    productType = '&productType=Special';
//	}

//    $('a[@href*=?PID=]').each(function(){
//        $(this).attr('href',$(this).attr('href') + '&cid=' + s_cid + '&OrderSort=' + s_ordersort + productType);
//    });
//    $('a[@href*=products/Product_]').each(function(){
//        $(this).attr('href',$(this).attr('href') + '?cid=' + s_cid + '&OrderSort=' + s_ordersort + productType);
//    });

	//给页码文本框绑定onkeyup事件
	$("#gopage").bind("keyup",function(){
		$("#gopage").attr({
			"value" : $("#gopage").val().replace(/\D/g,"")
		});
	});
	//给跳转按钮绑定onclick事件
	$("#go").bind("click",function(){
		var pageNum = $("#gopage").val();
		if(pageNum.replace(new RegExp("(^[\\s]*)|([\\s]*$)", "g"), "") != "" )
        {
            if(pageNum != "0")
            {
                if(pageNum > totalpage)
                {
                    alert("输入的数字大于总页数");
                    $("#gopage").attr("value","");
                    return false;
                }
                else
                {
					var urlPara="";
					var number=$().getParmByUrl("Number");
					urlPara += number == undefined ? "" : "Number="+number+"&";
					urlPara += "page="+pageNum +"&";
					if(urlPara.substring(urlPara.length-1,urlPara.length) == "&")
					{
						urlPara = urlPara.substring(0,urlPara.length-1);
					}
					window.location.href=baseUrl+urlPara;
                }
            }
            else
            {  
                alert("输入错误！");
                $("#gopage").attr("value","");
                return false;
            }
        }
        else
        {
            alert("请输入要跳转到的页面");
           $("#gopage").attr("value","");
            return false;
        }
	});
});