//<![CDATA[
/*
 Copyright (c) 2006 MexWebs Developer Team. All rights reserved.
 version 0.1.0
 Author: Caridy Patiño

 JS-YUI
 ==============
 Assumed Document Object Model described in:
 "Document Object Model (DOM) Level 2 Specification Version 1.0"
 (http://www.w3.org/TR/1999/CR-DOM-Level-2-19991210)
 Latest version: (http://www.w3.org/TR/DOM-Level-2)

 Successfully tested on:
  - Miscrosoft Internet Explorer 6.02
  - Mozilla Firefox 1.5
  - Opera 8.5
 All in platform Win32, Operating System Windows XP SP2.

 Description:
 ============
 Implementación de las principales funciones de YAHOO USER INTERFACE usadas en nuestros sitios...
*/

YAHOO.namespace("tms.panel");
YAHOO.namespace("tms.simpledialog");
YAHOO.namespace("tms.helphint");YAHOO.tms.helphint = new Array();
YAHOO.namespace("tms.animations");YAHOO.tms.animations = new Array();
YAHOO.namespace("tms.dimensions");YAHOO.tms.dimensions = new Array();
YAHOO.namespace("tms.vars");YAHOO.tms.vars = new Array();

function downloadScripts ( s ) { // under production...
	// cut out all script tags, push them into scripts array
	var m = [], remoteScripts = Array(), localscripts = "", attr = false, self = this;
	while(m){
		m = s.match(/<script([^>]*)>([\s\S]*?)<\/script>/i);
		if(!m){ break; }
		if(m[1]){
		  attr = m[1].match(/src=(['"]?)([^"']*)\1/i);
		  if(attr)
			remoteScripts.push(attr[2]);
		}
		if(m[2]){
		  localscripts += m[2];
		}
	}

	try{
	  // initialize a new anonymous container for our script, dont make it part of this widgets scope chain
	  // instead send in a variable that points to this widget, usefull to connect events to onLoad, onUnLoad etc..
	  this.scriptScope = null;
	  this.scriptScope = new (new Function('_container_', localscripts+'; return this;'))(self);
	}catch(e){
  	  alert("Error running scripts from content:\n"+e);
	}
	return remoteScripts;
}

