﻿// Archivo JScript

    // Cambiar color de fondo de las celdas del menu
    function overMenu(td){td.style.color='#FE6001';} 
    function outMenu(td){td.style.color='#252F41';} 
    
    // ************************************************************
    // Validaciones generales
    //     
    var nav4 = window.Event ? true : false;
    
    function soloNumeros(evt)
    {
        // Espacio = 8, Enter = 13, '0' = 48, '9' = 57
        var key = nav4 ? evt.which : evt.keyCode;
        return (key <= 13 || (key >= 48 && key <= 57));
    }
    
    
    
	// ***************************************************************************
	// Validar página contactar
	//
	function validarPaginaContactar()
	{
	    var valido = true;
	    var msg = "";
	    var campo = "";
	    
	    
        with ( document.frmContactar )
        {
            // Empresa
            if ( valido )
            {
                campo = "txtEmpresa";
                valido = txtObligatorio(txtEmpresa);
                if ( !valido )
                    msg = "Por favor, indique el nombre de su empresa.";
            }
            
            // Nombre
            if ( valido )
            {
                campo = "txtNombre";
                valido = txtObligatorio(txtNombre);
                if ( !valido )
                    msg = "Por favor, indique un nombre de contacto.";
            }
            
            // Email
            if ( valido )
            {
                campo = "txtEmail";
                valido = txtObligatorio(txtEmail);
                if ( !valido )
                    msg = "Por favor, indique un correo de contacto.";
            }
            
            // Telefono
            if ( valido )
            {
                campo = "txtTelefono";
                valido = txtObligatorio(txtTelefono);
                if ( !valido )
                    msg = "Por favor, indique un teléfono de contacto.";
            }
            
            // Consulta
            if ( valido )
            {
                campo = "txtConsulta";
                valido = txtObligatorio(txtConsulta);
                if ( !valido )
                    msg = "Por favor, indique su consulta.";
            }
            
	    }
	    // Final de with( document.frmContactar )
	    // -------------------------------------------
        
        // Quitar    
        // Para hacer pruebas
	    // valido = true;    
        // Quitar    

	    if (!valido)
	    {
	        alert(msg);
	        document.getElementById(campo).focus();
        }
        
	    return valido;
	}
	//
	// Fin Validar página contactar
	// ***************************************************************************
	
    
    
    
    
    //
    // Valida si un ddl tiene un valor distinto de ?,
    // esto indica que se ha seleccionado un valor
    //
    function ddlObligatorio ( ddl )
    {
        var valido = true;
        var valor = ddl.value;
        if ( valor == '' || valor == '?' )
        {
            ddl.style.background = '#FFE4D5';
            valido = false;   
        }
        else
            ddl.style.background = 'white';

        return valido;        
    }
	
    //
    // Valida si un txt tiene un valor con longitud mínima,
    // Un valor de 0 en len indica cualquier longitud
    //
    function txtObligatorio ( txt, len )
    {
        var valido = true;
        var valor = txt.value.length;
        if ( valor == 0 || valor < len )
        {
            txt.style.background = '#FFE4D5';
            valido = false;   
        }
        else
            txt.style.background = 'white';

        return valido;        
    }
    
    
    // 
    // IMAGENES
    //
    var xg = 450;
    var yg = 339;
    var xp = 200;
    var yp = 151;
    var ival, imgname, total, steps, maxx, maxy, currentx, currenty, dx, dy;
    // function zoomImg(imgname, total, steps, maxx, maxy)	
    function zoomImg(imgname, total, steps)	
    {
        // convert the total from seconds to miliseconds
        total = total * 1000;
        objref = eval("document.getElementById('"+imgname+"')");
        currentx = objref.width;
        currenty = objref.height;
        
        if ( currentx > xp )
        {
            maxx = xp;
            maxy = yp;
        }
        else
        {
            maxx = xg;
            maxy = yg;
        }
        
        
        // alert("currentx::"+currentx+"  currenty::"+currenty);
        
        // work out how much we need to increase the image by each step
        // devide image sizes by number of steps to get the amount we need to change each step
        stepx = maxx / steps;
        stepy = maxy / steps;
        // devide the total time (in ms) by the number of steps to get the interval time
        inttime = total / steps;
        // set the interval to increase the size of the image by the required pixels 
        functionRef = "resizeImg('"+imgname+"', "+stepx+", "+stepy+", "+maxx+", "+maxy+")";
        ival = setInterval(functionRef, inttime);
    }
    
    function resizeImg(imgname, dx, dy, maxx, maxy) 
    {
        objref = eval("document.getElementById('"+imgname+"')");
        currentx = objref.width;
        currenty = objref.height;
        if ((currentx<maxx-dx) && (currenty<maxy-dy)) 
        {
            objref.height = currenty + dy;
            objref.width = currentx + dx;
        }
        else 
        {
            clearInterval(ival);
            objref.height = maxy;
            objref.width = maxx;
        }
    }
	
    function NavegarPost( url )
    {
        var homeUrl = "";
        if ( document.getElementById('strHomeUrl').value != null )
            homeUrl = document.getElementById('strHomeUrl').value+"/";
        
        document.forms[0].action = homeUrl + url;
        document.forms[0].target = "";
        document.forms[0].method = "POST";
        document.forms[0].submit();
    }

    /* Abre una ventana para ver una demo */
    function AbrirVentanaDemo( url )
    {
        // window.open(url,"hola","width=800,height=300,scrollbars=yes");
        // window.open(url,"hola","width=900,height=700,toolbar=YES,menubar=YES");
        window.open(url,"win","width=940,height=680");
    }

    function AbrirVentanaDemoSima( url )
    {
        // window.open(url,"hola","width=800,height=300,scrollbars=yes");
        // window.open(url,"hola","width=900,height=700,toolbar=YES,menubar=YES");
        window.open(url,"win","width=940,height=550");
    }

    // Muestra una capa
    function MostrarCapa( capa )
    {
        document.getElementById(capa).style.display = 'block';
    }

    // Muestra u Oculta una capa
    function OcultarCapa( capa )
    {
        document.getElementById(capa).style.display = 'none';
    }


