﻿var uid,type,autoID,Guid,callType;
var activex_hqm = ((navigator.userAgent.indexOf('Win')  != -1) && (navigator.userAgent.indexOf('MSIE') != -1) && (parseInt(navigator.appVersion) >= 4 ));

function isHQMInstalled()
{
	var oHQM = null;
	try
	{
		oHQM = new ActiveXObject("HqtChat.HqtChatDlg");
		if( oHQM == null )
		{
			return false;
		}
		oHQM = null;
		return true;
	}
	catch( E )
	{
		return false;
	}
}

function isHQM2011InstalledOld()
{
	var oHQM = null;
	try 
	{
		oHQM = new ActiveXObject("hqRun.hqtmRun");

		if (oHQM == null) 
		{
			return false;
		}
		oHQM = null;

		return true;

	} catch (err) 
	{
		return false;
	}

}



function isHQM2011Installed()
{

	var oHQM = null;
	try 
	{

		oHQM = new ActiveXObject("HqmTalk.HqmPlugin");

		if (oHQM == null) 
		{
			return false;

		}

		oHQM = null;

		return true;

	} 
	catch (err) 
	{
		return false
	}

}


function HQMCheck()
{
        if( !activex_hqm )
        {
            return true;
        }
	
      if( isHQMInstalled() || isHQM2011Installed() || isHQM2011InstalledOld())
      {
  	    return true;
      }        
      
      return false;
}

function HqmChat(userid,uguid,pguid)
{
    if (HQMCheck())
    {
        window.location.href="hqew://?uid=" + userid + "&uname=" + uguid;//+"&pguid="+pguid;
    }else
    {
        window.open("/Web/Hqen/Imrfq/Imrfqidic.aspx?uguid=" + uguid+"&pguid="+pguid,target='_blank');    
    }
}

function HqmChatIBS(userid,uguid){
    if (HQMCheck())
    {
        window.location.href="hqew://?uid=" + userid + "&uname=" + uguid ;
        return true;
    }else{
        return false;
    }
}

//参数UserID:对方ID,type:产品类型，autoID：产品标识，Guid:产品GUID 询报价
function HqmChatRFQ(userid,uguid,type,autoID,Guid)
{
    if (HQMCheck())
    {
        window.location.href="hqew://?uid=" + userid + "&uname=" + uguid + "&RFQType=1&PType=" + type + "&PID=" + autoID + "&PGuid="+ Guid;

    }else
    {
        window.open("/Web/Hqen/Imrfq/Imrfqidic.aspx?uguid=" + uguid+"&imrfqtype="+type+"&autoid="+autoID+"&guid="+Guid,target='_blank');
    }
}
var HqmServiceObj = null;
var HqmClientEntUrl = "";
var HqmClientDefUrl = "";
function HqmService(userid,uguid,stype,entuid,roid)
{
	HqmClientEntUrl = "hqew://?uid=" + userid + "&uname=" + uguid+"&entuid="+entuid+"&roid="+roid;
	HqmClientDefUrl = "hqew://?uid=" + userid + "&uname=" + uguid;
    if (HQMCheck())
    {
		try
		{
			Hqmjs({
				url: 'http://hqmim.hqew.com/ajax/services.aspx?uid='+userid+'&ug='+uguid+'&type='+stype+'&entuid='+entuid+'&roid='+roid+'&r='+new Date().getTime(),
				success: function () 
				{
					//alert(HqmServiceObj['ResultCode']+'  '+HqmServiceObj['Data']['ServiceID']);
					if (HqmServiceObj != undefined)
					{
						var resultCode = 9;
						if (HqmServiceObj['ResultCode'] != undefined)
						{
							resultCode = HqmServiceObj['ResultCode'].toString();
						}
						if (resultCode == "0")
						{
							if (HqmServiceObj['Data']['EntID'] == "0")
							{
								window.location.href = HqmClientDefUrl;
							}
							else if (HqmServiceObj['Data']['ServiceID'] != undefined)
							{
								window.location.href="hqew://?uid=" + HqmServiceObj['Data']['ServiceID'] + "&uname=" + HqmServiceObj['Data']['Guid']+"&entuid=" + HqmServiceObj['Data']['EntID']+"&roid=" + HqmServiceObj['Data']['RoID'];
							}
						}
						else
						{
						}
					}
					else
					{
						window.location.href=HqmClientDefUrl;
						//"hqew://?uid=" + userid + "&uname=" + uguid+'&entuid='+entuid+'&roid='+roid;
					}
					HqmServiceObj = null;
				}
			});
		}
		catch(err)
		{
			//window.open("/Web/Hqen/Imrfq/Imrfqidic.aspx?uguid=" + uguid+"&pguid=",target='_blank');    
		}
    }
	else
    {
        window.open("/Web/Hqen/Imrfq/Imrfqidic.aspx?uguid=" + uguid+"&pguid=",target='_blank');    
    }
}

