//<![CDATA[
/*
 Copyright (c) 2006 MexWebs Developer Team. All rights reserved.
 version 0.1.0
 Author: Caridy Patiño
*/
function MM_openBrWindow(theURL,winName,features) { //v2.0

  window.open(theURL,winName,features);

}
/* Funcion para ocultar un div */
function ocultadiv(id1) {
  var obj1 = findObj ( id1 );
  if (obj1)
    obj1.style.display = 'none';
}
/* Funcion para mostrar un div */
function mostrandodiv(id1) {
  var obj1 = findObj ( id1 );
  if (obj1)
    obj1.style.display = 'block';
}
/* Funcion para mostrar un bloque */
function mostrarbloque(mostrar,ocultar0,ocultar1) {
  var obj1 = findObj ( mostrar );
  var obj2 = findObj ( ocultar0 );
  var obj3 = findObj ( ocultar1 );
  if (obj1){obj1.style.display = 'block';}
  if (obj2){obj2.style.display = 'none';}
  if (obj3){obj3.style.display = 'none';}
}

/*funcion para buscar articulo por ID*/
function busca_articulo_por_ID(){
    var id = document.getElementById('_idArticuloBusqueda').value;
		if(id != "")
        window.location = "index.php?page=detalle&id="+id;
		else
		    alert("Por favor, introduzca un ID");
}

function casa_selection ( id, value ) {
  var id_obj = findObj ( id );
  if (id_obj)
	for (var i = 0; i < id_obj.length; i++)
	  if (id_obj.options[i].value == value)
		id_obj.options[i].selected = true;
  return true;
}
var popUpWin = 0;
function popUpWindow(URLStr, left, top, width, height, style)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin',
                          'toolbar=no,'+
                          'location=no,'+
                          'directories=no,'+
                          'status=no,'+
                          'menubar=no,'+
                          'scrollbar=yes,'+
                          'resizable=yes,'+
                          'copyhistory=yes,'+
                          'width='+width+','+
                          'height='+height+','+
                          'left='+left+','+
                          'top='+top+','+
                          'screenX='+left+','+
                          'screenY='+top+ '' +
                           style  );

}
var handleSuccess = function(o){
	if((o.responseText !== undefined) && (o.argument.c)){
	  // aqui utilizo el magicFade para intercambiar contenidos, pero además le mando la funcion que debe 
	  // ejecutarse inmediatamente despues de la conclusión de la animación, para garantizar que nada falle...
	  var onCompleteMagicFade = function() { verify_ajax_link ( o.argument.c ); reinitialization (); executeble ( o.argument.c ); }
	  magicFade ( o.argument.c, o.responseText, onCompleteMagicFade  );
	}
	YAHOO.tms.panel.wait.hide();
}
var handleFailure = function(o){
	if((o.responseText !== undefined) && (o.argument.c)){
		// o.argument.c.innerHTML = "<ul><li>Transaction id: " + o.tId + "</li>";
		// o.argument.c.innerHTML += "<li>HTTP status: " + o.status + "</li>";
		// o.argument.c.innerHTML += "<li>Status code message: " + o.statusText + "</li></ul>";
	}
	YAHOO.tms.panel.wait.hide();
}
var hSuccess = function(o){
	if((o.responseText !== undefined) && (o.argument.c)){
	  var onCompleteMagicFade = function() { reinitialization (); executeble ( o.argument.c ); }
	  magicFade ( o.argument.c, o.responseText, onCompleteMagicFade  );
	}

}

var hFailure = function(o){

	if((o.responseText !== undefined) && (o.argument.c)){

	  // o.argument.c.innerHTML = "";

	}

}

/**

* Este método muestrar un nuevo banner...

* @public

* @return boolean

*/

function display_banners() {

    var url_intro  = '/ajax.php?lang='+ TMS_CURRENT_LANG +'&webpart=webparts/ajax/intro.inc.html';

    var url_banner = '/ajax.php?lang='+ TMS_CURRENT_LANG +'&webpart=webparts/ajax/banner.inc.html';
		
    ajaxLoadContent ( 'ajax-intro',  url_intro,  hSuccess, hFailure);
		
    ajaxLoadContent ( 'ajax-banner', url_banner, hSuccess, hFailure);

	return true;

}



