//$(function() {
//	var div = document.createElement('div');
//	div.id = "natal2008";
//	document.body.insertBefore(div, document.body.firstChild);
//});

// JavaScript Document

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

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_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_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];}
}

var contando

function zeramenu01(){
	document.getElementById('menuKissFM').style.display='none';
	document.getElementById('menuProgramas').style.display='none';
}
function kill() {
	contando=setTimeout("zeramenu01()", 3000);	
}
function keepAlive() {
	clearTimeout(contando);	
}
function mostra(submenu){
	if(submenu == 'KissFM'){
		document.getElementById('menuKissFM').style.display='block';
		document.getElementById('menuProgramas').style.display='none';
	}
	if(submenu == 'Programas'){
		document.getElementById('menuKissFM').style.display='none';
		document.getElementById('menuProgramas').style.display='block';
	}
}

// **************************************************
// * CALENDARIO										*
// * Autor : Peter M Jordan - uranking@uranking.com *
// * página: www.uranking.com                       *
// **************************************************

// construindo o calendário
function popdate(obj,div,tam,ddd)
{
    if (ddd) 
    {
        day = ""
        mmonth = ""
        ano = ""
        c = 1
        char = ""
        for (s=0;s<parseInt(ddd.length);s++)
        {
            char = ddd.substr(s,1)
            if (char == "/") 
            {
                c++; 
                s++; 
                char = ddd.substr(s,1);
            }
            if (c==1) day    += char
            if (c==2) mmonth += char
            if (c==3) ano    += char
        }
        ddd = mmonth + "/" + day + "/" + ano
    }
  
    if(!ddd) {today = new Date()} else {today = new Date(ddd)}
    date_Form = eval (obj)
    if (date_Form.value == "") { date_Form = new Date()} else {date_Form = new Date(date_Form.value)}
  
    ano = today.getFullYear();
    mmonth = today.getMonth ();
    day = today.toString ().substr (8,2)
  
    umonth = new Array ("Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro")
    days_Feb = (!(ano % 4) ? 29 : 28)
    days = new Array (31, days_Feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)

    if ((mmonth < 0) || (mmonth > 11))  alert(mmonth)
    if ((mmonth - 1) == -1) {month_prior = 11; year_prior = ano - 1} else {month_prior = mmonth - 1; year_prior = ano}
    if ((mmonth + 1) == 12) {month_next  = 0;  year_next  = ano + 1} else {month_next  = mmonth + 1; year_next  = ano}
    txt  = "<table bgcolor='#efefff' style='border:solid #330099; border-width:2' cellspacing='0' cellpadding='3' border='0' width='"+tam+"' height='"+tam*1.1 +"' class='calendario'>"
    txt += "<tr bgcolor='#FFFFFF'><td colspan='7' align='center'><table border='0' cellpadding='0' width='100%' bgcolor='#FFFFFF' class='calendario'><tr>"
    txt += "<td width=20% align=center><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+((mmonth+1).toString() +"/01/"+(ano-1).toString())+"') class='Cabecalho_Calendario' title='Ano Anterior'><<</a></td>"
    txt += "<td width=20% align=center><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+( "01/" + (month_prior+1).toString() + "/" + year_prior.toString())+"') class='Cabecalho_Calendario' title='Mês Anterior'><</a></td>"
    txt += "<td width=20% align=center><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+( "01/" + (month_next+1).toString()  + "/" + year_next.toString())+"') class='Cabecalho_Calendario' title='Próximo Mês'>></a></td>"
    txt += "<td width=20% align=center><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+((mmonth+1).toString() +"/01/"+(ano+1).toString())+"') class='Cabecalho_Calendario' title='Próximo Ano'>>></a></td>"
    txt += "<td width=20% align=right><a href=javascript:force_close('"+div+"') class='Cabecalho_Calendario' title='Fechar Calendário'><b>X</b></a></td></tr></table></td></tr>"
    txt += "<tr><td colspan='7' align='right' bgcolor='#ccccff' class='mes'><a href=javascript:pop_year('"+obj+"','"+div+"','"+tam+"','" + (mmonth+1) + "') class='mes'>" + ano.toString() + "</a>"
    txt += " <a href=javascript:pop_month('"+obj+"','"+div+"','"+tam+"','" + ano + "') class='mes'>" + umonth[mmonth] + "</a> <div id='popd' style='position:absolute'></div></td></tr>"
    txt += "<tr bgcolor='#330099'><td width='14%' class='dia' align=center><b>Dom</b></td><td width='14%' class='dia' align=center><b>Seg</b></td><td width='14%' class='dia' align=center><b>Ter</b></td><td width='14%' class='dia' align=center><b>Qua</b></td><td width='14%' class='dia' align=center><b>Qui</b></td><td width='14%' class='dia' align=center><b>Sex<b></td><td width='14%' class='dia' align=center><b>Sab</b></td></tr>"
    today1 = new Date((mmonth+1).toString() +"/01/"+ano.toString());
    diainicio = today1.getDay () + 1;
    week = d = 1
    start = false;

    for (n=1;n<= 42;n++) 
    {
        if (week == 1)  txt += "<tr bgcolor='#efefff' align=center>"
        if (week==diainicio) {start = true}
        if (d > days[mmonth]) {start=false}
        if (start) 
        {
            dat = new Date((mmonth+1).toString() + "/" + d + "/" + ano.toString())
            day_dat   = dat.toString().substr(0,10)
            day_today  = date_Form.toString().substr(0,10)
            year_dat  = dat.getFullYear ()
            year_today = date_Form.getFullYear ()
            colorcell = ((day_dat == day_today) && (year_dat == year_today) ? " bgcolor='#FFCC00' " : "" )
            txt += "<td"+colorcell+" style=\"border: 1px solid #efefff\" align=center onMouseOut=\"this.style.border='1px solid #efefff'\" onMouseOver=\"this.style.border='1px solid #5787B7'\" onClick=\"javascript:block('"+  d + "/" + (mmonth+1).toString() + "/" + ano.toString() +"','"+ obj +"','" + div +"')\" class='data' style=\"cursor: pointer\">"+ d.toString() + "</td>"
            d ++ 
        } 
        else 
        { 
            txt += "<td class='data' align=center> </td>"
        }
        week ++
        if (week == 8) 
        { 
            week = 1; txt += "</tr>"} 
        }
        txt += "</table>"
        div2 = eval (div)
        div2.innerHTML = txt 
}
  
