// Open fix-sized browser window
var win=null;
var divHtmls = new Array();

function openWindow(mp,mn,w,h,i){
	settings="width=" + w + ",height=" + h +  ",top=0,left=0,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes";
	win=window.open(mp,mn,settings);
	win.focus();
}

function hideDiv(id){
  the_div = document.getElementById(id);
  if (the_div) {
     divHtmls[id] = the_div.innerHTML;
     the_div.innerHTML = "";
     the_div.style.display = 'none';
  }
}

function showDiv(id){
  the_div = document.getElementById(id);
  if(the_div.innerHTML == ""){
    the_div.innerHTML = divHtmls[id];
    the_div.style.display = '';
  }else{
    the_div.innerHTML = "";
    the_div.style.display = 'none';
  }
}

function validateForm(id){
  c = document.getElementById('comment');
  if (c.value.length > 0){
    return true;
  }else{
    alert("请留下评论!");
    return false;
  }
}

function addComment(fid) {
   if (validateForm()) {
      f     = document.getElementById(fid);
      sid   = f.srcid;
      scat  = f.srccat;
      uname = f.usr_name;
      ti    = f.title;
      co    = f.comment;
      if (f.rating) {
         for (i=0; i < f.rating.length; i++) {
            if (f.rating[i].checked) {
               i++;
               the_str = '&rt=' + i;
               break;
            }
         }
      } else {
         the_str   = '';
      }
      cl    = document.getElementById('commentList');
      cl.innerHTML = '载入中...';
      d     = new Date();
      ajaxGo('/services/addComment.php?srcid=' + sid.value + '&srccat=' + scat.value + '&usr_name=' + uname.value + '&title=' + ti.value + '&comment=' + co.value + '&rdm=' + d.getTime() + the_str, 'commentList');
      showDiv('commentBox');
   }
   return false;
}

function modifyAd(pwd, fid, action)
{
   password = document.getElementById(pwd);
   if (password.value == '') {
      alert("请输入修改密码！");
      password.setFocus();
      return false;
   }
   a = document.getElementById(fid);
   a.value = action;
   return true;
}

function startup_index(cat) {
   switch (cat) {
     case 'yep':
      collapse_all();
      ajaxGo('/services/get_cat.php?cat_id=4', 'cat_div_4');
      ajaxGo('/yep/getyep.php', 'contentBox');
      ajaxGo('/services/ws_post.php?c=' + cat, 'hotBox');
      break;
     case 'news':
      collapse_all();
      ajaxGo('/services/get_cat.php?cat_id=1', 'cat_div_1');
      ajaxGo('/services/getnews.php', 'contentBox');
      ajaxGo('/services/ws_post.php?c=' + cat, 'hotBox');
      break;
     case 'gallery':
      collapse_all();
      ajaxGo('/services/get_cat.php?cat_id=5', 'cat_div_5');
      ajaxGo('/services/getgallery.php', 'contentBox');
      break;
     case 'deal':
      collapse_all();
      ajaxGo('/services/get_cat.php?cat_id=7', 'cat_div_7');
      ajaxGo('/services/getdeal.php', 'contentBox');
      ajaxGo('/services/ws_post.php?c=' + cat, 'hotBox');
      break;
     case 'url':
      collapse_all();
      ajaxGo('/services/get_cat.php?cat_id=2', 'cat_div_2');
      ajaxGo('/urllist/geturl.php', 'contentBox');
      break;
     case 'cad':
      collapse_all();
      ajaxGo('/services/get_cat.php?cat_id=3', 'cat_div_3');
      ajaxGo('/services/getcad.php', 'contentBox');
      break;
     case 'game':
      collapse_all();
      ajaxGo('/services/get_cat.php?cat_id=6', 'cat_div_6');
      ajaxGo('/services/getgame.php', 'contentBox');
      break;
     case 'expert':
     case 'main':
     default:
      ajaxGo('/services/getnews.php?action=headline', 'news_box');
      ajaxGo('/services/getgallery.php?action=summary', 'gallery_box');
      ajaxGo('/services/getcad.php?action=headline', 'cad_box');
      ajaxGo('/services/getgame.php?action=summary', 'game_box');
      ajaxGo('/urllist/getUrlHomepage.php', 'url_box');
      ajaxGo('/yep/getRecentRes.php', 'recentRes');
      ajaxGo('/services/getdeal.php?action=hot', 'deal_box');
      ajaxGo('/services/getmtv.php', 'mtv_box');
//      ajaxGo('/services/ws_post.php', 'recentReview');
      s=document.getElementById('searchInput');
      s.focus();
   }

}

