var url = "";


function PonValor(theTable,valor,Table2)
{
	if (document.getElementById(Table2).style.display == 'none')
	{
		document.getElementById(theTable).value = '0';
	}
	else
	{
		document.getElementById(theTable).value = valor ;
	}
}

function PonValor2(theTable,valor)
{
	document.getElementById(theTable).value = valor;
}

function VerSeccion(theTable)
{
		$('#'+theTable).slideToggle('fast');
}

function VerCarro_new(theTable, img, ruta)
{
	if($('#'+theTable).is(':visible'))
	{
		$('#'+img).attr('src', ruta+'ver_carrito.gif');
		$('#'+theTable).slideToggle('fast');
	}
	else
	{
		$('#'+img).attr('src', ruta+'ocultar_carrito02.gif');
		$('#'+theTable).slideToggle('normal');
	}
}

function VerSeccion2(theTable)
{
	if (document.getElementById(theTable).style.display == 'none')
	{
		document.getElementById(theTable).style.display = '';
		document.getElementById('Off'+theTable).style.display = 'none';
	}
	else
	{
		document.getElementById(theTable).style.display = 'none';
		document.getElementById('Off'+theTable).style.display = '';
	}
}

function OcultaSeccion(theTable)
{
		document.getElementById(theTable).style.display = 'none';
		document.getElementById('Off'+theTable).style.display = '';
}

function CambiaIdioma(id){
		recarga(recuperaUrl(strUrl_Act) + "&idioma=" + id);
}

function PopImage(type,id){
	window.open("image.asp?type=" + type + "&id=" + id,"image","toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=1,height=1,left = 0,top = 0");
}

function addToCart(field_id){
	var resultado = document.getElementById("codigo_opcion_producto_" + field_id).value;
	var cant = document.getElementById("cantidad_producto_" + field_id).value;
	var cant2 = document.getElementById("cantidad_producto_" + field_id).value;
    var donde = resultado.indexOf(",");
	var producto_id = resultado.substring(0,donde);
	var cant_max = resultado.substring((donde+1),resultado.length);
	var cant_max = 29999;
	if(parseFloat (cant)>=parseFloat (cant_max)){
		cant= cant_max;
	}
	if(parseFloat (cant)<= 0){
		cant= 1;
	}
	if(cant!=0){
		recarga(recuperaUrl(strUrl_Act) + "&accion=add&id=" + producto_id + "&cant=" + cant);
	}
}

function addToCart2(field_id, cant_max){
	var cant = document.getElementById("cantidad_producto_" + field_id).value;
	var producto_id = field_id;
	var cant_max = 29999;
	if(parseFloat (cant)>=parseFloat (cant_max)){
		cant= cant_max;
	}
	if(parseFloat (cant)<= 0){
		cant= 1;
	}
	if(cant!=0){
		recarga(recuperaUrl(strUrl_Act) + "&accion=add&id=" + producto_id + "&cant=" + cant);
	}
}

function addToCart3(producto_id){
	var cant = 1;
	recarga(recuperaUrl(strUrl_Act) + "&accion=add&id=" + producto_id + "&cant=" + cant);
}


function modifCart(field_id, cant_max){
	var cant = document.getElementById("cantidad_carro_" + field_id).value;
	var producto_id = field_id;
	var cant_max = 29999;
	if(parseFloat (cant)>=parseFloat (cant_max)){
		cant= cant_max;
	}
	if(parseFloat (cant)<= 0){
		cant= 1;
	}
	if(cant!=0){
		recarga(recuperaUrl(strUrl_Act) + "&accion=modif&id=" + producto_id + "&cant=" + cant);
	}
}

function deleteFromCart(producto_id, cant){
	if(producto_id!=0){
		recarga(recuperaUrl(strUrl_Act) + "&accion=quit&id=" + producto_id + "&cant=" + cant);
	}
}


function recuperaUrl(Url0){
	var strUrl = Url0;
	var strUrl_out = "?";
	var strUrl_out2 = "";
	var intInicio = strUrl.indexOf('[') + 1;
	var intFin = strUrl.indexOf('&accion',intInicio);
	if (intFin <= 0){
		intFin = strUrl.indexOf('&estilo',intInicio);
	};
	if (intFin <= 0){
		intFin = strUrl.indexOf('&mk',intInicio);
	};
	if (intFin <= 0){
		intFin = strUrl.indexOf('&idioma',intInicio);
	};
	if (intFin <= 0){
		intFin = strUrl.indexOf('&menu',intInicio);
	};
	if (intFin <= 0){
		intFin = strUrl.indexOf(']',intInicio);
	};
	if (intFin > 0){
		strUrl_out2 = strUrl_out + strUrl.substring(intInicio,intFin);
	};
	if (strUrl_out2 == '?')
	{
		strUrl_out = strUrl_out + 'mod=dest';
	}
	else
	{
		strUrl_out = strUrl_out + strUrl.substring(intInicio,intFin);
	};
	return strUrl_out;
}


