function disable(){
	document.getElementById('submit').disabled = true;
}

function validaForm(){
	
	   		d = document.formulario; 
		   
		   //validar Nome
		   if (d.firstName.value == ""){
					 alert("The 'name' field must be filled!");
					 document.getElementById('submit').disabled = false;
					 d.firstName.focus();
					 return false;
		   }
		   
		   //validar Sobrenome
		   else if (d.lastName.value == ""){
					 alert("The 'last name' field must be filled!");
					 document.getElementById('submit').disabled = false;
					 d.lastName.focus();
					 return false;
		   }
	
		   //validar email
		   else if (d.email.value == ""){
					 alert("The 'email' field must be filled");
					 document.getElementById('submit').disabled = false;
					 d.email.focus();
					 return false;
		   }
		   
		   //Nacionalidade
		   else if (d.nationality.value == ""){
					 alert("The 'nationality' field must be filled!");
					 document.getElementById('submit').disabled = false;
					 d.nationality.focus();
					 return false;
		   }
		   
		   //Sexo
		   else if ( (d.gender[0].checked == false) && (d.gender[1].checked == false ) ){
					 alert("The 'gender' field must be filled!");
					 document.getElementById('submit').disabled = false;
					 return false;
		   }
		   
		   //Endereço
		   else if (d.address.value == ""){
					 alert("The 'address' field must be filled!");
					 document.getElementById('submit').disabled = false;
					 d.address.focus();
					 return false;
		   }
		   
		   //País
		   else if (d.country.value == ""){
					 alert("The 'country' field must be filled");
					 document.getElementById('submit').disabled = false;
					 d.country.focus();
					 return false;
		   }
		   
		   //Telefone
		   else if (d.phone.value == ""){
					 alert("The 'phone' field must be filled!");
					 document.getElementById('submit').disabled = false;
					 d.phone.focus();
					 return false;
		   }
		   
		   
		   //Resumo
		   if (d.summary.value == ""){
					 alert("The 'summary' field must be filled!");
					 document.getElementById('submit').disabled = false;
					 d.summary.focus();
					 return false;
		   }
	  
		   //CV
		   else if (d.file0.value == ""){
					 alert("The 'Complete CV' field must be filled!");
					 document.getElementById('submit').disabled = false;
					 d.file0.focus();
					 return false;
		   }
		   
		   //Proposição
		   else if (d.statement.value == ""){
					 alert("The 'Statement' field must be filled!");
					 document.getElementById('submit').disabled = false;
					 d.statement.focus();
					 return false;
		   }
		   
		   //Plano
		   else if (d.residency.value == ""){
					 alert("The 'Residency Plan' field must be filled!");
					 document.getElementById('submit').disabled = false;
					 d.residency.focus();
					 return false;
		   }
		   
		   else{
			   return true;
		   }
		   
}

function mascara(o,f){
   v_obj=o;
	v_fun=f;
	setTimeout("execmascara()",1);
}

function execmascara(){
	v_obj.value=v_fun(v_obj.value);
}

function soNumeros(v){
	return v.replace(/\D/g,"");
}

function telefone(v){
	
	v=v.replace(/\D/g,"");
	v=v.replace(/^(\d\d)(\d)/g,"($1) $2");
	v=v.replace(/(\d{4})(\d)/,"$1-$2");
	
	return v;
}


