﻿
var y=0;  //圆形 0为未选中，1为选中
var f=0;  //方形
var x=0;  //心形

//形状
$("#003").toggle(function(){
	$(this).attr("class","diamond_bg_shape_on");
    y=1;
	page(1);
  },function(){
    $(this).attr("class","diamond_bg_shape_off");
	y=0;
	page(1);
});

$("#001").toggle(function(){
	$(this).attr("class","diamond_bg_shape_on");
	f=1;
	page(1);
  },function(){
    $(this).attr("class","diamond_bg_shape_off");
	f=0;
	page(1);
});

$("#006").toggle(function(){
	$(this).attr("class","diamond_bg_shape_on");
	x=1;
	page(1);
  },function(){
    $(this).attr("class","diamond_bg_shape_off");
	x=0;
	page(1);
});

//切工
var cut=new Array();
$("#cut_Ideal").toggle(function(){
	$(this).attr("class","diamond_bg_cut_on");
    cut[0]="Ideal";page(1);
  },function(){
    $(this).attr("class","diamond_bg_cut_off");
    cut[0]="";page(1);
});
$("#cut_EX").toggle(function(){
	$(this).attr("class","diamond_bg_cut_on");
    cut[1]="EX";page(1);
  },function(){
    $(this).attr("class","diamond_bg_cut_off");
    cut[1]="";page(1);
});
$("#cut_VG").toggle(function(){
	$(this).attr("class","diamond_bg_cut_on");
    cut[2]="VG";page(1);
  },function(){
    $(this).attr("class","diamond_bg_cut_off");
    cut[2]="";page(1);
});
$("#cut_G").toggle(function(){
	$(this).attr("class","diamond_bg_cut_on");
    cut[3]="G";page(1);
  },function(){
    $(this).attr("class","diamond_bg_cut_off");
    cut[3]="";page(1);
});
$("#cut_Fair").toggle(function(){
	$(this).attr("class","diamond_bg_cut_on");
    cut[4]="Fair";page(1);
  },function(){
    $(this).attr("class","diamond_bg_cut_off");
    cut[4]="";page(1);
});
//color
var color=new Array();
$("#color_D").toggle(function(){
	$(this).attr("class","diamond_bg_color_on");
    color[0]="D";page(1);
  },function(){
    $(this).attr("class","diamond_bg_color_off");
    color[0]="";page(1);
});
$("#color_E").toggle(function(){
	$(this).attr("class","diamond_bg_color_on");
    color[1]="E";page(1);
  },function(){
    $(this).attr("class","diamond_bg_color_off");
    color[1]="";page(1);
});
$("#color_F").toggle(function(){
	$(this).attr("class","diamond_bg_color_on");
    color[2]="F";page(1);
  },function(){
    $(this).attr("class","diamond_bg_color_off");
    color[2]="";page(1);
});
$("#color_G").toggle(function(){
	$(this).attr("class","diamond_bg_color_on");
    color[3]="G";page(1);
  },function(){
    $(this).attr("class","diamond_bg_color_off");
    color[3]="";page(1);
});
$("#color_H").toggle(function(){
	$(this).attr("class","diamond_bg_color_on");
    color[4]="H";page(1);
  },function(){
    $(this).attr("class","diamond_bg_color_off");
    color[4]="";page(1);
});
$("#color_I").toggle(function(){
	$(this).attr("class","diamond_bg_color_on");
    color[5]="I";page(1);
  },function(){
    $(this).attr("class","diamond_bg_color_off");
    color[5]="";page(1);
});
$("#color_J").toggle(function(){
	$(this).attr("class","diamond_bg_color_on");
    color[6]="J";page(1);
  },function(){
    $(this).attr("class","diamond_bg_color_off");
    color[6]="";page(1);
});
$("#color_K").toggle(function(){
	$(this).attr("class","diamond_bg_color_on");
    color[7]="K";page(1);
  },function(){
    $(this).attr("class","diamond_bg_color_off");
    color[7]="";page(1);
});
//净度
var clarity=new Array();
$("#clarity_FL").toggle(function(){
	$(this).attr("class","diamond_bg_clarity_on");
    clarity[0]="FL";page(1);
  },function(){
    $(this).attr("class","diamond_bg_clarity_off");
    clarity[0]="";page(1);
});
$("#clarity_IF").toggle(function(){
	$(this).attr("class","diamond_bg_clarity_on");
    clarity[1]="IF";page(1);
  },function(){
    $(this).attr("class","diamond_bg_clarity_off");
    clarity[1]="";page(1);
});
$("#clarity_VVS1").toggle(function(){
	$(this).attr("class","diamond_bg_clarity_on");
    clarity[2]="VVS1";page(1);
  },function(){
    $(this).attr("class","diamond_bg_clarity_off");
    clarity[2]="";page(1);
});
$("#clarity_VVS2").toggle(function(){
	$(this).attr("class","diamond_bg_clarity_on");
    clarity[3]="VVS2";page(1);
  },function(){
    $(this).attr("class","diamond_bg_clarity_off");
    clarity[3]="";page(1);
});
$("#clarity_VS1").toggle(function(){
	$(this).attr("class","diamond_bg_clarity_on");
    clarity[4]="VS1";page(1);
  },function(){
    $(this).attr("class","diamond_bg_clarity_off");
    clarity[4]="";page(1);
});
$("#clarity_VS2").toggle(function(){
	$(this).attr("class","diamond_bg_clarity_on");
    clarity[5]="VS2";page(1);
  },function(){
    $(this).attr("class","diamond_bg_clarity_off");
    clarity[5]="";page(1);
});
$("#clarity_SI1").toggle(function(){
	$(this).attr("class","diamond_bg_clarity_on");
    clarity[6]="ST1";page(1);
  },function(){
    $(this).attr("class","diamond_bg_clarity_off");
    clarity[6]="";page(1);
});
$("#clarity_SI2").toggle(function(){
	$(this).attr("class","diamond_bg_clarity_on");
    clarity[7]="SI2";page(1);
  },function(){
    $(this).attr("class","diamond_bg_clarity_off");
    clarity[7]="";page(1);
});
//抛光
var polish=new Array();
$("#polish_Ideal").toggle(function(){
	$(this).attr("class","diamond_bg_polish_on");
    polish[0]="Ideal";page(1);
  },function(){
    $(this).attr("class","diamond_bg_polish_off");
    polish[0]="";page(1);
});
$("#polish_EX").toggle(function(){
	$(this).attr("class","diamond_bg_polish_on");
    polish[1]="EX";page(1);
  },function(){
    $(this).attr("class","diamond_bg_polish_off");
    polish[1]="";page(1);
});
$("#polish_VG").toggle(function(){
	$(this).attr("class","diamond_bg_polish_on");
    polish[2]="VG";page(1);
  },function(){
    $(this).attr("class","diamond_bg_polish_off");
    polish[2]="";page(1);
});
$("#polish_G").toggle(function(){
	$(this).attr("class","diamond_bg_polish_on");
    polish[3]="G";page(1);
  },function(){
    $(this).attr("class","diamond_bg_polish_off");
    polish[3]="";page(1);
});
$("#polish_Fair").toggle(function(){
	$(this).attr("class","diamond_bg_polish_on");
    polish[4]="Fair";page(1);
  },function(){
    $(this).attr("class","diamond_bg_polish_off");
    polish[4]="";page(1);
});
//对称
var symmetry=new Array();
$("#symmetry_Ideal").toggle(function(){
	$(this).attr("class","diamond_bg_symmetry_on");
    symmetry[0]="Ideal";page(1);
  },function(){
    $(this).attr("class","diamond_bg_symmetry_off");
    symmetry[0]="";page(1);
});
$("#symmetry_EX").toggle(function(){
	$(this).attr("class","diamond_bg_symmetry_on");
    symmetry[1]="EX";page(1);
  },function(){
    $(this).attr("class","diamond_bg_symmetry_off");
    symmetry[1]="";page(1);
});
$("#symmetry_VG").toggle(function(){
	$(this).attr("class","diamond_bg_symmetry_on");
    symmetry[2]="VG";page(1);
  },function(){
    $(this).attr("class","diamond_bg_symmetry_off");
    symmetry[2]="";page(1);
});
$("#symmetry_G").toggle(function(){
	$(this).attr("class","diamond_bg_symmetry_on");
    symmetry[3]="G";page(1);
  },function(){
    $(this).attr("class","diamond_bg_symmetry_off");
    symmetry[3]="";page(1);
});
$("#symmetry_Fair").toggle(function(){
	$(this).attr("class","diamond_bg_symmetry_on");
    symmetry[4]="Fair";page(1);
  },function(){
    $(this).attr("class","diamond_bg_symmetry_off");
    symmetry[4]="";page(1);
});

