﻿
function Resaltar_On(GridViewRow)
{
    if(GridViewRow != null)
    {
        GridViewRow.originalBgColor = GridViewRow.style.backgroundColor;
        GridViewRow.style.backgroundColor = "#DBE7F6";
        MostrarMano(GridViewRow);
    }
}

function Resaltar_Off(GridViewRow)
{
    if(GridViewRow != null)
    {
        GridViewRow.style.backgroundColor = GridViewRow.originalBgColor;
        OcultarMano(GridViewRow);        
    }
}

function ModificarProducto(indice)
{
    var strContent = "ctl00_ContentPlaceHolder1_";
    var iUpdate = document.getElementById(strContent + "gridProductos_ctl" + indice + "_iUpdate");    
    iUpdate.click();
}

function EliminarProducto(indice, ref)
{
    var strMsg = "¿Desea eliminar este producto con referencia '" + ref + "'?"
    
    return confirm(strMsg);
}

function MostrarDetalle()
{
    var strContent = "ctl00_ContentPlaceHolder1_";
    var divDetalle = document.getElementById(strContent + "divDetalle");
    divDetalle.style.display = "block";    
    divDetalle.style.height = "380px";  
    var iNew = document.getElementById(strContent + "iNew");
    iNew.style.display = "none";
    var divProductos = document.getElementById(strContent + "divProductos");
    divProductos.style.display = "none";
    var divBusquedaPor = document.getElementById(strContent + "divBusquedaPor");
    divBusquedaPor.style.display = "none";
}

function CancelarDetalle()
{
    var strContent = "ctl00_ContentPlaceHolder1_";
    var divDetalle = document.getElementById(strContent + "divDetalle");
    divDetalle.style.display = "none";
    var iNew = document.getElementById(strContent + "iNew");
    iNew.style.display = "block";
    var divProductos = document.getElementById(strContent + "divProductos");
    divProductos.style.display = "block";
    var divBusquedaPor = document.getElementById(strContent + "divBusquedaPor");
    divBusquedaPor.style.display = "block";
    LimpiarDetalle();
    return false;
}

function LimpiarDetalle()
{
    var strContent = "ctl00_ContentPlaceHolder1_";
    var txtReferencia_NEW = document.getElementById(strContent + "txtReferencia_NEW");
    var txtNombre_NEW = document.getElementById(strContent + "txtNombre_NEW");
    var txtPrecio_NEW = document.getElementById(strContent + "txtPrecio_NEW");  
    var txtDescCorta_NEW = document.getElementById(strContent + "txtDescCorta_NEW");   
    var txtDescLarga_NEW = document.getElementById(strContent + "txtDescLarga_NEW");    
    var txtImagen_NEW = document.getElementById(strContent + "txtImagen_NEW");    
    var ddlSubFamilia_NEW = document.getElementById(strContent + "ddlSubFamilia_NEW");
    var ddlMarca_NEW = document.getElementById(strContent + "ddlMarca_NEW");
    
    txtReferencia_NEW.value = "";
    txtNombre_NEW.value = "";
    txtPrecio_NEW.value = "";
    txtDescCorta_NEW.value = "";
    txtDescLarga_NEW.value = "";
    txtImagen_NEW.value = "";
    ddlSubFamilia_NEW.value = 0;
    ddlMarca_NEW.value = 0;    
}

function MostrarMano(a)
{
    a.style.cursor = 'hand'; 
}

function OcultarMano(a)
{
    a.style.cursor = 'normal'; 
}


function IsFloat(strNumber)
{
	if(isNaN(parseFloat(strNumber)))
	{
		return true;
	}
	else
	{
		return false;
	}	
}

function ModificarPedido(indice)
{
    var strContent = "ctl00_ContentPlaceHolder1_";
    var iUpdate = document.getElementById(strContent + "gridPedidos_ctl" + indice + "_iUpdate");    
    iUpdate.click();
}

function EliminarPedido(indice, numPedido)
{
    var strMsg = "¿Desea eliminar este pedido con número de pedido '" + numPedido + "'?"
    
    return confirm(strMsg);
}

function AbrirPedido(idUsuario, numPedido)
{
    var _size = 600;        
    var _sizeX = 625;        
    var _sizeY = 600;        
    var _top = (screen.height - _size)/2;
    var _left = (screen.width - _size)/2;
    var _params = "top=" + _top + ", left=" + _left + ", width=" + _sizeX +", height=" + _sizeY + ", status=no, resizable=no, scrollbars=no";
    
    window.open("AbrirPedido.aspx?idUsuario=" + idUsuario + "&numPedido=" + numPedido , "Pedido", _params); 
}

