// JavaScript Document
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

//Abrir Infograficos
	
openInfograficoAtletismo = function(file) {
	win = window.open('http://www.timebrasil.com.br/esportes/infograficos/AT/index.html', 'infografico', 'width=700, height=420, scrollbars=0');
	win.focus();
}

openInfograficoBasquete = function(file) {
	win = window.open('http://www.timebrasil.com.br/esportes/infograficos/BK/index.html', 'infografico', 'width=700, height=420, scrollbars=0');
	win.focus();
}

openInfograficoHandebol = function(file) {
	win = window.open('http://www.timebrasil.com.br/esportes/infograficos/HB/index.html', 'infografico', 'width=700, height=420, scrollbars=0');
	win.focus();
}

openInfograficoJudo = function(file) {
	win = window.open('http://www.timebrasil.com.br/esportes/infograficos/JU/index.html', 'infografico', 'width=700, height=420, scrollbars=0');
	win.focus();
}

openInfograficoNatacao = function(file) {
	win = window.open('http://www.timebrasil.com.br/esportes/infograficos/SW/index.html', 'infografico', 'width=700, height=420, scrollbars=0');
	win.focus();
}

openInfograficoVolei = function(file) {
	win = window.open('http://www.timebrasil.com.br/esportes/infograficos/VO/index.html', 'infografico', 'width=700, height=420, scrollbars=0');
	win.focus();
}

openInfograficoTenisdemesa = function(file) {
	win = window.open('http://www.timebrasil.com.br/esportes/infograficos/TT/index.html', 'infografico', 'width=700, height=420, scrollbars=0');
	win.focus();
}

openInfograficoGinasticaRitmica = function(file) {
	win = window.open('http://www.timebrasil.com.br/esportes/infograficos/GR/index.html', 'infografico', 'width=700, height=420, scrollbars=0');
	win.focus();
}

openInfograficoCiclismo = function(file) {
	win = window.open('http://www.timebrasil.com.br/esportes/infograficos/CX/index.html', 'infografico', 'width=700, height=420, scrollbars=0');
	win.focus();
}

