var __SME_STATIC = {};
__SME_STATIC.ZH_CN = "zh_cn";
__SME_STATIC.EN_US = "en_us";
__SME_STATIC.NO = "n";
__SME_STATIC.YES = "y";
__SME_STATIC.F = "false";
__SME_STATIC.T = "true";

var __SME_PROBE_CUSTOM_PARAMS = null;

function __clear(timer) {
	clearTimeout(timer);
	clearInterval(timer);
	return null;
}

function __get_cookie_map(name) {
	var map = new Object();
	
	var cookie = document.cookie;
	var start = cookie.indexOf(name + "=");
	if (start >= 0) {
		start = start + name.length + 1;
		var end = cookie.indexOf(";", start);
		if (end < 0) {
			end = cookie.length;
		}
		
		var value = __unesc(cookie.substring(start, end));
		var pairs = value.split(";");
		for (var i = 0; i < pairs.length; i++) {
			var kv = pairs[i].split(/\s*=\s*/);
			if (kv.length == 2) {
				map[kv[0]] = __unesc(kv[1]);
			}
		}
	}
	
	return map;
}

function __save_cookie_map(map, name, domain, path, isPerm) {
	var s = "";
	for (var p in map) {
		s += p + "=" + __esc(map[p]) + ";";
	}
	
	if (s.length > 0) s.length--;
	
	var cookie = name + "=" + __esc(s) + "; domain=" + domain + "; path=" + path;
	if (isPerm) {
		cookie += "; expires=Sat, 1 Jan 2050 00:00:00 GMT";
	}
	
	document.cookie = cookie;
}

function __parse_int(value) {
	var iv = parseInt(value);
	return isNaN(iv) ? 0 : iv;
}

function __parse_float(value) {
	var fv = parseFloat(value);
	return isNaN(fv) ? 0 : fv;
}

function __esc(s) {
	return s == null ? "" : escape(s.toString());
}

function __unesc(s) {
	return s == null ? "" : unescape(s.toString());
}

function __attach_event(evt, callback) {
	if (window.addEventListener) {
		window.addEventListener(evt, callback, false); 
	} else if (window.attachEvent) {
		window.attachEvent("on" + evt, callback);
	}
}

function __detach_event(evt, callback) {
	if (window.removeEventListener) {
		window.removeEventListener(evt, callback, false); 
	} else if (window.detachEvent) {
		window.detachEvent("on" + evt, callback);
	}
}

function __do_request(reqId, url) {
	if (reqId != null) {
		var sc = document.getElementById(reqId);
		if (sc != null) {
			sc.parentNode.removeChild(sc);
		}
	}
	
	var sc = document.createElement("script");
	if (reqId != null) {
		sc.id = reqId;
	}
	
	sc.src = url;
	var headNode = document.getElementsByTagName('head')[0];
	headNode.insertBefore(sc, headNode.lastChild);
}

var __tips_closed = false;
function __open_win(winId, width, height, url, fallback, language, paramsObject) {

	if (__SME_PROBE_CUSTOM_PARAMS==null && 'undefined'!=paramsObject) {
		__SME_PROBE_CUSTOM_PARAMS = paramsObject;
	}

	var feature = "menubar=0,toolbar=0,status=0,resizable=0,width=" + width + ",height=" + height;
	var win = null;
	try {
		win = window.open(url, winId, feature);
	} catch (ex) {
	}
	if (win == null && fallback) {
		__remove_tips_block();
		__create_tips_block(winId, width, height, url, language);
		__attach_event("scroll", function() { __adjust_tips_block(winId, width, height, url, language); });
		__attach_event("resize", function() { __adjust_tips_block(winId, width, height, url, language); });
	}
	
	return win;
}

