function validate() {
	//if (validaCPF(document.application.cpf.value)) 
	if (checktext("name","Name")) 
	if (checktext("last_name1","Middle Name"))
	if (checktext("last_name2","Last Name"))
	if (checkradio1("rbgender","Gender"))
	if (checktext("nacionality","Nacionality")) 
	if (checktextor("cpf","CPF","passport","Passport Number")) 
	if (checktext("address","Address")) 
	if (checktext("city","City")) 
	if (checktext("state","State")) 
	if (checktext("zip_code","Zip Code")) 
	if (checktext("date_birth","Date of Birth")) 
	if (checktext("mail","e-mail")) 
	if (checktext("phone_home","Home phone")) 
	if (checkselect("school","School Name")) 
	if (checkselect("course","Course")) 
	if (checkselect("qualification","Qualification")) 
	if (checktext("date_conclusion","Date of conclusion")) 
	if (checkradio2("rbparticipated","Have you participated in any other McKinsey recruiting process?"))
	if (checkradio3("rbparticipating","Currently, are you participating in any other McKinsey recruiting process?"))
	if (checkselect("know_recruiting","How did you know about recruiting process?")) 
	if (checkselect("rboffice","Office preference")) 
	if (checkfile("fichero")) 
	if (checkdata()) 
		return true;
	return false;
}
function validate1() {
	//if (validaCPF(document.application.cpf.value)) 
	if (checktext("name","Name")) 
	if (checktext("last_name1","Middle Name"))
	if (checktext("last_name2","Last Name"))
	if (checkradio1("rbgender","Gender"))
	if (checktext("nacionality","Nacionality")) 
	if (checktextor("cpf","CPF","passport","Passport Number")) 
	if (checktext("address","Address")) 
	if (checktext("city","City")) 
	if (checktext("state","State")) 
	if (checktext("zip_code","Zip Code")) 
	if (checktext("date_birth","Date of Birth")) 
	if (checktext("mail","e-mail")) 
	if (checktext("phone_home","Home phone")) 
	if (checktext("date_conclusion","Date of conclusion")) 
	if (checkradio2("rbparticipated","Have you participated in any other McKinsey recruiting process?"))
	if (checkradio3("rbparticipating","Currently, are you participating in any other McKinsey recruiting process?"))
	if (checkselect("know_recruiting","How did you know about recruiting process?")) 
	if (checkfile("fichero")) 
	if (checkdata()) 
		return true;
	return false;
}

function validaCPF(CPF) {
   var soma;
   var Resto;
   var i;

   if (CPF.length == 0) {
      return true;
   }

   if ((CPF.length != 11) || (CPF == 99999999999) || (CPF == 88888888888) || (CPF == 77777777777) || (CPF == 66666666666) || (CPF == 55555555555) || (CPF == 44444444444) || (CPF == 33333333333) || (CPF == 22222222222) || (CPF == 11111111111)) {
      alert("You entered and invalid CPF number.\nPlease correct and try again.");
      return false;
   }

   soma = 0;
   for(i=0; i < 9; i++) {
       soma = soma + CPF.substr( i, 1) * (10 - i)
   }

   Resto = 11 - (soma - Math.floor(soma / 11) * 11);
   if ((Resto == 10) || (Resto == 11))  { Resto = 0 }
   if (Resto != CPF.substr(9,1)) {
      alert("You entered and invalid CPF number.\nPlease correct and try again.");
      return false;
   }

   soma = 0;
   for(i=0; i < 10; i++) {
       soma = soma + CPF.substr(i,1) * (11 - i)
   }
   Resto = 11 - (soma - Math.floor(soma / 11) * 11)
   if ((Resto == 10) || (Resto == 11))  { Resto = 0 }
   if (Resto != CPF.substr(10,1)) {
      alert("You entered and invalid CPF number.\nPlease correct and try again.");
      return false;
   }

   return true
}


function checkselect(ctrlName, ctrlTag) {
   var foundCtrl = false;

   if (eval("document.application."+ctrlName+".selectedIndex") != 0 ) {
      foundCtrl = true;
   }
   else {
      alert("You forgot to fill the "+ctrlTag+" field !");
   }
   return foundCtrl;
}

function checktext(ctrlName, ctrlTag) {
   var foundCtrl = false;

   if (eval("document.application."+ctrlName+".value") != "" ) {
      foundCtrl = true;
   }
   else {
      alert("You forgot to fill the "+ctrlTag+" field !");
   }
   return foundCtrl;
}

function checkradio1(ctrlName,ctrlTag) {
var marcado = "no";
with (document.application){
for ( var i = 0; i < rbgender.length; i++ ) {
if ( rbgender[i].checked ) {
return true;
}
}
if ( marcado == "no" ){
alert("You forgot to fill the "+ctrlTag+" field !");
}
}
}

function checkradio2(ctrlName,ctrlTag) {
var marcado = "no";
with (document.application){
for ( var i = 0; i < rbparticipated.length; i++ ) {
if ( rbparticipated[i].checked ) {
return true;
}
}
if ( marcado == "no" ){
alert("You forgot to fill the "+ctrlTag+" field !");
}
}
}

function checkradio3(ctrlName,ctrlTag) {
var marcado = "no";
with (document.application){
for ( var i = 0; i < rbparticipating.length; i++ ) {
if ( rbparticipating[i].checked ) {
return true;
}
}
if ( marcado == "no" ){
alert("You forgot to fill the "+ctrlTag+" field !");
}
}
}

function checktextor(ctrlName1, ctrlTag1, ctrlName2, ctrlTag2) {
   var foundCtrl = false;

   if ((eval("document.application."+ctrlName1+".value") != "" ) || (eval("document.application."+ctrlName2+".value") != "" )) {
      foundCtrl = true;
   }
   else {
      alert("You must fill the "+ctrlTag1+" or "+ctrlTag2+" fields !");
   }
   return foundCtrl;
}

function checkdata() {
   return confirm("You will not be allowed to change the data on your applicarion after having sent it. \nDo you confirm the operation ?");
}


function checkfile(ctrlName) {
   var foundCtrl = false;

	if (eval("document.application.fichero.value") != "" ) {
		if ((document.application.fichero.value.substr(document.application.fichero.value.length-3).toLowerCase() == "doc" ) || (document.application.fichero.value.substr(document.application.fichero.value.length-3).toLowerCase() == "rtf" ) || (document.application.fichero.value.substr(document.application.fichero.value.length-3).toLowerCase() == "pdf" ) ) {
		foundCtrl = true;
		}
		else {
			alert("The attached file format is not correct, please upload \n it in one of the following formats: doc, pdf or rtf.");
		}
	}
	else {
		alert("You forgot to attach the application form!");
	}
	return foundCtrl;
}



