﻿// JScript File

$(document).ready(function() {

	//Select all anchor tag with rel set to tooltip
	$('span[rel=tooltip]').mouseover(function(e) {
		
		//Grab the title attribute's value and assign it to a variable
		var tip = $(this).attr('title');	
		
		//Remove the title attribute's to avoid the native tooltip from the browser
		$(this).attr('title','');
		
		//Append the tooltip template and its value
		$(this).append('<div id="tooltip"><div class="tipHeader"></div><div class="tipBody">' + tip + '</div><div class="tipFooter"></div></div>');		
				
		//Show the tooltip with faceIn effect
		$('#tooltip').fadeIn('500');
		$('#tooltip').fadeTo('10',0.9);
		
	}).mousemove(function(e) {
	
		//Keep changing the X and Y axis for the tooltip, thus, the tooltip move along with the mouse
		$('#tooltip').css('top', e.pageY + 10 );
		$('#tooltip').css('left', e.pageX + 20 );
		    
	}).mouseout(function() {
	
		//Put back the title attribute's value
		$(this).attr('title',$('.tipBody').html());
	
		//Remove the appended tooltip template
		$(this).children('div#tooltip').remove();
		
	}).css('cursor','pointer');	
	
	//Select all anchor tag with rel set to tooltip
	$('a[rel=tooltip]').mouseover(function(e) {
		
		//Grab the title attribute's value and assign it to a variable
		var tip = $(this).attr('title');	
		
		//Remove the title attribute's to avoid the native tooltip from the browser
		$(this).attr('title','');
		
		//Append the tooltip template and its value
		$(this).append('<div id="tooltip"><div class="tipHeader"></div><div class="tipBody">' + tip + '</div><div class="tipFooter"></div></div>');		
				
		//Show the tooltip with faceIn effect
		$('#tooltip').fadeIn('500');
		$('#tooltip').fadeTo('10',0.9);
		
	}).mousemove(function(e) {
	
		//Keep changing the X and Y axis for the tooltip, thus, the tooltip move along with the mouse
		$('#tooltip').css('top', e.pageY + 10 );
		$('#tooltip').css('left', e.pageX + 20 );
		
	}).mouseout(function() {
	
		//Put back the title attribute's value
		$(this).attr('title',$('.tipBody').html());
	
		//Remove the appended tooltip template
		$(this).children('div#tooltip').remove();
		
	}).css('cursor','pointer');	
	  
});

function validateSelectionCheckBox(elemento)
{
       
    if(elemento.checked == true)
    {
        $(elemento).attr('checked','checked');
    }
    else { $(elemento).removeAttr('checked');}
}

function alteraVisibilidadeDiv()
{
    var elementoAtual = $('#ctl00_cphConteudo_hdnDivShow').val();   
    
    for(i = 5; i < 17; i++)
    {
        if (i <= elementoAtual  && elementoAtual != "")
        { $("#div" + i).removeAttr("style"); }
    }
}
function excludeShow()
{   ex = 0;
    $('a[id*=hlkOpcao] img').each(function(){
        
        if($(this).attr('src') != "img/foto_enquete.jpg")
        { 
            $("#divCK" + ex).removeAttr("style");            
        }
        ex++;
    });
}

$(document).ready(function(){    
    
    alteraVisibilidadeDiv();
    excludeShow();
    $('input[id*=chkOpcaoExclusaoImagemLinks]').each(function(){
        var elemento = ($(this).attr('id')).substr(($(this).attr('id')).length - 1);        
        $(this).click(function(){
            $('#ctl00_cphConteudo_hdnExclude').val(elemento);
            $("#ctl00_cphConteudo_hlkOpcao" + elemento).attr('name','modal');
        });
    
    });
    
    
    var index = 5;
    $('#ctl00_cphConteudo_btnAddOpcao').click(function(){
        $("#div" + index).fadeIn();
        $('#ctl00_cphConteudo_hdnDivShow').val(index);        
        index++;
	
	  $('a[name=modal]').click( chamaModal );
      return false;  
    });

    $('input[name$=EspecificoComponente]').click(function(){
        var id = $(this).attr('id');
        
        $('input[name$=EspecificoComponente]').each(function(){
            if($(this).attr('id') ==  id)
            {
                $(this).attr('checked','checked');
                $('#ctl00_cphConteudo_hdnValorValue').val($(this).attr('value'));
            }
            else { $(this).removeAttr('checked');}
        });
    });
    
    $('a[name=modal]').click(function(){
        $('#ctl00_cphConteudo_hdnControleAtual').val(($(this).attr('id')).substr(($(this).attr('id')).length - 1));       
        $('#ctl00_cphConteudo_fulImagem').val("");
	    $('#ctl00_cphConteudo_txtLinkYouTube').val("");
	    $('#ctl00_cphConteudo_lblValida').text("");    	
	    
//	    if($(this).attr('id') == 'ctl00_cphConteudo_hlkOpcao0')
//	    { $('#ctl00_cphConteudo_hdnAlternate').val("1");  }
    });
        
    $('#ctl00_cphConteudo_btnSalvarImagem').click(function(){      
    
         if ($('#ctl00_cphConteudo_fulImagem').val() == "" && $('#ctl00_cphConteudo_txtLinkYouTube').val() == "")
         {
            $('#ctl00_cphConteudo_lblValida').text('Informe pelo menos uma das opções.');
            return false;
         } 
         else if ($('#ctl00_cphConteudo_fulImagem').val() != "" && $('#ctl00_cphConteudo_txtLinkYouTube').val() != "")
         {
            $('#ctl00_cphConteudo_lblValida').text('Informe somente uma das opções.');
            return false;
         }
         else if ($('#ctl00_cphConteudo_fulImagem').val() != "")
         {
         
            var arqExpReg  = /^[\s\S]+\.(png|PNG|jpg|JPG|jpeg|JPEG|gif|GIF)$/;
            
              if (document.getElementById("ctl00_cphConteudo_fulImagem").value.length != 0 )
                {  if (!document.getElementById("ctl00_cphConteudo_fulImagem").value.match(arqExpReg)){
                        $('#ctl00_cphConteudo_lblValida').text('Formato de Arquivo inválido.');
                        return false;
                    }
                }  
         } 
         else if($('#ctl00_cphConteudo_txtLinkYouTube').val() != "")
         {
            var regex = /^(http|https):\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?$/;
            if (!document.getElementById("ctl00_cphConteudo_txtLinkYouTube").value.match(regex)){
                $('#ctl00_cphConteudo_lblValida').text('URL inválida.');
                return false;
            }
            else 
            {   
                $('#ctl00_cphConteudo_hdnLinks').val( $('#ctl00_cphConteudo_hdnControleAtual').val() + ">" + $('#ctl00_cphConteudo_txtLinkYouTube').val());
            }
         }
         
         return true;
    });


    var chamaModal = (function(e) {
		e.preventDefault();
		
		var id = $(this).attr('href');
	
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		$('#mask').css({'width':maskWidth,'height':maskHeight});

		$('#mask').fadeIn(1000);	
		$('#mask').fadeTo("normal",0.8);	
	
		//Get the window height and width
		var winH = $(window).height()/2;
		var winW = $(window).width();
              
		$(id).css('top',  winH/2-$(id).height()/2 + 400);
		$(id).css('left', winW/2-$(id).width()/2);
	
		$(id).fadeIn(2000); 
	
	});
	
	$('a[name=modal]').click( chamaModal );
	
	$('.window .close').click(function (e) {
		e.preventDefault();
		
		$('#mask').hide();
		$('.window').hide();
		
		$('#ctl00_cphConteudo_fulImagem').val("");
		$('#ctl00_cphConteudo_txtLinkYouTube').val("");
		
	});		
	
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});		
    
    
    $('a[Task=manager]').click(function(){          
       var url = "minhasTarefas.aspx?task=" + $('input[id*='+ ($(this).attr('id')).substring(35,40) +'_hdnIDTask]').val() + "&ds=" + $('input[id*='+ ($(this).attr('id')).substring(35,40) +'_hdnDesafio]').val() + "&opt=" + $('select[id*='+ ($(this).attr('id')).substring(35,40) +'_ddlOpcaoResultado]').val() + "ddl";       
       $(this).attr("url", url.toString());
       
       confirm("","Ao gravar o status desta tarefa será impossível alterá-lo. Deseja realmente alterar o status desta tarefa?", url );       
    });
    
