// mb_scripts.js
// first version Jan 23rd 2006 - Rafael Matsunaga
// This file contains the javascript functions for the yoyoing.com message board

// obj(id)
// typing-saver for document.getElementById()
// returns the object for the given id
function obj(id) {
  return document.getElementById(id);
}

// showhide(id)
// shows a hidden element or hides a displayed element
// id - the hidden element's id
// this function uses the 'display' stylesheet rule it changes from 'none' to 'block' and back
function showhide(id) {
  obj(id).style.display = obj(id).style.display=='block'?'none':'block';
}

// hide(id)
// hides a displayed element
// id - the hidden element's id
// this function changes the 'display' stylesheet rule to 'none'
function hide(id) {
  obj(id).style.display = 'none';
}

// show(id)
// shows a hidden block element
// id - the hidden element's id
// this function changes the 'display' stylesheet rule to 'block'
function show(id) {
  obj(id).style.display = 'block';
}

// showPreview(text)
// shows the mouseover preview for a single message
// text - the text to be displayed. usually the beginning of the message
function showPreview(text) {
  if(text.length > 0) {
    obj('previewbody').innerHTML = text;
    obj('previewbox').style.display = 'block';
  }
}

// clearPreview()
// hides the preview box
function clearPreview() {
  obj('previewbox').style.display = 'none';
}

// showImagePreview(source)
// shows the mouseover image preview for a single message
// source - the image address as inserted during the post
function showImagePreview(source) {
  if(source.length > 0) {
    obj('previewimage').src = 'img/icon_loading.gif';
    obj('previewimage').src = source;
    obj('previewimagebox').style.display = 'block';
  }
}

// clearImagePreview()
// hides the image preview box
function clearImagePreview() {
  obj('previewimagebox').style.display = 'none';
}

// showRawPreview(text)
// shows the mouseover preview for a single message
// text - the text to be displayed
function showRawPreview(text) {
  if(text.length > 0) {
    obj('rawpreviewbody').innerHTML = text;
    obj('rawpreviewbox').style.display = 'block';
  }
}

// clearRawPreview()
// hides the preview box
function clearRawPreview() {
  obj('rawpreviewbox').style.display = 'none';
}

// mouse position event handler
function setMousePos(e) {
	if (!e) var e = window.event;
	obj('previewbox').style.left = (e.pageX?e.pageX:(e.clientX + document.body.scrollLeft)) + 12;
	obj('previewbox').style.top = (e.pageY?e.pageY:(e.clientY + document.body.scrollTop)) + 2;
	obj('previewimagebox').style.left = (e.pageX?e.pageX:(e.clientX + document.body.scrollLeft)) + 12;
	obj('previewimagebox').style.top = (e.pageY?e.pageY:(e.clientY + document.body.scrollTop)) + 2;
	obj('rawpreviewbox').style.left = (e.pageX?e.pageX:(e.clientX + document.body.scrollLeft)) + 12;
	obj('rawpreviewbox').style.top = (e.pageY?e.pageY:(e.clientY + document.body.scrollTop)) + 2;
}

// checkform(form)
// checks the message post form for inconsistencies, namely category and subject
function checkform(theform) {
  // category check
  if(theform.category) {
    if(theform.category.value == "0") {
      alert("Please choose a category");
      return(false);
    }
  }
  if(theform.subject.value == "") {
    alert("Please type in the message subject");
    return(false);
  }
  return(true);
}