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

function escribe_text(obj1, obj2){

  var radiobutton = findObj(obj1);
	var inputtext = findObj(obj2);
	
	if(radiobutton){
	  inputtext.value = radiobutton.value; 
	}
	
}

function limitarSeleccion(casilla,form){
    a0 = casilla.form.casilla1[0].checked;
    a1 = casilla.form.casilla1[1].checked;
    a2 = casilla.form.casilla1[2].checked;
    a3 = casilla.form.casilla1[3].checked;
    a4 = casilla.form.casilla1[4].checked;
    a5 = casilla.form.casilla1[5].checked;
    a6 = casilla.form.casilla1[6].checked;
    a7 = casilla.form.casilla1[7].checked;
    a8 = casilla.form.casilla1[8].checked;
    a9 = casilla.form.casilla1[9].checked;
    a10 = casilla.form.casilla1[10].checked;
    a11 = casilla.form.casilla1[11].checked;
    a12 = casilla.form.casilla1[12].checked;
    a13 = casilla.form.casilla1[13].checked;
    a14 = casilla.form.casilla1[14].checked;
    a15 = casilla.form.casilla1[15].checked;
    a16 = casilla.form.casilla1[16].checked;
    a17 = casilla.form.casilla1[17].checked;
    a18 = casilla.form.casilla1[18].checked;
    a19 = casilla.form.casilla1[19].checked;
    a20 = casilla.form.casilla1[20].checked;
    a21 = casilla.form.casilla1[21].checked;
    a22 = casilla.form.casilla1[22].checked;
    a23 = casilla.form.casilla1[23].checked;
    a24 = casilla.form.casilla1[24].checked;
    a25 = casilla.form.casilla1[25].checked;
    a26 = casilla.form.casilla1[26].checked;



contador = (a0 ? 1 : 0) 
				 + (a1 ? 1 : 0) 
				 + (a2 ? 1 : 0) 
				 + (a3 ? 1 : 0) 
				 + (a4 ? 1 : 0) 
				 + (a5 ? 1 : 0) 
				 + (a6 ? 1 : 0) 
				 + (a7 ? 1 : 0) 
				 + (a8 ? 1 : 0) 
				 + (a9 ? 1 : 0) 
				 + (a10 ? 1 : 0) 
				 + (a11 ? 1 : 0) 
				 + (a12 ? 1 : 0) 
				 + (a13 ? 1 : 0) 
				 + (a14 ? 1 : 0) 
				 + (a15 ? 1 : 0) 
				 + (a16 ? 1 : 0) 
				 + (a17 ? 1 : 0) 
				 + (a18 ? 1 : 0) 
				 + (a19 ? 1 : 0) 
				 + (a20 ? 1 : 0) 
				 + (a21 ? 1 : 0) 
				 + (a22 ? 1 : 0) 
				 + (a23 ? 1 : 0) 
				 + (a24 ? 1 : 0) 
				 + (a25 ? 1 : 0) 
				 + (a26 ? 1 : 0) 
				 + (a27 ? 1 : 0) 
				 + (a28 ? 1 : 0) 
				 + (a29 ? 1 : 0);

    if (contador > 6)

    {
    alert("Solo puedes seleccionar 6 opciones");
    casilla.checked = false;
    }
}



function validacion(obj) {
  var limite=6;
  var num=0;
  if (obj.checked) {
    for (i=0; ele=obj.form.elements[i]; i++)
      if (ele.checked) num++;
  if (num>limite)
    obj.checked=false;
//		alert('solo puedes seleccionar 6');
  }
}

function ocultadiv(id){
  var obj = findObj(id);
	
	if(id){
	  obj.style.display='none';
	}
}

function siguiente(id, id2){
  var obj = findObj(id);
	var obj2 = findObj(id2);
	
	if(obj){
	  obj.style.display='none';
	}
	
	if(obj2){
	  obj2.style.display='block';
	}
}


function total(){
   var string = "";
	 var boxes = document.getElementById("generoscine").getElementsByTagName("input");
   for(var i = 0; i < boxes.length; i++){
	   if(boxes[i].checked){
	     string += boxes[i].value + ", ";
	   }		 
		 document.getElementById("totalcine").value = string; // siendo input la referencia al campo de texto;		 
	 }     
}

function soloNumeros(evt) {  
     //Validar la existencia del objeto event  
     evt = (evt) ? evt : event;  
       
     //Extraer el codigo del caracter de uno de los diferentes grupos de codigos  
     var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));  
       
     //Predefinir como valido  
     var respuesta = true;  
       
     //Validar si el codigo corresponde a los NO aceptables  48 > charcode > 57 es hasta el 9
     if (charCode > 31 && (charCode < 48 || charCode > 59)){  
         //Asignar FALSE a la respuesta si es de los NO aceptables  
         respuesta = false;  
     }  
       
     //Regresar la respuesta  
     return respuesta;  
 }
 
function soloNumeros4(evt) {  
     //Validar la existencia del objeto event  
     evt = (evt) ? evt : event;  
       
     //Extraer el codigo del caracter de uno de los diferentes grupos de codigos  
     var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));  
       
     //Predefinir como valido  
     var respuesta = true;  
       
     //Validar si el codigo corresponde a los NO aceptables  48 > charcode > 57 es hasta el 9
     if (charCode > 31 && (charCode < 49 || charCode > 52)){  
         //Asignar FALSE a la respuesta si es de los NO aceptables  
         respuesta = false;  
     }  
       
     //Regresar la respuesta  
     return respuesta;  
 }  

