//a mostrar al pulsar sobre los enlaces de los apartados sin desarrollar
function apartado_pendiente()
{
  alert ('\nEste servicio sera activado en breve.\n\n Disculpe las Molestias.\n');
}


/* = codigo para el manejo del menu principal            =*/
/* =======================================================*/

var empezar = false
var anclas = new Array ("ancla1","ancla2","ancla3","ancla4","ancla5","ancla6","ancla6")
var capas = new Array("","e2","e3","e4","","e6","e7")
var retardo 
var ocultar

function muestra(capa){
	xShow(capa);
}

function oculta(capa){
	xHide(capa);
}

function posiciona (){

	for (i=0;i<capas.length;i++){

		//posx= xOffsetLeft(anclas[i])
		posy= xOffsetTop (anclas[i])

		//alert (anclas[i]+"("+posx+","+posy+") <--> "+capas[i])

		xMoveTo(capas[i],0,posy+20)
	}

}


window.onresize = function() {
	posiciona()
}

function muestra_coloca(capa){
 if (empezar){
	for (i=0;i<capas.length;i++){
		if (capas[i] != capa) xHide(capas[i])
	}
	clearTimeout(retardo)
	xShow(capa)
 }
}

function oculta_retarda(capa){
 if (empezar){
	ocultar =capa
	clearTimeout(retardo)
	retardo = setTimeout("xHide('" + ocultar + "')",1000)
 }
}

function muestra_retarda(ind){
 if (empezar){
	clearTimeout(retardo)
 }
}

/* a llamar en el onload de "todas las paginas" body de 'index.php'*/
function init_menu() {
	posiciona()
	empezar = true
}



/* = abre una pagina dentro de una ventana de pop-up =*/
/* ===================================================*/


function abre_popup(pag_fuente, titulo, formato)
{
  //alert (pag_fuente);
  
	id_ventana = window.open(pag_fuente, "" /*titulo*/, formato);
  id_ventana.focus();
 
}



/* = codigo para el manejo de la galeria. javascript/DOM =*/
/* =======================================================*/

var fotos = new Array();
var img_p = "thumbnail";         // this is universal for the page
var img_vacia = "img/blank.gif"; // this is universal for the page
var img_g = "bigimage";          // this is universal for the page



// object constructor
function csnPhotoNavObject(csnPhoto) {
	// define object's properties
	this.photo = csnPhoto;

	// attach object's methods
	this.handleMouseOver = csnPhotoNavObjectShowThumb;
	this.handleMouseOut = csnPhotoNavObjectHideThumb;
	this.handleClick = csnPhotoNavObjectHandleClick;
}

// define object's methods

function csnPhotoNavObjectShowThumb() {
	// simply hand off this off to the photo object
	this.photo.showThumb();
	
	//=== (muestra recuadro del thumb)
	document.getElementById('thumb').style.visibility="visible";
}

function csnPhotoNavObjectHideThumb() {
	// simply hand off this off to the photo object
	this.photo.hideThumb();
	
	//=== (oculta recuadro del thumb)
	document.getElementById('thumb').style.visibility="hidden"; 
}

function  csnPhotoNavObjectHandleClick() {
	// our other events were a bit simpler, here we want to return false in addition to showing the full photo
	this.photo.showFull(); // first hand the display of the image off
	return false; // then return false
}





// object constructor
function csnPhotoObject(thumbID,thumbOffURI,thumbOnURI,fullID,fullURI) {
	// define object's properties
	this.thumbDOMRef = document.getElementById(thumbID);
	this.fullDOMRef = document.getElementById(fullID);
	this.thumbOffImg = new csnSmartImageObject(thumbOffURI,true);
	this.thumbOnImg = new csnSmartImageObject(thumbOnURI,true);
	// we don't want to load the full image until its needed
	this.fullImg = new csnSmartImageObject(fullURI,false); 
	
	// attach object's methods
	this.showThumb = csnPhotoObjectShowThumb;
	this.hideThumb = csnPhotoObjectHideThumb;
	this.showFull = csnPhotoObjectShowFull;
	
}

// define object's methods
function csnPhotoObjectShowThumb() { this.thumbDOMRef.src = this.thumbOnImg.getImage(); }
function csnPhotoObjectHideThumb() { this.thumbDOMRef.src = this.thumbOffImg.getImage(); }
function csnPhotoObjectShowFull() { this.fullDOMRef.src = this.fullImg.getImage(); }





// object constructor
function csnSmartImageObject(imgURI,preload) {
	// define local properties
	this.URI = imgURI;
	this.imageobj = null; // we don't need this image until we are ready to load it
	
	// attach object's methods
	this.load = csnSmartImageObjectLoad; // this fuction will force the loading of the image
	this.getImage = csnSmartImageObjectGetImage; // this function will retireve the source of the image from this object for use by other javscript objects
	
	// complete constuctor
	if (preload) { // if preload is true we want to load the image up right away
		this.load();
	}
}

