// JavaScript Document


//    FUNCION PARA AGREGAR EVENTOS


function addEvent( obj, type, fn ) {
	if ( obj.attachEvent ) 
	{
		obj['e'+type+fn] = fn;
		obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
		obj.attachEvent( 'on'+type, obj[type+fn] );
	} 
	else
		obj.addEventListener( type, fn, false );
}



//    FUNCION PARA MOSTRAR / OCULTAR ELEMENTOS


function verOnover(ide,visible)
{
	obj = document.getElementById(ide);
	obj.style.display = (visible)?'block':'none';
}



//    FUNCION PREGUNTAR SI SE QUIERE ELIMINAR



function borraritem()
{
	if(confirm('¿Esta seguro que quiere borrarlo?'))
	{
		window.location = this.href;
	}
	else
	{
		return false;	
	}
}



//    FUNCION PARA ABRIR UN POPUP


function popUp(url,name,ancho,alto)
{
	var propiedades = "toolbar=0,location=0,directories=0,status=0,menubar=no,scrollbars=1,top=50,left=50,resizable=0,width="+ancho+",height="+alto;
	window.open(url,name,propiedades);	
}



//    FUNCION PARA HACER QUE EN UN CAMPO SOLO SE INGRESEN NUMEROS


function onlyNumberDot()
{	
	var tecla = window.event.keyCode;
	var punto = window.event.srcElement.value.indexOf('.');
	if ((tecla == 44) || (tecla == 46))
	{
		if (punto != -1)
			window.event.keyCode = 0;
		else
			window.event.keyCode = 46;
	}
	if (!((tecla == 44) || (tecla == 46) || (tecla == 8) || (tecla == 9) || (((tecla - 48) >= 0) && ((tecla - 48) <= 9))))
		window.event.keyCode = 0;
}


//    Abrir el popUP de problemas


function problemas()
{
	var propiedades = "toolbar=0,location=0,directories=0,status=0,menubar=no,scrollbars=1,top=100,left=100,resizable=0,width=450,height=325";
	window.open("problemas.php?"+window.location,name,propiedades);
}

// Funcion para abrir imagenes en una ventana con tamaño

var ventana

function afoto(cual)
{
vacio = '';
ventana=window.open(vacio,vacio,'width=600, height=400, resizable=yes,scrollbars=no, left=150 ; top=150')
ventana.document.write('<html><head><title>Industrias Buho | Productos</title></head><body style="overflow:hidden" marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" scroll="no"><img src="' + cual + '" onLoad="opener.redimensionar(this.width, this.height)"></body></html>');
ventana.document.close();
}
function redimensionar(ancho, alto)
{
ventana.resizeTo(ancho+10,alto+30);
ventana.moveTo((screen.width-(ancho+10))/2,(screen.height-(alto+30))/2); //centra la ventana.
}


// Cambio la funcionalidad de los link segun funcion

function cambiarLinks() {

	if (!document.getElementsByTagName) return;
	
	var anchors = document.getElementsByTagName("a");
	
	for (var i=0; i<anchors.length; i++) 
	{
		var anchor = anchors[i];
		
		// cambio los enlaces externos
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
		{
			anchor.target = "_blank";
		}
	 	// Cambio los enlaces para borrar
		else if (anchor.getAttribute("href") && (anchor.getAttribute("className") == "eliminar" || anchor.getAttribute("class") == "eliminar"))
		{
			/*
			url = anchor.getAttribute("href");
			anchor.setAttribute("href", "javascript:borraritem('" + url + "')")
			*/
			anchor.onclick = borraritem;
		}
		// cambio los enlaces de fotos
		else if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "foto")
		{
			foto = anchor.getAttribute("href");
			anchor.setAttribute("href","javascript:afoto('" + foto + "');");
		}
	}
}


//                 AGREGO LOS EVENTOS                


addEvent(window, 'load', cambiarLinks);