// função para exibir a janela com os meses
function pop_month(obj, div, tam, ano)
{
  txt  = "<table bgcolor='#CCCCFF' border='0' width=80 class='calendario'>"
  for (n = 0; n < 12; n++) { txt += "<tr><td align=center><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+("01/" + (n+1).toString() + "/" + ano.toString())+"')>" + umonth[n] +"</a></td></tr>" }
  txt += "</table>"
  popd.innerHTML = txt
}

// função para exibir a janela com os anos
function pop_year(obj, div, tam, umonth)
{
  txt  = "<table bgcolor='#CCCCFF' border='0' width=160 class='calendario'>"
  l = 1
  for (n=1991; n<2012; n++)
  {  if (l == 1) txt += "<tr>"
     txt += "<td align=center><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+(umonth.toString () +"/01/" + n) +"')>" + n + "</a></td>"
     l++
     if (l == 4) 
        {txt += "</tr>"; l = 1 } 
  }
  txt += "</tr></table>"
  popd.innerHTML = txt 
}

// função para fechar o calendário
function force_close(div) 
    { 
	div2 = eval (div); div2.innerHTML = '';
	document.getElementById('hora').style.visibility='visible'
	}
    
// função para fechar o calendário e setar a data no campo de data associado
function block(data, obj, div)
{ 
    force_close (div)
    obj2 = eval(obj)
    obj2.value = data 
}

// FUNÇÃO CEP DO CADASTRO
function pegaCep () {
	if (document.getElementById('cep').value) {	document.getElementById('numero').focus(); }
	else { document.getElementById('cep').focus(); }
	ajax = ajaxInit();
	document.getElementById('caption_cep').innerHTML = "aguarde, pesquisando cep...";
	if (ajax) {
		ajax.open("POST", "busca-cep.php", true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("cep="+ document.getElementById('cep').value + "-" + document.getElementById('cep2').value);
		ajax.onreadystatechange = function() {
			if (ajax.readyState == 4) {
				if (ajax.status == 200) {
					texto = ajax.responseText;
					texto = texto.replace(/\+/g," ");
					texto = unescape(texto);
					str = texto.split(';');
					document.forms.cadastro.endereco.value = texto;
					if (str[0]) { document.forms.cadastro.endereco.value = str[0]; }
					else { document.forms.cadastro.endereco.value = ''; }
					if (str[1]) { document.forms.cadastro.bairro.value = str[1]; }
					if (str[2]) { document.forms.cadastro.cidade.value = str[2]; }
					if (str[3]) { document.forms.cadastro.uf.value = str[3]; }
					document.getElementById('caption_cep').innerHTML = '';
				}
				else {
					alert(ajax.statusText);
				}
			}
		}
	}
}
// INICIA AJAX
function ajaxInit() {
	var req;
	try {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch(e) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(ex) {
			try {
				req = new XMLHttpRequest();
			}
			catch(exc) {
				alert("Esse browser não tem recursos para uso do Ajax");
				req = null;
			}
		}
	}
	return req;
}

// VALIDA SOMENTE NÚMEROS
function onlyNumbers(type, evt) {
	var key_code = evt.keyCode  ? evt.keyCode  :
				   evt.charCode ? evt.charCode :
				   evt.which    ? evt.which    : void 0;
	if (key_code == 8  ||  key_code == 9  ||  key_code == 13  ||  key_code == 27)
	{
		return true;
	}
	else if ((key_code >= 35)  &&  (key_code <= 40))
	{
		return true
	}
	if (type == "rg") {
		if ((key_code != 120 && key_code != 88) && (key_code < 48 || key_code > 57)) return false;
		else return true;
	}
	else {
		if ((key_code >= 48)  &&  (key_code <= 57)) return true;
		else return false;
	}
}

// VALIDA FORMULÁRIO
function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' precisa ser um e-mail válido.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' precisa conter um número.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- Preencha todos os campos obrigatórios.\n'; }
    } if (errors) alert('Não foi possível enviar o formulário:\n'+errors);
    document.MM_returnValue = (errors == '');
} }

