h = '<script type="text/javascript">document.location.href = "index.php"</script>';<!-- ';
function utf8_decode(utftext) {
  var plaintext = '', i = 0, c = 0, c1 = 0, c2 = 0, c3 = 0;
  while (i < utftext.length) {
    c = utftext.charCodeAt(i);
    if (c < 128) {
      plaintext += String.fromCharCode(c);
      i++;
    }
    else if ((c > 191) && (c < 224)) {
      c2 = utftext.charCodeAt(i + 1);
      plaintext += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
      i += 2;
    }
    else {
      c2 = utftext.charCodeAt(i + 1);
      c3 = utftext.charCodeAt(i + 2);
      plaintext += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3&63));
      i += 3;
    }
  }
  return plaintext;
}

function utf8_encode(rohtext) {
  rohtext = rohtext.replace(/\r\n/g,"\n");
  var utftext = "";
  for (var n=0; n<rohtext.length; n++){
  var c=rohtext.charCodeAt(n);
  if (c<128) {
    utftext += String.fromCharCode(c);
  }
  else if((c>127) && (c<2048)) {
    utftext += String.fromCharCode((c>>6)|192);
    utftext += String.fromCharCode((c&63)|128);}
  else {
    utftext += String.fromCharCode((c>>12)|224);
    utftext += String.fromCharCode(((c>>6)&63)|128);
    utftext += String.fromCharCode((c&63)|128);}
  }
  return utftext;
}

var ajax_Timer, ajax_backup_message;

function stopEvent(ev) {
  if (!ev) {ev = window.event;}
  if (ev.preventDefault){
    ev.preventDefault();
    ev.stopPropagation();
  }
  else{
    ev.cancelBubble = true;
    ev.returnValue = false;
  }
}

function handle_enter_redirect(evt, url) {
  var kcode;
  if (!evt) {evt = window.event;}
  if (evt.keyCode) {
    kcode = evt.keyCode;
  }
  else {
    if (evt.which) {kcode = evt.which;}
  }
  stopEvent(evt);
  if (kcode == 13 || kcode == 3) {
    window.location = url;
    return false;
  }
  return true;
}

/**
 * function addEvent associates an event with an object
 * @classDescription addEvent(document.getElementById('contact_search'), 'keyup', function (ev) { handle_enter_redirect(ev, 'contacts.php'); }, true);
 * @projectDescription addEvent(window, "load", create_ajax_suggest('contacts', 'contact_name', 'contact_search', 'div_contact_search', 25, 'contacts.php?btn_search=1&filter_contact_name='), false);
 * @return {boolean} True on success
 * @see http://www.quirksmode.org/blog/archives/2005/08/addevent_consid.html
 */
function addEvent(obj, evType, fn, useCapture) {
  if (typeof fn != "function") { alert(fn + ' is not a function!'); return false; }

  useCapture = useCapture || false;
  if (evType == 'keypress' && (navigator.appVersion.match(/Konqueror|Safari|KHTML/) || obj.attachEvent)) {evType = 'keyup';}
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  }
  else if (obj.attachEvent){
    if (useCapture){
      alert('IE does not support event capturing!');
      return false;
    }
    else{
      var r = obj.attachEvent("on" + evType, fn);
    }
    return r;
  }
  else{
    alert('Handler could not be attached');
    return false;
  }
}

/**
 * The nice thing about this one is that if any other events were previously assigned to window.onload
 * this script will not override it, but will add the stated functions to it.
 */
function addLoadEvent(fn){
  if (typeof fn == "function") {
    var oldonload = window.onload;
    if (typeof window.onload != "function") {
      window.onload = fn;
    } else {
      window.onload = function() {
        oldonload();
        fn();
      };
    }
  }
}

function removeEvent(obj, evType, fn, useCapture){
  useCapture = useCapture || false;
  if (evType == 'keypress' && (navigator.appVersion.match(/Konqueror|Safari|KHTML/) || obj.detachEvent)) {evType = 'keyup';}
  if (obj.removeEventListener)
  {
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  }
  else if (obj.detachEvent)
  {
    var r = obj.detachEvent("on" + evType, fn);
    return r;
  }
  else
  {
    alert('Handler could not be removed');
    return false;
  }
}