//    var contador = 5;
//    $('#ctl00_cphConteudo_hlkAdicionarOpcao').click(function(){            
//        $(this).append("<br /><a runat='server' href='#dialog' name='modal' id='ctl00_cphConteudo_hlkOpcao" + contador +"' ><img runat='server' style='position:relative; left:130%; cursor:pointer;' src='img/foto_enquete.jpg' id='ctl00_cphConteudo_imgOpcao" + contador + "' /></a><span runat='server' style='position:relative; font-size:11px; left:130%;' ID='ctl00_cphConteudo_lblOpcao" + contador + "'>Opção " + contador + ":</span><br /><input type='text' style='position:relative;left:130%;' runat='server' ID='ctl00_cphConteudo_txtOpcao" + contador + "' /><br />");
//        contador++;
//    });
//        
    $('#ctl00_cphConteudo_mostrarModeloXLS').hide();    
    $('#ctl00_cphConteudo_chkVerModelo').click(function(){      
      $('#ctl00_cphConteudo_mostrarModeloXLS').toggle("normal");
      });
      
    $('#ctl00_cphConteudo_hlkCalcular').click(function(){        
        var totalTarefas = 0;
        var totalAtual = 0;
        $('#ctl00_cphConteudo_pnlMeuHistoricoParticipacao select option:selected').each(function(){            
            totalTarefas = parseInt(totalTarefas) + 1;
            var i = parseInt($(this).val());
            if(i != 0)
            {
                totalAtual = parseInt(totalAtual) + 1;
            }
        });
        var porcentagem = (totalAtual * 100 / totalTarefas);
        $('#ctl00_cphConteudo_lblResultado').text(porcentagem.toFixed(1) + " %");
     });
            
});


$(document).ready(function(){

    $('#ctl00_cphConteudo_btnVotar').click(function(){
    
    var msg = "";
    var valida = false;
    var newTarget = false;
    $('input[name$=EspecificoComponente]').each(function(){
        if($(this).attr('checked') == true)
        {
           valida = true;
        }
        newTarget == true;
     });
     
     if(valida == false && newTarget == true){
         msg = "Selecione uma opção."
         if(msg != "")
        {
            Abrir("<h2 class='Avermelho'></h2>\n<p style='color:red;'><b>" + msg + "</b></p>");
            return false;
        }
     }
     else { return true;}
    
});
    
    $('#ctl00_cphConteudo_btnCriarEnquete').click(function(){
        $('#ctl00_cphConteudo_hdnPrincipal').val($('#ctl00_cphConteudo_hlkOpcao0 > img').attr('src'));
        
        var msg = ""; 
        var DataServidor = $('#ctl00_cphConteudo_hdnDataServidor').val();
        var HoraServidor = $('#ctl00_cphConteudo_hdnHoraServidor').val();
        
        var DataCliente = (document.getElementById("ctl00_cphConteudo_dataResultado").value).split("/");
        DataCliente = DataCliente[2] +  DataCliente[1] + DataCliente[0];
        var HoraCliente = document.getElementById("ctl00_cphConteudo_ddlHoraAberta").value + document.getElementById("ctl00_cphConteudo_ddlMinAbertura").value
    
        if(document.getElementById("ctl00_cphConteudo_txtPergunta").value == "")   
            msg += "<h1>Informe uma pergunta para a enquete.</h1>";
        
        if(document.getElementById("ctl00_cphConteudo_txtOpcao1").value == "")   
            msg += "<h1>Opção 1 deve ser informada.</h1>";
        
        if(document.getElementById("ctl00_cphConteudo_txtOpcao2").value == "")   
            msg += "<h1>Opção 2 deve ser informada.</h1>";
            
        if(document.getElementById("ctl00_cphConteudo_dataResultado").value == "")   
            msg += "<h1>Data Resultado deve ser informada.</h1>";    
        
        if(DataCliente < DataServidor)        
            msg += "<h1>Data término da enquete inferior à data atual.</h1>";        
        else if (HoraCliente < HoraServidor && DataCliente == DataServidor)        
            msg += "<h1>Hora inferior à hora atual.</h1>";        
        
        
        if(msg != "")
        {
            Abrir("<h2 class='Avermelho'></h2>\n<p>" + msg + "</p>");
            return false;
        }
        
         
    });

});



    