function executeble(content) {
  if (!content) return true;
  if (!content.getElementsByTagName) return;
  var items = new Array(), localscripts = '', self = this;
  items.merge( content.getElementsByTagName("script") );
  
  for (var i=0; i<items.length; i++)
    localscripts += items[i].innerHTML;
	
  if (localscripts != '') {
	  try{
		// initialize a new anonymous container for our script, dont make it part of this widgets scope chain
		// instead send in a variable that points to this widget, usefull to connect events to onLoad, onUnLoad etc..
		this.scriptScope = null;
		this.scriptScope = new (new Function('_container_', localscripts+'; return this;'))(self);
	  } catch(e) {
		// alert("Error running scripts from content:\n"+e);
		return false;
	  }
  }
  return true;	
}
/**
* Este método muestra el contenido de una url externa dentro de un div...
* @public
* @param {string} t    title, el título del dialogo...
* @param {string} b    body, el contenido del dialogo... ;-)
* @param {string} w    width, el ancho del dialogo
* @param {string} d    dragable, si es o no dragable
* @return boolean
*/
function displayDialog( t, b, w, d, r ) {
	t = asset ( t, '' );
	b = asset ( b, '' );
	w = asset ( w, '' ); /* 50em */
	d = assetbool ( d, false );
	r = assetbool ( r, true );
	var dialogClass = YAHOO.widget.SimpleDialog;
	var handleCancel = function() {
		this.hide();
	}
	var handleOK = function() {
		this.hide();
	}
	try {YAHOO.tms.simpledialog.dlg.hide();} catch (e) {}
	if (r) dialogClass = YAHOO.widget.ResizePanel;
	YAHOO.tms.simpledialog.dlg = new dialogClass("dlg", 
	 							  { width:w,  
	 							    fixedcenter: true, 
	 							    constraintoviewport: true, 
	 							    underlay:"shadow", 
	 							    close:true, 
	 							    visible:false, 
	 							    draggable:d,
									iframe: true
	 							    } 
	 							   );
	YAHOO.tms.simpledialog.dlg.setHeader( t );
	YAHOO.tms.simpledialog.dlg.setBody( b );
	YAHOO.tms.simpledialog.dlg.cfg.queueProperty("buttons", [ { text:"Close", handler:handleCancel } ]);

    var listeners = new YAHOO.util.KeyListener(document, { keys : 27 }, {fn:handleCancel ,scope:YAHOO.tms.simpledialog.dlg, correctScope:true} );
	YAHOO.tms.simpledialog.dlg.cfg.queueProperty("keylisteners", listeners);

	YAHOO.tms.simpledialog.dlg.render(document.body);
	YAHOO.tms.simpledialog.dlg.show();
	return true;
}
/**
* Este método muestra el contenido de una url externa dentro de un div...
* @public
* @param {string} content_id    ID que identifica al DIV donde se debe mandar a cargar el contenido resultado de la navegación de url
* @param {string} url           URI de navegación
* @return boolean
*/
function displayLoading( m ) {
	m = assetbool ( m, false );
	try {YAHOO.tms.panel.wait.hide();} catch (e) {}
	YAHOO.tms.panel.wait = new YAHOO.widget.Panel("wait",
							{ width:"240px",
							  fixedcenter:true,
							  underlay:"shadow",
							  close:true,
							  visible:true,
							  draggable:true,
							  modal: m,
							  effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration:0.2}
							  }
							 );
    var loading_msg = "Loading, please wait...";
	if (TMS_LOADING_MESSAGE && (TMS_LOADING_MESSAGE != ''))
	  loading_msg = TMS_LOADING_MESSAGE;
	YAHOO.tms.panel.wait.setHeader( loading_msg );  // {caridy} este mensaje tiene que ser multilenguaje
	YAHOO.tms.panel.wait.setBody("<img src='" + TMS_THEMEPATH + "images/loading.gif' />");
	YAHOO.tms.panel.wait.render(document.body);
	return true;
}
/**
* Este método muestra el contenido de una url externa dentro de un div...
* @public
* @param {string} content_id    ID que identifica al DIV donde se debe mandar a cargar el contenido resultado de la navegación de url
* @param {string} url           URI de navegación
* @return boolean
*/
function ajaxLoadContent( content, url, aHandleSuccess, aHandleFailure ) {
  if ((typeof content == 'object') || (content = document.getElementById( content ))) {
	  var callback =
	  {
		success:aHandleSuccess,
		failure:aHandleFailure,
		argument: { c:content }
	  };
	
	  var request = YAHOO.util.Connect.asyncRequest('GET', url, callback);
  }
  return false;
}
/**
* Este método muestra el contenido de una url externa dentro de un div...
* @public
* @param {Object} el    ID que identifica al Elemento donde se debe mandar a cargar el contenido
* @param {string} c     Content que debe ser colocado como hijo...
* @return boolean
*/
function safeInnerHTML( el, c ) {
  if ((typeof el == 'object') || (el = document.getElementById( el ))) {
	while (el.childNodes.length > 0)
	  el.removeChild(el.childNodes[0]);
	try { el.innerHTML = c; } catch (e) {}	
  }
}
/**
* Este método asegura que las variables esten definidas
* @public
* @param {object} variable    
* @param {object} valor por defecto    
* @return integer
*/
function asset( v, d ) {
  if (v == 'undefined')
    var v = d;
  else if (((v == null) || (v == '')) && (d)) 
    v = d;
  return v;
}
function isEmpty( v ) {
  if ((v == 'undefined') || (v == null) || (v == ''))
    return true;
  return false;
}
function assetbool( v, d ) {
  if (typeof v == 'boolean')
    return v;
  else if ((typeof v == 'string') && ((v == 'true') || (v == 'false')))
    return eval( v );
  else if (typeof d == 'boolean')
    return d;
  else
    return null;
}
function assetObj( o, d ) {
  if (!isEmpty( o ) && ((typeof o == 'object') || (o = document.getElementById( o ))))
	return o;
  else if (!isEmpty( d ) && ((typeof d == 'object') || (d = document.getElementById( d ))))
	return d;
  return false;
}
function assetOffset ( o, a ) {
  if (o = assetObj(o)) {
    var dd = new YAHOO.util.Anim(o);  
    var offset = dd.getAttribute (a); // este de aqui si determina el atributo (width, height) de verdad, aunque sea auto...
    return offset;
  }
  return null;
}
/**
* Este método elimina el px de las dimensiones...
* @public
* @param {string} dimension    ej. (102px) y esta funcion devuelve el numero 102
* @return integer
*/
function px2int( d ) {
  d = new String ( d );
  if (d.indexOf ( 'px' ) > -1) d = d.replace ( 'px', '' );
  return d;
}
/**
* Este método hace un parsing de una url, completa sus parametros sobrescribiendo parametros que se pasan como m a la funcion
* @public
* @param {string} url URI de navegación
* @param {string} m   MoreParams representa una cadena de parametros con el siguiente formato ( param1=value1&param2=value2 )
* @return string
*/
function url_completion ( url, m ) {
  var anch = '';
  var p    = '';
  var params = '';
  var moreparams = new String(m);
  var query = new Array();
  // separando la url en sus 3 partes (url, parametros, anchor)
  if (url.indexOf('#') > -1) {
	 anch = url.substring ( url.indexOf('#'), url.length );
	 url  = url.substring ( 0, url.indexOf('#') );
  }
  if (url.indexOf('?') > -1) {
	 params = url.substring ( url.indexOf('?')+1, url.length );
	 url   = url.substring ( 0, url.indexOf('?') );
  }
  // sustituyendo el separados de parametros para que no de problema con ajax
  while (params.indexOf ( '&amp;' ) > -1)
    params = params.replace ( '&amp;', '&' );
  while (moreparams.indexOf ( '&amp;' ) > -1)
    moreparams = query.replace ( '&amp;', '&' );

  // este bloque verifica que no se repitan los parametro en la url de resultado
  // tener en cuenta que los moraparams tienen prioridad sobre los parametros que ya venian en la url
  query = query.concat ( params.split ('&'), moreparams.split ('&') );
  var tmp = new String('');
  var par = new Array ();
  var s   = new String();
  query = query.reverse();
  for (var i=0; i<query.length; i++) {
	s = new String (query[i]);
	par = s.split ('='); // array( param, value )
	if (tmp.indexOf ('{'+par[0]+'}') > -1)
	  query[i] = null;
	else
      tmp += '{'+par[0]+'}';
  }
  // una vez eliminados los parametros que estaban repetidos se procede a construir la url.
  for (var i=0; i<query.length; i++) {
    if (query[i] != null)
	  if (p == '') p += '?'+query[i]; else p += '&'+query[i]; 
  }
  return url + p + anch;
}

