﻿   function f_close()
   {
      document.getElementById("wrap1").style.display="none";
      document.getElementById("divbg").style.display="none";
   }
   function f_openLogin()
   {
      document.getElementById("wrap1").style.display="block";
      document.getElementById("divbg").style.display="block";
      document.getElementById("divbg").style.height=document.body.scrollHeight;
      document.getElementById("wrap1").style.top=(document.documentElement.scrollTop+100);
   }
   function f_keyDown(eve)
     {
              var even=window.event||eve;
              if(even.keyCode==13)goToLogin_1("list");
     }

var ProvideID='';
var CategoryID='';
var EnterpriseID='';
var BrandID='';
var UnitPrice='';

$(document).ready(function()
{
var aa=document.getElementById("txtProvideID").value;
    ProvideID=$("#txtProvideID").val();
    CategoryID=$("#txtCategoryID").val();
    EnterpriseID=$("#txtEnterpriseID").val();
    BrandID=$("#txtBrandID").val();
    UnitPrice=$("#txtUnitPrice").val();
    //GetIMState();
    //GetIMServerUserState();
    AddFavorites();
    AddRecommend();
    ShowPrice();
    UpdateClickCount();
    GetClickCount();
    GetOrderCount();
    GetCategoryProducts();
    GetPriceProducts();
    GetBrandProducts();
});
function UpdateClickCount()
{
    //更新产品点击数
     $.ajax({
        type: "GET",
        url: "/Product/AjaxService/ClickCount.ashx",
        dataType:"text",
        data: "ID="+ProvideID+"&URL="+$("#txtInfoUrl").val()+"&Title="+$("#txtProvideTitle").val()+"",
        success: function(html){}
    });  
}

function GetClickCount()
{
    //更新产品点击数
     $.ajax({
        type: "GET",
        url: "/Product/AjaxService/GetProductInfo.ashx",
        dataType:"text",
        data: "ProvideID="+ProvideID+"&type=ClickNum",
        success: function(html){
          $("#GZNum").html(html); 
        }
    });  
}

function GetOrderCount()
{
    //更新产品点击数
     $.ajax({
        type: "GET",
        url: "/Product/AjaxService/GetProductInfo.ashx",
        dataType:"text",
        data: "ProvideID="+ProvideID+"&type=OrderNum",
        success: function(html){
          $("#GMNum").html(html); 
        }
    });  
}

function GetCategoryProducts()
{
    //本公司其它同类最新产品
    $.ajax({
        type: "GET",
        url: "/Product/AjaxService/GetProducts.ashx",
        dataType:"text",
        data: "CategoryID="+CategoryID+"&ProductType=CategoryProduct",
        success: function(html)
        {
            $("#trCategoryProduct").html(html); 
        },
        cache:false
    });    
}

function GetPriceProducts()
{
    //本公司其它同类最新产品
    $.ajax({
        type: "GET",
        url: "/Product/AjaxService/GetProducts.ashx",
        dataType:"text",
        data: "UnitPrice="+UnitPrice+"&ProductType=PriceProduct",
        success: function(html)
        {
            $("#trPriceProduct").html(html); 
        },
        cache:false
    });    
}

function GetBrandProducts()
{
    //本公司其它同类最新产品
    $.ajax({
        type: "GET",
        url: "/Product/AjaxService/GetProducts.ashx",
        dataType:"text",
        data: "BrandID="+BrandID+"&ProductType=BrandProduct",
        success: function(html)
        {
            $("#trBrandProduct").html(html); 
        },
        cache:false
    });    
}

function GetIMState()
{
    $.ajax({
        type:"GET",
        dataTpye:"text",
        url:'/Product/AjaxService/user.ashx',
        data:"type=name&eID="+EnterpriseID,
        success:function(response)
        {$("#IMImage").click(function(){window.open('http://58.248.62.23/openTalkingForm.aspx?LoginName='+response); return false;});}
    });
}