var minweight="",maxweight="",minprice="",maxprice="";
function get()
{
    //重量
    minweight=$("#manualkey_weight_from").val();
    maxweight=$("#manualkey_weight_to").val();
    //价格
    minprice=$("#manualkey_price_from").val();
    maxprice=$("#manualkey_price_to").val();
}


//数组返回字符窜
function getstring(array)
{
   var str="";
   for(var i=0;i<array.length;i++)
	{
		if(typeof(array[i])!='undefined'&&array[i]!="")
		{
		    str+="'"+array[i]+"'"+",";
		}
	}
	if(str!="")
	{
		str=str.substr(0,str.length-1);
	}
	return str;
}
function reset()
{
    y=0;f=0;x=0;
    cut.length=0;
    color.length=0;
    clarity.length=0;
    polish.length=0;
    polish.length=0;
    symmetry.length=0;
    minweight=0;
    maxweight=3;
}
//关键字
function getweight(min,max)
{
    reset();
    minweight=min;
    maxweight=max;
    page(1);
}
function get3ex()
{
    reset();
    cut[1]="EX";page(1);
}
//初始分页

var pageCount = 20;
var totalRecord = 0;
     
var currentPageIndex = 1;

var pagerStyle = "diamindpage";//quotes
var url='/Ajax/diamond.ashx';
var orderBy = "";//排序字段

