// JavaScript Document

// detect browser
var browser=navigator.appName
var b_version=navigator.appVersion
var version=parseFloat(b_version)
var winW;
var winH;

// determine size of browser window
function OnLoad() {
  if (parseInt(navigator.appVersion)>3) {
   if (browser=="Netscape") {
    winW = window.innerWidth;
    winH = window.innerHeight;
   }
   if (browser.indexOf("Microsoft")!=-1) {
    winW = document.body.offsetWidth;
    winH = document.body.offsetHeight;
   }
  }
}

// article -------------------------------------------------------------------------------
function ArticleChangeVersion() {
  var version=document.getElementById("VERSION");
  document.forms.content_area.action="?view_article&version="+version.value;
  document.forms.content_area.submit();  
}

function ArticlePublish() {
  document.forms.content_area.action="?publish_article";
  document.forms.content_area.submit();
}

function ArticleCover() {
  document.forms.content_area.action="?cover_article";
  document.forms.content_area.submit();
}

function EmailLink() {
  document.forms.content_area.action="?email_link";
  document.forms.content_area.submit();
}

function WasItUsefull() {
  document.forms.content_area.action="?usefull";
  document.forms.content_area.submit();
}

function Suggestion() {
  document.forms.content_area.action="?suggestion";
  document.forms.content_area.submit();
}

function Proposal() {
  document.forms.content_area.action="?proposal";
  document.forms.content_area.submit();
}

// section -------------------------------------------------------------------------------
function SectionChangeVersion() {
  var version=document.getElementById("VERSION");
  document.forms.content_area.action="?view_section&version="+version.value;
  document.forms.content_area.submit();  
}

function SectionNew() {
  document.forms.content_area.action="?new_section";
  document.forms.content_area.submit();
}

function SectionEdit() {
  document.forms.content_area.action="?edit_section";
  document.forms.content_area.submit();
}

function SectionSave() {
  document.forms.content_area.action="?save_section";
  document.forms.content_area.submit();
}

function SectionView() {
  document.forms.content_area.action="?view_section";
  document.forms.content_area.submit();
}

function SectionCancel() {
  document.forms.content_area.action="?cancel_section";
  document.forms.content_area.submit();
}

function SectionDelete(sid, msg1, msg2) {
  if (window.confirm(msg1)) {
    if (window.confirm(msg2)) {
      document.forms.content_area.action="?delete_section&section="+sid;
      document.forms.content_area.submit();
    }
  }
}

function PageMap () {
  document.forms.content_area.action="?page_map";
  document.forms.content_area.submit();
}

function News () {
  document.forms.content_area.action="?news";
  document.forms.content_area.submit();
}

function Book() {
  b=document.getElementById("BOOKED");
  if (b.checked) {
    document.forms.content_area.action="?book";
  } else {
    document.forms.content_area.action="?unbook";
  }
  document.forms.content_area.submit();
}

function HasBoard() {
  if (document.getElementById("BOARD").checked) {
    document.getElementById("PANEL_BOARD").style.display="block";
  } else {
    document.getElementById("PANEL_BOARD").style.display="none";
  }
}

function SetThemesOrder() {
  document.forms.content_area.action="?set_themes_order";
  document.forms.content_area.submit();
}

function Quote(board_id) {
  var reply=document.getElementById("CONTENT");
  AjaxStart();
  if (xmlHttp) {
    xmlHttp.onreadystatechange=function() {
      switch (xmlHttp.readyState) {
        case 1:
          reply.focus();
          break;
        case 4: // The request is complete
          reply.value=reply.value+xmlHttp.responseText;
          reply.scrollTop=reply.scrollHeight-reply.clientHeight;
          break;
      }
    }
    xmlHttp.open(
      "GET",
      "ajax.php?GET_QUOTE&bid="+board_id,
      true
    );
    xmlHttp.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
    xmlHttp.send(null);
  }
}

function DeleteRating(tid, rid) {
  AjaxStart();
  if (xmlHttp) {
    xmlHttp.onreadystatechange=function() {
      switch (xmlHttp.readyState) {
        case 4: // The request is complete
          //alert(xmlHttp.responseText);
          var row=document.getElementById('F_'+rid+'_A');
          document.getElementById(tid).deleteRow(row.rowIndex);
          var row=document.getElementById('F_'+rid+'_B');
          document.getElementById(tid).deleteRow(row.rowIndex);
          break;
      }
    }
    xmlHttp.open(
      "GET",
      "ajax.php?DELETE_RATING&rid="+rid,
      true
    );
    xmlHttp.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
    xmlHttp.send(null);
  }
}
