//杨老师的 function.js
//在 include 目录下
var appName = "";
var WEBROOT="";
//var WEBROOT="";

function Browser(){var ua,s,i;this.isIE= false;this.isNS= false; this.version = null;ua=navigator.userAgent;s="MSIE";if ((i=ua.indexOf(s))>= 0) {this.isIE=true;this.version = parseFloat(ua.substr(i + s.length));return;}s="Netscape6/";if ((i = ua.indexOf(s)) >= 0) {this.isNS = true;this.version = parseFloat(ua.substr(i + s.length));return;}s="Gecko";if ((i = ua.indexOf(s)) >= 0) {this.isNS = true;this.version = 6.1;return;}}

function LoginIn(obj,flag)
{
	//var mydate = new Date();
	var loc="../LoginServlet";
	var userMsg = "userid="+loginForm.userid.value+"&password="+loginForm.userpass.value;
	var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp.open("POST",loc,false);
	xmlhttp.setRequestHeader("Content-Length",loc.length);
	xmlhttp.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded");
	xmlhttp.send(userMsg)
	var feedback = xmlhttp.responseText;
	var count= -1;
	//alert(feedback);
	try{
	count = parseInt(feedback.split("#$")[0]);
	}catch(e){count=-1;}


	if (count!=1 && count !=2 && count !=4 && count !=5 && count != 7)
	{
		if(loginForm.userpass.value=="666666" || loginForm.userpass.value=="888888" || loginForm.userpass.value=="66666666" || loginForm.userpass.value=="88888888"){
			alert("请修改初始密码后登录！");
		return;
		}
			else{
	/*	mydate.setTime(mydate.getTime + 48*60*60*1000);
		setCookie("uname", count.split("#$")[0], mydate, "", "", "") ;
		setCookie("uchannelid", count.split("#$")[1], mydate, "", "", "") ;
		alert(getCookie("uname")+"---"+getCookie("uchannelid"));*/

		//var feedback= count.split("#$");
		if(flag && flag == 'app'){
			url_ = WEBROOT+"/govweb/LoginApp.jsp?" + document.getElementById("lastreq").value;
			obj.href=url_;
			return true;
		}
		else if(count == 6){
			alert("警告：您已在其他位置进行登录，其他位置会话将自动退出！");
			resetTableMsg(feedback.split("#$")[1]);
		}else if(count == 9)
			resetTableMsg(feedback.split("#$")[1]);
		}
	}
	else
	{
		var n = feedback.split("#$")[1];
		if(n && n >3 && n<=5){
			alert("您已连续输入" + n + " 次错误密码，还有" + (5-n) + "登录机会！");
		}else if(n>5){
			alert("对不起，您已经重复输入错误 " + n + " 次密码，在1小时内将不允许再次登录!");
		}else
			alert("用户名或密码无效，请重新登录！");
		return;
	}
}


function loginKey(e)
 {
   if(e.keyCode == 13)
   {
      document.form2.userpass.focus(0);
    }
 }

 function checkInfoKey(e) 
 {
   if(e.keyCode == 13)
   {
	  LoginIn();
   }	
 }

function getUserMsg()
{
//	var loc="../SessionMsg";
	var loc="../LoginServlet?action=getstatus"
	var userMsg = "";
	var xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp2.open("POST",loc,false);
	xmlhttp2.setRequestHeader("Content-Length",loc.length);
	xmlhttp2.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded");
	xmlhttp2.send(userMsg)
	var count= xmlhttp2.responseText;

	return count;
}

function getUserStatus()
{
	if(getUserMsg().split("#").length!=0)
	{
		if(getUserMsg().split("#")[0]!="null")
		{
			resetTableMsg(getUserMsg().split("#")[0]);
		}
		else
		{
			//getCertUserMsg();
		}
	}
}

function getCertUserMsg()
{
	var loc="../GetCertMsgServlet";
	var userMsg = "";
	var xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp2.open("POST",loc,false);
	xmlhttp2.setRequestHeader("Content-Length",loc.length);
	xmlhttp2.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded");
	xmlhttp2.send(userMsg)
	var count= xmlhttp2.responseText;
	if(count!="" && count !="null")
	{
		document.loginForm.userid.value=count;
		document.loginForm.userid.readOnly=true;
	}
	else
	{
		document.loginForm.userid.readOnly=false;
	}
}

