// JavaScript Document
var txt_menu = new Array("Home","Empresa","Especiales","Noticias","Catálogo Productos","Zona de descargas","Agenda del agricultor","Financiación","Segunda Mano","Postventa","Tablón de anuncios","Novedades","Recomendaciones","Presupuesto","Contacto");
var	lnk_menu = new Array("index.asp","empresa.asp","especiales.asp","noticias.asp","productos.asp","descargas.asp","agenda.asp","credito.asp","segundamano.asp","postventa.asp","tablon.asp","novedades.asp","novedades.asp?tipo=recomendaciones","quepresupuesto.asp","contacto.asp");

var txt_menuPie = new Array("Empresa","Catálogo Productos","Segunda Mano","Postventa","Especiales","Noticias","Zona de descargas","Agenda del agricultor","Financiación","Tablón de anuncios","Recomendaciones","Contacto");
var	lnk_menuPie = new Array("empresa.asp","productos.asp","segundamano.asp","postventa.asp","especiales.asp","noticias.asp","descargas.asp","agenda.asp","credito.asp","tablon.asp","novedades.asp?tipo=recomendaciones","contacto.asp");

function buildMenu(){		
	document.write('<table width="160" style="margin-left:2px; margin-right:2px" cellpadding="0" cellspacing="0">');
	for(i=0;i<txt_menu.length;i++){
		document.write('<tr>');
		document.write('<td width="12" class="menu"><img src="images/vinieta.jpg" alt="' + txt_menu[i] + '" onclick="goToPage(' + i +  ')" /></td>');
		document.write('<td class="menu" onClick="goToPage(' + i + ')" onMouseOver="sobreMenu(this,true)" onMouseOut="sobreMenu(this,false)">' + txt_menu[i] + '</td>');
		document.write('</tr>');
	}
	document.write('<tr>');
	document.write('<td colspan="2" align="center" onclick="verelTiempo()"><table><tr><td><img src="images/btnTiempo.jpg" alt="El tiempo" /></td><td class="tiempo">El Tiempo</td></tr></table></td>');
	document.write('</td>');
	document.write('</tr>');
	document.write('</table>');
}
function verelTiempo(){
	window.location = "eltiempo.asp";
}	
function buildMenuPie(){
	document.write('<table width="990" cellpadding="0" cellspacing="0" class="fondoRojoPie"><tr>');	
	for(i=0;i<txt_menuPie.length;i++){		
		document.write('<td class="lnkBlanco" onClick="goToPagePie(' + i + ')" onMouseOver="sobreMenuPie(this,true)" onMouseOut="sobreMenuPie(this,false)">' + txt_menuPie[i] + '</td>');
		if(i<txt_menuPie.length-1)
			document.write('<td width="5" class="lnkBlanco"> | </td>');
	}	
	document.write('</tr></table>');
}
function goToPage(indice){
	window.location = lnk_menu[indice];
}
function goToPagePie(indice){
	window.location = lnk_menuPie[indice];
}
function validarLogin(){
	var aErr = new Array("fusuario","fpassword");
	var aErrT = new Array("el usuario", "la contraseńa")
	var sw = true;
	var msj = "Faltan por rellenar los siguientes campos:\n";	
	for(i=0;i<aErr.length;i++){
		if(document.getElementById(aErr[i]).value == ""){
			sw = false;
			msj+= "     · " + aErrT[i] + ".\n";			
		}
	}
	if(msj != "Faltan por rellenar los siguientes campos:\n")
		alert(msj);
	else
		document.getElementById("frmLog").submit();
}
function sobreMenu(ob, si){
	if(si)
		ob.className = "menu_on";	
	else
		ob.className = "menu";
	
}
function sobreMenuPie(ob, si){
	if(si)
		ob.className = "lnkBlanco_on";	
	else
		ob.className = "lnkBlanco";	
}
function verNovedades(){
	window.location = "novedades.asp";
}
function verRecomendaciones(){
	window.location = "novedades.asp?rec=yes";
}
function verAnuncios(){
	window.location = "tablon.asp";
}
function goDetalle(ide,seccion){
	switch(seccion){
		case "tablon":
			window.location = "detAnuncio.asp?id=" + ide;
		break;
		
	}
}
function paginar(nPage, webPage){
	
	switch(webPage)	{
		case "tractores":
			window.location = "productos.asp?tipo=trac&p=" + nPage;
		break;
		case "maquinaria":
			window.location = "productos.asp?tipo=maq&p=" + nPage;
		break;
		case "recambios":
			window.location = "productos.asp?tipo=rec&p=" + nPage;
		break;
		case "segundamano":
			window.location = "segundamano.asp?p=" + nPage;
		break;
	}
}

//-----------------------------------------------------
function verImagen(arr,visor,ir){
	document.getElementById(visor).src = arr[ir][0];
	document.getElementById("contadorRec").innerHTML = parseInt(ir+1) + " de " + arr.length;
}
function atras(array,idVisor){
	if(array.length > 0){
		if(indiceRec == 0){
			indiceRec = array.length-1;
		}else{
			indiceRec--;
		}	
		verImagen(array,idVisor,indiceRec);
	}
}
function play(array,idVisor,imagen){	
	if(imagen.alt == "Play"){
		imagen.src = "images/control_pause_blue.png";	
		imagen.alt = "stop";
		swRec = false;
	}else{
		imagen.src = "images/control_play_blue.png";	
		imagen.alt = "Play";
		swRec = true;		
	}
	reproduciendo();	
}
function ahead(array,idVisor){
	if(array.length > 0){
		if(indiceRec < array.length-1){
			indiceRec++;
		}else{
			indiceRec = 0;
		}
		verImagen(array,idVisor,indiceRec);
	}
}
function reproduciendo(){
	if(arrayImg.length>0){
		if(swRec){
		ahead(arrayImg,"imagenVisor");
		window.setTimeout("reproduciendo()",1500);}
	}
}
//-----------------------------------------------------------------
function validar(aErr,aErrT,valEmail){
	var sw = true;
	var msj = "Faltan por rellenar los siguientes campos:\n";
	if(valEmail){
		if(!validarMail(document.getElementById(valEmail)))
			sw = false;	
		}
	for(i=0;i<aErr.length;i++){
		if(document.getElementById(aErr[i]).value == ""){
			sw = false;
			msj+= "     · " + aErrT[i] + ".\n";
	}}
	if(msj != "Faltan por rellenar los siguientes campos:\n")
		alert(msj);

	return sw;
}
function validarMail(mail){
	if (mail.value.indexOf("@") < 0 && mail.value.length > 0) {
		alert ('El valor del e-mail no se corresponde con un patrón válido');		
		return false;}
	else 
		return true;	
}
