var exp_reg1 = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
var exp_reg2 = /^\d+$/;
var errores = new Array();

errores["esp"]=new Array("Introduzca su Nombre", "Introduzca sus Apellidos", "Introduzca su Email", "Introduzca su consulta o Comentarios", "El Email introducido es incorrecto", "El Telefono introducido es incorrecto");
errores["ing"]=new Array("Insert your Name", "Insert your Surmane", "Insert your Email", "Insert your Comments", "The Email is incorrect", "The Telephone is incorrect");

addEvent(window, "load", init);

function init() {
	if (document.getElementById) {
		tck = document.getElementById("noticias");
		if(tck!=null) {
		  if(tck.getElementsByTagName("div").length > 0) {
			actual = 0;
			step = 2;
			speed = 15;
			delay = 1500;
			news = new Array();
			for (i = 0; i < tck.getElementsByTagName("div").length; i++) {
				news[i] = tck.getElementsByTagName("div")[i];
				news[i].style.left = tck.offsetWidth + "px";
			}
			rollNews();
			addEvent(tck, "mouseover", stopNews);
			addEvent(tck, "mouseout", rollNews);
		  }
		}
	}
}

function rollNews() {
	news[actual].style.left = parseInt(news[actual].style.left) - step + "px";
	
	if (parseInt(news[actual].style.left) == tck.offsetWidth % step) {
		// if that movement hasnt taken us off the edge of the div then wait
		// a bit and move it again.
		tick = setTimeout("rollNews()",delay);
	}
	else {
		// if it has taken us over the edge then move to the next item in news array
		if (parseInt(news[actual].style.left) <= 0-news[actual].offsetWidth) {
			actual++;
			// if at end of array then knock it back to start
			if (actual == news.length) {actual = 0;}
			news[actual].style.left =  tck.offsetWidth + "px";
		}
		// wait a bit and try again.
		tick = setTimeout("rollNews()",speed);
	}
}

function stopNews() {
	clearTimeout(tick);
}

function addEvent(obj, evType, fn){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, true);
    return true;
  } else if (obj.attachEvent){
	var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
	return false;
  }
}

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function validarConsulta(formulario, idioma) {
    if(formulario.nombre.value=="") { alert(errores[idioma][0]); return false; }
	if(formulario.apellidos.value=="") { alert(errores[idioma][1]); return false; }
	if(formulario.email.value=="") { alert(errores[idioma][2]); return false; }
	if(formulario.comentarios.value=="") { alert(errores[idioma][3]); return false; }
	if(!exp_reg1.test(formulario.email.value)) { alert(errores[idioma][4]); return false; }
	if(formulario.telefono.value!=""&&!exp_reg2.test(formulario.telefono.value)) { alert(errores[idioma][5]); return false; }
	formulario.submit();
}

