var hasBeeninstanced=false;
var hasBeenInstancePlugIn=false;
OnlyCheckAlitalkInstalled();
function clickAlitalk(uid){
	var binstalled=newCheckAlitalkInstalled();
	var isIE = checkIEorFirefox();
	if (isIE==true) {
		if(binstalled==true) {
			window.location="TradeManager:SendIM?"+"enaliint"+uid;
		}else{
      	  		doForwardTrademanagerIfNotInstalled();
      	}
    } else {
      		doIfExploreIsNotSupport();
      	//	window.location = "";
    }
}
function checkIE(){
	var name = navigator.appName;
	if (name == "Microsoft Internet Explorer"){
		return true;
	} else {
       		return false;
    }
}
function doIfExploreIsNotSupport(){
     alert("Only Available to Microsoft Internet Explorer and FireFox 1.5 or above.");
}
function doForwardTrademanagerIfNotInstalled(){
	if(checkIE()) {
		window.location='http://us.my.alibaba.com/mcweb/contact.htm?action=mcweb:contact_action&chkProductIds=105422847';
	} else if(checkFirefoxIsBigThan15()){
		if(!hasBeenInstancePlugIn && confirm("You need the Firefox plug-in. Click the Confirm button to download it.")){
			if(window.InstallTrigger){
				InstallTrigger.install({'alibaba':'http://download.alitalk.alibaba.com/TradeManager/download/aliww.xpi'});
			}
		} else if(hasBeenInstancePlugIn) {
			window.location="http://us.my.alibaba.com/mcweb/contact.htm?action=mcweb:contact_action&chkProductIds=105422847";
		}
	}
}
function checkIEorFirefox(){
	var name = navigator.appName;
	if (name == "Microsoft Internet Explorer" || checkFirefoxIsBigThan15()){
		return true;
	} else {
       		return false;
    }
}
function OnlyCheckAlitalkInstalled(){
	hasBeeninstanced=false;
    //IE.
    if (window.navigator.userAgent.indexOf("MSIE")>=1){
    	var obj;
    	try{
        	obj = new ActiveXObject("TradeManagerSetup.Install.1");
    	} catch (e) {
         //alert(e.message);
        }
    	if (null!=obj) {
        	hasBeeninstanced=true;
        	return hasBeeninstanced;
    	}
 	}

	if (checkFirefoxIsBigThan15()){
	 	var mimetype = navigator.mimeTypes["application/ww-plugin"];

	 	if (mimetype){
	 		hasBeenInstancePlugIn=true;
	    // Yes, so can we display the plug-in?
	  		plugin = mimetype.enabledPlugin
			if (plugin){
				document.write( "<embed id=\"chk_ww\" name=\"chk_ww\" type=\"application/ww-plugin\" width=1 height=1 hidden=\"true\" >");
				hasBeeninstanced=document.getElementById("chk_ww").isInstalled(2); //0,wangwang,1,alitalk,2. TradeManager
			}
		}
 	}else{
		hasBeeninstanced=false;
 	}

	return hasBeeninstanced;
}
function checkFirefoxIsBigThan15(){
	if(window.navigator.userAgent.indexOf("Firefox")>=1){
	    userAgent=window.navigator.userAgent;
		Findex=userAgent.indexOf("Firefox/");
		versionName=userAgent.substr(Findex+"Firefox/".length, 3);
		if(versionName>="1.5"){
			return true;
		}
	}
	return false;
}
function newCheckAlitalkInstalled(){
	return hasBeeninstanced;
}