function MostrarMarca()
{
    var strContent = "ctl00_ContentPlaceHolder1_";
    var iNew = document.getElementById(strContent + "iNew");
    iNew.style.display = "none";
    var gridMarca = document.getElementById(strContent + "gridMarca");
    gridMarca.style.display = "none";
    var divDetalleMarca = document.getElementById(strContent + "divDetalleMarca");
    divDetalleMarca.style.display = "block";  
}

function CancelarMarca()
{
    var strContent = "ctl00_ContentPlaceHolder1_";
    var iNew = document.getElementById(strContent + "iNew");
    iNew.style.display = "block";
    var gridMarca = document.getElementById(strContent + "gridMarca");
    gridMarca.style.display = "block";
    var divDetalleMarca = document.getElementById(strContent + "divDetalleMarca");
    divDetalleMarca.style.display = "none"; 

    return false;
}

function ModificarMarca(indice)
{
    var strContent = "ctl00_ContentPlaceHolder1_";
    var iUpdate = document.getElementById(strContent + "gridMarca_ctl" + indice + "_iUpdate");    
    iUpdate.click();
}

function EliminarMarca(indice, nombreMarca)
{
    var strMsg = "¿Desea eliminar esta Marca '" + nombreMarca + "'?"
    
    return confirm(strMsg);
}

function MostrarMenu()
{
    var strContent = "ctl00_ContentPlaceHolder1_";
    var iNew = document.getElementById(strContent + "iNew");
    iNew.style.display = "none";
    var iTest = document.getElementById(strContent + "iTest");
    iTest.style.display = "none"; 
    var divMenu = document.getElementById(strContent + "divMenu");
    divMenu.style.display = "none";
    var divDetalleMenu = document.getElementById(strContent + "divDetalleMenu");
    //divDetalleMenu.style.height = "440px";  
    divDetalleMenu.style.display = "block";  
    var divBusquedaPor = document.getElementById(strContent + "divBusquedaPor");
    divBusquedaPor.style.display = "none"; 
}

function CancelarMenu()
{
    var strContent = "ctl00_ContentPlaceHolder1_";
    var iNew = document.getElementById(strContent + "iNew");
    iNew.style.display = "block";
    var iTest = document.getElementById(strContent + "iTest");
    iTest.style.display = "block";  
    var divMenu = document.getElementById(strContent + "divMenu");
    divMenu.style.display = "block";
    var divDetalleMenu = document.getElementById(strContent + "divDetalleMenu");
    divDetalleMenu.style.height = "";  
    divDetalleMenu.style.display = "none"; 
    var divBusquedaPor = document.getElementById(strContent + "divBusquedaPor");
    divBusquedaPor.style.display = "block";

    return false;
}

function ModificarMenu(indice)
{
    var strContent = "ctl00_ContentPlaceHolder1_";
    var iUpdate = document.getElementById(strContent + "gridMenu_ctl" + indice + "_iUpdate");    
    iUpdate.click();
}

function EliminarMenu(indice, nombreMenu)
{
    var strMsg = "¿Desea eliminar este Menú '" + nombreMenu + "'?"
    
    return confirm(strMsg);
}

function ComprobarMenu()
{
    var _size = 400;        
    var _sizeX = 400;        
    var _sizeY = 400;        
    var _top = (screen.height - _size)/2;
    var _left = (screen.width - _size)/2;
    var _params = "top=" + _top + ", left=" + _left + ", width=" + _sizeX +", height=" + _sizeY + ", status=no, resizable=no, scrollbars=no";
    
    window.open("VerMenu.aspx", "Menu", _params); 
   return false; 
}

function MostrarCatalogo()
{
    var strContent = "ctl00_ContentPlaceHolder1_";
    var iNew = document.getElementById(strContent + "iNewCatalogo");
    iNew.style.display = "none";
    var gridCatalogo = document.getElementById(strContent + "gridCatalogo");
    gridCatalogo.style.display = "none";
    var divDetalleCatalogo = document.getElementById(strContent + "divDetalleCatalogo");
    divDetalleCatalogo.style.display = "block";  
}