function resetTableMsg(userName)
{

	if(!userName || userName == ""){
		resetLoginTable();
		return;
	}
	for (i=0;i<=document.all.userstatus.rows.length;i++)
	{
		document.all.userstatus.deleteRow(document.all.userstatus.rows.length-1);
		i=0;
	}

	var tempR=document.all.userstatus.insertRow();
	tempR.bgcolor="#FFFFFF";
	var temp1=tempR.insertCell();
	temp1.height="50";
	temp1.colspan="2";
	temp1.align="center";
	temp1.innerHTML=userName+" 欢迎您的到来！";
	var tempR2=document.all.userstatus.insertRow();
	tempR2.bgcolor="#FFFFFF";
	var temp2=tempR2.insertCell();
	temp2.height="30";
	temp2.colspan="2";
	temp2.align="center";
	temp2.innerHTML="<a href=\"JavaScript:Logout()\" ><img src=\"images/login_10.gif\" width=\"70\" height=\"19\" border=\"0\"></a>";
}

function Logout()
{
	var userInfo="";
	var oBao = new ActiveXObject("Microsoft.XMLHTTP");
	oBao.open("POST","include/quit.jsp",false);
	oBao.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	oBao.send(userInfo);
	var info = oBao.responseText;
	alert(info);

	for (i=0;i<=document.all.userstatus.rows.length;i++)
	{
		document.all.userstatus.deleteRow(document.all.userstatus.rows.length-1);
		i=0;
	}

	var tempR=document.all.userstatus.insertRow();
	tempR.bgcolor="#FFFFFF";
	var temp1=tempR.insertCell();
	temp1.height="29";
	temp1.width="66";
	temp1.align="right";
	temp1.innerHTML="用户名：";
	var temp2=tempR.insertCell();
	temp2.width="104";
	temp2.innerHTML="<input name=\"userid\" type=\"text\" style=\"width:105px;\" onKeyDown=\"loginKey(event)\">";

	var tempR2=document.all.userstatus.insertRow();
	var temp1=tempR2.insertCell();
	temp1.height="21";
	temp1.align="right";
	temp1.innerHTML="密&nbsp; 码：";
	var temp2=tempR2.insertCell();
	temp2.innerHTML="<input name=\"userpass\" type=\"password\" style=\"width:105px;\" onKeyDown=\"checkInfoKey(event)\">";

	var tempR3=document.all.userstatus.insertRow();
	tempR3.bgcolor="#FFFFFF";

	var temp3=tempR3.insertCell();
	temp3.colSpan=2;
	temp3.height="30";
	temp3.align="center";
	temp3.innerHTML="<a href=\"JavaScript:LoginIn()\"><img src=\"images/login_08.gif\" width=\"42\" height=\"19\"></a> &nbsp;&nbsp; <a href=\"include/changepass.htm\" target=\"_blank\"><img src=\"images/login_11.gif\" width=\"62\" height=\"19\"></a>";
	//getCertUserMsg();
}

function resetLoginTable(){
	for (i=0;i<=document.all.userstatus.rows.length;i++)
	{
		document.all.userstatus.deleteRow(document.all.userstatus.rows.length-1);
		i=0;
	}

	var tempR=document.all.userstatus.insertRow();
	tempR.bgcolor="#FFFFFF";
	var temp1=tempR.insertCell();
	temp1.height="29";
	temp1.width="66";
	temp1.align="right";
	temp1.innerHTML="用户名：";
	var temp2=tempR.insertCell();
	temp2.width="104";
	temp2.innerHTML="<input name=\"userid\" type=\"text\" style=\"width:105px;\" onKeyDown=\"loginKey(event)\">";

	var tempR2=document.all.userstatus.insertRow();
	var temp1=tempR2.insertCell();
	temp1.height="21";
	temp1.align="right";
	temp1.innerHTML="密&nbsp; 码：";
	var temp2=tempR2.insertCell();
	temp2.innerHTML="<input name=\"userpass\" type=\"password\" style=\"width:105px;\" onKeyDown=\"checkInfoKey(event)\">";

	var tempR3=document.all.userstatus.insertRow();
	tempR3.bgcolor="#FFFFFF";

	var temp3=tempR3.insertCell();
	temp3.colSpan=2;
	temp3.height="30";
	temp3.align="center";
	temp3.innerHTML="<a href=\"JavaScript:LoginIn()\"><img src=\"images/login_08.gif\" width=\"42\" height=\"19\"></a> &nbsp;&nbsp; <a href=\"include/changepass.htm\" target=\"_blank\"><img src=\"images/login_11.gif\" width=\"62\" height=\"19\"></a>";
	
}

