﻿function getHistory(key_path) {
	temp_v = getCookie(key_path);
	if (temp_v == "") {
		temp_v = [];
	} else {
		temp_v = temp_v.split(",");
	}
	return temp_v;
}

function addHistory(name, url, tag){
	var history = getCookie(tag);
	var newStr = name +"|"+ url;
	var str = '';
	str = newStr + ',' + history;
	if (history == '') {
		str = newStr;
	}
	SetCookie(tag, str);
}

function getCookie(Name) {
	var search = Name + "=";
	var returnvalue = "";
	if (document.cookie.length > 0) {
		offset = document.cookie.lastIndexOf(search);
		if (offset != -1){
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1) {
				end = document.cookie.length;
			}
			returnvalue=decodeURIComponent(document.cookie.substring(offset,end));//unescape(document.cookie.substring(offset,end));
		}
	}
 	return returnvalue;
}

function SetCookie(name, value, expires, path, domain){
	var date = new Date();
	date.setTime(date.getTime() + 30*24*60*60);
	expires = date.toGMTString();
	path    = '/';
	domain  = 'lai95.com';
	document.cookie=name+"="+escape(value)+("; expires="+expires)+("; path="+path)+("; domain="+domain);
}

function addFav(sURL, sTitle){
	try{
		window.external.addFavorite(sURL, sTitle);
	}catch (e){
		try{
			window.sidebar.addPanel(sTitle, sURL, "");
		}catch (e){
			alert("加入收藏失败，请使用Ctrl+D进行添加");
		}
	}
}

function setHomePage(obj,homepage){
	if (document.all){
		document.body.style.behavior='url(#default#homepage)';
		document.body.setHomePage(homepage);
	}else if (window.sidebar){
		if(window.netscape){
			try{
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			}catch(e){
				alert("您的firefox安全限制限制您进行剪贴板操作，请在浏览器地址栏输入’about:config’并回车，然后将’signed.applets.codebase_principal_support’设置为’true’之后重试。");
				return;
			}
		}
		var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
		prefs.setCharPref('browser.startup.homepage',homepage);
	}
}

var timer2 = null;
function superTab(tab,subtab,cursel,from,max){
	timer2 = setTimeout("superTabDo('"+tab+"','"+subtab+"','"+cursel+"','"+from+"','"+max+"')",500);
}
function superTabDo(tab,subtab,cursel,from,max){
	for(i=from;i<=max;i++){
		var menu=document.getElementById(tab+i);
		var con=document.getElementById(subtab+"_"+i);
		menu.className=i==cursel?"hover":"";
		con.style.display=i==cursel?"block":"none";
	}
}

var stat = 1;
var timer = null;
function qhshow(t){
	timer = setTimeout("newshow("+t+")",500);
}
function qhshow2(t){
		for(var i=1;i<=3;i++){
			document.getElementById('s1'+i).className = 'mall_menu_text02';
			document.getElementById('s_s1'+i).style.display = 'none';
		}
		document.getElementById('s1'+t).className = 'mall_menu_text01';
		document.getElementById('s_s1'+t).style.display = '';
}
function newshow(t){
	for(var j=1;j<=3;j++){
		if(t!=j){
			document.getElementById('s1'+j).className = 'title_menu_text02';
			document.getElementById('s_s1'+j).style.display = 'none';
		}else{
			document.getElementById('s1'+j).className = 'title_menu_text01';
			document.getElementById('s_s1'+j).style.display = 'block';
		}

		if(j==4){
			// 最新浏览
			history_stat = 0;
			arr = getCookie("historyTag");
			arr = arr.split(',');
			if (arr.length != 0) {
				tr_history = "";
				for (i=0; i<arr.length;i++) {
					temp_arr = arr[i].split("|");

					tr_history += '<li><a target="_blank" href="' + temp_arr[1] + '">' + temp_arr[0] + '</li>';
	
				}
				$("#urlhistory").html(tr_history);
			} else {
				$("#urlhistory").html("<li>没有浏览记录</li>");
			}

		}
	}	
}
function showImg(f){
		var arrImg=document.getElementById(f).getElementsByTagName("IMG");

			for (var j=0;j<arrImg.length;j++){
				if (arrImg[j].name!=""){
					arrImg[j].src = arrImg[j].name;
					arrImg[j].removeAttribute('name');
				}
			}
	}
$(document).ready(function(){
	$(".mainnav a").mouseover(function(){
		$(".mainnav a").attr("class","");
		$("#"+this.id).attr("class","actived");
		var currentMenuNo = parseInt(this.id.substring(1));
		$(".secondnav div").each(function(){
			$(this).hide();
			$("#subnav"+currentMenuNo).show();
		});
	});
	for(var i=0;i<10;i++){
		if(null!=document.getElementById('main0'+i)){
			$('#navsub'+i).show();
			$('#nav'+i).addClass('nav_cur');
			if(i==5 || i==6){
				$('#nav_t_s').hide();
			}
			if(i<=3){
				right_review_on(i-1);
			}
			if(i==4){
				right_review_on(2);
			}
			if(i==5){
				right_review_on(3);
			}
		}
			
	}
});

var Taoku={};var N={};
var UP=38;
var DOWN=40;
var LEFT=37;
var RIGHT=39;

