var w3c=(document.getElementById)? true:false;
var agt=navigator.userAgent.toLowerCase();
var ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1) && (agt.indexOf("omniweb") == -1));
var ie5=(w3c && ie)? true : false;
var ns6=(w3c && (navigator.appName=="Netscape"))? true: false;
var op8=(navigator.userAgent.toLowerCase().indexOf("opera")==-1)? false:true;

var sRootDir="../";

String.prototype.replaceAll = stringReplaceAll;

function stringReplaceAll(AFindText,ARepText){
 var raRegExp = new RegExp(AFindText.replace(/([\(\)\[\]\{\}\^\$\+\-\*\?\.\"\'\|\/\\])/g,"\\$1"),"ig");
 return this.replace(raRegExp,ARepText);
}

document.getElementsByClassName = function(className,oBox) {
 this.d= oBox || document;
 var children = this.d.getElementsByTagName('*') || document.all;
 var elements = new Array();
 for (var i = 0; i < children.length; i++) {
 var child = children[i];
 var classNames = child.className.split(' ');
 for (var j = 0; j < classNames.length; j++) {
 if (classNames[j] == className) {
 elements.push(child);
 break;
 }
 }
 }
 return elements;
}

function setCookie(name,value){
     var argv=setCookie.arguments;
     var argc=setCookie.arguments.length;
     var expires=(2<argc)?argv[2]:null;
     var path=(3<argc)?argv[3]:null;
     var domain=(4<argc)?argv[4]:null;
     var secure=(5<argc)?argv[5]:false;
     document.cookie=name+"="+escape(value)+((expires==null)?"":("; expires="+expires.toGMTString()))+((path==null)?"":("; path="+path))+((domain==null)?"":("; domain="+domain))+((secure==true)?"; secure":"");
} 

function getCookie(Name) {
 var search = Name + "=";
 var returnvalue = "";
 if (document.cookie.length > 0) {
  offset = document.cookie.indexOf(search);
  if (offset != -1) {      
   offset += search.length;
   end = document.cookie.indexOf(";", offset);                        
   if (end == -1)
   end = document.cookie.length;
   returnvalue=unescape(document.cookie.substring(offset,end));
  }
 }
 return returnvalue;
}


$Cls = function (s,o){
return document.getElementsByClassName(s,o);
};

function $(s){
	return document.getElementById(s)?document.getElementById(s):s;
}


function getIdx(s){
	return s.replace(/[^\d]/g,"");
}

function HitTree(e){
 var tag = ie ? e.srcElement : e.target;exCls(tag.parentNode,"open","close");
}

function SetEvt(o,a,b){
 ie?o.attachEvent("on"+a,b):o.addEventListener(a,b, false);
}

function exCls(o,a,b){
 o.className=(o.className.indexOf(a)!=-1)?b:a;
}


function movMod(){
	var arrMovModbox=$Cls("modTab",$("MovWrap"));
	doMovMod(arrMovModbox[0].id);
	var expdate=new Date();
	expdate.setTime(expdate.getTime()+(24*60*60*1000*30));
	setCookie("Move265Box",arrMovModbox[0].id,expdate,"/",null,false);
}

function doMovMod(s){
	try {
		var oMov=$(s);
		oMov.parentNode.appendChild(oMov);
		var oBtn1=$("btnMov_1");
		var oBtn2=$("btnMov_2");
		if (s.indexOf("Useful")!=-1) {
		   oBtn1.innerHTML="上移↑";
		   oBtn2.innerHTML="下移↓";
		} else {
		   oBtn1.innerHTML="下移↓";
		   oBtn2.innerHTML="上移↑";
		}
	} catch (e) {; }
}

function check(i){
 if(i.MailBox.options.selectedIndex==0){
	 alert("提示：请正确选择你使用的邮箱");
	 return false;
 } else {
	  var expdate=new Date();
	  expdate.setTime(expdate.getTime()+(24*60*60*1000*30));
	  setCookie("My265Mail",i.MailBox.value,expdate,"/",null,false);
 }
 if(i.Username.value=="" || i.Username.value=="请在此输入您的用户名"){
	 alert("提示：邮箱用户名必须填写！");
	 i.Username.focus();
	 return false;
 }
 if(i.Password.value=="" || i.Password.value.length<3){
	 alert("提示：邮箱密码必须填写完整！");
	 i.Password.focus();
	 return false;
 }
 i.submit();
}

function CP(input){
 input.Password.value="";
}

function init265Mail(){
	var sMail=getCookie("My265Mail");
	if (sMail!="") {
		var oSel=$("MailBox");
		for (var i=0;i<oSel.length;i++){
		   if (oSel[i].value==sMail) {
			 oSel[i].selected=true;
			 return(false);
		   }  
		}
	}
}

function initInp(o){
	if (o.className.indexOf("notClicked")!=-1) {
	  o.className=o.className.replace("notClicked","");
	  o.className=o.className.replaceAll("  "," ");
	  o.value="";
	}
	o.onblur=function(){
		if (o.value=="") {
		   o.className=o.className+" notClicked";
		   o.value="请在此输入您的用户名";
		}
	}
}

function doSearch(s){
	switch (s) {
	case "ZHSoForm" :
		if ($("Kaa").value=="") return(false);
		var arrChk=$("allSo").getElementsByTagName("input");
		var sTemp="";
		var u;
		var t=$("Kaa").value;
		u = 'Y:';
		for (var i=0;i<arrChk.length;i++) {
			if (arrChk[i].checked) {
				sTemp+="1";
				u+=getIdx(arrChk[i].id)+";";
				doSubmit(arrChk[i].value);
			} else {
				sTemp+="0";
			}
		}
		savZHSo(sTemp);

		break;
	default :
		var u;
		var t=$("Ka").value;
		u = 'G';
	}
}

function doSubmit(s){
	switch (s) {
	case "baidu" :
	     $("soNo").name="tn";
		 $("soNo").value="javeezhao_pg";
	     $("Kaa").name="word";
		 $("ZHSoForm").action="http://www.baidu.com/baidu";
		 $("ZHSoForm").submit();
		 break;
	case "joyo" :
	     $("soNo").name="source";
		 $("soNo").value="javee";
	     $("Kaa").name="searchWord";
		 $("ZHSoForm").action="http://www.amazon.cn/search/search.asp";
		 $("ZHSoForm").submit();
		 break;
	case "google" :
	     $("soNo").name="client";
		 $("soNo").value="pub-3455104598199370";
	     $("Kaa").name="q";
		 $("ZHSoForm").action="http://www.google.cn/search";
		 $("ZHSoForm").submit();
		 break;
	case "ciba" :
	     $("soNo").name="t";
		 $("soNo").value="word";
	     $("Kaa").name="s";
		 $("ZHSoForm").action="http://www.iciba.com/search";
		 $("ZHSoForm").submit();
		 break;
	default :
	     $("soNo").name="NO";
		 $("soNo").value=s;
	     $("Kaa").name="Key";
		 $("ZHSoForm").action="http://www.superso.cn/go.asp";
		 $("ZHSoForm").submit();
	}

}


function savZHSo(s){
  var expdate=new Date();
  expdate.setTime(expdate.getTime()+(24*60*60*1000*30));
  setCookie("MyZHSo",s,expdate,"/",null,false);
}


function init265ZHSo(){
	var sMySo=getCookie("MyZHSo");
	var arrInp=$("allSo").getElementsByTagName("input");
	if (sMySo.length>=15) {
		for(var i=0;i<arrInp.length;i++) {
		  arrInp[i].checked=(sMySo.charAt(i)=="1");
		}
	}
}

function init265Home(){
	sRootDir="";
	So(1);
	initAjaxTAB("famTAB","usefulTAB");
	doMovMod(getCookie("Move265Box"));

	init265ZHSo();
	init265Mail();
	resetMyTag();
	$("setting_famousSite").onclick=function(){
	setMyFavSite();
	}
	if (ie) {
		$("SetHome").onclick=function(){
		this.style.behavior='url(#default#homepage)';
		this.setHomePage('http://www.ok881.com/');
		return(false);
		}
	} else {
		$("SetHome").innerHTML="";
	}
}

function sav265Cookie(sName,sValue){
	var expdate=new Date();
	expdate.setTime(expdate.getTime()+(24*60*60*1000*30));
	setCookie(sName,sValue,expdate,"/",null,false);
}

function CNLTree(id,ClsOpen,ClsClose,ClsChild){
 this.id=id;
 this.ClassOpen=ClsOpen || "open";
 this.ClassClose=ClsClose || "close";
 this.ClassChild=ClsChild || "child";
 this.AddEvt = function () {
  var arrObj=$(this.id).getElementsByTagName("img");
  for (var i=0;i<arrObj.length; i++) {
   if (arrObj[i].className=="s") {
     SetEvt(arrObj[i],"click",HitTree);
	 ie?arrObj[i].style.cursor="hand":"";
   }
  }
 }
}

//window.onerror=function(){return true;}

function clock() {
window.open('time/clock.htm','time','left='+(screen.width-380)+',height=310,width=305,status=no,toolbar=no,menubar=no')
}
function luck() {
window.open('time/luck.htm','time','left='+(screen.width-380)+',height=310,width=305,status=no,toolbar=no,menubar=no')
}

//Function for subpage
function copyToClipBoard(){
			 var clipBoardContent="";	 
             clipBoardContent+=document.title;
			 clipBoardContent+=window.location;
			 window.clipboardData.setData("Text",clipBoardContent);
			 alert("复制成功，请粘贴到你的QQ/MSN上推荐给你的好友");
		}

function addfavr(){
var favr_url="";
var favr_title="";
favr_title+=document.title;
if(favr_title==""){
			favr_title+="无主题网址（请在此修改要收藏网址的标题内容）";			
		}
favr_url+=window.location;
window.external.AddFavorite(favr_url,favr_title);
		}
