


/* 象这样框着我的这种代码勿动！ */


function addRemenber(type) {
  var cookieStr;
  var reg = new RegExp('' + type + '(<a [^\\\|]+)', 'i');
  var val = (stratSearchHot[type] && typeof(stratSearchHot[type]) != 'undefined') ? stratSearchHot[type] : '';
  if (cookieStr = getCookie('searchHot')) {
    if (cookieStr = cookieStr.match(reg)) {
      val = '' + cookieStr[1] + ' <a href="javascript:void(0)" onclick="delRemenber(\'' + type + '\');return false;" style="color:#999999; border:1px #EEE solid; display:inline-block !important; display:inline; zoom:1; width:13px; height:13px; line-height:13px; text-decoration:none;" title="清除">×</a>'
    }
  }

  /* search_under_ad */
var search_under_ad = '<iframe id="baidutop" vspace="0" hspace="0" scrolling="no" allowtransparency="true" frameborder="0" width="146" height="13" src="writable/ad/baidutop.html" style="vertical-align: text-bottom;"></iframe>';
/* /search_under_ad */

  if ($('search_hot_word') != null) {
    $('search_hot_word').innerHTML = search_under_ad + ' ' + val;
  }
};

/* search_default_bar */
var search_default_type = 'wangye';
var search_default_id = 'baidu';
/* /search_default_bar */

var searchBarO = getCookie('searchBarBody').toString();
var nowSearchBody = (searchBarO == '1' || searchBarO == '2' || searchBarO == '3') ? searchBarO : defaultBayId;
var searchSelect = {};

/* search_bar */
searchSelect = {
  'wangye': {
    0 : '搜网页',
    '360': ['http://www.so.com/s?ie=utf-8&q=', '360'],
    'baidu': ['http://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&rsv_idx=1&ch=&tn=baiduerr&bar=&rn=&rsv_enter=1&wd=', '百度'],
    'sousou': ['http://www.soso.com/q?ie=utf-8&w=', '搜搜'],
    'Google': ['http://www.google.com.hk/search?hl=zh-CN&q=', 'Google'],
    'sougou': ['http://www.sogou.com/web?ie=utf8&query=', '搜狗'],
    'jichengsousuo': ['search.php?is=wangye&go=http%3A%2F%2Fwww.baidu.com%2Fs%3Fie%3Dutf-8%26word%3D&kw=', '集成搜索'],
    'zhanneisousuo': ['member.php?get=search_site&kw=', '站内搜索']
  },
  'shangpin': {
    0 : '搜商品',
    'taobao': ['http://search.taobao.com/search?commend=all&source=search1&q=', '淘宝'],
    'zhuoyue': ['http://www.amazon.cn/s/?ie=utf-8&keywords=', '卓越']
  },
  'tupian': {
    0 : '搜图片',
    'Google': ['http://images.google.com.hk/images?hl=zh-CN&q=', 'Google'],
    'baidu': ['http://image.baidu.com/i?ie=utf-8&word=', '百度']
  },
  'yinle': {
    0 : '搜音乐',
    'baidu': ['http://music.baidu.com/search?ie=utf-8&key=', '百度'],
    'Google': ['http://www.google.cn/music/search?q=', 'Google'],
    'sougou': ['http://d.sogou.com/music.so?ie=utf8&query=', '搜狗'],
    'yiting': ['http://so.1ting.com/all.do?q=', '一听']
  },
  'shipin': {
    0 : '搜视频',
    '56': ['http://so.56.com/index?type=video&charset=utf-8&key=', '56'],
    'baidu': ['http://video.baidu.com/v?ie=utf-8&word=', '百度'],
    'Google': ['http://video.google.cn/videosearch?hl=zh-CN&q=', 'Google'],
    'youku': ['http://so.youku.com/search_video/q_', '优酷'],
    'ku6': ['http://so.ku6.com/v/q', '酷6'],
    'xinlang': ['http://video.sina.com.cn/search/index.php?k=', '新浪']
  },
  'xinwen': {
    0 : '搜新闻',
    'baidu': ['http://news.baidu.com/ns?word=', '百度'],
    'Google': ['http://www.google.com.hk/search?hl=zh-CN&q=', 'Google']
  },
  'youxi': {
    0 : '搜游戏',
    '17173': ['http://search.17173.com/jsp/game.jsp?keyword=', '17173'],
    'baidu': ['http://youxi.baidu.com/search.xhtml?c=searchGame&q=', '百度'],
    '52pk': ['http://so.52pk.com/search.php?keyword=', '52pk']
  },
  'ditu': {
    0 : '搜地图',
    'Google': ['http://ditu.google.cn/maps?hl=zh-CN&q=', 'Google'],
    'baidu': ['http://ditu.baidu.com/?s=s%26wd%3D', '百度']
  }
};
/* /search_bar */

