/*Recently:jiafei Updated Date: 2009-6-1 9:50*/
function gb2312(key)
              {
                    var r = "";
                    for(var i=0;i<key.length;i++)
                    {
                            var t = key.charCodeAt(i);
                            if(t>=0x4e00 || t==0x300A || t==0x300B)
                            {
                                    try
                                    {
                                    execScript("ascCode=hex(asc(\""+key.charAt(i)+"\"))", "vbscript"); r += ascCode.replace(/(.{2})/g, "%$1"); }
                                    catch(e)
                                     {}
                             }
                            else{r += escape(key.charAt(i))}
                       }
                    return r;
               }

var duk = {};
duk.__init__ = function() {
	duk.initSearch();
}

duk.search = function(text, type) {
//	text = encodeURIComponent(text);
       // text=gb2312(text);
     //  text = encodeURIComponent(text);
	var searchUrl;
	if (type == 'searchsort') {//搜商户               
		value="shop"
	} else if (type == 'search_body') {//搜折扣
		searchUrl = "http://www.guoli.com/sale/sale.search.php?textK=" + text;
	} else if (type == 'search_all') {//搜商户
                // text=gb2312(text);
		searchUrl = "http://www.guoli.com/search/search.php?city=310000&keyword=" + text;
	} else if (type == 'search_problem') {//搜资讯
		searchUrl = "http://i.taohz.com/article/index.php?classid=&order=dateline&author=&keyword=" + text;
	}
	document.searchform.submit()
}

duk.initSearch = function() {
	duk._initSearchBox();
	jQuery("#opt, #searchoption").bind('mouseover', function(event) {
		if (jQuery("#searchoption").is(':hidden')) {
			var offset = jQuery("#opt").offset();
			var left = offset.left - 6 + 'px';
			var top = offset.top - 44 + 'px';
			jQuery("#searchoption").css('top', -29).css('left', 350).show();
		}
	});

	jQuery("#searchoption").bind('mouseout', function() {
		jQuery("#searchoption").hide();
	});
}

duk._initSearchBox = function() {
	jQuery("#search_keywords").keypress( function(e) {
		if (e.which == 13) {
			duk.search(jQuery("#search_keywords").val(), "search_all");
			jQuery("#search_keywords").blur();
		}
	});
	
	jQuery("#searchoption").click( function(e) {
		var text = jQuery("#search_keywords").val();
		var type = e.target.className;
		duk.search(text, type);
	});
}

duk.initSecondaryNavigation = function() {
	duk._initSearchBox();
	jQuery("#brandopt span").css({cursor:"pointer",fontSize:"12px"});
	jQuery("#brandopt span, #brandopt a:first").click( function(e) {
		var text = jQuery("#search_keywords").val();
		if (text == "请输入搜索关键词...") {
			alert("输入搜索关键词...");
			return ;
		}
		duk.search(text, "search_all");
	});
	
	jQuery("#brandopt, #searchoption").bind('mouseenter', function(){
		jQuery("#brandopt").children(":first").addClass("mouseover");
		jQuery("#searchoption").show();
	});
	
	jQuery("#brandopt, #searchoption").bind('mouseleave', function(){
		jQuery(this).prev().removeClass("mouseover");
		jQuery("#searchoption").hide();
	});

	jQuery("#pbobj > a, #pbtar").bind('mouseenter', function(){
		jQuery("#pbtar").show();
		jQuery("#pbobj a").addClass('mouseover');
	});
	
	jQuery("#pbobj, #pbtar").bind('mouseleave', function(){
		jQuery("#pbtar").hide();
		jQuery("#pbobj a").removeClass('mouseover');
	});
	
	jQuery("#ppobj a, #pptar").bind('mouseenter', function(){
		jQuery("#ppobj a").addClass('mouseover');
		jQuery("#pptar").show();
	});
	
	jQuery("#ppobj, #pptar").bind('mouseleave', function(){
		jQuery("#ppobj a").removeClass('mouseover');
		jQuery("#pptar").hide();
	});

	if (!jQuery.cookie('visited')) {
		var date = new Date();
		date.setTime(date.getTime() + (365 * 24 * 60 * 60 * 1000));
		jQuery.cookie('visited', '1', { path: '/', domain: 'guoli.com', expires: date });
		jQuery("#tips_cfloor").show();
		jQuery("#tips_cfloor a").click(function(){
			jQuery("#tips_cfloor").hide();
			return false;
		});
	}
	
	jQuery('#notice').cycle({
	  	pause:1,
	  	timeout: 4000,
	  	speed: 400,
	  	height: 8,
	  	fx: 'scrollUp'
	});
	
	if(jQuery(".dktemp").width() < 1006) jQuery(".dktemp").css("width","1006px");
}