function recarga(pag){
	var menu = document.getElementById("PosMenu").value;
	var carro = document.getElementById("PosCarro").value;
	document.title = strTitulo + ' - ' + strCarga;
	window.status=strCarga;
	document.location = pag + "&menu=" + menu + "&carro=" + carro;
}


function PagCargada(pie, tit){
	VerSeccion('precarga'); 
    scObjTop10.scroll(); 
	window.status=pie;
	document.title = tit;
}

function buscar(pag){
	var busca = document.getElementById("buscar").value;
	var menu = document.getElementById("PosMenu").value;
	var carro = document.getElementById("PosCarro").value;
	document.location = pag +  busca + "&menu=" + menu + "&carro=" + carro;
}


function botonbuscar(pag){
	var busca = document.getElementById("CadenaBuscar").value;
	var bmenu_id = document.getElementById("bmenu_id").value;
	var fab_id = document.getElementById("fab_id").value;
	var menu = document.getElementById("PosMenu").value;
	var carro = document.getElementById("PosCarro").value;
	document.location = pag +  busca + "&bmenu_id=" + bmenu_id + "&fab_id=" + fab_id + "&menu=" + menu + "&carro=" + carro;
}

function showError(number, source, description){
	div_name = "errordiv";
	document.getElementById(div_name).style.visibility = "";
}

function mandaestilo(accion){
	if (accion != '')
	{
		sruta = recuperaUrl(strUrl_Act);
		recarga(sruta + '&estilo=' + accion );
	};
}


function recargaprod(pag){
		recarga('?mod=ficha&prod_id=' + pag + '&mk=all' );
}

function scrollObject(main, width, height, direct, pause, speed) {
	var self = this;
	this.main = main;
	this.width = width;
	this.height = height;
	this.direct = direct;
	this.pause = pause;
	this.speed = Math.max(1.001, Math.min((direct == "up" || direct == "down") ? height : width, speed));
	this.block = new Array();
	this.blockprev = this.offset = 0;
	this.blockcurr = 1;
	this.mouse = false;
	this.scroll = function() {
		if (!document.getElementById) return false;
		this.main = document.getElementById(this.main);
		while (this.main.firstChild) this.main.removeChild(this.main.firstChild);
		this.main.style.overflow = "hidden";
		this.main.style.position = "relative";
		this.main.style.width = this.width + "px";
		this.main.style.height = this.height + "px";
		for (var x = 0; x < this.block.length; x++) {
			var table = document.createElement('table');
					table.cellPadding = table.cellSpacing = table.border = "0";
					table.style.position = "absolute";
					table.style.left = table.style.top = "0px";
					table.style.width = this.width + "px";
					table.style.height = this.height + "px";
					table.style.overflow = table.style.visibility = "hidden";
				var tbody = document.createElement('tbody');
					var tr = document.createElement('tr');
						var td = document.createElement('td');
								td.innerHTML = this.block[x];
							tr.appendChild(td);
						tbody.appendChild(tr);
					table.appendChild(tbody);
			this.main.appendChild(this.block[x] = table);
		}
		if (this.block.length > 1) {
			this.main.onmouseover = function() { self.mouse = true; }
			this.main.onmouseout = function() { self.mouse = false; }
			setInterval(function() {
				if (!self.offset && self.scrollLoop()) self.block[self.blockcurr].style.visibility = "visible";
			}, this.pause);
		} this.block[this.blockprev].style.visibility = "visible";
	}
	this.scrollLoop = function() {
		if (!this.offset) {
      if (this.mouse) return false;
			this.offset = (this.direct == "up" || this.direct == "down") ? this.height : this.width;
    } else this.offset = Math.floor(this.offset / this.speed);
		if (this.direct == "up" || this.direct == "down") {
			this.block[this.blockcurr].style.top = ((this.direct == "up") ? this.offset : -this.offset) + "px";
			this.block[this.blockprev].style.top = ((this.direct == "up") ? this.offset - this.height : this.height - this.offset) + "px";
		} else {
			this.block[this.blockcurr].style.left = ((this.direct == "left") ? this.offset : -this.offset) + "px";
			this.block[this.blockprev].style.left = ((this.direct == "left") ? this.offset - this.width : this.width - this.offset) + "px";
		}
		if (!this.offset) {
			this.block[this.blockprev].style.visibility = "hidden";
			this.blockprev = this.blockcurr;
			if (++this.blockcurr >= this.block.length) this.blockcurr = 0;
		} else setTimeout(function() { self.scrollLoop(); }, 30);
    return true;
	}
}