function startup_sub(cat) {
   switch (cat) {
     case 'yep':
     case 'news':
     case 'gallery':
     case 'deal':
     case 'url':
     case 'expert':
     case 'main':
     default:
   }

}

function startup_popup(cat, id, cat_id) {
   switch (cat) {
     case 'yep':
      ajaxGo('/services/ws_counter.php?a=r&t=' + cat + '&i=' + id, cat + 'Read');
      ajaxGo('/services/getyep.php?a=i&i=' + id, 'yepInfo');
      ajaxGo('/services/getpost.php?srcid=' + id + '&srccat=' + cat_id, 'commentList');
      ajaxGo('/services/ws_website.php?a=r&t=' + cat_id, cat + 'Related');
      ajaxGo('/services/ws_website.php?a=h&t=' + cat_id, 'hotTopic');
      break;
     case 'deal':
      ajaxGo('/services/ws_counter.php?a=r&t=' + cat + '&i=' + id, cat + 'Read');
      ajaxGo('/services/ws_website.php?a=r&t=' + cat_id, cat + 'Related');
      ajaxGo('/services/ws_website.php?a=h&t=' + cat_id, 'hotTopic');
      ajaxGo('/services/getpost.php?srcid=' + id + '&srccat=' + cat_id, 'commentList');
      break;
     case 'news':
      ajaxGo('/services/ws_counter.php?a=r&t=' + cat + '&i=' + id, cat + 'Read');
      ajaxGo('/services/ws_news.php?action=related&cat_id=' + cat_id, cat + 'Related');
      ajaxGo('/services/ws_website.php?action=news&cat_id=' + cat_id, 'hotTopic');
      ajaxGo('/services/getpost.php?srcid=' + id + '&srccat=' + cat_id, 'commentList');
      break;
     case 'cad':
      ajaxGo('/services/ws_counter.php?a=r&t=' + cat + '&i=' + id, cat + 'Read');
      ajaxGo('/services/ws_website.php?a=r&t=' + cat_id, cat + 'Related');
      ajaxGo('/services/ws_website.php?a=R&t=' + cat_id, 'hotTopic');
      ajaxGo('/services/getpost.php?srcid=' + id + '&srccat=' + cat_id, 'commentList');
      break;
     case 'gallery':
     case 'url':
     case 'expert':
     case 'main':
     default:
   }
   hideDiv('commentBox');
   hideDiv('editBox');
}

function startup(page, cat, id, cat_id) {
   switch (page) {
      case 'sub':
         startup_sub(cat);
         break;
      case 'popup':
         startup_popup(cat, id, cat_id);
         break;
      case 'index':
      default:
         startup_index(cat);
         break;
   }
}

function checkAll(name)
{
   field = document.getElementsByName(name);
   for (i = 0; i < field.length; i++)
         field[i].checked = true ;
}

function uncheckAll(name)
{
   field = document.getElementsByName(name);
   for (i = 0; i < field.length; i++)
         field[i].checked = false ;
}

function bookmark(url, description)
{
   netscape = "请按Ctrl+D键把本网站加入收藏夹。谢谢！";
   if (navigator.appName == 'Microsoft Internet Explorer') {
      window.external.AddFavorite(url, description);
   } else if (navigator.appName === 'Netscape') {
      alert(netscape);
   }
}
