﻿

function $(vid){return document.getElementById(vid);}

//clear space
String.prototype.trim = function()   
{   
    return this.replace(/(^\s*)|(\s*$)/g, "");   
}

function SearchClient()
{
 var key=$('key').value.trim().replace('"', ' ').replace('*', ' ').replace('-',' ');
if (key.length < 2) {
alert("关键词必须2个字以上");
return false;
}
// if(key=="")
// {
//  alert("请输入搜索关键字");
//  $('key').focus();
// }
// else
// {
  window.location.href="/search/"+encodeURIComponent(key)+"-"+$('category').value+"-"+$('type').value+".html";
// }
 return false;
}

function Search(index)
{
var key="";
var category="0";
var type="0";
if(index==0){
key=$('header_txtKey').value.trim();
category=$('header_ddlCategory').value;
type=$('header_ddlType').value;
}
if(index==1){
key=$('txtKey').value.trim();
category=$('ddlCategory').value;
type=$('ddlType').value;
}
key=key.replace('"', ' ').replace('*', ' ').replace('-',' ');
if (key.length < 2) {
alert("关键词必须2个字以上");
return false;
}
window.location.href="/search/"+encodeURIComponent(key)+"-"+category+"-"+type+".html";
}

function getFocus(index)
{
 if(event.keyCode==13)
 {
    var btn=null;
    switch(index)
    {
     case 0:
      btn=$('header_ibSearch');
       break;
     case 1:
      btn=$('ibSearch');
       break;
     case 2:
      btn=$('login_btnLogin');
       break;
     case 3:
      btn=$('btnLogin');
       break;
    }
    
    if(btn!=null)
    {
     btn.focus();
    }
 }
}

function AddFav(num){
	if(num==0){
		url = "http://www.xuehi.com";
		title = "学海网_专业教育资源分享平台";
	}else{
		url = document.location.href;
		title = document.title;
	}	
 if ( window.sidebar && "object" == typeof( window.sidebar ) && "function" == typeof( window.sidebar.addPanel ) ){
   //  firefox
   window.sidebar.addPanel( title, url, '' );
 }else if ( document.all && "object" == typeof( window.external ) ){
   //  ie
   window.external.addFavorite( url, title );
 }
}

function copyToClipBoard(str)
{
 var clipBoardContent=str;
 clipBoardContent+=':' + window.document.location.href;
 window.clipboardData.setData("Text",clipBoardContent);
 alert("复制成功，请粘贴到你的QQ/MSN上推荐给你的好友！\r\n\r\n内容如下：\r\n\r\n" + clipBoardContent);
}

function doZoom(size){
		var content = document.getElementById('content');
		if(!content){
			return;
		}
		var contentChild = content.childNodes;
		content.style.fontSize = size + 'px';
		//对content div内的直接html节点设置fontSize属性
		for(var i = 0; i < contentChild.length; i++){
			if(contentChild[i].nodeType == 1){
				contentChild[i].style.fontSize = size + 'px';
			}
		}		
	}

window.defaultStatus = "学海网_专业教育资源分享平台(www.xuehi.com)";
//window.onload=SetInputStyle;

function SetInputStyle()
{
 var inputs = document.getElementsByTagName("input");
 for(var i=0; i<inputs.length; i++){
   if(inputs[i].type=="text"||inputs[i].type=="password")
   {
     SetEvent(inputs[i]);
   }
  }
   
  var textareas = document.getElementsByTagName("textarea");
 for(var i=0; i<textareas.length; i++){
     SetEvent(textareas[i]);
 }
}

function SetEvent(obj)
{
 if(window.addEventListener){ 
       obj.addEventListener("onfocus", SetValue(obj,"textfocus"), false);
       obj.addEventListener("onblur", SetValue(obj,"textbox"), false);
   } else {
        obj.attachEvent('onfocus',SetValue(obj,"textfocus"));
        obj.attachEvent('onblur',SetValue(obj,"textbox"));
    }
}

var SetValue = function(obj,par1)
{
  return function()
   {
     obj.className=par1;
   }
}


function FloatTop() {
    var obj = document.getElementById("divQQbox");
if(obj!=null){
    var scrollTop = window.pageYOffset
            || document.documentElement.scrollTop
            || document.body.scrollTop
            || 0;
    obj.style.top = (parseInt(scrollTop) + 230) + "px";
    obj.style.left = "0px";
}
}
//FloatTop();

window.onscroll = FloatTop;

window.onresize = FloatTop;
//FloatTop();

function thisQQiframeclose() {
    document.getElementById("qqdiv1").style.display = "none";
    document.getElementById("qqdiv2").style.display = "block";
}
function thisQQiframeopen() {
    document.getElementById("qqdiv1").style.display = "block";
    document.getElementById("qqdiv2").style.display = "none";
}