function CancelarCatalogo()
{
    var strContent = "ctl00_ContentPlaceHolder1_";
    var iNew = document.getElementById(strContent + "iNewCatalogo");
    iNew.style.display = "block";
    var gridCatalogo = document.getElementById(strContent + "gridCatalogo");
    gridCatalogo.style.display = "block";
    var divDetalleCatalogo = document.getElementById(strContent + "divDetalleCatalogo");
    divDetalleCatalogo.style.display = "none"; 

    return false;
}

function ModificarCatalogo(indice)
{
    var strContent = "ctl00_ContentPlaceHolder1_";
    var iUpdate = document.getElementById(strContent + "gridCatalogo_ctl" + indice + "_iUpdate");    
    iUpdate.click();
}

function EliminarCatalogo(indice, nombreCatalogo)
{
    var strMsg = "¿Desea eliminar este Catálogo '" + nombreCatalogo + "'?"
    
    return confirm(strMsg);
}

function MostrarFamilia()
{
    var strContent = "ctl00_ContentPlaceHolder1_";
    var iNew = document.getElementById(strContent + "iNewFamilia");
    iNew.style.display = "none";
    var gridFamilia = document.getElementById(strContent + "gridFamilia");
    gridFamilia.style.display = "none";
    var divDetalleFamilia = document.getElementById(strContent + "divDetalleFamilia");
    divDetalleFamilia.style.display = "block";  
}

function CancelarFamilia()
{
    var strContent = "ctl00_ContentPlaceHolder1_";
    var iNew = document.getElementById(strContent + "iNewFamilia");
    iNew.style.display = "block";
    var gridFamilia = document.getElementById(strContent + "gridFamilia");
    gridFamilia.style.display = "block";
    var divDetalleFamilia = document.getElementById(strContent + "divDetalleFamilia");
    divDetalleFamilia.style.display = "none"; 

    return false;
}

function ModificarFamilia(indice)
{
    var strContent = "ctl00_ContentPlaceHolder1_";
    var iUpdate = document.getElementById(strContent + "gridFamilia_ctl" + indice + "_iUpdate");    
    iUpdate.click();
}

function EliminarFamilia(indice, nombreFamilia)
{
    var strMsg = "¿Desea eliminar esta Familia '" + nombreFamilia + "'?"
    
    return confirm(strMsg);
}

function MostrarSubfamilia()
{
    var strContent = "ctl00_ContentPlaceHolder1_";
    var iNew = document.getElementById(strContent + "iNewSubfamilia");
    iNew.style.display = "none";
    var gridSubfamilia = document.getElementById(strContent + "gridSubfamilia");
    gridSubfamilia.style.display = "none";
    var divDetalleSubfamilia = document.getElementById(strContent + "divDetalleSubfamilia");
    divDetalleSubfamilia.style.display = "block";  
}

function CancelarSubfamilia()
{
    var strContent = "ctl00_ContentPlaceHolder1_";
    var iNew = document.getElementById(strContent + "iNewSubfamilia");
    iNew.style.display = "block";
    var gridSubfamilia = document.getElementById(strContent + "gridSubfamilia");
    gridSubfamilia.style.display = "block";
    var divDetalleSubfamilia = document.getElementById(strContent + "divDetalleSubfamilia");
    divDetalleSubfamilia.style.display = "none"; 

    return false;
}

function ModificarSubfamilia(indice)
{
    var strContent = "ctl00_ContentPlaceHolder1_";
    var iUpdate = document.getElementById(strContent + "gridSubfamilia_ctl" + indice + "_iUpdate");    
    iUpdate.click();
}

function EliminarSubfamilia(indice, nombreSubfamilia)
{
    var strMsg = "¿Desea eliminar esta Subfamilia '" + nombreSubfamilia + "'?"
    
    return confirm(strMsg);
}

function cambiaBorde()
{	        
    var tabla = document.getElementsByName("tblCarrito");
    
    if(tabla[0].style.borderColor == "#0025cd")
    {	        
        tabla[0].style.borderColor = "yellow";// "#FFFFFF";
    }
    else
    {	         
        tabla[0].style.borderColor = "#0025cd";	        
    }	        
}

function AbrirImpresion()
{
    var _size = 600;        
    var _sizeX = 625;        
    var _sizeY = 600;        
    var _top = (screen.height - _size)/2;
    var _left = (screen.width - _size)/2;
    var _params = "top=" + _top + ", left=" + _left + ", width=" + _sizeX +", height=" + _sizeY + ", status=no, resizable=no, scrollbars=no";
    
    window.open("ImprimirPedido.aspx", "Informacion", _params); 
}