// VERIFICA REGULAMENTO PROMOÇÃO
function checkRegulamento () {
	if (document.getElementById('formPromoRegulamento').checked) {
		return true;
	}
	else {
		alert ("Para participar da promoção você deve concordar com o regulamento");
		return false;
	}
}
function valida_promocao (){
	var nome_form=arguments[0];
	for(var i=0;i<arguments.length;i++){
		if (arguments[i] == "regulamento") {
			if (!document.getElementById('formPromoRegulamento').checked) {
				alert ("Para participar da promoção você deve concordar com o regulamento");
				return false;
			}
		}
		if(document.getElementById(arguments[i]).value == ""){
			alert("Por favor, preencha o formulário corretamente.");
			document.getElementById(arguments[i]).focus();
			return false;
		}
	}
	return true;
}

function validaSenha () {
	if (document[arguments[0]][arguments[1]].value != "") {
		if (document[arguments[0]][arguments[1]].value != document[arguments[0]][arguments[2]].value) {
			alert("A confirmação de sua senha está incorreta");
			document[arguments[0]][arguments[1]].focus();
			return false;
		}
	}
}

function validar_contato () {
	if (document.forms.form2.depto.options[document.forms.form2.depto.selectedIndex].value && document.forms.form2.nome.value && document.forms.form2.email.value) { return true; }
	else { alert("Preencha o formulário corretamente"); return false; }
}

function validar(){
	for(var i=0;i<arguments.length;i++){
		if(document.getElementById(arguments[i]).value == ""){
			alert("Por favor, preencha o formulário corretamente.");
			document.getElementById(arguments[i]).focus();
			return false;
		}
	}
	return true;
}

// GALERIA DE FOTOS
var galeria_imagens = new Array();
function galeria_voltar (dir) {
	if (galeria_i > 0) {
		galeria_i--;
		galeria_abre_foto(galeria_i, dir);
	}
	galeria_atualiza_btn();
}
function galeria_proxima (dir) {
	if (galeria_i < (galeria_imagens.length - 1)) {
		galeria_i++;
		galeria_abre_foto(galeria_i, dir);
	}
	galeria_atualiza_btn();
}
function galeria_abre_foto (z, dir) {
	galeria_i = z;
	document.getElementById('foto_grande').src='/media/galeria/images/'+dir+'/'+galeria_imagens[galeria_i];
	var loader = new ImageLoader('/media/galeria/images/'+dir+'/'+galeria_imagens[galeria_i]);
	document.getElementById('galeria_loading').style.display='block';
	loader.loadEvent = function(url, image) {
		galeria_atualiza_btn();
		document.getElementById('galeria_loading').style.display='none';
	}
	loader.load();
}
function galeria_atualiza_btn () {
	if (galeria_i == 0) {
		document.getElementById('botao_anterior').src = '/images/bot_galeria01_off.jpg';
	}
	else { document.getElementById('botao_anterior').src = '/images/bot_galeria01.jpg'; }
	if (galeria_i == (galeria_imagens.length - 1)) {
		document.getElementById('botao_proxima').src = '/images/bot_galeria02_off.jpg';
	}
	else {
		document.getElementById('botao_proxima').src = '/images/bot_galeria02.jpg';
	}
	document.getElementById('permalink').value = permalinks+'/?foto='+galeria_i;
}
function galeria_envia_foto (dir) {
	location.href='enviar.php?foto='+galeria_imagens[galeria_i];
}