function Rejected(fileName, size, maxSize){
  var addMessage = (maxSize >= 0)?("exceeds "+maxSize+" bytes"):("-- session lost");
  alert("File "+fileName+" is rejected \nIts size ("+size+" bytes) "+addMessage);
}


function confirm(titulo,texto,pagina) {   
  jQuery.noConflict();
  jQuery('#dialog p').html(texto).css({'font-family' : 'verdana', 'font-size' : '11px'});   
  jQuery('#dialog p').dialog({
  title: titulo,  
  draggable: true,
  resizable: false,
  buttons: {
            Confirmar: function(){
            window.location.href = pagina;
            jQuery(this).dialog('close');            
            },
            Cancelar: function(){            
            jQuery(this).dialog('close');
            return false;
            }
        }
 });
   jQuery('#dialog').dialog('open');
}

function HideField(idDiv, idCbx)
{
    if(document.getElementById(idCbx).checked)
    {
        document.getElementById(idDiv).style.display = "none";
    }
    else
    {
        document.getElementById(idDiv).style.display = "block";
    }
}

function mask(isNum, event, field, mask, maxLength) 
{
	var keyCode;
	if (event.srcElement)
		keyCode = event.keyCode;
	else if (event.target)
		keyCode = event.which;
	var maskStack = new Array();
	var isDynMask = false;
	if (mask.indexOf('[') != -1)
		isDynMask = true;
	var length = mask.length;
	for (var i = 0; i < length; i++)
		maskStack.push(mask.charAt(i));
	var value = field.value;
	var i = value.length;
	if (keyCode == 0 || keyCode == 8)
		return true;
	//código adaptado para aceitar X (maiúsculo) ou x (minúsculo), além de números
	if (isNum && (keyCode < 48 || keyCode > 57) && (keyCode != 88) && (keyCode != 120))
		return false;
	if (!isDynMask && i < length) {
		if (maskStack.toString().indexOf(String.fromCharCode(keyCode)) != -1 && keyCode != 8) {
			return false;
		} else {
			if (keyCode != 8) {
				if (maskStack[i] != '#') {
					var old = field.value;
					field.value = old + maskStack[i];
				}			
			}
			if (autoTab(field, keyCode, length)) {
				if (!document.layers) {
					return true;
				} else if (keyCode != 8) {
					field.value += String.fromCharCode(keyCode);
					return false;
				} else {
					return true;
				}
			} else {
				return false;
			}				
		}
	} else if (isDynMask) { 
		var maskChars = "";
		for (var j = 0; j < maskStack.length; j++)
			if (maskStack[j] != '#' && maskStack[j] != '[' && maskStack[j] != ']')
				maskChars += maskStack[j];
		var tempValue = "";
		for (var j = 0; j < value.length; j++) {
			if (maskChars.indexOf(value.charAt(j)) == -1)
				tempValue += value.charAt(j);
		}
		value = tempValue + String.fromCharCode(keyCode);
		if (maskChars.indexOf(String.fromCharCode(keyCode)) != -1) {
			return false;
		} else {
			var staticMask = mask.substring(mask.indexOf(']') + 1);
			var dynMask = mask.substring(mask.indexOf('[') + 1, mask.indexOf(']'));
			var realMask = new Array;
			if (mask.indexOf('[') == 0) {
				var countStaticMask = staticMask.length - 1;
				var countDynMask = dynMask.length - 1;
				for (var j = value.length - 1; j >= 0; j--) {
					if (countStaticMask >= 0) {
						realMask.push(staticMask.charAt(countStaticMask));
						countStaticMask--; 
					} 
					if (countStaticMask < 0) {
						if (countDynMask >= 0) {
							if (dynMask.charAt(countDynMask) != '#') {
								realMask.push(dynMask.charAt(countDynMask));
								countDynMask--;
							}
						}
						if (countDynMask == -1) {
							countDynMask = dynMask.length - 1;
						}
						realMask.push(dynMask.charAt(countDynMask));
						countDynMask--; 
					}
				}
			}
			var result = "";
			var countValue = 0;
			while (realMask.length > 0) {
				var c = realMask.pop();	
				if (c == '#') {
					result += value.charAt(countValue);
					countValue++;	
				} else {
					result += c;
				}
			}
			field.value = result;
			if (maxLength != undefined &&  value.length == maxLength) {
				var form = field.form;
				for (var i = 0; i < form.elements.length; i++) {
					if (form.elements[i] == field) {
						field.blur();
						//if alterado para quando a máscara for utilizada no último campo, não dê mensagem de erro quando tentar colocar o foco no "Salvar"
						//if (form.elements[i + 1] != null)										 
						if ((form.elements[i + 1] != null) && (form.elements[i + 1].name != "METHOD"))
							form.elements[i + 1].focus();
						break;
					}
				}
			}
			return false;
		}
	} else {
		return false;
	}
	function autoTab(field, keyCode, length) {
		var i = field.value.length;
		if (i == length - 1) {
			field.value += String.fromCharCode(keyCode);
			var form = field.form;
			for (var i = 0; i < form.elements.length; i++) {
				if (form.elements[i] == field) {
					field.blur();										 
					//if alterado para quando a máscara for utilizada no último campo, não dê mensagem de erro quando tentar colocar o foco no "Salvar"
					//if (form.elements[i + 1] != null)
					if ((form.elements[i + 1] != null) && (form.elements[i + 1].name != "METHOD"))
						form.elements[i + 1].focus();
					break;
				}
			}
			return false;
		} else {
			return true;
		}	
	}
}   

function Abrir(strMensagem)
{
	$(document).ready(function(){
		 jQuery.facebox(strMensagem);
	})
}

function alternateMenu(id, opcao)
{
    
    $(function(){
        var paineis = new Array('dadosdagincana','premiacao','tarefas','patrocinadores');
        var element = document.getElementById(id);
        var conteudo;
        for ( i=0; i < paineis.length; i++)
        {   conteudo = document.getElementById(paineis[i]);
            if (i == opcao)
            {   
                $(element).css("class","active");
                $(conteudo).css("display","block");
            }
            else 
            {
                $(conteudo).css("display","none");
            }
        }
    
    });
}

