var dataurl='ybzx/data7';
var ajaxdata=null; 
initSelectStyle = function() { 
	$(".mod_select").each(function(index, item) { 
		$(this).hover(function() { 
			$(item).find("ul").show();
		},
		function() {  
			$(item).find("ul").hide();
		});
		$(item).find("li").hover(function() {
			$(this).attr("class", "even");
		},
		function() {
			$(this).attr("class", "");
		});
		$(item).find("li").bind("click",
		function() {
			$("#ctime").val($(this).attr("id"));
			$(".mod_select").eq(index).find("span").eq(0).html($(this).html());
			$(".mod_select").eq(index).find("ul").hide();
		})
	})
};	
getData = function(params) {
	var defaults = {
		page: 1,
		stockCode: "",
		title: "",
		ctime: 1,
		orgid: "",
		orders: "1",
		url: "",
		sid: "1",
		ps: 20
	}
	$("#load").show();
	var url = $("#httphost").val();
	var params = $.extend(defaults, params);
	if(params.stockCode=="\u4ee3\u7801/\u540d\u79f0/\u7b80\u62fc")params.stockCode="";
	$("#stockCode").val(params.stockCode);
	$("#title").val(params.title);
	$("#title1").val(encodeURIComponent(params.title));
	$("#ctime").val(params.ctime);
//	$("#orders").val(params.orders);
	$("#page").val(params.page);
	//params.sid=getCk("sids");
	if(params.sid==""){alert("\u8bf7\u9009\u62e9\u680f\u76ee");return;}
 	$.ajax({
		type: "get",
		url: httphost+"ybzx/data7/"+params.page+"/"+params.ctime+"/"+params.orders+"/"+params.stockCode+"?title="+($("#title").val()==undefined?'':$("#title1").val()),
		dataType: "jsonp",
		success: function(json) {
			if (json.list.length > 0) {
				if (json.page.totalpage > 1) {
					strFy="<input type=\"hidden\" id=\"tp\" value=\""+json.page.totalpage+"\"/><div class='la'>\u3010\u5f53\u524d\u7b2c" + json.page.page + "\u9875\u3011</div>";
					if(json.page.page>1){
					strFy+="<div class='a' onclick='return getData({page:"+json.page.uppage + ",stockCode:$(\"#stockCode\").val(),title:$(\"#title\").val(),sid:$(\"#sid\").val(),ctime:$(\"#ctime\").val(),orders:$(\"#orders\").val()})' ><font face=\"webdings\">3</font></div>";
					}else strFy+="";
					var endpage=11;
					if(json.page.endpage<=11)endpage=json.page.endpage;
					if(json.page.totalpage<10)endpage=json.page.totalpage+1;
					 for(var j=1;j<endpage;j++){
						if(j!=json.page.page&&j<=json.page.totalpage)
						strFy+="<div class='a' onclick='return getData({page:"+j+",stockCode:$(\"#stockCode\").val(),title:$(\"#title\").val(),sid:$(\"#sid\").val(),ctime:$(\"#ctime\").val(),orders:$(\"#orders\").val()})'>"+j+"</div>";
						else
						strFy+="<div class='cur'>"+j+"</div>"; 
						}
						if(json.page.page<json.page.totalpage&&json.page.page<10)
						strFy+="<div class='a' onclick='return getData({page:" + json.page.nextpage+ ",stockCode:$(\"#stockCode\").val(),title:$(\"#title\").val(),sid:$(\"#sid\").val(),ctime:$(\"#ctime\").val(),orders:$(\"#orders\").val()})'><font face=\"webdings\">4</font></div>"; 
					$("#fenye").html(strFy).show();
					$tt=(950-$("#fenye").width())/2; 
					$("#fenye").css("margin-left",$tt+"px");
				}
				 else {
					$("#fenye").hide();
				}
				var str = "";
				for (var i = 0; i < json.list.length; i++) {
					var cl="odd";
						if(i%2==0){ cl="odd";}else cl="even";
						str += "<tr class=\""+cl+"\" style=\"cursor:pointer;\" tid=\"" + json.list[i].id +"|"+json.list[i].sid+ "\" id=\"t" + json.list[i].glid + "\">";
					
					str += "<td class=\"type\">" + json.list[i].atype+ "</td>";
					str += "<td class=\"type\" code="+json.list[i].code+">" + json.list[i].code+ "</td>";
					str += "<td class=\"type\">" + json.list[i].codename+ "</td>";
				 	str += "<td class=\"title\">" +json.list[i].title + "</td>";
				 	str += "<td class=\"time\">" + json.list[i].createtime.substring(0, 10)+ "</td>";
					str += "</tr>";
					str += "<tr><td style=\"display:none;\" id=\"d" + json.list[i].glid + "\" colspan=\"3\"></td></tr>";
				}
				$("#commonTable").find("tbody").html(str).show();
				if(params.orders==0)$("#sortbytime").removeClass("sort_d").addClass("sort_a");
				else if(params.orders==1)$("#sortbytime").removeClass("sort_a").addClass("sort_d");

				$("#commonTable").find("tbody tr").each(function() { 
					$(this).mouseover(function(){
						$(this).toggleClass("over");
					}); 
					$(this).mouseout(function(){
						$(this).removeClass("over");
					});
				});
				$("#commonTable").find("tbody tr .title").bind("click",
				function() { 
					wkstock.openUrl(external.getModulePath()+'zgl/zixun/content.html?tid='+$(this).parent().attr("tid"));
				});
				$("#commonTable").find("[code]").bind("click",
						function() { 
					   if($(this).attr("code").length==6)
					    wkstock.jumppage(9354,$(this).attr("code")); 
						});
			} else
			 {
				$("#commonTable").find("tbody").html("<tr><td colspan=\"5\" >\u6ca1\u6709\u5173\u4e8e\u76f8\u5173\u4e2a\u80a1\u7684\u8d44\u8baf</td></tr>").show();
				$("#fenye").hide();
			}
			$("#load").hide();
		},
		error: function() {
			$("#load").hide();
		}
	});
	return false;
}; 
$(function(){  
	wkstock.opentype=1;
	//initSelectStyle();
	getData({orders:$("#orders").val()});
	$("#sortbytime").bind("click",
			function() {  
				var order = parseInt($("#orders").val());
				if (order == 1) {
					getData({
						page: $("#page").val(), 
						stockCode: $("#stockCode").val(),
						title: $("#title").val(),
						ctime: $("#ctime").val(),
						orders: 0
					});
					
					
				}
				 else {
					getData({
						page: $("#page").val(),
						stockCode: $("#stockCode").val(),
						title: $("#title").val(),
						ctime: $("#ctime").val(),
						orders: 1
					});  
				}
			});
			$("#searchYb").bind("click",
			function() {
				getData({
					page: 1,
					stockCode: $("#stockCode").val(),
					title: $("#title").val(),
					ctime: $("#ctime").val()
				});
			});
			$("#searchAll").bind("click",
				function() {
					getData({orders:$("#orders").val()});
				});
});