if(!Array.indexOf){
    Array.prototype.indexOf = function(obj){
        for(var i=0; i<this.length; i++){
            if(this[i]==obj){
                return i;
            }
        }
        return -1;
    }
}
var data = new Date();
var dia = data.getDate();
var mes = data.getMonth();
var ano = Number(data.getFullYear());

if (Number(dia) < 10)
    dia = "0" + dia;
if (Number(mes) < 10)
    mes = "0" + String(Number(mes) + 1);
if (ano < 2000)
    ano = 1900 + ano

var CalS = mes + '/' + dia + '/' + ano;
var CalSBr = dia + '/' + mes + '/' + ano;

//Volta
if ( dia == '29' && mes == '2' )
    dia = '28';
mes = parseInt(data.getMonth()) + 12
if (mes > 12) 
{
   ano = ano + 1;
   mes = mes - 12
}

var CalE = mes + '/' + dia + '/' + ano;
var CalEBr = dia + '/' + mes + '/' + ano;

var calSplitE = CalEBr.split('/')
var calSplitS = CalSBr.split('/')
var diaCalE = calSplitE[0]
var mesCalE = calSplitE[1]
var anoCalE = calSplitE[2]
var diaCalS = calSplitS[0]
var mesCalS = calSplitS[1]
var anoCalS = calSplitS[2]

var CalSNulo = '';