function applyHint ( obj, tt, alt, op ) {
    if (!document.getElementById( obj ))
      return false;
	YAHOO.tms.vars[obj+'-hint'] = YAHOO.tms.helphint.length;
	YAHOO.tms.helphint[YAHOO.tms.helphint.length] = new YAHOO.widget.Helphint(obj+'-hint', { 
							  preventoverlap:false,
							  constraintoviewport:true,
							  zIndex: 10,
							  context:obj, 
							  text: String(tt) ,
							  alt: String(alt) 
							  } );
	return true;
}
function clearHint () {
  for (var i=0; i<YAHOO.tms.helphint.length; i++)
   YAHOO.tms.helphint[i].doHide();
}
function displayHint () {
  for (var i=0; i<YAHOO.tms.helphint.length; i++)
   YAHOO.tms.helphint[i].doShow();
}
function relocateHint () {
  for (var i=0; i<YAHOO.tms.helphint.length; i++)
   YAHOO.tms.helphint[i].relocate();
}
/**
* Este metodo se encarga de asignarle al obj correspondiente los eventos de tooltip, asi como la conformación de la información que debe mostrar dicha caja
* @public
* @param {object} obj Referencia al objeto que vamos a aplicarle el evento de tooltip
* @param {string} tt  DOM ID - estilo que se le va a aplicar a la caja del tooltip
* @param {real}   op  Opacity - Valor de la opacidad para la caja de estilo del tooltip
* @return void
*/
function applyToolTips( content, tt, op ) {
	if (!(content = assetObj (content, document)) || (!content.getElementsByTagName)) return false;
	var ttid    = ( tt ? tt.toString() : "tt" );      // quoting value for DOM ID - the default id is #tt
	var opacity = ( op ? op.toString() : "0.9" );     // default value for DOM opacity attribute (semi-transparent)
	var host = location.hostname.toString();
	var txt  = new String ();
	var pattern = new RegExp("(http://?)"+host,"gi");
	var fullPath = new String ();
	var path = new String ();
	
	var items    = new Array();
    items.merge( content.getElementsByTagName("a") );
    items.merge( content.getElementsByTagName("area") );
	$c(items).each(function(child){
		if ((child.id != '') && (child.id.indexOf('yui') == 0)) {
		  fullPath = child.href.toString();
	      path = fullPath.replace(pattern,'');
		  applyToolTipNow (child, ttid, opacity, path);
		}
	});  
}
/**
* Este metodo se encarga de asignarle al obj correspondiente los eventos de tooltip, asi como la conformación de la información que debe mostrar dicha caja
* @public
* @param {object} obj Referencia al objeto que vamos a aplicarle el evento de tooltip
* @param {string} tt  DOM ID - estilo que se le va a aplicar a la caja del tooltip
* @param {real}   op  Opacity - Valor de la opacidad para la caja de estilo del tooltip
* @return void
*/
function applyToolTipNow( obj, ttid, opacity, path ) {
	var host = location.hostname.toString();
	var txt  = new String ();
	addy = (path.length > 30 ? path.toString().substring(0,40)+"..." : path);
	if ((addy.indexOf('/#') == 0) || (addy.indexOf('#') == 0) || (addy.indexOf('javascript:') == 0) || (addy == '/')) addy = ''; // remove the anchor links if it´s empty or null
	var access = ( obj.accessKey ? " ["+obj.accessKey+"]" : "" );
	// verifing if we really have text to display in the tooltip
	var tip = ( obj.getAttribute('title')? obj.getAttribute('title').toString() + '<br />' : "" );
	obj.removeAttribute('title');
	if (tip+access+addy != '') {
	    var ttb = new YAHOO.widget.Tooltip(ttid, { 
							  preventoverlap:true,
							  constraintoviewport:true,
							  zIndex: 10,
							  context:obj, 
							  hidedelay: 0,
							  autodismissdelay: 10000,
							  text: String(tip+'<em>'+access+'<em>'+addy) 
							  } );
		// Eliminando todos los ATL de las imagenes que estan dentro del Anchor
	    var childs = new Array();
		if (assetObj( obj ) && (childs = obj.getElementsByTagName("img"))) 
		  for (var i=0; i<childs.length; i++)
		    childs[i].alt = '';
	}
    // Defino el estilo para la caja de los tooltips, para que tenga un poco de transparencia.
    YAHOO.util.Dom.setStyle(ttid, 'opacity', opacity);
	return true;
}





