﻿    function CheckInput()
    {        
        if (document.getElementById("questionSelect").options[document.getElementById("questionSelect").selectedIndex].value == "CommentID")
        {
            if(isNaN(document.getElementById("searchContent").value))
             {
                alert("留言ID请输入数字");
                return false;
             }    
             if(document.getElementById("searchContent").value.length > 9)
             {
                alert("留言ID数字过大");
                return false;
             }                    
        }
        if (f_check_ZhOrNumOrLett(document.getElementById("searchContent")) == false)
            {
            alert("请输入汉字、字母或数字");   
            return false;
            }    
        return true;
    }
    
     
     //判断是否是汉字、字母、数字组成   
    function f_check_ZhOrNumOrLett(obj)
    {    
        var regu = "^[0-9a-zA-Z\u4e00-\u9fa5]+$";      
        var re = new RegExp(regu);   
        if (obj.value != "")
        {
            if (re.test( obj.value ))
            {   
              return true;   
            }       
            return false;   
        }
        return true;
    }  
        
function GetSelect()
{
    var obj = document.getElementById("questionSelect");
    var selectValue =  obj.options[obj.selectedIndex].value;	
    if (selectValue == "Time")
    {
        document.getElementById("searchContent").style.display = "none";
        document.getElementById("beginDate").style.display = "block";
        document.getElementById("endDate").style.display = "block";
    }
    else
    {
        document.getElementById("searchContent").style.display = "block";
        document.getElementById("beginDate").style.display = "none";
        document.getElementById("endDate").style.display = "none"; 
    }

}

function regInput(obj, reg, inputStr) 
{	var docSel = document.selection.createRange() 
	oSel = docSel.duplicate() 
	oSel.text = "" 
	var srcRange = obj.createTextRange() 
	oSel.setEndPoint("StartToStart", srcRange) 
	var str = oSel.text + inputStr + srcRange.text.substr(oSel.text.length) 
	return reg.test(str) 
}

