function checkstr(str,digit){      //定义checkstr函数实现对用户名长度的限制   
var n=0;         //定义变量n，初始值为0
for(i=0;i<str.length;i++){     //应用for循环语句，获取表单提交用户名字符串的长度
var leg=str.charCodeAt(i);     //获取字符的ASCII码值
if(leg>255){       //判断如果长度大于255 
n+=2;       //则表示是汉字为两个字节
}else {n+=1;       //否则表示是英文字符，为一个字节
}}if (n>digit){        
//判断用户名的总长度如果超过指定长度，则返回true
return true;}else {return false;       //如果用户名的总长度不超过指定长度，则返回false
}    
} 

function checktext()
{
	var t = $F('Text1');
	if (checkstr(t,24))
	{	alert("字符长度不能超过24个字符，请重新输入！");return false;	}
	else
	{ return true;}
	}
	
		function ChangeStatusRoot(o,id,term)
		{
			if (o.parentNode)
			{
				if (o.parentNode.className == "Opened")
				{
					o.parentNode.className = "Closed";
					o.className="bai";
				}
				else
				{
					o.parentNode.className = "Opened";
					o.className="bai2";

					document.getElementById('TextHidden').value=term;
					var t1="";
					if ($F('Text1').replace(/\'/g,"")!="")
					{
					    if ($F('Text1').replace(/\'/g,"")!="关键字：专题名称")
					        t1 =" 关键字 <span class=\"STYLE4\">"+$F('Text1')+"</span>";
					}
                    $('soustxt').innerHTML="您的搜素条件是 <span class=\"STYLE4\">"+term+"</span>"+t1;
					getfeatureview(1,10,term,'','',$F('Text1').replace(/\'/g,""));

				}

				document.getElementById(id).childNodes[0].className="s";
			}
			for (var i=1;i<4;i++)
			{
			    if ("li_"+i!=id)
			    {
			        document.getElementById('li_'+i).className="Closed";
			        document.getElementById('li_'+i).childNodes[1].className="bai";

			    }
			}
		}

		function ChangeStatus(o,id,t,c,term,garde)
		{
			if (o.parentNode)
			{
				if (o.parentNode.className == "Opened")
				{
					o.parentNode.className = "Closed";

				}
				else
				{
					
					o.parentNode.className = "Opened";
                    document.getElementById('TextHidden').value=term+'&'+garde;
                    var t1="";
					if ($F('Text1').replace(/\'/g,"")!="")
					{
					    if ($F('Text1').replace(/\'/g,"")!="关键字：专题名称")
					        t1 =  " 关键字 <span class=\"STYLE4\">"+$F('Text1')+"</span>";
					}
                    $('soustxt').innerHTML="您的搜素条件是 <span class=\"STYLE4\">"+term+" "+garde+"</span>"+t1;
                    getfeatureview(1,10,term,garde,'',$F('Text1').replace(/\'/g,""));
				}
			}
			for (var i=1;i<c+1;i++)
			{
			    if ("li_"+t+"_"+i!=id)
			    {
			        //alert("li_"+t+"_"+i);
			        document.getElementById("li_"+t+"_"+i).className="Closed";
			    }
			}

		}
		function ChangeStatusChild(term,garde,km)
		{
		    document.getElementById('TextHidden').value=term+'&'+garde+'&'+km;
		    var t="";
		    if ($F('Text1'.replace(/\'/g,""))!="")
		    {
    		    if ($F('Text1').replace(/\'/g,"")!="关键字：专题名称")
			        t =  " 关键字 <span class=\"STYLE4\">"+$F('Text1').replace(/\'/g,"")+"</span>";

		    }
		    $('soustxt').innerHTML="您的搜素条件是 <span class=\"STYLE4\">"+term+" "+garde+" "+km+"</span>"+t;
		    getfeatureview(1,10,term,garde,km,$F('Text1').replace(/\'/g,""));
		}
		function SearchItems()
		{
		    var search = $F('TextHidden');
		    if (search!="")//如果之前有判断
		    {
		        if (search.indexOf("&")!=-1)
		        {
		            mystr=search.split("&"); 
		            if(mystr.length==2)
		            {
		                getfeatureview(1,10,mystr[0],mystr[1],'',$F('Text1').replace(/\'/g,""));
		                $('soustxt').innerHTML="您的搜素条件是 <span class=\"STYLE4\">"+mystr[0]+" "+mystr[1]+"</span>";
		            }
		            else
		            {
		                getfeatureview(1,10,mystr[0],mystr[1],mystr[2],$F('Text1'));
		                $('soustxt').innerHTML="您的搜素条件是 <span class=\"STYLE4\">"+mystr[0]+" "+mystr[1]+" "+mystr[2]+"</span>";
		            } 

		        }
		        else
		        {
		            getfeatureview(1,10,search,'','',$F('Text1').replace(/\'/g,""));
		             $('soustxt').innerHTML="您的搜素条件是 <span class=\"STYLE4\">"+mystr[0]+"</span>";
		        }
		        var tmp="";
		        if ($F('Text1')!="")
		        {
		            if ($F('Text1').replace(/\'/g,"")!="关键字：专题名称")
		            {  
						tmp =  " 关键字 <span class=\"STYLE4\">"+$F('Text1').replace(/\'/g,"")+"</span>"; }
		        }
		        
		        $('soustxt').innerHTML+=tmp;
		    }
		    else
		    {
		        var ss="";
		        if ($F('Text1').replace(/\'/g,"")!="")
		        {
		            if ($F('Text1').replace(/\'/g,"")!="关键字：专题名称")
		            {
		                ss =  " 关键字 <span class=\"STYLE4\">"+$F('Text1').replace(/\'/g,"")+"</span>";
		                $('soustxt').innerHTML="您的搜素条件是 "+ss;
		                }
		        }
		        getfeatureview(1,10,'','','',$F('Text1').replace(/\'/g,""));
		        
		    }
		}
		//ajax 调用list
        function getfeatureview(pageindex,pagesize,first,second,third,txt)
        {
            var postbody="pageindex="+pageindex+"&pagesize="+pagesize+"&first="+first+"&second="+second+"&third="+third+"&txt="+txt+"&random="+Math.random();
	        var myajax=new Ajax.Request
	         (
		          "/common/v3_featureview.aspx",
		          {
			          method:'post',
			          postBody: postbody,
			          onComplete:function showResponse(response)
			          {
				          $('ztdtlis').innerHTML=response.responseText;
			          }
        			  
		          }
	         )
        }
        //ajax 调用top 6
        function getfeatureview_istop()
        {
            var postbody="info=1&random="+Math.random();
	        var myajax=new Ajax.Request
	         (
		          "/common/v3_featureview.aspx",
		          {
			          method:'post',
			          postBody: postbody,
			          onComplete:function showResponse(response)
			          {
				          $('ztdt').innerHTML=response.responseText;
			          }
        			  
		          }
	         )
        }
        //ajax 调用点击率最高的
        function getfeatureview_ismoreclick()
        {
            var postbody="click=1&random="+Math.random();
	        var myajax=new Ajax.Request
	         (
		          "/common/v3_featureview.aspx",
		          {
			          method:'post',
			          postBody: postbody,
			          onComplete:function showResponse(response)
			          {
				          $('rmztsc').innerHTML=response.responseText;
			          }
        			  
		          }
	         )
        }

    // JavaScript Document
String.prototype.trim = function()
{
   return this.replace(/(^\s+)|\s+$/g,"");
}
//关闭全部Windows
function CloseAll()
{
window.parent.location.reload();
//window.close();   
	//form_data.closeAll();
}

//从这里开始第一步
//targetUrl:页面转到路径 如果targetUrl为空代表不需要转到页面 只是判断是否登陆 
//info:是否需要ajaxWindows Bool类型 [True代表需要ajaxWindow] [False代表location.href]
//Width:宽度 Height:高度 Title:弹出页面标题
//closeInfo:判断是否需要叶面右上角的关闭按钮 0：没有 1：有
//Request:传入参数 例如：id=1&type=1
var cookie="0";
function NeedCookieExam(targetUrl,info,Title,Width,Height,closeInfo,Request)
{
	//首先读取Cookie 如果为0 证明Cookie为空

	var request = "random="+Math.random();
	new Ajax.Request(
		'../common/ajaxCookie_Exam.aspx',
		{
			method: 'post',
			postBody: request,
			onComplete: function(response) 
			{
				cookie=response.responseText;
				if (cookie=="0") 
				{
					ajax_login_Exam(false, targetUrl,'登陆界面',info,Title,Width,Height,closeInfo,Request);
				} 
				else 
				{
					if (info == false)//如果不需要AjaxLogin 直接转到该页面
					{
						location.href = targetUrl;
					}
					else
					{
						Windows.closeAll();
						ajaxOpenDialogExam(targetUrl,Title,Width,Height,closeInfo,Request) 
					}
				}
			}
		}
	);
}

//此方法是为了调用登陆页面
var loginDialog = null;
var redirectUrl = '';
var userinfo;
var userTitle;
var userwidth;
var userheight;
var RequestString;
var usercloseInfo;
function ajax_login_Exam(force, targetUrl, ajaxtitle,info,title,width,height,closeInfo,Request) 
{
	loginDialog = new Window(
		{
			className: "bluelighting",
			title: ajaxtitle || "该页面需要登录",
			parent: document.body,
			width: 850,
			height: 470,
			destroyOnClose: true,
			recenterAuto: true,
			closable: !force,
			maximizable: false
		}
	);
	loginDialog.getContent().update('<div class="working-img"></div>');
	loginDialog.showCenter(true);
	new Ajax.Request(
		'../common/login.aspx',
		{
			method: 'post',
			onSuccess: function(transport) {
				loginDialog.getContent().innerHTML = transport.responseText;
				
				if (targetUrl) {
					redirectUrl = targetUrl;
					userinfo = info;
					userTitle = title;
					userwidth = width;
					userheight = height;
					usercloseInfo = closeInfo;
					RequestString = Request;
				} else {
					windows.location.reload();
				}
			}
		}
	);
}

//此方法调用转到页面的按钮事件[登陆按钮 后台进行代码处理判断]
function doLogin2()
{
	new Ajax.Request('../common/ajaxdo.aspx',
	{
		method: 'post',
		parameters: Form.serialize('login-form'),
		//parameters: request,
		onSuccess: function(request)
		{
			var data = request.responseText;
			if(data != "-1")// true 代表通过
			{
				//Windows.closeAll();
				if (redirectUrl!="")
				{
					if (userinfo==true)
					{
							ajaxOpenDialogExam(redirectUrl,userTitle,userwidth,userheight,usercloseInfo,RequestString);
						}
					else
					{	
						location.href = redirectUrl;
						location.reload();
						}
				}
				else
				{
					Windows.closeAll();
				}
			} 
			else 
			{
				displayError('login-error', '无法登录，请检查您的输入');
			}
		}
	}
	);
}

//根据已经弹出的AJAX对话框（登陆界面） 直接转到Url[目前专为TutorOrder编写]
function ajaxOpenDialogExam(url,title,width,height,closeInfo,Request) 
{

	if (Request!='')
	{	url = url + "?" + Request; }
	
	var c = true;//closable
	var m = false;//maximizable
	if (closeInfo=="0")//判断如果不需要关闭按钮的话
	{

		c = false;m=false;	
	}
	var dialog = new Window(
		{
			url: url, 
			className: "bluelighting",
			title: title,
			parent: document.body,
			width:width,
			height:height,
			destroyOnClose: true,
			recenterAuto: true,
			closable: c,
			minimizable: false,
			maximizable: false,
			//top:100, left:100,  width:300, height:200, zIndex:150, opacity:1, 
			resizable: true
		}
	);
	dialog.setDestroyOnClose();
    dialog.showCenter(true);

}