// define object's methods
function csnSmartImageObjectLoad() {
	this.imageobj = new Image(); // create the image object
	this.imageobj.src = this.URI;
}

function csnSmartImageObjectGetImage() {
	if (this.imageobj) { // if we already have it, send the src along
		return this.imageobj.src;
	} else { // if not send the URI to the source back, process a concurrent load here
		/* note, it may be better form to load() and then return the full
			source when its done loading, but this is a much easier way to
			code it and works because the image.src is "overloaded" and can
			handle either case */
		this.load();
		return this.URI;
	}
}



/* = codigo para el manejo de las solapas (vehiculo) javascript =*/
/* ==============================================================*/


/*
   Variable GLOBAL a inicializar en el evento onLoad de la pagina
   Para que funciones correctamente
*/
var totalSolapas;


/*
   Para inicializar el numero total de capas a manejar en la página
   (evento onLoad del tag body) despues de definir la estructura de 
   capas necesaria: "menui0"(estilo visto) sin enlace , "menui1"
   (estilo oculto) con enlace, y "cajai" contenido de la solapa i-esima
*/
function init_solapas(nroSolapas) 
{
   totalSolapas=nroSolapas;
	 
	 mostrar_solapa(1); //Por defecto se muestra la primera
}


 
function mostrar_solapa(nSolapa)
{

    for (i=1; i <= totalSolapas; i++)
	{
		if (i != nSolapa)
		  show('menu'+i+'1'); //Muestra la i-esima solapa con enlace, i1
		else
		  hide('menu'+i+'1'); // Oculta la solapa 1 con enlace, i1  (SELECCIONADA)
		  
		if (i != nSolapa)
		  hide('menu'+i+'0'); // Oculta la solapa i sin enlace, i0
		else
		  show('menu'+i+'0'); // Muestra la solapa 1 sin enlace, i0 (SELECCIONADA)
		  
		if (i != nSolapa)
		  hide('caja'+i) // Oculta las cajas no seleccionadas
		else
		  show('caja'+i) // Muestra la caja (SELECCIONADA)		  
		
	}
		
}


/* = para validar campos del formulario de "contacto" =*/
/* ====================================================*/

function validar_contacto() {

	var sintaxisEmail = new RegExp ("^[a-z0-9_.-]+@{1}[a-z0-9_.-]+[\.]{1}[a-z0-9_.-]+$","i");
  
 	if (document.form.nombre.value  == '') {
		alert("Por favor, introduzca su nombre")
		document.form.nombre.focus()
		return false
	}
	
	if ((document.form.email.value == '')||(document.form.email.value.search(sintaxisEmail) == -1)) {
		alert("Por favor introduzca su dirección de email de manera correcta")
		document.form.email.focus()
		return false
	}
	
 	if (document.form.texto.value  == '') {
		alert("Por favor, introduzca su comentario")
		document.form.texto.focus()
		return false
	}
		
	return true
}//End validar_contacto




/* = para validar campos de email "recordar_contraseña" =*/
/* ======================================================*/

function validar_email() {

	var sintaxisEmail = new RegExp ("^[a-z0-9_.-]+@{1}[a-z0-9_.-]+[\.]{1}[a-z0-9_.-]+$","i");
  
	
	if ((document.form.email.value == '')||(document.form.email.value.search(sintaxisEmail) == -1)) {
	
		alert("Por favor introduzca su dirección de email de manera correcta");
	
		document.form.email.focus();
	
		return false;
	}
		
	return true;
	
}//End validar_email



/* = para validar campos del formulario de  inscripcion del boletin =*/
/* ==================================================================*/

function validar_boletin() {

	var sintaxisEmail = new RegExp ("^[a-z0-9_.-]+@{1}[a-z0-9_.-]+[\.]{1}[a-z0-9_.-]+$","i");
  
 	if (document.form.nombre.value  == '') {

		alert("Por favor, introduzca su nombre")
		document.form.nombre.focus()
		return false
	}
	
	
 	if (document.form.apellidos.value  == '') {

		alert("Por favor, introduzca sus apellidos")
		document.form.apellidos.focus()
		return false
	}
	
	
 	if (!document.form.sexo[0].checked && !document.form.sexo[1].checked) {

		alert("Por favor, facilítenos su sexo")
		return false
	}
	
 	
	if (document.form.empresa.value  == '') {

		alert("Por favor, facilítenos la empresa para la cual trabaja.\n O bien ponga su nombre si trabaja como autónomo.\n\n Esta información se recopila únicamente para fines estadísticos.")
		document.form.empresa.focus()
		return false
	}
	
	
	if (document.form.localizacion.value  == 'NULL') {

		alert("Por favor, introduzca la localización de su empresa.\n O bien la zona en donde usted tiene su cobertura profesional.\n\n Esta información se recopila únicamente para fines estadísticos.")
		document.form.localizacion.focus()
		return false
	}	


	if (document.form.telefono.value  == '') {

		alert("Por favor, facilítenos el teléfono de la empresa para la cual trabaja.\n O bien ponga el suyo si trabaja como autónomo.\n\n Esta información se recopila únicamente para fines estadísticos.")
		document.form.telefono.focus()
		return false
	}
	
	
	if ((document.form.email.value == '')||(document.form.email.value.search(sintaxisEmail) == -1)) {

		alert("Por favor introduzca su dirección de email de manera correcta")
		document.form.email.focus()
		return false
	}
	
	
	if (document.form.password.value  == '') {

		alert("Por favor, facilítenos una clave de acceso por duplicado.")
		document.form.password.focus()
		return false
		
	} else {
	
	   if ( document.form.password.value  != document.form.re_password.value ){

			alert("La clave de acceso tecleada, no coincide con el valor repetido de verificación.\n\n Por favor, vuelva a facilitarnos una clave de acceso por duplicado.")
			document.form.password.focus()
			return false
	   }
	
	}	
	
	return true

}//End validar newsletter




