function CambiarPwd(){
    bool = false; 
    if(document.getElementById('admpwd').value != document.getElementById('admpwd2').value) {
        bool = false;
        alert("Las contraseñas no coinciden");
        document.getElementById('admpwd2').focus();
    }
    else{
        bool = true;
    }        
    if(bool){
        document.getElementById('frmdatos').submit();
    }
}
function CambiarSubcategorias(id){
    location.href = "frmsubcategorias.php?idcategoria="+id;
}
function CambiarCategorias2(id){
    location.href = "frmproductos.php?idcategoria="+id;
}
function CambiarSubcategorias2(id){
    location.href = "frmproductos.php?idcategoria="+document.getElementById('idcategoria').value+"&idsubcategoria="+id;
}
function CambiarSubsubcategorias2(id){
    location.href = "frmproductos.php?idcategoria="+document.getElementById('idcategoria').value+"&idsubcategoria="+document.getElementById('idsubcategoria').value+"&idsubsubcategoria="+id;
}
function CambiarCategorias3(id){
    valor = '';
    if(document.getElementById('proid').value != ''){
        valor = "&id="+document.getElementById('proid').value;
    }
    location.href = "frmproductoseditar.php?idcategoria="+id+valor;
}
function CambiarSubcategorias3(id){
    valor = '';
    if(document.getElementById('proid').value != ''){
        valor = "&id="+document.getElementById('proid').value;
    }
    location.href = "frmproductoseditar.php?idcategoria="+document.getElementById('idcategoria').value+valor+"&idsubcategoria="+id;
}
function MM_effectBlind(targetElement, duration, from, to, toggle){
    Spry.Effect.DoBlind(targetElement, {duration: duration, from: from, to: to, toggle: toggle});
}

function OcultarDiv(opcion) {
    //div = document.getElementById(opcion);
    if(document.getElementById(opcion).style.display!='block'){
        document.getElementById(opcion).style.display = 'block';
    }else{
        document.getElementById(opcion).style.display = 'none';
    }
}



function MismosDatos(opcion){
    if(opcion=="borra"){
            document.getElementById('NombreF').value = "";
            document.getElementById('DireccionF').value = "";
            document.getElementById('CPF').value = "";
            document.getElementById('LocalidadF').value = "";
            document.getElementById('ProvinciaF').value = "";        
    }
    else{
        bool = false;
        if(document.getElementById('Nombre').value == "") {
            bool = false;
            alert("El nombre es obligatorio");
            document.getElementById('frmconfir').elements[8].checked = true;
            
            document.getElementById('Nombre').focus();
        }
        else{
            bool = true;
        }
        if(document.getElementById('Apellidos').value == "") {
            bool = false;
            alert("Los Apellidos son obligatorios");
            document.getElementById('frmconfir').elements[8].checked = true;
            
            document.getElementById('Apellidos').focus();
        }
        else{
            bool = true;
        }        
        if(bool){
            if(document.getElementById('Direccion').value == "") {
                bool = false;
                alert("La dirección es obligatoria");
                document.getElementById('frmconfir').elements[8].checked = true;
                 
                document.getElementById('Direccion').focus();
            }
            else{
                bool = true;
            }
        }
        if(bool){
            if(document.getElementById('CP').value == "") {
                bool = false;
                alert("El C.P. es obligatorio");
                document.getElementById('frmconfir').elements[8].checked = true;
                 
                document.getElementById('CP').focus();
            }
            else{
                bool = true;
            }
        }
        if(bool){
            if(document.getElementById('Localidad').value == "") {
                bool = false;
                alert("La localidad es obligatoria");
                document.getElementById('frmconfir').elements[8].checked = true;
                 
                document.getElementById('Localidad').focus();
            }
            else{
                bool = true;
            }
        }
        if(bool){
            if(document.getElementById('Provincia').value == "") {
                bool = false;
                alert("La provincia es obligatoria");
                document.getElementById('frmconfir').elements[8].checked = true;
                 
                document.getElementById('Provincia').focus();
            }
            else{
                bool = true;
            }
        }        
        if(bool){
            document.getElementById('NombreF').value = document.getElementById('Nombre').value;
            document.getElementById('ApellidosF').value = document.getElementById('Apellidos').value;                
            document.getElementById('DireccionF').value = document.getElementById('Direccion').value;
            document.getElementById('CPF').value = document.getElementById('CP').value;
            document.getElementById('LocalidadF').value = document.getElementById('Localidad').value;
            document.getElementById('ProvinciaF').value = document.getElementById('Provincia').value;
        }
    }
}

