function agregar_alert(campo, nombre, alerta){

    if(campo.value=="0"||campo.value=="" || campo.value==nombre){
        alerta += "El "+ nombre + " es obligatorio \n";
        campo.value=nombre;
		campo.style.color='#ff0000';
    }
    return alerta;
    
}


function validar_email(campo, alerta){
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
   
   	if (!filter.test(campo.value) ) {
            alerta += "Por favor ingrese un mail valido (Ej. usuario@dominio.com) \n" ;
            campo.style.color='#ff0000';
        }
        
        return alerta;
}  


  
function guardar_newsletter_footer()	{
	var alerta="";
	var nombre = document.getElementById("nombre_front");
	var email = document.getElementById("email_front");
	alerta = validar_email(email, alerta);
	
	var parametros = "";
	parametros += "email="+encodeURIComponent(email.value);   
	parametros += "&nombre="+encodeURIComponent(nombre.value);
	
	if(alerta==""){
		get_pagina({contenedor:"msg2_result",page:"php/guardar_newsletter.php",params:parametros});
		return false;
    }else{
        alert(alerta);
        return false;
        
    }
}



function guardar_contacto()	{
	var alerta="";
	var nombre = document.getElementById("nombre");
	var apellido = document.getElementById("apellido");
	var email = document.getElementById("email");
	var telefono = document.getElementById("telefono");
	var empresa = document.getElementById("empresa");
	var donde = document.getElementById("donde");
	var como = document.getElementById("como");
	var comentario = document.getElementById("comentario");
	
	
	alerta = agregar_alert(nombre, 'NOMBRE *', alerta);
	alerta = agregar_alert(apellido, 'APELLIDO *', alerta);
	alerta = validar_email(email, alerta);
	alerta = agregar_alert(comentario, 'COMENTARIO *', alerta);
	
	var parametros = "";
	parametros += "email="+encodeURIComponent(email.value);   
	parametros += "&nombre="+encodeURIComponent(nombre.value);
	parametros += "&apellido="+encodeURIComponent(apellido.value);
	parametros += "&telefono="+encodeURIComponent(telefono.value);
	parametros += "&empresa="+encodeURIComponent(empresa.value);
	parametros += "&donde="+encodeURIComponent(donde.value);
	parametros += "&como="+encodeURIComponent(como.value);
	parametros += "&comentario="+encodeURIComponent(comentario.value);
	
	
	if(alerta==""){
		get_pagina({contenedor:"msg",page:"php/guardar_contacto.php",params:parametros});
        nombre.value='NOMBRE *';
        nombre.style.color='#fff';
        apellido.value='APELLIDO *';
        apellido.style.color='#fff';
        email.value='EMAIL *';
        email.style.color='#fff';
        telefono.value='TELEFONO';
        empresa.value='EMPRESA';
        donde.value='¿DE DONDE SOS?';        
        como.value='¿COMO NOS CONOCISTE?';
        comentario.value='COMENTARIO *';
        comentario.style.color='#fff';
		return false;
    }else{
        alert(alerta);

        
        return false;
        
    }
}


function limpiar(campo, valor){
	elemento = document.getElementById(campo);
	if (elemento.value==valor){
		elemento.value='';
	}
	
}

function completar(campo, valor){
	elemento = document.getElementById(campo);
	if (elemento.value==''){
		elemento.value=valor;
	}
	
}

function loopImagenes(nombre){
	if(imagen_seleccionada<imagen_total){
		var valor = imagen_seleccionada+1;
		document.getElementById('imagen_loop').src='images/'+nombre+valor+'.jpg';
		imagen_seleccionada=valor;
	}else{
		document.getElementById('imagen_loop').src='images/'+nombre+1+'.jpg';
		imagen_seleccionada=1;
	}
	
}

function cambiar_proyecto(proyecto, proyectoNuevo){
	document.getElementById(proyecto).style.display='none';
	document.getElementById(proyectoNuevo).style.display='inline';
	
}

function mostrar_noticia(id){
	document.getElementById('noticias_noticias').style.display='none';
	document.getElementById('noticia_'+id).style.display='inline';
		
}
function cerrar_noticia(id){
	document.getElementById('noticias_noticias').style.display='inline';
	document.getElementById('noticia_'+id).style.display='none';
		
}