var Hqmjs = function (o) {
    function jsfind() {
        var s = document.getElementsByTagName('script'),
            i = s.length;
        while (i--) {
            if (s[i].src == ((o.url.toLowerCase().indexOf('http') > -1) ? '' : location.href.cut(location.href.lastIndexOf('/'))) + o.url) {
                return s[i]
            }
        }
        return jscreate()
    }

    function jscreate() {
        var s = document.createElement('script');
        s.type = 'text/javascript';
        s.src = o.url;
        s.charset = o.charset || 'utf-8';
        document.getElementsByTagName('head')[0].appendChild(s);
        return s
    }

    function jsload(e) {
        window.addEventListener ? e.addEventListener('load', function () {
            o.success()
        },
        false) : e.attachEvent('onreadystatechange', function (a) {
            if (e.readyState == 'loaded' || e.readyState == 'complete') {
                o.success()
            }
        })
    }
    jsload(jsfind())
};


function HqmICUpload() {
    if (HQMCheck()) {
        window.location.href = "hqew://?&cmd=icupload";
    }
    else {
        alert("您未安装华强洽洽2011！");
    }
}

function HqmBidOpen() {
    if (HQMCheck()) {
        window.location.href = "hqew://?&cmd=hqmbid";
    }
    else {
        alert("您未安装华强洽洽2011！");
    }
}

function HqmBidAddKeyword() {
    if (HQMCheck()) {
        window.location.href = "hqew://?&cmd=hqmbid&ExecuteType=1";
    }
    else {
        alert("您未安装华强洽洽2011！");
    }

}

function HqmBidEditPrice(BidID) {
    if (HQMCheck()) {
        window.location.href = "hqew://?&cmd=hqmbid&ExecuteType=2&BiddingID=" + BidID;
    }
    else {
        alert("您未安装华强洽洽2011！");
    }
}

function HqmBidChooseKeyword() {
    if (HQMCheck()) {
        window.location.href = "hqew://?&cmd=hqmbid&ExecuteType=3";
    }
    else {
        alert("您未安装华强洽洽2011！");
    }
}

function HqmBidSetStragety(BidID) {
    if (HQMCheck()) {
        window.location.href = "hqew://?&cmd=hqmbid&ExecuteType=4&BiddingID=" + BidID;
    }
    else {
        alert("您未安装华强洽洽2011！");
    }
}

function HqmStockOpen(index) {
    if (HQMCheck()) {
        if (index) {
            window.location.href = "hqew://?&cmd=hqmstock&hqmstatus=" + index;
        } else {
            window.location.href = "hqew://?&cmd=hqmStock";
        }
    }
    else {
        alert("您未安装华强洽洽2011！");
    }
}

function HqmEnterpriseOpen(index) {
    if (HQMCheck()) {
        if (index) {
            window.location.href = "hqew://?&cmd=hqmcorp&mgrtype=" + index;
        } else {
            window.location.href = "hqew://?&cmd=hqmcorp";
        }
    }
    else {
        alert("您未安装华强洽洽2011！");
    }
}
