
// --------------------------------------------------------------------------------
// --- Función que gestiona el tamaño de la zona central de la web (con y sin
// --- avatar)
// --------------------------------------------------------------------------------

function MostrarZonaCentral()
{
	/* NO SE USA ********************
	if (Avatar == "S")
	{
		document.getElementById("TdZonaCentralSinAvatar").style.width = 0;
		document.getElementById("TdZonaCentralSinAvatar").style.display = "none";

		document.getElementById("TdZonaCentralConAvatar").style.width = 598;
		document.getElementById("TdZonaCentralConAvatar").style.display = "block";
	}
	else
	{
		document.getElementById("TdZonaCentralConAvatar").style.width = 0;
		document.getElementById("TdZonaCentralConAvatar").style.display = "none";

		document.getElementById("TdZonaCentralSinAvatar").style.width = 588;
		document.getElementById("TdZonaCentralSinAvatar").style.display = "block";
	}
	*/
}

// --------------------------------------------------------------------------------
// Función que abre una nueva ventana (deprecated)
// --------------------------------------------------------------------------------

function AbrirVentana(Url, Seccion)
{
	if (Seccion == "Documentos")
	{
		var ancho = screen.width - 90;
		var alto = screen.height * 73 / 100;

		window.open(Url, "", "width="+ancho+", height="+alto+", left=40, top=40, location=yes, menubar=yes, resizable=yes, scrollbars=no, status=yes, toolbar=yes");
	}
}

function AbrirDocumento(Ruta)
{
	window.open(Ruta, "", "location=no, menubar=yes, resizable=yes, scrollbars=no, status=yes, toolbar=yes");
}

function AbrirVentanaDocumentos(Ruta)
{
	window.open(Ruta, "", "width=480, height=480, top=60, left=60, resizable=no");
}

function AbrirVentanaDocumentosAuto(Ruta)
{
	window.open(Ruta, "", "width=540, height=480, top=60, left=60, resizable=no");
}

// --------------------------------------------------------------------------------
// --- Función que deshabilita el combo especificado y pone el texto "Cargando
// --- datos..." mientras éstos se cargan
// --------------------------------------------------------------------------------

function CargandoCombo(Combo)
{
	document.getElementById(Combo).length = 0;
	document.getElementById(Combo).options[0] = new Option("Cargando datos...", "");
	document.getElementById(Combo).disabled = true;
}

// --------------------------------------------------------------------------------
// --- Función que vacía y/o deshabilita el combo especificado según los
// --- parámetros especificados y luego pone en la primera posición el texto
// --- "-- Seleccione..."
// --------------------------------------------------------------------------------

function InicializarCombo(Combo, Deshabilitar, Vaciar)
{
	if (Vaciar == "S") document.getElementById(Combo).length = 1;

	switch (Combo)
	{
		case "TipoVehiculo": CmbText = "-- Seleccione un tipo --"; break;
		case "Uso": CmbText = "-- Seleccione un uso --"; break;
		case "Marca": CmbText = "-- Seleccione una marca --"; break;
		case "Modelo": CmbText = "-- Seleccione un modelo --"; break;
		case "Version": CmbText = "-- Seleccione una versión --"; break;
		default: CmbText = ""; break;
	}

	document.getElementById(Combo).options[0].text = CmbText;
	document.getElementById(Combo).options[0].value = "";

	document.getElementById(Combo).disabled = (Deshabilitar == "S" ? true : false);
}

// --------------------------------------------------------------------------------
// --- Función que controla si, al cambiar el estado de la opción tracción 4x4,
// --- el tipo de vehículo es 150 (todo terreno) porque, en ese caso, la opción
// --- debe estar siempre a sí
// --------------------------------------------------------------------------------

function GestionarTraccion4x4(Estado)
{
	if (Estado == "N" && document.FVehiculo.TipoVehiculo.value == "150")
		document.FVehiculo.CuatroXCuatro[0].checked = true;
}

function ObtenerPrefijoArchivos(TipoConcesionario)
{
	switch (TipoConcesionario)
	{
		case "MERCEDES": Prefijo = "mb_"; break;
		case "SMART": Prefijo = "sm_"; break;
		case "CHRYSLER": Prefijo = "cj_"; break;
		default: Prefijo = ""; break;	
	}

	return Prefijo;
}