function __create_tips_block(winId, width, height, url, language) {
	if (document.getElementById("__parent_tips_block") && document.getElementById("__tips_block")) { return; }
	var spDiv = document.createElement("div");
	spDiv.id = "__parent_tips_block";
	var div = document.createElement("div");
	div.style.position = "absolute";
	div.id = "__tips_block";
	div.style.zIndex = 61345;
	div.style.width = 430;
	div.style.height = 160;
	div.style.left = (document.body.clientWidth - 495) / 2;
	div.style.top = 118;
	div.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=100)";
	
	var img1 = null;
	var img2 = null;
	var img3 = null;
	var img4 = null;
	if ("zh_cn" == language) {
		img1 = "http://cnimg.alisoft.com//images/probe/ww_alert_011.jpg";
		img2 = "http://cnimg.alisoft.com//images/probe/ww_alert_012.jpg"
		img3 = "http://cnimg.alisoft.com//images/probe/ww_alert_2.jpg";
		img4 = "http://cnimg.alisoft.com//images/probe/ww_alert_button.jpg";
	} else {
		img1 = "http://cnimg.alisoft.com//images/probe/ww_alert_011.jpg";
		img2 = "http://cnimg.alisoft.com//images/probe/ww_alert_012.jpg"
		img3 = "http://cnimg.alisoft.com//images/probe/ww_alert_2_eng.jpg";
		img4 = "http://cnimg.alisoft.com//images/probe/ww_alert_button_eng.jpg";
	}
	
	var content = [], i = 0;

	content[i++] = '<table width="430" height="160" border="0" cellpadding="0" cellspacing="0">';
	content[i++] = '<tr><td height="34" valign="bottom"><img src="' + img1 + '" width="386" height="34" alt="" /><img src="' + img2 + '" alt=""  style="cursor:hand" onclick="__close_tips_block()" width="44" height="34" border="0" />';
	content[i++] = '</td></tr><tr><td align="center" bgcolor="#FFFFFF" style="border-left:#999999 1px solid;border-right:#999999 1px solid;border-bottom:#999999 1px solid;" ><table width="100%" border="0" cellspacing="0" cellpadding="0">';
	content[i++] = '<tr><td width="100" rowspan="2" align="center" style="padding-left:25px;"><img src="' + __SME_PROBE_CUSTOM_PARAMS.invitePanelPic + '" width="100" height="100" />';
	content[i++] = '</td><td align="center" style="color:#333; font-size:14px; text-align:left; padding:0 10px 0 10px; line-height:180%; height:30px;font-family:Verdana, Arial, Helvetica, sans-serif;">' + __SME_PROBE_CUSTOM_PARAMS.inviteText + '</td>';
	content[i++] = '</tr><tr><td align="right" style="padding-right:20px;"><a href="#" target="_self"><img src="' + img4 + '" width="94" height="30"';
	content[i++] = ' onclick="if(__open_win(\''+ winId + '\', ' + width + ', ' + height + ', \''+ url + '\', false, \''+language+'\'))__close_tips_block()" border="0" />';
	content[i++] = '</a></td></tr></table></td></tr></table>';

	div.innerHTML = content.join("");
	spDiv.innerHTML = "<iframe style='position:absolute;z-index:61344;width:expression(this.nextSibling.offsetWidth);height:expression(this.nextSibling.offsetHeight);top:expression(this.nextSibling.offsetTop);left:expression(this.nextSibling.offsetLeft);' frameborder='0' scrolling='no'></iframe>";
	spDiv.appendChild(div);
	document.body.insertBefore(spDiv, document.body.firstChild);
}

function __adjust_tips_block(winId, width, height, url, language) {
	var tip_div = document.getElementById("__tips_block");
	if(!tip_div) {
		__create_tips_block(winId, width, height, url, language);
	}
	var obj = _get_scrollValue();
	tip_div.style.left =  obj.scrollLeftValue + (document.body.clientWidth - 495) / 2;
	tip_div.style.top =  obj.scrollTopValue + 118;
}

