var __downstr = '本地计算机可能未安装FastMsg客户端，单击“确定”下载客户端，单击“取消”直接进行网页会话。';
var __downurl = 'http://down.fastmsg.cn/team/client/demo_7_16_setup.exe';
var __localstart = 'fastmsg://startclient/?userid=';

/*-------------------------WebVisitorDialog---------------------------*/

function WebVisitorDialog(userid)
{
	var getContextPath = function() {
		var __jsfilename = "js/handler.js";
		var __rName = new RegExp(__jsfilename+"(\\?(.*))?$")
		var __jss=document.getElementsByTagName('script');
		for (var i = 0;i < __jss.length; i++){
		  var j = __jss[i];
		  if (j.src&&j.src.match(__rName)){
			var url = j.src;
			var pos = url.lastIndexOf(__jsfilename);
			return url.substr(0, pos)
		  }
		}
		return '';
	}

	var browserIsIE = function() 
	{
		var browser=navigator.appName 
		return (browser=="Microsoft Internet Explorer"); 
	};

	var browserIsIE6 = function() 
	{
		var browser=navigator.appName 
		var b_version=navigator.appVersion 
		var trim_Version=b_version.replace(/[ ]/g,""); 
		return (browser=="Microsoft Internet Explorer") && (trim_Version.indexOf("MSIE6.0") >= 0);  
	};

    var resetPos = function()
    {
		var theWidth = document.documentElement.clientWidth;
		var theHeight = document.documentElement.clientHeight;
		var left = (theWidth - parseInt(dialog.style.width)) / 2;
		var top = (theHeight - parseInt(dialog.style.height)) / 2;
		if(!isIe6) {  
			dialog.style.top = top + 'px';
			dialog.style.left = left + 'px';
		} else {   
			dialog.style.top = top + document.documentElement.scrollTop + 'px';
			dialog.style.left = left + document.documentElement.scrollLeft + 'px';
		}
    };

	this.drag = function(o)
	{
		var a="onmousemove",b="setCapture",c="releaseCapture",f="clientY",g="clientX",
		d=document,z=d.documentElement,x,y,t,l,w,h;o=d.getElementById(o);o.onmousedown=function(e)
		{e=e||event;x=e[g]-o.offsetLeft;y=e[f]-o.offsetTop;d[a]=function(e){e=e||event;t=e[f]-y;
		l=e[g]-x;w=z.clientWidth-o.offsetWidth;h=z.clientHeight-o.offsetHeight;l<0&&(l=0);
		t<0&&(t=0);l>w&&(l=w);t>h&&(t=h);with(o.style){top=t+"px";left=l+"px"}};
		d.onmouseup=function(){d[a]=null;o[c]&&o[c]()};o[b]&&o[b]();return false}
	};

    this.show = function()
    {
		if(!isShow) {
			dialog.style.display = "block";
			isShow = true;
		}
        resetPos();
    };

    this.hide = function()
    {
		if(isShow) {
			dialog.style.display = "none";
			isShow = false;
		}
    };

    this.close = function()
    {
		var obj = document.getElementById(dialogid);
		if (obj != undefined) document.body.removeChild(obj);
        isShow = false;
    };

	var http_path = getContextPath();

    var dialogid = 'webvisitordialog-' + WebVisitorDialog.__count; 
    var isShow = false;
    var isIe = browserIsIE();
    var isIe6 = browserIsIE6();
	var width = 420;
	var height = 350;

	var closebtnHtml = '<a id="webvisitordialog_closebtn" style="float:right;margin:0;padding:0;cursor:pointer;background-position:top;'+
		'width:17px;height:17px;background-image:url(' + http_path + 'images/close.png);background-repeat:no-repeat;"></a>';
    var barHtml = 
        '<div style="margin:0;padding:6px;min-height:17px;font-family:SimHei;font-size:13px;' +
		'background-color:#3e4247;cursor:move;color:#e1e1e1;">'+
		'<div id="webvisitordialog_title" style="float:left;margin:0;padding:1px;"></div>'+
		closebtnHtml+'</div>';
	var dialog = document.createElement("div");
    dialog.id = dialogid;
	dialog.style.margin = "0";
	dialog.style.padding = "1px";
	dialog.style.background = "#3e4247";
	dialog.style.width = width + "px";
	dialog.style.height = height + "px";
	dialog.style.position = "fixed";
	dialog.style.zIndex = 999999;
	dialog.style.display = 'none';
	dialog.innerHTML = barHtml+'<div class="content" style="margin:0;padding:0;background:#fff;width:'+width+'px;height:'+(height-29)+'px;">'+
		'<iframe style="margin:0;padding:0;width:100%;height:100%;border:0;" src="' + http_path + 'main.php?userid=' + userid + '" /></div>';
    document.body.appendChild(dialog);

	if(isIe6)
	{
		dialog.style.position = "absolute";
		resetPos();
		var top = parseInt(dialog.style.top) - document.documentElement.scrollTop;
		var left = parseInt(dialog.style.left) - document.documentElement.scrollLeft;
		window.onscroll = function(){
			dialog.style.top = document.documentElement.scrollTop + top + 'px';
			dialog.style.left = document.documentElement.scrollLeft + left + 'px';
		};
	}

	this.drag(dialogid);

	var aObj = document.getElementById("webvisitordialog_closebtn");
	if (window.addEventListener) {
		aObj.addEventListener('click', this.close, false);
		aObj.addEventListener('mouseover', function(){aObj.style.backgroundPosition = 'bottom';}, false);
		aObj.addEventListener('mouseout', function(){aObj.style.backgroundPosition = 'top';}, false);
	} else if (window.attachEvent) { 	
		aObj.attachEvent('onclick', this.close);
		aObj.attachEvent('onmouseover', function(){aObj.style.backgroundPosition = 'bottom';});
		aObj.attachEvent('onmouseout', function(){aObj.style.backgroundPosition = 'top';});
	}

    WebVisitorDialog.__count++;
}
WebVisitorDialog.__count = 1;

var g_WebVisitorDialog = null;

function openWebVisitorDialog(userid)
{
	if (g_WebVisitorDialog != null) {
		g_WebVisitorDialog.close();
		delete g_WebVisitorDialog;
		g_WebVisitorDialog = null;
	}
	g_WebVisitorDialog = new WebVisitorDialog(userid); 
	g_WebVisitorDialog.show();
}

function runWebVisitorScript(userid)
{
	openWebVisitorDialog(userid);
	return;//temp
	/*
	try{
		var obj = new ActiveXObject("WebIntf.Client");
		if (obj){
			delete obj;
			location.href = __localstart + userid;
		}
	}catch (e) {
		if ((__downstr != "") && (__downurl != "")) {
			if (window.confirm(decodeURIComponent(__downstr))) {
				location.href = decodeURIComponent(__downurl);
			} else {
				openWebVisitorDialog(userid);
			}
		} else {
			openWebVisitorDialog(userid);
		}
	}
	*/
}


