TTMflashReady = function () {
    gWizard.flashReady();
};

function getURLParam(strParamName) {
	var strReturn = "";
	var strHref = window.location.href;
	if (strHref.indexOf("?") > -1 ) {
		var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
		var aQueryString = strQueryString.split("&");
		for(var i = 0; i < aQueryString.length; i++ ) {
			if (aQueryString[i].indexOf(strParamName + "=") > -1 ) {
				var aParam = aQueryString[i].split("=");
				strReturn = aParam[1];
				break;
			}
		}
	}
	return strReturn;
}
function lTrim(str) {
    return str.replace(/(^\s*)/g, "");
}

var ttmApp = {};
ttmApp.wizardMgr = function () {
    this.m_ttmTitle = "我的聊窗";
    this.m_ttmNick = "我";
    this.m_bNewUser = true;
    this.m_widgetW = 190;
    this.m_widgetH = 275;
    this.m_imtataId = "";
    this.m_pass = "";
    this.m_email = "";
    this.m_ttmid = "";
    this.m_rand = 100;
    this.bgColor;
    this.ttColor;
    this.ttbColor;
    this.tbColor;
    this.m_advancedElem = null;
    this.m_advancedToggleElem = null;
    this.m_flashElem;
    this.m_colorPicker = null;
    this.m_bLoadedColorPicker = false;
    this.m_nextBtn;
    this.m_previousBtn;
    this.m_an1Img;
    this.m_an2Img;
    this.m_an3Img;
    this.m_updateUserName;
    this.m_updateSessionID;
    this.m_updateWid;
    this.m_fromWid;
    this.m_curRootUrl;//当前页面的URL，包含协议和主机名和路径名，不含页面名
    this.m_seccode;
    this.sessionIDType;
     this.presets = {         //background          //titlebar                                 //textbackground      //titletext
          "me":["DBDBDC", "#F3F4F6", "#F7F7F9", "#F3F4F6", "#DDDDDD", "#CCCCCC", "#F3F4F6", "#FFFFFF", "#FFFFFF", "#66667E", "#000000"],
          "webim":["BCD2EA", "#f6f6f6", "#F7F7F9", "#CCE0F6", "#9EBFDF", "#9EBFDF", "#EEEFE5", "#FFFFFF", "#FFFFFF", "#03468f", "#000000"],
          "veggie":["BDD99E", "#F3FFEA", "#D9F0DB", "#55AA00", "#80DA3B", "#80DA3B", "#F3FFEA", "#FFFFFF", "#FFFFFF", "#005500", "#000000"],
       "pink girl":["FFACD9", "#FFF3F8", "#F7F7F9", "#FFADDA", "#FFE4F0", "#FF90E4", "#FFF3F8", "#FFFFFF", "#FFFFFF", "#d5009f", "#000000"],
             "mac":["989A95", "#C5C5C5", "#F7F7F9", "#858585", "#BABABA", "#989898", "#C5C5C5", "#FFFFFF", "#FFFFFF", "#dadada", "#000000"],
              "xp":["989A95", "#efefef", "#F7F7F9", "#007BD7", "#00A4FC", "#0080DB", "#EBE8D7", "#FFFFFF", "#FFFFFF", "#ffffff", "#000000"],
       "pink punk":["FF90E4", "#ffd5ea", "#F7F7F9", "#d5009f", "#FF90E4", "#FF2DCF", "#FFC9F3", "#FFFFFF", "#FFFFFF", "#ffd5f4", "#000000"],
           "grape":["C2C4B8", "#dfd5ff", "#F7F7F9", "#b000aa", "#8180C1", "#4E4E96", "#F3F6E9", "#FFFFFF", "#FFFFFF", "#dfd5ff", "#000000"],
           "black":["505050", "#787878", "#F7F7F9", "#515151", "#787878", "#787878", "#787878", "#FFFFFF", "#FFFFFF", "#CCCCCC", "#000000"]
           };

    this.demotext = {"pink girl":"我是粉红女郎！", "mac":"苹果麦金塔，技术与艺术的结合！", "xp":"我爱盖茨，我爱XP！", "grape":"吃葡萄不吐葡萄皮!", "black":"黑夜给了我黑色的眼睛。", "veggie":"春天来了，满眼都是绿色！", "me":"me我，给你沟通的惊喜！", "webim":"随时随地随沟通！", "pink punk":"很好，就是这种颜色"};
    this.m_version;
    this.checkMode = function(){
        index = window.location.pathname.lastIndexOf("/");
        this.m_curRootUrl = "http://"+window.location.host+window.location.pathname.substring(0,index);
        //imtata页面调转到此处,修改tatame配置
        this.m_updateUserName = getURLParam("username");
        this.m_updateSessionID = getURLParam("sessionid");
        this.m_updateWid = getURLParam("wid");
        //flash窗口链接跳转到此处,创建新窗口
        this.m_fromWid = getURLParam("fromwid");
        this.sessionIDType = getURLParam("idtype");

        if(this.m_updateUserName&&this.m_updateSessionID&&this.m_updateWid){
            var titletext = $("titletext");
            if(titletext&&titletext.hasChildNodes){
                titletext.removeChild(titletext.firstChild);
                var textnode = document.createTextNode("修改你的meeboMe聊窗设置");
			    titletext.appendChild(textnode);
            }
            titletext = $("firststeptext");
            if(titletext&&titletext.hasChildNodes){
                titletext.removeChild(titletext.firstChild);
                var textnode = document.createTextNode("定制您的聊窗风格");
			    titletext.appendChild(textnode);
            }

            titleCtl = $("an1img");
            if (titleCtl) titleCtl.style.display = "none";
            titleCtl = $("an2img");
            if (titleCtl) titleCtl.style.display = "none";
            titleCtl = $("an3img");
            if (titleCtl) titleCtl.style.display = "none";
            titleCtl = $("previousstep");
            if (titleCtl) titleCtl.style.display = "none";
            titleCtl = $("nextImg");
            if (titleCtl)
                titleCtl.src = "skin/default/img/an_queren.jpg";

            this.loadSettingFromServer();
        }
        else{
           createFlash($("ttmembed"), "preview", this.m_curRootUrl+"/me.swf", "meflash", 190, 275);
        }
    }
    this.loadSettingFromServer = function(){
        gAjax.invoke(this.m_curRootUrl+"/../func/getmejson.php?wid="+this.m_updateWid,"text",this.handleSettingFromServer);
        //alert(settingData);
    }
    _this = this;
    this.handleSettingFromServer  = function(responseText){
        var settingData = eval('(' + responseText + ')');
        if(settingData.title){
            var titleCtl = $("ttm_title");
            if (titleCtl)  titleCtl.value = settingData.title;

            titleCtl = $("ttm_nick");
            if (titleCtl) titleCtl.value = settingData.nick;

            if(settingData.width=="160" && settingData.height=="250"){
                titleCtl = $("r1");
                if(titleCtl) titleCtl.checked = true;
            }else if(settingData.width=="190" && settingData.height=="275"){
                titleCtl = $("r2");
                if(titleCtl)  titleCtl.checked = true;
            }
            else{
                titleCtl = $("r3");
                if (titleCtl) titleCtl.checked = true;
                titleCtl = $("szWidth");
                if(titleCtl) titleCtl.value = settingData.width;
                titleCtl = $("szHeight");
                if(titleCtl) titleCtl.value = settingData.height;
            }
            _this.bgColor = "#"+settingData.bgcolor;
            _this.ttColor = "#"+settingData.ttcolor;
            _this.ttbColor = "#"+settingData.tbcolor;
            _this.tbColor = "#"+settingData.txtacolor;
            createFlash($("ttmembed"), "preview", _this.m_curRootUrl+"/me.swf", "meflash", parseInt(settingData.width), parseInt(settingData.height));
        } else{
            createFlash($("ttmembed"), "preview", _this.m_curRootUrl+"/me.swf", "meflash", 190, 275);
        }
    }
    this.loadReg1 = function () {
        this.m_advancedElem = $("advancedcolors");
        this.m_advancedToggleElem = $("advancedtoggle");
        this.setupFlashEmbed();
        this.m_nextBtn = $("nextstep");
        this.m_previousBtn = $("previousstep");
        this.m_an1Img = $("an1img");
        this.m_an2Img = $("an2img");
        this.m_an3Img = $("an3img");
        this.loadPreset("imtata");
    };
    this.loadPreset = function (_3ee) {
        var skin = this.presets[_3ee];
        if (skin) {
            this.bgColor = skin[1];
            this.ttColor = skin[9];
            this.ttbColor = skin[3];
            this.tbColor = skin[7];
        } else{
            this.bgColor = "#f6f6f6";
            this.ttColor = "#03468f";
            this.ttbColor = "#CCE0F6";
            this.tbColor = "#FFFFFF";
        }
        if(this.m_flashElem){
            this.m_flashElem.changeSkinColor(this.bgColor,this.ttColor,this.ttbColor,this.tbColor);
            this.updateWidgetTitle();
            this.updateWidgetAlias();
            if (this.demotext[_3ee]) {
                 this.m_flashElem.changeTipText(this.demotext[_3ee]);
            }
        }
    };
    this.clearError = function (errorrow) {
        this.doError(errorrow,"");
    };
    this.doError = function (errorrow,errMsg) {
        var row = document.getElementById(errorrow);
        if (row) {
            row.innerHTML = replaceHTML(errMsg);
        }
        this.m_sessionKey = "";
    };
    this.setColor = function (_3f0, rgb, _3f2) {
        rgbValue = rgb;
        if (rgb != "" && rgb.length >= 6) {
            rgbValue = rgb.substr(rgb.length - 6, 6);
            var _3f3 = "0x" + rgbValue;
        }

        if (_3f3 ) {
            switch(_3f0){
				case "bfc":
				    if(this.m_flashElem)
					    this.m_flashElem.changeBackgndColor(_3f3);
					this.bgColor = "#"+rgbValue;
					break;
				case "tbtc":
				    if(this.m_flashElem)
				        this.m_flashElem.changeTitleTextColor(_3f3);
				    this.ttColor =  "#"+rgbValue;
					break;
				case "tbc2":
				    if(this.m_flashElem)
				        this.m_flashElem.changeTitleBarColor(_3f3);
				    this.ttbColor =  "#"+rgbValue;
					break;
				case "hbfc":
				    if(this.m_flashElem)
				        this.m_flashElem.changeTextBackgndColor(_3f3);
				    this.tbColor = "#"+rgbValue;
					break;
				default:
					break;
			}

			if(rgb[0]=='#')
			    rgbColor = rgb.substr();

            var _3f4 = $(_3f0 + "_cb");
            if (_3f4) {
                 _3f4.style.backgroundColor = rgbValue;
            }
        }
        if (_3f2 == null || !_3f2) {
            this.checkSpecialColors(_3f0, rgb);
        }
    };
    this.checkSpecialColors = function (_3f5, rgb) {
        if (_3f5 == "hbfc") {
            this.setColor("ibfc", rgb);
        } else {
            if (_3f5 == "tbc2") {
                this.setColor("tbc3", this.darkenRGB(rgb, -20, true));
                this.setColor("tbc", this.presets["me"][2]);
                this.setColor("tbc4", this.presets["me"][5]);
            } else {
                if (_3f5 == "bfc") {
                    this.setColor("sbfc", rgb);
                    this.setColor("blc", this.darkenRGB(rgb, 20, true));
                } else {
                    if (_3f5 == "dtc") {
                        //this.clearDemoText();
                        //this.m_flashElem.changeTipText("and here's me chatting it up imtata style");
                    }
                }
            }
        }
    };
    this.darkenRGB = function (rgb, _3f8, _3f9) {
        var r = parseInt(rgb.substr(0, 2), 16) - _3f8;
        var g = parseInt(rgb.substr(2, 2), 16) - _3f8;
        var b = parseInt(rgb.substr(4, 2), 16) - _3f8;
        if (r < 0) {
            r = _3f9 ? -r : 0;
        }
        if (g < 0) {
            g = _3f9 ? -g : 0;
        }
        if (b < 0) {
            b = _3f9 ? -b : 0;
        }
        if (r > 255) {
            r = _3f9 ? (510 - r) : 255;
        }
        if (g > 255) {
            g = _3f9 ? (510 - g) : 255;
        }
        if (b > 255) {
            b = _3f9 ? (510 - b) : 255;
        }
        var _3fd = pad(decToHex(r), 2) + pad(decToHex(g), 2) + pad(decToHex(r), 2);
        return _3fd;
    };
    this.leaveStep1 = function()
    {
       var _437 = this.isValidWidgetName("ttm_title");
       var _438 = this.isValidWidgetName("ttm_nick");
       if (_437 || _438) {
            this.doError("errorrow1",(_437 ? _437 + "\n" : "") + (_438 ? _438 + "\n" : ""));
            return;
        }
        var _439 = document.getElementById("ttm_title");
        if (_439) {
            //alert("ttmTitle="+_439.value);
            gWizard.m_ttmTitle = _439.value;
        }
        var _43a = $("ttm_nick");
        if (_43a) {
            gWizard.m_ttmNick = _43a.value;
        }
        var r1 = document.getElementById("r1");
        if (r1 && r1.checked) {
            this.m_widgetW = 160;
            this.m_widgetH = 250;
        }
        var r2 = document.getElementById("r2");
        if (r2 && r2.checked) {
            this.m_widgetW = 190;
            this.m_widgetH = 275;
        }
        var r3 = document.getElementById("r3");
        if (r3 && r3.checked) {
            var r3_w = $("szWidth");
            var r3_h = $("szHeight");
            if (r3_w && r3_w.value && r3_h && r3_h.value) {
                var n = 0;
                for (n = 0; n < r3_w.value.length; n++) {
                    if (!isdigit(r3_w.value.charAt(n))) {
                        this.doError("errorrow1","请输入一个有效的宽度.");
                        return;
                    }
                }
                for (n = 0; n < r3_h.value.length; n++) {
                    if (!isdigit(r3_h.value.charAt(n))) {
                        this.doError("errorrow1","请输入一个有效的高度.");
                        return;
                    }
                }
                this.m_widgetW = r3_w.value;
                this.m_widgetH = r3_h.value;
            } else {
                this.doError("errorrow1","请输入一个有效的宽度和高度.");
                return;
            }
        }
        this.clearError();

        if(this.m_updateUserName&&this.m_updateSessionID&&this.m_updateWid){
            if(!this.invokeUpdate())
                return;
            this.enterStep3();
            var step1Div = $("step1");
            var step3Div = $("step3");
            step1Div.style.display = "none";
            step3Div.style.display = "block";
        }
        else{
            var step1Div = $("step1");
            var step2Div = $("step2");
            step1Div.style.display = "none";
            step2Div.style.display = "block";
            document.getElementById("nimtataid").focus();
            this.m_nextBtn.href = "#";
            this.m_nextBtn.onclick = function(){ gWizard.leaveStep2();return false; };
            this.m_previousBtn.href = "#";
            this.m_previousBtn.onclick = function(){ gWizard.returnStep1();return false;};
            //this.m_previousBtn.style.visibility = "visible";
            this.m_an1Img.src = "skin/default/img/an1_cheng.gif";
            this.m_an2Img.src = "skin/default/img/an2_hong.gif";
            var previousImg = $("previousImg");
            previousImg.src = "skin/default/img/an_home.gif";
            this.refreshSeccode();
        }
    }
    this.returnStep1 = function()
    {
        var step1Div = $("step1");
        var step2Div = $("step2");
        step2Div.style.display = "none";
        step1Div.style.display = "block";
        this.m_nextBtn.onclick = function(){ gWizard.leaveStep1();return false; };
        this.m_nextBtn.style.visibility = "visible";
        this.m_previousBtn.style.visibility = "visible";
        this.m_previousBtn.removeAttribute("href");
        this.m_previousBtn.removeAttribute("onclick");
        this.m_an1Img.src = "skin/default/img/an1_hong.gif";
        this.m_an2Img.src = "skin/default/img/an2_hui.gif";
        this.m_an3Img.src = "skin/default/img/an3_hui.gif";
        var previousImg = $("previousImg");
        previousImg.src = "skin/default/img/an_home_hui.gif";
    }
    this.leaveStep2 = function () {
        this.unhighlightFields();
        //this.showWait(true, gLang.oneMoment);
        var _4a1 = this.validateReg2();
        if (_4a1) {
            //this.showWait(false);
            var step2Div = $("step2");
            var step3Div = $("step3");
            step2Div.style.display = "none";
            step3Div.style.display = "block";
            this.enterStep3();
        }
        return false;
    };
    this.enterStep3 = function () {
        //this.doError("errorrow3",this.m_ttmid);
        if(this.m_updateUserName&&this.m_updateSessionID&&this.m_updateWid){
            var successtext = $("success_text");
            if(successtext&&successtext.hasChildNodes){
                successtext.removeChild(successtext.firstChild);
                var textnode = document.createTextNode("修改meeboMe配置成功！下面是您所需要的代码：");
			    successtext.appendChild(textnode);
            }
        }
        var codeArea = $("codearea");
        var jsUrl = this.m_curRootUrl + "/script/checkflash.js";
        flashUrl = this.m_curRootUrl+"/me.swf?wid=" + this.m_ttmid;

        if(codeArea)
          //codeArea.value = "<script src=\""+ jsUrl + "\" type=\"text/javascript\"></script>"+
          codeArea.value = "<embed src=\"" + flashUrl + "\" type=\"application/x-shockwave-flash\"  width=\"" +  this.m_widgetW + "\" height=\"" + this.m_widgetH + "\" allowScriptAccess=\"always\"></embed>";
        codeArea.onmouseup = function (ev)
        {
           codeArea.select();
        };
        this.m_previousBtn.style.visibility = "hidden";
        this.m_nextBtn.style.visibility = "hidden";
        this.m_an1Img.src = "skin/default/img/an1_cheng.gif";
        this.m_an2Img.src = "skin/default/img/an2_cheng.gif";
        this.m_an3Img.src = "skin/default/img/an3_hong.gif";

        var bindEmailFrame = document.createElement("iframe");
		if(!bindEmailFrame) return;
		/*bindEmailFrame.setAttribute("src", "bindemail.html");
		bindEmailFrame.setAttribute("frameborder", 0);
		bindEmailFrame.setAttribute("width", 511);
		bindEmailFrame.setAttribute("height", 160);
		bindEmailFrame.setAttribute("marginwidth", 0);
		bindEmailFrame.setAttribute("marginheight", 0);
		bindEmailFrame.setAttribute("scrolling", "no");*/
		bindEmailFrame.src = "bindemail.html?wid="+this.m_ttmid+"&userid="+this.m_imtataId;
		bindEmailFrame.frameBorder = 0;
		bindEmailFrame.width = 511;
		bindEmailFrame.height = 167;
		bindEmailFrame.marginWidth = 0;
		bindEmailFrame.marginHeight = 0;
		bindEmailFrame.scrolling = "no";
		$("codetd").appendChild(bindEmailFrame);
    }
    this.highlightField = function (id) {
        this.unhighlightFields();
        var f = document.getElementById(id);
        if (f) {
            f.style.backgroundColor = "#FFC1C1";
            f.select();
        }
    };
    this.unhighlightFields = function () {
        var _474 = document.getElementsByTagName("input");
        for (var i = 0; i < _474.length; i++) {
            _474[i].style.backgroundColor = "transparent";
        }
    };
    this.onReg2KeyPress = function (ev, el) {
        if (!ev) {
            ev = window.event;
        }
        if (ev.keyCode == 13) {
            this.leaveStep2();
            return false;
        }
        if (ev.keyCode == 9 && el && el.id == "pass") {
            var next = document.getElementById("next");
            if (next && next.select) {
                next.select();
            }
            return false;
        }
        return true;
    };
    this.validateReg2 = function () {
        var errMsg = "";
        var ctlId = "";
        var imttid = document.getElementById("imtataid");
        var ttpass = document.getElementById("pass");
        if (imttid && ttpass && (imttid.value || ttpass.value)) {
            errMsg = this.isValidImtataId("imtataid");
            ctlId = "imtataid";
            if (!errMsg) {
                errMsg = this.isValidPassword("pass");
                if (errMsg) {
                    errMsg.replace("new", "");
                }
                ctlId = "pass";
            }
            if (!errMsg) {
                return this.loginUser(false);

            } else {
                if (!getValue("nimtataid") && !getValue("email") && !getValue("npass") && !getValue("ncpass")) {
                    this.doError("errorrow2",errMsg);
                    this.highlightField(ctlId);
                    return false;
                }
            }
        }
        var errMsg = this.isValidImtataId("nimtataid");
        if (errMsg) {
            ctlId = "nimtataid";
        }
        if (!errMsg) {
            errMsg = this.isValidEmail("email");
            ctlId = "email";
        }
        if (!errMsg) {
            errMsg = this.isValidPassword("npass");
            ctlId = "npass";
        }
        if (!errMsg) {
            errMsg = this.isValidConfirmPassword("ncpass", "npass");
            ctlId = "ncpass";
        }
        if (!errMsg) {
            errMsg = this.isValidSeccode("seccodeverify");
            ctlId = "seccodeverify";
        }
        if (errMsg) {
            this.highlightField(ctlId);
            this.doError("errorrow2",errMsg);
            return false;
        }
        return this.loginUser(true);
        //return true;
    };
    this.refreshSeccode = function(){
        $('seccode').src = '../func/getseccodeimg.php?update=' + Math.random()
    };
    this.invokeUpdate = function () {

        var updateUrl = this.m_curRootUrl+"/../func/updateme.php?imtataid="+this.m_updateUserName+"&sessionid="+this.m_updateSessionID+"&wid="+this.m_updateWid;
        updateUrl += "&ttmTitle="+ encodeURIComponent(this.m_ttmTitle);
        updateUrl += "&ttmNick=" + encodeURIComponent(this.m_ttmNick);
        updateUrl += "&ttmWidth=" + this.m_widgetW;
        updateUrl += "&ttmHeight=" + this.m_widgetH;
        updateUrl += "&bgColor=" + this.getRealColor(this.bgColor);
        updateUrl += "&ttColor=" + this.getRealColor(this.ttColor);
        updateUrl += "&ttbColor=" + this.getRealColor(this.ttbColor);
        updateUrl += "&tbColor=" + this.getRealColor(this.tbColor);
        if(this.sessionIDType)
            updateUrl += "&sessionidtype=" + this.sessionIDType;
        updateUrl += "&rand=" + Math.random();
        //alert(loginUrl);

        var result = gAjax.invoke(updateUrl,"text");

        var ctlId;
        if(result=="-1")
            this.doError("errorrow1",gLang.serverError);
        else if(result == "-6"){
            this.doError("errorrow1",gLang.tatanotlogin);
        }
        else if(result == "-4"){
            //this.returnStep1();
            ctlId = "ttm_title";
            //titleCtl.focus();
            this.doError("errorrow1",gLang.titleExist);
        }
        else if(result == "-7"){
            this.doError("errorrow1",gLang.invalidUpdateParam);
        }
        else
        {
            this.m_ttmid = result;
            return true;
        };
        this.highlightField(ctlId);
        return false;
    }
    this.getRealColor = function(colorValue) {
        return colorValue.charAt(0)=='#'?colorValue.substring(1):colorValue;
    }
    this.loginUser = function (bCreateNewTataAccount) {
        this.m_bNewUser = false;
        var  loginUrl;
        //var encryPass = rsaEncrypt(this.m_pass);
        var md5Pass = hex_md5(this.m_pass);
        if(bCreateNewTataAccount)
            //loginUrl = this.m_curRootUrl+"/../func/createme.php?imtataid="+this.m_imtataId+"&pass="+encryPass+"&email="+this.m_email+"&md5pass="+md5Pass;
            loginUrl = this.m_curRootUrl+"/../func/createme.php?imtataid="+this.m_imtataId+"&email="+this.m_email+"&md5pass="+md5Pass;
        else
            //loginUrl = this.m_curRootUrl+"/../func/createme.php?imtataid="+this.m_imtataId+"&pass="+encryPass;
            loginUrl = this.m_curRootUrl+"/../func/createme.php?imtataid="+this.m_imtataId+"&md5pass="+md5Pass;

        getClientId();

        loginUrl += "&ttmTitle="+ encodeURIComponent(this.m_ttmTitle);
        loginUrl += "&ttmNick=" + encodeURIComponent(this.m_ttmNick);
        loginUrl += "&ttmWidth=" + this.m_widgetW;
        loginUrl += "&ttmHeight=" + this.m_widgetH;
        loginUrl += "&bgColor=" + this.getRealColor(this.bgColor);
        loginUrl += "&ttColor=" + this.getRealColor(this.ttColor);
        loginUrl += "&ttbColor=" + this.getRealColor(this.ttbColor);
        loginUrl += "&tbColor=" + this.getRealColor(this.tbColor);
        loginUrl += "&seccodeverify=" + this.m_seccode;
        if(this.m_fromWid)
            loginUrl += "&fromwid=" + this.m_fromWid;
        loginUrl += "&rand=" + Math.random();
        //alert(loginUrl);

        var result = gAjax.invoke(loginUrl,"text");

        if(result<0){
            $('seccodeverify').value = "";
           this.refreshSeccode();
        }
        var ctlId;
        if(result=="-1")
           this.doError("errorrow2",gLang.serverError);
        else if(result == "-2"){
            ctlId = "imtataid";
            this.doError("errorrow2",gLang.serverNoUser);
        }
        else if(result == "-3"){
            this.doError("errorrow2",gLang.serverErrPass);
            ctlId = "pass";
        }
        else if(result == "-4"){
            this.returnStep1();
            ctlId = "ttm_title";
            //titleCtl.focus();
            this.doError("errorrow1",gLang.titleExist);
        }
        else if(result == "-5"){
            ctlId = "nimtataid";
            this.doError("errorrow2",gLang.tataAcountExist);
        }
        else if(result == "-6"){
            ctlId = "seccodeverify";
            this.doError("errorrow2",gLang.seccodeError);
        }
        else if(result == "-7"){
            this.doError("errorrow2",gLang.serverErrPass);
            ctlId = "pass";
        }
        else
        {
            this.m_ttmid = result;
            return true;
        };
        this.highlightField(ctlId);
        //var timeoutfunc = "this.highlightField(" + ctlId + ")";
        //直接调用highlightField可能会失败
        //setTimeout(timeoutfunc,300);

        return false;

        //this.doRequest("login", _485, "gWizard.callbackLogin", false, true);
    };

    this.showColorPicker = function (elem, _403) {
        if (!this.m_advancedElem) {
            return;
        }
        this.m_colorTarget = elem;
        var _404 = getElementPosition(elem);
        this.m_colorPicker.show(false);
        this.m_colorPicker.setPos((_404.left + Math.round(3 * elem.offsetWidth / 4)), _404.top + Math.round(3 * elem.offsetHeight / 4));
        this.m_colorPicker.setCurrentColor(elem.rgbvalue);
        var obj = this;
        this.m_colorPicker.setHighlightCallback(function (rgb) {
            obj.setColor(_403, rgb);
        });
        this.m_colorPicker.setCallback(function (rgb) {
            obj.setColor(_403, rgb);
        });
        this.m_colorPicker.show(true);
    };
    this.toggleAdvancedColors = function(){
        if (!this.m_advancedElem) {
            return;
        }
        this.m_advancedElem.style.display = this.m_bShowAdvanced ? "none" : "block";
        this.m_bShowAdvanced = !this.m_bShowAdvanced;
        if (!this.m_bShowAdvanced) {
            //this.setWidgetSize(this.m_widgetW, this.m_widgetH);
        }
        if (this.m_advancedToggleElem) {
            this.m_advancedToggleElem.innerHTML = this.m_bShowAdvanced ? "关闭" : "定制颜色...";
        }
        if (!this.m_bLoadedColorPicker) {
            this.loadColorPicker();
        }
    };
    this.setupFlashEmbed = function () {
        var flashDiv = $("ttmembed");
        flashDiv.style.display = "block";
    };
    this.onReg1KeyPress = function (ev, el) {
        if (!ev) {
            ev = window.event;
        }
        var titleIput;
        if (el === document.getElementById("ttm_title")) {
            if (titleIput = this.isValidWidgetName("ttm_title")) {
                this.setWidgetNameError(titleIput, true, "widgetnameerror");
            } else {
              //  if (nButton) {
              //      nButton.enable();
              //  }
                this.setWidgetNameError(" ", false, "widgetnameerror");
            }
            this.updateWidgetTitle();
        } else {
            if (el === document.getElementById("ttm_nick")) {
                if (titleIput = this.isValidWidgetName("ttm_nick")) {
                    this.setWidgetNameError(titleIput, true, "displaynameerror");
                } else {
                   // if (nButton) {
                   //     nButton.enable();
                   // }
                    this.setWidgetNameError(" ", false, "displaynameerror");
                }
                this.updateWidgetAlias();
            }
        }
       // if (ev.keyCode == 13) {
       //     this.leaveReg1();
       //     return false;
       // }
        return true;
    };
    this.setWidgetNameError = function (msg, _44e, id) {
        var _450 = document.getElementById(id);
        if (_450) {
            removeChildren(_450);
            _450.appendChild(document.createTextNode(msg));
            if (_44e) {
                _450.style.color = "#FF0000";
            } else {
                _450.style.color = "#009900";
            }
        }
    };
    this.isValidImtataId = function (id) {
        var _45a = document.getElementById(id);
        var minLen = 4;
        var maxLen = 64;
        if (!_45a || !_45a.value) {
            return gLang.noIdError;
        }
        var val = stripWhitespace(_45a.value);
        if (!val) {
            return;
        }
        if (val.length < minLen) {
            return gLang.shortIdError;
        }
        if (val.length > maxLen) {
            return gLang.longIdError;
        }
        if (val.search(/[^A-Za-z0-9_.]/) != -1) {
            return gLang.specialCharError;
        }
        this.m_imtataId = val;
    };
    this.isValidEmail = function (id) {
        var _462 = document.getElementById(id);
        if (!_462 || !_462.value) {
            return gLang.noEmailError;
        }
        var val = stripWhitespace(_462.value);
        if (!val) {
            return gLang.noEmailError;
        }
        if (!isEmail(val)) {
            return gLang.poorEmailError;
        }
        this.m_email = val;
    };
    this.isValidPassword = function (id) {
        var _465 = 6;
        var _466 = 100;
        var _467 = document.getElementById(id);
        if (!_467 || !_467.value) {
            return gLang.noPasswordError;
        }
        var val = stripWhitespace(_467.value);
        if (!val) {
            return gLang.noPasswordError;
        }
        if (val.length < 6) {
            return gLang.shortPasswordError;
        }
        if (val.length > 100) {
            return gLang.longPasswordError;
        }
        this.m_pass = val;
    };
    this.isValidConfirmPassword = function (id, _46a) {
        var _46b = document.getElementById(id);
        if (!_46b || !_46b.value) {
            return gLang.noConfirmPassword;
        }
        var val = stripWhitespace(_46b.value);
        if (!val) {
            return gLang.noConfirmPassword;
        }
        var _46d = document.getElementById(_46a);
        var _46e = "";
        if (_46d) {
            _46e = _46d.value;
        }
        if (val != _46e) {
            return gLang.noMatchPassword;
        }
    };
    this.isValidSeccode = function (id) {
         var seccodeCtl = document.getElementById(id);
        if (!seccodeCtl || !seccodeCtl.value) {
            return gLang.noSeccodeError;
        }
        var val = stripWhitespace(seccodeCtl.value);
        if (!val) {
            return gLang.noSeccodeError;
        }
        if (val.length < 4) {
            return gLang.shortSeccodeError;
        }
        if (val.length > 4) {
            return gLang.longSeccodeError;
        }
        this.m_seccode = val;
    };
    this.isValidWidgetName = function (id) {
        var _470 = 100;
        var _471 = document.getElementById(id);
        if (!_471) {
            return "";
        }
        var _472 = "";
        if (_471.getAttribute("nameType")) {
            _472 = _471.getAttribute("nameType");
        }
        if (!_471.value) {
            return sprintf("请填写一个%1", _472);
        }
        var val = stripWhitespace(_471.value);
        if (!val || !val.length) {
            return sprintf("请填写一个%1", _472);
        }
        if (val.length > 100) {
            return sprintf("请填写一个小于50个汉字的 %1 ", _472);
        }
        if (val.search(/[&<>?\"]/) != -1) {
            return sprintf("%1不能包含 &<>?\"", _472);
        }
    };
    this.updateWidgetTitle = function () {
        var titleCtl = $("ttm_title");
        if (titleCtl) {
            if (this.m_flashElem) {
                if(!titleCtl.value || titleCtl.value.length==0)
                    this.m_flashElem.changeTitleText("请输入聊窗名称！");
                else
                    this.m_flashElem.changeTitleText(titleCtl.value);
            }
        }
    };
    this.updateWidgetAlias = function () {
        var nickCtl = $("ttm_nick");
        if (nickCtl) {
            if (this.m_flashElem) {
                if(!nickCtl.value || nickCtl.value.length==0)
                    this.m_flashElem.changeNickName("请输入您的昵称！");
                else
                    this.m_flashElem.changeNickName(nickCtl.value);
                //this.m_flashElem.changeTitleText("选择一个合适的名字很重要");
            }
        }
    };
    this.setWidgetSize = function (w, h) {
        if (!w || !h) {
            return;
        }
        this.m_widgetW = w;
        this.m_widgetH = h;
        var _42c = $("ttmpreviewspace");
        var _42d = 300 + Math.max(0, Math.round((_42c.offsetWidth - w) / 2));
        var _42e = Math.max(0, Math.round((_42c.offsetHeight - h) / 2));
        var _42f = $("ttmembed");
        _42f.style.left = _42d + "px";
        _42f.style.top = _42e + "px";
        var _430 = $("preview");
        if (_430 && _430.width && _430.height) {
            _430.width = w;
            _430.height = h;
            _430.style.width = w;
            _430.style.height = h;
        }
//        var _431 = $("previewembed");
//        if (_431 && _431.width && _431.height) {
//            _431.width = w;
//            _431.height = h;
//        }
    };
    this.updateWidgetSizeToCustom = function (isUpdateCtrl) {
        var widthInput = $("szWidth");
        var heightInput = $("szHeight");
        if (widthInput && heightInput) {
            var w = parseInt(widthInput.value);
            if (w > 300) {
                w = 300;
                if(isUpdateCtrl) widthInput.value = 300;
            }
            if (w < 125) {
                w = 125;
                if(isUpdateCtrl) widthInput.value = 125;
            }
            var h = parseInt(heightInput.value);
            if (h > 400) {
                h = 400;
                if(isUpdateCtrl) heightInput.value = 400;
            }
            if (h < 210) {
                h = 210;
                if(isUpdateCtrl) heightInput.value = 210;
            }
            this.setWidgetSize(w, h);
            var _436 = $("r3");
            if (_436) {
                _436.checked = _436.defaultChecked = true;
            }
        }
    };
    this.flashReady = function (tataid) {
        if (this.isIE) {
            this.m_flashElem = window["preview"];
        } else {
            this.m_flashElem = document["preview"];
        }
        if(this.m_updateUserName&&this.m_updateSessionID&&this.m_updateWid){
            if(this.m_flashElem){
                this.m_flashElem.changeSkinColor(this.bgColor,this.ttColor,this.ttbColor,this.tbColor);
                this.updateWidgetTitle();
                this.updateWidgetAlias();
                if (this.demotext[_3ee]) {
                     this.m_flashElem.changeTipText(this.demotext[_3ee]);
                }
            }
        }else
            this.loadPreset("imtata");
    };

    this.loadColorPicker = function () {
        this.m_colorPicker = new ui.colorPicker();
        this.m_colorPicker.create();
        if (this.m_advancedElem) {
            this.m_colorPicker.m_element.className += " defaulttext";
            this.m_colorPicker.m_element = document.body.appendChild(this.m_colorPicker.m_element);
            this.m_colorPicker.m_element.style.zIndex = 5;
            this.m_bLoadedColorPicker = true;
        }
    };

function stripWhitespace(str) {
    str = str.replace(/^[\s]*/, "");
    str = str.replace(/[\s]*$/, "");
    return str;
};

function sprintf() {
    if (!arguments || arguments.length < 1 || !RegExp || !arguments[0]) {
        return;
    }
    var str = arguments[0];
    for (var i = 1; i < arguments.length; i++) {
        var _1ad = isDefined(arguments[i]) ? arguments[i] : "";
        str = str.replace(new RegExp("%" + i, "g"), _1ad);
    }
    return str;
};

this.isBrowser = function (name) {
    var ua = navigator.userAgent;
    if ((i = ua.indexOf(name)) >= 0) {
        this.m_version = parseFloat(ua.substr(i + name.length));
        return true;
    }
    return false;
};
this.isOS = function (name) {
    var ua = navigator.userAgent.toLowerCase();
    return (ua.indexOf(name) >= 0);
};
this.isSafari = this.isBrowser("Safari");
this.isIE = this.isBrowser("MSIE");
this.isNS = this.isBrowser("Netscape6/");
this.isGecko = this.isBrowser("Gecko");
this.isMac = this.isOS("mac");
this.isWin = this.isOS("win");
this.isLinux = this.isOS("linux");
this.isUnix = this.isOS("x11");
this.isHttps = (document.location.href.indexOf("https") == 0);
this.isIE7 = (this.isIE && this.m_version >= 7);

    /*this.onTitileFocus = function (evt) {
        evt = evt ? evt : (window.event ? window.event : null);
        var inputCtl = evt.srcElement?evt.srcElement : evt.target;
        if(inputCtl){
            inputCtl.value = "";
            inputCtl.isFocused = true;
            inputCtl.style.color = "#000000";
        }
    }*/
    this.isValidBindEmail = function (emailCtrl) {
        if (!emailCtrl || !emailCtrl.value) {
            return gLang.noEmailError;
        }
        var val = stripWhitespace(emailCtrl.value);
        if (!val) {
            return gLang.noEmailError;
        }
        if (!isEmail(val)) {
            return gLang.poorEmailError;
        }
    };
    this.submitbindemail = function(){
         var emailCtrl = document.getElementById("bindemail");
         var errMsg = this.isValidBindEmail(emailCtrl);
         if(errMsg){
            this.highlightField("bindemail");
            var bindErrorCtrl = document.getElementById("bindemailerror");
            if(bindErrorCtrl)
                bindErrorCtrl.style.backgroundColor = "transparent";
            this.doError("bindemailerror",errMsg);
        }
        else{
        　　var invokeUrl = this.m_curRootUrl+"/../func/mebindemail.php?email="+emailCtrl.value+"&wid="+this.m_ttmid;
            var bindresult = gAjax.invoke(invokeUrl,"text");
            bindresult = lTrim(bindresult);
            if(bindresult=="0"){
                $("bindemailform").style.visibility = "hidden";
                $("bindemailresult").style.visibility = "visible";
                $("bindemailresult").innerHTML = "服务器已经接受绑定请求，请到您"+emailCtrl.value+"邮箱中收取激活邮件，并按照提示激活该绑定！";
            }
            else{
                var resultText;
                if(bindresult=="-3")
                    resultText = "该Email地址已经被绑定，请选择其他Email地址！";
                else if(bindresult=="-1")
                    resultText = "抱歉，服务器故障，请稍后重试！";
                else if(bindresult=="-2")
                    resultText = "错误的窗口id，请重新申请窗口！";
                else if(bindresult=="-4")
                    resultText = "无法向您绑定的Email地址发送激活邮件，请检查是否有效Email地址或重试！";
                else
                    resultText = "无法连接服务器，请稍后重试！";
                //alert("bindresult="+bindresult);
                this.doError("bindemailerror",resultText);
            }

        }
    }
};
var g_currentUniqueId = 1;
function getUniqueId() {
    return ++g_currentUniqueId;
}
function removeChildren(_19d, _19e, _19f) {
    if (!_19d || !_19d.hasChildNodes()) {
        return _19d;
    }
    var _1a0;
    var tag;
    var c = _19d.firstChild;
    while (c) {
        if (c["control"] && strArrayCompare(c["control"], _19f)) {
            c = c.nextSibling;
            continue;
        }
        if (c.tagName && strArrayCompare(c.tagName, _19e)) {
            c = c.nextSibling;
            continue;
        }
        var tmp = c.nextSibling;
        _19d.removeChild(c);
        c = tmp;
    }
    return _19d;
};
function replaceHTML(str) {
    if (!str || !str.length) {
        return str;
    }
    str = str.replace(/&/g, "&amp;");
    str = str.replace(/</g, "&lt;");
    str = str.replace(/>/g, "&gt;");
    str = str.replace(/(\r\n|\r|\n)/g, "<br>");
    return str;
};
function isdigit(c) {
    return ((c >= "0") && (c <= "9"));
};
function isEmail(str) {
    if (!str) {
        return false;
    }
    var _130 = -1;
    _130 = str.indexOf("@");
    if (_130 == -1) {
        return false;
    }
    if (_130 == (str.length - 1)) {
        return false;
    }
    return true;
}
function langcap(str) {
    if (!str || !str.length || !str.charAt) {
        return;
    }
    var c = str.charAt(0);
    c = c.toUpperCase();
    return c + str.substring(1);
};
function getValue(id) {
    var _163 = $(id);
    if (!_163) {
        return "";
    }
    if (!isDefined(_163.value)) {
        return "";
    }
    var _164 = _163.value;
    if (!_164) {
        return "";
    }
    return _164;
}
var $ = (function () {
    var _29 = [document];
    function dollar() {
        var _2a = [];
        for (var i = 0; i < arguments.length; i++) {
            var _2c = arguments[i], results = [];
            if (typeof (_2c) != "string") {
                _2a.push(_2c);
            } else {
                for (var d = 0; d < _29.length; ++d) {
                    try {
                        var _2e = _29[d].getElementById(_2c);
                        if (_2e) {
                            results.push(_2e);
                        }
                    }
                    catch (windowMightHaveClosed) {
                    }
                    if (results.length > 0) {
                        break;
                    }
                }
                _2a.push(results.length == 0 ? null : (results.length == 1 ? results[0] : results));
            }
        }
        if (_2a.length == 1) {
            return _2a[0];
        } else {
            return _2a;
        }
    }
    dollar.remember = function (doc) {
        for (var i = 0; i < _29.length; ++i) {
            if (doc === _29[i]) {
                return;
            }
        }
        _29.push(doc);
    };
    dollar.forget = function (doc) {
        var _32 = [];
        for (var i = 0; i < _29.length; ++i) {
            if (_29[i] !== doc) {
                _32.push(_29[i]);
            }
        }
        _29 = _32;
    };
    return dollar;
})();

    function isDefined(obj) {
        if (typeof obj == "undefined") {
            return false;
        }
        return true;
    };

AjaxEngine = function(){
};
var _p = AjaxEngine.prototype;
_p._XMLHTTP_PROGIDS = ["Msxml2.XMLHTTP", "Microsoft.XMLHTTP", "Msxml2.XMLHTTP.4.0"];
_p.getXmlhttpObject = function(){
	var xmlhttp;
	if(typeof XMLHttpRequest != "undefined"){
		try{
			xmlhttp = new XMLHttpRequest();
			xmlhttp.overrideMimeType("text/xml");
			return xmlhttp;
		}catch(e){}
	}
	if(!xmlhttp){
		for(var i = 0; i < 3; ++i){
			var progid = this._XMLHTTP_PROGIDS[i];
			try{
				xmlhttp = new ActiveXObject(progid);
			}catch(e){
			}
			if(xmlhttp){
				this._XMLHTTP_PROGIDS = [progid];
				return xmlhttp;	//break;
			}
		}
	}
	if(!xmlhttp){
		window.alert("XMLHTTP not available");
	}
	return xmlhttp;
};
_p.invoke = function(url, type, callback){
	try{
		var http = this.getXmlhttpObject();
		var async = callback ? true : false;
		http.open("GET", url, async);
		if(async){
			http.onreadystatechange = function(){
				if(http.readyState == 4){
					var o;
					switch(type){
					case "text":
						o = http.responseText;
						break;
					case "xml":
					default:
						o = http.responseXML;
						break;
					}
					callback(o);
				}
			};
		}
		http.send("");
		if(async){
			return;
		}else{
			//http.readyState
			//http.status
			if(http.readyState != 4){
				window.alert("资源文件加载失败");
				return;
			}else{
				//code = Bytes2BStr(http.responseBody);
					switch(type){
					case "text":
						return http.responseText;
					case "xml":
					default:
						return http.responseXML;
					}
			}
		}
	}catch(e){
		var s = "";
		for(var id in e){
			s += "\n" + id + "=" + e[id];
		}
		window.alert(s);
		return;
	}
};

function decToHex(num) {
    var _20a = "0123456789ABCDEF";
    var hex = _20a.substr(num & 15, 1);
    while (num > 15) {
        num >>= 4;
        hex = _20a.substr(num & 15, 1) + hex;
    }
    return hex;
}
function pad(str, pad) {
    if (!str) {
        str = "";
    }
    for (var i = 0; i < pad; i++) {
        if (str.length == pad) {
            return str;
        }
        str = "0" + str;
    }
    return str;
}
function getElementPosition(_141) {
    if (!_141) {
        return;
    }
    var _142 = 0;
    var _143 = 0;
    while (_141) {
        _142 += _141.offsetLeft;
        _143 += _141.offsetTop;
        _141 = _141.offsetParent;
    }
    if (navigator.userAgent.indexOf("Mac") != -1 && isDefined(document.body.leftMargin)) {
        _142 += document.body.leftMargin;
        _143 += document.body.topMargin;
    }
    return {left:_142, top:_143};
}
function argsToArray(args) {
    if (!args || !args.length) {
        return args;
    }
    var arr = new Array();
    for (var i = 0; i < args.length; i++) {
        arr = arr.concat(args[i]);
    }
    return arr;
}
function isCursorInElement(_181, _182) {
    if (!_182) {
        _182 = gWin(_181).event;
    }
    if (!_182 || !_181) {
        return false;
    }
    var pos = getElementPosition(_181);
    var x = ui.getCursorX(_182);
    var y = ui.getCursorY(_182);
    return isInRect(x, y, pos.left, pos.top, _181.offsetWidth, _181.offsetHeight);
}
function isInRect(pX, pY, x, y, w, h) {
    if ((pX < x) || (pX >= x + w)) {
        return false;
    }
    if ((pY < y) || (pY >= y + h)) {
        return false;
    }
    return true;
}
var ui = {};
ui.colorPicker = function () {
    this.m_element = null;
    this.m_currentColor = "000000";
    this.m_swatch = null;
    this.m_colorBox = null;
    this.m_rgbInput = null;
    this.m_bShow = false;
    this.m_hsteps = 24;
    this.m_ssteps = 6;
    this.m_vsteps = 6;
    this.m_callback = null;
    this.create = function () {
        var elem = document.createElement("div");
        elem.style.position = "absolute";
        elem.style.display = "none";
        elem.style.width = (8 * this.m_hsteps) + "px";
        elem.style.top = "0px";
        elem.style.left = "0px";
        elem.style.border = "1px solid #DFECFF";
        elem.style.backgroundColor = "#ffffff";
        var _3b2 = document.createElement("table");
        _3b2.className = "colorpicker";
        _3b2.cellPadding = "0";
        _3b2.cellSpacing = "0";
        _3b2.border = "0";
        var _3b3 = new Array();
        for (var j = 0; j < this.m_hsteps; j++) {
            _3b3.push(Math.round(j / this.m_hsteps * 360));
        }
        for (var i = -this.m_ssteps; i <= (this.m_vsteps + 2); i++) {
            var row = _3b2.insertRow(-1);
            var s = 1;
            var v = 1;
            if (i < 0) {
                s = (i + this.m_ssteps) / this.m_ssteps;
            } else {
                v = (this.m_vsteps - i) / this.m_vsteps;
            }
            if (i > this.m_vsteps) {
                var half = (i == this.m_vsteps + 2) ? (this.m_hsteps + 1) : 0;
            }
            for (var j = 0; j < this.m_hsteps; j++) {
                var cell = row.insertCell(-1);
                if (i > this.m_vsteps) {
                    var _3bb = pad(decToHex(Math.round((j + half) / (this.m_hsteps * 2) * 255)), 2);
                    var _3bc = _3bb.toString() + _3bb.toString() + _3bb.toString() + "";
                } else {
                    var _3bc = this.hsvToRgb(_3b3[j], s, v);
                }
                cell.style.backgroundColor = "#" + _3bc;
                cell.rgbvalue = _3bc;
            }
        }
        this.m_swatch = elem.appendChild(_3b2);
        var _3bd = document.createElement("div");
        _3bd.id = "colorbox";
        _3bd.style.width = "30px";
        _3bd.style.height = "30px";
        _3bd.style.margin = "5px";
        _3bd.style.border = "1px solid #000000";
        this.m_colorBox = elem.appendChild(_3bd);
        var _3be = document.createElement("span");
        _3be.style.margin = "5px";
        _3be.style.position = "absolute";
        _3be.style.right = "0px";
        _3be.style.bottom = "0px";
        _3be.appendChild(document.createTextNode("rgb: #"));
        var _3bf = document.createElement("input");
        _3bf.maxLength = 6;
        _3bf.id = "rgbinput";
        _3bf.style.width = "50px";
        _3bf.style.fontSize = "10px";
        this.m_rgbInput = _3be.appendChild(_3bf);
        elem.appendChild(_3be);
        var obj = this;
        this.m_rgbInput.onkeyup = function (ev, el) {
            return obj.onRGBKeyPress(ev, el);
        };
        this.m_element = elem;
        return this.m_element;
    };
    this.show = function (_3c3) {
        this.m_bShow = _3c3;
        this.m_element.style.display = this.m_bShow ? "block" : "none";
        if (this.m_bShow) {
            ui.connectEvent(this.m_swatch, "mousedown", this, "onColorMouseDown", true, true);
            ui.connectEvent(this.m_swatch, "mousemove", this, "onColorMouseMove", true, true);
            ui.connectEvent(this.m_swatch, "mouseout", this, "onColorMouseOut", true, true);
            var obj = this;
            ui.connectEvent(document.body, "mousedown", this, "onMouseOut", true, true);
            ui.connectGlobalEvent("mousedown", function (ev, el) {
                return obj.onMouseOut(ev, el);
            });
        } else {
            ui.disconnectGlobalEvent("mousedown");
            if (document.body.eventHash) {
                ui.disconnectEvent(document.body, "mousedown", document.body.eventHash["mousedown"]);
            }
        }
    };
    this.isShowing = function () {
        return this.m_bShow;
    };
    this.setPos = function (left, top) {
        this.m_element.style.left = left + "px";
        this.m_element.style.top = top + "px";
    };
    this.setCurrentColor = function (rgb) {
        if (this.validRGB(rgb)) {
            this.m_currentColor = rgb;
            this.m_colorBox.style.backgroundColor = "#" + rgb;
            this.m_rgbInput.value = rgb;
        }
    };
    this.getCurrentColor = function () {
        return this.m_currentColor;
    };
    this.setCallback = function (func) {
        this.m_callback = func;
    };
    this.setHighlightCallback = function (func) {
        this.m_highlightCallback = func;
    };
    this.onRGBKeyPress = function (ev, el) {
        if (!ev) {
            ev = window.event;
        }
        var _3ce = this.m_rgbInput.value;
        if (this.validRGB(_3ce)) {
            this.m_colorBox.style.backgroundColor = "#" + _3ce;
            if (this.m_highlightCallback) {
                this.m_highlightCallback(_3ce);
            }
            if (ev.keyCode == 13) {
                if (this.m_callback) {
                    this.m_callback(this.m_rgbInput.value);
                }
                this.show(false);
                return false;
            }
        }
        if (ev.keyCode == 27) {
            if (this.m_highlightCallback) {
                this.m_highlightCallback(this.m_currentColor);
            }
            this.show(false);
        }
        return true;
    };
    this.getColorFromEvent = function (ev) {
        var pos = getElementPosition(this.m_swatch);
        var x = ev.x - pos.left;
        var y = (ev.y - 4) - pos.top;
        var row = Math.max(Math.min(Math.floor(y / 8), this.m_swatch.rows.length - 1), 0);
        var cell = Math.max(Math.min(Math.floor(x / 8), this.m_swatch.rows[row].cells.length - 1), 0);
        return this.m_swatch.rows[row].cells[cell];
    };
    this.onColorMouseDown = function (ev, el) {
        if (!ev) {
            ev = window.event;
        }
        if (ev) {
            if (ui.isSafari) {
                var elem = this.getColorFromEvent(ev);
            } else {
                var elem = ev.target || ev.srcElement;
            }
            if (elem.rgbvalue && this.validRGB(elem.rgbvalue)) {
                if (this.m_callback) {
                    this.m_callback(elem.rgbvalue);
                }
                this.show(false);
            }
        }
    };
    this.onColorMouseMove = function (ev, el) {
        if (!ev) {
            ev = window.event;
        }
        if (ev) {
            if (ui.isSafari) {
                var elem = this.getColorFromEvent(ev);
            } else {
                var elem = ev.target || ev.srcElement;
            }
            if (elem.rgbvalue && this.validRGB(elem.rgbvalue)) {
                this.m_colorBox.style.backgroundColor = "#" + elem.rgbvalue;
                this.m_rgbInput.value = elem.rgbvalue;
                if (this.m_highlightCallback) {
                    this.m_highlightCallback(elem.rgbvalue);
                }
            }
        }
    };
    this.onColorMouseOut = function (ev, el) {
        if (!this.m_bShow) {
            return;
        }
        this.m_colorBox.style.backgroundColor = "#" + this.m_currentColor;
        this.m_rgbInput.value = this.m_currentColor;
        if (this.m_highlightCallback) {
            this.m_highlightCallback(this.m_currentColor);
        }
    };
    this.isInsideColorPicker = function (x, y) {
        var pos = getElementPosition(this.m_element);
        return (pos.left <= x && x <= (pos.left + this.m_element.offsetWidth) && pos.top <= y && y <= (pos.top + this.m_element.offsetHeight));
    };
    this.onMouseOut = function (ev, el) {
        if (ui.isSafari) {
            if (this.isInsideColorPicker(ev.x, ev.y)) {
                return true;
            }
        } else {
            if (isCursorInElement(this.m_element, ev)) {
                return true;
            }
        }
        if (this.m_highlightCallback) {
            this.m_highlightCallback(this.m_currentColor);
        }
        this.show(false);
        return false;
    };
    this.hsvToRgb = function (h, s, v) {
        var r;
        var g;
        var b;
        if (s == 0) {
            r = g = b = v;
        } else {
            h /= 60;
            var i = Math.floor(h);
            var f = h - i;
            var p = v * (1 - s);
            var q = v * (1 - s * f);
            var t = v * (1 - s * (1 - f));
            switch (i) {
              case 0:
                r = v;
                g = t;
                b = p;
                break;
              case 1:
                r = q;
                g = v;
                b = p;
                break;
              case 2:
                r = p;
                g = v;
                b = t;
                break;
              case 3:
                r = p;
                g = q;
                b = v;
                break;
              case 4:
                r = t;
                g = p;
                b = v;
                break;
              default:
                r = v;
                g = p;
                b = q;
                break;
            }
        }
        return (pad(decToHex(Math.round(r * 255)), 2) + pad(decToHex(Math.round(g * 255)), 2) + pad(decToHex(Math.round(b * 255)), 2));
    };
    this.validRGB = function (rgb) {
        if (rgb == null || rgb == "") {
            return false;
        }
        return rgb.match(/^#?[0-9A-Fa-f]{6}$/);
    };

};
ui.connectGlobalEvent = function (_27a, func) {
    globalEvents[_27a] = func;
};
ui.disconnectGlobalEvent = function (_27c) {
    globalEvents[_27c] = null;
};
ui.connectEvent = function (_27d, _27e, obj, ftn, _281, _282) {
    if (!_27d || !_27e || !obj || !ftn) {
        return;
    }
    var args = argsToArray(arguments);
    args = args.slice(6, args.length);
    var f = function (_285) {
        if (!window["ui"]) {
            return;
        }
        if (!ui.bEnabled) {
            return;
        }
        var o = obj;
        var e = _27d;
        var ev = _285;
        var r = 0;
        var eVa = new Array(ev, e);
        if (_281 && _282) {
            eval("r = o." + ftn + ".apply(o, eVa.concat(args));");
        } else {
            if (_281) {
                eval("r = o." + ftn + ".apply(o, new Array(eVa[0]).concat(args));");
            } else {
                if (_282) {
                    eval("r = o." + ftn + ".apply(o, new Array(eVa[1]).concat(args));");
                } else {
                    eval("r = o." + ftn + ".apply(o, args);");
                }
            }
        }

        return r;
    };
    ui.assignEvent(_27d, _27e, f);
    var id = ui.retrieveEventId(_27d);
    if (!ui.connectedEvents[id]) {
        ui.connectedEvents[id] = new Object();
    }
    ui.connectedEvents[id][_27e] = {elem:_27d, func:f};
};
ui.disconnectEvent = function (_28c, _28d, ftn) {
    if (!_28c || !_28d || !ftn) {
        return;
    }
    if (_28c.detachEvent) {
        _28c.detachEvent("on" + _28d, ftn);
    } else {
        if (_28c.removeEventListener) {
            _28c.removeEventListener(_28d, ftn, true);
        }
    }
    var id = ui.retrieveEventId(_28c);
    if (ui.connectedEvents[id] && ui.connectedEvents[id][_28d]) {
        ui.connectedEvents[id][_28d].elem = null;
    }
};
ui.setEventHandled = function (_290) {
    var win = gWin(_290);
    if (win && win.event) {
        if (win.event) {
            win.event.cancelBubble = true;
            win.event.returnValue = false;
        } else {
            _290.cancelBubble = true;
            _290.returnValue = false;
        }
    } else {
        if (_290 && _290.preventDefault) {
            _290.preventDefault();
            _290.stopPropagation();
        }
    }
};
ui.assignEvent = function (_275, _276, f) {
    if (!_275 || !_276 || !f) {
        return;
    }
    if (!_275.eventHash) {
        _275.eventHash = new Object();
    }
    if (_275.eventHash[_276] && (_275.eventHash[_276] != f)) {
        ui.disconnectEvent(_275, _276, _275.eventHash[_276]);
    }
    if (_275.attachEvent) {
        _275.attachEvent("on" + _276, f);
    } else {
        if (_275.addEventListener) {
            _275.addEventListener(_276, f, true);
        }
    }
    _275.eventHash[_276] = f;
};
ui.retrieveEventId = function (_278) {
    if (!_278) {
        return;
    }
    if (!_278.hasAttributes || !_278.hasAttributes()) {
        return;
    }
    if (_278.getAttribute("eventid")) {
        return _278.getAttribute("eventid");
    }
    var id = getUniqueId();
    _278.setAttribute("eventid", id);
    return id;
};
ui.getCursorX = function getCursorX(_297) {
    if (ui.isSafari && _297 && !isDefined(_297.clientX)) {
        return (_297.target) ? 0 : -1;
    }
    var doc = gDoc(_297 && (_297.target || _297.srcElement));
    var win = gWin(doc);
    if (ui.isIE) {
        return win.event.clientX + doc.documentElement.scrollLeft + doc.body.scrollLeft;
    }
    return _297.clientX + win.scrollX;
};
ui.getCursorY = function getCursorY(_29a) {
    if (ui.isSafari && _29a && !isDefined(_29a.clientY)) {
        return (_29a.target) ? 0 : -1;
    }
    var doc = gDoc(_29a && (_29a.target || _29a.srcElement));
    var win = gWin(doc);
    if (ui.isIE) {
        return win.event.clientY + doc.documentElement.scrollTop + doc.body.scrollTop;
    }
    return _29a.clientY + win.scrollY;
};
ui.isBrowser = function (name) {
    var ua = navigator.userAgent;
    if ((i = ua.indexOf(name)) >= 0) {
        ui.m_version = parseFloat(ua.substr(i + name.length));
        return true;
    }
    return false;
};
ui.isOS = function (name) {
    var ua = navigator.userAgent.toLowerCase();
    return (ua.indexOf(name) >= 0);
};
ui.isOS;
ui.isSafari = ui.isBrowser("Safari");
ui.isIE = ui.isBrowser("MSIE");
ui.isNS = ui.isBrowser("Netscape6/");
ui.isGecko = ui.isBrowser("Gecko");
ui.isMac = ui.isOS("mac");
ui.isWin = ui.isOS("win");
ui.isLinux = ui.isOS("linux");
ui.isUnix = ui.isOS("x11");
ui.isHttps = (document.location.href.indexOf("https") == 0);
ui.isIE7 = (ui.isIE && ui.m_version >= 7);
ui.getVersion = function () {
    return ui.m_version;
};
ui.bEnabled = true;
ui.connectedEvents = new Object();
var globalEvents = new Object();

function gDoc(hint) {
    if (hint) {
        if (hint.ownerDocument) {
            return hint.ownerDocument;
        } else {
            if (typeof (hint.nodeName) == "string") {
                if (hint.nodeName.match(/document/i)) {
                    return hint;
                } else {
                    if (hint.nodeName.match(/window/i)) {
                        return hint.document;
                    }
                }
            }
        }
        var _104 = hint.target || hint.srcElement;
        if (_104) {
            return gDoc(_104);
        }
    }
    return gDoc._doc;
}
gDoc._doc = document;
window.gWin = (function () {
    var _105 = [window];
    function fn(hint) {
        var doc = gDoc(hint);
        for (var i = 0; i < _105.length; ++i) {
            if (_105[i].document === doc) {
                return _105[i];
            }
        }
        var _109 = doc.parentWindow || doc.defaultView;
        return _109 || _105[0];
    }
    fn.remember = function (owin) {
        if (isDefined(owin._gWinPos)) {
            return;
        }
        owin._gWinPos = _105.length;
        _105.push(owin);
    };
    fn.forget = function (owin) {
        if (!isDefined(owin._gWinPos)) {
            return;
        }
        _105 = _105.slice(0, owin._gWinPos).concat(_105.slice(owin._gWinPos + 1));
        for (var i = owin._gWinPos; i < _105.length; ++i) {
            _105[i]._gWinPos = i;
        }
        try {
            delete owin._gWinPos;
        }
        catch (IESUCKS) {
        }
    };
    return fn;
})();
function createFlash(parent, id, src, title, w, h){
	var flashObj;
	if(ui.isIE){
		flashObj = document.createElement("OBJECT");
		flashObj.setAttribute("id", id);
		flashObj.setAttribute("name", id);
		flashObj.setAttribute("classid", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000");
		flashObj.setAttribute("codeBase", "http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab");
		flashObj.setAttribute("movie", src);
		flashObj.setAttribute("wmode", "transparent");
		flashObj.setAttribute("title", title);
		flashObj.setAttribute("width", w);
		flashObj.setAttribute("height", h);
		flashObj.setAttribute("allowScriptAccess", "always");
		//obj.style.width = w + "px";
		//obj.style.height = h + "px";
	}else{
		flashObj = document.createElement("EMBED");
		flashObj.setAttribute("id", id);
		flashObj.setAttribute("type", "application/x-shockwave-flash");
		flashObj.setAttribute("name", id);
		flashObj.setAttribute("src", src);
		flashObj.setAttribute("pluginspage","http://www.adobe.com/go/getflashplayer");
		flashObj.setAttribute("quality", "high");
		flashObj.setAttribute("wmode", "transparent");
		flashObj.setAttribute("width", w);
		flashObj.setAttribute("height", h);
		flashObj.setAttribute("allowScriptAccess", "always");
		flashObj.style.width = w + "px";
		flashObj.style.height = h + "px";
	}
	if(flashObj){
		flashObj.style.display = "block";
		if(parent) parent.appendChild(flashObj);
	}else{
		var alternateContent = 'flash创建失败，请您确定浏览器设置允许播放flash，或刷新浏览器重试，如果仍然不能正常使用请重新安flash插件';
		var textNode = document.createTextNode(alternateContent);
		if(parent) parent.appendChild(textNode);
	}

	return flashObj;
};
var gDomain      = ".meebo.com.cn";  //共享Cookie所用的
function saveCookie(name, value, bErase){
	var days = (bErase) ? -1 : 365;
	var date = new Date();
	date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
	var str = name + "=" + value + "; ";
	var expires = "expires=" + date.toGMTString() + "; ";
	var domain  = "domain=" + gDomain + "; ";
	var path    = "path=/; ";
	window.document.cookie = str + expires + domain + path;
	//window.document.cookie = str + expires + domain;
}
function eraseCookie(name, path){
	saveCookie(name, "", true);
}
/**
 * 使用 cookie 保存的信息有：
 * mid         = 用户帐号
 * state       = 登陆状态(invisible|online)
 * minisitepos = minisite位置(x-y)
 * lang        = 所使用的语言
 * sound       = 是否开启声音(null||true|false)
 * searchtype  = 搜索的类型索引(number)
 * searchhide  = 是否隐藏搜索(true|false)
 */
function loadCookie(name){
	var sCookie = window.document.cookie;
	if(sCookie.length == 0) return;
	var arr = sCookie.split(";");
	var key = name + "=";
	for(var i=0; i < arr.length; i++){
		var item = arr[i];
		if(item.length == 0) continue;
		while(item.charAt(0) == " "){
			item = item.substring(1, item.length);
		}
		if(item.indexOf(key) == 0){
			return item.substring(key.length, item.length);
		}
	}
	return null;
}
/* get client id */
function getClientId(){
	var clientid = loadCookie("clientid");
	if(!clientid || clientid.length==0)
	{
		clientid = getRandString();
		saveCookie("clientid", clientid, false);
	}
	return clientid;
}
/* get random string */
function getRandString() {
	var charBase = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	return generateRandString(64, charBase);
}
function generateRandString(len, base) {
	var str="";
	for (var i = 0; i < len; i++) {
		str += base.charAt(Math.floor(Math.random() * base.length));
	}
	return str;
}

Imtatalang = function ()
{
    this.noIdError = "请填写一个帐号名称以便为您创建新帐号!";
    this.shortIdError = "帐号名称至少要4个字符!";
    this.longIdError = "帐号名称不能超过64个字符!";
    this.specialCharError = "帐号名称只能包含A-Z、0-9、下划线或半角句号";
    this.noPasswordError = "密码不能为空!";
    this.shortPasswordError ="密码不能小于6个字符!";
    this.longPasswordError = "密码不能超过100个字符";
    this.noConfirmPassword = "密码确认不能为空";
    this.noMatchPassword = "两次输入的密码不匹配";
    this.noEmailError = "请填写email地址";
    this.poorEmailError = "请填写有效的email地址，如 'name@domain.com'";
    this.serverError = "服务器访问失败，请稍候再试!";
    this.serverNoUser = "用户不存在，请检查您输入的用户名";
    this.serverErrPass = "您输入的口令不对，请检查后再试!";
    this.titleExist = "您已经注册过相同的聊窗标题，请更换聊窗标题!";
    this.tataAcountExist　=　"ImTata帐号已被使用，请使用其他帐号名!";
    this.tatanotlogin = "未登陆ImTata或验证码失效，请登陆ImTata后再次尝试修改配置！";
    this.invalidUpdateParam = "未登陆ImTata或验证码失效，请登陆ImTata后再次尝试修改配置！";
    this.seccodeError = "验证码错误";
    this.noSeccodeError = "验证码不能为空!";
    this.shortSeccodeError ="验证码不能小于4个字符!";
    this.longSeccodeError = "验证码不能超过4个字符";
};
var gLang = new Imtatalang();

gWizard = new ttmApp.wizardMgr();
gAjax = new AjaxEngine();

