Date.prototype.format = function(format) {
       var date = {
              "M+": this.getMonth() + 1,
              "d+": this.getDate(),
              "h+": this.getHours(),
              "m+": this.getMinutes(),
              "s+": this.getSeconds(),
              "q+": Math.floor((this.getMonth() + 3) / 3),
              "S+": this.getMilliseconds()
       };
       if (/(y+)/i.test(format)) {
              format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
       }
       for (var k in date) {
              if (new RegExp("(" + k + ")").test(format)) {
                     format = format.replace(RegExp.$1, RegExp.$1.length == 1
                            ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
              }
       }
       return format;
}
var dataurl='http://soft.zzjjc.com.cn/newoem/appimp.php/Appimp/getggnews/callback/a/type/1/';
var ajaxdata=null; 
getData = function(params) {
	var defaults = {
		page: 1,
		stockCode: "",
		title: "",
		ctime: 1,
		orgid: "",
		orders: "1",
		url: "",
		sid: "1",
		ps: 20
	}
	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);
	if(params.sid==""){alert("\u8bf7\u9009\u62e9\u680f\u76ee");return;}
 	$.ajax({
		type: "get",
		url: dataurl+"p/"+params.page+"/n/18/",
		dataType: "jsonp",
		success: function(json) {
			if (json.data.length > 0) {
				if (json.pcount > 1) {
					var strFy=[];
			 		strFy[0] = "<input type=\"hidden\" id=\"tp\" value=\""+json.pcount+"\"/><label style='color:#fff'>\u3010\u5f53\u524d\u7b2c" + json.nowp + "\u9875\u3011</label>";
					strFy[1]="<span onclick='return getData({page:1,stockCode:$(\"#stockCode\").val(),title:$(\"#title\").val(),sid:$(\"#sid\").val(),ctime:$(\"#ctime\").val(),orders:$(\"#orders\").val()})'>\u9996\u9875</span></span><span><span onclick='return getData({page:"+(parseInt(json.nowp)-1) + ",stockCode:$(\"#stockCode\").val(),title:$(\"#title\").val(),sid:$(\"#sid\").val(),ctime:$(\"#ctime\").val(),orders:$(\"#orders\").val()})'>\u4e0a\u4e00\u9875</span></span><span><span onclick='return getData({page:"+(parseInt(json.nowp)+1) + ",stockCode:$(\"#stockCode\").val(),title:$(\"#title\").val(),sid:$(\"#sid\").val(),ctime:$(\"#ctime\").val(),orders:$(\"#orders\").val()})'>\u4e0b\u4e00\u9875</span></span><span><span onclick='return getData({page:"+(json.pcount) + ",stockCode:$(\"#stockCode\").val(),title:$(\"#title\").val(),sid:$(\"#sid\").val(),ctime:$(\"#ctime\").val(),orders:$(\"#orders\").val()})'>\u672b\u9875</span></span>";
				$("#fenye").html(strFy.join("")).show();
				strFy=null;
				$("#fenye").find("span").bind("mouseover",function(){
					$(this).css("textDecoration","underline");
				});
				$("#fenye").find("span").bind("mouseout",function(){
					$(this).css("textDecoration","none");
				});
				}
				 else {
					$("#fenye").hide();
				}
				var str = "";
				for (var i = 0; i < json.data.length; i++) {
					var cl="odd";
						if(i%2==0){ cl="odd";}else cl="even";
						str += "<tr class=\""+cl+"\" style=\"cursor:pointer;\" tid=\"" + json.data[i].id + "\">";
						var d=json.data[i].addtime*1000;
		var newDate = new Date();
		newDate.setTime(d); 
					str += "<td class=\"time\">" +newDate.format('yyyy-MM-dd hh:mm:ss')+ "</td>";
				 	str += "<td class=\"title\">"+json.data[i].title + "</td>";
					str += "</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").bind("click",
				function() { 
					wkstock.openUrl(external.getModulePath()+'zgl/zixun/contentx1.html?tid='+$(this).attr("tid"));
				});
			} else
			 {
				$("#commonTable").find("tbody").html("<tr><td colspan=\"2\" >\u6ca1\u6709\u5173\u4e8e\u76f8\u5173\u4e2a\u80a1\u7684\u8d44\u8baf</td></tr>").show();
				$("#fenye").hide();
			}
		},
		error: function() {
		}
	});
	return false;
}; 
$(function(){  
	wkstock.opentype=1;
	getData();
});