if (navigator.cookieEnabled == 0) {
  alert("Seu browser não tem cookies habilitado.\n Por favor habilite este recurso para navegar no site corretamente.");
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ 
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { 
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

function visualizarParm(elemento){

	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var objLoadingImage = document.getElementById(elemento);
	if (objLoadingImage) {
			objLoadingImage.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - (getStyle(elemento,"height")).replace("px","")) / 2) + 'px'); 
			objLoadingImage.style.left = (((arrayPageSize[0]  - (getStyle(elemento,"width")).replace("px","")) / 2) + 'px');
			objLoadingImage.style.display = 'block';
	}
}

function getStyle(el,styleProp)
{
	var x = document.getElementById(el);
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}

function ocultarParm(elemento){
  	jQuery(elemento).hide();
}

function visualizar(){
	jQuery("divBoxAlt").show();
    
}

function ocultar(){
    document.getElementById("divBoxAlt").style.display="none";
}

function show(id) {
    var obj = document.getElementById(id);
    if (obj != null) {
        obj.style.display = "block";
    }
}

function hide(id) {
    var obj = document.getElementById(id);
    if (obj != null) {
        obj.style.display = "none";
    }
}

function writeHTML(id, content) {
    document.getElementById(id).innerHTML=content;
}

function objectEval(text) {
    text = text.replace(/\n/g, ' ');
    text = text.replace(/\r/g, ' ');
    if (text.match(/^\s*\{.*\}\s*$/))
    {
      text = '[' + text + '][0]';
    }
    return eval(text);
}
 
 function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function loadFlash(js_url, js_w, js_h){
  document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="' + js_w +  '" height="' + js_h + '">\n');
  document.write('<param name="movie" value="' + js_url + '" />\n');
  document.write('<param name="quality" value="high" />\n');
  document.write('<param name="wmode" value="transparent"/>\n');
  document.write('<embed src="' + js_url + '" wmode="transparent" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+ js_w + '" height="' + js_h + '"></embed>\n');
  document.write('</object>\n');
}
 
function campoMinusculo(event, objTxt) {

    var teclaPress = event.charCode == undefined ? event.keyCode : event.charCode;
    var str = String.fromCharCode(teclaPress);

    if ((teclaPress > 64 && teclaPress < 91) || (teclaPress > 191 && teclaPress < 224)) {
        var startpos = objTxt.selectionStart;
        var endpos = objTxt.selectionEnd;

        objTxt.value = objTxt.value.substr(0, startpos) + str.toLowerCase() + objTxt.value.substr(endpos);
        objTxt.setSelectionRange(startpos + 1, startpos + 1);

        event.preventDefault();
        event.stopPropagation();
    }

    return;

}

function validaEmailOnBlur(txtEmail) {
    if (txtEmail.value != undefined && txtEmail.value != "") {
        var Email = txtEmail.value;

        if (!Email.match(/^[a-zA-Z0-9]{1}([\._a-zA-Z0-9-]+)(\.[_a-zA-Z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+){1,3}$/) || !findChar(Email)) {
            txtEmail.value = "";
            var campoFocus = 'document.getElementById("' + txtEmail.id + '").focus()';
            setTimeout(campoFocus, 50);
        }
    }

}

function WriteLayer(ID,parentID,sText) {
 if (document.layers) {
   var oLayer;
   if(parentID){
     oLayer = eval('document.' + parentID + '.document.' + ID + '.document');
   }else{
     oLayer = document.layers[ID].document;
   }
   oLayer.open();
   oLayer.write(sText);
   oLayer.close();
 } else if (parseInt(navigator.appVersion)>=5 && navigator.appName=="Netscape") {
   document.getElementById(ID).innerHTML = sText;
 } else if (document.all) 
   document.all[ID].innerHTML = sText;
}

function validateFormAereo(){
	
	if(!validaElemento(jQuery("#origVal")) || !validaElemento(jQuery("#origPaisVal")) || !validaElemento(jQuery("#aerpOrig"))){
		aplicaErrorClass(jQuery("#aerpOrig"), "Preencher o aeroporto de origem.");
		controleLightBox('none');
		return false;
	}
	
	if(!validaElemento(jQuery("#origCityVal")) ||  !validaElemento(jQuery("#origEstVal"))){
		aplicaErrorClass(jQuery("#aerpOrig"), "Preencher o aeroporto de origem.");
		controleLightBox('none');
		return false;
	}
	jQuery("#aerpOrig").removeClass("errorCampo");
	if(!validaElemento(jQuery("#aerpDest")) || !validaElemento(jQuery("#destVal")) || !validaElemento(jQuery("#destPaisVal")) || !validaElemento(jQuery("#destEstVal"))){
		aplicaErrorClass(jQuery("#aerpDest"), "Preencher o aeroporto de destino.");
		controleLightBox('none');
		return false;
	}

	if(!validaElemento(jQuery("#destCityVal"))){
		aplicaErrorClass(jQuery("#aerpDest"), "Preencher o aeroporto de destino.");
		controleLightBox('none');
		return false;
	}
	jQuery("#aerpDest").removeClass("errorCampo");
	
	if(!validaElemento(jQuery("#dtIda"))){
		aplicaErrorClass(jQuery("#dtIda"), "Preencher a data de saída.");
		controleLightBox('none');
		return false;
	}
	jQuery("#dtIda").removeClass("errorCampo");
	var selecao = jQuery("#idaVolta").val();
	if(selecao == "true"){
		if(!validaElemento(jQuery("#dtVolta"))){
			aplicaErrorClass(jQuery("#dtVolta"), "Preencher a data de retorno.");
			controleLightBox('none');
			return false;
		}
	}
	jQuery("#dtVolta").removeClass("errorCampo");
	controleLightBox('block');
	document.formVoo.submit();
}
	
function validateFormHotel(){
	
	if(!validaElemento(jQuery("#destinoPesquisa"))){
		aplicaErrorClass(jQuery("#destinoPesquisa"), "Preencher a cidade de saida.");
		return false;
	}
	
	if(!validaElemento(jQuery("#paisId")) || !validaElemento(jQuery("#estadoId")) || !validaElemento(jQuery("#cidadeId")) || !validaElemento(jQuery("#tipoDestino"))){
		aplicaErrorClass(jQuery("#destinoPesquisa"), "Preencher da cidade de saida.");
		return false;
	}
	
	jQuery("#destinoPesquisa").removeClass("errorCampo");
	if(!validaElemento(jQuery("#dataEntrada"))){
		aplicaErrorClass(jQuery("#dataEntrada"), "Preencher data de saida.");
		return false;
	}
	jQuery("#dataEntrada").removeClass("errorCampo");
	if(!validaElemento(jQuery("#dataSaida"))){
		aplicaErrorClass(jQuery("#dataSaida"), "Preencher data de retorno.");
		return false;
	}
	jQuery("#dataSaida").removeClass("errorCampo"); 
	controleLightBox('block');
	
	document.formBuscaHotel.submit();
}
	
function validaElemento(elemento){
	if(elemento.val() == "" || elemento.val() == null){
		return false;
	}else{
		return true;
	}
}

function aplicaErrorClass(field, mensagem){
	field.addClass("errorCampo");
	field.toolTipCVC(mensagem);
}

function controleLightBox(param){
	document.getElementById('light').style.display = param;
	document.getElementById('fade').style.display  = param;
}

