function confirmaPredileto(link){
    if(confirm('Deseja adicionar este perfil ao seus prediletos?'))
	window.location.href=link;
    else
	return false;
}

function reload(){
	document.location.reload();
}

function selectAll(){
	for (i = 0;i < document.formulario.elements.length;i++)
		if(document.formulario.elements[i].type == "checkbox")
			document.formulario.elements[i].checked=1;
}

function unSelectAll(){
	for (i = 0;i < document.formulario.elements.length;i++)
		if(document.formulario.elements[i].type == "checkbox")
			document.formulario.elements[i].checked=0;
}


function submitAction(value, modulo){
	if(value == ""){
		return 0;
	}
	var campos = 0;
	for (i = 0;i < document.formulario.elements.length;i++){
		if(document.formulario.elements[i].checked == 1){
			campos++;
		}
	}
	if(campos == 0){
		alert("Por favor selecione algum registro!");
		return 0;
	}
	if(campos==1){
		if(modulo=='mensagem')
			var moduloTexto = 'Tem certeza que deseja '+value+' essa mensagem?';
		if(modulo=='predileto')
			var moduloTexto = 'Tem certeza que deseja '+value+' esse predileto?';
		if(modulo=='lista_negra')
			var moduloTexto = 'Tem certeza que deseja '+value+' esse usuário da lista negra?';
		if(modulo=='pendentes')
			var moduloTexto = 'Tem certeza que deseja '+value+' esses usuário da lista de pendente?';
	}else if(campos>1){
		if(modulo=='mensagem')
			var moduloTexto = 'Tem certeza que deseja '+value+' essas mensagens?';
		if(modulo=='predileto')
			var moduloTexto = 'Tem certeza que deseja '+value+' esses prediletos?';
		if(modulo=='lista_negra')
			var moduloTexto = 'Tem certeza que deseja '+value+' esses usuários da lista negra?';
		if(modulo=='pendentes')
			var moduloTexto = 'Tem certeza que deseja '+value+' esses usuários da lista de pendentes?';
	}
	if(!confirm(moduloTexto)){
		return 0;
	}
	else{
		document.formulario.submit();
	}
}

function selectAndSubmit(value,acao){
	if(confirm('Tem certeza que deseja '+acao+' ?')){
		document.getElementById('acao').value = acao;
		if(document.getElementById(value).checked == 0){
			document.getElementById(value).checked = 1;
			document.formulario.submit();
		}
		else{
			document.formulario.submit();
		}
	}
}


function executeUrl(opcoes){
    var ext = opcoes.ext || '.php';
    if(confirm('Tem certeza que deseja '+opcoes.msg+' ?')) {
        location.href = opcoes.url+ext+'?acao='+opcoes.param+'&uid='+opcoes.uid;
    }
}


function habilitaCombo(elemento){
	if(document.getElementById(elemento).disabled){
		document.getElementById(elemento).disabled = false;
	}
}

function checkIdadeBusca(idade, opcao){
	if(opcao){
		var idade_de = document.getElementById('idade_de_'+opcao);
		var idade_a = document.getElementById('idade_a_'+opcao);
	}else{
		var idade_de = document.getElementById('idade_de');
		var idade_a = document.getElementById('idade_a');
	}

	if(idade_de.value != idade_a.value){
		if(idade == "de"){
			if(idade_de.value > idade_a.value)
				idade_a.value = idade_de.value;
		}
		if(idade == "a"){
			if(idade_de.value > idade_a.value)
				idade_de.value = idade_a.value;
		}
	}

}

function validarData(){
	f = document.cadastro
	dia = f.dia_nasc.value;
	mes = f.mes_nasc.value;
	ano = f.ano_nasc.value;

	var date = dia+'/'+mes+'/'+ano;
	var array_data = new Array;
	var ExpReg = new RegExp("(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[012])/[12][0-9]{3}");
	//vetor que contem o dia o mes e o ano
	array_data = date.split("/");
	erro = false;
	//Valido se a data esta no formato dd/mm/yyyy e se o dia tem 2 digitos e esta entre 01 e 31
	//se o mes tem d2 digitos e esta entre 01 e 12 e o ano se tem 4 digitos e esta entre 1000 e 2999
	if ( date.search(ExpReg) == -1 )
		erro = true;
	//Valido os meses que nao tem 31 dias com execao de fevereiro
	else if ( ( ( array_data[1] == 4 ) || ( array_data[1] == 6 ) || ( array_data[1] == 9 ) || ( array_data[1] == 11 ) ) && ( array_data[0] > 30 ) )
		erro = true;
	//Valido o mes de fevereiro
	else if ( array_data[1] == 2 ) {
		//Valido ano que nao e bissexto
		if ( ( array_data[0] > 28 ) && ( ( array_data[2] % 4 ) != 0 ) )
			erro = true;
		//Valido ano bissexto
		if ( ( array_data[0] > 29 ) && ( ( array_data[2] % 4 ) == 0 ) )
			erro = true;
	}
	if ( erro ) {
		alert("Data de nascimento inválida!");
	}
}

function setDestino(valor){
        if ($.browser.msie && $.browser.version<=6){
            //BUG IE não identificado
            $('#fundo_msg_hack').css({'margin-top':'76px','margin-left':'-165px'});
        }
        else if ($.browser.msie && $.browser.version>6){
            $('#fundo_msg_hack').css({'margin-top':'-268px'});
        }

	if(valor=="um_predileto"){
                $('#dest').attr('disabled','');
	}else{
                $('#dest').attr('disabled',true);
	}
}