function destoryLogout(){
	var oBao = new ActiveXObject("Microsoft.XMLHTTP");
	oBao.open("POST","include/quit.jsp",false);
	oBao.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	oBao.send(userInfo);
}

function keyListener()
{
	if(event.srcElement.channelclass=='F')
	{	
		if(getUserMsg().split("#")[0]=="null")
		{
			alert("该栏目需要登录后才能浏览！");
			return false
		}
	}
}

function addKeyListener() {
    var inputList = document.body.getElementsByTagName("A");
    if(inputList[0]) firstInput = inputList[0];
    for(var i=0;i<inputList.length;i++) {
      inputList[i].attachEvent ('onclick', keyListener);
   }
	//clear(); //清空用户查看到的源代码（段体田）
}


//清空用户查看到的源代码（段体田）：开始
function clear(){ 
	Source=document.body.firstChild.data; 
	document.open(); 
	document.close(); 
	document.title="河南省电子政务外网"; 
	document.body.innerHTML=Source; 
} 
//清空用户查看到的源代码（段体田）：结束

/*
function loginApp(appName)
{
	alert("登录：" + appName);
	var h=screen.height;
	var w=screen.width;
	var scrollsign="yes";
    var para = para =  "height="+h+", width="+w+",toolbar=yes, menubar=yes, scrollbars="+scrollsign+", resizable=no, location=yes, status=yes,top=0,left=0";
	if(appName=="jcyt")
	{
		w="720";
		h="460";
		scrollsign="no";
		para =  "height="+h+", width="+w+",toolbar=yes, menubar=yes, scrollbars="+scrollsign+", resizable=no, location=yes, status=yes";
	}
	var theURL="/govweb/login.jsp?appName="+appName;
	window.open (theURL, "河南省电子政务外网登录系统");
}
*/
//2009-05-04 Modify by Sivyer
function loginApp(appName,resurl)
{
//	alert(resurl);
	var h=screen.height;
	var w=screen.width;
	var scrollsign="yes";
    var para = para =  "height="+h+", width="+w+",toolbar=yes, menubar=yes, scrollbars="+scrollsign+", resizable=no, location=yes, status=yes,top=0,left=0";
	if(appName=="jcyt")
	{
		w="720";
		h="460";
		scrollsign="no";
		para =  "height="+h+", width="+w+",toolbar=yes, menubar=yes, scrollbars="+scrollsign+", resizable=no, location=yes, status=yes";
	}
	//var theURL="login.jsp?appName="+appName;
	var theURL=WEBROOT + "/govweb/LoginApp.jsp?action=loginApp&appName="+appName;
	if(resurl)
		theURL += "&resurl=" + resurl;
	window.open (theURL, "河南省电子政务外网登录系统");
}

function loadIptv(){
	AppBeanJS.getForwardHTMLPage('http://iptv.hazw.gov.cn/index.php?option=com_shinvy_index&Itemid=210','UTF-8','',function(result){
		$("iptvDiv").innerHTML = result;
	});
}
function loadBlog(){
	AppBeanJS.getForwardHTMLPage('http://blog.hazw.gov.cn/recentlist_govweb.jsp','UTF-8','',function(result){
		$("blogDiv").innerHTML = result;
	});
}
function loadWeather(){
	AppBeanJS.getForwardHTMLPage('http://www.hnnw.net/file/public/weather.htm','gb2312','',function(result){
		$("weather").innerHTML = result;
	});
}
function loadBBS(){
	AppBeanJS.getForwardHTMLPage('http://comm.hazw.gov.cn/lybbs/homePageNewTopic_govweb.jsp','GBK','',function(result){
		$("commDiv").innerHTML = result;
	});
}

function initApp(){
	loadIptv();	
	loadBlog();
	loadWeather();
	loadBBS();
}
var browser = new  Browser();
var css7 = browser.version >= 7;





