// JavaScript Document
function ShowTime() 
{
	var days=new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
	var sDate=new Date();
	var year=sDate.getYear();
	var month=sDate.getMonth() + 1 ;
	var date=sDate.getDate();
	var sDate=new Date();
	var hours=sDate.getHours();
	var minutes=sDate.getMinutes();
	var seconds=sDate.getSeconds();
	if (month<10) 
  	month="0"+month;
	if (date<10) 
  		date="0"+date;
	if (hours<10) 
  		hours="0"+hours;
	if (minutes<10) 
  		minutes="0"+minutes;
	if (seconds<10) 
		seconds="0"+seconds;
	var sTimer=document.getElementById('sTimer');
	sTimer.innerHTML=year+"年"+month+"月"+date+"日&nbsp;&nbsp;</a><font color=\"#FF0000\">"+days[sDate.getDay()]+"</font>&nbsp;&nbsp;"+hours+":"+minutes+":"+seconds;
	
	setTimeout("ShowTime()",1000);
}
function clearTitle(inputID)
{
	var inputObj=document.getElementById(inputID);
	if(inputObj.value=='请输入要查询的关键字')
	{
		inputObj.value='';
		return;
	}
	else
	{
		return;
	}
}
function addTitle(inputID)
{
	var inputObj=document.getElementById(inputID);
	if(inputObj.value=='')
	{
		inputObj.value='请输入要查询的关键字';
		return;
	}
	else
	{
		return;
	}
}
function ExpandDiv(el) {
  DivEl=eval(el+"Child");
  ImgEl=eval("Img"+el);
  if (DivEl.style.display == "block") {
    DivEl.style.display="none";
    ImgEl.src="picture/plus.gif";
  } else {
    DivEl.style.display="block";
    ImgEl.src="picture/minus.gif";
  }
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//生成ajax对象
function initxmlhttp()
{
  	var xmlhttp
  	try 
  	{
   	 xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
  	 } 
  	 catch (e) 
  	 {
    	 try 
		 {
      	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
     	} 
	 	catch (E) 
	 	{
       	 xmlhttp=false;
     	}
  	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined')
	{
		try {
                xmlhttp = new XMLHttpRequest();
        	} 
			catch (e) 
			{
                xmlhttp=false;
        	}
	}
	if (!xmlhttp && window.createRequest) 
	{
        try 
		{
                xmlhttp = window.createRequest();
        } 
		catch (e) 
		{
                xmlhttp=false;
        }
	}
  	return xmlhttp;
}
//内容请求处理
function startxmlRequet(requrl,contenter)
{
	var contenterObj=document.getElementById(contenter);
	var requestObj=initxmlhttp();
	requestObj.open("GET",requrl,true);
  	requestObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  	requestObj.onreadystatechange=function()
  	{
		if(requestObj.readyState==4 && requestObj.status==200)
		{
			contenterObj.innerHTML=requestObj.responseText;
		}
		else
		{
			contenterObj.innerHTML='加载中......';
		}
	}
	requestObj.send(null);
}
//页面的初始化
function startInitXmlRequest()
{
	startxmlRequet('phpScript/newsHandle.php','dynamic');
	startxmlRequet('phpScript/ForumInfo.php','information2');
}
//页面无刷新登陆处理
function loginHandle(u_name,u_pass,s_code)
{
	var content='name='+u_name+'&pass='+u_pass+'&surecode='+s_code;
	var loginRequestObj=initxmlhttp();
	loginRequestObj.open("POST",'ajaxLoginHandle.php',true);
  	loginRequestObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	loginRequestObj.onreadystatechange=function()
  	{
		if(loginRequestObj.readyState==4 && loginRequestObj.status==200)
		{
			var responseContent=loginRequestObj.responseText;
			var flag=parseInt(responseContent,10);
			if(flag=='2')
			{
				alert('用户不存在，你没有注册，或你输入的用户名或密码错误！');
			}
			else if(flag=='3')
			{
				alert('验证码错误！');
			}
			else
			{
				var tObj=document.getElementById('loginTable');
				tObj.rows(1).cells(0).innerHTML='你好：'+loginRequestObj.responseText;
				tObj.rows(3).cells(0).innerHTML='';
				tObj.rows(5).cells(0).innerHTML='';
				tObj.rows(6).cells(1).innerHTML='<a href="javascript::" onclick="logout();return false">安全退出</a>';
			}
		}		
	}
	loginRequestObj.send(content);
}
//登陆数据输入校验
function checkLogoinData()
{
	if(document.getElementById('userName').value=='')
	{
		document.getElementById('userName').focus();
		alert('请输入用户！');
		return false;
	}
	if(document.getElementById('userPass').value=='')
	{
		document.getElementById('userPass').focus();
		alert('请输入密码！');
		return false;
	}
	if(document.getElementById('sureCode').value=='')
	{
		document.getElementById('sureCode').focus();
		alert('请输入验证码！');
		return false;
	}
	else
	{
		loginHandle(document.getElementById('userName').value,document.getElementById('userPass').value,document.getElementById('sureCode').value);
		return false;
	}
}
function logout()
{
	var logoutObj=initxmlhttp();
	logoutObj.open("GET",'logout.php',true);
  	logoutObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	logoutObj.onreadystatechange=function()
  	{
		if(logoutObj.readyState==4 && logoutObj.status==200)
		{
			window.location.reload();
		}		
	}
	logoutObj.send(null);
}
function loginInfo()
{
	var cookies=document.cookie;
	var userIndex=cookies.indexOf ("; userName=");
	if(userIndex>0)
	{
		var username=cookies.split('; userName=');
		var tObj=document.getElementById('loginTable');
		tObj.rows(1).cells(0).innerHTML='你好：'+username[1];
		tObj.rows(3).cells(0).innerHTML='';
		tObj.rows(5).cells(0).innerHTML='';
		tObj.rows(6).cells(1).innerHTML='<a href="javascript::" onclick="logout();return false">安全退出</a>';
	}	
}