function EnviarMisDatos(){
    bool = false;
    if(document.getElementById('Nombre').value == "") {
        bool = false;
        alert("El nombre es obligatorio");
        document.getElementById('frmconfir').elements[8].checked = true;
        
        document.getElementById('Nombre').style.backgroundColor='#E0E9F6';
        document.getElementById('Nombre').focus();
        return;
    }
    else{
        bool = true;
    }
    
    if(document.getElementById('Apellidos').value == "") {
        bool = false;
        alert("Los Apellidos son obligatorios");
        document.getElementById('frmconfir').elements[8].checked = true;
        
        document.getElementById('Apellidos').style.backgroundColor='#E0E9F6';
        document.getElementById('Apellidos').focus();
        return;
    }
    else{
        bool = true;
    }    
    if(bool){
        if(document.getElementById('Direccion').value == "") {
            bool = false;
            alert("La dirección es obligatoria");
            document.getElementById('frmconfir').elements[8].checked = true;
            document.getElementById('Direccion').style.backgroundColor='#E0E9F6';
            document.getElementById('Direccion').focus();
            return;
        }
        else{
            bool = true;
        }
    }
    if(bool){
        if(document.getElementById('CP').value == "") {
            bool = false;
            alert("El C.P. es obligatorio");
            document.getElementById('frmconfir').elements[8].checked = true;
            document.getElementById('CP').style.backgroundColor='#E0E9F6'; 
            document.getElementById('CP').focus();
            return;
        }
        else{
            bool = true;
        }
    }
    if(bool){
        if(document.getElementById('Localidad').value == "") {
            bool = false;
            alert("La localidad es obligatoria");
            document.getElementById('frmconfir').elements[8].checked = true;
            document.getElementById('Localidad').style.backgroundColor='#E0E9F6'; 
            document.getElementById('Localidad').focus();
            return;
        }
        else{
            bool = true;
        }
    }
    if(bool){
        if(document.getElementById('Provincia').value == "") {
            bool = false;
            alert("La provincia es obligatoria");
            document.getElementById('frmconfir').elements[8].checked = true;
            document.getElementById('Provincia').style.backgroundColor='#E0E9F6';
            document.getElementById('Provincia').focus();
            return;
        }
        else{
            bool = true;
        }
    }
    if(bool){
        if(document.getElementById('NombreF').value == "") {
            bool = false;
            alert("El nombre es obligatorio"); 
            document.getElementById('NombreF').style.backgroundColor='#E0E9F6';
            document.getElementById('NombreF').focus();
            return;
        }
        else{
            bool = true;
        }
    }

    if(bool){
        if(document.getElementById('DireccionF').value == "") {
            bool = false;
            alert("La dirección es obligatoria");
            document.getElementById('DireccionF').style.backgroundColor='#E0E9F6';
            document.getElementById('DireccionF').focus();
            return;
        }
        else{
            bool = true;
        }
    }
    if(bool){
        if(document.getElementById('CPF').value == "") {
            bool = false;
            alert("El C.P. es obligatorio");
            document.getElementById('CPF').style.backgroundColor='#E0E9F6';
            document.getElementById('CPF').focus();
            return;
        }
        else{
            bool = true;
        }
    }
    if(bool){
        if(document.getElementById('LocalidadF').value == "") {
            bool = false;
            alert("La localidad es obligatoria");
            document.getElementById('LocalidadF').style.backgroundColor='#E0E9F6';
            document.getElementById('LocalidadF').focus();
            return;
        }
        else{
            bool = true;
        }
    }
    if(bool){
        if(document.getElementById('ProvinciaF').value == "") {
            bool = false;
            alert("La provincia es obligatoria");
            document.getElementById('ProvinciaF').style.backgroundColor='#E0E9F6';
            document.getElementById('ProvinciaF').focus();
            return;
        }
        else{
            bool = true;
        }
    }
    if(bool){
        if(document.getElementById('NifF').value == "") {
            bool = false;
            alert("El NIF es obligatorio");
            document.getElementById('NifF').style.backgroundColor='#E0E9F6';
            document.getElementById('NifF').focus();
            return;
        }
        else{
            bool = true;
        }
    }
    if(bool){
        if(document.getElementById('Movil').value == "") {
            bool = false;
            alert("El teléfono de contacto es obligatorio");
            document.getElementById('Movil').style.backgroundColor='#E0E9F6';
            document.getElementById('Movil').focus();
            return;
        }
        else{
            bool = true;
        }
    }
    if(bool){
        if(document.getElementById('email').value == "") {
            bool = false;
            alert("El email es obligatorio");
            document.getElementById('email').style.backgroundColor='#E0E9F6';
            document.getElementById('email').focus();
            return;
        }
        else{
            bool = true;
        }
    }
    if(bool){
        document.getElementById('frmconfir').submit();
    }  
}

