var EXP = 5;

function expand (me, url, destination, num) {
   contentDiv = document.getElementById(me);
   if (contentDiv.value < EXP * num) {
      contentDiv.value = parseInt(contentDiv.value) + num;
   }
   setCookie(me, contentDiv.value, 10);
   ajaxGo(url+contentDiv.value, destination);
   dest = document.getElementById(destination);
   dest.style.display = "block";
}

function collapse (me, url, destination, num) {
   contentDiv = document.getElementById(me);
   if (contentDiv.value > 0) {
      contentDiv.value = parseInt(contentDiv.value) - num;
   }
   setCookie(me, contentDiv.value, 10);
   if (contentDiv.value > 0) {
      ajaxGo(url+contentDiv.value, destination);
   } else {
      dest = document.getElementById(destination);
      dest.innerHTML = "";
      dest.style.display = "none";
   }

}

function collapse_all () {
   d=document.getElementsByTagName('span');
   for(i=0; i<d.length; i++) {
      if (d[i].className == 'cat_div') {
         d[i].innerHTML='';
      }
   }
}

function setSearchEngine (me, value) {
   s = document.getElementById('searchGoogle');
   s.className="tab firstTab";
   s = document.getElementById('searchBidu');
   s.className="tab";
   s = document.getElementById('searchBT');
   s.className="tab";
   s = document.getElementById('searchVeryCD');
   s.className="tab";
   s = document.getElementById('searchMp3');
   s.className="tab";
   s = document.getElementById('searchAnswers');
   s.className="tab";
   s = document.getElementById('searchPic');
   s.className="tab";
   s = document.getElementById('searchCiba');
   s.className="tab";
   s = document.getElementById('searchMW');
   s.className="tab";

   if(value == "google"){
     me.className="tab activeTab firstTab";
   }else {
     me.className="tab activeTab";
   }
   div = document.getElementById('searchEngine');
   div.value = value;
   i = document.getElementById('searchInput');
   i.focus();
}

function doSearch() {
   div = document.getElementById('searchEngine');
   input = document.getElementById('searchInput').value;
   query = input;
   switch (div.value) {
      case 'google':
//        url = "http://www.google.ca/custom?hl=en&domains=star5.ca&client=pub-0692996259905098&forid=1&safe=active&cof=L:http://star5.ca/images/logo_main.gif;S:http://star5.ca;FORID:1&q=" + encodeURIComponent(query);
        url = "http://www.google.ca/custom?hl=en&q=" + encodeURIComponent(query);
         break;
      case 'baidu':
         url = "http://www.baidu.com/s?wd=" + query;
         break;
      case 'verycd':
         url = "http://find.verycd.com/folders/" + query;
         break;
      case 'mp3':
         url = "http://mp3.baidu.com/m?tn=baidump3&ct=134217728&word=" + query;
         break;
      case 'bt':
         url = "http://search.btchina.net/search.php?type=0&query=" + query;
         break;
      case 'answers':
         url = "http://www.answers.com/" + query;
         break;
      case 'pic':
         url = "http://images.google.ca/images?hl=en&q=" + query;
         if (window.RegExp && window.encodeURIComponent) {
           var ue=url;
           var qe=encodeURIComponent(query);
           url=ue.replace(new RegExp("q=[^&$]*"),"q="+qe);
         }
         break;
      case 'ciba':
         url = "http://www.iciba.com/search?s=" + query;
         break;
      case 'm-w':
         url = "http://www.m-w.com/dictionary/" + query;
         break;
   }
   window.open(url);
}

function showSideBar(){
  document.getElementById('sideBar').style.display='';
}
