var last_menu = null;
var hide_timeout = null;

var stamp = new Date( ).getTime( );

function httpgetstring( formid )
{
  getstring = "";
  firstval = true;
  for( i = 0; i < formid.elements.length; i++ )
  {      
    if( formid.elements[i].name )
    {
      if( formid.elements[i].type != "checkbox" || formid.elements[i].checked )
      {
        if( firstval )
          firstval = false;
        else
          getstring += "&";

        getstring += formid.elements[i].name + "=" + escape( formid.elements[i].value );
      }
    }
  }

  return getstring;
}

function httpload( url, hand )
{
  handler = hand;

  url += "&dynamicload=" + stamp++;

  // branch for native XMLHttpRequest object
  if( window.XMLHttpRequest )
    req = new XMLHttpRequest( );   
  // Branch for IE/Windows ActiveX version
  else if( window.ActiveXObject )
    req = new ActiveXObject( "Microsoft.XMLHTTP" );

  if( req )
  {
    req.open( "GET", url, true );
    req.onreadystatechange = httpready;
    req.send( null );

    return false;
  }
  else
    return true;
}

function httpready( ) 
{
  if( req.readyState == 4 )
    handler( req );
}

function new_wysiwyg( instance, width, height )
{
  var oFCKeditor = new FCKeditor( instance );

  if( oFCKeditor )
  {  
    oFCKeditor.BasePath	= "htmleditor/" ;
    oFCKeditor.Width = width;
    oFCKeditor.Height = height;
    oFCKeditor.ToolbarSet = "Basic"; // This can be changed to "Advanced"

    oFCKeditor.ReplaceTextarea( );

    document.all["html"].value = 1; // HTML is used in this field
  }
}

function wysiwyg_inserthtml( instance, data )
{
	var oEditor = FCKeditorAPI.GetInstance( instance );

	if( oEditor.EditMode == FCK_EDITMODE_WYSIWYG )
		oEditor.InsertHtml( data );
  else
    document.all[instance].value += data;
}

function wysiwyg_sethtml( instance, data )
{
	var oEditor = FCKeditorAPI.GetInstance( instance );

	if( oEditor.EditMode == FCK_EDITMODE_WYSIWYG )
		oEditor.SetHTML( data );
  else
    document.all[instance].value = val;
}

function display_menu( target )
{
  if( target )
  {
    if( last_menu )
      hide_menu( );

    if( hide_timeout )
      clearTimeout( hide_timeout );

    var obj = document.getElementById( target );
    var parent = document.getElementById( target + "_parent" );

    obj.style.left = (getPageOffsetLeft( parent ) - 1) + "px";
    obj.style.top = (getPageOffsetTop( parent ) + parent.offsetHeight) + "px";
    obj.style.visibility = "visible";

    last_menu = obj;
  }
  else
    hide_timeout = setTimeout( "hide_menu()", 300 );     
}

function hide_menu( )
{
  last_menu.style.visibility = "hidden";
  last_menu = null;
  clearTimeout( hide_timeout );
}

function hover( el, obj )
{
  el.oldColor = el.style.backgroundColor;
  el.style.backgroundColor = '#FFFFFF';

  if( obj )
    show( obj );
}

function unhover( el, obj )
{
  el.style.backgroundColor = el.oldColor;

  if( obj )
    hide( obj );
}

function getPageOffsetLeft( el )
{
  var x;

  x = el.offsetLeft;
  if( el.offsetParent )
    x += getPageOffsetLeft( el.offsetParent );

  return x;
}

function getPageOffsetTop( el )
{
  var y;

  y = el.offsetTop;
  if( el.offsetParent )
    y += getPageOffsetTop( el.offsetParent );

  return y;
}

function define( what, def )
{
  wnd = window.open( "","","width=400,height=338" );
  wnd.document.writeln( "<font size='+1'><b>" + what + ":</b></font><hr /><br />" );
  wnd.document.writeln( def );
}

function change_vis( obj )
{
  if( navigator.userAgent.indexOf( "MSIE" ) == -1 )
  {
    var o = document.getElementById( obj );
    if( o.style.display == "none" )
    {
      if( o.tagName == "TR" )
        o.style.display = "table-row";
      else
        o.style.display = "block";
    }
    else
      o.style.display = "none";
  }
  else
  {
    if( document.all[obj].style.display == "none" )
      document.all[obj].style.display = "block";
    else
      document.all[obj].style.display = "none";
  }
}  

function set_vis( obj, vis )
{
  if( navigator.userAgent.indexOf( "MSIE" ) == -1 )
  {
    var o = document.getElementById( obj );
    if( vis )
    {
      if( o.tagName == "TR" )
        o.style.display = "table-row";
      else
        o.style.display = "block";
    }
    else
      o.style.display = "none";
  }
  else
  {
    if( vis )
      document.all[obj].style.display = "block";
    else
      document.all[obj].style.display = "none";
  }
}

document.onmousemove = mouseMove;
if( document.layers ) document.captureEvents( Event.MOUSEMOVE );

var cur_obj;
var x_offset = 5, y_offset = 5;
var x, y;

function show( obj )
{
  cur_obj = obj;

  if( document.all[cur_obj] )
  {
    if( ( x + document.all[cur_obj].offsetWidth + x_offset ) > document.body.clientWidth )
      x -= document.all[cur_obj].offsetWidth + 2*x_offset;
    if( ( y + document.all[cur_obj].offsetHeight + y_offset ) > document.body.clientHeight )
      y -= document.all[cur_obj].offsetHeight + 2*y_offset;

    document.all[cur_obj].style.left = document.body.scrollLeft + x + x_offset;
    document.all[cur_obj].style.top = document.body.scrollTop + y + y_offset;

    document.all[cur_obj].style.visibility = "visible";
  }
}

function hide( obj )
{
  cur_obj = null;

  if( document.all[obj] )
    document.all[obj].style.visibility = "hidden";
}

function mouseMove( e )
{
  if( document.all )
  {
    x = event.clientX;
    y = event.clientY;
  }
  else
  {
    x = e.clientX;
    y = e.clientY;
  }

  if( document.getElementById(cur_obj) )
  {
    if( ( x + document.all[cur_obj].offsetWidth + x_offset ) > document.body.clientWidth )
      x -= document.all[cur_obj].offsetWidth + 2*x_offset;
    if( ( y + document.all[cur_obj].offsetHeight + y_offset ) > document.body.clientHeight )
      y -= document.all[cur_obj].offsetHeight + 2*y_offset;

    document.all[cur_obj].style.left = document.body.scrollLeft + x + x_offset;
    document.all[cur_obj].style.top = document.body.scrollTop + y + y_offset;
  }
}