function page(pageIndex)
{
	currentPageIndex = pageIndex;
    $("#nowpage").val(currentPageIndex);
	var shape="";var dian="";
	if(y!=0)
	{
		shape+=dian+"'"+"圆形"+"'";
		dian=",";
	}
	if(f!=0)
	{
		shape+=dian+"'"+"方型"+"'";
		dian=",";
	}
	if(x!=0)
	{
		shape+=dian+"'"+"心型"+"'";
		dian=",";
	}
    //alert( "type=diamond&pageIndex="+escape(pageIndex)+"&pageCount="+escape(pageCount)+"&shape="+escape(shape)+"&cut="+escape(getstring(cut))+"&color="+escape(getstring(color))+"&clarity="+escape(getstring(clarity))+"&polish="+escape(getstring(polish))+"&symmetry="+escape(getstring(symmetry))+"&minweight="+escape(minweight)+"&maxweight="+escape(maxweight)+"&minprice="+escape(minprice)+"&maxprice="+escape(maxprice)+"&orderby="+orderBy+"");
	$.ajax({
           type: "post",
           dataType:"json",
           url:  url,
           data:"type=diamond&pageIndex="+escape(pageIndex)+"&pageCount="+escape(pageCount)+"&shape="+escape(shape)+"&cut="+escape(getstring(cut))+"&color="+escape(getstring(color))+"&clarity="+escape(getstring(clarity))+"&polish="+escape(getstring(polish))+"&symmetry="+escape(getstring(symmetry))+"&minweight="+escape(minweight)+"&maxweight="+escape(maxweight)+"&minprice="+escape(minprice)+"&maxprice="+escape(maxprice)+"&orderby="+orderBy+"",
           beforeSend:function(){$("#totalCount").html("......");$("#loading").show();},
           complete:function(){},
           error:function(){},
           success: function(msg){
			        $("#loading").hide();
			        if(msg.totalCount!=0){$("#totalCount").html(msg.totalCount);}else{$("#totalCount").html("0");}
			        
			        
			        
					$("#diamondlist tbody").find("tr.newrow").remove();
                    $.each(msg.data,function(i,item){
                        if(item.productid != null && item.productid != "")
                        
						$("<tr class='newrow' id='tip"+item.productid+"' on></tr>").append("<td  width='7%'   style=\"text-align:center\"><img src='/images/02-s-xz.gif' width='30' height='14' /></td>"+
                     
                          "<td width='9%'   style=\"text-align:center;cursor:pointer;\"><a   tips=\"产品名字:"+item.productname+"<br>市场价:"+item.price_market.substr(0,item.price_market.length-2)+"<br>海盟价:"+item.price_member.substr(0,item.price_member.length-2)+"\">"+item.productcode+"</a></td>"+
                          "<td width='7%'  style=\"text-align:center\">"+item.productcertificate.substr(0,3)+"</td>"+
                          "<td width='6%'  style=\"text-align:center\">"+(item.My_maincarat==""?"-":item.My_maincarat)+"</td>"+
                          "<td width='7%'   style=\"text-align:center\">"+(item.My_clarity==""?"-":item.My_clarity)+"</td>"+
                          "<td width='7%'   style=\"text-align:center\"><span class='hei12_z'>"+(item.My_color==""?"-":item.My_color)+"</span></td>"+
                          "<td width='7%'   style=\"text-align:center\">"+(item.My_cutting==""?"-":item.My_cutting)+"</td>"+
                          "<td width='6%'   style=\"text-align:center\"><span class='hei12_z'>"+(item.My_Polish==""?"-":item.My_Polish)+"</span></td>"+
                          "<td width='8%'  style=\"text-align:center\"><span class='hei12_z'>"+(item.My_Symmetry==""?"-":item.My_Symmetry)+"</span></td>"+                          
                          "<td width='10%'  style=\"text-align:left\"><span style='text-decoration:line-through '>￥"+item.price_market.substr(0,item.price_market.length-2)+"</span></td>"+
                          "<td width='10%' style=\"text-align:left\"><span style='color:#BF0000'>￥"+item.price_member.substr(0,item.price_member.length-2)+"</span></td>"+
                          "<td width='8%'  style=\"text-align:left\">成都</td>"+
                          "<td width='6%'  style=\"text-align:left\"><a href='javascript:void(0)' onclick=joincart("+item.productid+")><img src='/images/02-s-gw.gif' width='30' height='14' border=0 /></a>&nbsp;&nbsp;&nbsp;</td>"+
                          "<td width='5%'  style=\"text-align:left\"><span class='hei12_z'><input type='checkbox' id="+item.productid+" onclick='changbj("+item.productid+")' name='checkboxbj' value='"+item.productid+"' /></span>&nbsp;&nbsp;</td>"+
                          "<td width='8%' height='28' align='center'><a href='/Diamond/Detail.aspx?pid="+item.productid+"' target=_blank><img src='/images/02-s-xx.gif' width='37' height='17' border=0 /></a></td>").appendTo($("#diamondlist tbody"));
	 
                   });
                   
                   var str=$("#bjvalue").val();
                   if(str!="")
                   {
                       str=str.substr(0,str.length-1);
                       var strs= new Array();
                       strs=str.split(",");
                       for (i=0;i<strs.length ;i++ )
                       {
                           try{
                              document.getElementById(strs[i]).checked=true;
                           }catch(e){}
                       }
                   }
				   
                  totalRecord = msg.totalCount;
				 
                  ShowPageBar("pageDataList1_Pager",
                   "<%= Request.Url.AbsolutePath %>",
                    {style:pagerStyle,mark:"page",
                    totalCount:msg.totalCount,showPageNumber:1,pageCount:pageCount,currentPageIndex:pageIndex,noRecordTip:"没有记录,<a href='../BBU/index.aspx'>请到全球搜索</a>",preWord:"<IMG src='/images/page_nav_prev.gif' border=0>",nextWord:"<IMG src='/images/page_nav_next.gif' border=0>",
                    onclick:"page({pageindex});return false;"}
                    );
               }
           });    
}
  
