/*
 * Función para añadir a favoritos
 */
function addFav()
{

    if( ( typeof window.sidebar == "object" ) && ( typeof window.sidebar.addPanel == "function" ) )
    {
        window.sidebar.addPanel( "INFECAR", "http://www.infecar.es/", "" );
    }
	else
	{
		window.external.Addfavorite( 'http://www.infecar.es', 'INFECAR' );
	}
}
/* FIN AÑADIR A FAVORITOS */

function addHomePage()
{
//this.style.behavior='url(#default#homepage)';this.setHomePage('http://www.yoursite.com');
}

/*
 * Función para abrir un popup
 *
 * @param	theURL	 se le pasa la URL de lo que se va a abrir
 * @param	winName
 * @param	features
 */
function MM_openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}

/*
 * Función revisar formulario
 *
 *	checkform 						Revisa que los campos con la clas "required" no estén vacios
 *
 *	checkField 						Revisa el campo (RegExp)
 *
 *	diaplay_form_message 			Determina si mostrar el campo de mensaje (oculto por defecto) o no
 *
 *	mensaje_error_idioma 			Aqui se ponen los mensajes de error a mostrar en cada idioma
 *						 			(El formulario debe tener un input oculto con el idioma)
 */
function checkform(formulario) {
var mensajeError = document.getElementById('displ_error');
var idioma = document.getElementById('idioma').value;
var mensaje = mensaje_error_idioma(idioma, 'warning');
		var obj = document.getElementById(formulario);
		var vacio  = 0;
		for (var i = 0; i <= formulario.length; i++){
			if(formulario.elements[i].className == 'required' && formulario.elements[i].value == ""){
			vacio++;
			formulario.elements[i].onblur();
			return false;
			}
		}
return true;
}

/*
 *
 */
function checkField(nombreCampo, idCampoError) {
var idioma = document.getElementById('idioma').value;
var campo = document.getElementById('validar_' + nombreCampo);
var valor_campo = campo.value;
var mensajeError = document.getElementById(idCampoError);
var mensaje;
	switch(nombreCampo) {
	case "sname":
	case "name":
	case "comment":
		if( !valor_campo.match(/^[a-z ._-]+$/i) ) {
			mensaje = mensaje_error_idioma(idioma, nombreCampo);
			diaplay_form_message(idCampoError, nombreCampo, mensaje);
		} else {
			diaplay_form_message(idCampoError, nombreCampo, "");
		}
		break;
	case "email":
		if( !valor_campo.match(/^[a-z0-9._%-]+@[a-z0-9.-]+\.[a-z]{2,4}$/i) ) {
			mensaje = mensaje_error_idioma(idioma, nombreCampo);
			diaplay_form_message(idCampoError, nombreCampo, mensaje);
		} else {
			diaplay_form_message(idCampoError, nombreCampo, "");
		}
	}
}

/*
 *
 */
function diaplay_form_message(idCampoError, nombreCampo, mensaje) {
var campo = document.getElementById('validar_' + nombreCampo);
var mensajeError = document.getElementById(idCampoError);

	var vacio = 0;
	if(mensaje == ""){
		mensajeError.style.display = "none";
	} else {
		mensajeError.style.display = "block";
		mensajeError.innerHTML = mensaje;
		campo.style.background = "#FFFFCC";
	}
}

/*
 *
 */
function mensaje_error_idioma(idioma, campo){
	switch(idioma) {
	case "en":
			if(campo == "warning"){
				mensaje = "Fill in all required fields";
			} else if(campo == "email"){
				mensaje = "Invalide email format";
			} else {
				mensaje = "Required field";
			}
			break;

	case "fr":
			if(campo == "warning"){
				mensaje = "Fill in all required fields";
			} else if(campo == "email"){
				mensaje = "Invalide email format";
			} else {
				mensaje = "Required field";
			}
			break;
	case "es":
	default:
			if(campo == "warning"){
				mensaje = "Rellene campos obligatorios";
			} else if(campo == "email"){
				mensaje = "Formato de correo inválido";
			} else {
				mensaje = "Campo obligatorio";
			}
			break;
	}
return mensaje;
}

function changeImage( imagen, url )
{
	document.getElementById('longImage').style.display='block';
	document.getElementById('longImage').src = imagen;
	
	var imagensita = imagen;
		imagensita.split("?");
	
	var a = imagensita.split("?");
	var b = a[ 1 ];
	var c = b.split("=");
	var d = c[ 1 ];
	var e = d.split("&");
	
	var f = "galeriaImagenes/" + e[ 0 ];
	
	document.getElementById('longImageLink').href = f;
}