function __close_tips_block() {
	var div = document.getElementById("__parent_tips_block");
	if (div) {
		div.style.display = 'none';
	}
	__tips_closed = true;
}
function __remove_tips_block() {
	var div = document.getElementById("__parent_tips_block");
	if (div) {
		div.parentNode.removeChild(div);
	}
	__tips_closed = false;
}
function _get_scrollValue(){
	var scrollLeftValue = 0 ;
	var scrollTopValue = 0 ; 
	var obj = new Object();
	if (typeof window.pageYOffset != 'undefined') {
	  scrollLeftValue = window.pageXOffset;  
	  scrollTopValue = window.pageYOffset;  
	}  
	else if (typeof document.compatMode != 'undefined' &&  
		document.compatMode != 'BackCompat') { 
		scrollLeftValue = document.documentElement.scrollLeft;  
		scrollTopValue = document.documentElement.scrollTop;  
	}  
	else if (typeof document.body != 'undefined') { 
		scrollLeftValue = document.body.scrollLeft;  
		scrollTopValue = document.body.scrollTop;
	}else{
		scrollLeftValue = 0 ;
		scrollTopValue = 0 ; 
	}
	obj.scrollLeftValue = scrollLeftValue;
	obj.scrollTopValue = scrollTopValue;
	return obj;
}
function __auto_scroll(left, top, iconUrl, language, img) {
	var varDiv = document.getElementById("__service_panel");
	if(!varDiv) { 
		__create_service_panel(left, top, iconUrl, language, img);
		return ; 
	}
	var obj = _get_scrollValue(); 
	varDiv.style.left = left + obj.scrollLeftValue;
	varDiv.style.top = top + obj.scrollTopValue;

}
function __create_service_panel(left, top, iconUrl, language,img) {
	if (!document.getElementById("__service_panel")) {
		var spDiv = document.createElement("div");
		var div = document.createElement("div");
		div.id = "__service_panel";
		var obj = _get_scrollValue(); 
		div.style.left = left + obj.scrollLeftValue;
		div.style.top = top + obj.scrollTopValue;
		div.style.clear = "both";
		div.style.position = "absolute";
		div.style.zIndex = 62345;
		div.style.overflow = 'hidden';
		//div.innerHTML = "<img border='0' style='cursor:hand' src='+ iconUrl +' onclick='__launch_contact(\"visitor\", \""+language+"\", \""+img+"\")' />";
		div.innerHTML=__get_custom_panel_html(iconUrl, language, img);
		spDiv.innerHTML = "<iframe style='position:absolute;z-index:62344;width:expression(this.nextSibling.offsetWidth);height:expression(this.nextSibling.offsetHeight);top:expression(this.nextSibling.offsetTop);left:expression(this.nextSibling.offsetLeft);filter:Alpha(opacity=0);' frameborder='0' scrolling='no'></iframe>";
		spDiv.appendChild(div);
		document.body.insertBefore(spDiv, document.body.firstChild);
	}
}