function Oculta_O_Muestra(rb) 
{ 
    var divTarjetas = document.getElementById("ctl00_cph_divTarjetas");

    if(rb.value == "ContraReembolso")
    {
        if(rb.checked)
        {
            divTarjetas.style.display = "none";
        }
        else
        {
            divTarjetas.style.display = "block";
        }
    }
    else if(rb.value == "Tarjeta")
    {
        if(rb.checked)
        {
            divTarjetas.style.display = "block";
        }
        else
        {
            divTarjetas.style.display = "none";
        }
    }    
} 
function MuestraCodTarjeta()
{
    var ddlTipoTarjeta = document.getElementById("ctl00_cph_ddlTipoTarjeta");
    var divTipoTarjeta = document.getElementById("ctl00_cph_divTipoTarjeta");
   
    if(ddlTipoTarjeta.value == "American Express")
    {        
        divTipoTarjeta.style.display = "block";
    }
    else
    {
        divTipoTarjeta.style.display = "none";
    }
}

function urlAmericanExpress() { 
    var _size = 400;        
    var _sizeX = 275;        
    var _sizeY = 475;        
    var _top = (screen.height - _size)/2;
    var _left = (screen.width - _size)/2;
    var _params = "top=" + _top + ", left=" + _left + ", width=" + _sizeX +", height=" + _sizeY + ", status=no, resizable=no, scrollbars=no";
    
    window.open("american_express.htm", "Informacion", _params); 
} 

function urlComentarios() { 
    _size = 400;        
    _top = (screen.height - _size)/2;
    _left = (screen.width - _size)/2;
    hidden = open("comentarios.htm", "Condiciones","top=" + _top +",left=" + _left + ",width=" + _size +",height=" + _size + ",status=no,resizable=no,scrollbars=no"); 
} 

function urlProteccion() { 
    _size = 500;        
    _top = (screen.height - _size)/2;
    _left = (screen.width - _size)/2;
    hidden = open("proteccion.htm", "Proteccion","top=" + _top +",left=" + _left + ",width=" + _size +",height=" + _size + ",status=no,resizable=no,scrollbars=yes"); 
} 

function ClickButton(url) 
{
    var strContent = "ctl00_cph_";
    var hidSwfUrl = document.getElementById(strContent + "hidSwfUrl"); 
    var btnSwfButton = document.getElementById(strContent + "btnSwfButton"); 
    
    hidSwfUrl.value = url;
    btnSwfButton.click();
}

function CompruebaUsuario(tbName)
{
    var strContent = "ctl00_cph_";
    var txtBox = document.getElementById(strContent + tbName);    
    
    if(txtBox.value == "")
   { 
        return false;
    }
   else
   {
        MostrarCapa();
        return true;  
   }
}

function Incrementa(fila)
{
    var lblCantidad, lblPrecio, lblTotal, hidCantidad, hidFila;
    var pos; 

    //Fila
    pos = fila + 2;
    //Buscamos los controles
    lblCantidad = document.getElementById("ctl00_cph_grdCarrito_ctl0" + pos + "_lblCantidad"); 
    lblTotal = document.getElementById("ctl00_cph_grdCarrito_ctl0" + pos + "_lblTotal"); 
    lblPrecio = document.getElementById("ctl00_cph_grdCarrito_ctl0" + pos + "_lblPrecio"); 
    hidCantidad = document.getElementById("ctl00_cph_hidCantidad"); 
    hidFila = document.getElementById("ctl00_cph_hidFila"); 
   
    //Comprobamos la cantidad
    if((parseInt(lblCantidad.innerText) + 1) >= 101)
        lblCantidad.innerText = "100";
    else
        lblCantidad.innerText = parseInt(lblCantidad.innerText) + 1;      
          
    //Guardamos la modificación
    hidCantidad.value =  lblCantidad.innerText
    //Guardamos la fila 
    hidFila.value =  fila     
    //Calculo
    lblTotal.innerText = (parseFloat(lblPrecio.innerText) * parseFloat(lblCantidad.innerText)).toFixed(2) + " €";
    //Ponemos las comas 
    lblTotal.innerText =  lblTotal.innerText.replace('.', ',');    
   //Actualiza el carrito
   ActualizarCarrito(); 
}