function validaVencedor()
{
    var msg = ""; 
    
    if(document.getElementById("ctl00_cphConteudo_rblFirst").checked == false && document.getElementById("ctl00_cphConteudo_rblSecond").checked == false && document.getElementById("ctl00_cphConteudo_rblThird").checked == false)
    {
        msg += "<h1>Selecione uma colocação para os vencedores.</h1>";
    }
    else
    {
        //if (document.getElementById(ctl00_cphConteudo_lbxParticipantesPost)
    
    }
    
    
    if(msg != "")
    {
        Abrir("<h2 class='Avermelho'></h2>\n<p>" + msg + "</p>");
        return false;
    }


}

function validaTituloEmail()
{
    var msg = ""; 
    if(document.getElementById("ctl00_cphConteudo_txtTituloEmail").value == ""){ msg += "<h1>Informe o 'Título' do e-mail.</h1>"; }      

    if(msg != "")
    {
        Abrir("<h2 class='Avermelho'></h2>\n<p>" + msg + "</p>");
        return false;
    }
}

function getUrlGincana(id){
    var paineis = new Array('dadosGincana.aspx','premiacoes.aspx','tarefas.aspx','patrocinadores.aspx');
    window.parent.location.href = paineis[id];    
}

function validaPremiacao()
{
  var msg = "";  
  if(document.getElementById("ctl00_cphConteudo_txtDescricaoPremiacao").value == ""){ msg += "<h1>Informe a 'Descrição' da Premiação.</h1>"; }      
  
  if(msg != "")
    {
        Abrir("<h2 class='Avermelho'></h2>\n<p>" + msg + "</p>");
        return false;
    }
}


function validaRedefinicaoSenha()
{
    var msg = "";
    var emailExpReg = /^([0-9a-z]+([_.-]?[0-9a-z]+)*@[0-9a-z]+[0-9,a-z,,.,-]*(.){1}[a-z]{2,4})+$/;
       
    if(document.getElementById("txtNomeLogin").value == "")
       {  msg += "<h1>Preencha o campo e-mail. </h1>"; }              
    else if (!document.getElementById("txtNomeLogin").value.match(emailExpReg))
    { msg += "<h1>Email inválido </h1>"; }
    if(document.getElementById("txtCaptcha").value == ""){ msg += "<h1>Preencha o código de segurança.</h1>"; }
    if(msg != "")
    {
        Abrir("<h2 class='Avermelho'></h2>\n<p>" + msg + "</p>");
        return false;
    }


}

function validaSenhaAtual()
{

    var msg = "";

    if(document.getElementById("ctl00_cphConteudo_txtPassword").value == ""){ msg += "<h1>Informe sua 'Senha'</h1>"; }  
    for (i = 0; i < document.getElementById("ctl00_cphConteudo_txtPassword").value.length; i++) 
        {
            password = document.getElementById("ctl00_cphConteudo_txtPassword").value;
            confirmPassword = document.getElementById("ctl00_cphConteudo_txtConfirmarSenha").value;       
            if (password.charAt(i) != confirmPassword.charAt(i))
            {  
			    msg += "<h1>Senha e confirmação de senha diferentes.</h1>";
			    break;
            }
        }

      if(msg != "")
        {
            Abrir("<h2 class='Avermelho'></h2>\n<p>" + msg + "</p>");
            return false;
        }
}

function validaAddNoticia()
{
    var msg = "";    
    if(document.getElementById("ctl00_cphConteudo_txtNoticiaOrganizador").value == ""){ msg += "<h1>Informe uma 'Notícia'.</h1>"; }    

    if(msg != "")
    {
        Abrir("<h2 class='Avermelho'></h2>\n<p>" + msg + "</p>");
        return false;
    }
}


function validaDadosGincanaAtual()
{

    var intLogo    = 0;
    var msg        = "";    
    var arqExpReg  = /^[\s\S]+\.(png|PNG|jpg|JPG|jpeg|JPEG|gif|GIF)$/;
    var dataInit   = (document.getElementById("ctl00_cphConteudo_dataInicio").value).split("/");
    var dataFim    = (document.getElementById("ctl00_cphConteudo_dataFinal").value).split("/");
    var dataResult = (document.getElementById("ctl00_cphConteudo_dataResultado").value).split("/");
    
    
    dataInit = dataInit[2] + dataInit[1] + dataInit[0];
    dataFim  = dataFim[2] + dataFim[1] + dataFim[0];
    dataResult = dataResult[2] + dataResult[1] + dataResult[0];
    
    if(document.getElementById("ctl00_cphConteudo_txtNomeGincana").value == ""){ msg += "<h1>Informe o 'Nome da Gincana'.</h1>"; }    
    if(document.getElementById("ctl00_cphConteudo_txtProposito").value == ""){ msg += "<h1>Informe o 'Propósito'.</h1>"; }    
    if(document.getElementById("ctl00_cphConteudo_txtDescricao").value == ""){ msg += "<h1>Informe a 'Descrição'.</h1>"; }    
   // if(document.getElementById("ctl00_cphConteudo_txtRegulamento").value == ""){ msg += "<h1>Informe o 'Regulamento'.</h1>"; }    
    if(document.getElementById("ctl00_cphConteudo_txtRegrasEspeciais").value == ""){ msg += "<h1>Informe as 'Regras Especiais'.</h1>"; }    
    if(document.getElementById("ctl00_cphConteudo_txtTema").value == ""){ msg += "<h1>Informe o 'Tema'.</h1>"; }    
    if(document.getElementById("ctl00_cphConteudo_txtPublicoAlvo").value == ""){ msg += "<h1>Informe o 'Público Alvo'.</h1>"; }    
    if(document.getElementById("ctl00_cphConteudo_dataInicio").value == ""){ msg += "<h1>Informe a 'Data de Início'.</h1>"; }    
    if(document.getElementById("ctl00_cphConteudo_dataFinal").value == ""){ msg += "<h1>Informe a 'Data Final'.</h1>"; }    
    if(document.getElementById("ctl00_cphConteudo_dataResultado").value == ""){ msg += "<h1>Informe a 'Data de Resultado'.</h1>"; }        
    if (dataFim < dataInit){ msg += "<h1>Data Final menor que a Data de Início'.</h1>"; }
    if (dataResult < dataInit){ msg += "<h1>Data de Resultado menor que a Data de Início'.</h1>"; }
    if (dataResult < dataFim ){ msg += "<h1>Data de Resultado menor que a Data Final'.</h1>"; }
   // if(document.getElementById("ctl00_cphConteudo_txtPtsExtras").value > 100){ msg += "<h1>O valor deve ser inferior a 100 pontos.</h1>"; }    
    if(document.getElementById("ctl00_cphConteudo_txtMaxParticipantes").value == ""){ msg += "<h1>Informe o 'Maximo de Participantes'.</h1>"; }    

    if(msg != "")
    {
        Abrir("<h2 class='Avermelho'></h2>\n<p>" + msg + "</p>");
        return false;
    }

}


