$(function(){var a=$(".gap").width()-2;$(".gap").css("width",a);$("table tr:even").addClass("change_color");$("#stockcode").focusout(function(){if($("#stockcode").val()=="\u8f93\u5165\u540d\u79f0/\u4ee3\u7801/\u7b80\u62fc"){$("#stockcode").css("color","#9b9b9b")}else{$("#stockcode").css("color","#000")}})});function MM_openBrWindow(c,a,b){if(typeof external.iWinMain=="undefined"){window.open(".."+c,a,b)}else{external.iWinMain("cmd_PopupWindow","http://app.upchina.com/sasweb/xysidkdydnhensydn_cdhds.dyshg/dsfyewlrndsfpoidsfewlkdsnf.cxgdsf_hdsfnew/web/"+c,"710","620")}}var Common={CheckDate:function(a){var b=/^(\d{1,4})(-)([0-1]{1})(\d{1})(-)([0-3]{1})(\d{1})/;if(!b.test(a)){alert("\u60a8\u8f93\u5165\u7684\u65e5\u671f\u683c\u5f0f\u4e0d\u6b63\u786e!");return false}else{return true}},CheckStockcode:function(b){var a=/^[0-9]{6}$/;if(!a.test(b)){alert("\u60a8\u8f93\u5165\u7684\u8bc1\u5238\u4ee3\u7801\u683c\u5f0f\u4e0d\u6b63\u786e!");return false}else{return true}}};

 
    $(document).ready(function () {
    	 //查询条件回填
        var stockcodeFromPHP = "";
        if (stockcodeFromPHP != "") {
            $("#stockcode").val(stockcodeFromPHP);
        }
        //单击选中文字
        $("#stockcode").click(function () {
            $(this).select();
        });
        $("#yg").click(function () {
			$("#atype").val('0');
			$(".switch").find("li").removeClass('selected');
			$(this).addClass('selected');
        	getd(1);
        });
        $("#yz").click(function () {
        	$("#atype").val('1');
        	$(".switch").find("li").removeClass('selected');
			$(this).addClass('selected');
        	getd(1);
        });
        $("#yj").click(function () {
        	$("#atype").val('2');
        	$(".switch").find("li").removeClass('selected');
			$(this).addClass('selected');
        	getd(1);
        });
        $("#query").click(function () {
            var stockcode = $.trim($("#stockcode").val(), "");
            if (stockcode == "输入名称/代码/简拼") {
                stockcode = "";
            }
            if (stockcode != "") {
                if (Common.CheckStockcode(stockcode) == false) return false;
            }
           // window.location.href = "list.php?stockcode=" + stockcode + "&buy=" + buy + "&sell=" + sell + "&date=" + date;
            getd(1);
        });
        function setpage(){ 
            var b = $("#pageno").val();
            var a = $("#pagecount").val();
            if (pagecount.value == b) {
                $("#page3").css("background", "#808080");
                $("#page4").css("background", "#808080");
            }else{
            	 $("#page3").css("background", "url(./images/pagebg.jpg) 0 0 repeat-x");
                 $("#page4").css("background", "url(./images/pagebg.jpg) 0 0 repeat-x");
                }
            if ("1" == b || pagecount.value == 0) {
                $("#page1").css("background", "#808080");
                $("#page2").css("background", "#808080");
            }else{
            	 $("#page1").css("background", "url(./images/pagebg.jpg) 0 0 repeat-x");
                 $("#page2").css("background", "url(./images/pagebg.jpg) 0 0 repeat-x");
                }
        }
         var ajaxd=null;
       function getd($p){ 
    	   $("#load").show();
           if(ajaxd!=null)ajaxd.abort();
			$c='';
			  $a=$("#atype").val(); 
           if($("#stockcode").val()!='输入名称/代码/简拼'){
             $c=$("#stockcode").val();
               }
           ajaxd= $.ajax({
        	       url:httphost+"mydata/data9/"+$a+"/16/"+$p+"?code="+$c,
        		   type:'get',
        		   dataType: "jsonp",
        		   success:function(json){
        	if (json.list.length > 0) { 
        		$("#pageno").val(json.page.page);
                $("#pagecount").val(json.page.totalpage);
                $("#page1").attr("p",1);
                if(json.page.uppage<=1)
                	$("#page2").attr("p",1);
                else
                $("#page2").attr("p",json.page.uppage);
                if(json.page.nextpage>=json.page.totalpage){
                	 $("#page3").attr("p",json.page.totalpage);
                    }else
                $("#page3").attr("p",json.page.nextpage); 
                $("#page4").attr("p",json.page.totalpage);
                setpage();
                $("[p]").unbind('click');
                $("[p]").click(function(){
                	getd($(this).attr("p"));
                	return false;
                    });
        		var str = "";
        		$g=16*($p-1)+1;
        		for (var i = 0; i < json.list.length; i++) {
            		$c='even';
            		if(i%2==0)$c='odd'; 
        		   	str+=' <tr class="'+$c+'" code="'+json.list[i]['d1']+'">'
        		   	+' <td class="font_1">'
                    +($g+i)
                    +'</td>'
                    +'<td class="font_1">'
                    + '<a class=stockCode1 href="javascript:void(0);" stockCode1="'+json.list[i]['d1']+'">'+json.list[i]['d1']
                        +'</a></td>'
                    +'<td class="font_2">'
                    +json.list[i]['d2']
                    +'</td>'
                    +'<td class="font_1">'
                    +json.list[i]['d3']
                    +'</td>'
                    +'<td class="font_1">'
                    +json.list[i]['d4']
                    +'</td>'
                    +'<td class="font_1">'
                    +json.list[i]['d5']+' </td>'
                    +'<td class="font_3">'
                    +json.list[i]['d6']
                    +'                     </td>'
                    +' <td class="font_3">'
                    +json.list[i]['createtime'].substr(0,10) 
                    +'</td>'
                    +' </tr>'; 
        		}
        		$("#list").html(str);
        		str=null;
				$("[code]").click(function(){
					wkstock.jumppage('379',$(this).attr("code"));

					});
					wkstock.autocloseTip=true;
			 wkstock.appendTip();  
			 wkstock.stockPlugin({pid:'379'});
        	}else   $("#list").html("");    
        	$("#load").hide();   
         },
         error:function(XMLHttpRequest, textStatus, errorThrown) { 
             $("#load").hide();
         }
         });
       }
       getd(1);
    }); 