function isArray(obj) {
  //return Object.prototype.toString.call(obj) === '[object Array]';
  for (i in obj) {
    if (i) {
      return true;
      break;
    }
  }
  return false;
}

//document.write('<sc'+'ri'+'pt type="text/javascript" language="javaScript" src="readonly/js/search_bar_' + nowSearchBody + '.js"></sc'+'ri'+'pt>');
switch (nowSearchBody) {
  case '1':
//搜索引擎样式1
document.writeln('<style type="text/css">\
#logo { padding-top:20px; }\
#search { padding-bottom:10px; }\
#search_body { width:550px; height:62px; font-size:13px; text-align:center; }\
#search_bar { width:550px; height:24px; position:relative; clear:both; z-index:2; }\
#search_bar_in { width:550px; /*height:26px; position:absolute; left:0; top:0; z-index:15;*/ overflow:hidden; }\
#search_bar_in a { width:50px; height:20px; line-height:20px; display:inline-block !important; display:inline; zoom:1; text-align:center; overflow:hidden; position:relative; }\
#search_bar_in a span { width:48px; height:20px; position:absolute; top:0px; left:2px; text-align:center; cursor:pointer; text-decoration:underline; }\
#search_bar_in a:hover { background:none; }\
#search_bar_in a#searchNavIs { width:56px; font-size:14px; font-weight:bold; cursor:default; }\
#search_bar_in a#searchNavIs { /*background-position:-480px -5px;*/ background:none; }\
#search_bar_in a#searchNavIs span { width:54px; color:#666666; text-decoration:none; }\
#f { width:550px; height:38px; background-position:0 0; position:relative; z-index:1; }\
#ou { width:81px; height:36px; margin:1px; float:left; text-align:left; cursor:pointer; position:relative; z-index:60; }\
.ou_in { width:81px; height:36px; text-align:center; overflow:hidden; position:absolute; left:0; top:0; z-index:61; }\
.ou_out { height:auto; overflow:inherit; margin-left:-1px; margin-top:-1px; border:1px #9B9F9F solid; border-radius:2px; -moz-border-radius:2px; -webkit-border-radius:2px; background-color:#FFF; }\
.ou_in img { margin:3px 0; }\
#kw { width:380px; height:30px; line-height:30px; padding:3px; margin:1px 0 1px -1px; }\
#su { width:81px; height:30px; margin:4px 0 0 0; font-size:14px; }\
#search_hot_word_out { min-height:24px; }\
#search_hot_word { padding-top:5px; padding-bottom:5px; font-size:13px; line-height:normal; }\
#search_hot_word a { margin:0 3px; }\
#changebar { background:url(writable/css/c_bar_1.gif) 0 0 no-repeat; width:15px; height:15px; overflow:hidden; position:absolute; top:21px; right:2px; z-index:20;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=80); -moz-opacity:0.8; -khtml-opacity:0.8; opacity:0.8; }\
</style><div id="search_body" class="forQQ1"><div id="search_bar"><div id="search_bar_in">');if(isArray(searchSelect)){for(type in searchSelect){var searchBarName=searchSelect[type][0].toString().replace(/搜/g,'');document.writeln('<a id="search_bar_type_'+type+'" name="search_bar_type_'+type+'" href="javascript:void(0);" onclick="addsearchBar(\''+type+'\');return false;" hidefocus="true">'+searchBarName+'<span>'+searchBarName+'</span></a>');delete searchBarName;}}document.write('</div></div><form id="f" name="f" onsubmit="return remenber()"><div id="ou"><div id="ou_in" class="ou_in" onmouseover="showOu(this)"></div></div><input type="text" name="kw" id="kw" maxlength="100" /><button name="su" type="submit" id="su">搜网页</button><input name="go" id="go" type="hidden" /><input name="is" id="is" type="hidden" value="wangye" /><a href="javascript:void(0);" id="changebar" title="切换引擎模式" onclick="changeBar();return false;"></a></form></div><table id="search_hot_word_out" class="forQQ_1" border="0" cellspacing="0" cellpadding="0"><tr valign="middle"><td id="search_hot_word"></td></tr></table>');var showOu=function (obj){obj.className='ou_in ou_out';obj.onmouseout=function(){obj.className='ou_in';}};var closeOu=function (){return;};
  break;
  case '2':
//搜索引擎样式2
document.writeln('<style type="text/css">\
#search { padding-bottom:10px; }\
#search_body { width:509px; height:38px; font-size:13px; position:relative; z-index:3; }\
#f { width:509px; height:38px; background-position:0 -42px; position:relative; }\
#kw { width:396px; height:30px; line-height:30px; margin:4px 0 0 4px; padding-left:3px; padding-right:3px; }\
#su { width:69px; height:30px; margin:4px 0 0 0; font-size:14px; color:#FFFFFF; }\
#search_bar_next { position:relative; z-index:4; float:left; margin-top:7px; width:26px; }\
.ou_in_ { position:absolute; top:0; left:0; z-index:69; margin:0; width:26px; height:24px; overflow:hidden; border:none; background:none; }\
.fc{ background-color:#FFFFFF; filter:progid:DXImageTransform.Microsoft.Alpha(opacity=50); -moz-opacity:0.5; -khtml-opacity:0.5; opacity:0.5; }\
.ou_out_ { width:95px; height:auto; overflow:inherit; margin:0; background-color:#FFFFFF; }\
.ou_in_ img { margin:4px auto; }\
#ou_in { width:26px;}\
.ou_in_ #ou_in {}\
.ou_out_ #ou_in { filter:progid:DXImageTransform.Microsoft.Alpha(opacity=100); -moz-opacity:1; -khtml-opacity:1; opacity:1; }\
#search_bar_index { background-color:#EFEFEF; /*border:1px #FFFFFF solid;*/ }\
#search_bar_index a { display:block; height:24px; line-height:24px; font-size:13px; overflow:hidden; }\
#search_bar_index a#searchNavIs { background:#FFFFFF; }\
#search_hot_word_out { min-height:24px; }\
#search_hot_word { padding-top:5px; padding-bottom:5px; font-size:13px; line-height:normal; }\
#search_hot_word a { margin:0 3px; }\
#changebar { background:url(writable/css/c_bar_1.gif) 0 0 no-repeat; width:15px; height:15px; overflow:hidden; position:absolute; top:16px; right:7px; z-index:20;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=80); -moz-opacity:0.8; -khtml-opacity:0.8; opacity:0.8; }\
</style><div id="search_body" class="forQQ2"><form id="f" name="f" onsubmit="return remenber()"><input type="text" name="kw" id="kw" onfocus="$(\'border_side\').style.display=\'block\';" onblur="$(\'border_side\').style.display=\'none\';" maxlength="100" /><div id="search_bar_next" onmousedown="showOu();"><div id="ou_in_" class="ou_in_"><table width="93" border="0" cellspacing="0" cellpadding="0"><tr valign="top"><td id="ou_in" title="点击切换引擎" onmouseover="this.className=\'fc\';" onmouseout="this.className=\'\';"></td><td id="search_bar_index">');if(isArray(searchSelect)){for(type in searchSelect){document.write('<a id="search_bar_type_'+type+'" name="search_bar_type_'+type+'" href="javascript:void(0);" onclick="addsearchBar(\''+type+'\');return false;">'+searchSelect[type][0]+'</a>');}}document.writeln('</td></tr></table></div></div><button name="su" type="submit" id="su">搜网页</button><br /><input name="go" id="go" type="hidden" /><input name="is" id="is" type="hidden" value="wangye" /><a href="javascript:void(0);" id="changebar" title="切换引擎模式" onclick="changeBar();return false;"></a></form></div><table id="search_hot_word_out" class="forQQ_2" border="0" cellspacing="0" cellpadding="0"><tr valign="middle"><td id="search_hot_word"></td></tr></table>');var showOu=function (){$('ou_in_').className='ou_in_ ou_out_';/*$('ou_in').title='';*/};var closeOu=function (){$('ou_in_').className='ou_in_';};if(typeof(HTMLElement)!="undefined"){HTMLElement.prototype.contains=function(obj){if(obj==this)return true;while(obj=obj.parentNode){if(obj==this)return true;}return false;}};document.onmouseover=function(e){e=e||event;var onMIn=$('ou_in_');if(onMIn.className=='ou_in_ ou_out_'){if(!onMIn.contains(e.target||e.srcElement)){closeOu();}}};
  break;
  default :
//搜索引擎样式3
document.writeln('<style type="text/css">\
#logo { padding-top:20px; }\
#search { width:760px; padding-bottom:10px; }\
#search_body { width:450px; height:86px; float:left; font-size:13px; text-align:center; }\
#search_bar { margin-left:0; width:450px; height:24px; position:relative; z-index:2; }\
#search_bar_in { width:450px; height:26px; line-height:26px; font-size:14px; position:absolute; left:0; top:0; z-index:15; overflow:hidden; }\
#search_bar_in a { width:50px; float:left; padding:0; height:26px; text-align:center; overflow:hidden; position:relative; }\
#search_bar_in a span { width:48px; height:24px; position:absolute; top:0px; left:2px; text-align:center; cursor:pointer; }\
#search_bar_in a:hover { background-position: right top; }\
#search_bar_in a#searchNavIs { background-position:-622px 0; }\
#search_bar_in a#searchNavIs { width:56px; font-size:14px; font-weight:bold; cursor:default; }\
#search_bar_in a#searchNavIs span { width:54px; color:#666666; }\
#f { margin-left:0; width:450px; height:38px; float:left; background-position:0 -83px; position:relative; z-index:1; }\
#ou { height:24px; margin-top:38px; line-height:24px;}\
#ou_in { padding:4px 0; text-align:left; width:450px; white-space:nowrap; overflow:hidden; }\
#ou_in button { margin-left:10px; margin-right:10px; padding:0; background:none; border:none; height:16px; line-height:16px; font-weight:normal; letter-spacing:0; cursor:pointer; }\
#ou_in button#ou_in_is { color:#999; background:#F0EFF0; padding-left:6px; padding-right:6px; font-weight:bold; }\
.ou_out {}.ou_in img {}\
#kw { height:28px; line-height:28px; width:363px; margin:5px 0 0 5px; }\
#su { height:28px; margin:5px 0 0 0; width:78px; font-size:14px; color:#FFFFFF; }\
#search_hot_word_out { width:300px; height:86px; float:right; clean:none; }\
#search_hot_word { line-height:normal; white-space:normal; }\
#search_hot_word a { margin:0 3px; font-size:12px; text-decoration:underline; }\
#changebar { background:url(writable/css/c_bar_1.gif) 0 0 no-repeat; width:15px; height:15px; overflow:hidden; position:absolute; top:18px; right:5px; z-index:20;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=80); -moz-opacity:0.8; -khtml-opacity:0.8; opacity:0.8; }\
</style><div id="search_body" class="forQQ3"><div id="search_bar"><div id="search_bar_in">');if(isArray(searchSelect)){for(type in searchSelect){var searchBarName=searchSelect[type][0].toString().replace(/搜/g,'');document.writeln('<a id="search_bar_type_'+type+'" name="search_bar_type_'+type+'" href="javascript:void(0);" onclick="addsearchBar(\''+type+'\');return false;" hidefocus="true">'+searchBarName+'<span>'+searchBarName+'</span></a>');delete searchBarName}}document.write('</div></div><form id="f" name="f" onsubmit="return remenber()"><input type="text" name="kw" id="kw" maxlength="100" /><button name="su" type="submit" id="su">搜网页</button><div id="ou"><div id="ou_in"></div></div><input name="go" id="go" type="hidden" /><a href="javascript:void(0);" id="changebar" title="切换引擎模式" onclick="changeBar();return false;"></a></form></div><table id="search_hot_word_out" class="forQQ_3" border="0" cellspacing="0" cellpadding="0"><tr valign="middle"><td id="search_hot_word"></td></tr></table>');function getSearchSelect3(type,n){var strOther='<input name="is" id="is" type="hidden" value="'+type+'">';for(i in searchSelect[type]){if(i!=0){var thisChecked=i==n?' id="ou_in_is" disabled="disabled"':'';
strOther+='<button onclick="saveBar(\''+type+'\',\''+i+'\');if($(\'ou_in_is\')!=null){$(\'ou_in_is\').disabled=false;$(\'ou_in_is\').id=\'\';this.disabled=true;this.id=\'ou_in_is\';}return false;																																																																																																																																																																																																																																							"'+thisChecked+'>'+searchSelect[type][i][1]+'</button>'}}return strOther};
  break;

}