/**
* Este metodo se encarga de asignarle al obj correspondiente los eventos de tooltip, asi como la conformación de la información que debe mostrar dicha caja
* @public
* @param {object} obj Referencia al objeto que vamos a aplicarle el evento de tooltip
* @param {string} tt  DOM ID - estilo que se le va a aplicar a la caja del tooltip
* @param {real}   op  Opacity - Valor de la opacidad para la caja de estilo del tooltip
* @return void
*/
function applyToolTip111( obj, tt, op ) {
   // if (!document.getElementById( obj ))
     // return false;
	// Adicionando el evento para el tooltip sobre cada enlace...
	var ttid    = ( tt ? tt.toString() : "tt" );      // quoting value for DOM ID - the default id is #tt
	var opacity = ( op ? op.toString() : "0.9" );     // default value for DOM opacity attribute (semi-transparent)
	var host = location.hostname.toString();
	var txt  = new String ();
	var pattern = new RegExp("(http://?)"+host,"gi");
	var fullPath = obj.href.toString();
	var path = fullPath.replace(pattern,'');
	addy = (path.length > 30 ? path.toString().substring(0,30)+"..." : path);
	if ((addy.indexOf('/#') == 0) || (addy.indexOf('#') == 0) || (addy.indexOf('javascript:') == 0) || (addy == '/')) addy = ''; // remove the anchor links if it´s empty or null
	var access = ( obj.accessKey ? " ["+obj.accessKey+"]" : "" );
	// verifing if we really have text to display in the tooltip
	var tip = ( obj.getAttribute('title')? obj.getAttribute('title').toString() + '<br />' : "" );
	obj.removeAttribute('title');
	if (tip+access+addy != '') {
	  if ((obj.id != '') && (obj.id.indexOf('yui') == 0)) {
		// si el id de el objecto comienza con yui entonces asumo que es un componente interno, y que no se le aplica el tooltip
	  }
	  else {
	    var ttb = new YAHOO.widget.Tooltip(ttid, { 
							  preventoverlap:true,
							  constraintoviewport:true,
							  zIndex: 10,
							  context:obj, 
							  hidedelay: 0,
							  autodismissdelay: 10000,
							  text: String(tip+'<em>'+access+'<em>'+addy) 
							  } );
		// Eliminando todos los ATL de las imagenes que estan dentro del Anchor
	    var childs = new Array();
		if (assetObj( obj ) && (childs = obj.getElementsByTagName("img"))) 
		  for (var i=0; i<childs.length; i++)
		    childs[i].alt = '';
	  }
	}
    // Defino el estilo para la caja de los tooltips, para que tenga un poco de transparencia.
    YAHOO.util.Dom.setStyle(ttid, 'opacity', opacity);
	
	// {caridy} hay un problema cuando ese enlace contiene una imagen con ALT o title, debería eliminarse tambien...
	return true;
}
/**
* Este metodo hace un fadeOut, luego sustituye el contendio actual del elemento por el nuevo contenido y hace un fadeIn
* @public
* @param {object}   el    			Referencia al objeto que vamos a aplicarle el pase magico
* @param {string}   text  			Nuevo contenido para el innerHTML del objeto
* @param {function} onCompleteFade	Function que se ejecutará al finalizar la animación...
* @return void
*/
function magicFade ( el, text, onCompleteFade ) {
  var myAnim = null;
  var magicFadeSwitchContent = function() {
	safeInnerHTML ( el, text );
	if (!YAHOO.util.Event.isIE) {
	  myAnim = new YAHOO.util.Anim(el, { opacity: { to: 1 } }, 1, YAHOO.util.Easing.easeOut);
	  if(typeof onCompleteFade == "function")
	    myAnim.onComplete.subscribe(onCompleteFade);
	  myAnim.animate();
	}
	else {
	  onCompleteFade.call();
	} 
  }
  try {
    if (!YAHOO.util.Event.isIE) {
      myAnim = new YAHOO.util.Anim(el, { opacity: { to: 0 } }, 1, YAHOO.util.Easing.easeIn);
      myAnim.onComplete.subscribe(magicFadeSwitchContent);
      myAnim.animate();
    }
    else {
      magicFadeSwitchContent.call();
    }
  }
  catch (e) {
	try { 
  	  safeInnerHTML ( el, text );
	  magicFadeSwitchContent.call(); 
	} catch (e) {}
  }
}
function slicing( el, h, onCompleteSlice ) {
  if ((typeof el != 'object') && !(el = document.getElementById( el ))) return false;
  YAHOO.util.Dom.setStyle(el, 'overflow', 'hidden');
  var id = YAHOO.util.Event.generateId (el) + '-slicing'; // stored height id

  if ((typeof YAHOO.tms.animations[id] == 'object') && (YAHOO.tms.animations[id].isAnimated())) { YAHOO.tms.animations[id].stop(); }
  YAHOO.tms.animations[id] = new YAHOO.util.Anim(el, { height: { to: storage( el, h, 'height') } }, 1.5, YAHOO.util.Easing.easeOutStrong);
  if(typeof onCompleteSlice == "function")
    YAHOO.tms.animations[id].onComplete.subscribe(onCompleteSlice);
  YAHOO.tms.animations[id].animate();
}
function expanding( el, w, onCompleteExpand ) {
  if ((typeof el != 'object') && !(el = document.getElementById( el ))) return false;
  YAHOO.util.Dom.setStyle(el, 'overflow', 'hidden');
  var id = YAHOO.util.Event.generateId (el) + '-expanding'; // stored height id
  
  if ((typeof YAHOO.tms.animations[id] == 'object') && (YAHOO.tms.animations[id].isAnimated())) { YAHOO.tms.animations[id].stop(); }
  YAHOO.tms.animations[id] = new YAHOO.util.Anim(el, { width: { to: storage( el, w, 'width') } }, 1.5, YAHOO.util.Easing.easeOutStrong);
  if(typeof onCompleteExpand == "function")
    YAHOO.tms.animations[id].onComplete.subscribe(onCompleteExpand);
  YAHOO.tms.animations[id].animate();
}
function storage( el, h, a) { // el, dimesion, attribute
  if ((typeof el != 'object') && !(el = document.getElementById( el ))) return false;
  var id = YAHOO.util.Event.generateId (el); // stored value id
  var hh = assetOffset(el, a); // current value
  var uaid = id + '-' + a;
  var usid = uaid + '-storage';
  var firsttime = false;
  if (isEmpty(YAHOO.tms.dimensions[uaid]))
	YAHOO.tms.dimensions[uaid] = hh;
  if (isEmpty(YAHOO.tms.dimensions[usid]) && (YAHOO.tms.dimensions[usid] != 0)) {
	YAHOO.tms.dimensions[usid] = hh; firsttime = true;
  }
  if (!isEmpty(h) || (h == 0))
    YAHOO.tms.dimensions[usid] = h;
  else if ((firsttime == false) && (Math.round(px2int(YAHOO.tms.dimensions[usid])) != Math.round(px2int(YAHOO.tms.dimensions[uaid]))))
    YAHOO.tms.dimensions[usid] = YAHOO.tms.dimensions[uaid];
  else
    YAHOO.tms.dimensions[usid] = 0;
  return YAHOO.tms.dimensions[usid];
}