var isShort = false;
function ValidateForm(form)
{
	var isOK = true;
	var msg = "Os erros abaixo foram detectados:\n";
	var name = ""
	isShort = false;
	
	var status_f_turno;
	var f_turno_manha = document.getElementById('f_turno_manha').checked;
	var f_turno_tarde = document.getElementById('f_turno_tarde').checked;
	var f_turno_noite = document.getElementById('f_turno_noite').checked;
	var f_turno_integral = document.getElementById('f_turno_integral').checked;	
	
	
	var status_evento;
	var f_evento_oe_fase1 = document.getElementById('f_evento_oe_fase1').checked;
	var f_evento_oe_fase2 = document.getElementById('f_evento_oe_fase2').checked;
	var f_evento_ou = document.getElementById('f_evento_ou').checked;
	
	
	var status_evento_participou = -1;
	var status_anoevento_participou = -1;
	
	if(document.getElementById('jafoi_sim').checked==true){
		
		if(document.getElementById('evento').value==''){
				status_evento_participou = 0;
			}else{
				status_evento_participou = 1;
				}
				
		if(document.getElementById('ano_evento').value==''){
				status_anoevento_participou = 0;
			}else{
				status_anoevento_participou = 1;
				}
		
		
		}
	
	if(f_turno_manha==true){
		status_f_turno = 1;
	}else {
		status_f_turno = 0;
	}
	
	
	if(f_turno_tarde==true){
		status_f_turno = 1;
	}else if(status_f_turno!=1){
		status_f_turno = 0;
	}
	
	if(f_turno_noite==true){
		status_f_turno = 1;
	}else if(status_f_turno!=1){
				status_f_turno = 0;
	}
		
	if(f_turno_integral==true){
		status_f_turno = 1;
	}else if(status_f_turno!=1){
				status_f_turno = 0;
	}
	
	
	
	
	
	if(f_evento_oe_fase1==true){
		status_evento = 1;
	}else {
		status_evento = 0;
	}
	
	
	if(f_evento_oe_fase2==true){
		status_evento = 1;
	}else if(status_evento!=1){
		status_evento = 0;
	}
	
	if(f_evento_ou==true){
		status_evento = 1;
	}else if(status_evento!=1){
				status_evento = 0;
	}
		

	
	
	
	
	
	
	
	
	for (var i=0; i < form.elements.length; i++) 
	{
		var element = form.elements[i];
		if(form[element.name + "_tag"] != undefined)
		{
			var tag = form[element.name + "_tag"].value;
			if (isCommom(element.type))
			{
				if (element.value == "")
				{
					msg += "O campo [" + tag + "] precisa ser preenchido.\n";
					isOK = false;
				}
				else
				{
					if(element.name == "campo_alternativo_1" || element.name == "campo_alternativo_2")
					{
						if((isShort && element.value.length > 250) || (!isShort && element.value.length > 560))
						{
							msg += "O total de caracteres digitados no campo [" + tag + "] é " + element.value.length + ".\n";
							if (isShort) msg += "O total máximo é 250 (Curta-Metragem).\n"
							if (!isShort) msg += "O total máximo é 560 (Longa-Metragem).\n"
							isOK = false;
						}
					}
				}
			}
			else
			{
				if(element.type == "radio" && validateCheckRadio(element.name) == false && name != element.name)
				{
					msg += "É necessário escolher um valor para o campo [" + tag + "].\n";
					isOK = false;
					name = element.name;
				}
				
				if(element.type == "checkbox" && element.name != "regulamento" && validateCheckRadio(element.name) == false && name != element.name)
				{
					msg += "É necessário escolher um valor para o campo [" + tag + "].\n";
					isOK = false;
					name = element.name;
				}
				
				if(element.type == "checkbox" && element.name == "regulamento" && element.checked == false)
				{
					msg += "É necessário concordar com o regulamento para efetivar a inscrição.\n";
					isOK = false;
				}
			}
		}
	}
	if (isOK){
		
		if(status_f_turno==0){
		
			msg = msg + 'É necessário escolher um valor para o campo [Período Disponível].\n';
		}
		
		if(status_evento==0){
		
			msg = msg + 'É necessário escolher um valor para o campo [Deseja ser voluntário nas].\n';
		}
		
		if(status_evento_participou==0){
			
			msg = msg + 'É necessário escolher um valor para o campo [Qual evento].\n';
			
			}
		
		if(status_anoevento_participou==0){
			
			msg = msg + 'É necessário escolher um valor para o campo [Em que ano].\n';
			
			}
		
		if(status_f_turno==1 & status_evento==1 & status_evento_participou != 0 & status_anoevento_participou != 0){
		
			form.submit();
		}else{
			alert(msg);
			
			}
	
	}
	else{
		
		if(status_f_turno==0){
		
			msg = msg + 'É necessário escolher um valor para o campo [Período Disponível].\n';
		}
		
		if(status_evento==0){
		
			msg = msg + 'É necessário escolher um valor para o campo [Deseja ser voluntário nas].\n';
		}
		
		if(status_evento_participou==0){
			
			msg = msg + 'É necessário escolher um valor para o campo [Qual evento].\n';
			
			}
		
		if(status_anoevento_participou==0){
			
			msg = msg + 'É necessário escolher um valor para o campo [Em que ano].\n';
			
			}
		
		alert(msg);
	}
		
		
	
	
			
}

function isCommom(strType)
{
	var ret = false;
	switch(strType)
	{
		case "select-one":
		case "text":
		case "textarea":
			ret = true
		break;
	}
	return ret;
}

function validateCheckRadio(nameField)
{
	
	var field = document.voluntarios[nameField];
	var ret = false;
	for (i = 0; i < field.length; i++)
	{
		ret = field[i].checked;
		if (nameField == "categoria" && ret)
		{
			if (field[i].value.substring(0, 5) == "Longa") 
				isShort = false;
			if (field[i].value.substring(0, 5) == "Curta") 
				isShort = true;
		}
		if (ret) break;
	}
	return ret;
}


