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;

String.prototype.replaceAll = function(s1,s2){
this.str=this;
if(s1.length==0)return this.str;
 var idx=this.str.indexOf(s1);
 while(idx>=0){
 this.str=this.str.substring(0, idx)+s2+this.str.substr(idx+s1.length);
 idx=this.str.indexOf(s1);
 }
 return this.str;
}

var sRootDir="../"; //临时路径

function $(o){
 var o=document.getElementById(o)?document.getElementById(o):o;
 return o;
}

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;
}

$Cls = function (s,o){
return document.getElementsByClassName(s,o);
};

function ExCls(o,a,b){
 o.className=(o.className.indexOf(a)!=-1)?b:a;
}

function addCls(o,s){
 if (o.className.length>0) {
	 o.className+=" "+s;
 } else {
	 o.className=s;
 }
}

function delCls(o,s){
 o.className=o.className.replace(s,"");
  o.className=o.className.replaceAll("  ","");
}


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;
}


function MySkin(n){
 var sHtml="";
 sHtml="&nbsp;&nbsp;<a href=\"about:blank\" title=\"比直接打开IE浏览器更快、更方便！\" target=\"_blank\">打开空白页</a>&nbsp;";
 sHtml="<p id=\"OrdSkin\">"+sHtml+"</p>";
 document.write (sHtml);
}


function HitFam(n1,n2){
 for (var i=1;i<=n2;i++) {
   if (i==n1) {
	$("FamTab"+i).className="active";
	$("famSiteBox"+i).className="famSiteBox";
   } else {
 	$("FamTab"+i).className="";
	$("famSiteBox"+i).className="hidden";
   }
 }
}

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 gt(f){
 var t;
 var u;
 if(f.a0 != undefined){
  u = 'Y:';
  t = f.q.value;
  if(f.a0.checked==true){u+='0;';}
  if(f.a1.checked==true){u+='1;';}
  if(f.a2.checked==true){u+='2;';}
  if(f.a3.checked==true){u+='3;';}
  if(f.a4.checked==true){u+='4;';}
  if(f.a5.checked==true){u+='5;';}
  if(f.a6.checked==true){u+='6;';}
  if(f.a7.checked==true){u+='7;';}
  if(f.a8.checked==true){u+='8;';}
  if(f.a9.checked==true){u+='9;';}
  if(f.a10.checked==true){u+='10;';}
  if(f.a11.checked==true){u+='11;';}
  if(f.a12.checked==true){u+='12;';}
  if(f.a13.checked==true){u+='13;';}
  if(f.a14.checked==true){u+='14;';}
  if(f.a15.checked==true){u+='15;';}
 }
 else{
  t = f.Ka.value;
  u = 'G';
 }
 if($("Ka").value == ""){
  $("ch").value = "noprefill";
 } else {
  $("ch").value = "prefill";
 }
}

function s4(){
 var v=$("Kaa").value
 if($("a0").checked){
 $("SoAll").action='http://www.google.cn/search';
 $("gForm").innerHTML="<input type='hidden' name='client' value='aff-avalanche' /><input type='hidden' name='forid' value='1' /><input type='hidden' name='channel' value='prefill' id='ch' /><input type='hidden' name='ie' value='gb' /><input type='hidden' name='oe' value='UTF-8' /><input type='hidden' name='hl' value='zh-CN' />";
 $("SoAll").submit();
 }
 if($("a1").checked)
 window.open("http://www.yok.com/go.php?NO=8&Key="+v,"1");
 if($("a2").checked)
 window.open("http://www.baidu.com/baidu?tn=265com&word="+v,"2");
 if($("a3").checked)
 window.open("http://www.yok.com/go.php?Key="+v+"&NO=13","4");
 if($("a4").checked)
 window.open("http://www.yok.com/go.php?Key="+v+"&NO=10","4");
 if($("a5").checked)
 window.open("http://www.yok.com/go.php?Key="+v+"&NO=11","5");
 if($("a6").checked)
 window.open("http://www.yok.com/go.php?Key="+v+"&NO=14","6");
 if($("a7").checked)
 window.open("http://cb.kingsoft.com/search?t=word&lang=gb2312&s="+v,"7");
 if($("a8").checked)
 window.open("http://www.yok.com/go.php?Key="+v+"&NO=193&PID=888_1001","8");
 if($("a9").checked)
 window.open("http://www.yok.com/go.php?Key="+v+"&NO=26","9");
 if($("a10").checked)
 window.open("http://www.yok.com/go.php?Key="+v+"&NO=158","10");
 if($("a11").checked)
 window.open("http://www.yok.com/go.php?Key="+v+"&NO=174","11");
 if($("a12").checked)
 window.open("http://www.yok.com/go.php?Key="+v+"&NO=39","12");
 if($("a13").checked)
 window.open("http://www.yok.com/go.php?Key="+v+"&NO=49","13");
 if($("a14").checked)
 window.open("http://www.yok.com/go.php?Key="+v+"&NO=24","14");
 if($("a15").checked)
 window.open("http://www.yok.com/go.php?Key="+v+"&NO=152","15");
 return false;
}

