


var hostName = "messenger";
var presenceServlet = "http://messenger.100buy.com/plugins/presence/status";
var presenceImgPath = "http://messenger.100buy.com/webchat/images/presence/--IMAGE--.gif";

//°Ù³ÇµÇÂ¼Ò³Ãæ
//var loginUrl = "http://www.100buy.com/b2conline/MemberLogin.html";
var loginUrl = "http://www.100buy.com/login.htm";

/*
	º¯ÊýÃû³Æ£ºtrim
	º¯Êý¹¦ÄÜ: È¥³ý×Ö·û´®Í·²¿ºÍÎ²²¿µÄ¿Õ¸ñ
	´«Èë²ÎÊý£º×Ö·û´®±äÁ¿
	´«³ö½á¹û£º´¦ÀíºóµÄ×Ó´®
*/
function trimString(str){
	return str.replace(/(^\s*)|(\s*$)/g, "");
}

function openChatWndNew(uf,pwd,ut) {
	var theEvent = window.event || arguments[0];
	var theObject = theEvent.srcElement ? theEvent.srcElement : theEvent.target;
	if(theObject.tagName.toUpperCase() == "IMG") {
		theObject = theObject.parentNode;
	}
	
	if(trimString(theObject.uf) == "" && trimString(theObject.pwd) =="") {
		location.href = (loginUrl + "?targetUrl=" + encodeURIComponent(location.href));
		return;
	}
	//var url = "http://messenger.ec.com.cn/webchat" + "/app/app_login.jsp?uf=" + encodeURIComponent(theObject.uf) + "&p=" + theObject.pwd + "&ut=" +encodeURIComponent(theObject.ut) ;
	var url = "http://messenger.ec.com.cn/webchat" + "/app/app_login.jsp?uf=" + (theObject.uf) + "&p=" + theObject.pwd + "&ut=" +(theObject.ut) ;
	//alert( url );
  var defaultOptions = "location=no,status=no,toolbar=no,personalbar=no,menubar=no,directories=no,";
  defaultOptions += "resizable=yes,";
	window.open(url , "_blank" , defaultOptions);
}

function showUserPresence(spanId, uf, pwd, ut) {
	var objSpan = document.getElementById(spanId);
	//objSpan.setAttribute("onclick", "javascript:openChatWndNew('" + uf + "','" + pwd + "','" + ut + "');" );
	objSpan.style.cursor = "pointer";
	objSpan.uf = uf;
	objSpan.pwd = pwd;
	objSpan.ut = ut;
	objSpan.onclick = openChatWndNew;
	
	var objImg = createElement("img",null,objSpan);
	objImg.setAttribute("src", presenceServlet + "?jid=" + encodeURIComponent(ut + "@" + hostName) + "&type=image&images=" + presenceImgPath);

}

function createElement(type,id,parent)
{
    var el=null;
    if(document.createElementNS)
    {
        el=document.createElementNS("http://www.w3.org/1999/xhtml",type);
    }
    else
    {
        el=document.createElement(type);
    }
    if(typeof parent!="undefined")
    {
        parent.appendChild(el);
    }
    if(typeof id!="undefined")
    {
        el.id=id;
    }
    return el;
}