function __get_custom_panel_html(iconUrl, language, img) {
	var tempHtmlCode = "";
	if (language==__SME_STATIC.ZH_CN) {
		tempHtmlCode = "<table width='144' border='0' cellpadding='0' cellspacing='0' style='line-height:16px;'>";
	} else {
		tempHtmlCode = "<table width='144' border='0' cellpadding='0' cellspacing='0' style='font-family:Verdana, Arial, Helvetica, sans-serif; line-height:14px;'><tr>";
	}
    var tempString1 = null;
	if (__SME_PROBE_CUSTOM_PARAMS.iconOrder == "-1") {
		tempString1 = "<td  style='height:128px; background:url(http://cnimg.alisoft.com//images/enet_custom.gif); text-align:center;'><a href='#' target='_self' style='margin:0'><img  onclick='__launch_contact(\"visitor\", \""+language+"\", \""+img+"\")'  style='cursor:hand' src='"+__SME_PROBE_CUSTOM_PARAMS.probeHeadPic+"' width='120' height='120' border='0' /></a></td></tr>";
	} else if (__SME_PROBE_CUSTOM_PARAMS.iconOrder == "0") {
		if ( language == __SME_STATIC.ZH_CN) {
			  tempString1 = "<td><a href='#' style='margin:0' target='_self'><img  onclick='__launch_contact(\"visitor\", \""+language+"\", \""+img+"\")' style='cursor:hand' src='http://cnimg.alisoft.com//images/enet_chn_s.gif' width='144' height='50' border='0' /></a></td></tr>";
		} else {
			  tempString1 = "<td><a href='#' style='margin:0' target='_self'><img  onclick='__launch_contact(\"visitor\", \""+language+"\", \""+img+"\")' style='cursor:hand' src='http://cnimg.alisoft.com//images/enet_eng_s.gif' width='144' height='50' border='0' /></a></td></tr>";
		}
	} else {
		var tempPicSrc = "";
		if (language==__SME_STATIC.ZH_CN) {
			tempPicSrc = "http://cnimg.alisoft.com//images/enet_chn_l_02.gif";
		} else {
			tempPicSrc = "http://cnimg.alisoft.com//images/enet_eng_l_02.gif";
		}
    	
		tempString1 = "<td style='background:url(http://cnimg.alisoft.com//images/enet_chn_l_01.gif) no-repeat; height:105px;'>";

		if (language==__SME_STATIC.ZH_CN) {
			tempString1 += "<div style='width:114px; height:43px; margin:15px 15px 1px; color:#333333; font-size:12px; line-height:14px; word-break:break-all;word-wrap: break-word; text-align:left;'>";
		} else {
			tempString1 += "<div style='width:114px; height:43px; margin:15px 15px 1px; color:#333333; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; font-weight:bold; line-height:12px; text-align:left;word-break:break-all;'>";
		}
           tempString1 +="" + __SME_PROBE_CUSTOM_PARAMS.probeHeadText + " </div>"
           +"<a href='#' style='margin:0' target='_self'><img onclick='__launch_contact(\"visitor\", \""+language+"\", \""+img+"\")' src='" + tempPicSrc + "' width='144' border='0' /></a></td></tr>";
    }
    tempHtmlCode += tempString1;
    
    if (__SME_PROBE_CUSTOM_PARAMS.hasProductClass==__SME_STATIC.NO) {
    	tempHtmlCode += "</table>";
    } else {
    	tempHtmlCode += "<tr><td style='background:url(http://cnimg.alisoft.com//images/e_net_1_02.png) no-repeat bottom;'>";
		if (language==__SME_STATIC.ZH_CN) {
			tempHtmlCode +="<div style='width:22px; float:left;  margin-left:10px; display:inline;'><img src='http://cnimg.alisoft.com//images/enet_chn_nav.gif'></div>";
			tempHtmlCode += "<ul style='width:75px; height:auto!important; height:80px; min-height:80px; float:left; font-size:12px; text-align:left; margin:10px 12px; list-style:none; padding:0;'>";
		} else {
			tempHtmlCode += "<div style='width:22px; float:left; margin-left:10px; display:inline;'><img src='http://cnimg.alisoft.com//images/enet_eng_nav.gif'></div>"
			tempHtmlCode += "<ul style='width:75px; height:auto!important; height:80px; min-height:80px; float:left; font-size:12px; text-align:left; margin:10px 12px; list-style:none; padding:0;'>";
		}
    	tempHtmlCode += __SME_PROBE_CUSTOM_PARAMS.productLabels+"</ul></td></tr>";
    }
	
	return tempHtmlCode;
}


function __show_service_panel(left, top, iconUrl, language, img, paramsObject) {
	__SME_PROBE_CUSTOM_PARAMS = paramsObject;
	__create_service_panel(left, top, iconUrl, language, img);
	
	if (__SME_PROBE_CUSTOM_PARAMS.isScrollable == __SME_STATIC.YES) {
		__attach_event("scroll", function() { __auto_scroll(left, top, iconUrl, language, img); });
		__attach_event("resize", function() { __auto_scroll(left, top, iconUrl, language, img); });
		window.setTimeout("__create_service_panel("+left+", "+top+", '"+iconUrl+"', '"+language+"', '"+img+"')", 3000);
	}

	
	
}