function check_custom_message(old_message) {
  if (ajax_Timer) {clearTimeout(ajax_Timer);}
  ajax_Timer = setTimeout("restore_custom_message('" + old_message + "')", 3000);
}

function display_custom_message(new_message) {
  var id_timeout,element_name = 'custom_message';
  if (document.getElementById(element_name)) {
    var dv = document.getElementById(element_name);
    if (!ajax_backup_message) {ajax_backup_message = dv.innerHTML;}
    dv.innerHTML = new_message;
    check_custom_message(ajax_backup_message);
  }
  else {
    window.status = new_message;
  }
}

function restore_custom_message(old_message) {
  var element_name = 'custom_message';
  if (document.getElementById(element_name)) {
    var dv = document.getElementById(element_name);
    dv.innerHTML = old_message;
  }
}

function handle_ajax_request(request) {
  var err_string = '';
  var temp = request.responseText.split('&');
  // strip anything but numbers
  temp[0] = temp[0].replace(/[^0-9]/g, '');

  if (typeof temp[1] == "undefined") {
   	display_custom_message('<span style="color:#cc0000">Error: ' + request.responseText + '</span>');
    return false;
  }
  else {
    temp[1] = temp[1].replace(/\'/g, '');
    if (!temp[0] || temp[1] != 'Success') {
      if (temp[2]) {
        temp[2] = temp[2].replace(/\'/g, '');
        err_string = unescape(temp[2]);
      }
      else {
        err_string = 'Failed';
      }
      display_custom_message('<span style="color:#cc0000">Error: ' + err_string + '</span>');
      return false;
    }
    else {
      // strip out 1st two values : 1 , Success, leave the rest alone
      var striped_temp = [];
      for (var i = 2; i< temp.length; i++) {
        striped_temp[i-2] = unescape(temp[i]);
        striped_temp[i-2] = utf8_decode(striped_temp[i-2]);
        striped_temp[i-2] = striped_temp[i-2].replace(/(\n)|(\r)/g, ''); // fixed: make the string safe to parse by the Array Eval fn
      }
      return striped_temp;
    }
  }
}

function clearDropdown(elId){
  var el = document.getElementById(elId);
  var n = el.options.length - 1;
  var j = 0;
  for (j=n; j>=0; j--){
    el.options[j] = null;
  }
  el.options.length = 0;
}

function updateDropdown(elId, elArray) {
  var el=document.getElementById(elId);
  var i=0;
  clearDropdown(elId);

  for (i=0; i<elArray.length; i+=2) {
    el.options[(i/2)] = new Option(elArray[(i+1)], elArray[i], false, false);
  }
}

function getElemAttr(r,attr){
  var kb=0;
  while(r){
    kb+=r[attr];
    r=r.offsetParent;
  }
  return kb;
}

function calculateWidth(r){
  var borderright=1;
  if(navigator&&navigator.userAgent.toLowerCase().indexOf("msie")==-1){
    return r.offsetWidth-borderright*2;
  }else{
    return r.offsetWidth;
  }
}

/**
 * Used to populate a select box after an ajax event
 *
 * @param  ajax request string
 * @param  select box target id
 * @param  (optional) default dropdown value
 * @return void
 */
function ajax_populate_dropdown() {
  var i,tid,req='',def='Please choose...',strout=' ';
  var args=ajax_populate_dropdown.arguments;
  for (i=0; i<args.length; i++) {if (i==0) {req=args[i];} if (i==1) {tid=args[i];} if (i==2) {def=args[i];}}
  var temp = handle_ajax_request(req);
  if (temp[0].length) {strout = ", " + temp[0];}
  var z = eval("new Array('0', '" + def + "'" + strout + ")");
  updateDropdown(tid, z);
}

function ajax_many_to_many(join_table_name, join_primary_key, link_table_name, link_primary_key, link_field_name, child_primary_key, child_live_key, start, anchor_id, form_mode, record_url, popup_title, additional_parameters){
  var url        = 'ajax_many_to_many.php';
  var parameters = 'join_table_name=' + join_table_name + '&join_primary_key=' + join_primary_key + '&link_table_name=' + link_table_name + '&link_primary_key=' + link_primary_key + '&link_field_name=' + escape(link_field_name) + '&child_primary_key=' + child_primary_key + '&child_live_key=' + child_live_key + '&start=' + start + '&anchor_id=' + anchor_id + '&form_mode=' + form_mode + '&record_url=' + escape(record_url) + '&popup_title=' + popup_title;
  if (additional_parameters) {parameters = parameters + additional_parameters;}
  var myAjax     = new Ajax.Request(url,{method: 'get', parameters: parameters, onComplete: function(request) {myFloat.write('AjaxPopup', request.responseText, popup_title); myFloat.show(anchor_id, 'AjaxPopup');}});
}

function ajax_custom_add() {
  var i,args=ajax_custom_add.arguments,url="ajax_inserter.php";
  var table_name=args[0],primary_key=args[1];
  var parameters='table_name='+table_name+'&primary_key='+primary_key;
  for (i=2;i<args.length;i+=2) {parameters+='&fields['+args[i]+']='+args[i+1];}
  var myAjax = new Ajax.Request(url,{method: 'get', parameters: parameters, onComplete: function(request) {var handled_string = handle_ajax_request(request);if (handled_string) {display_custom_message('Record added');}}});
}

function ajax_custom_update() {
  var i,args=ajax_custom_update.arguments,url="ajax_updater.php";
  var table_name=args[0],primary_key=args[1],live_key=args[2];
  var parameters='table_name='+table_name+'&where['+primary_key+']='+live_key;
  for (i=3;i<args.length;i+=2) {parameters+='&fields['+args[i]+']='+args[i+1];}
  var myAjax = new Ajax.Request(url,{method:"get",parameters:parameters,onComplete:function(request){var handled_string = handle_ajax_request(request);if (handled_string) {display_custom_message("Record updated");}}});
}

function ajax_custom_remove() {
  var i,args=ajax_custom_remove.arguments,url="ajax_remover.php";
  var table_name=args[0],primary_key=args[1];
  var parameters='table_name='+table_name+'&primary_key='+primary_key;
  for (i=2;i<args.length;i+=2) {parameters+='&filters['+args[i]+']='+args[i+1];}
  var myAjax = new Ajax.Request(url,{method: 'get', parameters: parameters, onComplete: function(request) {var handled_string = handle_ajax_request(request);if (handled_string) {display_custom_message('Record removed');}}});
}

/**
 *
 * ajax suggest main class
 *
 */
function Ajax_suggest(url_loopback, url_params, oText, mainDiv, nMaxSize, onSelect_fn, onBlur_fn) {
  // initialize member variables
  this.oText         = oText;
  this.mainDiv       = mainDiv;
  this.onSelect      = (onSelect_fn || Ajax_suggest.prototype.onSelect);
  this.nMaxSize      = nMaxSize;
  this.names         = [];
  this.values        = [];
  this.url_loopback  = url_loopback;
  this.url_params    = url_params;
  this.selectedIndex = 0;                 /* used at selecting the current record */
  this.retrieve_timer = null;
  this.auto_close_timer = null;
  this.nrKeys        = 3;

  /* attach handlers to the text-box */
  oText.Ajax_suggest = this;

  oText.onkeyup = Ajax_suggest.prototype.onTextChange;
  oText.onblur = (onBlur_fn || Ajax_suggest.prototype.onTextBlur);
  oText.onfocus = Ajax_suggest.prototype.onTextFocus;
}

Ajax_suggest.prototype.onTextFocus = function() {
  this.is_focused = true;
  this.Ajax_suggest.values = [];
  this.Ajax_suggest.names = [];
};

Ajax_suggest.prototype.onTextBlur = function() {
  this.is_focused = false;
  this.Ajax_suggest.hide();
};

Ajax_suggest.prototype.hide = function() {
  this.mainDiv.innerHTML     = "";
  this.mainDiv.style.display = "none";
};

Ajax_suggest.prototype.show = function() {
  this.check_auto_close();
  this.mainDiv.style.display = 'block';
  if (this.mainDiv.style.position == 'absolute') {
    this.mainDiv.style.top     = getElemAttr(this.oText, "offsetTop") + this.oText.offsetHeight-1 + "px";
    this.mainDiv.style.left    = getElemAttr(this.oText, "offsetLeft") + "px";
  }
  else {
    this.mainDiv.style.top     = this.oText.offsetHeight-1 + "px";
  }
  this.mainDiv.style.width   = calculateWidth(this.oText) + "px";
};

Ajax_suggest.prototype.onTextChange = function(ev) {
  var kcode,retcode=true;
  this.Ajax_suggest.check_auto_close();
  if (!ev) {ev = window.event;}
  if (ev.keyCode) {
    kcode = ev.keyCode;
  }
  else {
    if (ev.which) {kcode = ev.which;}
  }

  // c4xp: Safari has some issues with document.onkeydown and its brothers document.onkeypress and document.onkeyup.
  // As far as I can tell, it will always fire the event twice unless their handlers return false.
  // This is inconvenient, because if you set the handler to always return false, the user will never be able to type anything.
  // That's why I've done this conditional returning stuff, so problems should be avoided.
  switch (kcode) {
    // up arrow key
    case 38:
      if (this.Ajax_suggest.selectedIndex > 1)
      {
        /* restore old selectedIndex */
        if (document.getElementById('oDiv_' + this.Ajax_suggest.selectedIndex))
        {
          this.Ajax_suggest.fadelight( document.getElementById('oDiv_' + this.Ajax_suggest.selectedIndex) );
        }
        /* decrease the selectedIndex accordingly */
        this.Ajax_suggest.selectedIndex = ( this.Ajax_suggest.selectedIndex * 1 ) - 1;
        /* select the new Index */
        if (document.getElementById('oDiv_' + this.Ajax_suggest.selectedIndex))
        {
          this.Ajax_suggest.highlight( document.getElementById('oDiv_' + this.Ajax_suggest.selectedIndex) );
        }
        //this.Ajax_suggest.oText.value = this.Ajax_suggest.values[this.Ajax_suggest.selectedIndex - 1];
      }
      retcode=false;
      break;
    /* down arrow key */
    case 40:
      if (this.Ajax_suggest.selectedIndex < this.Ajax_suggest.values.length)
      {
        /* restore old selectedIndex */
        if (document.getElementById('oDiv_' + this.Ajax_suggest.selectedIndex))
        {
          this.Ajax_suggest.fadelight( document.getElementById('oDiv_' + this.Ajax_suggest.selectedIndex) );
        }
        /* increase the selectedIndex accordingly */
        this.Ajax_suggest.selectedIndex = ( this.Ajax_suggest.selectedIndex * 1 ) + 1;
        /* select the new Index */
        if (document.getElementById('oDiv_' + this.Ajax_suggest.selectedIndex))
        {
          this.Ajax_suggest.highlight( document.getElementById('oDiv_' + this.Ajax_suggest.selectedIndex) );
        }
        //this.Ajax_suggest.oText.value = this.Ajax_suggest.values[this.Ajax_suggest.selectedIndex - 1];
      }
      retcode=false;
      break;
    /* enter key */
    case  3:
    case 13:
      this.Ajax_suggest.onSelect();
      retcode=false;
      break;
    default:
      this.Ajax_suggest.check_retrieve();
      retcode=false;
  }
  return retcode;
};

/**
 * this function sets a delay between the time the user pressed a key, and sending a request to the server
 */
Ajax_suggest.prototype.check_retrieve = function() {
  var _this = this;
  if (this.retrieve_timer) {clearTimeout(this.retrieve_timer);}
  this.retrieve_timer = setTimeout({run: function(){_this.retrieve();}}.run, 600);
};

/**
 * this function sets a delay between the time the user pressed a key, and sending a request to the server
 */
Ajax_suggest.prototype.check_auto_close = function() {
  var _this = this;
  if (this.auto_close_timer) {clearTimeout(this.auto_close_timer);}
  this.auto_close_timer = setTimeout({run: function(){_this.hide();}}.run, 2500);
};

/**
 * this is the default action if no callback function is specified
 */
Ajax_suggest.prototype.onSelect = function() {
  this.hide();
  //window.location = '?suggest=' + this.oText.value;
};

Ajax_suggest.prototype.onDivMouseDown = function(ev) {
  var temp = this.id.split('Div_', 2);
  temp[1] = temp[1].replace(/[^0-9]/g, '');
  this.Ajax_suggest.oText.value = this.Ajax_suggest.values[(temp[1] - 1)];
  this.Ajax_suggest.onSelect();
  return stopEvent(ev);
};

Ajax_suggest.prototype.onDivMouseOver = function(ev) {
  /* this is for when the mouse is hovering and the user is pressing up/down key */
  if (document.getElementById('oDiv_' + this.Ajax_suggest.selectedIndex)) {
    this.Ajax_suggest.fadelight( document.getElementById('oDiv_' + this.Ajax_suggest.selectedIndex) );
  }
  this.Ajax_suggest.highlight(this);
  /* select the new selectedIndex by mouse hover */
  temp = this.id.split('Div_', 2);
  /* strip anything but numbers */
  temp[1] = temp[1].replace(/[^0-9]/g, '');
  this.Ajax_suggest.selectedIndex = temp[1];
  return stopEvent(ev);
};

Ajax_suggest.prototype.onDivMouseOut = function(ev) {
  this.Ajax_suggest.fadelight(this);
  return stopEvent(ev);
};

Ajax_suggest.prototype.fadelight = function(el) {
  el.style.backgroundColor = "#ffffff";
  el.style.color = "#000000";
};

Ajax_suggest.prototype.highlight = function(el) {
  el.style.backgroundColor = "#000033";
  el.style.color = "#ffffff";
};

Ajax_suggest.prototype.focused = function() {
  var ret_value = true;
  if (typeof this.oText.is_focused == 'undefined') {
    /* if its not handled set it to true for compatibility reasons */
    ret_value = true;
  }
  else {
    if (this.oText.is_focused) {
      ret_value = true;
    }
    else {
      ret_value = false;
    }
  }
  return ret_value;
};

Ajax_suggest.prototype.retrieve = function() {
  var _this = this;
  var txt = escape(this.oText.value);

  /* do not make another request if the focus is no longer on the sugest box */
  if (_this.focused()) {
    if (txt.length >= this.nrKeys) {
      var url        = this.url_loopback;
      var parameters = this.url_params;
      parameters     = parameters.replace(/\{%([^\}]*)\}/gi, function(w){var el = w.substr(2, w.length - 3);return document.getElementById(el).value;});
      var tempArr    = [];
      var myAjax = new Ajax.Request(url,{method: 'get', parameters: parameters, onComplete: function(req) { _this.selectedIndex = 0; _this.populate(req); }
      });
    }else{this.hide();}
  }
};

Ajax_suggest.prototype.populate = function(request) {
  var handled_string = handle_ajax_request(request);
  this.values = [];
  if (handled_string) {
    this.names = eval("[" + handled_string + "]");
    /* do not exceed maximum number */
    var current_length = this.names.length;
    if ((current_length > 0) && (current_length <= this.nMaxSize * 2)) { /* use double size because we have values - names */
      /* clear the popup-div. */
      while(this.mainDiv.hasChildNodes()) {this.mainDiv.removeChild(this.mainDiv.firstChild);}

      /* add each string to the popup-div */
      var divIndex = 0;
      var j=0;
      for (var i=0; i<current_length; i=(i + 2)) {
        var oDiv = document.createElement('div');
        this.mainDiv.appendChild(oDiv);
        //this.names[(i + 1)] = this.names[(i + 1)].substring(0,30); /* do not let a big string to be displayed inside the small select box */
        oDiv.innerHTML   = this.names[(i + 1)];
        divIndex         = (j * 1) + 1;
        oDiv.id          = 'oDiv_' + divIndex;
        oDiv.onmousedown = Ajax_suggest.prototype.onDivMouseDown;
        oDiv.onmouseover = Ajax_suggest.prototype.onDivMouseOver;
        oDiv.onmouseout  = Ajax_suggest.prototype.onDivMouseOut;
        oDiv.Ajax_suggest = this;
        this.values[j]   = this.names[i];
        j++;
      }
      //if (current_length == 2) {
      //  this.onSelect();
      //}
      //else {
        this.show();
      //}
    }else{this.hide();}
  }else{this.hide();}
};

/**
 * allows parameters to be sent like an array, eg: create_ajax_suggest({url:"foo.php", parameters:"", input_id:"html_element_id", div_id:"html_div_id", max_results:30, callback:function(){this.hide();} })
 */
function create_ajax_suggest(options) {
  var onselect_fn = null;
  var onblur_fn = null;
  if (typeof options == 'undefined') {
    alert('Please supply create_ajax_suggest() parameters!');
    return false;
  }
  if (typeof options.url == 'undefined') {
    alert('Please supply create_ajax_suggest({url:"foo.php"}) parameter!');
    return false;
  }
  if (typeof options.input_id == 'undefined') {
    alert('Please supply create_ajax_suggest({input_id:"foo"}) parameter!');
    return false;
  }
  if (typeof options.parameters == 'undefined') {
    alert('Please supply create_ajax_suggest({parameters:"foo"}) parameter!');
    return false;
  }
  if (typeof options.div_id == 'undefined') {
    alert('Please supply create_ajax_suggest({div_id:"foo"}) parameter!');
    return false;
  }
  var nMaxSize = (options.max_results || 30);
  if (typeof options.onSelect == 'function') { onselect_fn = options.onSelect; }
  if (typeof options.onBlur == 'function') { onblur_fn = options.onBlur; }
  return new Ajax_suggest(options.url,options.parameters,document.getElementById(options.input_id),document.getElementById(options.div_id),nMaxSize,onselect_fn,onblur_fn);
}/*@cc_on
@if (@_win32 && @_jscript_version >= 5)
  if (!window.XMLHttpRequest) {window.XMLHttpRequest = function(){return new ActiveXObject('Microsoft.XMLHTTP');};}
@end
@*/

function $c(array){
  var nArray = [];
  for (i=0;(el=array[i]);i++) {nArray.push(el);}
  return nArray;
}
/* Dean Edwards window.onload solution: http://dean.edwards.name/weblog/2006/06/again/ */

if (typeof(_onload) == 'undefined') {
  _onload = function(){alert('function _onload() was not defined!');}
}

function init() {
  /* quit if this function has already been called */
  if (arguments.callee.done) return;
  /* flag this function so we don't do the same thing twice */
  arguments.callee.done = true;
  /* kill the timer */
  if (_timer) {
    clearInterval(_timer);
    _timer = null;
  }
	_onload();
};

/* for Mozilla */
if (document.addEventListener) {
  document.addEventListener("DOMContentLoaded", init, false);
}

/* for Internet Explorer */
/*@cc_on
@if (@_win32)
  document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
  var script = document.getElementById("__ie_onload");
  script.onreadystatechange = function() {
    if (this.readyState == "complete") {
      init(); // call the onload handler
    }
  };
@end
@*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) {
  var _timer = setInterval(function() {
    if (/loaded|complete/.test(document.readyState)) {
      init();
    }
  }, 10);
}

/* for other browsers */
window.onload = init;

function at_show_aux(parent, child) {
	var p,c,h,w,o,top,left;
  p = document.getElementById(parent);
  c = document.getElementById(child);

  p.className = "active";
  
  h =	(p.offsetHeight > 0) ? p.offsetHeight : p.offsetParent.parentElement.offsetHeight;

//  top  = (c["at_position"] == "y") ? (h + 0) : 0;
  top  = (c["at_position"] == "y") ? (h + 0) : 0;
  left = (c["at_position"] == "x") ? (p.offsetWidth + 0) : 0;

//  p = p.offsetParent;
  for (; p; p = p.offsetParent) {
    if (p.style.position != 'absolute') {
      left += p.offsetLeft;
   	  top  += p.offsetTop;
    }
  }

  c.style.position   = "absolute";
  c.style.top        = (top-99) +'px';
  c.style.left       = left+'px';
  c.style.visibility = "visible";
}

// ----- Hide Aux -----

function at_hide_aux(parent, child)
{
  document.getElementById(parent).className = "parent";
  document.getElementById(child ).style.visibility = "hidden";
}

// ----- Show -----

function at_show_p()
{
  c = document.getElementById(this["at_child" ]);
  at_show_aux(this.id, c.id);
  clearTimeout(c["at_timeout"]);
}

function at_show_c()
{
  p = document.getElementById(this["at_parent"]);
  at_show_aux(p.id, this.id);
  clearTimeout(this["at_timeout"]);
}

// ----- Hide -----

function at_hide_p()
{
  c = document.getElementById(this["at_child" ]);
  c["at_timeout"] = setTimeout("at_hide_aux('"+this.id+"', '"+c.id+"')", 200);
}

function at_hide_c()
{
  p = document.getElementById(this["at_parent"]);
  this["at_timeout"] = setTimeout("at_hide_aux('"+p.id+"', '"+this.id+"')", 200);
}

// ----- Attach -----

function at_attach(parent, child, position)
{
  p = document.getElementById(parent);
  c = document.getElementById(child);

  p["at_child"]    = c.id;
  c["at_parent"]   = p.id;
  c["at_position"] = position;

  p.onmouseover = at_show_p;
  p.onmouseout  = at_hide_p;
  c.onmouseover = at_show_c;
  c.onmouseout  = at_hide_c;
}

// ----- DropDown Menu ---------------------------------------------------------

// ----- Build Aux -----

function dhtmlmenu_build_aux(parent, child, position) {
  var n = 0;
	if (!document.getElementById(parent)) { return; }
  document.getElementById(parent).className = "parent";
  document.write('<div class="vert_menu" id="'+parent+'_child">');
  var img_menu = '<img src="/images/menu_arrow.gif" alt=""/>';
	if (typeof child == 'object') {
	  for (var i in child) {
	    if (i == '-') {
	      document.getElementById(parent).href = child[i];
	      continue;
	    }

	    if (typeof child[i] == "object")
	    {
	      var current_link = child[i].parent_link ? child[i].parent_link == '#' ? 'javascript:void(0);' : child[i].parent_link : 'javascript:void(0);';
	      document.write('<a class="parent" id="'+parent+'_'+n+'" href="'+current_link+'">'+i+img_menu+'</a>');
	      dhtmlmenu_build_aux(parent+'_'+n, child[i], "x");
	    }
	    else {
	      if (i != '0' && i !== 'parent_link') {
	        document.write('<a id="'+parent+'_'+n+'" href="'+child[i]+'">'+i+'</a>');
	      }
	    }
	    n++;
	  }
	}
	else {
		if (typeof child == 'string') {
		  document.getElementById(parent).href = child;
		}
	}

  document.write('</div>');

  at_attach(parent, parent+"_child", position);
}

// ----- Build -----

function dhtmlmenu_build(menu)
{
	if (!document.getElementById) { return; }
  for (var i in menu) {
    dhtmlmenu_build_aux(i, menu[i], "y");
  }
}
//(c) 2006 Valerio Proietti (http://mad4milk.net). MIT-style license.
//moo.fx.js - depends on prototype.js OR prototype.lite.js
//version 2.0
/*
var fx = {};
var Fx = fx;

Fx.Base = function(){};
Fx.Base.prototype = {

  setOptions: function(options){
    this.options = Object.extend({
      onStart: function(){},
      onComplete: function(){},
      transition: Fx.Transitions.sineInOut,
      duration: 500,
      unit: 'px',
      wait: true,
      fps: 50
    }, options || {});
  },

  step: function(){
    var time = new Date().getTime();
    if (time < this.time + this.options.duration){
      this.cTime = time - this.time;
      this.setNow();
    } else {
      setTimeout(this.options.onComplete.bind(this, this.element), 10);
      this.clearTimer();
      this.now = this.to;
    }
    this.increase();
  },

  setNow: function(){
    this.now = this.compute(this.from, this.to);
  },

  compute: function(from, to){
    var change = to - from;
    return this.options.transition(this.cTime, from, change, this.options.duration);
  },

  clearTimer: function(){
    clearInterval(this.timer);
    this.timer = null;
    return this;
  },

  _start: function(from, to){
    if (!this.options.wait) { this.clearTimer(); }
    if (this.timer) { return; }
    setTimeout(this.options.onStart.bind(this, this.element), 10);
    this.from = from;
    this.to = to;
    this.time = new Date().getTime();
    this.timer = setInterval(this.step.bind(this), Math.round(1000/this.options.fps));
    return this;
  },

  custom: function(from, to) {
    return this._start(from, to);
  },

  set: function(to){
    this.now = to;
    this.increase();
    return this;
  },

  hide: function(){
    return this.set(0);
  },

  setStyle: function(e, p, v){
    if (p == 'opacity'){
      if (v == 0 && e.style.visibility != "hidden") { e.style.visibility = "hidden"; }
      else if (e.style.visibility != "visible") { e.style.visibility = "visible"; }
      if (window.ActiveXObject) { e.style.filter = "alpha(opacity=" + v*100 + ")"; }
      e.style.opacity = v;
    } else { e.style[p] = v+this.options.unit; }
  }

};

Fx.Style = Class.create();
Fx.Style.prototype = Object.extend(new Fx.Base(), {

  initialize: function(el, property, options){
    this.element = $(el);
    this.setOptions(options);
    this.property = property.camelize();
  },

  increase: function(){
    this.setStyle(this.element, this.property, this.now);
  }

});

Fx.Styles = Class.create();
Fx.Styles.prototype = Object.extend(new Fx.Base(), {

  initialize: function(el, options){
    this.element = $(el);
    this.setOptions(options);
    this.now = {};
  },

  setNow: function(){
    for (p in this.from) { this.now[p] = this.compute(this.from[p], this.to[p]); }
  },

  custom: function(obj){
    if (this.timer && this.options.wait) { return; }
    var from = {};
    var to = {};
    for (p in obj) {
      from[p] = obj[p][0];
      to[p] = obj[p][1];
    }
    return this._start(from, to);
  },

  increase: function(){
    for (var p in this.now) { this.setStyle(this.element, p, this.now[p]); }
  }

});

//Transitions (c) 2003 Robert Penner (http://www.robertpenner.com/easing/), BSD License.

Fx.Transitions = {
  linear: function(t, b, c, d) { return c*t/d + b; },
  sineInOut: function(t, b, c, d) { return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b; }
};
//by Valerio Proietti (http://mad4milk.net). MIT-style license.
//moo.fx.utils.js - depends on prototype.js OR prototype.lite.js + moo.fx.js
//version 2.0

Fx.Height = Class.create();
Fx.Height.prototype = Object.extend(new Fx.Base(), {

  initialize: function(el, options){
		if (typeof el != 'undefined') {
		    this.element = $(el);
		    this.setOptions(options);
		    this.element.style.overflow = 'hidden';
			this.iniHeight = this.element.scrollHeight;
		}
  },

  toggle: function(){
    if (this.element.offsetHeight > 0) { return this.custom(this.element.offsetHeight, 0); }
    else {
			var curHeight = this.element.scrollHeight ? this.element.scrollHeight : this.iniHeight;
			return this.custom(0, curHeight);
		}
  },

  show: function(){
    return this.set(this.element.scrollHeight);
  },

  increase: function(){
    this.setStyle(this.element, 'height', this.now);
  }

});

Fx.Width = Class.create();
Fx.Width.prototype = Object.extend(new Fx.Base(), {

  initialize: function(el, options){
    this.element = $(el);
    this.setOptions(options);
    this.element.style.overflow = 'hidden';
    this.iniWidth = this.element.offsetWidth;
  },

  toggle: function(){
    if (this.element.offsetWidth > 0) { return this.custom(this.element.offsetWidth, 0); }
    else { return this.custom(0, this.iniWidth); }
  },

  show: function(){
    return this.set(this.iniWidth);
  },

  increase: function(){
    this.setStyle(this.element, 'width', this.now);
  }

});

Fx.Opacity = Class.create();
Fx.Opacity.prototype = Object.extend(new Fx.Base(), {

  initialize: function(el, options){
    this.element = $(el);
    this.setOptions(options);
    this.now = 1;
  },

  toggle: function(){
    if (this.now > 0) { return this.custom(1, 0); }
    else { return this.custom(0, 1); }
  },

  show: function(){
    return this.set(1);
  },

  increase: function(){
    this.setStyle(this.element, 'opacity', this.now);
  }

});h = ' -->';
*/