// --------------------------------------------------------------------------------
// --- Función que procesa el tipo de vehículo. Recibe el ramo (GM, EG o AUTO) y
// --- el tipo de concesionario (MERCEDES, SMART o CHRYSLER) como parámetros
// --------------------------------------------------------------------------------

function SubmitTipoVehiculo(Ramo, TipoConcesionario)
{
	Prefijo = ObtenerPrefijoArchivos(TipoConcesionario);

	if (Ramo == "GM")
	{
		document.FVehiculo.Combustible.disabled = true;
		document.FVehiculo.Cilindrada.value = "";

		// Si Tipo de vehiculo = 150, entonces Tracción 4x4 = Sí
		if (document.FVehiculo.TipoVehiculo.value == "150")
			document.FVehiculo.CuatroXCuatro[0].checked = true;
		else
			document.FVehiculo.CuatroXCuatro[1].checked = true;

		CargandoCombo("Marca");
		CargandoCombo("Modelo");
		CargandoCombo("Version");

		document.FVehiculo.action = Prefijo + "proceso.asp?Motivo=tipovehiculo";
		document.FVehiculo.target = "auxiliar";
		document.FVehiculo.submit();
	}
}

// --------------------------------------------------------------------------------
// --- Función que procesa la marca. Recibe el ramo (GM, EG o AUTO) y el tipo de
// --- concesionario (MERCEDES, SMARTo CHRYSLER) como parámetros
// --------------------------------------------------------------------------------

function SubmitMarca(Ramo, TipoConcesionario)
{
	Prefijo = ObtenerPrefijoArchivos(TipoConcesionario);

	if (Ramo == "GM")
	{
		document.FVehiculo.Combustible.disabled = true;
		document.FVehiculo.Cilindrada.value = "";

		if (document.FVehiculo.Marca.selectedIndex == 0)
		{
			InicializarCombo("Modelo");
			InicializarCombo("Version");
		}
		else
		{
			CargandoCombo("Modelo");
			CargandoCombo("Version");

			document.FVehiculo.action = Prefijo + "proceso.asp?Motivo=marca";
			document.FVehiculo.target = "auxiliar";
			document.FVehiculo.submit();
		}
	}
}

// --------------------------------------------------------------------------------
// --- Función que procesa el modelo. Recibe el ramo (GM, EG o AUTO) y el tipo de
// --- concesionario (MERCEDES, SMART o CHRYSLER) como parámetros
// --------------------------------------------------------------------------------

function SubmitModelo(Ramo, TipoConcesionario)
{
	Prefijo = ObtenerPrefijoArchivos(TipoConcesionario);

	if (Ramo == "GM")
	{
		document.FVehiculo.Combustible.disabled = false;
		document.FVehiculo.Cilindrada.value = "";

		if (document.FVehiculo.Modelo.selectedIndex == 0)
		{
			InicializarCombo("Version");
		}
		else
		{
			CargandoCombo("Version");

			document.FVehiculo.action = Prefijo + "proceso.asp?Motivo=modelo";
			document.FVehiculo.target = "auxiliar";
			document.FVehiculo.submit();
		}
	}
}

// --------------------------------------------------------------------------------
// --- Función que procesa el combustible. Recibe el ramo (GM, EG o AUTO) y el
// --- tipo de concesionario (MERCEDES, SMART o CHRYSLER) como parámetros
// --------------------------------------------------------------------------------

function SubmitCombustible(Ramo, TipoConcesionario)
{
	Prefijo = ObtenerPrefijoArchivos(TipoConcesionario);

	if (Ramo == "GM")
	{
		document.FVehiculo.Cilindrada.value = "";

		CargandoCombo("Version");

		document.FVehiculo.action = Prefijo + "proceso.asp?Motivo=combustible";
		document.FVehiculo.target = "auxiliar";
		document.FVehiculo.submit();
	}
}

// --------------------------------------------------------------------------------
// --- Función que procesa la versión. Recibe el ramo (GM, EG o AUTO) como
// --- parámetro
// --------------------------------------------------------------------------------

function SubmitVersion(Ramo)
{
	if (Ramo == "GM")
	{
		if (document.FVehiculo.Version.selectedIndex == 0)
			document.FVehiculo.Cilindrada.value = "";
		else
			document.FVehiculo.Cilindrada.value = document.FVehiculo.Version.options[document.FVehiculo.Version.selectedIndex].cilindrada;
	}
}

