function getOrigem(form) {
	return form.Origem.value;
}
function getDestino(form) {
	return form.Destino.value;
}
function getDataIda(form) {
	return form.DataIda.value
}
function getDataVolta(form) {
	return form.DataVolta.value;
}
function getIdaEvolta(form) {	
	return form.idavolta.item(0).checked;
	//isso não funciona no safari
	return 0;
}
function enviar(form,strParam) {
	form.method = "post";
	form.action = "http://www.submarinoviagens.com.br/Produtos/Aereo/BuscaIatas.aspx" + strParam ;
	form.submit();
}

function HabilitaIdaVolta(){}


function get(id) {
	return document.getElementById(id);
}

function getV(id) {
	return document.getElementById(id).value;
}

function isEmpty(id) {
	if (getV(id)=='')
		return true;
	return false;
}

function isEmptyV(campo) {
	if (campo=='')
		return true;
	return false;
}

function PesquisaAereoHomeAfiliados(form,parametros)
{
	
    var strParam = '';

    if( isEmptyV(getOrigem(form))) {
        alert('Selecione a Origem.');
        return;
    }
    if(isEmptyV(getDestino(form))) {
        alert('Selecione o Destino.');
        return;
    }
	if(isEmptyV(getDataIda(form))) {
        alert('Selecione a data de ida.');
        return;
    }
	
    if(getOrigem(form).toLowerCase() == getDestino(form).toLowerCase()) {
        alert('Origem não pode ser igual ao Destino.');
        return;
    }
    if(getDataIda(form).value=='dd/mm/aaaa') {
        alert('Selecione a data de ida.');
        return;
    }
    if(getIdaEvolta(form))	{
        if(getDataVolta(form)=='dd/mm/aaaa' || isEmptyV(getDataVolta(form)))	{
       		alert('Selecione a data de volta.');
       		return;
    	}
    }

    strParam =  '?Origem=' + getOrigem(form);
    strParam += '&Destino=' + getDestino(form);
    strParam += '&Data=' + getDataIda(form);
    strParam += '&Hora=00:00';

	if(getIdaEvolta(form)) {    
        strParam += '&Origem=' + getDestino(form);
        strParam += '&Destino=' + getOrigem(form);
        strParam += '&Data=' + getDataVolta(form);
        strParam += '&Hora=00:00';
    }  
    
	strParam += '&NumADT=1';
    strParam += '&NumCHD=0';
    strParam += '&NumINF=0';
	strParam += '&SomenteDireto=0';		
	strParam += (getIdaEvolta(form)) ? '&SomenteIda=0' : '&SomenteIda=0';	
	strParam += '&Cia=';

	enviar(form,strParam + parametros);
}		
	
		
// Formata a data enquanto o usuário está digitando
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 + "/";
			}
		}

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