function validaUsuario()
{
    var intLogo = 0;
    var msg = "";
    var emailExpReg = /^([0-9a-z]+([_.-]?[0-9a-z]+)*@[0-9a-z]+[0-9,a-z,,.,-]*(.){1}[a-z]{2,4})+$/;
    var arqExpReg = /^[\s\S]+\.(png|PNG|jpg|JPG|jpeg|JPEG|gif|GIF)$/;
    
    if(document.getElementById("ctl00_cphConteudo_txtNickName").value == ""){ msg += "<h1>Informe um Nickname </h1>"; }    
    
    if(document.getElementById("ctl00_cphConteudo_txtEmail").value == "")
    { msg += "<h1>Informe o email de contato </h1>"; }
    else if (!document.getElementById("ctl00_cphConteudo_txtEmail").value.match(emailExpReg))
    { msg += "<h1>Email inválido </h1>"; }
    if(document.getElementById("ctl00_cphConteudo_txtNome").value == ""){ msg += "<h1>Informe seu 'Nome'</h1>"; }
	
    //if(ValidaCPF("ctl00_cphConteudo_txtCpf"))
     // { msg += ""; }
     // else
     // { msg += "<h1>O CPF informado &eacute; inv&aacute;lido!</h1>"; } 
	  
	if(document.getElementById("ctl00_cphConteudo_password").value == ""){ msg += "<h1>Informe sua 'Senha'</h1>"; }  
      
    for (i = 0; i < document.getElementById("ctl00_cphConteudo_password").value.length; i++) 
    {
        password = document.getElementById("ctl00_cphConteudo_password").value;
        confirmPassword = document.getElementById("ctl00_cphConteudo_txtConfirmarSenha").value;       
        if (password.charAt(i) != confirmPassword.charAt(i))
        {  
			msg += "<h1>Senha e confirmação de senha diferentes.</h1>";
			break;
        }
    }
   
//   if (document.getElementById("ctl00_cphConteudo_trabFile").value.length != 0 )
//    {  if (!document.getElementById("ctl00_cphConteudo_trabFile").value.match(arqExpReg)){
//        msg += "<h1>Formato de arquivo inválido.</h1>";
//        }
//    }
//    if(document.getElementById("cbxOrkut").checked)
//    { if (document.getElementById("ctl00_cphConteudo_txtOrkut").value == "" )
//      { msg += "<h1>Campo \"Orkut\" vazio.</h1>"; } }
//    if(document.getElementById("cbxFlicker").checked)
//    { if (document.getElementById("ctl00_cphConteudo_txtFlicker").value == "" )
//      { msg += "<h1>Campo \"Flicker\" vazio.</h1>"; } }
//    if(document.getElementById("cbxBlog").checked)
//    { if (document.getElementById("ctl00_cphConteudo_txtBlog").value == "" )
//      { msg += "<h1>Campo \"Blog\" vazio.</h1>"; } }
//    if(document.getElementById("cbxFacebook").checked)
//    { if (document.getElementById("ctl00_cphConteudo_txtFacebook").value == "" )
//      { msg += "<h1>Campo \"Facebook\" vazio.</h1>"; } }
//    if(document.getElementById("cbxLinkedin").checked)
//    { if (document.getElementById("ctl00_cphConteudo_txtLinkedin").value == "" )
//      { msg += "<h1>Campo \"Linkedin\" vazio.</h1>"; } }
//    if(document.getElementById("cbxMSN").checked)
//    { if (document.getElementById("ctl00_cphConteudo_txtMSN").value == "" )
//      { msg += "<h1>Campo \"Msn\" vazio.</h1>"; } }
//    if(document.getElementById("cbxHI5").checked)
//    { if (document.getElementById("ctl00_cphConteudo_txtHl5").value == "" )
//      { msg += "<h1>Campo \"HI5\" vazio.</h1>"; } }
//    if(document.getElementById("cbxTwitter").checked)
//    { if (document.getElementById("ctl00_cphConteudo_txtTwitter").value == "" )
//      { msg += "<h1>Campo \"Twitter\" vazio.</h1>"; } }
	  
	  
    if(document.getElementById("ctl00_cphConteudo_txtCaptcha").value == ""){ msg += "<h1>Preencha o código de segurança.</h1>"; }
    if(msg != "")
    {
        Abrir("<h2 class='Avermelho'></h2>\n<p>" + msg + "</p>");
        return false;
    }

}

