
/* base functions */
function $(id){
	return document.getElementById(id);
}
/*不让搜狗浏览器篡改链接地址*/
var erhuo;
if(erhuo = $('home_123')) {
	erhuo.href = '/';
	erhuo.id = 'null';
}

/*继续做点猥琐的事情，针对daohang.qq.com做些事情*/
if(document.referrer.match(/http:\/\/www\.2345m\.com/g)) {
	siteUrl = 'http://www.2345m.com/';
	site = '网址导航 www.2345m.com';
	var tbr = $('topbar')
		, tpr = $('upperzy')
		, lar = $('logo');
	if(tbr) {
		tbr = tbr.getElementsByTagName('a')[0];
		if(tbr) {
			tbr.href = siteUrl;
		}
	}
	if(tpr) {
		tpr = tpr.getElementsByTagName('a')[0];
		if(tpr) {
			tpr.href = siteUrl;
		}
	}
	if(lar) {
		lar = lar.getElementsByTagName('a')[0];
		if(lar) {
			lar.href = siteUrl;
		}
	}
}

function getCookie(name){  
	var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)")); 
	return (arr != null)?unescape(arr[2]):null; 
}
function setCookie(name, value, exptime){
	var Days = 30;
	var exp  = new Date();
	exp.setTime(exp.getTime() + exptime);
	document.cookie = name + "=" + escape(value) + ";path=/;expires=" + exp.toGMTString() + ";";
}
function in_array(arr, value){
	if (arr.length < 1)
		return -1;
	for (var i=0; i<arr.length; i++)
		if (value == arr[i])
			return i;
	return -1;
}
function attach_js_src(src){
	var o = document.createElement("script");
	o.type = "text/javascript";
	o.src = src;
	var h = document.getElementsByTagName("HEAD").item(0);
	h.appendChild(o);
}

/* about index functions */
function sys_init(){
	sys_vars.suid = getCookie("SUID");
	sys_vars.sduv = getCookie("SDUV");
	sys_vars.refer = document.referrer ? encodeURIComponent(document.referrer) : "";
	sys_vars.page = encodeURIComponent(document.getElementsByTagName("title")[0].innerHTML);
	sys_vars.wlh = encodeURIComponent(window.location.href);
	sys_vars.loc = getCookie("IPLOC");
	var opid = getCookie("GOTO");
	if (!(opid && (opid.indexOf("sogou-") != -1 || /^Af[0-9]{5}$/.test(opid)))){
		opid = "AQxRG";
	}
	else{
		search_vars.surl[1] = "http://www.sogou.com/sogou";
		if ($("pid")) $("pid").value = opid;
	}
	search_vars.gb_sr_action = search_vars.surl[1];
	sys_vars.pid = opid;
	uigs_para['sogou-hp'] = sys_vars.hp;
	uigs_para.page = sys_vars.ptitle;
	uigs_para.pageUrl = sys_vars.wlh;
}
function addbookmark(A,C){
	try{
		if(document.all){
			window.external.AddFavorite(A,C);
		}
		else if(window.sidebar && window.sidebar.addPanel){
			window.sidebar.addPanel(C,A,"");
		}
		else if(window.external){
			window.external.AddFavorite(A,C);
		}
		else if(window.opera && window.print){
			return true;
		}
	}
	catch(e){
		alert("您好，您的浏览器不支持直接加入收藏，请使用浏览器菜单手动将本站加入收藏，祝您使用愉快！");
	}
}
function init_upper(fg){
	try{
	if (fg == 1){
		try{$("upperdf").href = $("logo_123").href = $("home_123").href = "se:navi";}catch(e){}
		var hp = '<a href="/" id="textnavi">返回首页</a>';
	}
	else{
		var hp = '<a href="javascript:void(0)" onclick="sethome(this);">设为主页</a>';
	}
	$("uppertx").innerHTML = [hp,'<a href="javascript:addbookmark(siteUrl, site);">加入收藏</a>','<a href="javascript:feedback();">意见反馈</a>'].join('&nbsp;&nbsp;|&nbsp;&nbsp;');
	}catch(e){}
}
function setSearchURL(searchurl){
	init_upper(1);
}
function sogouexplore_init(){
	init_upper(2);
	/*
	try{
		if (navigator.userAgent.toLowerCase().indexOf(" se ") > -1){
			window.external.StartPageCall('onload', '0');
		}
		else{
			init_upper(2);
		}
	}
	catch(e){
		init_upper(2);
	}*/
}

