// JavaScript Document
function addBookmark(title,url){
	if(title="" || !title)title=document.title;
	if(url="" || !url)url=document.location;
	if (window.sidebar){
		window.sidebar.addPanel(title,url,""); 
	} else if(document.all){
		window.external.AddFavorite(url,title);
	} else if(window.opera&&window.print){
		return true;
	}
}
function addToBookmark(obj,res){
    var t=document.title;
    var u=document.location;
    var loc = "";
    switch(res){
        case "stumbleupon":
            loc = "http://www.stumbleupon.com/submit?url="+u+"&title="+t;
            break;
        case "reddit":
            loc = "http://reddit.com/submit?url="+u+"&title="+t;
            break;
        case "yahoo":
            loc = "http://myweb2.search.yahoo.com/myresults/bookmarklet?u="+u+"&t="+t;
            break;
         case "twitter":
            loc = "http://twitter.com/home?status=I%20like%20this%20on%20"+u;
            break;
         case "kaboodle":
            loc = "http://www.kaboodle.com/za/additem?get=1&url="+u+"&title="+t;
            break;
         case "digg":
            loc = "http://digg.com/submit?url="+u+"&title="+t;
            break;
         case "delicious":
            loc = "http://del.icio.us/post?url="+u+"&title="+t;
            break;
         case "google":
            loc = "http://www.google.com/bookmarks/mark?op=add&bkmk="+u+"&title="+t;
            break;
         case "facebook":
            loc = "http://www.facebook.com/sharer.php?u="+u;
            break;
        default:
            break;
    }
    obj.href=loc;
    return true;
}
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(uid);
      	}
    } 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(uid){
	if(checkIE()) {
		window.location='http://us.my.alibaba.com/mcweb/contact.htm?action=mcweb:contact_action&iframe_delete=true&req_page=feedback.init&domain=2&id=200502014';
	} 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&iframe_delete=true&req_page=feedback.init&domain=2&id=200502014";
		}
	}
}
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;
}