//function ValidaVotacao()
//{
//    var intLogo = 0;
//    var msg = "";
//    var emailExpReg = /^([0-9a-z]+([_.-]?[0-9a-z]+)*@[0-9a-z]+[0-9,a-z,,.,-]*(.){1}[a-z]{2,4})+$/;
//    var arqExpReg = /^[\s\S]+\.(png|PNG|jpg|JPG|jpeg|JPEG|gif|GIF)$/;
//    
//    if(document.getElementById("ctl00_cphConteudo_txtNickName").value == ""){ msg += "<h1>Informe um Nickname </h1>"; }
//    if(document.getElementById("ctl00_cphConteudo_txtEmail").value == "")
//    { msg += "<h1>Informe o email de contato </h1>"; }
//    else if (!document.getElementById("ctl00_cphConteudo_txtEmail").value.match(emailExpReg))
//    { msg += "<h1>Email inválido </h1>"; }
//    if(document.getElementById("ctl00_cphConteudo_txtNome").value == ""){ msg += "<h1>Informe seu 'Nome'</h1>"; }
//    if(document.getElementById("ctl00_cphConteudo_txtCpf").value == "")
//    { msg += "<h1>Preencha o campo CPF.</h1>"; }
//    else 
//    { if(ValidaCPF("ctl00_cphConteudo_txtCpf"))
//      { msg += ""; }
//      else
//      { msg += "<h1>O CPF informado &eacute; inv&aacute;lido!</h1>"; } }
//    
//    if(document.getElementById("cbxOrkut").checked)
//    { if (document.getElementById("ctl00_cphConteudo_txtOrkut").value == "" )
//      { msg += "<h1>Campo \"Orkut\" vazio.</h1>"; } }
//    if(document.getElementById("cbxFlicker").checked)
//    { if (document.getElementById("ctl00_cphConteudo_txtFlicker").value == "" )
//      { msg += "<h1>Campo \"Flicker\" vazio.</h1>"; } }
//    if(document.getElementById("cbxBlog").checked)
//    { if (document.getElementById("ctl00_cphConteudo_txtBlog").value == "" )
//      { msg += "<h1>Campo \"Blog\" vazio.</h1>"; } }
//    if(document.getElementById("cbxFacebook").checked)
//    { if (document.getElementById("ctl00_cphConteudo_txtFacebook").value == "" )
//      { msg += "<h1>Campo \"Facebook\" vazio.</h1>"; } }
//    if(document.getElementById("cbxLinkedin").checked)
//    { if (document.getElementById("ctl00_cphConteudo_txtLinkedin").value == "" )
//      { msg += "<h1>Campo \"Linkedin\" vazio.</h1>"; } }
//    if(document.getElementById("cbxMSN").checked)
//    { if (document.getElementById("ctl00_cphConteudo_txtMSN").value == "" )
//      { msg += "<h1>Campo \"Msn\" vazio.</h1>"; } }
//    if(document.getElementById("cbxHI5").checked)
//    { if (document.getElementById("ctl00_cphConteudo_txtHl5").value == "" )
//      { msg += "<h1>Campo \"HI5\" vazio.</h1>"; } }
//    if(document.getElementById("cbxTwitter").checked)
//    { if (document.getElementById("ctl00_cphConteudo_txtTwitter").value == "" )
//      { msg += "<h1>Campo \"Twitter\" vazio.</h1>"; } }
//    
//    for(i = 1; i<9; i++)
//    {
//        if (document.getElementById("logo" + i).checked == true)
//        {
//            intLogo ++;
//        }
//    }
//    
//    if((intLogo == 0) && (document.getElementById("ctl00_cphConteudo_fulArquivo").value == ""))
//    { msg+= "<h1>Selecione uma das logos, ou insira a sua.</h1>"; }
//    
//    else if((intLogo > 0) && (document.getElementById("ctl00_cphConteudo_fulArquivo").value != ""))
//    { msg+= "<h1>Você deve escolher uma logo \"ou\" inserir a sua.</h1>"; }
//    
//    if((intLogo > 0) && (!document.getElementById("cbxRegulamento").checked) && (document.getElementById("ctl00_cphConteudo_fulArquivo").value == ""))
//    {
//        msg += "<h1>Você deve concordar com o 1º regulamento.</h1>";
//    }
//    
//    if((document.getElementById("ctl00_cphConteudo_fulArquivo").value != "") && (!document.getElementById("cbxRegulamento2").checked) && (intLogo == 0))
//    {
//        msg += "<h1>Você deve concordar com o 2º regulamento.</h1>";
//    }    
//    if( (!document.getElementById("ctl00_cphConteudo_fulArquivo").value.match(arqExpReg)) &&
//        (document.getElementById("ctl00_cphConteudo_fulArquivo").value != "") && 
//        (document.getElementById("cbxRegulamento2").checked))
//    {
//        msg += "<h1>Formato inválido de arquivo.</h1>";
//    }
//    
//    if(document.getElementById("ctl00_cphConteudo_txtCaptcha").value == ""){ msg += "<h1>Preencha o código de segurança.</h1>"; }
//    
//    if(msg != "")
//    {
//        Abrir("<h2 class='Avermelho'></h2>\n<p>" + msg + "</p>");
//        return false;
//    }
//}

function teste()
{
    for(i = 1; i<=9; i++)
    {
        document.getElementById("logo" + i).checked = false;
    }
}

function ValidaCPF(Campo)
{
    CNUMB = document.getElementById(Campo).value;

    if(Verify(CNUMB, 'CPF') == false)
    {
	    return false;
    } 
    else
    {
        return true;
    }
}

function Verify(CNUMB,CTYPE)
{
    CNUMB=ParseNumb(CNUMB)
    
    if(CNUMB == 0)
    {
        return(false);
    }
    else
    {
        g=CNUMB.length-2;
        if(TestDigit(CNUMB,CTYPE,g))
        {
            g=CNUMB.length-1;
            if(TestDigit(CNUMB,CTYPE,g))
            {	
                return(true);
            }
            else
            {
                return(false);
            }
        }
        else
        {
            return(false);
        }
    }
}

function ParseNumb(c)
{
    c=ClearStr(c,'-');
    c=ClearStr(c,'/');
    c=ClearStr(c,',');
    c=ClearStr(c,'.');
    c=ClearStr(c,'(');
    c=ClearStr(c,')');
    c=ClearStr(c,' ');
    
    if((parseFloat(c) / c != 1))
    {
        if(parseFloat(c) * c == 0)
        {
            return(c);
        }
        else
        {
            return(0);
        }
    }
    else
    {
        return(c);
    }
}

function ClearStr(str,charo)
{
    while((cx=str.indexOf(charo))!=-1)
    {		
        str = str.substring(0,cx)+str.substring(cx+1);
    }
    return(str);
}

function TestDigit(CNUMB,CTYPE,g)
{
    var dig=0;
    var ind=2;
    for(f=g;f>0;f--)
    {
        dig+=parseInt(CNUMB.charAt(f-1))*ind;
        if (CTYPE=='CNPJ')
        {
            if(ind>8) 
            {ind=2}
            else
            {ind++}
        }
        else
        { ind++ }
    }
    dig%=11;
    if(dig<2)
    {
        dig=0;
    }
    else
    {
        dig=11-dig;
    }
    if(dig!=parseInt(CNUMB.charAt(g)))
    {
        return false;
    }
    else
    {
        return(true);
    }
}