function resetAccordion ( m, id )  {
  if ((typeof m == 'object') || (m = document.getElementById( m ))) {
	  if (isEmpty(id)) id = '';
	  // bloque para ocultar todos los elementos...
	  for (var i = 0; i < m.childNodes.length; i++) {
	    var o = false; var c = false;
        if (m.childNodes[i].tagName == "LI") {
          for (var j = 0; j < m.childNodes[i].childNodes.length; j++)
			  switch (m.childNodes[i].childNodes[j].tagName) {
				case "A":
				  if (YAHOO.util.Event.generateId (m.childNodes[i].childNodes[j]) == id) {
					  if (YAHOO.util.Dom.hasClass(m.childNodes[i].childNodes[j], 'open')) {
					    YAHOO.util.Dom.removeClass(m.childNodes[i].childNodes[j], 'open');
					    YAHOO.util.Dom.addClass(m.childNodes[i].childNodes[j], 'close');
						c = true;
					  } else if (YAHOO.util.Dom.hasClass(m.childNodes[i].childNodes[j], 'close')) {
					    YAHOO.util.Dom.removeClass(m.childNodes[i].childNodes[j], 'close');
					    YAHOO.util.Dom.addClass(m.childNodes[i].childNodes[j], 'open');
						o = true;
					  } else {
					    YAHOO.util.Dom.removeClass(m.childNodes[i].childNodes[j], 'close');
					    YAHOO.util.Dom.addClass(m.childNodes[i].childNodes[j], 'open');
					  }
				  }
				  else {
					YAHOO.util.Dom.removeClass(m.childNodes[i].childNodes[j], 'open');
				    YAHOO.util.Dom.addClass(m.childNodes[i].childNodes[j], 'close');
					c = true;
				  }
				  break;
				case "UL":
				  if (c)
					slice_panel( m.childNodes[i].childNodes[j], 0 );
				  else if (o)
					slice_panel( m.childNodes[i].childNodes[j] );
				  break;
				default:
			  }		  
		}
      }
  }
}
function accordion ( el ) {
	if ((typeof el == 'object') || (el = document.getElementById( el ))) {
	  if (isEmpty(el.parentNode) || isEmpty(el.parentNode.parentNode)) return false;
	  var m = el.parentNode.parentNode;
	  resetAccordion  ( m, YAHOO.util.Event.generateId (el) );
	}
}
/**
* Este metodo se encarga de asignarle un menu contextual sobre un enlace o elemento cualquiera 
* @public
* @param {string} obj_id   DOM ID - Referencia o ID del elemento al que se le va a enlazar el menu contextual
* @param {string} menu_id  DOM ID - Referencia o ID del elemento que representa en menu
* @return void
*/
function init_contextual_menu ( el, menu_id, single ) {
  if ((typeof el == 'object') || (el = document.getElementById( el ))) 
	YAHOO.widget.MyContextMenu ( el,	{ 
									  context:el,
									  menu:menu_id,
									  opacity:0.9
									}
							 );
}
// Render de un menu a partir de la estructura en xhtml
function initMenuBar( el, single, op ) {
  if ((typeof el == 'object') || (el = document.getElementById( el ))) 
	YAHOO.widget.MyMenuBar( el, { opacity:op } );
}

