﻿$(document).ready(function() {
	$("#sort_price dl").mouseover(function(){
		$(this).addClass("hove");
	}).bind("mouseleave",function(){
		$(this).removeClass("hove");
		$(this).children("dd").each(function(){
			$(this).hide();
		});
	});
	$("#sort_price dd").hover(function(){
		$(this).css({background:"#dddddd"});
	},function(){
		$(this).css({background:"#000000"});
	});
	$("#ddlSort").attr("value",sort);
	// 设置上一页、下一页信息
	var curpage = $("#curpage").length>0 ? parseInt($("#curpage").text()) : "1";
	var totalpage =  $("#totalpage").length>0 ? parseInt($("#totalpage").text()) : "1";
	if(curpage==1){
		if(curpage!=totalpage && totalpage!=0){
			$(".prepage").html(prePage);
			curpage = curpage+1;
			page = curpage;
			$(".nextpage").html("<a href='" + baseUrl+"TagProduct-"+tagID+"-"+cID+"-"+page+"-"+display+"-"+sort+"."+extend+"'>"+nextPage +"</a>");
		}else{
			$(".prepage").html(prePage);
			$(".nextpage").html(nextPage);
		}
	}
	else if(curpage!=1 && curpage!=totalpage){
		var curpage1=curpage-1
		var curpage2=curpage+1
		$(".prepage").html("<a href='" + baseUrl+"TagProduct-"+tagID+"-"+cID+"-"+curpage1+"-"+display+"-"+sort+"."+extend+"'>"+prePage +"</a>");
		$(".nextpage").html("<a href='" + baseUrl+"TagProduct-"+tagID+"-"+cID+"-"+curpage2+"-"+display+"-"+sort+"."+extend+"'>"+nextPage +"</a>");
	}else{
		$(".nextpage").html(nextPage);
		curpage = curpage-1;
		page = curpage;
		$(".prepage").html("<a href='"+baseUrl+"categorys-"+tagID+"-"+cID+"-"+page+"-"+display+"-"+sort+"."+extend+"'>"+prePage +"</a>");
	}

	//给ddlSort控件绑定onChange事件
	$("#ddlSort").bind("change",function(){
		sort = $("#ddlSort").val();
		window.location.href=baseUrl+"TagProduct-"+tagID+"-"+cID+"-"+page+"-"+display+"-"+sort+"."+extend;
	});
	//给页码文本框绑定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{
					window.location.href=baseUrl+"TagProduct-"+tagID+"-"+cID+"-"+pageNum+"-"+display+"-"+sort+"."+extend;
                }
            }
            else{  
                alert("输入错误！");
                $("#gopage").attr("value","");
                return false;
            }
        }else{
            alert("请输入要跳转到的页面");
           $("#gopage").attr("value","");
            return false;
        }
	});
	
});