$(document).ready(function() {

	$('#summary').wordCount({counterElement:"summary_count"}, 200, "Max 200 words");

	$('#statement').wordCount({counterElement:"statement_count"}, 400, "Max 400 words");

	$('#brief1').wordCount({counterElement:"brief1_count"}, 100, "Max 100 words");

	$('#brief2').wordCount({counterElement:"brief2_count"}, 100, "Max 100 words");

	$('#brief3').wordCount({counterElement:"brief3_count"}, 100, "Max 100 words");

	$('#brief4').wordCount({counterElement:"brief4_count"}, 100, "Max 100 words");

	$('#brief5').wordCount({counterElement:"brief5_count"}, 100, "Max 100 words");



	$("#formPart1 a").click(function(){ $('#formPart1Open').toggle(); $('#formPart2Open').hide(); $('#formPart3Open').hide(); $('#formPart4Open').hide(); $('#formPart5Open').hide(); });

	$("#formPart2 a").click(function(){ $('#formPart2Open').toggle(); $('#formPart1Open').hide(); $('#formPart3Open').hide(); $('#formPart4Open').hide(); $('#formPart5Open').hide(); });

	$("#formPart3 a").click(function(){ $('#formPart3Open').toggle(); $('#formPart1Open').hide(); $('#formPart2Open').hide(); $('#formPart4Open').hide(); $('#formPart5Open').hide(); });

	$("#formPart4 a").click(function(){ $('#formPart4Open').toggle(); $('#formPart1Open').hide(); $('#formPart2Open').hide(); $('#formPart3Open').hide(); $('#formPart5Open').hide(); });

	$("#formPart5 a").click(function(){ $('#formPart5Open').toggle(); $('#formPart1Open').hide(); $('#formPart2Open').hide(); $('#formPart3Open').hide(); $('#formPart4Open').hide(); });

	

	$("a#abreFecha").click(

	function (evento) {

			evento.preventDefault();	

			$("#menu_en ul li.page-item-8 ul").slideToggle();

			$('#menu_en ul li.page-item-8 ul a').unbind('click');

      	}

	);

	

	$("#menu_en .page-item-11 a").hover(



		function () {

			$('#aboutHover').show();

      	}, 

      	function () {

        $('#aboutHover').hide();

		  }

	);

   

   $("#visualizarForm a").click(function(){

		$("#formPart1Open").show();

		$("#formPart2Open").show();

		$("#formPart3Open").show();

		$("#formPart4Open").show();

		$("#formPart5Open").show();

	});

   

	   $("#menu_en .page-item-8 a").hover(

      	function () {

			$('#peopleHover').show();

      	}, 

      	function () {

        $('#peopleHover').hide();

		  }

		);

	    $("#menu_en .page-item-106 a").hover(function () {

	        $('#peopleHover').hide();

		 });

	    $("#menu_en .page-item-107 a").hover(function () {

	        $('#peopleHover').hide();

		 });

	    $("#menu_en .page-item-108 a").hover(function () {

	        $('#peopleHover').hide();

		 });

	   

	   

	   $("#menu_en .page-item-7 a").hover(

      	function () {

			$('#partnersHover').show();

      	}, 

      	function () {

        $('#partnersHover').hide();

		  }

		);

	   

	   

	   $("#menu_en .page-item-5 a").hover(

      	function () {

			$('#applicationHover').show();

      	}, 

      	function () {

        $('#applicationHover').hide();

		  }

		);

	   $("#menu_en .page-item-72 a").hover(

      	function () {

			$('#sponsorsHover').show();

      	}, 

      	function () {

        $('#sponsorsHover').hide();

		  }

		);

	   

	   $("#menu_en .page-item-6 a").hover(

      	function () {

			$('#contactHover').show();

      	}, 

      	function () {

        $('#contactHover').hide();

		  }

		);

	   

	   

	   $("#menu_pt .page-item-11 a").hover(

      	function () {

			$('#sobreHover').show();

      	}, 

      	function () {

        $('#sobreHover').hide();

		  }

		);

	   

	   

	   $("#menu_pt .page-item-8 a").hover(

      	function () {

			$('#pessoasHover').show();

      	}, 

      	function () {

        $('#pessoasHover').hide();

		  }

		);

	   

	   

	   $("#menu_pt .page-item-7 a").hover(

      	function () {

			$('#parceirosHover').show();

      	}, 

      	function () {

        $('#parceirosHover').hide();

		  }

		);

	   

	   

	   $("#menu_pt .page-item-5 a").hover(

      	function () {

			$('#formularioHover').show();

      	}, 

      	function () {

        $('#formularioHover').hide();

		  }

		);

	   $("#menu_pt .page-item-72 a").hover(

      	function () {

			$('#patrocinioHover').show();

      	}, 

      	function () {

        $('#patrocinioHover').hide();

		  }

		);

	   

	   

	   $("#menu_pt .page-item-6 a").hover(

      	function () {

			$('#contatoHover').show();

      	}, 

      	function () {

        $('#contatoHover').hide();

		  }

		);

	   

	   

	   $("#form").submit(function() {

			var name = $(".input_nome").val();

			var username = $(".input_email").val();

			var password = $(".textarea_mensagem").val();



			var dataString = 'input_nome='+ name + '&input_email=' + username + '&input_mensagem=' + password;

			

			if(name=='' || username=='' || password==''){

				$('.success').fadeOut(200).hide();

				$('.sending').fadeOut(200).hide();

				$('.error').fadeOut(200).show();

			}

			else{

				$('.sending').fadeIn(200).show();

				$('.error').fadeOut(200).hide();

				$('.success').fadeOut(200).hide();

				$.ajax({

					type: "POST",

					url: "http://www.jacaarte.org/wp-content/themes/jaca/enviar_contato.php",

					data: dataString,

					success: function(){

					$('.success').fadeIn(200).show();

					$('.error').fadeOut(200).hide();

					$('.sending').fadeOut(200).hide();

				}

				});

			}

			return false;

		});	

	   

	   $("#formulario").submit(function() {

			var retorno = false;

			//validação individual dos campos do ITEM 5

			if(($("#projectTitle1").val() == '' || $("#brief1").val() == '' || $("#year1").val() == '' || $("#exhibitionTitle1").val() == '' || $("#refUrls1").val() == '' || $("#pressURLs1").val() == '' ) && ($("item1").val() != '')){

				$("item1").val() == '';

	   			retorno = true;

			}else{

				retorno = true;	

			}

			

			if(($("#projectTitle2").val() == '' || $("#brief2").val() == '' || $("#year2").val() == '' || $("#exhibitionTitle2").val() == '' || $("#refUrls2").val() == '' || $("#pressURLs2").val() == '' ) && ($("item2").val() != '')){

				$("item1").val() == '';

	   			retorno = true;

			}else{

				retorno = true;	

			}

			

			if(($("#projectTitle3").val() == '' || $("#brief3").val() == '' || $("#year3").val() == '' || $("#exhibitionTitle3").val() == '' || $("#refUrls3").val() == '' || $("#pressURLs3").val() == '' ) && ($("item3").val() != '')){

				$("item1").val() == '';

	   			retorno = true;

			}else{

				retorno = true;	

			}

			

			if(($("#projectTitle4").val() == '' || $("#brief4").val() == '' || $("#year4").val() == '' || $("#exhibitionTitle4").val() == '' || $("#refUrls4").val() == '' || $("#pressURLs4").val() == '' ) && ($("item4").val() != '')){

				$("item1").val() == '';

	   			retorno = true;

			}else{

				retorno = true;	

			}

			

			if(($("#projectTitle5").val() == '' || $("#brief5").val() == '' || $("#year5").val() == '' || $("#exhibitionTitle5").val() == '' || $("#refUrls5").val() == '' || $("#pressURLs5").val() == '' ) && ($("item5").val() != '')){

				$("item1").val() == '';

	   			retorno = true;

			}else{

				retorno = true;	

			}

			if(!validaForm()) retorno = false;
			
			else retorno = true;			

			return retorno;

		});	

 });

