var $mobiquo ={};
var $mobiquo_id;

function check_mobiquo_status(id, mobiquo_dir){
    $mobiquo_id = id;
    var _url = '/xmlrpc/mobiquo_check_status.php?id=' + id + '&mobiquo_dir=' + mobiquo_dir;
    var _data = 'id='+id;
    httpRequest('GET',_url,true,update_status,_data);
}

function update_status(id){
    if( request.readyState == 4) {
        refresh_forum(request.responseText);
    } else {
        document.getElementById("forum_status_loader_"+$mobiquo_id).style.display = "";
    }
}

var request = null;
function httpRequest(reqType,url,asynch,respHandle){

    if(window.XMLHttpRequest){
        request = new XMLHttpRequest();
    } else if(window.ActiveXObject){
        request = new ActiveXObject("Msxml2.XMLHTTP");
        if(! request){
            request = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }

    if(request){

    	if(reqType.toLowerCase() != "post") {
    	   initReq(reqType,url,asynch,respHandle);
    	} else {
    		var args = arguments[4];
    		if(args != null && args.length > 0){
    			initReq(reqType,url,asynch,respHandle,args);
    		}
    	}
    }	else {
    	alert("Your browser dose not permit the use of all of this application's features!");
    }
}

function initReq(reqType,url,bool,respHandle){
	try{
		request.onreadystatechange =respHandle;
		request.open(reqType,url,bool);
		if(reqType.toLowerCase () == "post"){
			request.setRequestHeader("Content-Type","application/x-www-form-unlencoded;charset=UTF-8");

			request.send(arguments[4]);
		} else {
			request.send(null);
		}
	} catch ( errv ){
		alert("The application cannot contact the server at the moment, Please try again in a few seconds\n" +
		      "Error detail:" + errv.message);
	}
}

function update_mobiquo_status(id, action){
    $mobiquo_id = id;
    var _url = '/action_manage_forum.php?id='+id+'&action='+action;
    httpRequest('GET',_url,true,update_status);
}
function refresh_forum(forum_status_str)
{
    var forum = new Array();
    forum = forum_status_str.split('|');
    var fid = forum[0];
    document.getElementById(fid+'status').innerHTML = '';
    document.getElementById('forum_status_'+fid).innerHTML = '';
    document.getElementById(fid+'publish').style.display = 'none';
    document.getElementById(fid+'publish_hide').style.display = 'none';
    document.getElementById(fid+'remove').style.display = 'none';
    document.getElementById(fid+'hide').style.display = 'none';
    document.getElementById(fid+'show').style.display = 'none';
    document.getElementById('forum_status_loader_'+fid).style.display = 'none';


    // set forum status
    if (forum[1] == '0'){ // deleted or not activated
        document.getElementById(fid+'status').innerHTML = "This forum has been removed by Tapatalk Administrator.";
    }else if (forum[2] == '0'){ // not display
        document.getElementById(fid+'status').innerHTML = "Not Published";
    } else if (forum[3] == '1'){ // search_only
        document.getElementById(fid+'status').innerHTML = "Published as Search Only";
    }else {
        document.getElementById(fid+'status').innerHTML = "Published";
    }
    // set error message
    if (forum[4] != '')
        document.getElementById('forum_status_'+fid).innerHTML = forum[4];

    if (forum[1] == '1' && forum[2] == '0' && forum[4] == 'Installed!')
    {
        document.getElementById(fid+'publish').style.display = "";
        document.getElementById(fid+'publish_hide').style.display = "";
    }

    if (forum[1] == '1' && forum[2] == '1'){
        document.getElementById(fid+'remove').style.display = "";
    }
    if (forum[1] == '1' && forum[2] == '1' && forum[3] == '0')
        document.getElementById(fid+'hide').style.display = "";

    if (forum[1] == '1' && forum[2] == '1' && forum[3] == '1')
        document.getElementById(fid+'show').style.display = "";
}


function text_focus(obj){
    obj.style.backgroundColor='#FFFFCC';
}

function text_blur(obj)
{
    obj.style.backgroundColor='';
    if(obj.id == 'name')
    {
        if(obj.value=='' || obj.value.length < 3){
            $("#name1").html("Forum name is too short.");
        } else {
            $("#name1").html("");
        }
    }
    else if(obj.id == 'url')
    {
        var reg1 = /^https?:\/\//;
        var reg2 = /\.(php|html)$/;
        var reg3 = /\?/;

        if( obj.value==''){
            $("#url1").html("The url can not be empty");
        } else if( obj.value.length < 13 ){
            $("#url1").html("Invalid forum url");
        } else if( !reg1.test(obj.value)){
            $("#url1").html("The url need start with 'http://' or 'https://'");
        } else if( reg2.test(obj.value)){
            $("#url1").html("File name at the end of url need to be removed");
        } else if( reg3.test(obj.value)){
            $("#url1").html("File name and parameters at the end of url need to be removed");
        } else{
            $("#url1").html("");
        }
    }
    else if (obj.id == 'description')
    {
        if(obj.value=='' || obj.value.length < 20){
            $("#description1").html("The description you provided is too short.");
        } else {
            $("#description1").html("");
        }
    }
    else if (obj.id == 'twitter')
    {
        var data = obj.value;
        var reCat = /^\s*\w*\s*$/;

        if(reCat.test(data) == false){
            $("#twitter1").html("Invalid twitter account(Only use letters, numbers and '_')");
        } else {
            $("#twitter1").html("");
        }
    }
    else if (obj.id == 'mobiquo_dir')
    {
        var data = obj.value;
        var reCat = /^\s*[a-z0-9-_]+\s*$/;

        if(data == ''){
            obj.value = 'mobiquo';
        } else if(reCat.test(data) == false){
            $("#mobiquo_dir1").html("Directory name must be lower-case Roman, numeric, hyphen or underscore characters.");
        } else {
            $("#mobiquo_dir1").html("");
        }
    }
}


    var isIe=(document.all)?true:false;
    //设置select的可见状态
    function setSelectState(state)
    {
        var objl=document.getElementsByTagName('select');
        for(var i=0;i<objl.length;i++)
        {
            objl[i].style.visibility=state;
        }
    }
    function mousePosition(ev)
    {

    }
    //登录函数
    function showMessageBox(wTitle,content,pos,wWidth)
    {
        closeWindow();
        var bWidth=parseInt(document.documentElement.scrollWidth);
        var bHeight=parseInt(document.documentElement.scrollHeight);
        if(isIe){
            setSelectState('hidden');
        }
        var back=document.createElement("div");
        back.id="back";
        var styleStr="top:0px;left:0px;position:absolute;background:#000000;width:"+bWidth+"px;height:"+bHeight+"px;";
        styleStr+=(isIe)?"filter:alpha(opacity=70);":"opacity:0.70;";
        back.style.cssText=styleStr;
        document.body.appendChild(back);
        var mesW=document.createElement("div");
        mesW.id="mesWindow";
        mesW.className="mesWindow";
        mesW.innerHTML="<div id='mesWindowContent'>"+content+"</div><div class='mesWindowBottom'></div>";
        styleStr="left:"+(screen.width/2-160)+"px;top:"+200+"px;position:absolute;width:"+wWidth+"px;";
        mesW.style.cssText=styleStr;
        document.body.appendChild(mesW);
    }

    //忘记密码函数

     function showForgetBox(wTitle,content,pos,wWidth)
    {
        closeWindow();
        var bWidth=parseInt(document.documentElement.scrollWidth);
        var bHeight=parseInt(document.documentElement.scrollHeight);
        if(isIe){
            setSelectState('hidden');
        }
        var back=document.createElement("div");
        back.id="back";
        var styleStr="top:0px;left:0px;position:absolute;background:#000000;width:"+bWidth+"px;height:"+bHeight+"px;";
        styleStr+=(isIe)?"filter:alpha(opacity=70);":"opacity:0.70;";
        back.style.cssText=styleStr;
        document.body.appendChild(back);
        var mesW=document.createElement("div");
        mesW.id="mesWindow";
        mesW.className="mesWindow";
        mesW.innerHTML="<div id='mesWindowContent'>"+content+"</div><div class='mesWindowBottom'></div>";
        styleStr="left:"+(screen.width/2-160)+"px;top:"+200+"px;position:absolute;width:"+wWidth+"px;";
        mesW.style.cssText=styleStr;
        document.body.appendChild(mesW);
    }
     //注册函数
     function showBox(wTitle,content,pos,wWidth)
    {
        closeWindow();
        var bWidth=parseInt(document.documentElement.scrollWidth);
        var bHeight=parseInt(document.documentElement.scrollHeight);
        if(isIe){
            setSelectState('hidden');
        }
        var back=document.createElement("div");
        back.id="back";
        var styleStr="top:0px;left:0px;position:absolute;background:#000000;width:"+bWidth+"px;height:"+bHeight+"px;";
        styleStr+=(isIe)?"filter:alpha(opacity=70);":"opacity:0.70;";
        back.style.cssText=styleStr;
        document.body.appendChild(back);
        var mesW=document.createElement("div");
        mesW.id="mesWindow";
        mesW.className="mesWindow";
        mesW.innerHTML="<div id='mesWindowContent'>"+content+"</div><div class='mesWindowBottom'></div>";
        styleStr="left:"+(screen.width/2-245)+"px;top:"+200+"px;position:absolute;width:"+wWidth+"px;";
        mesW.style.cssText=styleStr;
        document.body.appendChild(mesW);
    }



     //注册成功之后函数
    function regestersucessBox(wTitle,content,pos,wWidth)
    {
        closeWindow();

        var bWidth=parseInt(document.documentElement.scrollWidth);
        var bHeight=parseInt(document.documentElement.scrollHeight);
        if(isIe){
            setSelectState('hidden');
        }
        var back=document.createElement("div");
        back.id="back";
        var styleStr="top:0px;left:0px;position:absolute;background:#000000;width:"+bWidth+"px;height:"+bHeight+"px;";
        styleStr+=(isIe)?"filter:alpha(opacity=70);":"opacity:0.70;";
        back.style.cssText=styleStr;
        document.body.appendChild(back);
        var mesW=document.createElement("div");
        mesW.id="mesWindow";
        mesW.className="mesWindow";
        mesW.innerHTML="<div id='mesWindowContent'>"+content+"</div><div class='mesWindowBottom'></div>";
        styleStr="left:"+(screen.width/2-290)+"px;top:"+200+"px;position:absolute;width:"+wWidth+"px;";
        mesW.style.cssText=styleStr;
        document.body.appendChild(mesW);
    }

    //邮箱发送之后函数
    function sendmailsucessBox(wTitle,content,pos,wWidth)
    {
        closeWindow();
        var bWidth=parseInt(document.documentElement.scrollWidth);
        var bHeight=parseInt(document.documentElement.scrollHeight);
        if(isIe){
            setSelectState('hidden');
        }
        var back=document.createElement("div");
        back.id="back";
        var styleStr="top:0px;left:0px;position:absolute;background:#000000;width:"+bWidth+"px;height:"+bHeight+"px;";
        styleStr+=(isIe)?"filter:alpha(opacity=70);":"opacity:0.70;";
        back.style.cssText=styleStr;
        document.body.appendChild(back);
        var mesW=document.createElement("div");
        mesW.id="mesWindow";
        mesW.className="mesWindow";
        mesW.innerHTML="<div id='mesWindowContent'>"+content+"</div><div class='mesWindowBottom'></div>";
        styleStr="left:"+(screen.width/2-280)+"px;top:"+200+"px;position:absolute;width:"+wWidth+"px;";
        mesW.style.cssText=styleStr;
        document.body.appendChild(mesW);
    }

    function showBackground(obj,endInt)
    {
        obj.filters.alpha.opacity+=1;
        if(obj.filters.alpha.opacity<endInt)
        {
            setTimeout(function(){showBackground(obj,endInt)},8);
        }
    }
    //关闭窗口
    function closeWindow()
    {
        if(document.getElementById('back')!=null)
        {
            document.getElementById('back').parentNode.removeChild(document.getElementById('back'));
        }
        if(document.getElementById('mesWindow')!=null)
        {
            document.getElementById('mesWindow').parentNode.removeChild(document.getElementById('mesWindow'));
      }
        if(isIe){
            setSelectState('');
        }
    }
    //登录弹窗
    function testMessageBox(ev)
    {
      var objPos = mousePosition(ev);
      var messContent = '';
      messContent += "<div style='background-image:url(../resources/images/t_ws_login_blg.png);height:278px;margin:0px;padding:0px;border:0px solid red'>"
      messContent += "<div style='text-align:center;height:50px'>"
      messContent += "<div style='width:200px;float:left;color:#5D2516;font-size:14pt;margin-top:20px;margin-left:12px'>Forum Owner Login</div>"
      messContent += "<div style='float:left;width:50px;margin-top:20px;margin-left:57px;border:0px solid red'><input type='image' src='../resources/images/t_ws_login_cancel_hl.png' onclick='closeWindow();'   /></div>"
      messContent += "</div>"

      messContent += "<div style='margin-left:30px;margin-top:10px;'><input type='text' id='username' name='username' onMouseDown=\"if(value==defaultValue){value='';}\" onBlur='if(!value){value=defaultValue;}' value='Username' style='background-color:#FFF1BF;border:2px solid #E2B59E;width:261px;height:30px;color:#777777'></div>"
      messContent += "<div style='margin-left:30px;margin-top:14px'><input id=\"txt\" type=\"text\"  value=\"Password\" onfocus=\"loginshow(this)\" style='background-color:#FFF1BF;border:2px solid #E2B59E;width:261px;height:30px;color:#777777'><input id=\"password\" type=\"password\" value='' style=\"display:none;background-color:#FFF1BF;border:2px solid #E2B59E;width:261px;height:30px;color:#777777\" onblur=\"loginshow(this)\"></div>"
      messContent += "<div style='color:#944B00;font-size:11pt;margin-left:197px;margin-top:15px'><input type='image' src='../resources/images/t_ws_forgotpassword.png' onclick='forgetbox(event);'></div>"
      messContent += "<div style='border:0px solid red'>"

      messContent += "<div style='float:left;margin-top:40px;color:blue;margin-left:5px;width:200px;text-align:right;border:0px solid red'><input type='image' src='../resources/images/t_ws_register.png' onclick='MessageBox(event);'></div>"
      messContent += "<div style='float:left;margin-top:27px;width:78px;margin-left:15px'><input type='image' src='../resources/images/t_ws_login_button.png' id='button' value='submit' onclick='saveUserInfo()'></div>"
      messContent += "<div id='msg' style='width:300px;font-size:10pt;margin-left:10px;line-height:10pt;color:#b5482b;margin-top:3px;text-align:center'><div id='flash' style='display:none'><img src='../resources/images/loading.gif'></div></div>"
      messContent += "</div></div>"
      showMessageBox('title',messContent,objPos,333);
    }



    //错误弹窗
    function ErrorMessageBox(ev, actions)
    {
      var objPos = mousePosition(ev);
      var messContent = '';
      var actions;
      messContent += "<div style='background-image:url(../resources/images/t_ws_login_blg.png);height:278px;margin:0px;padding:0px;border:0px solid red'>"
      messContent += "<div style='text-align:center;height:50px'>"
      messContent += "<div style='width:200px;float:left;color:#5D2516;font-size:14pt;margin-top:20px;margin-left:12px'>Forum Owner Login</div>"
      messContent += "<div style='float:left;width:50px;margin-top:20px;margin-left:57px;border:0px solid red'><input type='image' src='../resources/images/t_ws_login_cancel_hl.png' onclick='closeWindow();'   /></div>"
      messContent += "</div>"

      messContent += "<div style='margin-left:30px;margin-top:10px;'><input type='text' id='username' name='username' onMouseDown=\"if(value==defaultValue){value='';}\" onBlur='if(!value){value=defaultValue;}' value='Username' style='background-color:#FFF1BF;border:2px solid #E2B59E;width:261px;height:30px;color:#777777'></div>"
      messContent += "<div style='margin-left:30px;margin-top:14px'><input id=\"txt\" type=\"text\"  value=\"Password\" onfocus=\"loginshow(this)\" style='background-color:#FFF1BF;border:2px solid #E2B59E;width:261px;height:30px;color:#777777'><input id=\"password\" type=\"password\" value='' style=\"display:none;background-color:#FFF1BF;border:2px solid #E2B59E;width:261px;height:30px;color:#777777\" onblur=\"loginshow(this)\"></div>"
      messContent += "<div style='color:#944B00;font-size:11pt;margin-left:197px;margin-top:15px'><input type='image' src='../resources/images/t_ws_forgotpassword.png' onclick='forgetbox(event);'></div>"
      messContent += "<div style='border:0px solid red'>"

      messContent += "<div style='float:left;margin-top:40px;color:blue;margin-left:5px;width:200px;text-align:right;border:0px solid red'><input type='image' src='../resources/images/t_ws_register.png' onclick='MessageBox(event);'></div>"
      messContent += "<div style='float:left;margin-top:27px;width:78px;margin-left:15px'><input type='image' src='../resources/images/t_ws_login_button.png' id='button' value='submit' onclick='saveUserInfo()'></div>"
      if(actions == 1)
      {
      	messContent += "<div id='msg' style='width:300px;font-size:10pt;margin-left:10px;line-height:10pt;color:#b5482b;margin-top:3px;text-align:center'><div style='float:left;margin-top:-3px;margin-left:22px'><img src='../resources/images/t_ws_popup_warn.png'></div><div style='float:left'>&nbsp;&nbsp;Invalid activation code (1)</div></div>"
      }else if(actions == 2)
      {
      	messContent += "<div id='msg' style='width:300px;font-size:10pt;margin-left:10px;line-height:10pt;color:#b5482b;margin-top:3px;text-align:center'><div style='float:left'><div style='float:left;margin-top:-3px;margin-left:22px'><img src='../resources/images/t_ws_popup_warn.png'></div><div style='float:left'>&nbsp;&nbsp;Invalid activation code (2)</div></div>"
      }else if(actions == 3)
      {
      	messContent += "<div id='msg' style='width:300px;font-size:10pt;margin-left:10px;line-height:10pt;color:#b5482b;margin-top:3px;text-align:center'><div style='float:left;margin-top:-3px;margin-left:22px'><img src='../resources/images/t_ws_popup_warn.png'></div><div style='float:left'>&nbsp;&nbsp;Invalid activation code (3)</div></div>"
      }else if(actions == 4)
      {
      	messContent += "<div id='msg' style='width:300px;font-size:10pt;margin-left:10px;line-height:10pt;color:#b5482b;margin-top:3px;text-align:center'>Your account has been activated.</div>"
      }else {
          return false;
      }
      messContent += "</div></div>"
      showMessageBox('title',messContent,objPos,333);
    }


    //注册弹窗
    function MessageBox(ev)
    {

      var objPos = mousePosition(ev);
      var messContent = '';
      messContent += "<div style='background-image:url(../resources/images/t_ws_register_bg.png);height:365px;width:504px;margin:0px;padding:0px;border:0px solid red'>"
      messContent += "<div style='text-align:center;height:50px;'>"
      messContent += "<div style='width:100px;float:left;color:#5D2516;font-size:14pt;margin-top:20px;margin-left:16px;border:0px solid red'>Register</div>"
      messContent += "<div style='float:left;width:50px;margin-top:20px;margin-left:320px;border:0px solid red'><input type='image' src='../resources/images/t_ws_login_cancel_hl.png' onclick='closeWindow();'   /></div>"
      messContent += "</div>"
      messContent += "<div style='border:0px solid red;width:470px;text-align:center;margin-left:13px'></div>"
      messContent += "<div id='textleft' style='float:left;border:0px solid red;margin-left:30px;width:218px;font-size:10pt;color:#836158'>";
      messContent += "<div style='margin-top:3px;border:0px solid red;color:#b5482b'>This registration form is intended for forum owners managing their Tapatalk installation only</div>"


      messContent += "</div>";
      messContent += "<div style='float:left;border:0px solid red'>";
      messContent += "<div style='border:0px solid red;margin-top:26px'><img src='../resources/images/t_ws_register_star.png'></div>";
			messContent += "<div style='border:0px solid red;margin-top:40px'><img src='../resources/images/t_ws_register_star.png'></div>";
			messContent += "<div style='border:0px solid red;margin-top:40px'><img src='../resources/images/t_ws_register_star.png'></div>";
			messContent += "<div style='border:0px solid red;margin-top:40px'><img src='../resources/images/t_ws_register_star.png'></div>";
			messContent += "<div style='border:0px solid red;margin-top:40px'><img src='../resources/images/t_ws_register_star.png'></div>";
      messContent += "</div>";
      messContent += "<div id='textright' style='float:left;border:0	px solid red;margin-top:-5px;width:231px;margin-left:-11px'>"
      messContent += "<div><input  type='text' value='Username'   id='username' onMouseDown=\"if(value==defaultValue){value='';}\" onBlur='if(!value){value=defaultValue;}' style='background-color:#FFF1BF;border:2px solid #E2B59E;width:200px;height:30px;margin-left:20px;margin-top:14px;color:#777777;' ></div>"

     	messContent += "<div><input id=\"txt\" type=\"text\"  value=\"Password\" onfocus=\"show(this)\" style=\"background-color:#FFF1BF;border:2px solid #E2B59E;width:200px;height:30px;margin-left:20px;margin-top:14px;color:#777777\">";
     	messContent += "<input id=\"password1\" type=\"password\" value='' style=\"display:none;background-color:#FFF1BF;border:2px solid #E2B59E;width:200px;height:30px;margin-left:20px;margin-top:14px;color:#777777\" onblur=\"show(this)\"></div>";



     	messContent += "<div><input id=\"newtxt\" type=\"text\"  value=\"Re-enter Password\" onfocus=\"newshow(this)\" style=\"background-color:#FFF1BF;border:2px solid #E2B59E;width:200px;height:30px;margin-left:20px;margin-top:14px;color:#777777\">";
     	messContent += "<input id=\"password2\" type=\"password\" value='' style=\"display:none;background-color:#FFF1BF;border:2px solid #E2B59E;width:200px;height:30px;margin-left:20px;margin-top:14px;color:#777777\" onblur=\"newshow(this)\"></div>";



     	messContent += "<div><input  type='text' value='Email Address' id='email1' onMouseDown=\"if(value==defaultValue){value='';}\" onBlur='if(!value){value=defaultValue;}' style='background-color:#FFF1BF;border:2px solid #E2B59E;width:200px;height:30px;margin-left:20px;margin-top:14px;color:#777777;' /></div>"
     	messContent += "<div><input  type='text' value='Re-enter Email Address' id='email2' onMouseDown=\"if(value==defaultValue){value='';}\" onBlur='if(!value){value=defaultValue;}' style='background-color:#FFF1BF;border:2px solid #E2B59E;width:200px;height:30px;margin-left:20px;margin-top:14px;color:#777777;' /></div>"

      messContent += "</div>"
      messContent += "<div id='msg' style='float:left;width:350px;margin-top:25px;margin-left:20px;font-size:10pt;color:#b5482b;text-align:center'><div id='flash' style='display:none'><img src='../resources/images/loading.gif'></div></div><div style='margin-left:23px;margin-top:25px;border:0px solid;float:left'><input type='image' src='../resources/images/t_ws_done_button.png' id='button' value='submit' onclick='register()'></div>"
      messContent += "</div>"

      messContent += "</div>"

      showBox('title',messContent,objPos,333);
    }


    //注册成功之后弹窗
    function regestersucess(ev)
    {

      var objPos = mousePosition(ev);
      var messContent = '';
      messContent += "<div style='background-image:url(../resources/images/t_ws_register_success.png);height:120px;margin:0px;padding:0px;border:0px solid red'>"
     	messContent += "<div style='color:#5D2516;font-size:14pt;padding-top:20px;margin-left:20px;border:0px solid red;float:left'>Thank you for your registration</div>";
     	messContent += "<div style='float:left;margin-left:240px;border:0px solid red;margin-top:10px'><input type='image' src='../resources/images/t_ws_login_cancel_hl.png' onclick='closeWindow();'/></div>";
     	messContent += "<div style='color:#5D2516;font-size:10pt;margin-left:20px;padding-top:60px;border:0px solid red'>We have sent you a confirmation email with instruction to activate your account.</div>";
      messContent += "</div>";

      regestersucessBox('title',messContent,objPos,560);
    }

   	//忘记密码邮箱发送成功之后弹窗
   	function sendmailsucess(ev)
    {
      var objPos = mousePosition(ev);
      var messContent = '';
      messContent += "<div style='background-image:url(../resources/images/t_ws_register_success.png);height:120px;margin:0px;padding:0px;border:0px solid red'>"
			messContent += "<div style='color:#5D2516;font-size:14pt;padding-top:20px;margin-left:20px;border:0px solid red;float:left'>Password Reset</div>";
     	messContent += "<div style='float:left;margin-left:355px;border:0px solid red;margin-top:17px'><input type='image' src='../resources/images/t_ws_login_cancel_hl.png' onclick='closeWindow();'/></div>";
     	messContent += "<div style='color:#5D2516;font-size:10pt;margin-left:20px;padding-top:58px;border:0px solid red'>A new password has been sent your email</div>";

      messContent += "</div>"

      sendmailsucessBox('title',messContent,objPos,560);
    }


   //<input> 文本框变成 密码输入框
		function show(obj){
		 if(obj.type=="text"){
		    obj.style.display = "none";
		    document.getElementById('password1').style.display = "block";
		    document.getElementById('password1').value="";
		    document.getElementById('password1').focus();
		 }else{
		    var pass = document.getElementById('password1').value;
		    if(pass.length<1){
		      obj.style.display = "none";
		      document.getElementById('txt').style.display = "block";
		    }
		 }
		}

 	//<input> 文本框变成 密码输入框
		function newshow(obj){
			 if(obj.type=="text"){
			    obj.style.display = "none";
			    document.getElementById('password2').style.display = "block";
			    document.getElementById('password2').value="";
			    document.getElementById('password2').focus();
			 }else{
			    var pass = document.getElementById('password2').value;
			    if(pass.length<1){
			      obj.style.display = "none";
			      document.getElementById('newtxt').style.display = "block";
			    }
			 }
		}


 	//<input> 文本框变成 密码输入框
		function loginshow(obj){
			 if(obj.type=="text"){
			    obj.style.display = "none";
			    document.getElementById('password').style.display = "block";
			    document.getElementById('password').value="";
			    document.getElementById('password').focus();
			 }else{
			    var pass = document.getElementById('password').value;
			    if(pass.length<1){
			      obj.style.display = "none";
			      document.getElementById('txt').style.display = "block";
			    }
			 }
		}

   	//忘记密码弹窗
    function forgetbox(ev)
    {

      var objPos = mousePosition(ev);
      var messContent = '';
      messContent += "<div style='background-image:url(../resources/images/t_ws_login_blg.png);height:268px;margin:0px;padding:0px;border:0px solid blue'>"
      messContent += "<div style='text-align:center;height:50px'>"
      messContent += "<div style='width:150px;float:left;color:#5D2516;font-size:14pt;margin-top:20px;margin-left:24px;border:0px solid red'>Password Reset</div>"
      messContent += "<div style='float:left;width:50px;margin-top:20px;margin-left:94px;border:0px solid red'><input type='image' src='../resources/images/t_ws_login_cancel_hl.png' onclick='closeWindow();'   /></div>"
      messContent += "</div>"
      messContent += "<div style='border:0px solid red;color:#5D2516;font-size:10pt;margin-left:29px;margin-top:24px'>Reset password with your email address:</div>";
      messContent += "<div style='margin-left:30px;margin-top:0px;'><input type='text' id='email' name='email' style='background-color:#FFF1BF;border:2px solid #E2B59E;width:261px;height:30px'></div>"
      messContent += "<div style='border:0px solid red;height:200px'>"
      messContent += "<div id='msg' style='float:left;border:0px solid red;width:170px;font-size:10pt;line-height:10pt;color:#b5482b;margin-top:60px;margin-left:20px;text-align:center;height:80px'><div id='flash' style='display:none'><img src='../resources/images/loading.gif'></div></div>";
      messContent += "<div style='float:left;width:78px;margin-left:220px;border:0px solid red;margin-top:-80px'><input type='image' src='../resources/images/t_ws_login_button.png' id='button' value='submit' onclick='forgetpassword()'></div>"
      messContent += "</div>"
      messContent += "</div>"

      showForgetBox('title',messContent,objPos,333);
    }

    //登录函数
    function saveUserInfo()
		{
			//获取接受返回信息层
			var msg = document.getElementById("msg");


			//获取表单对象和用户信息值
			var username=document.getElementById("username").value;
			var password=document.getElementById("password").value;



			//接收表单的URL地址
			var url = "/new_login.php? username="+ username +"&password="+ password;

			var newmsg = document.getElementById('flash');
			if(newmsg != null)
			{
				document.getElementById('flash').style.display='block';
			}else
			{
				document.getElementById('msg').innerHTML = "<div id='flash' style='display:block'><img src='../resources/images/loading.gif'></div>";
			}

			//实例化Ajax
			//var ajax = InitAjax();

	          var ajax = false;
	         //开始初始化XMLHttpRequest对象
	         if(window.XMLHttpRequest) { //Mozilla 浏览器
	                 ajax = new XMLHttpRequest();
	                 if (ajax.overrideMimeType) {//设置MiME类别
	                         ajax.overrideMimeType("text/xml");
	                 }
	         }
	         else if (window.ActiveXObject) { // IE浏览器
	                 try {
	                         ajax = new ActiveXObject("Msxml2.XMLHTTP");
	                 } catch (e) {
	                         try {
	                                 ajax = new ActiveXObject("Microsoft.XMLHTTP");
	                         } catch (e) {}
	                 }
	         }
	         if (!ajax) { // 异常，创建对象实例失败
	                 window.alert("不能创建XMLHttpRequest对象实例.");
	                 return false;
	         }





			//通过Post方式打开连接
			ajax.open("GET", url, true);


			//发送GET数据,已经在URL中赋了值所以send那里只要加个空参.
			ajax.send(null);


			//获取执行状态

			ajax.onreadystatechange = function() {
			   //如果执行状态成功，那么就把返回信息写到指定的层里

			   if (ajax.readyState == 4 && ajax.status == 200) {

				    if(ajax.responseText == 'welcome admin')
				    {
				    		//setTimeout("location='admin_landing.php'",3000);
				    		location.href = '/admin_landing.php';
				    }else if(ajax.responseText == 'welcome user')
				    {
				    		//setTimeout("location='download.php'",3000);
				    		location.href = '/download.php';
				    }else
			    	{
			    		msg.innerHTML = ajax.responseText;
			    	}

			   }
			}
		}

		//注册函数
		function register()
		{
			//获取接受返回信息层
			var msg = document.getElementById("msg");


			//获取表单对象和用户信息值
			var username = document.getElementById("username").value;
			var password1 = document.getElementById("password1").value;
			var password2 = document.getElementById("password2").value;
			var email1 = document.getElementById("email1").value;
			var email2 = document.getElementById("email2").value;



			//接收表单的URL地址
			var url = "/action_create_user.php? username="+ username +"&password1="+ password1+"&password2="+ password2+"&email="+ email1+"&email2="+ email2;

			//document.getElementById('flash').style.display='block';
			var newmsg = document.getElementById('flash');
			if(newmsg != null)
			{
				document.getElementById('flash').style.display='block';
			}else
			{
				document.getElementById('msg').innerHTML = "<div id='flash' style='display:block'><img src='../resources/images/loading.gif'></div>";
			}
			//实例化Ajax
			//var ajax = InitAjax();

	          var ajax1 = false;
	         //开始初始化XMLHttpRequest对象
	         if(window.XMLHttpRequest) { //Mozilla 浏览器
	                 ajax1 = new XMLHttpRequest();
	                 if (ajax1.overrideMimeType) {//设置MiME类别
	                         ajax1.overrideMimeType("text/xml");
	                 }
	         }
	         else if (window.ActiveXObject) { // IE浏览器
	                 try {
	                         ajax1 = new ActiveXObject("Msxml2.XMLHTTP");
	                 } catch (e) {
	                         try {
	                                 ajax1 = new ActiveXObject("Microsoft.XMLHTTP");
	                         } catch (e) {}
	                 }
	         }
	         if (!ajax1) { // 异常，创建对象实例失败
	                 window.alert("不能创建XMLHttpRequest对象实例.");
	                 return false;
	         }





			//通过Post方式打开连接
			ajax1.open("GET", url, true);


			//发送GET数据,已经在URL中赋了值所以send那里只要加个空参.
			ajax1.send(null);


			//获取执行状态

			ajax1.onreadystatechange = function() {
			   //如果执行状态成功，那么就把返回信息写到指定的层里

			   if (ajax1.readyState == 4 && ajax1.status == 200) {


			    if(ajax1.responseText == 666)
			    {

							regestersucess();

			    		setTimeout("location.href='index.php?login=5'",10000);
			    }else
		    	{
		    		msg.innerHTML = ajax1.responseText;
		    	}

			    //msg.innerHTML = 1;
			   }
			}
		}

		//忘记密码函数
		 function forgetpassword()
		{
			//获取接受返回信息层
			var msg = document.getElementById("msg");


			//获取表单对象和用户信息值
			var email=document.getElementById("email").value;


			//接收表单的URL地址
			var url = "/action_reset_password.php? email="+ email;
			//document.getElementById('flash').style.display='block';
			var newmsg = document.getElementById('flash');
			if(newmsg != null)
			{
				document.getElementById('flash').style.display='block';
			}else
			{
				document.getElementById('msg').innerHTML = "<div id='flash' style='display:block'><img src='../resources/images/loading.gif'></div>";
			}
			//实例化Ajax
			//var ajax = InitAjax();

	          var ajax = false;
	         //开始初始化XMLHttpRequest对象
	         if(window.XMLHttpRequest) { //Mozilla 浏览器
	                 ajax = new XMLHttpRequest();
	                 if (ajax.overrideMimeType) {//设置MiME类别
	                         ajax.overrideMimeType("text/xml");
	                 }
	         }
	         else if (window.ActiveXObject) { // IE浏览器
	                 try {
	                         ajax = new ActiveXObject("Msxml2.XMLHTTP");
	                 } catch (e) {
	                         try {
	                                 ajax = new ActiveXObject("Microsoft.XMLHTTP");
	                         } catch (e) {}
	                 }
	         }
	         if (!ajax) { // 异常，创建对象实例失败
	                 window.alert("不能创建XMLHttpRequest对象实例.");
	                 return false;
	         }





			//通过Post方式打开连接
			ajax.open("GET", url, true);


			//发送GET数据,已经在URL中赋了值所以send那里只要加个空参.
			ajax.send(null);


			//获取执行状态

			ajax.onreadystatechange = function() {
			   //如果执行状态成功，那么就把返回信息写到指定的层里

			   if (ajax.readyState == 4 && ajax.status == 200) {

			   		if(ajax.responseText == 1)
			   		{
			   			sendmailsucess();
			   			setTimeout("testMessageBox('event')",10000);
			   		}else
			   		{
			   			msg.innerHTML = ajax.responseText;
			   		}

			   }
			}
		}




