//Author: Antonio Sejas
//Fecha: Agosto 2009
//Vasado en: http://www.askthecssguy.com/2007/05/validation_hints_for_your_form_1.html
// evalua que todos los campos requeridos tengan la clase "correcto".
function evaluado_todo(form,cuantos_requeridos,cuantos_requeridos_facturacion) {
var cuantos_requeridos_total=0;
if (form.facturacioninscrito.checked){
cuantos_requeridos_total=cuantos_requeridos;
}else{
cuantos_requeridos_total=cuantos_requeridos_facturacion+cuantos_requeridos;
}//end if;


if (form.evento.value=="Ninguno"){
	  if (form.evento.length<=1){ // Si solo hay un evento y es NINGUNO entonces enseñamos Alerta informando que no hay cursos.
		alert("Disculpe actualmente no hay eventos disponibles por formulario.\nDebe contactar con formacion@ateneainteractiva.com");
	   }else {
	   form.evento.focus();
	   form.evento.style.backgroundColor="#F00";
	   }
	   return false; // No dejamos que envie el formulario;
	   // document.getElementById("errores").innerHtml = "Debe Seleccionar un Evento";
}else{
	if (cuantos(form,'welldone')<cuantos_requeridos_total){
		alert( "Le faltan "+(cuantos_requeridos_total-cuantos(form,'welldone'))+" campos por rellenar correctamente\n Gracias" );
		return false;
	}else{ // si en el formulario hay al menos cuantos_requeridos con la clase: welldone , entonces permitimos el envio
	alert ("Gracias, su solicitud se est\xe0 enviando.");
	return true;
	}// end if (cuantos)

}// end if; ()Evento==Ninguno
}//end evaluado_todo;
// This function checks if the username field
// is at least min_length characters long.
// If so, it attaches class="welldone" to the 
// containing fieldset.
function checkForLength(whatYouTyped,min_length) {
	var fieldset = whatYouTyped.parentNode;
	var txt = whatYouTyped.value;
	if (txt.length >= min_length) {
		fieldset.className = "welldone";
		whatYouTyped.className="correcto";
	}
	else {
		fieldset.className = "";
		whatYouTyped.className="";
	}
}
// Evalua si el  Evento != "Ninguno"
function checkForEvento(whatYouTyped) {
	var fieldset = whatYouTyped.parentNode;
	var txt = whatYouTyped.value;
	if (txt != "Ninguno") {
		fieldset.className = "welldone";
		whatYouTyped.className="correcto";
		whatYouTyped.style.backgroundColor="#FFF";
	}
	else {
		fieldset.className = "";
		whatYouTyped.className="";
	}
}
// If the password is at least 4 characters long, the containing 
// fieldset is assigned class="kindagood".
// If it's at least 8 characters long, the containing
// fieldset is assigned class="welldone", to give the user
// the indication that they've selected a harder-to-crack
// password.
function checkPassword(whatYouTyped) {
	var fieldset = whatYouTyped.parentNode;
	var txt = whatYouTyped.value;
	if (txt.length > 3 && txt.length < 8) {
		fieldset.className = "kindagood";
	} else if (txt.length > 7) {
		fieldset.className = "welldone";
	} else {
		fieldset.className = "";
	}
}
// This function checks the email address to be sure
// it follows a certain pattern:
// blah@blah.blah
// If so, it assigns class="welldone" to the containing
// fieldset.
function checkEmail(whatYouTyped) {
	var fieldset = whatYouTyped.parentNode;
	var txt = whatYouTyped.value;
	//if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(txt)) {
	if (/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i .test(txt)) {
		fieldset.className = "welldone";
	} else {
		fieldset.className = "";
	}
}
// This function checks if the username field
// is at least min_length characters long. And every character is a Number.
// If so, it attaches class="welldone" to the 
// containing fieldset.
function checkForNumLength(whatYouTyped,min_length) {
	var fieldset = whatYouTyped.parentNode;
	var txt = whatYouTyped.value;
// IsUnsignedInteger(txt)
	if (txt.length >= min_length && !isNaN(txt)) {
		fieldset.className = "welldone";
		whatYouTyped.className="correcto";
	}
	else {
		fieldset.className = "";
		whatYouTyped.className="";
	}
}
// this part is for the form field hints to display
// only on the condition that the text input has focus.
// otherwise, it stays hidden.
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
function prepareInputsForHints() {
  var inputs = document.getElementsByTagName("input");
  for (var i=0; i<inputs.length; i++){
    inputs[i].onfocus = function () {
       this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
    }
    inputs[i].onblur = function () {
       this.parentNode.getElementsByTagName("span")[0].style.display = "none";
    }
  }
}
addLoadEvent(prepareInputsForHints);
/*
//pre:cierto - usando prototype.
//post: cuenta cuantas etiquetas tienen las class: 'clase'
function cuantos(formulario,clase){
	  var cuantos_well=0;
     // var arrayNodosfamilia = document.getElementsByClassName(clase);
	  var arrayNodosfamilia = formulario.getElementsByClassName(clase); // esta clase será por lo general 'welldone'
      var Arreglo = $A(arrayNodosfamilia); 
      cuantos_well=0;
	  Arreglo.each( function(el, indice){
		cuantos_well++;
       // el.innerHTML = indice + ':' + 'divider ' + el.id;
        el.style.color = 'blue';
      });
	  return cuantos_well;
   }//end cuantos
*/
//pre:cierto
//post: cuenta cuantas etiquetas tienen las class: 'clase'
function cuantos(formulario,clase){
	  var cuantos_well=0;
     // var arrayNodosfamilia = document.getElementsByClassName(clase);
	  //var arrayNodosfamilia = formulario.getElementsByClassName(clase); // esta clase será por lo general 'welldone'
	    var divs = document.getElementsByTagName("fieldset");
		var numDivs = divs.length;
		cuantos_well=0;
		for(var i = 0; i < numDivs; i++) if(divs[i].className == "welldone") cuantos_well++;
      // var Arreglo = $A(arrayNodosfamilia); 
      //cuantos_well= arrayNodosfamilia.length;
	  return cuantos_well;
}//end cuantos

//pre:cierto
//post:  si el checkbox que me llega esta marcado, oculto la capa "datosFacturacion", e.o.c. La enseño.
function mostrarDatosFacturacion(casilla){
	  if (casilla.checked==true){
	  //$("datosFacturacion").style.display='none';
	  Effect.Fade('datosFacturacion',{ duration:0.5, from:1.0, to:0.0 });
	  }else{
	  //$("datosFacturacion").style.display='block';
	  Effect.Appear('datosFacturacion');
	  }
}//end cuantos