function __detect_im() {
	return null;// TODO
	try {
		var im = new ActiveXObject("AlitalkSetup.Install");
		if (im != null) {
			delete im;
			return "Alitalk";
		}
	} catch (e) { }
	
	try {
		var im = new ActiveXObject("WangWangX.WangWangObj");
		if (im != null) {
			delete im;
			return "WangWang";
		}
	} catch (e) { }
	return null;
}

function __open_im(im, to) {
	var url;
	if (im == "Alitalk") {
		url = im + ":SendIM?" + to.substring(8);
	} else {
		url = im + ":SendIM?tositeid=cnalichn&uid=" + to.substring(8);	
	}
	
	__open_iframe("__iframe_im", url);
}

function __open_iframe(frmId, url) {
	var frm = document.getElementById(frmId);
	if (frm == null) {
		frm = document.createElement("iframe");
		frm.id = frmId;
		frm.style.display = "none";
		document.body.appendChild(frm);
	}
	
	frm.src = url;
}
function _subStringUrl(varUrl){
		if(varUrl!=null&&varUrl.indexOf("http://")>-1){
			varUrl =  varUrl.substring(varUrl.indexOf("http://")+7,varUrl.length-1);
			if(varUrl.indexOf("/")>-1)return varUrl.substring(0,varUrl.indexOf("/"));
			else if(varUrl.indexOf("\\")>-1)return varUrl.substring(0,varUrl.indexOf("\\"));
			else return varUrl;
		}
		else return varUrl;
}
function _subStringTitle(titleStr,strNum){
	if(titleStr==null||titleStr.length==0)return "";
	else if(titleStr.length>strNum) return titleStr.substring(0,strNum);
	else return titleStr;
}
var __COOKIE_PERM = "__ENET_PERM";
var __COOKIE_TMP = "__ENET_TMP";

var __C_P_USER = "user";
var __C_P_VISIT_COUNT = "visit_count";
var __C_P_STAY_TIME = "stay_time";
var __C_P_LAST_CONTACT = "last_contact";

var __C_T_PAGES = "pages";
var __C_T_CONTACT_FLAGS = "contact_flags";
var __C_T_SESSION_START = "session_start";
var __C_T_STAY_TIME = "stay_time";

var __F_RULE_TRIGGERED = 0x01;
var __C_T_RULED_FLAGS = 0x01;

if (window.ActiveXObject) var __IE = window[window.XMLHttpRequest ? 'ie7' : 'ie6'] = true;
function __domReady(fn) {
	if (__domReady.done){
		fn.call(this);
		return;
	}
	if (document.readyState && __IE){
		if (!document.getElementById('ie_ready')){
			var src = (window.location.protocol == 'https:') ? '://0' : 'javascript:void(0)';
			document.write('<script id="ie_ready" defer src="' + src + '"><\/script>');
			document.getElementById('ie_ready').onreadystatechange = function(){
				if (this.readyState == 'complete') {
					__domReady.done = true;
					__domReady(fn);
				}
			};
		}
	} else {
		__attach_event("load", function () { __domReady.done = true; __domReady(fn); });
		__attach_event("DOMContentLoaded", function () { __domReady.done = true; __domReady(fn); });
	}
}
/**
  * site, The ID of the company.
  * language, The language version of WebIm.
  * img, The img url at the top right of WebIm.
  */
function __launch_probe(site, language) {
	__domReady(function() {
		var url = "http://cn.alisoft.com/sme/probe/probe.jspa?site=" + site;
		var user = __get_cookie_map(__COOKIE_PERM)[__C_P_USER];
		if (user) {
			url += "&user=" + user;
		} else {
			url += "&ts=" + new Date().getTime();
		}
		url+="&img=0&requestDomain="+encodeURIComponent(document.domain) + "&lang=" + (language==null?"zh_cn":language);
		__do_request(null, url);
	});
}