function OrderBy(orderColum,orderTip)
{
        var ordering = "a";
        //var orderTipDOM = $("#"+orderTip);
        var allOrderTipDOM  = $(".orderTip");
        
        if( $("#"+orderTip).attr("src")=="/images/arrow_desc.gif")
        {
             allOrderTipDOM.attr("src","/images/arrow_desc.gif");
             $("#"+orderTip).attr("src","/images/arrow_asc.gif");
        }
        else
        {
            ordering = "d";
            //allOrderTipDOM.attr("src","/images/arrow_asc.gif");
            $("#"+orderTip).attr("src","/images/arrow_desc.gif");
        }
        orderBy = orderColum+"_"+ordering;
        page(1);
}
   
function showdiv(o)
{
var tip=document.getElementById("tip_info"+o);
var t=document.getElementById("tip"+o);
tip.style.display="block";
tip.style.background="#ffefef";
tip.style.position="absolute";
tip.style.height=100;
tip.style.top=mouseY(event)-40;
tip.style.width=160;
tip.style.left=200;
tip.style.color="#009933";
//alert(event.y);
}
function hide(o)
{
var t=document.getElementById("tip_info"+o);
t.style.display="none";
}
function mouseY(evt) {
if (evt.pageY) return evt.pageY;
else if (evt.clientY)
   return evt.clientY + (document.documentElement.scrollTop ?
   document.documentElement.scrollTop :
   document.body.scrollTop);
else return null;
}

