﻿

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();
// if(key=="")
// {
//  alert("请输入搜索关键字");
//  $('key').focus();
// }
// else
// {
  window.location.href="/search/"+escape(key)+"-"+$('category').value+"-"+$('type').value+".html";
// }
 return false;
}

function Search(index)
{
// var key=$('header_txtKey');
// if(index==1){key=$('txtKey');}
// if(key.value.trim()=="")
// {
//  alert("请输入搜索关键字");
//  key.focus();
//  return false;
// }
}

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;
   }
}