$(document).ready(function(){
	$('<div id="suggest_box"><div>').appendTo("body");
	N.lastKey="";
	N.suggestBox=$("#suggest_box");
	N.kwf=$("input[name=q]");
	N.kwf.keyup(function(d){
		switch(d.keyCode){
			case LEFT:case RIGHT:return false;break;
			case DOWN:
				if(!N.suggestBox.is(":hidden")){
					var a=$("tr",N.suggestBox);
					var c=null;
					if(a.filter(".hover").length>0){
						c=a.filter(".hover").next();
						a.removeClass("hover");
						c.addClass("hover")
					}else{
						c=a.eq(0).addClass("hover")
					}
					N.kwf.val($(".suggest_keyword",c).text())
				}
				return false;
				break;
			case UP:
				if(!N.suggestBox.is(":hidden")){
					var a=$("tr",N.suggestBox);
					var c=null;
					if(a.filter(".hover").length>0){
						c=a.filter(".hover").prev();
						a.removeClass("hover");
						c.addClass("hover")
					}else{
						c=a.eq(a.length-1).addClass("hover")
					}
					N.kwf.val($(".suggest_keyword",c).text())
				}
				return false;
				break
		}
		var b=$.trim(this.value);
		if(b!=""&&b.length>0){
			if(b==N.lastKey){return false}
			N.lastKey=b;
			switch($("li.cur a").attr("rel")){
				case "taobao":loadJS("http://www.taoku.com/index.php?c=api&a=taobao&q="+encodeURIComponent(b)+"&t="+Math.random());break;
				case "shop":loadJS("http://www.taoku.com/index.php?c=api&a=shop&q="+encodeURIComponent(b)+"&t="+Math.random());break;
				case "discount":loadJS("http://www.taoku.com/index.php?c=api&a=discount&q="+encodeURIComponent(b)+"&t="+Math.random());break;
				case "news":loadJS("http://www.taoku.com/index.php?c=api&a=news&q="+encodeURIComponent(b)+"&t="+Math.random());break;
				case "item":loadJS("http://suggest.taobao.com/sug?code=utf-8&callback=TB.Suggest.callback&q="+encodeURIComponent(b)+"&t="+Math.random());break;
				default:
			}
		}else{
			N.suggestBox.hide()
		}
	}
);
	
$(document).click(function(b){
	var a=$(b.target);
	if(a.parents("#suggest_box").length==0){N.suggestBox.hide()}
	})});
function loadJS(a,d){
	var c="tbsuggent";
	if($("#"+c)){$("#"+c).remove()}
	var b=document.body.appendChild(document.createElement("script"));
	d="utf-8"||d;
	b.language="javascript";
	b.id=c;
	b.charset=d;
	b.src=a
}
var TB={};
TB.Suggest={};
TB.Suggest.callback=function(b){
	suggestCallback(b,"条结果")
};
Taoku.Suggest={};
Taoku.Suggest.callback=function(b){suggestCallback(b,"")};
function suggestCallback(c,f){
	var e="<table cellspacing='0' cellpadding='0'>";
	result=c.result;
	var b=result.length;
	if(b>0){for(var d=0;d<b;d++){
		e+="<tr><td class='suggest_keyword'>"+result[d][0]+"</td><td class='suggest_num'>"+result[d][1]+f+"</td></tr>"
	}
	e+="</table>";
	var g=N.kwf.offset();
	N.suggestBox.html(e).css({left:g.left,top:g.top+N.kwf.outerHeight()});
	if(N.suggestBox.width()<N.kwf.outerWidth()){
		$("table",N.suggestBox).width(N.kwf.outerWidth())
	}
	N.suggestBox.show();
	$("tr",N.suggestBox).hover(function(){$(this).addClass("hover")},function(){$(this).removeClass("hover")}).click(function(){N.kwf.val($(".suggest_keyword",this).text());N.suggestBox.hide()})}else{N.suggestBox.hide()}};

var objlength = 3;
  var urlArr = [
  'http://www.taoku.com/redirect.php',
  'http://shop.taoku.com/index.php',
  'http://tb.taoku.com/index.php',
  'http://www.taoku.com/index.php',
  'http://news.taoku.com/index.php'
  ];
  var typeArr = [
  'item',
  'shop',
  'tb',
  'dazhe',
  'news'
  ];
	function right_review_on(gubun){
		for(var i=0;i<=objlength;i++){
			document.getElementById('rel'+i).className = '' ;
		}
		document.getElementById('rel'+gubun).className = 'cur';
		document.forms['searchForm'].action = urlArr[gubun];
		$("input[name=c]").val(typeArr[gubun]);
		if(gubun == 0)
			$("input[name=c]").val('redirect');
		else
			$("input[name=a]").val('list');
		$("input[name=q]").val('');
	}
	function keysearch(form){
		var val = $("input[name=q]").val();
		if(val == ''){
			alert('请输入查询内容')
			return false;
		}
		return true;
	}
	
var arrEndTime=[],timmer;
function tuanCountDown(){
	for(var i = 0; i < arrEndTime.length; i++){
		var countDownId = arrEndTime[i]["countDownId"],
			endTime  = arrEndTime[i]["endTime"] + "000",
			lastTime = (parseInt(endTime) - new Date().getTime()) / 1000,
			days     =  Math.floor(lastTime  / (24 * 3600)),
			lastSec  = (lastTime - days * 24 * 3600),
			hours    = Math.floor(lastSec/3600),
			minutes  = Math.floor((lastSec - hours * 3600)/60),
			seconds  = Math.floor(lastSec - (hours * 3600) - (minutes * 60));
	if(days <= 0){
		days = 0;
	}else{
		days = days;
	}
	if(lastTime <= 0){
		$('#'+countDownId).html("<font>团购已结束</font>");	
	}else{
		$('#'+countDownId).html("还有 <font>"+days+"</font>天<font>"+hours+"</font>小时<font>"+minutes+"</font>分<font>"+seconds+"</font>秒");
	}
	}
	clearInterval(timmer);
	timmer = setInterval(tuanCountDown,1000);
}