function Decrementa(fila)
{
    var lblCantidad, lblPrecio, lblTotal, hidCantidad, hidFila;
    var pos; 

    //Fila
    pos = fila + 2;    
    //Buscamos los controles
    lblCantidad = document.getElementById("ctl00_cph_grdCarrito_ctl0" + pos + "_lblCantidad"); 
    lblTotal = document.getElementById("ctl00_cph_grdCarrito_ctl0" + pos + "_lblTotal"); 
    lblPrecio = document.getElementById("ctl00_cph_grdCarrito_ctl0" + pos + "_lblPrecio"); 
    hidCantidad = document.getElementById("ctl00_cph_hidCantidad"); 
    hidFila = document.getElementById("ctl00_cph_hidFila"); 
    
    //Comprobamos la cantidad
    if((parseInt(lblCantidad.innerText) - 1) <= 0)
        lblCantidad.innerText = "1";
    else
        lblCantidad.innerText = parseInt(lblCantidad.innerText) - 1;       
        
    //Guardamos la modificación
    hidCantidad.value =  lblCantidad.innerText
    //Guardamos la fila 
    hidFila.value =  fila    
    //Calculo
    lblTotal.innerText = (parseFloat(lblPrecio.innerText) * parseFloat(lblCantidad.innerText)).toFixed(2) + " €";
    //Ponemos las comas 
    lblTotal.innerText =  lblTotal.innerText.replace('.', ',');     
   //Actualiza el carrito
   ActualizarCarrito();
}

function ActualizarCarrito()
{
    var btnActualizar = document.getElementById("ctl00_cph_btnActualizar");
    btnActualizar.click();
}

function AbrirInfoGastosDeEnvio()
{
    var _size = 400;        
    var _sizeX = 475;        
    var _sizeY = 200;        
    var _top = (screen.height - _size)/2;
    var _left = (screen.width - _size)/2;
    var _params = "top=" + _top + ", left=" + _left + ", width=" + _sizeX +", height=" + _sizeY + ", status=no, resizable=no, scrollbars=no";
    
    window.open("InformacionGastosDeEnvio.htm", "Informacion", _params); 
}

function OnlyNumericCharacters()
{
    // Get the ASCII value of the key that the user entered
    var key = window.event.keyCode;
    // Verify if the key entered was a numeric character (0-9) or a decimal (.)
    if ( (key > 47 && key < 58) || key == 46 || key == 110 || key == 188 || key == 44)
        // If it was, then allow the entry to continue
        return;
    else
        // If it was not, then dispose the key and continue with entry
        window.event.returnValue = null; 
}

function ObtenerScroll(div)
{
    var strContent = "ctl00_ContentPlaceHolder1_";
    var hidScrollX = document.getElementById(strContent + "hidScrollX");    
    var hidScrollY = document.getElementById(strContent + "hidScrollY");    

    hidScrollX.value =  div.scrollLeft;
    hidScrollY.value =  div.scrollTop;
}

function PonerScroll(divName)
{
    var strContent = "ctl00_ContentPlaceHolder1_";
    var hidScrollX = document.getElementById(strContent + "hidScrollX");    
    var hidScrollY = document.getElementById(strContent + "hidScrollY");    
    var div = document.getElementById(strContent + divName);    
    
    if(div != null) 
    {
        div.scrollLeft = parseInt(hidScrollX.value); 
        div.scrollTop = parseInt(hidScrollY.value);   
    }
}

function SetTxtBuscar()
{
    if(document.getElementById('ctl00_cabecera1_txtBuscar').value == '')
    {
        document.getElementById('ctl00_cabecera1_txtBuscar').value = 'Buscar en...';
    }
}
function InitTxtBuscar()
{
    if(document.getElementById('ctl00_cabecera1_txtBuscar').value == 'Buscar en...')
    {
        document.getElementById('ctl00_cabecera1_txtBuscar').value = '';
    }
}

function CheckText()
{
    if(document.getElementById('ctl00_cabecera1_txtBuscar').value == 'Buscar en...')
    {
        return false;
    }
   else
   {
        MostrarCapa();
        return true;
   } 
}

function quitarScroll()
{
    document.body.style.overflow = "hidden";	     
} 

function ponerScroll()
{	        
    document.body.style.overflow = "";	       
} 

function EliminarComentario(indice, ref)
{
    var strMsg = "¿Desea eliminar este comentario con asunto '" + ref + "'?"
    
    return confirm(strMsg);
}