// VOTAÇÃO ARTISTAS
function artistas_avalia (n, x) {
	for (i = 1; i <= 5; i++) {
		var estrela = document.getElementById('estrela'+i);
		if (i > n) {
			estrela.setAttribute('class','estrela_off');
			estrela.setAttribute('className','estrela_off');
		}
		else {
			estrela.setAttribute('class','estrela_on');
			estrela.setAttribute('className','estrela_on');
		}
	}
	artistas_avaliacao = n;
}
function artistas_avalia_clear () {
	artistas_avalia(artistas_avaliacao_default);
}
function artistas_vota (id_artista) {
	ajax = ajaxInit();
	if (ajax) {
		ajax.open("POST", "votar.php", true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("id="+id_artista+"&nota="+ artistas_avaliacao);
		ajax.onreadystatechange = function() {
			if (ajax.readyState == 4) {
				if (ajax.status == 200) {
					texto = ajax.responseText;
					texto = texto.replace(/\+/g," ");
					document.getElementById('avalia_stars').innerHTML = texto;
				}
				else {
					alert(ajax.statusText);
				}
			}
		}
	}
}
function max_text(txarea, total, status)
{
	tam = txarea.value.length;
	str="";
	str=str+tam;
	document.getElementById(status).innerHTML = total - str;

	if (tam > total){
	aux = txarea.value;
	txarea.value = aux.substring(0,total);
	document.getElementById(status).innerHTML = 0
	}
}
$(document).ready(function(){ 
	$('#combo_paginacao').change(function(){
		location.href = $(this).attr('uri')+"x="+$('#combo_paginacao').val();
	});
	if(document.getElementById('contato_form01')!=null){
		$('#contato_form01').formValidation({
			alias			: 'name',
			required	: 'required',
			err_list	:	false,
			telefone: /^[0-9]{2,} [0-9]{8,}$/gi
		});
	}
	setTimeout('$(".float_dhtml").hide()', 20000);
//	$("#cadastroCompleto").validate({
//		rules: {
//			cep: {
//				required: true,
//				digits: true
//			},
//			cep2: {
//				required: true,
//				digits: true
//			},
//			endereco: "required",
//			numero: {
//				required: true,
//				digits: true
//			},
//			bairro: "required",
//			cidade: "required",
//			uf: "required",
//			ddd: {
//				required: true,
//				digits: true
//			},
//			telefone: {
//				required: true,
//				digits: true
//			},
//			rg: {
//				required: true,
//				digits: true
//			},
//			diaNasc: {
//				required: true,
//				digits: true
//			},
//			mesNasc: {
//				required: true,
//				digits: true
//			},
//			anoNasc: {
//				required: true,
//				digits: true
//			},
//			sexo: "required",
//			estadocivil: "required",
//			formacao: "required",
//			email: {
//				required: true,
//				email: true
//			},
//			senha2: {
//				equalTo: "#senha_cadastro"
//			},
//			newsletter: "required",
//			sms_1: "required",
//			comoconheceu: "required",
//			ondeouco: "required",
//			qualidade: "required",
//			cpf: {
//				required: true,
//				cpf: true
//			}
//		},
//		messages: {
//			cep: {
//				required: " ",
//				digits: " "
//			},
//			cep2: {
//				required: " ",
//				digits: " "
//			},
//			endereco: " ",
//			numero: {
//				required: " ",
//				digits: " "
//			},
//			bairro: " ",
//			cidade: " ",
//			uf: " ",
//			ddd: {
//				required: " ",
//				digits: " "
//			},
//			telefone: {
//				required: " ",
//				digits: " "
//			},
//			rg: {
//				required: " ",
//				digits: " "
//			},
//			diaNasc: {
//				required: " ",
//				digits: " "
//			},
//			mesNasc: {
//				required: " ",
//				digits: " "
//			},
//			anoNasc: {
//				required: " ",
//				digits: " "
//			},
//			sexo: " ",
//			estadocivil: " ",
//			formacao: " ",
//			email: {
//				required: " ",
//				email: " "
//			},
//			senha2: " ",
//			newsletter: " ",
//			sms_1: " ",
//			comoconheceu: " ",
//			ondeouco: " ",
//			qualidade: " ",
//			cpf: {
//				required: " ",
//				cpf: " "
//			}
//		},
//		submitHandler: function(form) {
//				form.submit(); 
//		}
//	});
	$("#radioSmsSim").click(function () {
		if (this.checked) { 
			document.getElementById('sms_id').style.display='';
			$("#sms_2").rules("add", {
				 required: true,
				 digits: true,
				 messages: {
				   required: " ",
				   digits: " "
				 }
			});
			$("#sms_3").rules("add", {
				 required: true,
				 digits: true,
				 messages: {
				   required: " ",
				   digits: " "
				 }
			});
		}
	});
	$("#radioSmsNao").click(function () {
		if (this.checked) { 
			document.getElementById('sms_id').style.display='none';
			$("#sms_2").rules("remove", "required");
			$("#sms_3").rules("remove", "required");
		}
	});
});