/* ------------------------ 1 -------------------------------- */

  function onSelectChange1(){

		var dropdown = document.getElementById("item1");

		var index = dropdown.selectedIndex;

		var ddVal = dropdown.options[index].value;

		var ddText = dropdown.options[index].text;

		 

		if(ddVal != '') {

			$('#item1Dados').show();

			output = ddText;

			document.getElementById("TipoMidia1").innerHTML = output;

			if(ddVal == 'Video'){

				$('#lblFile1').hide();

				$('#file1').hide();

				$('#lblUrl1').css('margin-top','15px');

			}else{

				$('#lblFile1').show();

				$('#file1').show();

				$('#lblUrl1').css('margin-top','-5px');

			}

		}

	}



	function sendBack1(){

		$('#item1Dados').hide();

		var titulo1 = document.getElementById("projectTitle1").value;

		if(titulo1 == ''){

			titulo1 = '&nbsp;';

		}

		document.getElementById("tituloNoItem1").innerHTML = titulo1;

		$('#formPart5Open').show();

	}

	function openDiv1(){

		$('#item1Dados').show();

		// melhorar isso aqui.

		document.getElementById("TipoMidia1").innerHTML = $('#item1').val();

	}



/* ----------------------------------------------------------- */

/* ------------------------ 2 -------------------------------- */

  function onSelectChange2(){

		var dropdown = document.getElementById("item2");

		var index = dropdown.selectedIndex;

		var ddVa2 = dropdown.options[index].value;

		var ddText = dropdown.options[index].text;

		 

		if(ddVa2 != '') {

			$('#item2Dados').show();

			output = ddText;

			document.getElementById("TipoMidia2").innerHTML = output;

			

			if(ddVa2 == 'Video'){

				$('#lblFile2').hide();

				$('#file2').hide();

				$('#lblUrl2').css('margin-top','15px');

			}else{

				$('#lblFile2').show();

				$('#file2').show();

				$('#lblUrl2').css('margin-top','-5px');

			}

		}

	}



	function sendBack2(){

		$('#item2Dados').hide();

		var titulo2 = document.getElementById("projectTitle2").value;

		if(titulo2 == ''){

			titulo2 = '&nbsp;';

		}

		document.getElementById("tituloNoItem2").innerHTML = titulo2;

		$('#formPart5Open').show();

	}

	function openDiv2(){

		$('#item2Dados').show();

	}