function initYUI () {
  YAHOO.util.Event.addListener( document, "mousedown", onDocumentMouseDown );
}

// "mousedown" handler for the document
YAHOO.tms.panel.OverlayManager = new YAHOO.widget.OverlayManager();
function onDocumentMouseDown(p_oEvent) {
	YAHOO.tms.panel.OverlayManager.hideAll();
}

/**
* Este metodo se encarga de asignarle una nueva clase a un elemento
* @public
* @param {string} el  DOM ID    - Referencia o ID del elemento al que se le va a enlazar el menu contextual
* @param {string} c1  ClassName
* @param {string} c2  ClassName
* @return void
*/
function swapClass( el, c1, c2 ) { // caridy: v1.0
  if ((typeof el == 'object') || (el = document.getElementById( el ))) {
    var id = YAHOO.util.Event.generateId (el);
	if (isEmpty(c2)) {
	  if (isEmpty(YAHOO.tms.vars[id+'-className']))
	    YAHOO.tms.vars[id+'-className'] = el.className;
	  c2 = YAHOO.tms.vars[id+'-className'];	
	}
	if ((c1 == c2) || isEmpty(c2)) c2 = 'none'; // eliminando el estilo si ya estaba puesto...
	if (YAHOO.util.Dom.hasClass(el, c1)) {
		YAHOO.util.Dom.removeClass(el, c1);
		YAHOO.util.Dom.addClass(el, c2);
	} else if (YAHOO.util.Dom.hasClass(el, c2)){
		YAHOO.util.Dom.removeClass(el, c2);
		YAHOO.util.Dom.addClass(el, c1);
	} else {
		YAHOO.util.Dom.addClass(el, c1);
	}	
  }
}


// Dustin Diaz Functions...   pending to be check it...
/* grab Elements from the DOM by className */
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

/* toggle an element's display */
function toggle(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}

/* insert an element after a particular node */
function insertAfter(parent, node, referenceNode) {
	parent.insertBefore(node, referenceNode.nextSibling);
}

/* Array prototype, matches value in array: returns bool */
Array.prototype.inArray = function (value) {
	var i;
	for (i=0; i < this.length; i++)
 	  if (this[i] === value)
		return true;
	return false;
};

/* Array prototype, marge a new array to the current array: returns bool */
Array.prototype.merge = function ( items ) {
	var i;
	for (i=0; i < items.length; i++)
      this.push(items[i]);
};

/* get, set, and delete cookies */
function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+"="+escape( value ) +
		( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) +
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}
	
function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

//]]>