function ValidaContato()
{
    var intLogo = 0;
    var msg = "";
    var emailExpReg = /^([0-9a-z]+([_.-]?[0-9a-z]+)*@[0-9a-z]+[0-9,a-z,,.,-]*(.){1}[a-z]{2,4})+$/;
    
    if(document.getElementById("ctl00_cphConteudo_txtNomeContato").value == ""){ msg += "<h1>Informe seu 'Nome'</h1>"; }
    if(document.getElementById("ctl00_cphConteudo_txtEmailContato").value == "")
    { msg += "<h1>Informe o email de contato </h1>"; }
    else if (!document.getElementById("ctl00_cphConteudo_txtEmailContato").value.match(emailExpReg))
    { msg += "<h1>Email inválido </h1>"; }
    if(document.getElementById("ctl00_cphConteudo_txtAssuntoContato").value == ""){ msg += "<h1>Informe o assunto do contato </h1>"; }
    if(document.getElementById("ctl00_cphConteudo_txtMensagemContato").value == ""){ msg += "<h1>Digite a mensagem. </h1>"; }
    
    if(msg != "")
    {
        Abrir("<h2 class='Avermelho'></h2>\n<p>" + msg + "</p>");
        return false;
    }
}


// CHECKBOX CADASTRO
function HideField(idDiv, idCbx, idDivCampo2)
{	
    if(document.getElementById(idCbx).checked)
    {
        document.getElementById(idDiv).style.display = "none";
		$(idDivCampo2).css({ height: "auto" });		
    }
    else
    {
        document.getElementById(idDiv).style.display = "block";
		$(idDivCampo2).css({ height: "50px" });
    }
}


//força da senha

jQuery(document).ready(function() {
	
	var bpos = "";
	var perc = 0 ;
	var minperc = 0 ;
	$('#ctl00_cphConteudo_password').css( {backgroundPosition: "0 0"} );
	$('.username').keyup(function(){
		$('#result').html(passwordStrength($('#ctl00_cphConteudo_password').val(),$('.username').val())) ;
		perc = passwordStrengthPercent($('#ctl00_cphConteudo_password').val(),$('.username').val());

		bpos=" $('#colorbar').css( {backgroundPosition: \"0px -" ;
		bpos = bpos + perc + "px";
		bpos = bpos + "\" } );";
		bpos=bpos +" $('#colorbar').css( {width: \"" ;
		bpos = bpos + (perc * 2) + "px";
		bpos = bpos + "\" } );";
		eval(bpos);
	    	$('#percent').html(" " + perc  + "% ");
	              })
	$('#ctl00_cphConteudo_password').keyup(function(){
		$('#result').html(passwordStrength($('#ctl00_cphConteudo_password').val(),$('.username').val())) ; 
		perc = passwordStrengthPercent($('#ctl00_cphConteudo_password').val(),$('.username').val());
		
		bpos=" $('#colorbar').css( {backgroundPosition: \"0px -" ;
		bpos = bpos + perc + "px";
		bpos = bpos + "\" } );";
		bpos=bpos +" $('#colorbar').css( {width: \"" ;
		bpos = bpos + (perc * 2) + "px";
		bpos = bpos + "\" } );";
		eval(bpos);
	    	$('#percent').html(" " + perc  + "% ");
		})
	})
	function showMore()
	{
		$('#more').slideDown()
	}
	
function ValidaEnquete()
{
    var intLogo = 0;
    var msg = "";	
	var emailExpReg = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	var arqExpReg =/^[\s\S]+\.(png|Png|pNg|pnG|PNG|jpg|Jpg|jPg|jpG|JPG|jpeg|Jpeg|jPeg|jpEg|jpeG|JPEG|gif|Gif|gIf|giF|GIF|PDF|pdf|Pdf|DOC|doc|Doc)$/;
    
    if(!document.getElementById("ctl00_plnLogado")){ msg += "<h1>Para votar, você precisa estar logado.</h1>"; }
    
//    for(i = 1; i < 9; i++)
//    {
//        if (document.getElementById("logo" + i).checked == true)
//        {
//            intLogo ++;
//        }
//    }
//    if(document.getElementById("ctl00_cphConteudo_hdnValorLogo").value == "")
//    {
//        if(intLogo == 0) {
//        msg+= "<h1>Selecione uma das logos</h1>";
//        }
//    }
   // alert(intLogo);
    
 //   if(document.getElementById("ctl00_cphConteudo_fulArquivo").value == "")
 //   { msg+= "<h1>Selecione uma das logos, ou insira a sua.</h1>"; }
    
//    else if((intLogo > 0) && (document.getElementById("ctl00_cphConteudo_fulArquivo").value != ""))
//    { 
//        msg+= "<h1>Você deve escolher uma logo \"ou\" inserir a sua.</h1>"; 
//    }
//    else if((intLogo == 0) && (document.getElementById("ctl00_cphConteudo_fulArquivo").value > 0))
//    {
//        msg+= "<h1>Você deve escolher uma logo \"ou\" inserir a sua.</h1>";     
//    }

//    for(i = 1; i < 9; i++)
//    {
//        if (document.getElementById("logo" + i).checked == true)
//        {
//            intLogo ++;
//        }
//    }
//    
//    if((intLogo == 0) && (document.getElementById("ctl00_cphConteudo_fulArquivo").value == ""))
//    { msg+= "<h1>Selecione uma das logos, ou insira a sua.</h1>"; }
//    
//    else if((intLogo > 0) && (document.getElementById("ctl00_cphConteudo_fulArquivo").value != ""))
//    { msg+= "<h1>Você deve escolher uma logo \"ou\" inserir a sua.</h1>"; }
//    
//    if((intLogo > 0) && (!document.getElementById("cbxRegulamento").checked) && (document.getElementById("ctl00_cphConteudo_fulArquivo").value == ""))
//    {
//        msg += "<h1>Você deve concordar com o 1º regulamento.</h1>";
//    }
    
    
    for(i = 1; i < 10; i++)
    {
        if (document.getElementById("logo" + i).checked == true)
        {
            intLogo ++;
        }
    }
    
    if((intLogo == 0) && (document.getElementById("ctl00_cphConteudo_fulArquivo").value == ""))
    { msg+= "<h1>Selecione uma das logos, ou insira a sua.</h1>"; }
    
    //else if((intLogo > 0) && (document.getElementById("ctl00_cphConteudo_fulArquivo").value != ""))
    //{ msg+= "<h1>Você deve escolher uma logo \"ou\" inserir a sua.</h1>"; }
    
    if((intLogo > 0) && (!document.getElementById("cbxRegulamento").checked))
    {
        msg += "<h1>Você deve concordar com o 1º regulamento.</h1>";
    }
    
   
    if(!document.getElementById("ctl00_cphConteudo_fulArquivo").value == "" && (!document.getElementById("cbxRegulamento2").checked))
    {
        msg += "<h1>Você deve concordar com o 2º regulamento.</h1>";
    }
    
    
//    if((intLogo > 0) && (!document.getElementById("cbxRegulamento").checked) && (document.getElementById("ctl00_cphConteudo_fulArquivo").value == ""))
//    {
//        msg += "<h1>Você deve concordar com o 1º regulamento.</h1>";
//    }
    
//    if((document.getElementById("ctl00_cphConteudo_fulArquivo").value != "") && (!document.getElementById("cbxRegulamento2").checked) && (intLogo == 0))
//    {
//        msg += "<h1>Você deve concordar com o 2º regulamento.</h1>";
//    }   
     
    if( (!document.getElementById("ctl00_cphConteudo_fulArquivo").value.match(arqExpReg)) &&
        (document.getElementById("ctl00_cphConteudo_fulArquivo").value != "") && 
        (document.getElementById("cbxRegulamento2").checked))
    {
        msg += "<h1>Formato inválido de arquivo.</h1>";
    }
    
    if(document.getElementById("ctl00_cphConteudo_txtCaptcha").value == ""){ msg += "<h1>Preencha o código de segurança.</h1>"; }
    
    if(msg != "")
    {
        Abrir("<h2 class='Avermelho'></h2>\n<p>" + msg + "</p>");
        return false;
    }
}