/* ----------------------------------------------------------- */

/* ------------------------ 3 -------------------------------- */

  function onSelectChange3(){

		var dropdown = document.getElementById("item3");

		var index = dropdown.selectedIndex;

		var ddVa3 = dropdown.options[index].value;

		var ddText = dropdown.options[index].text;

		 

		if(ddVa3 != '') {

			$('#item3Dados').show();

			output = ddText;

			document.getElementById("TipoMidia3").innerHTML = output;

			

			if(ddVa3 == 'Video'){

				$('#lblFile3').hide();

				$('#file3').hide();

				$('#lblUrl3').css('margin-top','15px');

			}else{

				$('#lblFile3').show();

				$('#file3').show();

				$('#lblUrl3').css('margin-top','-5px');

			}

		}

	}



	function sendBack3(){

		$('#item3Dados').hide();

		var titulo3 = document.getElementById("projectTitle3").value;

		if(titulo3 == ''){

			titulo3 = '&nbsp;';

		}

		document.getElementById("tituloNoItem3").innerHTML = titulo3;

		$('#formPart5Open').show();

	}

	function openDiv3(){

		$('#item3Dados').show();

	}

/* ----------------------------------------------------------- */

/* ------------------------ 4 -------------------------------- */

  function onSelectChange4(){

		var dropdown = document.getElementById("item4");

		var index = dropdown.selectedIndex;

		var ddVa4 = dropdown.options[index].value;

		var ddText = dropdown.options[index].text;

		 

		if(ddVa4 != '') {

			$('#item4Dados').show();

			output = ddText;

			document.getElementById("TipoMidia4").innerHTML = output;

			

			if(ddVal == 'Video'){

				$('#lblFile4').hide();

				$('#file4').hide();

				$('#lblUrl4').css('margin-top','15px');

			}else{

				$('#lblFile4').show();

				$('#file4').show();

				$('#lblUrl4').css('margin-top','-5px');

			}

		}

	}



	function sendBack4(){

		$('#item4Dados').hide();

		var titulo4 = document.getElementById("projectTitle4").value;

		if(titulo4 == ''){

			titulo4 = '&nbsp;';

		}

		document.getElementById("tituloNoItem4").innerHTML = titulo4;

		$('#formPart5Open').show();

	}

	function openDiv4(){

		$('#item4Dados').show();

	}

/* ----------------------------------------------------------- */