/**

* Este método representa un evento de navegación sobre un enlace usando ajax - Desplegar un video en popup...

* @public

* @param {object} e Referencia al evento

* @return void

*/

function navAjaxPlayVideo(e) {

  if (this && this.href) {

	var content = "<embed width='500' height='500' src='" + this.href + "' autostart='true'></embed>";	
	
	displayDialog( 'Play Video...', content, '600px', false );

    YAHOO.util.Event.stopEvent(e);

  }

}



/**

* Este método representa un evento de navegación sobre un enlace usando ajax...

* @public

* @param {object} e Referencia al evento

* @return void

*/

function navAjaxPlayAudio(e) {

  if (this && this.href) {
	
	var content = "<embed width='200' height='200' src='" + this.href + "' autostart='true'></embed>";

	displayDialog( 'Play Audio...', content, '400px', false );
		
	
  
	YAHOO.util.Event.stopEvent(e);
    
  }

}



/**

* Este método representa un evento de navegación sobre un enlace usando ajax...

* @public

* @param {object} e Referencia al evento

* @return void

*/

function navAjaxDisplayPhoto(e) {

  if (this && this.href) {

	var content = "<img src='"+this.href+"' border='0' />";

	displayDialog( 'Mostrando una Foto...', content, '400px', true );

    YAHOO.util.Event.stopEvent(e);

  }

}



/**

* Este método representa un evento de navegación sobre un enlace usando ajax...

* @public

* @param {object} e Referencia al evento

* @return void

*/

function navAjaxPagination(e) {

  if (this && this.href) {

	navHistory.push ( this.href );

	displayLoading ();

	ajaxLoadContent ( 'tms-pagination', url_completion ( this.href, 'tpl=tpls/ajax' ), handleSuccess, handleFailure);

    YAHOO.util.Event.stopEvent(e);

  }

}

/**

* Este metodo se encarga de revisar cada uno de los elementos que pueden causar navegación y le aplica

* el respectivo evento para garantizar que funcionen las llamadas usando ajax...

* @public

* @param {object} content    Referencia al elemento que se le va a aplicar el filtro de navegación...

* @return void

*/

function verify_ajax_link( content ) {

  if (!content) content = document;  // si no se pasa ningun parametro entonces se

  if (!content.getElementsByTagName) return;

  var items    = new Array();

  var relType   = null, relRef   = null; // definiendo el tipo de referencia y la referencia como tal a una funcion...

  var classType = null, classRef = null; // definiendo el tipo de clase y la referencia como tal a una funcion...

  var itemclass = null, itemrel  = null; 

  items.merge( content.getElementsByTagName("a") );

  items.merge( content.getElementsByTagName("area") );

  for (var i=0; i<items.length; i++) {

    var anch = items[i];

    if (anch.getAttribute("href") && isAjaxble(anch.getAttribute("href"))) {

	  relType   = null;

	  relRef    = null; 

	  classType = null;

	  classRef  = null;

	  itemrel   = new String(anch.getAttribute("rel"));

	  itemclass = new String(anch.className);

	  if ((itemrel != "") && (itemrel.indexOf('nav') == 0)) {

		try {

	      relType = eval("typeof "+itemrel);

		  relRef  = eval(anch.getAttribute("rel"));

		} catch (e) {}

	  }

	  if ((itemclass != "") && (itemclass.indexOf('nav') == 0)) {

		try {

	      classType = eval("typeof "+itemclass);

		  classRef  = eval(anch.className);

		} catch (e) {}

	  }

	  switch (itemrel) {

		case "external":

		  anch.target = "_blank";

		  break;

		case "internal":

		  anch.target = "_top";

		  break;

		default:

		  // si se especific aun valor para REL que es una funcion definida, entonces se aplica el evento correspondiente...

		  if (relType == "function")

            YAHOO.util.Event.addListener ( anch, 'click', relRef );

		  else {

			if (classType == "function")

              YAHOO.util.Event.addListener ( anch, 'click', classRef );

		  }

	  }

    }

	applyToolTip( anch );

  }

}

//]]>