﻿function getXmlhttp()
{
	var http_request;
	if(window.XMLHttpRequest) { 
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType("text/xml");
		}
	}
	else if (window.ActiveXObject) { 
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request) { 
		window.alert("can't create XMLHttpRequest object.");
		return null;
	}	
	return http_request;
}
function SubmitKeyClick(button) 
{    
 if (event.keyCode == 13) 
 {        
  event.keyCode=9;
  event.returnValue = false;
  getId(button).focus();
  getId(button).click(); 
 }
}
function ch(obje)
{
    getId("sn").className="out";
    getId("try").className="out";
    getId("sntext").style.display="none";
    getId("trytext").style.display="none";
    
    getId(obje).className="on";
    getId(obje+'text').style.display="block";
}
function ClickSch() 
{    
   var sch = getId("txtSch").value;
   var currselectvalue = getId("selSch").value;
   if(!isempty(sch))
   {
      window.location.href=currselectvalue+"?key="+escape(sch);
      return true;
   }
   else
   {
     alert("请输入搜索关键字!");
     getId("txtSch").focus();
     return false;
   }
}
function CertSch() 
{    
   var csch = getId("certSch").value;
   var cvalue = getId("certselSch").value;
   if(!isempty(csch))
   {
      window.location.href = cvalue+"&key="+escape(csch);
      return true;
   }
   else
   {
     alert("请输入查询关键字!");
     getId("certSch").focus();
     return false;
   }
}
function upGuest(vid,varpid,varUrl) 
{    
   var name = getId("txtName").value;
   var guest = getId("txtGuest").value;
   if(isempty(name))
   {
     alert("请输入姓名！");
     getId("txtName").focus();
     return false;
   }
   else if(isempty(guest))
   {
     alert("有何高见，畅所欲言！");
     getId("txtGuest").focus();
     return false;
   }
   else
   {
        var loadDiv = getId("upg"); // get the div
        loadDiv.style.display = "block"; //hide loading status
        var url = varUrl+"?type=upguest&id="+vid+"&pid="+varpid+"&user="+escape(name)+"&sign="+escape(guest);
    
		var xhttp = getXmlhttp();	
		xhttp.onreadystatechange = function()
		{	
		    if(xhttp.readyState == 4 && (xhttp.status==200 || window.location.href.indexOf("http")==-1))
		    {				
				    var re = xhttp.responseText;
                    loadDiv.style.display = "none";
				    if(re=="True")
				    {
				      getId("txtGuest").value="";
				      alert("评论已经成功提交，感谢关注本站。");
		              guestList(0,vid,varpid,varUrl);
				    }
				    else
				    {
				      alert(re);
				    }
		    }
	    }
	    xhttp.open("GET",url,true);
	    xhttp.send(null);
	    return; 
    }
}
function guestList(varpage,vid,varpid,varUrl) 
{    
   var ulguest = getId("ulguest");
    var loadDiv = getId("upg"); // get the div
    loadDiv.style.display = "block"; //hide loading status
    var url = varUrl+"?type=guestlist&page="+varpage+"&id="+vid+"&pid="+varpid;

	var xhttp = getXmlhttp();	
	xhttp.onreadystatechange = function()
	{	
	    if(xhttp.readyState == 4 && (xhttp.status==200 || window.location.href.indexOf("http")==-1))
	    {				
			    var re = xhttp.responseText;
                loadDiv.style.display = "none";
			    ulguest.innerHTML = re;
			    getId("labRemark").innerHTML = "评论（"+getId("lists").innerHTML+"）条";
	    }
    }
    xhttp.open("GET",url,true);
    xhttp.send(null);
    return; 
}
function getRead(vid,varpid,varUrl) 
{    
   var readtimes = getId("readtimes");
    var loadDiv = getId("upg"); // get the div
    loadDiv.style.display = "block"; //hide loading status
    var url = varUrl+"?type=read&id="+vid+"&pid="+varpid;

	var xhttp = getXmlhttp();	
	xhttp.onreadystatechange = function()
	{	
	    if(xhttp.readyState == 4 && (xhttp.status==200 || window.location.href.indexOf("http")==-1))
	    {				
			    var re = xhttp.responseText;
                loadDiv.style.display = "none";
			    readtimes.innerHTML = re;
	    }
    }
    xhttp.open("GET",url,true);
    xhttp.send(null);
    return; 
}
function getReport(vid,varUrl) 
{    
    var reporttimes = getId("reporttimes");
    var loadDiv = getId("upg"); // get the div
    loadDiv.style.display = "block"; //hide loading status
    var url = varUrl+"?type=report&id="+vid;

	var xhttp = getXmlhttp();	
	xhttp.onreadystatechange = function()
	{	
	    if(xhttp.readyState == 4 && (xhttp.status==200 || window.location.href.indexOf("http")==-1))
	    {				
			    var re = xhttp.responseText;
                loadDiv.style.display = "none";
			    reporttimes.innerHTML = re;
	    }
    }
    xhttp.open("GET",url,true);
    xhttp.send(null);
    return; 
}
function TryStudy(vid,varUrl) 
{    
    var tryTree = getId("tryTree");
    var loadDiv = getId("upg"); // get the div
    loadDiv.style.display = "block"; //hide loading status
    var url = varUrl+"?type=trystudy&id="+vid;

	var xhttp = getXmlhttp();	
	xhttp.onreadystatechange = function()
	{	
	    if(xhttp.readyState == 4 && (xhttp.status==200 || window.location.href.indexOf("http")==-1))
	    {				
			    var re = xhttp.responseText;
                loadDiv.style.display = "none";
                tryTree.innerHTML = re;
	    }
    }
    xhttp.open("GET",url,true);
    xhttp.send(null);
    return; 
}
function execInnerScript(innerhtml)
{  
  var temp=innerhtml.replace(/\n|\r/g,"");
  var regex=/<script.+?<\/script>/gi;
  var arr=temp.match(regex);  
  if(arr)
  {    
    for(var i=0;i<arr.length;i++)
    {      
      var temp=arr[i];      
      var reg=new RegExp("^<script(.+?)>(.+)<\/script>$","gi");
      reg.test(temp);                  
      eval(RegExp.$2);            
    }
  }  
}
function setInnerHTML(el, htmlCode)
{
        var ua = navigator.userAgent.toLowerCase();
        if (ua.indexOf('msie') >= 0 && ua.indexOf('opera') < 0)
        {
        htmlCode = '<div style="display:none">for IE</div>' + htmlCode;
        htmlCode = htmlCode.replace(/<script([^>]*)>/gi,'<script$1 defer>');
        el.innerHTML = htmlCode;
        el.removeChild(el.firstChild);
        }
        else {
        var el_next = el.nextSibling;
        var el_parent = el.parentNode;
        el_parent.removeChild(el);
        el.innerHTML = htmlCode;
        if (el_next) {
        el_parent.insertBefore(el, el_next)
        } else {
        el_parent.appendChild(el);
        }
    }
}
function getWether(varUrl) 
{    
    var labToday = getId("labToday");
    var loadDiv = getId("upg"); // get the div
    loadDiv.style.display = "block"; //hide loading status
    var url = varUrl+"?type=weather";

	var xhttp = getXmlhttp();	
	xhttp.onreadystatechange = function()
	{	
	    if(xhttp.readyState == 4 && (xhttp.status==200 || window.location.href.indexOf("http")==-1))
	    {				
			    var re = xhttp.responseText;
                loadDiv.style.display = "none";
			    labToday.innerHTML = re;
	    }
    }
    xhttp.open("GET",url,true);
    xhttp.send(null);
    return; 
}
function NoLogin(varUrl) 
{    
    var pOut = getId("pOut");
    var pIn = getId("pIn");
    var loadDiv = getId("upg"); // get the div
    loadDiv.style.display = "block"; //hide loading status
    var url = varUrl+"?type=userlogin";

	var xhttp = getXmlhttp();	
	xhttp.onreadystatechange = function()
	{	
	    if(xhttp.readyState == 4 && (xhttp.status==200 || window.location.href.indexOf("http")==-1))
	    {				
		    var re = xhttp.responseText;
            loadDiv.style.display = "none";
            if(re=="True")
            {   
		        pIn.style.display = "block";
		        pOut.style.display = "none";
		    }
		    else
		    {  
		        pIn.style.display = "none";
		        pOut.style.display = "block";
		        pOut.innerHTML = re;
                getId("txtName").value = getId("sUserId").innerHTML;
		    }
	    }
    }
    xhttp.open("GET",url,true);
    xhttp.send(null);
    return; 
}
function Login(varkey,varUrl) 
{    
    var txtUser = getId("txtUser").value;
    var txtPass = getId("txtPass").value;
    var pOut = getId("pOut");
    var pIn = getId("pIn");
    if(varkey == "login")
    {
        if(isempty(txtUser))
        {
           alert("用户名不能为空的!");
           getId("txtUser").focus();
           return false;
        }
        else if(isempty(txtPass))
        {
           alert("密码不能为空的!");
           getId("txtPass").focus();
           return false;
        }
     }
    var loadDiv = getId("upg"); // get the div
    loadDiv.style.display = "block"; //hide loading status
    var url = varUrl+"?type=login&id="+varkey+"&user="+escape(txtUser)+"&pass="+escape(txtPass);

    var xhttp = getXmlhttp();	
    xhttp.onreadystatechange = function()
    {	
        if(xhttp.readyState == 4 && (xhttp.status==200 || window.location.href.indexOf("http")==-1))
        {				
            var re = xhttp.responseText;
            loadDiv.style.display = "none";
            if(re=="True")
            {  //已经退出
                pIn.style.display = "block";
                pOut.style.display = "none";
                getId("txtPass").value = "";
                return false;
            }
            else if(re=="False")
            {
                alert("尝试登陆失败,请重试!");
                getId("txtUser").focus();
                return false;
            }
            else
            {
		        pOut.innerHTML = re;
                pIn.style.display = "none";
                pOut.style.display = "block";
                getId("txtName").value = txtUser;
                return false;
            }
        }
    }
    xhttp.open("GET",url,true);
    xhttp.send(null);
    return;
}