// JavaScript Document

 


function MM_openBrWindow(theURL,winName,features) { 
  window.open(theURL,winName,features);
}

function Confirm_Accion(aviso)
{
	var v=confirm(aviso);
	return (v);
}

function Confirm_Link(aviso, lnk)
{
	var v=confirm(aviso);
	
	if(v) self.location=lnk;
	
	return;
}
function btnConfirmar(boton, aviso, lnk){
	var v=confirm(aviso);
	if(v){ 
		$(boton).disabled=true;
		$(boton).value='Espere...';	
		window.location=url;
	}
	return true;
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function sendForm(formulario, btnSubmit){
	$(btnSubmit).disabled=true;
	$(btnSubmit).value='Espere...';	
	$(formulario).submit();
	return true;
}
function botonGoTo(boton, url){
	$(boton).disabled=true;
	$(boton).value='Espere...';	
	window.location=url;
	return true;
}

function imprimirPagina() { 
	if (window.print) 
		window.print(); 
	else 
		alert("Lo siento, pero a tu navegador no se le puede ordenar imprimir" + " desde la web. Actualizate o hazlo desde los menús"); 
}

/* 	manejo de las pestañas tabs */
function swapTabs(pestana, cantidad){
	for(i=1; i<cantidad+1;i++){
		pest = 'paso'+i;
		pesta = 'pas'+i;
		if(i==pestana){
			$(pest).style.display='block'; 
			Element.addClassName($(pesta), 'selected')
		}else{
			 $(pest).style.display='none'
			 Element.removeClassName($(pesta), 'selected')
		}
	}
}

function limitarTexto(texto, maximo, monitor){
    total = maximo;
    tam = texto.value.length;
	temp = total-tam;
	txt = tam+'/'+temp;
    $(monitor).innerHTML = txt;

    if (tam > total){
        aux = texto.value;
        texto.value = aux.substring(0,total);
       	txt = total+"/0";
	    $(monitor).innerHTML = txt;
   }
	
}

/*********************************************************************
	Dichosos favoritos
*********************************************************************/
var STAR_ON = host+"images/link_yoque_activado.gif";
var STAR_OFF = host+"images/link_yoque_desactivado.gif";
var img = new Image();
img.src = STAR_ON;
img.src = STAR_OFF;


function setFav(elemento, idContenido, tipo){

if(elemento.src.indexOf(STAR_ON,0)>-1){
	desde = 'marcados';
	hasta = elemento;
	elemento.src=STAR_OFF;
}else{
	desde=elemento;
	hasta='marcados';
	elemento.src=STAR_ON;
}

//Creamos el div
var div = document.createElement("div");
//Le damos una clase CSS
Element.addClassName(div,'flotante');
//Le damos el aspecto del que hay que mover
var tamano = Element.getDimensions($(desde));
var posicion = Position.cumulativeOffset($(desde));
var target = Position.cumulativeOffset($(hasta));

div.style.width = (tamano.width - 4)+"px";
div.style.height = (tamano.height - 4)+"px";
div.style.top = posicion[1]+"px";
div.style.left = posicion[0]+"px";

document.body.appendChild(div);

//ahora hacemos el movimiento

  new Rico.Effect.SizeAndPosition(div, 
								  target[0], //  x = 450 null, // don't change the y 
								  target[1],
								  5 , // width = 300px 
								  5, // don't change the height 
								  250, // 500ms (1/2 second) 
								  10, // 10 steps
								  {complete:function(){
									  cargarFavoritosAjax(idContenido, tipo);
									  removerEsteDiv(div);
								  	}
								  }
								  
								  );

}
function removerEsteDiv(div){
	Element.remove(div);
}
function cargarFavoritosAjax(idContenido, tipo){
	var url 	= host+'ajax/ajx.setFavoritos.php';
	var pars 	= 'id='+idContenido+'&tipo='+tipo;	
	var myAjax = new Ajax.Updater( 'marcados', url, { method: 'post', parameters: pars }); 
	
}

function setFavAviso(elemento, idContenido, tipo){
if(elemento.src.indexOf(STAR_ON,0)>-1){
	elemento.src=STAR_OFF;
}else{
	elemento.src=STAR_ON;
}	
	
	var url 	= host+'ajax/ajx.setFavoritos.php';
	var pars 	= 'id='+idContenido+'&tipo='+tipo;	
	var myAjax = new Ajax.Request( url, { 
								  		method: 'post',
								  		parameters: pars	
										});



}


/*********************************************************************
	Busqueda avanzada
*********************************************************************/
function cargarExtendida(categoria){
var url = host+'ajax/ajx.busqueda_avanzada.php';
var pars = 'cat='+$F(categoria);
var myAjax = new Ajax.Updater( 
							  'extendido', 
							  url,
							  { 
								  method: 'post', 
								  parameters: pars 
							  }
							  ); 	
	
}
/*********************************************************
	Dichosos gallegos y sus imagenes repetidas también
**********************************************************/
function checkFotoDelUp(checkbox, elemento){
	if($(checkbox).checked){
		Element.show(elemento);
	}else{
		Element.hide(elemento);
	}
}
