/***** ROLLOVER SENCILLO QE TE CAGAS *****/
//en la imagen --> onmouseover="this.src=Imagenes[0].src;" onmouseout="this.src=Imagenes[1].src;"
//en onLoad de <body> -->onLoad="Precargar('rutarelativa/imagen-ON', 'rutarelativa/imagen-OFF')"
Imagenes = new Array();
function Precargar() {
	
  for (var i=0; i<Precargar.arguments.length; i++) {    
    Imagenes[i]=new Image; 
    Imagenes[i].src=Precargar.arguments[i];
  }
}



/***** Captura de la posición del ratón *****/
function Browser() {
this.isIE = false; // Internet Explorer
this.isNS = false; // Netscape
this.isOpera = false; // Opera
if (navigator.userAgent.indexOf("Netscape6/") >= 0) {
this.isNS = true;
return;
}
if (navigator.userAgent.indexOf("Gecko") >= 0) {
this.isNS = true;
return;
}
if (navigator.userAgent.indexOf("MSIE") >=0 && navigator.userAgent.indexOf("Opera") <0) {
this.isIE = true;
return;
}
if (navigator.userAgent.indexOf("Opera") >=0) {
this.isOpera = true;
return;
}
}

var browser = new Browser();

function initMovimiento(event){
cancelar();
if (browser.isIE || browser.isOpera) {
document.attachEvent("onmousemove", getposicion);
window.event.cancelBubble = true;
window.event.returnValue = false;
}
if (browser.isNS) {
document.addEventListener("mousemove", getposicion, true);
event.preventDefault();
}
}
function initPulsar(event){
cancelar();
if (browser.isIE || browser.isOpera) {
document.attachEvent("onclick", getposicion);
window.event.cancelBubble = true;
window.event.returnValue = false;
}
if (browser.isNS) {
document.addEventListener("click", getposicion, true);
event.preventDefault();
}
}
function getposicion(event){
if (browser.isIE) {
x = window.event.clientX + document.documentElement.scrollLeft
+ document.body.scrollLeft;
y = window.event.clientY + document.documentElement.scrollTop
+ document.body.scrollTop;
}
if (browser.isNS) {
x = event.clientX + window.scrollX;
y = event.clientY + window.scrollY;
}
if (browser.isOpera) {
x = window.event.clientX + document.documentElement.scrollLeft;
y = window.event.clientY + document.documentElement.scrollTop;
}
document.getElementById("posicion").style.visibility = "visible";
document.getElementById("posicion").style.left= (x - 55) +"px";
document.getElementById("posicion").style.top = y + 20 +"px";
document.getElementById("posicion").innerHTML = "Coordenada x: " + x + "<br>Coordenada y: " + y;
}

function cancelar() {
if (browser.isIE || browser.isOpera) {
document.detachEvent("onmousemove", getposicion);
document.detachEvent("onclick", getposicion);
}
if (browser.isNS ) {
document.removeEventListener("mousemove", getposicion, true);
document.removeEventListener("click", getposicion, true);
}
document.getElementById("posicion").style.visibility= "hidden";
}

//-----------------------------------------

// popups de imágenes de la galería
function popup(ruta_base, ancho, id_imagen)
{
	var features = "width=" + ancho + ", height=600";
	
	nueva = window.open(ruta_base + "admin/galeria/ver_imagen.php?id=" + id_imagen, "imagen", features);
	nueva.focus();
}

// funciones para mostrar/ocultar capas
function mostrar_capa(event, capa)
{
	var flagstyle = document.getElementById('flagstyle');
	if (flagstyle.style.display == 'none') {
		document.getElementById(capa).style.display = "block";
		document.getElementById(capa).style.position = "absolute";

		if (browser.isIE) {
			x = window.event.clientX + document.documentElement.scrollLeft
			+ document.body.scrollLeft;
			y = window.event.clientY + document.documentElement.scrollTop
			+ document.body.scrollTop;
		}
		if (browser.isNS) {
			x = event.clientX + window.scrollX;
			y = event.clientY + window.scrollY;
		}
		if (browser.isOpera) {
			x = window.event.clientX + document.documentElement.scrollLeft;
			y = window.event.clientY + document.documentElement.scrollTop;
		}

		document.getElementById(capa).style.left= (x - (document.getElementById(capa).offsetWidth/2)) +"px";
		document.getElementById(capa).style.top = (y + 20) +"px";
	}
}
function ocultar_capa(capa)
{
	var flagstyle = document.getElementById('flagstyle');
	if (flagstyle.style.display == 'none') {
		document.getElementById(capa).style.display = "none";
		document.getElementById(capa).style.position = "absolute";

		if (browser.isIE || browser.isOpera) {
			document.detachEvent("onmousemove", getposicion);
			document.detachEvent("onclick", getposicion);
		}
		
		if (browser.isNS ) {
			document.removeEventListener("mousemove", getposicion, true);
			document.removeEventListener("click", getposicion, true);
		}
	}
}
function limpiarTexto(cajaTexto)
{
	if (cajaTexto.defaultValue==cajaTexto.value)
		cajaTexto.value = "";
} 

function validar(carrito)
{
	
	if (document.carrito.precio_oculto.value != 0)
	{
		return true;		
	}
	else
	{
		alert ("Imposible añadir un producto de precio con valor 0");
		return false;
	}
	
}

// Version Imprimible

// el temita de la impresion
function __poner_cabeceras(ruta_base, idioma, ventana)
{
	var salida_html = "<html>\n";
	salida_html += "\n\t<head>";
	salida_html += "\n\t\t<title>";
	salida_html += "TARSOMAN - Detalle de producto";
	salida_html += "</title>\n";
	salida_html += "<link href='popup.css' rel='stylesheet' type='text/css'>";
	salida_html += "\n\t</head>\n\t";
	salida_html += __poner_estilos_de_pagina(ruta_base, idioma);
	salida_html += "\n\t<body>";
	
	ventana.document.write(salida_html);
}

function __poner_pie(ventana)
{
	var salida_html = "";
	
	salida_html += "\n\t<div style=\"text-align: center\">";
	salida_html += "\n\t\t<a class='peque' class='link_de_categoria' href='#' onclick='window.print(); window.close();'>Imprimir</a>&nbsp;&nbsp;";
	salida_html += "\n\t&nbsp;&nbsp;<a class='peque' class='link_de_categoria' href='#' onclick='window.close(); window.close();'>Cerrar</a>";
	salida_html += "\n\t</div>";
	salida_html += "\n<br>";
	
	salida_html += "\n</body>";
	salida_html += "\n\n</html>";
	
	ventana.document.write(salida_html);
	
}

function __poner_estilos_de_pagina(ruta_base, idioma)
{
	var salida_html = "<style type='text/css'>";
	//salida_html += "\n@import url(" + ruta_base + "css/otros/portada.css);";
	
	salida_html += "\n</style>";
	
	return salida_html;
}

function print_test(ruta_base, idioma, idcapa)
{
	
	capa = document.getElementById(idcapa);
	alto = capa.offsetHeight + 50;
	nueva = window.open("", "", "width=650, height=" + alto + ", scrollbars=yes");

	__poner_cabeceras(ruta_base, idioma, nueva);
	nueva.document.write("<div id='capa_imprimir' align='left'>");
	nueva.document.write(capa.innerHTML);
	nueva.document.write("</div>");
	__poner_pie(nueva);
	nueva.document.close();
	nueva.focus();
	
}