function addValor(){
    valor = document.getElementById("colores").value;
    pos = 0;
    valores = new Array();
    tm = document.getElementById("coloresadd").options.length;
    
    try{
        if(valor != ""){                                                                      
            if(document.getElementById("colores").options.length > 0){
                document.getElementById("coloresadd").options[tm] = new Option(valor);
                document.getElementById("coloresadd").options[tm].value = valor;
                
                for(i = 0 ; i < document.getElementById("colores").options.length ; i++){ 
                    valores[i] = document.getElementById("colores").options[i].text;  
                }
                
                for(i = 0 ; i < valores.length ; i++){ 
                    if(valores[i] == valor){
                        valores.splice(i,1);
                    }                    
                }
                
                document.getElementById("colores").options.length -= 1;
                
                for(i = 0 ; i < valores.length ; i++){ 
                    document.getElementById("colores").options[i] = new Option(valores[i]);
                    document.getElementById("colores").options[i].value = valores[i];                    
                }
            }
            
            else{
                alert("El campo de colores ya está vacío");
            }
        }
        
        else{
            alert("Debes de seleccionar un elemento de la lista");    
        }
    }
    catch(e){
        alert(e);
    }
}

function EliminaValor(){
    valor = document.getElementById("coloresadd").value;
    pos = 0;
    valores = new Array();
    tm = document.getElementById("colores").options.length;
    
    try{
        if(valor != ""){
            if(document.getElementById("coloresadd").options.length > 0){
                document.getElementById("colores").options[tm] = new Option(valor);
                document.getElementById("colores").options[tm].value = valor;
                
                for(i = 0 ; i < document.getElementById("coloresadd").options.length ; i++){ 
                    valores[i] = document.getElementById("coloresadd").options[i].text;  
                }
                
                for(i = 0 ; i < valores.length ; i++){ 
                    if(valores[i] == valor){
                        valores.splice(i,1);
                    }                    
                }
                
                document.getElementById("coloresadd").options.length -= 1;
                
                for(i = 0 ; i < valores.length ; i++){ 
                    document.getElementById("coloresadd").options[i] = new Option(valores[i]); 
                    document.getElementById("coloresadd").options[i].value = valores[i];                    
                }
            }
            
            else{
                alert("El campo de colores ya está vacío");
            }
        }
        
        else{
            alert("Debes de seleccionar un elemento de la lista");    
        }
    }
    catch(e){
        alert(e);
    }

}

