/**************************************************************************
 *                                                                        *
 *  JAVASCRIPT MENU HIGHLIGHTER v.1.0 (051123)                            *
 * --------------------------------------------                           *
 * ©2005 Media Division (www.MediaDivision.com)                           *
 *                                                                        *
 * Written by Marius Smarandoiu & Armand Niculescu                        *
 *                                                                        *
 * You are free to use, modify and distribute this file, but please keep  *
 * this header and credits                                                *
 *                                                                        *
 * Usage:                                                                 *
 * - the script will apply the .current class to the <a> and its parent   *
 *   <li> that is contained in the element with id="primarynav" and points*
 *   to the current URL                                                   *
 * - works in IE6, Firefox and Opera                                      *
 **************************************************************************/
// Enlaces externos
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}

function extractPageName(hrefString)
{
 var arr = hrefString.split('.');
 if(arr.length >= 2) {
  arr = arr[arr.length-2].split('/');
  return arr[arr.length-1].toLowerCase();
 } else {
  return "x";
 }
}

function setActiveMenu(arr, crtPage)
{
	for(var i=0; i < arr.length; i++)
		if(extractPageName(arr[i].href) == crtPage)
		{
			var nombre;
			nombre=arr[i].parentNode.getAttribute("class");
			if(nombre==null){
				nombre="selec";
			}else{
				nombre=nombre + " selec";
			}
			arr[i].parentNode.className = nombre;	
		}

}

function setPage()
{
	if(document.location.href) 
		hrefString = document.location.href;
	else
		hrefString = document.location;
		
	/*if (document.getElementById("menu")!=null) 
		setActiveMenu(document.getElementById("menu").getElementsByTagName("a"), extractPageName(hrefString));*/
	if (document.getElementById("submenu")!=null) 
		setActiveMenu(document.getElementById("submenu").getElementsByTagName("a"), extractPageName(hrefString));
}
window.onload=function()
{
  setPage();
  externalLinks();
}

/*Validaciones formularios*/
function validarContacto(){
	 var pattern = /^[a-zA-Z0-9\-\._]+@[a-zA-Z0-9\-_]+(\.?[a-zA-Z0-9\-_]*){2,3}\.[a-zA-Z]{2,3}$/;
				var Str;
        with (document.forms['formContacto']){
			if (nombre.value=="" || nombre.value=="Insert your name"){
							alert("Please, insert your name");
							nombre.focus();
							return false;
           	}   
			if (apellidos.value=="" || apellidos.value=="Insert your surname"){
							alert("Please, insert your surname");
							apellidos.focus();
							return false;
           	}  
            if (email.value=="" || email.value=="Insert your e-mail"){
                alert("Please, insert your e-mail");
								email.focus();
                return false;
			}
			if (email.value!="" && !pattern.test(email.value) ){
                alert("Please enter a valid email address");
								email.focus();
                return false;
            }
			
			if (telefono.value=="" || telefono.value=="Insert your telephone number"){
							alert("Please, insert your telephone number");
							telefono.focus();
							return false;
           	}  
				Str = mensaje.value;
			if (Str.length == 0 || mensaje.value=="Insert your comment")
			{
				alert ("Please, insert your comment");
				mensaje.focus();
				return false;
			}
			if (aceptar.checked != true){
				alert("You must read and accept the privacy policy");
				return false;
			}		
    	}
}


/*Ocultar Mensajes*/
function ocultarMensajes(idDiv){
    var box = document.getElementById(idDiv).setAttribute("class","oculto");
}
function mostrarMensajes(idDiv){
    var box = document.getElementById(idDiv).setAttribute("class","mostrar");
}
