﻿
function openDialog5(id,name)
{
 $("#productid").val(id);
 $("#productname").val(name);
 var test=$("#Button"+id).offset(); 
 document.getElementById("find_con").style.top=test.top;
 document.getElementById("find_con").style.left=test.left;
 $("#find_con").show("slow");

}

function openDialog(id,name)
{
 $("#productid").val(id);
 $("#productname").val(name);
 var test=$("#Button"+id).offset(); 
 document.getElementById("find_con").style.top=test.top;
 document.getElementById("find_con").style.left=test.left-250;
 $("#find_con").show("slow");

}

NeatDialog.prototype.close = function()
{
  if (this.elt)
  {
    this.elt.style.display = "none";
    this.elt.parentNode.removeChild(this.elt);
  }
  window.neatDialog = null;
}
 
function ot(ev,obj,lrcID) 
{
	var ev=window.event||ev;
	ev.returnValue=false;
	var isFF=!document.all;
	var re=new RegExp("^[0-9]+$");
	if(lrcID!=null&&!isFF)
	{
		var d=lrcID.match(re);
		if(d&&parseInt(lrcID)>0){return wo(obj.href,364,542,0,1)}
	}
	return wo(obj.href,364,200,0,1);
}
function wo(url,w,h,m,s)
{
	var left=(screen.width-w)/2;
	var top=m?(screen.height-h)/2:0;
	window.open(url,'','width='+w+',height='+h+',top='+top+',left='+left+',scrollbars=0,resizable=0,status='+s);
	return false;
}

var userfriends;
$().ready(function() {

    //对页面进行初始化
    function init()
    {     
        var datas="";		 	   
        var url = "user-Getuserfriends.ashx";
 
        openAjaxDialog(url,{},function(json){           
          
            userfriends = json.message;            
            //初始化类别
            var old,curr;
            var options;
            old = '';        
            $.each(userfriends,function(i,n){
                curr = eval("n."+"typename");
                if(old != curr)   {
                    //增加一个option                
                    options = new Option(curr,curr);               
                    document.getElementById("friendtype").options.add(options);
                    old = curr; 
                }           
            })   
        
            //默认所有会员信息
            var html;
            html = '<ul><li>';
            $.each(userfriends,function(i,n){            
                html += '<p class="findflist"><input name="friendid" title="'+eval("n."+"friendname")+'" type="checkbox" value="'+eval("n."+"friendid")+'" class="radio1" />'+eval("n."+"friendname")+'</p>';
            })
            html += '</li></ul>';
            $("#userfriend").html(html);   
        
         },function(json){});      
    }  

    
    initLoginInfo();

    init(); 
    
    $("#friendtype").change(function()
    {   
        var typename;
        var obj = this;
   
        typename = obj.options[obj.selectedIndex].text;    
       
        var html;
        html = "";
        html = '<ul><li>';
        $.each(userfriends,function(i,n){      
            if(typename == "全部好友")
                html += '<p class="findflist"><input name="" type="checkbox" value="" class="radio1" />'+eval("n."+"friendname")+'</p>';
            else {        
                if(eval("n."+"typename") == typename)
                    html += '<p class="findflist"><input name="friendid" title="'+eval("n."+"friendname")+'" type="checkbox" value="'+eval("n."+"friendid")+'" class="radio1" />'+eval("n."+"friendname")+'</p>';
            }
        })
         html += '</li></ul>';
        $("#userfriend").html(html);
       
    });   

    $("#friendselect").click(function()
    {
        var id,name;
        id = "";
        name = "";    
        $("input[@name='friendid']").each(function(){
            
            if(this.checked)     {
                id += id==""?this.value:","+this.value;
                name += name==""?this.title:","+this.title;           
            }
        }); 

         if(id == "")
        {
            openAlertDialog("你还没有选择好友哦");
            return;
        } 
        
        var url = "product-RecommendProduct.ashx";

        openAjaxDialog(url,{id:id,name:name,productid:$("#productid").val(),productname:$("#productname").val()},function(json){
                	        
             openAlertDialog('推荐成功!');   
            
        });      
       $("#find_con").hide("slow");

    });
    
      $("#cancelselect").click(function()
     {         
       $("#find_con").hide("slow");
     });  
    
})

/* 正在采购 持续关注 */
function concern(sid)
{
    var url = "product-Favoriteproduct.ashx";
    
    openAjaxDialog(url,{sid:sid},function(json){
        
        openAlertDialog( '<div style="color:#FE6B09;font-size:14px;font-weight:bold;text-align:center;border-bottom:1px solid #EDEDED;height:60px;line-height:60px;margin-bottom:5px;">您已经成功收藏此采购信息！</div>');
        
    });    
 }


  function search()
  {
    if($("#Pname").val()=='')
    {
     alert('搜货产品名称不能不空!');
     return;
    }
    if($("#Pname").val().length>4)
    {
     alert("搜货产品名称不能超过4个汉字!");
     return;
    }
    window.location="../products/search.aspx?name="+$("#Pname").val();
  }  