﻿// JavaScript Document
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

var curNew=0;
var timer;
var timeout;
var tsTimer = null;
var catTimer = null;
var indexTabTimer = null;
var keywordTimer = null;

$(document).ready(function() {

  /**
   * 鼠标移动到该标签对应标签的状态变成可用且显示当前标签页对应的内容
   * 标签页和列表项的区别:标签页的id都是以tabmenu开头的
   */
  $("[id^='tabmenu']").mouseover(function() {
       var obj4Li = $(this);
       timeout = setTimeout(function() { overProcess(obj4Li);}, 500);
  }).mouseout(function() {
       clearTimeout(timeout);
  });

  /**
   * 搜索关键字非空检查
   * 1.搜索关键字为空白或者是默认值'请输入关键字' 弹出提示信息：请输入关键字
   * 2.上述以外情况 成功提交
   */
  $('#SearchForm1').submit(function() {
      word = $('#q');
      if (word.val() == "" || word.val() == "请输入关键词") {
        alert("请输入关键词");
        return false;
      }
      //word.val(trim(word.val()));
      return true;
  });
	//liugp_loadcity();

  /** 搜索默认值设定 **/
  addDefaultValueShow('#q', '请输入关键词');
  $('.dropItem input').val("搜商铺");

  /**
   * 鼠标移入，移出或点击搜索条件框的时候，下拉按钮样式改变
   * 模拟下拉列表框在选中时的状态
   */
  $('.dropItem input').mouseover(function() {
      $(this).addClass('onInput');
  }).mouseout(function() {
      $(this).removeClass('onInput');
  }).mousedown(function() {
      $(this).addClass('inInput');
  }).mouseup(function() {
      $(this).removeClass('inInput');
  });

  // 鼠标移动到搜索条件上的时候，该搜索条件显示成选中状态
  $('ul.options li').mouseover(function() {
      $('ul.options li').removeClass('hover');
      $(this).addClass('hover');
  });

  /**
   * 模拟搜索条件选择功能
   * @param {Object} e
   */
  $(this).click(function(e) {
      e = e || window.event;
      el = e.target || e.srcElement;
      // 当点击搜索选择框的时候
      if ($(el).is('.dropItem input')) {
          $(el).blur();
          var ibPos = $('.dropItem').position();
          var isIE = !(navigator.userAgent.indexOf('MSIE')==-1);
          $('ul.options').css({
              'width': isIE ? ($('.dropItem').width() + 4) + 'px' : ($('.dropItem').width() + 5) + 'px',
              'left': isIE ? (ibPos.left - 6) + 'px' : (ibPos.left - 5) + 'px',
              'top': isIE ? (ibPos.top + $('#SearchForm1').height()) + 'px' :(ibPos.top + $('#SearchForm1').height() + 2) + 'px'
          }).toggle();
      }
      else {
          // 当点击搜索条件的时候
          if ($(el).is('ul.options li')) {
              $('.dropItem input').val($(el).text());
              $('#SearchForm1').attr('action', ['/productdirectory.do', '/offerboard.do', '/companysearch.do'][$('ul.options li').index($(el))]);
              $('#SearchForm1').find('.textsuggest').attr('searchtype', ['0', '1', '2'][$('ul.options li').index($(el))]);
          }
          else if($(el).parent().is('ul.options li')) {
              $('.dropItem input').val($(el).text());
              $('#SearchForm1').attr('action', ['/productdirectory.do', '/offerboard.do', '/companysearch.do'][$('ul.options li').index($(el))]);
              $('#SearchForm1').find('.textsuggest').attr('searchtype', ['0', '1', '2'][$('ul.options li').index($(el).parent())]);
          }
          $('ul.options').hide();
      }
  });

  // 解决IE6下鼠标闪烁问题
  if (window.ActiveXObject && !window.XMLHttpRequest && '_UA<IE7') {
      try {
          document.execCommand('BackgroundImageCache', false, true);
          $('.dropItem ul.options li').find('span').css({
            'float':'left'
          });
      }
      catch (e) {
      }
  }

});

var addDefaultValueShow = function(slctr, valOut, clrIn, clrOut) {
    var valueOut = valOut || '';
    // 设置成指定颜色或者黑色
    var colorIn = clrIn || '#000';
    // 设置成指定颜色或者灰色
    var colorOut = clrOut || '#c2c2c2';
    $(slctr).val(valueOut).css('color', colorOut).focus(function() {
        // 去除字符串前后空格
        var valNow = $(this).val().replace(/^( )*|( )*$/g, '');
        if (valNow === '' || valNow == valueOut) {
            $(this).val('').css('color', colorIn);
        }
    }).blur(function() {
        var valNow = $(this).val().replace(/^( )*|( )*$/g, '');
        if (valNow === '' || valNow == valueOut) {
            $(this).val(valueOut).css('color', colorOut);
        }
    });
};


function liugp_selectcity(cityid,citycode,cityname)
{
	delCookie("CityName");
	delCookie("CityId");
	setCookie("CityName",cityname,"d30");
	setCookie("CityCode",cityid,"d30");
	setCookie("CityId",cityid,"d30");
	$("#selcity").html(cityname);
	$('#dm_changCity').hide('fast');
}

function liugp_loadcity()
{
$.post('/CityList.aspx', function(responseText, textStatus, XMLHttpRequest) {
	$("#allcitylist").html(responseText);
});
}


function drop_mouseover(pos){
 try{window.clearTimeout(timer);}catch(e){}
}
function drop_mouseout(pos){
 var posSel=document.getElementById(pos+"Sel").style.display;
 if(posSel=="block"){
  timer = setTimeout("drop_hide('"+pos+"')", 1000);
 }
}
function drop_hide(pos){
 document.getElementById(pos+"Sel").style.display="none";
}
function search_show(pos,searchType,href){
    document.getElementById("SearchType").value=searchType;
    document.getElementById(pos+"Sel").style.display="none";
    document.getElementById(pos+"Slected").innerHTML=href.innerHTML;
    //document.getElementById("q").focus();
    var sE = document.getElementById("searchExtend");
    if(sE != undefined  &&  searchType == "bar"){
     sE.style.display="block";
    }else if(sE != undefined){
     sE.style.display="none";
    }
 try{window.clearTimeout(timer);}catch(e){}
 return false;
}


/*javascript 读写Cookies*/

//写入
function setCookie(name,value,time){
var strsec = getsec(time);
var exp = new Date();
exp.setTime(exp.getTime() + strsec*1);
document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString()+";path=/";
}
function getsec(str){
//alert(str);
var str1=str.substring(1,str.length)*1; 
var str2=str.substring(0,1); 
if (str2=="s"){
return str1*1000;
}else if (str2=="h"){
return str1*60*60*1000;
}else if (str2=="d"){
return str1*24*60*60*1000;
}
}

//读取cookies
function getCookie(name)
{
var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
if(arr=document.cookie.match(reg)) return unescape(arr[2]);
else return null;
}
//删除cookies
function delCookie(name)
{
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval=getCookie(name);
if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}

var cityname=getCookie("CityName");
if (cityname == null)
{
	cityname="珠海";
	setCookie("CityName","珠海","d30");
	setCookie("CityCode","0756","d30");
	setCookie("CityId","203","d30");
}