function validaTarefaGincana()
{
    var msg = "";
    var dataInit   = (document.getElementById("ctl00_cphConteudo_txtDataAbertura").value).split("/");
    var dataFim    = (document.getElementById("ctl00_cphConteudo_txtDataFinalizado").value).split("/");
    
       
    dataInit = dataInit[2] + dataInit[1] + dataInit[0];
    dataFim = dataFim[2] + dataFim[1] + dataFim[0];
      
     
     if(document.getElementById("ctl00_cphConteudo_txtDescricaoTarefa").value == "")
     { msg += "<h1>Informe a 'Descrição da Tarefa'</h1>"; }
     
     if(document.getElementById("ctl00_cphConteudo_txtDicasTarefa").value == "")
     { msg += "<h1>Informe a 'Dicas da Tarefa'</h1>"; }
     
     if(document.getElementById("ctl00_cphConteudo_txtValor").value == "")
     {
        msg += "<h1>Informe um 'valor'</h1>";
     }
     if(document.getElementById("ctl00_cphConteudo_txtValor").value > 100)
     {
        msg += "<h1>Informe um valor menor que 100 para o número de pontos.</h1>";
     }
     if(document.getElementById("ctl00_cphConteudo_txtCriterio").value == "")
     {
        msg += "<h1>Informe o 'Criterio'</h1>";
     }     
      if(document.getElementById("ctl00_cphConteudo_ddlTipoTarefas").value == "0")
     { msg += "<h1>Informe um 'Tipo de tarefa'</h1>"; }
     
     if(document.getElementById("ctl00_cphConteudo_txtDataAbertura").value == "")
     {
        msg += "<h1>Informe uma 'data de inicio'</h1>";
     }
     
     if(document.getElementById("ctl00_cphConteudo_txtDataFinalizado").value == "")
     {
        msg += "<h1>Informe uma 'data final'</h1>";
     }
     
     if(dataInit > dataFim)
     {
        msg += "<h1>A Data final e menor que a data de abertura</h1>";
     }
     
     
    if(msg != "")
    {
        Abrir("<h2 class='Avermelho'></h2>\n<p>" + msg + "</p>");
        return false;
    }
}

function validaPatrocinadores()
{
    var msg = "";
    
     if(document.getElementById("ctl00_cphConteudo_txtNome").value == "")
     { msg += "<h1>Informe o 'Nome do Patrocinador'</h1>"; }
     
     if(document.getElementById("ctl00_cphConteudo_txtLink").value == "")
     { msg += "<h1>Informe o 'Link para o site'</h1>"; }
    
    if(msg != "")
    {
        Abrir("<h2 class='Avermelho'></h2>\n<p>" + msg + "</p>");
        return false;
    }
}

function ValidaParticipacaoRegulamento()
{
    var msg = "";
    
    if(!document.getElementById("ctl00_cphConteudo_cbxAceitaTermos").checked)
    { msg += "<h1>Você deve concordar com o regulamento e as <br />regras especiais do desafio.</h1>"; }
    
    if(msg != "")
    {
        Abrir("<h2 class='Avermelho'></h2>\n<p>" + msg + "</p>");
        return false;
    }
}

function ValidaAceitarRegulamento()
{
    var msg = "";
    
    if(!document.getElementById("ctl00_cphConteudo_chkRegurlamento").checked)
    { msg += "<h1>Você deve concordar com o regulamento.</h1>"; }
    
    if(msg != "")
    {
        Abrir("<h2 class='Avermelho'></h2>\n<p>" + msg + "</p>");
        return false;
    }
}

function validaAddConvidado()
{
    var msg = "";
    var emailExpReg = /^([0-9a-z]+([_.-]?[0-9a-z]+)*@[0-9a-z]+[0-9,a-z,,.,-]*(.){1}[a-z]{2,4})+$/;
    
    if(document.getElementById("ctl00_cphConteudo_txtNomeConvidado").value == ""){ msg += "<h1>Informe o 'Nome do Convidado'</h1>"; }
    if(document.getElementById("ctl00_cphConteudo_txtEmailConvidado").value == ""){ msg += "<h1>Informe o 'Email do Convidado'</h1>"; }
    else if(!document.getElementById("ctl00_cphConteudo_txtEmailConvidado").value.match(emailExpReg))
    { msg += "<h1>Email inválido. </h1>";}
    
    if(msg != "")
    {
        Abrir("<h2 class='Avermelho'></h2>\n<p>" + msg + "</p>");
        return false;
    }
}

function validaAddListaConvidado()
{
    var msg = "";
    if(document.getElementById("ctl00_cphConteudo_fulConvidados").value == ""){ msg += "<h1>Selecione uma Lista de Convidados.</h1>"; }
  if(msg != "")
    {
        Abrir("<h2 class='Avermelho'></h2>\n<p>" + msg + "</p>");
        return false;
    }
}