function addValorRelacion(){
    valor = document.getElementById("accesorios").value;
    pos = 0;
    valores = new Array();
    tm = document.getElementById("relacionados").options.length;
    
    try{
        if(valor != ""){                                                                      
            if(document.getElementById("accesorios").options.length > 0){
                document.getElementById("relacionados").options[tm] = new Option(valor);
                document.getElementById("relacionados").options[tm].value = valor;
                
                for(i = 0 ; i < document.getElementById("accesorios").options.length ; i++){ 
                    valores[i] = document.getElementById("accesorios").options[i].text;  
                }
                
                for(i = 0 ; i < valores.length ; i++){ 
                    if(valores[i] == valor){
                        valores.splice(i,1);
                    }                    
                }
                
                document.getElementById("accesorios").options.length -= 1;
                
                for(i = 0 ; i < valores.length ; i++){ 
                    document.getElementById("accesorios").options[i] = new Option(valores[i]);
                    document.getElementById("accesorios").options[i].value = valores[i];                    
                }
            }
            
            else{
                alert("El campo de colores ya está vacío");
            }
        }
        
        else{
            alert("Debes de seleccionar un elemento de la lista");    
        }
    }
    catch(e){
        alert(e);
    }
}

function EliminaValorRelacion(){
    valor = document.getElementById("relacionados").value;
    pos = 0;
    valores = new Array();
    tm = document.getElementById("accesorios").options.length;
    
    try{
        if(valor != ""){
            if(document.getElementById("relacionados").options.length > 0){
                document.getElementById("accesorios").options[tm] = new Option(valor);
                document.getElementById("accesorios").options[tm].value = valor;
                
                for(i = 0 ; i < document.getElementById("relacionados").options.length ; i++){ 
                    valores[i] = document.getElementById("relacionados").options[i].text;  
                }
                
                for(i = 0 ; i < valores.length ; i++){ 
                    if(valores[i] == valor){
                        valores.splice(i,1);
                    }                    
                }
                
                document.getElementById("relacionados").options.length -= 1;
                
                for(i = 0 ; i < valores.length ; i++){ 
                    document.getElementById("relacionados").options[i] = new Option(valores[i]); 
                    document.getElementById("relacionados").options[i].value = valores[i];                    
                }
            }
            
            else{
                alert("El campo de colores ya está vacío");
            }
        }
        
        else{
            alert("Debes de seleccionar un elemento de la lista");    
        }
    }
    catch(e){
        alert(e);
    }

}

function EnviarFrmProductos()
{
    if(document.getElementById("coloresadd").options.length > 0){
        for(i = 0 ; i < document.getElementById("coloresadd").options.length ; i++){ 
            document.frmdatos.txtcolores.value += document.getElementById("coloresadd").options[i].text;  
            document.frmdatos.txtcolores.value += ",";
        }
    }
    
    else{
       document.frmdatos.txtcolores.value = " "; 
    }
    
    save_in_textarea_all();
    document.frmdatos.submit();
}

function EnviarFrmRelacion()
{
    if(document.getElementById("relacionados").options.length > 0){
        for(i = 0 ; i < document.getElementById("relacionados").options.length ; i++){ 
            document.frmdatos.txtcolores.value += document.getElementById("relacionados").options[i].text;  
            document.frmdatos.txtcolores.value += ",";
        }
    }
    
    else{
       document.frmdatos.txtcolores.value = " "; 
    }
    
    document.frmdatos.submit();
}

function EnviarFrmComprar()
{
 /*   if(document.getElementById("relacionados").options.length != 0){        
        for(n = 0 ; n < document.getElementById("relacionados").options.length ; n++){
            if(n ==  document.getElementById("relacionados").options.length - 1){
                document.getElementById("compleseleccionados").value += document.getElementById("relacionados").options[n].text;                            
            }
            
            else if(document.getElementById("compleseleccionados").value.length >= 0){
               document.getElementById("compleseleccionados").value += document.getElementById("relacionados").options[n].text;
               document.getElementById("compleseleccionados").value += ";";  
            }
            
        }
    } */
    
    document.frmcomprar.submit();
}

