// JavaScript Document

function validaForm(f) {
	
	if ( f.blog.value == "" ) {
		alert("El Nombre del Blog es obligatorio.")
		f.blog.focus()
		return false
	}
	
	if ( f.blog_url.value == "" ) {
		alert("La Direccion del Blog es obligatoria.")
		f.blog_url.focus()
		return false
	}
	
	//if ( !validaweb(f.blog_url.value)){
	//	alert("La Direccion del Blog no es correcta.")
	//	f.blog_url.focus()
	//	return false
	//}
	
	if ( f.nombre.value == "" ) {
		alert("El Autor del Blog es obligatorio.")
		f.nombre.focus()
		return false
	}
	
	if ( f.tematica.value == "" ) {
		alert("La Tematica del Blog es obligatoria.")
		f.tematica.focus()
		return false
	}	
	
	if ( f.categoria.value == "Selecciona" ) {
		alert("Debes seleccionar una Categoria.")
		f.categoria.focus()
		return false
	}	
	
	if ( f.email == "" ) {
		alert("El Email de contacto es obligatorio.")
		f.txtEmail.focus()
		return false
	}	
	
	
	if( f.email.value.length == 0 || !validamail(f.email.value) ) {
		alert("El E-mail parece incorrecto.");
	    f.email.focus();
		return false
    }
	
	if ( f.telefono.value == "" ) {
		alert("El Telefono de contacto es obligatorio.")
		f.telefono.focus()
		return false
	}
	
	if (!f.txtPolitica.checked) {
		alert("Es Obligatorio aceptar la Politica de Privacidad")
	    f.txtPolitica.focus()
		return false
	}
	
	// Todo OK, enviamos el formulario
	return true
}





function validamail(email){

	// Mínimo de 5 caracteres
	if (email.length < 5)
		return false
		
	// Cadena de caracteres no permitidos
	var iChars = "+*|,\":<>[]{}`';()&$#% ";	
	
	// Primero comprobamos que en el email no haya algún 
	// caracter no permitido
	var eLength = email.length;	
	for (var i=0; i < eLength; i++)	{		
		if (iChars.indexOf(email.charAt(i)) != -1)
			return false
	}	
	
	// Comprobamos que la @ tenga algún caracter delante y alguno detrás
	var atIndex = email.lastIndexOf("@");	
	if(atIndex < 1 || (atIndex == eLength - 1))
		return false

	// Comprobamos que exista '.' a partir del cuarto carácter, pero
	// que no acabé en '.'
	var pIndex = email.lastIndexOf(".");	
	if(pIndex < 3 || (pIndex == eLength - 1))	
		return false;	

	// Por último, comprobamos que el punto esté detrás de la @
	if(atIndex > pIndex)	
		return false	

	return true
}

//function validaweb(blog_url){

	// Mínimo de 5 caracteres
//	if (blog_url.length < 5)
//		return false
		
	// Cadena de caracteres no permitidos
//	var iChars = "+*|,\":<>[]{}`';()&$#% ";	
	
	// Primero comprobamos que en el email no haya algún 
	// caracter no permitido
//	var eLength = blog_url.length;	
//	for (var i=0; i < eLength; i++)	{		
//		if (iChars.indexOf(blog_url.charAt(i)) != -1)
//			return false
//	}
	
	// Segundo comprobamos que la dirección comience por 3 w.

//	for (var i=0; i < 2; i++)	{		
//		if ((blog_url.charAt(i)) != "w")
//			return false
//	}
	
//	if ((blog_url.charAt(3)) != "."){
//			return false
//	}
	
	// Comprobamos que exista '.' a partir del cuarto carácter, pero
	// que no acabé en '.'
//	var pIndex = blog_url.lastIndexOf(".");	
//	if(pIndex < 6 || (pIndex == eLength - 1))	
//		return false;	

	// Por último, comprobamos que el punto esté detrás de la @
//	if(atIndex > pIndex)	
//		return false	

//	return true
//}