/* ------------------------ 5 -------------------------------- */

  function onSelectChange5(){

		var dropdown = document.getElementById("item5");

		var index = dropdown.selectedIndex;

		var ddVa5 = dropdown.options[index].value;

		var ddText = dropdown.options[index].text;

		 

		if(ddVa5 != '') {

			$('#item5Dados').show();

			output = ddText;

			document.getElementById("TipoMidia5").innerHTML = output;

			

			if(ddVa5 == 'Video'){

				$('#lblFile5').hide();

				$('#file5').hide();

				$('#lblUrl5').css('margin-top','15px');

			}else{

				$('#lblFile5').show();

				$('#file5').show();

				$('#lblUrl5').css('margin-top','-5px');

			}

		}

	}



	function sendBack5(){

		$('#item5Dados').hide();

		var titulo5 = document.getElementById("projectTitle5").value;

		if(titulo5 == ''){

			titulo5 = '&nbsp;';

		}

		document.getElementById("tituloNoItem5").innerHTML = titulo5;

		$('#formPart5Open').show();

	}

	function openDiv5(){

		$('#item5Dados').show();

	}

/* ----------------------------------------------------------- */



	function validaFilePDF(){

		var ext = $('#cv').val().split('.').pop().toLowerCase();

		if(ext != 'pdf'){

			alert('Its not a PDF file.');

			return false;

		}else{

			return true;

		}

	}

	function validaFile1(){

		var ext = $('#file1').val().split('.').pop().toLowerCase();

		var tipo = $("#TipoMidia1").text();		

		if(tipo == 'Audio'){

			if(ext != 'mp3'){

				alert('Send only mp3 files');

				return false;

			}else{

				return true;

			}

		}

		if(tipo == 'Image'){

			if(ext != 'jpg' || ext != 'png' || ext != 'gif'){

				alert('Send only .jpg, .gif, .png files');

				return false;

			}else{

				return true;

			}

		}



	}

	function validaFile2(){

		var ext = $('#file2').val().split('.').pop().toLowerCase();

		var tipo = $("#TipoMidia2").text();		

		if(tipo == 'Audio'){

			if(ext != 'mp3'){

				alert('Send only mp3 files');

				return false;

			}else{

				return true;

			}

		}

		if(tipo == 'Image'){

			if(ext != 'jpg' || ext != 'png' || ext != 'gif'){

				alert('Send only .jpg, .gif, .png files');

				return false;

			}else{

				return true;

			}

		}



	}

	function validaFile3(){

		var ext = $('#file3').val().split('.').pop().toLowerCase();

		var tipo = $("#TipoMidia3").text();		

		if(tipo == 'Audio'){

			if(ext != 'mp3'){

				alert('Send only mp3 files');

				return false;

			}else{

				return true;

			}

		}

		if(tipo == 'Image'){

			if(ext != 'jpg' || ext != 'png' || ext != 'gif'){

				alert('Send only .jpg, .gif, .png files');

				return false;

			}else{

				return true;

			}

		}



	}

	function validaFile4(){

		var ext = $('#file4').val().split('.').pop().toLowerCase();

		var tipo = $("#TipoMidia4").text();		

		if(tipo == 'Audio'){

			if(ext != 'mp3'){

				alert('Send only mp3 files');

				return false;

			}else{

				return true;

			}

		}

		if(tipo == 'Image'){

			if(ext != 'jpg' || ext != 'png' || ext != 'gif'){

				alert('Send only .jpg, .gif, .png files');

				return false;

			}else{

				return true;

			}

		}



	}

	function validaFile5(){

		var ext = $('#file5').val().split('.').pop().toLowerCase();

		var tipo = $("#TipoMidia5").text();		

		if(tipo == 'Audio'){

			if(ext != 'mp3'){

				alert('Send only mp3 files');

				return false;

			}else{

				return true;

			}

		}

		if(tipo == 'Image'){

			if(ext != 'jpg' || ext != 'png' || ext != 'gif'){

				alert('Send only .jpg, .gif, .png files');

				return false;

			}else{

				return true;

			}

		}



	}