//利用异步通信获取IM登录信息
function GetIMServerUserState()
{
 var IMImage;
 IMImage= window.document.getElementById("IMImage");
 xmlhttp.onreadystatechange=function(){
  
      if(xmlhttp.readyState==4)//判断是否是完成状态
      {
         if(xmlhttp.status==200)//判断是否执行成功
         {
           var ImInfos; 
           ImInfos = xmlhttp.responseText.split(':');
           $(IMImage).click(function(){
              OpenIM1('"+ImInfos[1]+"','"+ImInfos[0]+"','0'); return false;  
           });           
         }
      }
    
    }
    xmlhttp.open("GET","/eStore/AjaxService/GetData.aspx?ID="+EnterpriseID,true);
    xmlhttp.send(null); 
}

function AddFavorites()
{
     $("#ibtnAddFavorites").click(function(){
        var link =$("#txtInfoUrl").val();       
        //将表单项的值组合成一个字符串    
        var dataString = 'InfoID='+ ProvideID + '&InfoType=Supply&PageLink=' + link;
         $.ajax({
               type: "GET",
               url: "/Product/AjaxService/AddFavorites.ashx",
               dataType:"text",
               data: dataString,
               success: function(msg){
                   alert( msg );
               }
            });      
    });
}

function AddRecommend(){
   $("#ibtnRecommend").click(function(){
   var link=$("#txtInfoUrl").val();
   OpenRecommend(link); return false;
   })
}

function OpenRecommend(url){
   window.open("/Product/Recommend.aspx?RequestURL="+url,'_blank');
}

function ShowPrice(){
    var displayObj = window.document.getElementById("TPrice");
    if(displayObj == null) {alert("找不到ID标识的对象:)");return;}
    
    //var displayObj2 = window.document.getElementById("TAM");
    //if(displayObj2 == null) {alert("找不到ID标识的对象:)");return;}
    
    //var displayObj3 = window.document.getElementById("txtP");
    //if(displayObj3 == null) {alert("找不到ID标识的对象:)");return;}
    
    //var displayObj4 = window.document.getElementById("txtM");
    //if(displayObj4 == null) {alert("找不到ID标识的对象:)");return;}
    
    var Price;
    var TP = window.document.getElementById("TradePrice");
    if(displayObj == null){
    Price=-1;
    }
    else{
    Price=TP.value;
    }
    
    var MobilePhones;
    var PhoneNumbers;
    var HM = window.document.getElementById("H_MobilePhone");
    var HP = window.document.getElementById("H_PhoneNumber");
    //if(displayObj2 == null){
    //MobilePhones=-1;
    //PhoneNumbers=-1;
    //}
    //else{
    //MobilePhones=HM.value;
    //PhoneNumbers=HP.value;
    //}
    
    var xmlhttp;
    if(window.ActiveXObject)
    {
       xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    else if(window.XMLHttpRequest)
    {
       xmlhttp=new XMLHttpRequest();
    }
    
    xmlhttp.onreadystatechange=function(){
      if(xmlhttp.readyState==4)//判断是否是完成状态
      {
         if(xmlhttp.status==200)//判断是否执行成功
         {
            var loginid; 
            loginid = xmlhttp.responseText;
            if(loginid == "0"){
            var html ="请 <a href=\"javascript:f_openLogin()\">登录</a> 后查看价格!";
            displayObj.innerHTML = "";
            displayObj.innerHTML = html;
            }else{
            displayObj.innerHTML = "";
            displayObj.innerHTML = Price+" 元";
            //displayObj2.className="";
            //displayObj3.innerHTML="";
            //displayObj3.innerHTML=PhoneNumbers;
            //displayObj4.innerHTML="";
            //displayObj4.innerHTML=MobilePhones;
            
            }
         }
      }
    
    }
    xmlhttp.open("GET","/GetData.aspx?type=GetLogin&ran="+Math.random(),true);
    xmlhttp.send(null);
    
}