function moveBox(sId,n){
var oSelf=$(sId);
var oParent=oSelf.parentNode;
var arrIDS=[];
var j=0;
var nCurNo=0;
for (var i=0;i<oParent.childNodes.length;i++) {
	if (oParent.childNodes[i].nodeType==1) {
		 arrIDS[j]=oParent.childNodes[i].id;
		 oParent.childNodes[i]==oSelf?nCurNo=j:"";
		 j++;
	}
}
if (nCurNo+n>-1 && nCurNo+n<arrIDS.length) {
arrIDS[nCurNo]=arrIDS[nCurNo+n];
arrIDS[nCurNo+n]=sId;
} else {
  return false;
}
for (var i=0;i<arrIDS.length;i++) {
	 oParent.appendChild($(arrIDS[i]));
	 setMovBtn(arrIDS[i],arrIDS.length,i);
}
  var expdate=new Date();
  expdate.setTime(expdate.getTime()+(24*60*60*1000*30));
  SetCookie("MyDlrenBoxes",arrIDS.join("|"),expdate,"/","dlren.com",false);
}

function resetBox(){
var arrIDS=GetCookie("MyDlrenBoxes").split("|");
if (arrIDS.length<=1) {
     arrIDS=["hSiteCate","hCoolSite"];
}
for (var i=0;i<arrIDS.length;i++) {
	 $(arrIDS[i]).parentNode.appendChild($(arrIDS[i]));
	 $(arrIDS[i]).style.visibility="visible";
	 setMovBtn(arrIDS[i],arrIDS.length,i);
}
}

function setMovBtn(sId,nMax,nNow){
 if (sId=="hSiteCate") {
    var upstr = "将“网址分类”版块移动至“大连网站导航”版块之上。";
    var downstr = "将“网址分类”版块移动至“大连网站导航”版块之下。";
 } else {
    var upstr = "将“大连网站导航”版块移动至“网址分类”版块之上。";
    var downstr = "将“大连网站导航”版块移动至“网址分类”版块之下。";
 }

 if(nNow<=0) {
	 $("btn_"+sId).innerHTML="<a href=\"javascript:void(0);\" target='_self' onclick=\"moveBox('"+sId+"',1);\" title='"+downstr+"'>下移↓</a>";
 } else {
	if (nNow>=nMax-1) {
	 $("btn_"+sId).innerHTML="<a href=\"javascript:void(0);\" target='_self' onclick=\"moveBox('"+sId+"',-1);\" title='"+upstr+"'>上移↑</a>";
	} else {
	 $("btn_"+sId).innerHTML="<a href=\"javascript:void(0);\" target='_self' onclick=\"moveBox('"+sId+"',-1);\" title='"+upstr+"'>上移↑</a>&nbsp;<a href=\"javascript:;\" target='_self' onclick=\"moveBox('"+sId+"',1);\" title='"+downstr+"'>下移↓</a>";
	}
 }
}


/*最近浏览的网站相关Cookie操作开始*/

function deleteCookie () {  //删除名称为name的Cookie  
    var exp = new Date();    
    exp.setTime (exp.getTime() - 1);    
    document.cookie = "fav_sites" + "=" + "" + "; expires=" + exp.toGMTString();
    get_recent_html();
}

function getcookie (name) {
	var CookieFound = false;
	var start = 0;
	var end = 0;
	var CookieString = document.cookie;
	var i = 0;
	
	while (i <= CookieString.length){
		start = i ;
		end = start + name.length;
		if (CookieString.substring(start, end) == name){
			CookieFound = true;
			break; 
		}
		i++;
	}
	if (CookieFound){
		start = end + 1;
		end = CookieString.indexOf(";",start);
		if (end < start)
			end = CookieString.length;
		var getvalue = CookieString.substring(start, end);
		return unescape(getvalue);
	}
	return "";
}

function get_recent_html(){
	var sites_str = getcookie("fav_sites");
	var favsites = new Array();
	favsites = sites_str.split(",");	
	var ret ="<ul class=\"Top listUrl\">\n";
	if(favsites.length == 1)
		ret = ret + "<li>近期没有访问记录!</li>\n";
	else{
		for(var j = 0; j < 7; j++){
			for( var i=j*7; i<(j+1)*7; i++){
				if(i >= favsites.length){
					
				}
				else{
					var lnk = favsites[i];
					var seppos = lnk.indexOf('|');
					var theurl = lnk.substr(0,seppos);
					var titlelen = lnk.length - seppos;
					var origtitle = lnk.substr(seppos + 1,titlelen);
					var thetitle = "";
					if(titlelen > 7){
						thetitle = lnk.substr(seppos + 1,6); 
						thetitle += "..";
					}
					else thetitle = origtitle;
					if(theurl != ""){		//代表不为空
						ret = ret + "<li><b>"+(i+1)+".</b><a href=\""+theurl+"\" title=\""+origtitle+"\" target=\"_blank\">"+thetitle+"</a></li>\n";	
					}				
				}
			}
		}
	}
	ret = ret + "</ul>\n";
	ret+="<div id=\"clearHits\"><a href=\"javascript:void(0);\" title=\"点此可以清除您“最近浏览网站”的所有记录。\" onclick=\"deleteCookie();\">[清除记录]</a>&nbsp;";
	$("MyDlrenHis").innerHTML=ret;
}
		
/*最近浏览的网站相关Cookie操作结束*/																					