// --------------------------------------------------------------------------------
// --- Función que envía los datos de la parte del vehículo al formulario de
// --- datos ocultos. Recibe el ramo (GM, EG o AUTO) como parámetro
// --------------------------------------------------------------------------------

function GuardarDatosVehiculo(Ramo)
{
	if (Ramo == "GM")
	{
		document.FDatosOcultos.CatVehiculo.value			= "1";
		document.FDatosOcultos.CodTipoVehiculo.value		= document.FVehiculo.TipoVehiculo.value;
		document.FDatosOcultos.DesTipoVehiculo.value		= document.FVehiculo.TipoVehiculo.options[document.FVehiculo.TipoVehiculo.selectedIndex].text;

		document.FDatosOcultos.Marca.value					= document.FVehiculo.Marca.value;
		document.FDatosOcultos.Modelo.value					= document.FVehiculo.Modelo.value;
		document.FDatosOcultos.Version.value				= document.FVehiculo.Version.options[document.FVehiculo.Version.selectedIndex].text;
		document.FDatosOcultos.CodVehiculo.value			= document.FVehiculo.Version.value;
		document.FDatosOcultos.Cilindrada.value				= document.FVehiculo.Cilindrada.value;
		document.FDatosOcultos.CuatroXCuatro.value			= (document.FVehiculo.CuatroXCuatro[0].checked == true ? "S" : "N");

		document.FDatosOcultos.VersionCilindrada.value		= document.FVehiculo.Version.options[document.FVehiculo.Version.selectedIndex].cilindrada;
		document.FDatosOcultos.VersionPotencia.value		= document.FVehiculo.Version.options[document.FVehiculo.Version.selectedIndex].potencia;
		document.FDatosOcultos.VersionCombustible.value		= document.FVehiculo.Version.options[document.FVehiculo.Version.selectedIndex].combustible;
		document.FDatosOcultos.VersionPuertas.value			= document.FVehiculo.Version.options[document.FVehiculo.Version.selectedIndex].puertas;
		document.FDatosOcultos.VersionNPlazas.value			= document.FVehiculo.Version.options[document.FVehiculo.Version.selectedIndex].n_plazas;
	}
}


// ****************************************
// Funciones para mostrar ayudas emergentes
//
function MostrarAyudaContextual(Tit, Msg, obj)
{
    var px = 0;
    var py = 0;
    var e = window.event;

    if (e.pageX || e.pageY)
    {
	    px = e.pageX;
	    py = e.pageY;
    }
    else if (e.clientX || e.clientY) 
    {
	    px = e.clientX + document.body.scrollLeft
				       + document.documentElement.scrollLeft;
	    py = e.clientY + document.body.scrollTop
				       + document.documentElement.scrollTop;
    }
    if (isNaN(py))
        py = (findPosY(obj))+10;
           if (isNaN(px))
              px = (((findPosX(obj)+ancho)<10)?10:findPosX(obj));
              px -= 10;
              py -= 10; 

            var ancho = document.getElementById('divAyudaContextual').style.width.split("px").join("");

            if ((parseInt(px,10) + parseInt(ancho,10)) > 600 )
                px = parseInt(px,10) - parseInt(ancho,10) - 10;

			document.getElementById('divTituloAyudaContextual').innerHTML = Tit;  
			document.getElementById('divTextoAyudaContextual').innerHTML = Msg;  
			document.getElementById('divAyudaContextual').style.display = 'block';
			document.getElementById('divAyudaContextual').style.left = (px) + "px";
			document.getElementById('divAyudaContextual').style.top = (py) + "px";

            var alto = document.getElementById('divAyudaContextual').offsetHeight;

    if ((parseInt(py,10) - parseInt(alto,10)) > 10 )
    {
	    py = (parseInt(py,10) - parseInt(alto,10) - 10);
	    document.getElementById('divAyudaContextual').style.top = (py) + "px";
    }

}

function OcultarAyudaContextual()
{
    document.getElementById('divAyudaContextual').style.display = 'none';
}        

function findPosX(obj)
{
    var curleft = 0;
    if(obj.offsetParent)

	    while(1) 
	    {
	      curleft += obj.offsetLeft;

	      if(!obj.offsetParent)
		       break;
	      obj = obj.offsetParent;
	    }
    else if(obj.x)
           curleft += obj.x;
           return curleft;
}

