// JavaScript Document

//FUNÇÕES 

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function habilita(campo,x){
	if(x==1){
		campo.disabled="";
		campo.value="";
		campo.focus();
	}else{
		campo.disabled="disabled";
		campo.value="Nome da Empresa";
	}
	return true;
}
function hab(campo,campo2,x){
	if(x==1){
		campo.disabled="";
		campo.value="";
		campo.focus();
		campo2.disabled="";
		campo2.value="";

	}else{
		campo.disabled="disabled";
		campo.value="";
		campo2.disabled="disabled";
		campo2.value="";
	}
	return true;
}

function confirma_exclusao(codigo,referencia,pagina){
	if(confirm('Deseja realmente excluir o registro:'+codigo+' ?')){
		eval("parent.location='"+pagina+"?acao=deletar&id="+codigo+referencia+"'");
	}
}

function extrato(){
	window.open('extrato.php','Estrato','width=417,height=550,scrollbars=yes');
	
}

function abraweb(){
	window.open('http://www.abraweb.com.br/pop_associado/censo2004/popup_censo2004.php?id=25d12b5dbcf59e182d87c38c12f1705a','','width=420,533');
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

function amplia(pasta,inicio,total,w,h){
	window.open('amplia.php?pasta='+pasta+'&inicio='+inicio+'&total='+total,'','width='+w+',height='+h);	
}

function confere(campo,prox){
		data = campo.value;
		tamData = campo.value.length;

		if (event.keyCode == 8)	
			tamData = tamData - 1;
		else{	
			if(tamData==2){
				data = data + "/";
			}else
			if(tamData==5){
				data = data + "/";
			}else
			if(tamData==10){
				prox.focus();
				data = data;				
				return false;
			}
		}
		campo.value = data;
		return true;
}

function confere2(campo,prox){
		hora = campo.value;
		tamhora= campo.value.length;
		if (event.keyCode == 8)	
			tamhora = tamhora - 1;
		else{	
			if(tamhora==2){
				hora = hora + ":";
			}else
			if(tamhora==5){
				prox.focus();
				hora = hora;				
				return false;
			}
		}
		campo.value = hora;		
		return true;
}

function EnviaForm(){
		document.opniao.submit();
}

function LimpaForm(){
		document.opniao.reset();
}
function Voltar(){
		history.back();
}
window.status = "Barão Center Hotel";
MM_reloadPage(true);




/////////////////////////////////////////////////////////////////////////

function popdate(obj,div,tam,ddd,obj1)
{
	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 = ano + "/" + mmonth + "/"  + day   
   }
 
   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='#336699' style='border:solid #333333; border-width:1' cellspacing='0' cellpadding='3' border='0' width='"+tam+"' height='"+tam*1.1 +"'>"
   txt += "<tr bgcolor='#f1f1f1'><td colspan='7' align='center'><table border='0' cellpadding='0' width='100%' bgcolor='#f1f1f1'><tr>"
   //escreve <<
   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>"
   // escreve <
   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>"
   //escreve ano ex: 2006
   txt += "<td colspan='7' align='center' bgcolor='#f1f1f1' class='mes1' nowrap><a href=javascript:pop_year('"+obj+"','"+div+"','"+tam+"','" + (mmonth+1) + "') class='mes1'>" + ano.toString() + "</a>"
   //escreve mes ex: janeiro
   txt += " <a href=javascript:pop_month('"+obj+"','"+div+"','"+tam+"','" + ano + "') class='mes1'>" + umonth[mmonth] + "</a><div id='popd' style='position:absolute'></div></td>"
   //escreve >
   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>"
   //escreve >>
   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>"
   // escreve X, fechar calendario
   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>"
  //escreve dias semana
   txt += "<tr bgcolor='#f1f1f1'><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='#f0f0f0' align=center>"
       if (week==diainicio) {start = true}
       if (d > days[mmonth]) {start=false}
       if (start) 
       {
           dat = new Date((mmonth+1).toString() + "/" + d + "/" + ano.toString())
		   dia = new Array()
		   dia[0] = "Domingo"
		   dia[1] = "Segunda-Feira"
		   dia[2] = "Terça-Feira"
		   dia[3] = "Quarta-Feira"
		   dia[4] = "Quinta-Feira"
		   dia[5] = "Sexta-Feira"
		   dia[6] = "Sábado"
		   
           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='#c9c9c9' " : "" )
		   
		   mesp = mmonth+1;
		   if (mesp<10){
			 mes_sh = '0' + mesp
		   }else{
			 mes_sh = mesp
		   }
		   if(d<10){
			 d = '0' + d;
		   }
	       diasem = dat
           txt += "<td"+colorcell+" align=center><a href=javascript:block('"+ d+ "/" + (mes_sh).toString() + "/" + ano.toString() +"','"+ obj +"','" + div +"','"+obj1+"') class='data'>"+ d.toString() + "</a></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 
}
 
function pop_month(obj, div, tam, ano)
{
 txt  = "<table bgcolor='#336699' border='0' width=80>"
 for (n = 0; n < 12; n++) { txt += "<tr><td align=center><font size=2 face=verdana color=#FFFFF><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+("01/" + (n+1).toString() + "/" + ano.toString())+"')>" + umonth[n] +"</a></td></tr>" }
 txt += "</table>"
 popd.innerHTML = txt
}

function pop_year(obj, div, tam, umonth)
{
 txt  = "<table bgcolor='#336699' border='0' width=160>"
 l = 1
 for (n=1991; n<2012; n++)
 {  if (l == 1) txt += "<tr>"
    txt += "<td align=center><font size=2 face=verdana color=#FFFFF><a href=javascript:popdate('"+obj+"','"+div+"','"+tam+"','"+(umonth.toString () +"/01/" + n) +"')>" + n + "</a></font></td>"
    l++
    if (l == 4) 
       {txt += "</tr>"; l = 1 } 
 }
 txt += "</tr></table>"
 popd.innerHTML = txt 
}

function force_close(div) 
   { div2 = eval (div); div2.innerHTML = ''}
   

function block(data, obj, div, obj1)
{ 
//   alert(diasem)
   force_close (div)
   obj2 = eval(obj)
   obj2.value = data 
   obj3 = eval(obj1)
   obj3.focus()
}

function MostraIdade()
{	
	var Total1=document.Form.qtdCrianca.value;
	var total;	
	var max=6;
	if(0==Total1)
	{
	document.all.IdadeFrame.style.display="none";
	}
	else
	{
	MostraCel(Total1,max);
	if(document.all.IdadeFrame.style.display=="none")
	{
	document.all.IdadeFrame.style.visibility="hidden";
	document.all.IdadeFrame.style.display="block";
	}
	document.all.IdadeFrame.style.visibility="visible";
	}
}
function MostraCel(c0,m)
{
	
	for(var i=0;i< m;i++)
//	strda = 'document.all.IdadeSel' + i;
//	var da = strda;
	{
	if(i< c0) d="block";
	else d="none";
	eval("document.all.IdadeSel"+i+".all.a"+i+".style.display='"+d+"'");
	}
}
function SKARI(n)
{
	if(n==0)
	{	
	n++; 
	}
	var da = document.all.IdadeFrame.all;
	if (n==1) d="block";
	else d="none";
	eval("document.all.IdadeFrame.all.IdadeSel0.style.display='"+d+"'");
	MostraIdade();
}

//******************************************
// Trata as Datas
//******************************************
function IsDate(pData){

	if(pData.length<10 || pData.length>10){
		alert('Data inválida\nInforme a data no formato (dd/mm/aaaa)');
	
		return false;
	}
	var ano = '' + pData.substring(6,10);
	var mes = '' + pData.substring(3,5);
	var dia = '' + pData.substring(0,2);
							
	if(dia>'31'){
		alert('Data inválida');
		return false;
	}							
	if(mes>'12'){
		alert('Data inválida');
		return false;
	}
	if(mes=='02'){
		if(ano%4!=0 && dia>'28'){
			alert('Data Inválida');
			return false;
		}
		else{
			if(dia>'29'){
				alert('Data Inválida');
				return false;
			}
		}
	}
	if(mes<='07'){
		if(mes%2==0 && dia>'30'){
			alert('Data inválida');
			return false;
		}
	}
	else{
		if(mes>'09'){
			if(mes%2!=0 && dia>'30'){
				alert('Data inválida');
				return false;
			}
		}
	}			
	
	//Data Correta!
	return true
}

//******************************************
// Compara datas.
//******************************************


function compara_data(data1,data2){
	/*var erro = "";
	d1 = data1.value;
	d2 = data2.value;
	hoje = new Date();
	h = hoje.getDate()+"/"+((hoje.getMonth()+1)<10?"0"+(hoje.getMonth()+1):(hoje.getMonth()+1))+"/"+hoje.getFullYear();
	if(d1 == ""){
		erro += "DATA DE CHECKIN INVÁLIDA! Por favor preencha este Campo\n\n";
//		popdate('document.Form.DataC','pop1','150',data1.value,'document.Form.hora');
	}
	if(d2 == ""){
		erro += "DATA DE CHECOUT INVÁLIDA! Por favor preencha este Campo\n\n";
	//	popdate('document.Form.DataP','pop1','150',data1.value,'document.Form.hora');		
	}
	if((d1 != "") && (d2 != "")){
		if(!dataMaior(d1,d2)){
			erro += "A DATA DE CHECKIN não pode ser maior que a DATA DE CHECKOUT!\n\n";
		
		}
	}
	if(d1 == d2){
		erro += "A DATA DE CHECKIN não pode ser igual que a DATA DE CHECKOUT\n\n";
	}
	if(!dataMaior(d1,h)){		
		erro += "A DATA DE CHECKIN não pode ser menor que a DATA DE ATUAL: "+h+"\n\n";
	}
	if(erro!=""){
		alert("Ocorreram os seguintes erros ao processar as DATAS: \n\n"+erro);
		data1.value = "";
		data2.value = "";	
		return false;
	}else
	*/
		return true;
}
function dataMaior(dt1,dt2){
	data1 = dt1.substring(6,10)+dt1.substring(3,5)+dt1.substring(0,2);
	data2 = dt2.substring(6,10)+dt2.substring(3,5)+dt2.substring(0,2);
	if(parseInt(data1)<=parseInt(data2)){
		return true;
	}else{
		return false;		
	}
}




//******************************************
// Validacao do Formulario.
//******************************************
function ValidaForm()
{

chegada=document.Form.DataC.value;
partida=document.Form.DataP.value;

var thetime=new Date();
    var nday=thetime.getDay();
    var nmonth=thetime.getMonth()+1;
	  var nano=thetime.getYear();
	  if (nday<10){
	 nday="0"+nday;
	 }

	 if (nmonth<10){
	 nmonth="0"+nmonth;
	 }
	 data_hj=nday+"/"+nmonth+"/"+nano;
data_comparada_dehj=compara_data(data_hj,chegada);
data_comparada=compara_data(chegada,partida);	

if(data_comparada_dehj==0){
alert ("A data de chegada não pode ser menor que a data de hoje");
return false;
}	

if(data_comparada==0){
alert ("A data de chegada não pode ser maior do que a de partida");
return false;
}

if ( ! IsDate(document.Form.DataC.value) ){
 document.Form.DataC.focus(); document.Form.DataC.select(); return false; }
   
if ( ! IsDate(document.Form.DataP.value) )
   { document.Form.DataP.focus(); document.Form.DataP.select(); return false; }
   
  
   
//Limpar os Combos das Idades  
for(var a=document.Form.qtdCrianca.selectedIndex+1;a< 7;a++)
{eval("document.Form.IdadeCrianca"+a+".selectedIndex=0");}


Form.submit();
}

function imprimir_relatorio_grafico(url){
	n = url.length;
	x = url.indexOf("?");
	url = url.substring(x,n);
	window.open("imprimir_relatorio_grafico.php"+url,"","scrollbars=yes,width=637,height=600");
}