function show_hidden(id){
  var obj = findObj(id);
	
	if(obj){
	   var estado = obj.style.display;
	   if(estado=='block'){
	      obj.style.display='none';
	   }else{
	      obj.style.display='block';
	   }
	} 
	 
}


function showMe (it, box) {
   var vis = (box.checked) ? "block" : "none";
   document.getElementById(it).style.display = vis;
}


 
function mostrar_idiomas( id) {
  var obj = findObj ( id );
  if (obj) obj.style.display='block';	
  return true;
}

function mostrar_ocultar( id) {
  var obj = findObj ( id );
  if (obj.style.display='none'){
	  obj.style.display='block';
	} 
	
	else if(obj.style.display='block'){
	  obj.style.display='none';
	} 	
  return true;
}

function mostrar_enviar( id) {
  var obj = findObj ( id );
  if(obj){
	  obj.style.display='block';
	} 	
  return true;
}

function ocultar_enviar( id) {
  var obj = findObj ( id );
  if(obj){
	  obj.style.display='none';
	} 	
  return true;
}

function ocultar_idiomas( id, id2) {
  var obj = findObj ( id );
	var obj2 = findObj ( id2 );
	
  if (obj){
	  obj.style.display='none';
	}
	if (obj2){
	  obj2.value='No seleccionado';
	} 	
  return true;
}

function mostrar_cp( id, id2) {
  var obj = findObj ( id );
	var obj2 = findObj ( id2 );
	
  if (obj) obj.style.display='block';
	if (obj2){
	  obj2.disabled='true';
		obj2.value='';
	} 
	 
  return true;
}

function mostrar_cp2( id, id2) {
  var obj1 = findObj ( id );
	var obj2 = findObj ( id2 );
	
  if (obj1) obj1.style.disabled='false';
	if (obj2){
	  obj2.disabled='true';
		obj2.value='';
	}
	
	 
  return true;
}



function maximoCheckboxarCheckbox(nombre, maximoCheckbox){

    for (var i=0; i<nombre.length; i++){
        nombre[i].onclick=function(){
        var num_chequeados=0;
        for (var i=0; i<nombre.length; i++)
            num_chequeados+=(nombre[i].checked)? 1 : 0
        if (num_chequeados>maximoCheckbox){
            alert("El numero máximo de elementos que pueden ser seleccionados es de "+maximoCheckbox+"");
            this.checked=false;
            }
        }
    }
}

function escribe(id,id2){
  var obj = findObj(id);
	var obj2 = findObj(id2);
	var palabra = '';
	
	if(obj){
	  palabra = obj.value;
	  obj2.value=palabra;
	}
	
}







function mostrar_subir( id, id2) {
  var obj = findObj ( id );
	var obj2 = findObj ( id2 );
	
  if (obj){
	  obj.style.display='block';
	}
	if (obj2){
	  obj2.disabled='true';
	} 	 	 
  return true;
}

function ocultar( id, id2, id3) {
  var obj = findObj ( id );
	var obj2 = findObj ( id2 );
	var obj3 = findObj ( id3 );
	
  if (obj){
	  obj.style.display='none';
	}
	if (obj2){
	  obj2.value='';
	}
	if (obj3){
	  obj3.disabled='';
	} 	
	
  return true;
}



function ocultar_hijos( id, id2, id3, id4, id5) {
  var obj = findObj ( id );
	var obj2 = findObj ( id2 );
	var obj3 = findObj ( id3 );
	var obj4 = findObj ( id4 );
	var obj5 = findObj ( id5 );
	
  if (obj){
	  obj.style.display='none';
	}
	if (obj2){
	  obj2.value='0';
	}
	if (obj3){
	  obj3.value='0';
	} 	
	if (obj4){
	  obj4.value='0';
	}
	if (obj5){
	  obj5.value='0';
	}
  return true;
}




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';
		
    var url_default = '/ajax.php?lang='+ TMS_CURRENT_LANG +'&webpart=webparts/ajax/default.inc.html';
		
    var url_left = '/ajax.php?lang='+ TMS_CURRENT_LANG +'&webpart=webparts/ajax/left.inc.html';		

    ajaxLoadContent ( 'ajax-intro',  url_intro,  hSuccess, hFailure);
		
    ajaxLoadContent ( 'ajax-banner', url_banner, hSuccess, hFailure);

		ajaxLoadContent ( 'ajax-default',  url_default,  hSuccess, hFailure);

		ajaxLoadContent ( 'ajax-left',  url_left,  hSuccess, hFailure);

	return true;

}


// menus dinamicos...

function init_states_list( obj_id ) {

   var obj = findObj ( obj_id );

   if (obj && obj.options) {

     reset_list ( obj ); // eliminando todos los elementos...

     var items = estados['states'];

	 insert_into_list (obj, '', '');

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

	   insert_into_list (obj, items[n].s, items[n].s);

	 return true;

   } 

   else

     return false;   

}

function init_cities_list( obj_id, state_id ) {

   var obj = findObj ( obj_id );

   var sta = findObj ( state_id );

   var indx = prepare_indx ( sta.value );

   if (sta && sta.options && sta.value && obj && obj.options && (ciudades[indx])) {

     reset_list ( obj ); // eliminando todos los elementos...

     var items = ciudades[indx];

	 insert_into_list (obj, '', '');

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

	   insert_into_list (obj, items[n].c, items[n].c);

	 return true;

   } 

   else

     return false;   

}

function prepare_indx ( i ) {

   var indx = new String ( i );

   while (indx.indexOf ( '/' ) > -1)

     indx = indx.replace ( '/', ' ' );

   while (indx.indexOf ( ' ' ) > -1)

     indx = indx.replace ( ' ', '_' );

   return indx;

}
/**

* 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 );

  }

}

//]]>