function setaDiasNulos()
{
	var tipoDePesquisa = document.getElementById('tipodepesquisa').value;
	
	var dataIda = '';
	
	switch(tipoDePesquisa)
	{
		case 'aereo':
			dataIda = 'DataIdaAereo';
			break;
		case 'hotel':
			dataIda = 'DataIdaHotel';
			break;
		case 'carro':
			dataIda = 'DataIdaCarro';
			break;
		case 'carros':
			dataIda = 'DataIdaCarro';
			break;
	}
			
	var data1 = document.getElementById(dataIda).value;
	var dia1 = '';
	var mes1 = '';
	var ano1 = '';
	
	if(data1 != '')
	{
		data1 = data1.replace(/\//g,'');

		dia1 = data1.substring(0,2);
		mes1 = data1.substring(2,4);
		ano1 = data1.substring(4);

		CalSNulo = mes1 + '/' + dia1 + '/' + ano1;
		CalSBr = dia1 + '/' + mes1 + '/' + ano1;
	}

	//Volta
	if ( dia1 == '29' && mes1 == '2' )
	    dia1 = '28';
	mes1 = parseInt(mes1) + 6
	if (mes1 > 12) 
	{
	   ano1 = ano1 + 1;
	   mes1 = mes1 - 12
	}

	calSplitS = CalSBr.split('/');
	diaCalS = calSplitS[0];
	mesCalS = calSplitS[1];
	anoCalS = calSplitS[2];
}

//*************************************************************************
// Limpa o valor dd/mm/aaaa no campo data
//*************************************************************************
function SetaData(objCampo, Valor)
{
	if ( (objCampo.value=='' && Valor=='dd/mm/aaaa') || (objCampo.value=='dd/mm/aaaa' && Valor==''))
		objCampo.value=Valor;
}
//*************************************************************************
// FIM
//*************************************************************************

function GetDowStart() {return 0;}function GetDateFmt() {return "ddmmyy";}function GetDateSep() {return "/";}
function ShowCalendar(eP,eD,eDP,dmin,dmax)
{
    var idEp = eP.getAttribute('id');
	if(idEp == 'DataIdaAereo' || idEp == 'DataIdaHotel' || idEp == 'DataIdaCarro')
	{
		//setaDiasNulos();
		SCal(eP,eD,eDP,dmin,dmax);
	}
	else
	{
		setaDiasNulos();
		SCal(eP,eD,eDP,CalSNulo,dmax);
	}
}
function ShowCalSimp(fm,eD,eDP,dmin,dmax)
{
	 if(!dmin)dmin='3/1/2005';if(!dmax)dmax='1/25/2006';
	 if(fm){SetNextFocus(objNext(fm,eD));SetPrevFocus(objPrev(fm,eD));}
	 SCal(eD,eD,eDP,dmin,dmax);
}

var zz, zv, d, fTSR;
d = new Date();
fTSR=0;
zv = d.getTime();
zz = "&zz="+zv;

var gBF=false;
function GoTo(u){window.top.location = u + zz;}
function Go(u){window.top.location = u;} 

function BF(){gBF=true;}

function Foci(o){if(!gBF && IsVis(o)){o.focus();}}

function IsVis(o)
{
	if(!o || o.type=="hidden")
	return false;
	
	while(o && o.style && o.style.display!='none')
	{
	o = o.parentNode;	
	}
	return !o || !o.style;
}


function TEK(a,evt){	
	var keycode;
	if (window.event){ keycode = window.event.keyCode; evt = window.event;}
	else if(evt) {keycode = evt.which;}
	else {return true;}
	if(13==keycode){evt.cancelBubble = true; evt.returnValue = false; eval(a);}
	}

function getObj(objID)
	{
	if (document.getElementById) {return document.getElementById(objID);}
	else if (document.all) {return document.all[objID];}
	else if (document.layers) {return document.layers[objID];}
	}
	
function objNext(f,d)
{
	var fFnd=false,el=f.elements,i=0;
	for(;i < el.length;i++)
	{
	if('hidden'!=el[i].type && false==el[i].disabled && IsVis(el[i]) && fFnd)return el[i];
	if(d.id==el[i].id)fFnd=true;
	}
	return null;
}
function objPrev(f,d)
{
	var fFnd=false,el=f.elements,i=el.length - 1;
	for(;i >= 0;i--)
	{
	if('hidden'!=el[i].type && false==el[i].disabled && IsVis(el[i]) && fFnd)return el[i];
	if(d.id==el[i].id)fFnd=true;
	}
	return null;
}

function DoNothing() {return false;}


var cF=null;var cW=null;var g_tid=0;var g_cP,g_eD,g_eDP,g_dmin,g_dmax;
var nextFocus;var g_fNoCal=false;

function getEventObj(e){if(!e)e=window.event;return e;}

function stopBubble(e){e=getEventObj(e);e.cancelBubble=true;if(e.stopPropagation)e.stopPropagation();}

function CB(){stopBubble(event);}

function SCal(cP,eD,eDP,dmin,dmax){

 clearTimeout(g_tid);
 if(g_fNoCal)
 {
	g_fNoCal=false;return;
 }
 if(g_calShown && eD==g_eD)
 {
	return;
}
 g_calShown = true;
 g_calCB = null;
 g_cP=cP;
 g_eD=eD;
 g_eDP=eDP;
 g_dmin=dmin;
 g_dmax=dmax; 
 WaitCal();;}

function CancelCal(){clearTimeout(g_tid);if(!cF)cF=getObj(CalFrame);cF.style.visibility="hidden";g_calShown=false;}
function WaitCal()
{ 
 var tipodepesquisa = document.getElementById('tipodepesquisa').value;
 if (tipodepesquisa == 'aereo')var CalFrame= 'CalFrameAereo';
 else if (tipodepesquisa=='hotel')var CalFrame = 'CalFrameHotel';
 else if (tipodepesquisa=='carro')var CalFrame = 'CalFrameCarro';
 else if (tipodepesquisa=='carros')var CalFrame = 'CalFrameCarros';
 else if (tipodepesquisa=='nacional')var CalFrame = 'CalFrameNacional';
 else if (tipodepesquisa=='internacional')var CalFrame = 'CalFrameInternacional';
 
 if(!cW) 
 {
	cW=frames[CalFrame]; 
 }
  if(null==cW||null==cW.g_fCL||false==cW.g_fCL){
	g_tid=setTimeout("WaitCal()", 200);
	}
 else{
 if(!cF){cF=getObj(CalFrame);}
 else { cF=getObj(CalFrame);}
 cF.style.visibility="hidden";
 DoCal();
 //setTimeout("DoCal()",1);
	}
}
function DoCal(){
 PosCal(g_cP);
 var tipodepesquisa = document.getElementById('tipodepesquisa').value;
 if (tipodepesquisa == 'aereo')var CalFrame= 'CalFrameAereo';
 else if (tipodepesquisa=='hotel')var CalFrame = 'CalFrameHotel';
 else if (tipodepesquisa=='carro')var CalFrame = 'CalFrameCarro';
 else if (tipodepesquisa=='carros')var CalFrame = 'CalFrameCarros';
 else if (tipodepesquisa=='nacional')var CalFrame = 'CalFrameNacional';
 else if (tipodepesquisa=='internacional')var CalFrame = 'CalFrameInternacional';
if(!cW)cW=frames[CalFrame];
cW.DoCal(g_eD,g_eDP,g_dmin,g_dmax);
var cW=null;
}

function getScrollTop()
{
	if(document.documentElement.scrollTop) return document.documentElement.scrollTop;
	if(document.body.scrollTop) return document.body.scrollTop;
	if(window.pageYOffset) return window.pageYOffset;
	return 0;
}

function getWinHeight()
{
	if(window.innerHeight) return window.innerHeight;
	if(document.documentElement.clientHeight) return document.documentElement.clientHeight;
	if(document.body.clientHeight) return document.body.clientHeight;
	return 0;
}

function PosCal(cP)
{	
	var tipodepesquisa = document.getElementById('tipodepesquisa').value;
	tipodepesquisa = tipodepesquisa.charAt(0).toUpperCase() + tipodepesquisa.substr(1);
	var frame_atual = document.getElementById('CalFrame'+tipodepesquisa).className;
	var dB=document.body;
	var eL=0;
	var eT=0;
	 if(!cF)cF=getObj(CalFrame);
	 {
		for(var p=cP;p&&p.tagName!='BODY';p=p.offsetParent)
		{
			if((document.body.className == 'frame' || document.getElementById('frame_pesquisa'))&& frame_atual.indexOf('vertical') != -1 && p.tagName == 'INPUT'){
				if(navigator.userAgent.indexOf("MSIE 7.0") != -1 || navigator.userAgent.indexOf("MSIE 6.0") != -1){
				eL+=p.offsetLeft+p.offsetWidth-126;
				eT+=p.offsetTop-207;
				}
				else{
				eL+=p.offsetLeft+p.offsetWidth-127;
				eT+=p.offsetTop-210;
				}
			}
			else{eL+=p.offsetLeft;eT+=p.offsetTop;}
		}
	}
	var eH=cP.offsetHeight;
	var dH=parseInt(cF.style.height);
	var sT=getScrollTop();
	if(eT-dH>=sT&&eT+eH+dH>getWinHeight()+sT){
		eT-=dH;
	}
	else{
		eT+=eH;
	}
	
	/*switch(frames)
	{
		case 'resultado_aereo2':
			alert('resultad_aereo2');
			eL = eL - 215;
		break;
		case 'resultado_hotel':
			alert('resultado_hotel');
			eL = eL - 215;
		break;
		case 'resultado_carro':
			alert('resultado_carro');
			eL = eL - 215;
		break;
	}*/
	//Coloca o calendario do frame vertical para abrir para a esquerda
	if(document.body.className == 'frame' && frame_atual.indexOf('vertical') != -1){
		eL = eL;
	}
	//Coloca o calendario do frame para abrir para a esquerda
	else if(document.body.className == 'frame'){	
		eL = eL - 215;
	}
	cF.style.left=eL+'px';
	cF.style.top=eT+'px';
	if((document.body.className == 'frame' || document.getElementById('frame_pesquisa')) && frame_atual.indexOf('vertical') && tipodepesquisa == 'Carro'){
		try{
			if(!fix_calendar && document.getElementById('CalFrameAereo')){
				frame_abas(1,'orange');
				frame_abas(3,'orange');
				fix_calendar = true;
			}
		}
		catch(e){}
	}
}

function SetNextFocus(e){nextFocus=e;if(nextFocus)nextFocus.onfocus=CancelCal;}
function SetPrevFocus(e){if(e)e.onfocus=CancelCal;}

function FGoNextFocus(){if(nextFocus){nextFocus.focus();return true;}return false;}

function CalSetFocus(e){if(e){g_fNoCal=true;e.focus();setTimeout("EndCalFocus()", 200);}}
function EndCalFocus(){g_fNoCal=false;}

function CalDateSet(eInp,d,m,y,giveFocus)
{
	var ds=GetDateSep();
	var fmt=GetDateFmt();

	if(fmt=="mmddyy")eInp.value=m+ds+d+ds+y;
	else if(fmt=="ddmmyy")
        { 
            meses = new Array()
            meses[0] = 'jan'
            meses[1] = 'fev'
            meses[2] = 'mar'
            meses[3] = 'abr'
            meses[4] = 'mai'
            meses[5] = 'jun'
            meses[6] = 'jul'
            meses[7] = 'ago'
            meses[8] = 'set'
            meses[9] = 'out'
            meses[10] = 'nov'
            meses[11] = 'dez'
            for(i=0; i<meses.length+1; i++){
                if(i == m){
                    if(eInp.id == 'DataVolta'){
                       document.getElementById('dia_volta').value = d
                       document.getElementById('mes_volta').value = meses[i-1]+ds+y
                       if(document.getElementById('dia_volta').value != d || document.getElementById('mes_volta').value != meses[i-1]+ds+y){
                           alert('Data não disponível para pesquisa aérea 1111'); 
                           eInp.value = ''
                           CancelCal();
                           return false
                       }
                    }
                    else if(eInp.id == 'DataIda'){
                       document.getElementById('dia_ida').value = d
                       document.getElementById('mes_ida').value = meses[i-1]+ds+y
                       if(document.getElementById('dia_ida').value != d || document.getElementById('mes_ida').value != meses[i-1]+ds+y){
                           alert('Data não disponível para pesquisa aérea 2222');
                           eInp.value = ''
                           CancelCal();
                           return false
                       }
                    }
                }
            }
           if (d < 10)   d = '0'+d
           else          d = d
           if (m < 10)   m = '0'+m
           else          m = m
           eInp.value=d+ds+m+ds+y;
        }
    else if(fmt=="ddmyy")eInp.value=d+ds+0+m+ds+y;
	else eInp.value=y+ds+m+ds+d;
	if(!giveFocus)
	CalSetFocus(eInp);
}

function validaCalErro(eInp)
{
    alert('Data não disponível para pesquisa aérea');
    eInp.value = ''
    CancelCal();
    return false
}
function CalDateSetKey(eInp,d,m,y,giveFocus)
{
	/*var dataAtual = new Date();
	var diaAtual = data.getDate();
	var mesAtual = data.getMonth();
	var anoAtual = Number(data.getFullYear());
		
	anoCalS = anoAtual;
	mesCalS = mesAtual + 1;
	diaCalS = diaAtual;*/
	
	if(eInp.value != '')
	{
		var ds=GetDateSep();
		var fmt=GetDateFmt();
		if(fmt=="ddmmyy")
		{
			var dataStart = new Date(anoCalS, mesCalS-1, diaCalS, 23, 59, 59) //Obs.: os três últimos parâmetros são, respectivamente: hora, minuto e segundo
			var dataEnd = new Date(anoCalE, mesCalE-1, diaCalE, 23, 59, 59) //Obs.: os três últimos parâmetros são, respectivamente: hora, minuto e segundo
			var dataPesq = new Date(y, m-1, d, 23, 59, 59)

			if (dataPesq <= dataEnd && dataPesq >= dataStart)  
			{
			   eInp.value=d+ds+m+ds+y;
			   
			   return true;
			}
			else
			{
			    validaCalErro(eInp)
			    return false;
			}
			/*
			        if (anoCalS == y || anoCalE == y)
			        {
			           if (mesCalS == m || mesCalE == m)
			           {
			               if (diaCalS <= d)
			               {
			                  eInp.value=d+ds+m+ds+y; return true;
			               }
			               else
			               {
			                   validaCalErro(eInp)
			                   return false
			               }
			           }
			           else
			           {
			               if (validaCalMes(m) == 'okmes')
			               {
			                    if (mesCalS == m || mesCalE == m)
			                    {
			                        if(validaCalDia(d) == 'okdia') {eInp.value=d+ds+m+ds+y; return true;}
			                        else
			                        {
			                            validaCalErro(eInp)
			                            return false
			                        }
			                    }
			                    else {eInp.value=d+ds+m+ds+y; return true;}
			               }
			               else
			               {
			                    validaCalErro(eInp)
			                    return false
			               }
			           }
			        }
			        else
			        {
			           if (validaCalAno(y) == 'okano')
			           {
			              if (validaCalMes(m) == 'okmes')
			              {
			                if(mesCalS == m || mesCalE == m)
			                {
			                    if(validaCalDia(d) == 'okdia')  {eInp.value=d+ds+m+ds+y; return true;}
			                    else
			                    {
			                         validaCalErro(eInp)
			                         return false
			                    }
			                }
			                else {eInp.value=d+ds+m+ds+y; return true;}
			              }
			              else
			              {
			                    validaCalErro(eInp)
			                    return false
			              }
			           }
			           else
			           {
			                validaCalErro(eInp)
			                return false   
			           }
			        }  
			    }
			    else
			    {
			        validaCalErro(eInp)
			        return false
			    }
			*/

			      /*if(CalEBr >= d+ds+m+ds+y && CalSBr <= d+ds+m+ds+y) {eInp.value=d+ds+m+ds+y;}
			      else{
			         alert('Data não disponível para pesquisa aérea');
			         eInp.value = ''
			         CancelCal();
			         return false
      }
      */
/*

	if(fmt=="mmddyy")eInp.value=m+ds+d+ds+y;
	else if(fmt=="ddmmyy")
        { 
                    if(eInp.id == 'DataVolta'){
                       if (d<10)  var diaDeVolta = d.split('0')[1]
                       else       var diaDeVolta = d
                       document.getElementById('dia_volta').value = diaDeVolta
                       document.getElementById('mes_volta').value = meses[i-1]+ds+y
                       if(document.getElementById('dia_volta').value != diaDeVolta || document.getElementById('mes_volta').value != meses[i-1]+ds+y){
                           alert('Data não disponível para pesquisa aérea');
                           eInp.value = ''
                           CancelCal();
                           return false
                       }
                    }
                    else if(eInp.id == 'DataIda'){

                       if (d<10)  var diaDeIda = d.split('0')[1]
                       else       var diaDeIda = d
                       document.getElementById('dia_ida').value = diaDeIda
                       document.getElementById('mes_ida').value = meses[i-1]+ds+y
                       if(document.getElementById('dia_ida').value != diaDeIda || document.getElementById('mes_ida').value != meses[i-1]+ds+y){
                           alert('Data não disponível para pesquisa aérea');
                           eInp.value = ''
                           CancelCal();
                           return false
                       }
                    }
           eInp.value=d+ds+m+ds+y;
        }
    else if(fmt=="ddmyy")eInp.value=d+ds+0+m+ds+y;
	else eInp.value=y+ds+m+ds+d;
	if(!giveFocus)
	CalSetFocus(eInp);
*/
		}
	}
}

var g_calShown = false;
function SetCalShown(fcshown){g_calShown=fcshown;}

var g_calCB;
function CalendarCallback(){if(g_calCB)g_calCB();}
function SetCalendarCallback(cb){g_calCB=cb;}


function GetInputDate(t)
{
	if(!t.length) return null;
	t=t.replace(/\s+/g,"");
	if(t.match(/[^-|\d|\.|\/]/)) return null;
	var rgt=t.split(/-|\.|\//);
	for(var i=0;i<rgt.length;i++) rgt[i]=parseInt(rgt[i],10);
	if(!rgt[1]) return null;
	var m,d,y;
	var fmt=GetDateFmt();
	if(fmt=="yymmdd")
	{
	if(!rgt[2]) return null;
	m=rgt[1];d=rgt[2];y=rgt[0];
	}
	else
	{
	if(fmt=="mmddyy"){m=rgt[0];d=rgt[1];}
	else{m=rgt[1];d=rgt[0];}//fmt=="ddmmyy"
	if(rgt[2])y=rgt[2];
	else y=DefYr(m-1,d);
	}
	m-=1;if(y<100)y+=2000;
	if(y<1601||y>4500||m<0||m>11||d<1||d>GetMonthCount(m,y))return null;
	return new Date(y,m,d);
}

var rM=new Array(12);rM[0]=rM[2]=rM[4]=rM[6]=rM[7]=rM[9]=rM[11]=31;rM[3]=rM[5]=rM[8]=rM[10]=30;rM[1]=28;
function GetMonthCount(m,y){var c=rM[m];if((1==m)&&IsLY(y))c++;return c;}
function IsLY(y){if(0==y%4&&((y%100!=0)||(y%400==0)))return true;else return false;}
function DefYr(m,d){var dt=new Date();var yC=(dt.getYear()<1000)?1900+dt.getYear():dt.getYear();if(m<dt.getMonth()||(m==dt.getMonth()&&d<dt.getDate()))yC++;return yC;}


function FormataData(objCampo,intKeyCode){
	
	if (!VerificaSoNumeros(objCampo,intKeyCode))
	{
		return false;
	}
	else
	{
		strValor = objCampo.value;
		intLengthValor = parseInt(strValor.length);
		if(intLengthValor == 0 && intKeyCode.charCode > 51){
				objCampo.value = strValor + "0";
		}
		
		if((intKeyCode.keyCode != 8) && (intKeyCode.keyCode != 46))
		{
		
			if(intLengthValor == 2){
				if(intKeyCode.charCode > 49)
					objCampo.value = strValor + "/0";
				else
					objCampo.value = strValor + "/";
			}
			
			if(intLengthValor == 5){
				objCampo.value = strValor + "/";
			}
		}

		//objCampo.selectionStart = objCampo.textLength;
		//objCampo.selectionEnd = objCampo.textLength;

		return true;
	}
}

function VerificaSoNumeros(objCampo,e){
	var tecla=new Number();
				
	if(window.event) {
		tecla = e.keyCode; 
	}else if(e.which) {
		tecla = e.which;
	}else {
		return true;
	}
	if ( (tecla==8) || (tecla==9) || (tecla==46) )
		return true;
	
	if((tecla < 48) || (tecla > 57)){
		return false;
	}
	return true;
}

function DtClkChamar(){
        calx.htm/DtClk(e)
}
