﻿var uid,type,autoID,Guid,callType;
var activex_hqm = ((navigator.userAgent.indexOf('Win')  != -1) && (navigator.userAgent.indexOf('MSIE') != -1) && (parseInt(navigator.appVersion) >= 4 ));
var hqewbaseurl = "http://www.hqew.com";
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(hqewbaseurl + "/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(hqewbaseurl + "/Web/Hqen/Imrfq/Imrfqidic.aspx?uguid=" + uguid + "&imrfqtype=" + type + "&autoid=" + autoID + "&guid=" + Guid, target = '_blank');
    }
}
var HqmServiceObj = null;
function HqmService(userid,uguid,stype,entuid,roid)
{
	
    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']['ServiceID'] != undefined)
							{
								window.location.href="hqew://?uid=" + HqmServiceObj['Data']['ServiceID'] + "&uname=" + HqmServiceObj['Data']['Guid']+'&entuid='+entuid+'&roid='+roid;
							}
						}
						else
						{
							//alert(HqmServiceObj['Message']);
						}

					}
					else
					{
						window.location.href="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(hqewbaseurl + "/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())
};