/* set homepage */
function feedback(){
	var url = "/feedback/?url="+encodeURIComponent(wlh);
	window.open(url);
}
function sethome(obj){
	try{
		obj.style.behavior='url(#default#homepage)';
		obj.setHomePage(siteUrl);
	}catch(e){
		alert("您好，您的浏览器不支持直接设为首页，请使用浏览器菜单手动设置本站为首页，祝您使用愉快！");
	}
}






var old = $('sgse_f').action;
function sgse_nava(e){
	if (typeof e == "string" && e == "sogou_2"){
		var id = 2;
	}
	else{
		e = e ? e : window.event;
		var src = (e.target) ? e.target : e.srcElement;
		if (src.tagName.toUpperCase() == "A") src = src.parentNode;
		if (!(src.tagName.toUpperCase() == 'LI' && src.id && src.id.indexOf("sgse_li_") > -1)){
			return;
		}
		var id = parseInt(src.id.substring(8));
	}
	for(var i=2; i<=8; i++){
		$("sgse_li_"+i).className = (id == i) ? "sgse_onsel" : "";
	}
	$("sgse_st").value = id;
	var sid_arr = ['', '', 'sogou_2', 'sogouzhishi_3', 'taobao_4', 'sogou_5', 'sogou_6', 'sogou_7', 'sogou_8'];
	var sid = sid_arr[id];
	$("sgse_sid").value = sid.split("_")[0];
    if(id == 2) {
        $('sgse_f').action = old;
    } else {
        $('sgse_f').action = "http://so.ie.sogou.com/s/";
    }
	search_vars.curid = id;
	search_vars.cursid = sid;
}
function sgse_sm(){
	var rt = true;
	var kw_val = $("sgse_kw").value.replace(/(^\s*)|(\s*$)/g, "");
	var cid = search_vars.cursid;
	var ssid = cid.split("_")[0];
	if(kw_val){
	}
	else if (cid.indexOf("sogou") == -1){
		rt = false;
	}
	search_vars.search_rand++;
    $('tsb').value = kw_val;
	$("sgse_sr").value = search_vars.search_rand;
	var pb_str = "&module=topSearch&urlName="+encodeURIComponent(kw_val)+"&stype="+ssid+"&sval="+search_vars.curid+"&url="+search_vars.search_rand;
	spb_vars.pingback(3,pb_str);
	return rt;
}
/*干点猥琐的事情*/
(function() {
	var sbm = $('subm');
	if(sbm) {
		var alluls = sbm.getElementsByTagName('ul');
		for(var i = 0, len = alluls.length; i < len; i++) {
			if(alluls[i].className.indexOf('subct') == -1) continue;
			var h = alluls[i].style.height;
			if(h) {
				h = parseInt(h);
				if(h) {
					alluls[i].style.height = h - 2 + 'px';
				}
			}
		}
	}
	/*操作footer*/
	/*
	var f = $('center_9');
	if(f) {
		var name = "Height"
			, elem = window
			, docElemProp = elem.document.documentElement[ "client" + name ]
			, h = elem.document.compatMode === "CSS1Compat" && docElemProp || elem.document.body[ "client" + name ] || docElemProp
			, h2 = document.body.clientHeight;
		if(h2 < h) {
			f.style.height = 60 + (h - h2) + 'px';
		}
	}*/
})();