/* = para validar campos del formulario de  inscripcion del boletin =*/
/* ==================================================================*/

function validar_nueva_contrasena() {

	if (document.form.password.value  == '') {

		alert("Por favor, facilítenos una clave de acceso por duplicado.")
		document.form.password.focus()
		return false
		
	} else {
	
	   if ( document.form.password.value  != document.form.re_password.value ){

			alert("La clave de acceso tecleada, no coincide con el valor repetido de verificación.\n\n Por favor, vuelva a facilitarnos una clave de acceso por duplicado.")
			document.form.password.focus()
			return false
	   }
	
	}	
	
	return true

}//End validar nueva contrasena




/* =  Centra verticalmente la capa principal de la web  = */
/* ====================================================== */

function centrarVertical( capa ) {


	var objeto = findDOM( capa, 0 );
	
	
	if ( screen.height > 600 ) {
	

		topY = Math.round(( screen.availHeight - objeto.offsetHeight ) / 3 );
	
	}
	else{
	
			topY=0;
	
	}
		
	
    var estilo = findDOM( capa, 1 );
	
	estilo.top = topY;
	
	
}



/* =  Funciones y variables auxiliares para mostrar/ocultar capas = */
/* =  entre otros, son utilizadas por el scrip del preload y los  = */
/* =  scripts de manejos de solapas                               = */
/* ================================================================ */
 
 /* compatible con iexplorer y mozilla */
 
 n4 = (document.layers)? true:false
 ie = (document.all)? true:false
 n6 = (document.getElementById)? true:false

 
 function show(id) 
 {

     if (n4) 
            document.ventana.document.layers[id].visibility = "show"
     
		 else if (ie) 
		          document.all[id].style.visibility = "visible"
							
        else if (n6) 
				            document.getElementById(id).style.visibility = "visible"
 }
    
 function hide(id) 
    {
 
		 if (n4) {
		 			
			  document.ventana.document.layers[id].visibility = "hide";

		 
		 } else if (ie) {
		 			
				document.all[id].style.visibility = "hidden";

				
		 } else if (n6) { 
			  			
				document.getElementById(id).style.visibility = "hidden";

		 }
 }
 
 
 
 /* 
    en el caso de l "preloader" basta con ocultarlo hay que eliminarlo
    "display: none", puesto que aunque no este visible afecta a la posicion
		del contenedor principal
 */
 function display_none(id) 
 {
 
   if (n4) {
   
  	  document.ventana.document.layers[id].display = "none";
   
   } else if (ie) {
   
  		document.all[id].style.display = "none";
  		
   } else if (n6) { 
  	  
  		document.getElementById(id).style.display = "none";
   }

 }


/* =  Muestra el 'contenedor' principal y oculta el preload  = */
/* =========================================================== */

function cesar_preloader () 
{
	 /*
	   Muestra el 'contenedor' principal, fue ocultado "al vuelo"
		 para ser mostrado posteriormente llamando en esta funcion
		 a partir del evento onLoad (cuando se cargo la hoja de estilo)
	 */
	 show('contenedor');
	 
	 /*una vez mostrado el 'contenedor', "elimina" el preload*/
	 display_none('preloader');
}



/* = funciones a llamar en el onLoad (body, de 'index.php') =*/
/* = personalizado con las inicializaciones JS de las paginas que lo demanden */
/* = ello se indicara en el campo ini_js, de la tabla 'entradas_menu de la BD */
/* ===========================================================================*/

/* inicializacion js para la pagina de vehiculo */

function init_vehiculo() {
  
	//solapas vehiculo
	init_solapas(3);
	
	//galeria fotos (vehiculo)
	initpage ();
}



/* inicializacion js para la pagina de fotografias de piloto */

function init_foto_piloto() {
  
	//galeria fotos (piloto)
	initpage ();
}



