// ==UserScript==
// @name Taobao.com
// @author somh
// @ahmore@gmail.com
// @include http://*.taobao.com/*
// @ujs:modified 23:35 2010-12-25
// ==/UserScript==

window.opera.defineMagicFunction('newCheckWangWangInstalled',function (){return "cntaobao";})
window.opera.defineMagicFunction('newCheckAlitalkInstalled',function (){return "cnalichn";})
window.opera.defineMagicFunction('newCheckYahooInstalled',function (){return "chnyahoo";})
window.opera.defineMagicFunction('WangWangVerSupportedSMS',function (r,t,i){return false;})
window.opera.addEventListener('BeforeEvent.load',function (e) {
	if ( location.host!="ju.taobao.com" && e.event.target instanceof Document ) {e.preventDefault();}
},false);

document.addEventListener('load',fixButtons,true);
document.addEventListener('DOMContentLoaded',fixButtons,false);

function fixButtons(){
	var es=document.selectNodes("//span[@class='ww:token'] | //span[@class='J_WangWang'] | //span[@class='ww:token wwicon'] | //span[@class='ww-light ww-large']");
	var o; var wn; var wnt; var wg;
	for(var i=0;i<es.length;i++){
		try{
			if(es[i].firstChild.href&&es[i].className.indexOf("+")<0){
				o=es[i].getAttribute("ww:params")?es[i].getAttribute("ww:params").toQueryParams():"";
				wn=es[i].getAttribute("data-nick");wn=wn?wn:o.nick?o.nick:""; wnt=es[i].getAttribute("data-tnick");wnt=wnt?wnt:o.tnick?o.tnick:"";
				wg=es[i].getAttribute("data-item")?es[i].getAttribute("data-item"):""; wg=wg?wg:(document.bidForm)?document.bidForm.item_id.value:o.item?o.item:"";
				with(es[i].firstChild){
					href=decodeURIComponent("aliim:sendmsg?uid=cntaobao&siteid=cntaobao&status=1&nick="+wn+"&touid=cntaobao"+wn+"&uid_t="+wnt+"&status=1&gid="+wg);
					setAttribute("onclick","location.href=decodeURIComponent(this.href);"); target="_self";
					//href="wangwang:SendIM?"+para_seller+"&gid="+para_gid;	' for WangWang 5.x
				}
				es[i].className+=" +";
			}
		}catch(e){}
	}
}