function validarForm(){
	args=validarForm.arguments;
	var errors="";
	var i;
	for (i=0; i<(args.length); i++){
		val=document.getElementById(args[i]);
		nm=val.name;
		if (val.value=="")
			errors += '- '+nm+' es obligatorio.\n';
		else if((nm=="email" || nm=="mail") && (val.value.match("@") == null || val.value.match(".") == null))
			errors += '- '+nm+' debe ser un email v\u00e1lido\n';
	}
	if(errors)
		alert(errors);
		
	return (errors=="");
}
//onsubmit="return validarForm('nombre','email');"

function contar(id,cant) {
  n = document.getElementById(id).value.length;
  t = cant;
  if (n > t) {
  	aux=document.getElementById(id).value.substring(0, t);
    document.getElementById(id).value=aux;
  }
  else
	document.getElementById(id+"_left").innerHTML=t-n;
}
//onkeyup="contar('campo',10);" onkeydown="contar('campo',10);"

function add_news(){
	if($('#nombre').val()=='' || $('#nombre').val()=='e-mail'){
		$('#nombre').focus();
		return;
	}
	if($('#email').val()=='' || $('#email').val()=='e-mail'){
		$('#email').focus();
		return;
	}
	if ($('#email').val().match("@") == null || $('#email').val().match(".") == null){	
		alert("Debe ser un email v\u00e1lido");
		$('#email').focus();
		return;
	}
	$('#news_cargando').css('display','block');
	$.ajax({
		type: 'POST',
		url: 'addnews.php',
		cache: false,
		data: 'nombre=' + encodeURIComponent($('#nombre').val()) +'&email=' + encodeURIComponent($('#email').val()) + '&ajax=1',
		success: function(h){
			alert(h);
			$('#news_cargando').css('display','none');
		},
		error: function(){
			$('#news_cargando').css('display','none');
			login();
		}
	});
}