function certeza(){
	var msg = "Você tem certeza que deseja excluir sua conta do Zugot.com.br? Você não poderá mais usar as ferramentas do site! \n\nTem realmente certeza?";
	var resposta = confirm(msg);
	if (resposta){
		return true;
	}
	else{
		return false;
	}
}

function checkIdiomas(){
	if(document.getElementById("idiomas[nao_resposta]").checked){
		uncheckAll();
	}else{
		checkAll();
	}
}

function checkAll(){
	document.getElementById("idiomas[hebraico]").disabled = false ;
	document.getElementById("idiomas[idiche]").disabled = false ;
	document.getElementById("idiomas[portugues]").disabled = false ;
	document.getElementById("idiomas[ingles]").disabled = false ;
	document.getElementById("idiomas[espanhol]").disabled = false ;
	document.getElementById("idiomas[italiano]").disabled = false ;
	document.getElementById("idiomas[arabe]").disabled = false ;
	document.getElementById("idiomas[alemao]").disabled = false ;
	document.getElementById("idiomas[polones]").disabled = false ;
	document.getElementById("idiomas[russo]").disabled = false ;
	document.getElementById("idiomas[frances]").disabled = false ;
	document.getElementById("idiomas[chines]").disabled = false ;
	document.getElementById("idiomas[japones]").disabled = false ;
	document.getElementById("idiomas[outros_text]").disabled = false ;
}

function uncheckAll(){
	document.getElementById("idiomas[hebraico]").disabled = true ;
	document.getElementById("idiomas[idiche]").disabled = true ;
	document.getElementById("idiomas[portugues]").disabled = true ;
	document.getElementById("idiomas[ingles]").disabled = true ;
	document.getElementById("idiomas[espanhol]").disabled = true ;
	document.getElementById("idiomas[italiano]").disabled = true ;
	document.getElementById("idiomas[arabe]").disabled = true ;
	document.getElementById("idiomas[alemao]").disabled = true ;
	document.getElementById("idiomas[polones]").disabled = true ;
	document.getElementById("idiomas[russo]").disabled = true ;
	document.getElementById("idiomas[frances]").disabled = true ;
	document.getElementById("idiomas[chines]").disabled = true ;
	document.getElementById("idiomas[japones]").disabled = true ;
	document.getElementById("idiomas[outros_text]").disabled = true ;
}

function esconde(campos){
	for (i = 0;i < campos.length;i++){
		if(document.getElementById(campos[i]).style.visibility == "hidden"){
			//document.getElementById(campos[i]).style.visibility = "visible";
			document.getElementById(campos[i]).disabled = false;
		}else{
			//document.getElementById(campos[i]).style.visibility = "hidden";
			document.getElementById(campos[i]).disabled = true;
		}
	}
}

function mostra(campos){
	for (i = 0;i < campos.length;i++){
			//document.getElementById(campos[i]).style.visibility = "visible";
			document.getElementById(campos[i]).disabled = false;
	}
}

function popup(){
	window.open('../termosUso.php','popup','width=1000,height=600,status=no, menubar=no,scrolling=yes,resizable=yes,scrollbars=yes,top=300,left=300')
}

var reDate = /^((0?[1-9]|[12]\d)\/(0?[1-9]|1[0-2])|30\/(0?[13-9]|1[0-2])|31\/(0?[13578]|1[02]))\/(19|20)?\d{2}$/;

function doDate(pStr)
{

	var ano = pStr.split('/')[2]
	if(new Date().getYear()<2000){
		var year = new Date().getYear()+1900;
	}else{
		var year = new Date().getYear();
	}

	if(ano.length < 4 || ano == "00" || ano == "0" || ano == "" || ano < 1910 || ano > year-18 || ano < year-99){
		$('#ano').val('');
		$('#ano').focus();
		alert("Data de nascimento não é válida. \n\nLembrando que você precisa ter no mínimo 18 anos para se cadastrar no Zugot.com.br.");
		return false;
	}
	eval("reDate = reDate");
	if (reDate.test(pStr)) {
		document.getElementById('dt_nasc').value = pStr;
	} else if (pStr != null && pStr != "") {
		alert("Data de nascimento não é válida.");
		return false;
	}
} // doDate

function pula(valor,tamanho, proximo){
	if(valor.length == tamanho){
		document.getElementById(proximo).focus();
	}
}

function countPerguntas(id){
	var request = YAHOO.util.Connect.asyncRequest('POST', 'ajax/requests/count_perguntas.php?id='+id);
}

function confirmaAtivacao(uid){
	if(confirm('Deseja ativa o usuario?'))
		window.location.href = 'confirmaCadastro.php?acesso=action&uid='+uid;
}

window.onload = function(){
    var bt_excluir_foto = document.getElementById('bt_excluir_foto');
    if (bt_excluir_foto!=null)
    {
        bt_excluir_foto.onclick = function(){
            if (confirm('Deseja excluir a foto?'))
                return true;
            else
                return false;
        }
    }
    if(typeof(jQuery)=='undefined')
    {
            if (document.all)
                var filho = 0;
            else
                var filho = 1;
            var lnk = document.createElement('a');
            lnk.setAttribute('href','../home.php');
            lnk.setAttribute('title','Voltar para home');
            lnk.setAttribute('id','link_home');
            document.getElementById('topo_cad').childNodes[filho].appendChild(lnk);
            document.getElementById('topo_cad').childNodes[filho].childNodes[0].onmouseover = function(){
                this.style.cursor = 'pointer';
            };
            lnk.appendChild(document.getElementById('topo_cad').childNodes[filho].childNodes[0]);
    }
}

/*
try{
    $(function(){
        if ($.browser.msie){
            $('div.miolo > div').css({'margin-top':'-520px'});
        }
    });
}catch(E){

}*/