function findPosY(obj)
{
    var curtop = 0;

    if(obj.offsetParent)
	    while(1)
	    {
	      curtop += obj.offsetTop;

	      if(!obj.offsetParent)

			       break;
	      obj = obj.offsetParent;
	    }
    else if(obj.y)
		    curtop += obj.y;
    return curtop;
}    

//
// Funciones para leer las ayudas

// Esta función sirve para bloquear la pantalla de fondo y aparezca una ventana de ayuda
    function abrirVentanaAyuda(msg)
    {
        var h = 0; // height
        var w = 0; // width
        if( window.innerHeight ) {//no es IE
            h = window.innerHeight;
            w = window.innerWidth;
        } 
        else { // if( document.body && document.body.clientHeight ) {//IE 4 o superior
            h = document.body.clientHeight;
            w = document.body.clientWidth;
        }
		
        var msgAyuda = msg;
	
		if (msgAyuda!="")
		{
	        document.getElementById("divTextoMsgAyuda").innerText = msgAyuda;

			cb = document.getElementById("capaBloqueo");
		    ib = document.getElementById("iframeBloqueo");
			cm = document.getElementById("capaMensaje");
			
			cb.style.filter="alpha(opacity=25)"; // Opacidad para IE
			cb.style.opacity="25.00"; // Ocapacidad para Netscape
			ib.style.filter="alpha(opacity=25)"; // Opacidad para IE
			ib.style.opacity="25.00"; // Ocapacidad para Netscape

			cb.style.width=w+"px";
			cb.style.height=h+"px";
			ib.style.width=w+"px";
			ib.style.height=h+"px";

			cb.style.display = "block";
	        ib.style.display = "block";
			cm.style.display = "block";
		}
		else
		{
			cerrarVentanaAyuda();
		}
    }
    
    // Esta función sirve para bloquear la pantalla de fondo y cerrar la ventana de ayuda
    function cerrarVentanaAyuda()
    {
        cb = document.getElementById("capaBloqueo");
        cm = document.getElementById("capaMensaje");
	    ib = document.getElementById("iframeBloqueo");

        cb.style.display = "none";
        cm.style.display = "none";        
        ib.style.display = "none";        
    }
// Esta función sirve para bloquear la pantalla de fondo y aparezca una ventana de ayuda

// Esta función sirve para bloquear la pantalla de fondo y aparezca una ventana de proceso
    function abrirVentanaProceso(msg)
    {
        var h = 0; // height
        var w = 0; // width
        if( window.innerHeight ) {//no es IE
            h = window.innerHeight;
            w = window.innerWidth;
        } 
        else { // if( document.body && document.body.clientHeight ) {//IE 4 o superior
            h = document.body.clientHeight;
            w = document.body.clientWidth;
        }
		
        var msgProceso = msg;
	
		if (msgProceso!="")
		{
	        document.getElementById("divTextoMsgProceso").innerText = msgProceso;

			cb = document.getElementById("capaBloqueo");
		    ib = document.getElementById("iframeBloqueo");
			cm = document.getElementById("capaProceso");
			
			cb.style.filter="alpha(opacity=25)"; // Opacidad para IE
			cb.style.opacity="25.00"; // Ocapacidad para Netscape
			ib.style.filter="alpha(opacity=25)"; // Opacidad para IE
			ib.style.opacity="25.00"; // Ocapacidad para Netscape

			cb.style.width=w+"px";
			cb.style.height=h+"px";
			ib.style.width=w+"px";
			ib.style.height=h+"px";

			cb.style.display = "block";
	        ib.style.display = "block";
			cm.style.display = "block";
		}
		else
		{
			cerrarVentanaProceso();
		}
    }
    
    // Esta función sirve para bloquear la pantalla de fondo y cerrar la ventana de proceso
    function cerrarVentanaProceso()
    {
        cb = document.getElementById("capaBloqueo");
        cm = document.getElementById("capaProceso");
	    ib = document.getElementById("iframeBloqueo");

        cb.style.display = "none";
        cm.style.display = "none";        
        ib.style.display = "none";        
    }
// Esta función sirve para bloquear la pantalla de fondo y aparezca una ventana de proceso


