//Para la portada
function moverPortada(cuanto){
	
	var derecha = $('contenedor_banners').offsetLeft;
	anchoTotal = Math.abs($$('div.banner').length*cuanto);
	anchoDisponible  = anchoTotal - 1500;
	if((derecha > -1) && (cuanto>0)){
		$('boton_portada_ant').style.height="0px";
	}else if((cuanto<0)&&(anchoDisponible<-derecha)){
		$('boton_portada_sig').style.height="0px";
	}else{
		//si y solo si estamos en los límites
		new Effect.Move ('contenedor_banners',
			{	x: cuanto,
				y: 0, 
				mode: 'relative',
				afterFinish: activarBotosPortada,
      			beforeStart: desactivarBotosPortada 
      			});
		$('boton_portada_sig').style.height = "63px";
		$('boton_portada_ant').style.height = "63px";
	}
}

function activarBotosPortada(obj){
	botonesArray = $$('#botones_banner a');
	botonesArray.each(function(item) {
	  	enableLink(item);
	});
}
function desactivarBotosPortada(obj){
	botonesArray = $$('#botones_banner a');
	botonesArray.each(function(item) {
	  	disableLink(item);
	});
}


//Para imagenes
function moverImagenes(cuanto){
	var derecha = $('imagenes_contenidos').offsetLeft;
	anchoTotal = Math.abs($$('div.item_imagen').length*cuanto);
	anchoDisponible  = anchoTotal - 975;
	if((derecha > -1) && (cuanto>0)){
		$('botones_imagenes_menos').style.height="0px";
	}else if((cuanto<0)&&(anchoDisponible<-derecha)){
		$('botones_imagenes_mas').style.height="0px";
	}else{
		//si y solo si estamos en los límites
		new Effect.Move ('imagenes_contenidos',
			{	x: cuanto,
				y: 0, 
				mode: 'relative',
				afterFinish: activarBotos,
      				beforeStart: desactivarBotos 
      			});
		$('botones_imagenes_mas').style.height = "10px";
		$('botones_imagenes_menos').style.height = "10px";
	}
}

function activarBotos(){
	botonesArray = $$('#botones_imagenes a');
	botonesArray.each(function(item) {
	  	enableLink(item);
	});
}
function desactivarBotos(){
	botonesArray = $$('#botones_imagenes a');
	botonesArray.each(function(item) {
	  	disableLink(item);
	});
}



//Para Maquinaria

function moverMaquinaria(cuanto,id){
	var derecha = $('maquinaria_contenidos_' + id).offsetLeft;
	anchoTotal = Math.abs($$('#maquinaria_contenidos_'+ id +' .maquinaria_imagen').length*cuanto);
	anchoDisponible  = anchoTotal - (432);
	
	if((derecha > -1) && (cuanto>0)){
		
		$('botones_maquinaria_menos_' + id).style.display="none";
		$('botones_maquinaria_menos_' + id).style.visibility="hidden";
	}else if((cuanto<0)&&(anchoDisponible<=-derecha)){
		
		
		$('botones_maquinaria_mas_' + id).style.display="none";
		$('botones_maquinaria_mas_' + id).style.visibility="hidden";
	}else{
		//si y solo si estamos en los límites
		new Effect.Move ('maquinaria_contenidos_' + id,
			{	x: cuanto,
				y: 0, 
				mode: 'relative',
				afterFinish: activarBotosMaquinaria,
				beforeStart: desactivarBotosMaquinaria 
      				
      			});
		$('botones_maquinaria_menos_' + id).style.display="block";
		$('botones_maquinaria_menos_' + id).style.visibility="visible";
		$('botones_maquinaria_mas_' + id).style.display="block";
		$('botones_maquinaria_mas_' + id).style.visibility="visible";
	}
}

function activarBotosMaquinaria(){
	botonesArrayMaquinaria = $$('a');
	botonesArrayMaquinaria.each(function(item) {
	  	enableLink(item);
	});
}
function desactivarBotosMaquinaria(){
	botonesArrayMaquinaria = $$('a');
	botonesArrayMaquinaria.each(function(item) {
	  	disableLink(item);
	});
}

function escondercliente(cliente){
	if (cliente){
		$('otros').style.visibility="hidden";
	}else{
		$('otros').style.visibility="visible";
	}
}



//General
function cancelLink () {
  return false;
}
function disableLink (link) {
  if (link.onclick)
    link.oldOnClick = link.onclick;
  link.onclick = cancelLink;
  if (link.style)
    link.style.cursor = 'default';
}
function enableLink (link) {
  link.onclick = link.oldOnClick ? link.oldOnClick : null;
  if (link.style)
    link.style.cursor = 
      document.all ? 'hand' : 'pointer';
}




function popupdinamico (nombre) {
	var ruta='/publico/popupdinamico.pl?';
	windowHandle=window.open(ruta+nombre, '_Imagen', 'width=480,height=200,scrollbars=0,resizable=1,toolbar=0,personalbar=0,menubar=0,status=0' );
	windowHandle.focus();
	return(false)
}

function popup(enlace,ancho,alto){
	enlace=escape(enlace);
        windowHandle=window.open(enlace,'Imagen','scrollbars=1,width='+ancho+',height='+alto+',scrollbars=1,toolbar=0,personalbar=0,menubar=0,status=0,resizable=0');
        windowHandle.focus();
	return (false);
}



/* PARA LAS FILAS DE LA TABLA, APAREZCAN CON COLOR DE FONDO */

function hasClass(obj) {
     var result = false;
     if (obj.getAttributeNode("class") != null) {
         result = obj.getAttributeNode("class").value;
     }
     return result;
}



function stripe(id) {
    var even = false;
    var evenColor = arguments[1] ? arguments[1] : "#fff";
    var oddColor = arguments[2] ? arguments[2] : "#eee";
  	var table = document.getElementById(id);
    if (! table) { return; }
    var tbodies = table.getElementsByTagName("tbody");
    for (var h = 0; h < tbodies.length; h++) {
      var trs = tbodies[h].getElementsByTagName("tr");
      for (var i = 0; i < trs.length; i++) {
        if (! hasClass(trs[i]) && ! trs[i].style.backgroundColor) {
          var tds = trs[i].getElementsByTagName("td");
          for (var j = 0; j < tds.length; j++) {
            var mytd = tds[j];
            //if (! hasClass(mytd) && ! mytd.style.backgroundColor) {
              mytd.style.backgroundColor = even ? evenColor : oddColor;
              //mytd.style.border = 'outset 1 #bbbbbb';
            //}
          }
        }
        even =  ! even;
      }
    }
  }
//eliminar parpadeo en backgrounds en iExplorer
try {
document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}


//abre en nueva ventana los enlaces con class="nuevaVentana"
function agregarBlank() {
	arrayAs = document.getElementsByTagName('a');
	for (var index = 0; index < arrayAs.length; ++index) {
		var item = arrayAs[index];
		if (item.className == 'nuevaVentana'){
			item.onclick = function (){
				ventanaNueva = window.open(this.href,'nueva');
				ventanaNueva.focus();
				return false;
			}
		}
	}
}