function changeBar() {
  var bar = nowSearchBody==1?2:(nowSearchBody==2?3:1);
  setCookie('searchBarBody', bar, 365);
  location.reload(false);
}

function addFocus() {
  //$('kw').focus();
};
if (document.all) {
  window.attachEvent('onload', addFocus);
} else {
  window.addEventListener('load', addFocus, false);
};
function getSearchSelect(type, n) {
  var strDefault = strOther = '';
  if (n != null) {
    strDefault = '<img src="writable/images/searchmark/' + nowSearchBody + '_' + type + '_' + n + '.gif" title="' + searchSelect[type][n][1] + '" /><br />\n';
  }
  //if (isArray(searchSelect[type])) {
    for (i in searchSelect[type]) {
      if (i != 0 && n != i) {
        strOther += '<img src="writable/images/searchmark/' + nowSearchBody + '_' + type + '_' + i + '.gif" onclick="saveBar(\'' + type + '\',\'' + i + '\');closeOu();" title="' + searchSelect[type][i][1] + '" /><br />\n';
      }
    }
  //}
  return strDefault + strOther;
};
function saveBar(type, n) {
  if (isArray(searchSelect[type])) {
    try {
      $('f').action = $('go').value = searchSelect[type][n][0];
    } catch(e) {}
    try {
      if (nowSearchBody != '3') $('ou_in').innerHTML = getSearchSelect(type, n);
    } catch(e) {}
    var reg = new RegExp('' + type + '\\\{\\\w+\\\}', 'ig');
    var str = (searchBarCookie = getCookie('searchBar')) ? searchBarCookie.replace(reg, '') + '' + type + '{' + n + '}': '' + type + '{' + n + '}';
    setCookie('searchBar', str, 365);
  }
};
function addsearchBar(type, sid) {
  if (isArray(searchSelect[type])) {
    if (searchBarCookie = getCookie('searchBar')) {
      var reg = new RegExp('' + type + '\\\{(\\\w+)\\\}', 'i');
      if (searchBarIs = searchBarCookie.match(reg)) {
        sid = searchBarIs[1];
      }
    } else {
      if (arguments[1]) {
        sid = arguments[1];
      }
    }
    if (sid && typeof(searchSelect[type][sid]) != 'undefined') {
    } else {
      for (i in searchSelect[type]) {
        if (i != 0) {
          sid = i;
          break;
        }
      }
    }
    if ($('searchNavIs') != null) {
      $('searchNavIs').id = $('searchNavIs').name;
    }
    try {
      $('search_bar_type_' + type + '').id = 'searchNavIs';
    } catch(e) {}
    try {
      $('f').action = $('go').value = searchSelect[type][sid][0];
    } catch(e) {}
    try {
      $('ou_in').innerHTML = nowSearchBody == '3' ? getSearchSelect3(type, sid) : getSearchSelect(type, sid);
    } catch(e) {}
    try {
      $('su').innerHTML = searchSelect[type][0];
    } catch(e) {}
    try {
      $('is').value = type;
    } catch(e) {}
    addRemenber(type)
  } else {
    $('su').onclick = function(){
      alert('没有任何搜索引擎被设置，无法执行搜索！');
      return false;
    }
  }
};
function remenber() {
  var strMax = 8;
  var strNum = 6;
  var nowMod = $('is').value;
  var newUrl = $('go').value;
  var newKey = $("kw").value.replace(/^(\s|\r|\n|　)+|(\s|\r|\n|　)+$/g, "").replace(/[\|\<\>\"\']+/g, "");
  var formAc = newUrl + encodeURIComponent(newKey);
  window.open(formAc);
  if (newKey != '') {
    var cutKey = cutStr(newKey, strMax);
    var cookieStr;
    if (cookieStr = getCookie('searchHot')) {
      var setArr = cookieStr.split("|");
      if (setArr.length > 0) {
        for (var i = 0; i < setArr.length; i++) {
          if (setArr[i].indexOf(nowMod) == 0) {
            var str = setArr[i].substr(nowMod.length, setArr[i].length);
            break
          }
        }
        if (str) {
          var reg = new RegExp('<a [^>]+>' + cutKey + '<\\\/a>', 'ig');
          str = str.replace(reg, '');
          str += '&nbsp;<a href="' + formAc + '">' + cutKey + '</a>';
          str = str.replace(/^(&nbsp;)+|(&nbsp;)+$/ig, '').replace(/(&nbsp;)+/ig, '&nbsp;');
          var strarr = str.split("&nbsp;").slice( - strNum);
          var reg2 = new RegExp('' + nowMod + '<a [^\\\|]+', 'ig');
          var newStr = cookieStr.replace(reg2, '' + nowMod + strarr.join('&nbsp;'))
        } else {
          var newStr = cookieStr + '|' + nowMod + '<a href="' + formAc + '">' + cutKey + '</a>'
        }
      }
    } else {
      var newStr = '' + nowMod + '<a href="' + formAc + '">' + cutKey + '</a>'
    }
    if (newStr) {
      setCookie('searchHot', newStr, 365)
    }
  }
  addRemenber(nowMod);
  return false
};
function delRemenber(type) {
  var cookieStr;
  if (cookieStr = getCookie('searchHot')) {
    var reg = new RegExp('' + type + '(<a [^\\\|]+)', 'ig');
    cookieStr = cookieStr.replace(reg, '');
    newCookieStr = cookieStr.replace(/^\|+|\|$/g, '').replace(/\|+/g, '\|');
    setCookie('searchHot', newCookieStr, 365)
  }
  $('search_hot_word').innerHTML = ''
};
function cutStr(str, len) {
  if (!str || !len) {
    return ''
  }
  var strlen = str.length;
  for (var i = 0; i < strlen; i++) {
    if (str.charCodeAt(i) <= 255) {
      len -= 0.5
    } else {
      len--
    }
    if (len <= -0.5) {
      break
    }
  }
  return str.substr(0, i) + (i < strlen ? '…': '')
};