var action;
function getHelp()
{
 action="help";
 var url="/ajax.aspx?module=help&id="+$("id").value;
 getAjax(url);
}
function getArticle()
{
 action="article";
 var url="/ajax.aspx?module=article&id="+$("id").value;
 getAjax(url);
}
function getDocs() {
    var html = "";
html+="<div id=\"divQQbox\" style=\"position:absolute;\">";
html+="<div class=\"fkz\" id=\"qqdiv1\">";
html+="<div class=\"kf_l01\" onclick=\"thisQQiframeclose()\" title=\"点击关闭\"><\/div>";
html+="<div class=\"kf_l02\">";
html+="<a target=\"_blank\" href=\"http://wpa.qq.com\/msgrd?v=3&uin=85948366&site=qq&menu=yes\" onclick=\"javascript:alert('请免去“你好”、“在吗”等等，需要什么帮助请直接说，谢谢合作')\"><img border=\"0\" src=\"http:\/\/wpa.qq.com\/pa?p=2:85948366:41 &r=0.4971184712931811\" alt=\"点击这里和网站客服QQ联系\" title=\"点击这里和网站客服QQ联系\"><\/a><br />";
html += "<a target=\"_blank\" href=\"http://wpa.qq.com\/msgrd?v=3&uin=5739126&site=qq&menu=yes\" onclick=\"javascript:alert('请免去“你好”、“在吗”等等，需要什么帮助请直接说，谢谢合作')\"><img border=\"0\" src=\"http:\/\/wpa.qq.com\/pa?p=2:5739126:41 &r=0.4971184712931811\" alt=\"点击这里投诉\" title=\"点击这里投诉\"><\/a><br />";
html += "&nbsp;&nbsp;&nbsp;&nbsp;论文代写:<br><a target=\"_blank\" href=\"http://wpa.qq.com\/msgrd?v=3&uin=85948366&site=qq&menu=yes\" onclick=\"javascript:alert('请免去“你好”、“在吗”等等，需要什么帮助请直接说，谢谢合作')\"><img border=\"0\" src=\"http:\/\/wpa.qq.com\/pa?p=2:85948366:41 &r=0.4971184712931811\" alt=\"论文代写、论文发表\" title=\"论文代写、论文发表\"><\/a><br />";
html+="<\/div>";
html+="<div class='kf_l03'>";
html+="<\/div>";
html+="<\/div>";
html+="<div id=\"qqdiv2\" style=\"display:none;\" title=\"点击展开\">";
html+="<img src=\"http:\/\/r.alocne.cn\/images\/kest.png\" style=\"cursor:pointer; \" title=\"点击展开\" onclick=\"thisQQiframeopen()\" \/>";
html+="<\/div>";
html+="<\/div>";

var objdiv = document.createElement("div");
objdiv.innerHTML = html;
document.body.appendChild(objdiv);
FloatTop();

'var tempdiv=document.createElement("div");
'tempdiv.innerHTML = "<span style='padding-left:20px;color:red'>注意:下载服务器正在升级，如果下载失败，请与客服联系</span>";
'document.getElementById("downaddress").appendChild(tempdiv);

 action="docs";
 var url="/ajax.aspx?module=docs&id="+$("id").value;
 getAjax(url);
}
function getDefault()
{
 action="default";
 var url="/ajax.aspx?module=default";
 getAjax(url);
}
function getAjax(url)
{
 http_request=CreateRequest();
 http_request.onreadystatechange = process;   
http_request.open("GET", url, true);   
http_request.send(null);
}

function process() {   
if (http_request.readyState == 4) {    
if (http_request.status == 200) {    
if(http_request.responseText!="")
{
var username;
var str= new Array(); 
switch(action)
{
case "default":
username=http_request.responseText;
if(username!=""){
$("default_login").innerHTML="	欢迎您，"+username;
}
case "help":
username=http_request.responseText;
break;
case "article":   
str=http_request.responseText.split("|");       
username=str[0];
$("click").innerHTML=str[1];
break;
case "docs":
str=http_request.responseText.split("|");       
username=str[0];
$("click").innerHTML=str[1];
$("down").innerHTML=str[2];
break;
}
if(username!=""){
$("top_login").innerHTML="欢迎您：<a href='http://www.xuehi.com/user/'>"+username+"</a> | <a href='http://www.xuehi.com/user/login.aspx?action=logout'>退出登录</a>";
}
}
}
}
}


function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

addLoadEvent(SetInputStyle);

var http_request = false;
function CreateRequest() {
http_request=false;
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("不能创建XMLHttpRequest对象实例.");
return null;
}
return http_request;
}