//改变每页记录数及跳至页数
$("#ShowPageCount").change(function(){
	   pageCount=$("#ShowPageCount").val();
	   page(1);
});

$("#A2").click(function(){
	get();
    page(1);
});
$("#turntopage").click(function(){
    var nowpage=$("#nowpage").val();
    var re=/^[1-9]+[0-9]*]*$/;
    if(!re.test(nowpage))
    {
       alert("请输入数字");
       $("#nowpage").focus();
       return false;
    }
    else
    {
       page(parseInt(nowpage));
    }
});

function changbj(pid)
{
  var  chkbox=document.getElementById(pid);   
  var   v="";   
  v=chkbox.value;
  var bj= $("#bjvalue").val();
  var str=v.replace(/^,{1}/,""); 
  if(chkbox.checked)
  {
     if(bj!="")
     {
        $("#bjvalue").val(bj+str+",");
     }
     else
     {
         $("#bjvalue").val(str+",");
     } 
  }
  else
  {
       $("#bjvalue").val(bj.replace(str+",",""));
  }   
}

$("#diamonbj").click(function(){
    var str="";
    /*
    $("[name='checkboxbj'][checked]").each(function(){
        str+=$(this).val()+",";
    });
    */
    str=$("#bjvalue").val();

    if(str!="")
    {
        str=str.substr(0,str.length-1);
        window.open('/Diamond/compare.aspx?pid='+str);
    }
    else
    {
       alert("你没有选择!");
    }
});

function joincart(pid)
{
     $.post(url,{type:"joincart",proid:pid},function(msg){
               alert(msg);      
      });
}

jQuery(function($) {
    page(1);
    
});



