﻿// JScript 文件
var NavigatorType = new Object()
NavigatorType.IE6 = 1;
NavigatorType.IE7 = 2;
NavigatorType.FIREFOX = 3;
NavigatorType.getType = function()
{
	var infoStr = navigator.userAgent.toString();
	//infoStr = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.5.21022; InfoPath.2; .NET CLR 3.5.30729; .NET CLR 3.0.30618)"
	if(/firefox/i.test(infoStr))
	{
		return NavigatorType.FIREFOX;
	}
	else if(/msie\s*7/i.test(infoStr) || /NT\s*6/i.test(infoStr))
	{
		return NavigatorType.IE7;
	}
	else if(/msie\s*6/i.test(infoStr))
	{
		return NavigatorType.IE6;
	}
	
}

function addEvent(obj,eventNameIE,eventNameFF,handler)
{
	if(window.attachEvent)
	{
		obj.attachEvent(eventNameIE,handler);
	}
	else
	{
		obj.addEventListener(eventNameFF,handler,false);
	}
}
function removeEvent(obj,eventNameIE,eventNameFF,handler)
{
	if(window.detachEvent)
	{
		obj.detachEvent(eventNameIE,handler);
	}
	else
	{
		obj.removeEventListener(eventNameFF,handler,false);
	}
}


    function getXY(el)
    {
        var pos;
        if(this.getExplorerType()==1)
        {
            var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
            var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
            pos = [el.getBoundingClientRect().left+scrollLeft, el.getBoundingClientRect().top+scrollTop];
        }
        else
        {
            pos = [el.offsetLeft, el.offsetTop];
            var parentNode = el.offsetParent;
            if (parentNode != el) 
            {
                while (parentNode) 
                {
                    pos[0] += parentNode.offsetLeft;
                    pos[1] += parentNode.offsetTop;
                    parentNode = parentNode.offsetParent;
                }
            }
            if (el.parentNode) { parentNode = el.parentNode; }
            else { parentNode = null; }

            while (parentNode && parentNode.tagName.toUpperCase() != 'BODY' && parentNode.tagName.toUpperCase() != 'HTML')
            {
                if (parentNode.style.display != 'inline') 
                {
                    pos[0] -= parentNode.scrollLeft;
                    pos[1] -= parentNode.scrollTop;
                }

                if (parentNode.parentNode) 
                {
                    parentNode = parentNode.parentNode; 
                } 
                else { parentNode = null; }
            }
        }
        pos.left = pos.X = pos.x = pos[0];
        pos.top = pos.Y = pos.y = pos[1];
        return pos;
    }
    function getExplorerType()
    {
        var ua = navigator.userAgent.toLowerCase();
        if(window.ActiveXObject)
        {
            return 1;
        }
        else if((ua.indexOf('firefox')>-1))
        {
            return 2;
        }
        else if((ua.indexOf('opera')>-1))
        {
            return 3;
        }
    }
	
	var MessageBox = new Object();
	MessageBox.close = function(){};
	MessageBox.pop = function(str,winWidth,winHeight,borderStyle)
	{
		if(!winWidth || !winHeight) 
		{
			alert("参数不全，请传入消息框的宽度和高度。");
			return;
		}
		var MaskObj = MessageBox.mask();
		var bodyWidth = document.body.clientWidth;
		var bodyHeight = document.body.clientHeight;

		
		var windowLeft = parseInt((bodyWidth-winWidth)/2);
		
		var WinElement = document.createElement("div")
		WinElement.style.width = winWidth+"px";
		WinElement.style.height = winHeight+"px";
		WinElement.style.position = "absolute";
		WinElement.style.zIndex = "101";
		WinElement.style.border = !borderStyle?"5px solid #959394":borderStyle;
		WinElement.style.left =  windowLeft+"px";
		WinElement.style.top =  (document.documentElement.scrollTop + 180) + "px";
		
		WinElement.style.backgroundColor = "white";
		WinElement.style.letterSpacing = "normal";
		WinElement.innerHTML = str;
		document.body.appendChild(WinElement);
		MessageBox.close = function(e1,e2)
		{
			return function()
			{
				document.body.removeChild(e1);
				document.body.removeChild(e2);
			}
		}(MaskObj,WinElement)
	}
	
	//实现模态对话框，遮挡下面的内容，防止用户进行额外操作（此函数返回遮罩Div对象）
	MessageBox.mask = function()
	{
		var bodyWidth = document.documentElement.clientWidth;
		var bodyHeight = document.body.clientHeight;
		var MaskObj = document.createElement("div");
		MaskObj.style.width = bodyWidth+"px";
		MaskObj.style.height = bodyHeight+"px";
		MaskObj.style.backgroundColor = "black";
		MaskObj.style.position = "absolute";
		MaskObj.style.left = "0px";
		MaskObj.style.top = "0px";
		MaskObj.style.zIndex = "100";
		MaskObj.style.filter = "alpha(opacity=15)";
		MaskObj.style.opacity = 0.15;
		document.body.appendChild(MaskObj); 
		return MaskObj;
	}
	
	
	
	
	
	//非本网站则跳转
	var checkCurrentlocation = window.location.toString()
	if(checkCurrentlocation.indexOf("chenre.") > -1 || checkCurrentlocation.indexOf("localhost") > -1 || checkCurrentlocation.indexOf("192.168") > -1)
	{
	    
	}
	else
	{
	    window.location = "http://www.chenre.cn";
	}
	
	
	var $ = function(id)
	{
	    return document.getElementById(id);
	}
	
	
	function PopBindPhoneWindow()
    {
        var messageHtml = "<div style='height:10px; overflow:hidden;'>&nbsp;</div><div style='color:#339800; font-size:13px; font-weight:bold; float:left; margin-left:5px; display:inline;'>用户手机绑定</div><div style='float:left;color:#FF5508; margin-left:7px; display:inline;'>(绑定手机将与当前用户一一对应，不能再与其他用户名绑定)</div><div style='clear:both;overflow:hidden; height:15px;'></div>"+
                        "<div id='bind_form_content'><div style='color:#525252; float:left; width:190px;text-align:right;'>手机号码(限重庆移动用户): </div><div style='float:left;'><input  maxlength='20' type=\"text\" id=\"BindPhoneNumInput\" /></div>"
                        +"<div style='clear:both; height:7px; overflow:hidden;'></div>"
                        +"<div style='color:#525252; float:left; width:190px;text-align:right;'>请输入验证码: </div><div style='float:left;'><input maxlength='10' id='valInput' type='text' style='width:100px;' /> <img id='valPic' src='ValidatePic.aspx?"+Math.floor(Math.random() *10000000)+"' align='absmiddle'> <a href='javascript:void(0)' onclick='document.getElementById(\"valPic\").src=\"ValidatePic.aspx?\"+Math.floor(Math.random() *10000000)'>看不清</a></div></div>"
                        +"<div style='height:51px; display:none;' id='bind_form_content2'>稍后您将会接收到手机短信，请把其中的随机码填入下框中。<br />随机码: <input  maxlength='10' name='bindRndId' id='bindRndId' type='text' style='width:100px;' /></div>"
                        +"<div style='clear:both;'></div>"
                        +"<div style='text-align:left; color:#359800; display:inline; margin-left:41px; float:left;'>绑定手机是完全免费的<br/>绑定手机后，用户可以用手机号登陆趁热网<br />绑定手机后，可以免费接受趁热网的各种活动信息</div><div style='clear:both;'></div>";
        messageHtml+="<div style='height:21px;overflow:hidden'>&nbsp;</div><div><button id='bind_phone_next_button' onclick='SendBindRequest();'>下一步 &gt;&gt;</button><button id='bind_now_button' style='display:none;' onclick='bindPhoneNow()'>立即绑定</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button onclick='MessageBox.close();'> 关闭 </button></div>";
        MessageBox.pop(messageHtml,463,221);
    }
    function SendBindRequest()//开始绑定，调用之后会下发临时密码到用户手机。
    {
        var phone = $("BindPhoneNumInput").value;
        var valNum = $("valInput").value;
        phone = phone.replace(/\s+/,"");
        if(phone == "")
        {
            alert("请输入你的手机号码。");
            $("BindPhoneNumInput").focus();
            return;
        }
        else if(phone.length != 11)
        {
            alert("手机号码长度不对。");
            $("BindPhoneNumInput").focus();
            return;
        }
        else if(phone.split("")[0] != "1"   || /[^\d]/.test(phone))
        {
            alert("手机号码格式不正确。");
            $("BindPhoneNumInput").focus();
            return;
        }
        else if(/^13[0-3]/.test(phone))
        {
            alert("只支持重庆移动的手机号码。");
            $("BindPhoneNumInput").focus();
            return;
        }
        else if(valNum == "")
        {
            alert("请输入验证码");
            $("valInput").focus();
            return;
        }
        //开始发送
        $("bind_phone_next_button").disabled = "disabled";
        var ajaxOjb_2 = new DTAjax();
        ajaxOjb_2.onGet = function(text)
        {
            if("验证码不正确。" == text)
            {
                alert("验证码不正确。");
                document.getElementById("valPic").src="ValidatePic.aspx?"+Math.floor(Math.random() *10000000);
                $("bind_phone_next_button").disabled = "";
            }
            else if(text.indexOf("完成") > -1)
            {
                $("bind_form_content").style.display = "none";
                $("bind_form_content2").style.display = "";
                $("bind_now_button").style.display = "";
                $("bind_phone_next_button").style.display = "none";
            }
            else
            {
                alert(text);
                document.getElementById("valPic").src="ValidatePic.aspx?"+Math.floor(Math.random() *10000000);
                $("bind_phone_next_button").disabled = "";
            }
        }
        ajaxOjb_2.addPostData("phone",phone);
        ajaxOjb_2.addPostData("valNum",valNum);
        ajaxOjb_2.getStringFromUrl("post","userbindphone.aspx",true);
    }
    
    function bindPhoneNow()
    {
        var doRndID = $("bindRndId").value;
        if(doRndID == "")
        {
            alert("请先输入你收到的随机码。");
            return;
        }
        
        var ajaxOjb_3 = new DTAjax();
        $("bind_now_button").disabled = "disabled";
        ajaxOjb_3.onGet = function(text)
        {
            if(text.indexOf("绑定完成")>-1)
            {
                alert("绑定成功!")
                MessageBox.close();
            }
            else
            {
                alert(text);
                $("bind_now_button").disabled = "";
            }
        }
        ajaxOjb_3.addPostData("doBind","1");
        ajaxOjb_3.addPostData("randKey",doRndID);
        ajaxOjb_3.getStringFromUrl("post","userbindphone.aspx",true);
    }
    
    function  PopPhoneLogin()
    {
        var messageHtml = "<div style='height:10px; overflow:hidden;'>&nbsp;</div><div style='color:#339800; font-size:13px; font-weight:bold; float:left; margin-left:5px; display:inline;'>手机登录</div><div style='float:left;margin-left:7px; display:inline; color:gray;'>已注册用户请先<a href='javascript:void(0)' onclick='MessageBox.close();document.getElementById(\"Login1_cr_lgi_u\").focus();' class='orangelink'>登录</a>，即可绑定手机到你的帐号(+20个币)</div><div style='clear:both;overflow:hidden; height:15px;'></div>"+
                        "<div id='login_form_content'><div style='color:#525252; float:left; width:190px;text-align:right;'>手机号码(限重庆移动用户): </div><div style='float:left;'><input  maxlength='20' type=\"text\" id=\"PhoneLoginNumInput\" /></div>"
                        +"<div style='clear:both; height:7px; overflow:hidden;'></div>"
                        +"<div style='color:#525252; float:left; width:190px;text-align:right;'>请输入验证码: </div><div style='float:left;'><input maxlength='10' id='valInput2' type='text' style='width:100px;' /> <img id='valPic2' src='ValidatePic.aspx?"+Math.floor(Math.random() *10000000)+"' align='absmiddle'> <a href='javascript:void(0)' onclick='ChangeValidatePic()'>看不清</a></div></div>"
                        +"<div style='height:51px; display:none;' id='login_form_content2'>稍后您将会接收到手机短信，请把其中的随机码填入下框中。<br />随机码: <input  maxlength='10' name='bindRndId2' id='bindRndId2' type='text' style='width:100px;' /></div>"
                        +"<div style='clear:both;'></div>"
                        +"<div style='text-align:left; color:#359800; display:inline; margin-left:41px; float:left;'>手机登录是完全免费的</div><div style='clear:both;'></div>";
        messageHtml+="<div style='height:21px;overflow:hidden'>&nbsp;</div><div><button id='phone_login_next_button' onclick='SendPhoneLoginRequest();'>下一步 &gt;&gt;</button><button id='login_now_button' style='display:none;' onclick='PhoneLoginNow()'>登录</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button onclick='MessageBox.close();'> 关闭 </button></div>";
        MessageBox.pop(messageHtml,463,176);
    }
    
    function ChangeValidatePic()
    {
        window.setTimeout(
            function(){
                document.getElementById("valPic2").src="ValidatePic.aspx?"+Math.floor(Math.random() *10000000);
                },1
        )
    }
    
    function SendPhoneLoginRequest()
    {
        var phone = $("PhoneLoginNumInput").value;
        var valNum = $("valInput2").value;
        phone = phone.replace(/\s+/,"");
        if(phone == "")
        {
            alert("请输入你的手机号码。");
            $("PhoneLoginNumInput").focus();
            return;
        }
        else if(phone.length != 11)
        {
            alert("手机号码长度不对。");
            $("BindPhoneNumInput").focus();
            return;
        }
        else if(phone.split("")[0] != "1"   || /[^\d]/.test(phone))
        {
            alert("手机号码格式不正确。");
            $("BindPhoneNumInput").focus();
            return;
        }
        else if(/^13[0-3]/.test(phone))
        {
            alert("只支持重庆移动的手机号码。");
            $("BindPhoneNumInput").focus();
            return;
        }
        else if(valNum == "")
        {
            alert("请输入验证码");
            $("valInput").focus();
            return;
        }
        
        $("phone_login_next_button").disabled = "disabled";
        var ajaxOjb_2 = new DTAjax();
        ajaxOjb_2.onGet = function(text)
        {
            if("验证码不正确。" == text)
            {
                alert("验证码不正确。");
                document.getElementById("valPic2").src="ValidatePic.aspx?"+Math.floor(Math.random() *10000000);
                $("phone_login_next_button").disabled = "";
            }
            else if(text.indexOf("完成") > -1)
            {
                $("login_form_content").style.display = "none";
                $("login_form_content2").style.display = "";
                $("login_now_button").style.display = "";
                $("phone_login_next_button").style.display = "none";
            }
            else
            {
                alert(text);
                document.getElementById("valPic2").src="ValidatePic.aspx?"+Math.floor(Math.random() *10000000);
                $("phone_login_next_button").disabled = "";
            }
        }
        ajaxOjb_2.addPostData("phone",phone);
        ajaxOjb_2.addPostData("valNum",valNum);
        ajaxOjb_2.getStringFromUrl("post","userphonelogin.aspx",true);
        
    }
    
    function PhoneLoginNow()
    {
        var doRndID = $("bindRndId2").value;
        if(doRndID == "")
        {
            alert("请先输入你收到的随机码。");
            return;
        }
        
        var ajaxOjb_3 = new DTAjax();
        $("login_now_button").disabled = "disabled";
        ajaxOjb_3.onGet = function(text)
        {
            if(text.indexOf("成功")>-1)
            {
                alert("登录成功!");
                MessageBox.close();
                window.location.reload();
            }
            else
            {
                alert(text);
                $("login_now_button").disabled = "";
            }
        }
        ajaxOjb_3.addPostData("doLogin","1");
        ajaxOjb_3.addPostData("randKey",doRndID);
        ajaxOjb_3.getStringFromUrl("post","userphonelogin.aspx",true);
    }
    function PhonUserSetNickName()
    {
        var messageHtml = "<div style='height:10px; overflow:hidden;'>&nbsp;</div><div style='color:#339800; font-size:13px; font-weight:bold; float:left; margin-left:5px; display:inline;'></div><div style='clear:both;overflow:hidden; height:15px;'></div>"+
                        "<div id='setname_form_content'><div style='color:#525252; float:left; width:90px;text-align:right;'>请输入昵称: </div><div style='float:left;'><input  maxlength='20' type=\"text\" id=\"SetNickInput\" /></div><div style='clear:both;'></div>";
                        
        messageHtml+="<div style='height:21px;overflow:hidden'>&nbsp;</div><div><button id='set_nick_button' onclick='SendSetNickRequest();'>设置</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button onclick='MessageBox.close();'> 关闭 </button></div>";
        MessageBox.pop(messageHtml,263,106);
    }
    
    function SendSetNickRequest()
    {
        var newName = $("SetNickInput").value;
        if(newName.length == 11 && /[^\d]/.test(newName) == false)
        {
            alert("请勿输入11位纯数字。");
            return;
        }
        if(newName == "")
        {
            alert("请输入昵称。");
            return;
        }
        var ajaxOjb_4 = new DTAjax();
        ajaxOjb_4.onGet = function(text)
        {
            if(text.indexOf("更新成功") > -1)
            {
                alert(text);
                window.location.reload();
            }
            else
            {
                alert(text);
            }
            
        }
        ajaxOjb_4.addPostData("nn",newName);
        ajaxOjb_4.getStringFromUrl("post","usersetnicknameajax.aspx",true);
    }
    
    
        var domReady = {
	add:function(fn) {
		
		var b=function (){
			domReady.ready=true;
			if(arguments.callee.done)return ;
			arguments.callee.done=true;
			fn.apply(document,arguments)
		};
		if(domReady.ready){
			b();
			return;
		}
		if(document.addEventListener){
			document.addEventListener('DOMContentLoaded',function (){
				document.removeEventListener('DOMContentLoaded',arguments.callee,false);
				b()
			},false)
		}else if(document.attachEvent){
			if(document.documentElement.doScroll&&window==window.top){
				(function (){
					try{
						document.documentElement.doScroll('left')
					}catch(e){
						setTimeout(arguments.callee,0);
						return 
					}
					b()
				})()
			}else {
				document.attachEvent('onreadystatechange',function (){
					if(document.readyState==='complete'){
						document.detachEvent('onreadystatechange',arguments.callee);
						b()
					}
				})
			}
		}
	}
};