//插入表情
//objName控件的名字
function AddFace(ImgName,objName)
{
    var str = "[:" + ImgName + "]";
    var obj = document.getElementById(objName);
    var objLength=obj.value.length;
    obj.focus();
    if(typeof document.selection !="undefined")
    {
        document.selection.createRange().text=str;  
    }
    else
    {
        obj.value=obj.value.substr(0,obj.selectionStart)+str+obj.value.substring(obj.selectionStart,objLength);
    }
}

        //打开窗口 
        function OpenWindow()
        {
            scall();        
            if (window.navigator.userAgent.indexOf("MSIE")>=1)
            {
                //如果浏览器为IE
                document.documentElement.scrollTop = 10;   
                document.getElementById("mask").style.width = document.body.clientWidth;
                document.getElementById("mask").style.height = document.body.clientHeight;         
            }
            else
            {
                if (window.navigator.userAgent.indexOf("Firefox")>=1)
                {
                    document.body.style.overflow="hidden";
                    document.documentElement.scrollTop = "10px";
                    document.getElementById("mask").style.width = document.body.clientWidth + "px";
                    document.getElementById("mask").style.height = document.body.clientHeight + "px";
                }
                else
                {
                    //如果浏览器为其他
                }
            }  
            document.getElementById("out").style.display = "block";
            document.getElementById("mask").style.display = "block";
        }
        
        //关闭窗口        
        function CloseWindow()
        {
            if (window.navigator.userAgent.indexOf("MSIE")>=1)
            {
                //如果浏览器为IE
                document.body.scroll = "yes";           
            }
            else
            {
                if (window.navigator.userAgent.indexOf("Firefox")>=1)
                {
                    document.body.style.overflow="visible";
                }
                else
                {
                    //如果浏览器为其他
                }
            }
            
            document.getElementById("out").style.display = "none"; 
            document.getElementById("mask").style.display = "none";                  
        } 
        
        //算弹出层的位置
        function sc1()
        { 
            if (window.navigator.userAgent.indexOf("MSIE")>=1)
            {
                //如果浏览器为IE
                document.getElementById("out").style.top = document.documentElement.scrollTop + 200;
                document.getElementById("out").style.left = (document.documentElement.clientWidth)/2 - 120;              
            }
            else
            {
                if (window.navigator.userAgent.indexOf("Firefox")>=1)
                {
                    document.getElementById("out").style.top = document.documentElement.scrollTop + 200 + "px";
                    document.getElementById("out").style.left = (document.documentElement.clientWidth)/2 - 120 + "px"; 
                }
                else
                {
                    //如果浏览器为其他
                }
            }
        }
        
        //验证登录
        function CheckLoginInput(userNameObj,passWordObj)
        {
            if (userNameObj.replace(/(^\s*)|(\s*$)/g, "").length == 0) 
            {
                Show("ErrorStr","登录邮箱不能为空");                
                return false;
            }
            else if (!(userNameObj.replace(/(^\s*)|(\s*$)/g, "").search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) )
            {
                Show("ErrorStr","登录邮箱地址不正确!");                
                return false;
            }
            else if (userNameObj.replace(/(^\s*)|(\s*$)/g, "").length > 40) 
            {
                Show("ErrorStr","登录邮箱的长度最多为40个字符");                
                return false;
            }
            else if (passWordObj.replace(/(^\s*)|(\s*$)/g, "").length == 0 && passWordObj.length != 0) 
            {
                Show("ErrorStr","密码不能输入空格");                
                return false;
            }
            else if (passWordObj.replace(/(^\s*)|(\s*$)/g, "").length == 0) 
            {
                Show("ErrorStr","密码不能为空");                
                return false;
            }
            else if (passWordObj.replace(/(^\s*)|(\s*$)/g, "").length < 4 || passWordObj.replace(/(^\s*)|(\s*$)/g, "").length > 14) 
            {
                Show("ErrorStr","密码必须为4~14位");                
                return false;
            }             
            return true;
        } 
        
        //显示提示信息
        function Show(elementId,str)
        {
            var div = document.getElementById(elementId);
            if(str != "")
            {
                div.style.display = "block";
                div.innerHTML="&nbsp;&nbsp;注：" + str ;
            }
        }
        
        //登录验证
        function Login(redirectUrl)
        {
            var userName = document.getElementById("LoginUserName").value;
            var passWord = document.getElementById("Password").value;
            var isKeepPassword = document.getElementById("IsKeepPassword").checked ? true : false;
            //验证输入
            if (CheckLoginInput(userName,passWord))
            {           
                //验证有效性
                $.ajax(
                            {           
                              type: "POST",
                              url: "/Dealer/LoginValidate.aspx",
                              data:   "UserName="+userName+"&PassWord="+passWord+"&IsKeepPassword="+isKeepPassword,
                              dataType:"text",
                              success: 
                               function(msg)
                                 {
                                    if(msg == "登录成功")
                                        document.location.href = redirectUrl;
                                    else                                    
                                        Show("ErrorStr",msg);                                       
                                 }
                            }
                         );    
             }
             
             return false;
        }
        
        //显示帮助层
		function ShowHelp(ev,objID,divID)
        {                          
            var topValue = ev.clientY;//当前高            
            var leftValue = ev.clientX;//当前宽
            var scrollValue = document.documentElement.scrollTop;//滚动条高
            var allTop;//当前高+滚动条高
            if ($.browser.msie ) 
            {
               allTop = topValue + scrollValue;
            }    
            else
            {   
                //firefox下值要加px
               allTop = topValue+scrollValue; 
               topValue = topValue + "px";
               leftValue = leftValue + "px";
               allTop = allTop + "px" ;               
            }    
            document.getElementById(divID).innerHTML = "#" + objID + "(留言ID号)";	    							
			document.getElementById(divID).style.top =allTop;
			document.getElementById(divID).style.left =leftValue;
			document.getElementById(divID).style.display = 'block';					
        }