function ValidarContacto()
{    
    
    if(document.frmcontacto.contacto.value == ""){
        alert("El nombre de contacto es obligatorio");
        document.frmcontacto.focus();
        return;
    }
    
    else if(document.frmcontacto.nombre.value == "Escriba su Nombre" || document.frmcontacto.nombre.value == ""){
        alert("El nombre es obligatorio");
        document.frmcontacto.nombre.focus();
        return;
    } 
    
    else if(document.frmcontacto.email.value == "Escriba su E-mail" || document.frmcontacto.email.value == ""){
        alert("El e-mail es obligatorio");
        document.frmcontacto.email.focus();
        return;
    }
    
    else if(document.frmcontacto.comentarios.value == "Escriba su Consulta" || document.frmcontacto.comentarios.value == ""){
        alert("La consulta es obligatoria");
        document.frmcontacto.comentarios.focus();
        return;
    }
    
    else if(!document.frmcontacto.politica.checked){
        alert("Debe aceptar las condiciones legales");
        document.frmcontacto.politica.focus();
        return;
    }
    
    
    document.frmcontacto.submit();   
        
}

function ValidarPostVenta()
{    
    
    if(document.frmpostventa.Nombre.value == "Escriba su nombre" || document.frmpostventa.Nombre.value == ""){
        alert("El nombre es obligatorio");
        document.frmpostventa.Nombre.value = "Escriba su nombre";
        document.frmpostventa.Nombre.focus();
        return;
    }
    
    if(document.frmpostventa.Telefono.value == "Escriba su telefono" || document.frmpostventa.Telefono.value == ""){
        alert("El teléfono es obligatorio");
        document.frmpostventa.Telefono.value = "Escriba su telefono";
        document.frmpostventa.Telefono.focus();
        return;
    } 
    
    if(document.frmpostventa.Pedido.value == "Escriba su número de pedido" || document.frmpostventa.Pedido.value == ""){
        alert("El número de pedido es obligatorio");
        document.frmpostventa.Pedido.value = "Escriba su número de pedido";
        document.frmpostventa.Pedido.focus();
        return;
    }
    
    if(document.frmpostventa.Email.value == "Escriba su email" || document.frmpostventa.Email.value == ""){
        alert("El email es obligatorio");
        document.frmpostventa.Email.value = "Escriba su email";
        document.frmpostventa.Email.focus();
        return;
    }
    
    if(document.frmpostventa.Observaciones.value == "Escriba sus observaciones" || document.frmpostventa.Observaciones.value == ""){
        alert("Las observaciones son obligatorias");
        document.frmpostventa.Observaciones.value = "Escriba sus observaciones";
        document.frmpostventa.Observaciones.focus();
        return;
    }    
    
    if(!document.frmpostventa.politica.checked){
        alert("Debe aceptar las condiciones legales");
        document.frmpostventa.politica.focus();
        return;
    }
    
    
    document.frmpostventa.submit();   
        
}

function ValidarFrmGrandesCompras()
{
    if(document.frmgrandescompras.Nombre.value == "Escriba su Nombre" || document.frmgrandescompras.Nombre.value == ""){
        alert("El nombre es obligatorio");
        document.frmgrandescompras.Nombre.value = "Escriba su Nombre";
        document.frmgrandescompras.Nombre.focus();
        return;
    }
    
    if(document.frmgrandescompras.Telefono.value == "Escriba su telefono" || document.frmgrandescompras.Telefono.value == ""){
        alert("El teléfono es obligatorio");
        document.frmgrandescompras.Telefono.value = "Escriba su telefono";
        document.frmgrandescompras.Telefono.focus();
        return;
    } 
    
    if(document.frmgrandescompras.Observaciones.value == "Escriba sus observaciones" || document.frmgrandescompras.Observaciones.value == ""){
        alert("El campo observaciones es obligatorio");
        document.frmgrandescompras.Observaciones.value = "Escriba sus observaciones";
        document.frmgrandescompras.Observaciones.focus();
        return;
    }    
    
    if(!document.frmgrandescompras.politica.checked){
        alert("Debe aceptar las condiciones legales");
        document.frmgrandescompras.politica.focus();
        return;
    }
    
    
    document.frmgrandescompras.submit();    
        
}
