// Mensagem de Error Geral e Mensagem de Carregamento
var msg_Error = "Ops... Houve um problema ao obter os dados:\n";
var msg_Loading = 
				'<div id="loading" style="text-align: center; width:200px; height:25px; border: 1px solid #000000; background: #ffffff; top:50px; left:550px; position: absolute; z-index: 1000">'+
				'	<img src="imgs/c_loading.gif" alt="Carregando" title="Carregando" style="vertical-align:middle;" />'+
				'	<b class="textos">Carregando...</b>'+
				'</div>';
var msg_LoadingBlue = 
				'<div id="loading" style="text-align: center; width:200px; height:25px; border: 1px solid #000000; background: #ffffff; top:50px; left:550px; position: absolute; z-index: 1000">'+
				'	<img src="imgs/loading_blue.gif" alt="Carregando" title="Carregando" style="vertical-align:middle;" />'+
				'	<b class="textos">Carregando...</b>'+
				'</div>';
				
var msg_Loading_Find_File = 
				'<div id="loading" style="text-align: center; width:200px; height:25px; border: 1px solid #000000; background: #ffffff; top:50px; left:550px; position: absolute; z-index: 1000">'+
				'	<img src="imgs/c_loading.gif" alt="Carregando" title="Carregando" style="vertical-align:middle;" />'+
				'	<b class="textos">Carregando...</b>'+
				'</div>';
var  msg_LoadingInfo = 
					'<center><img src="../imgs/c_loading.gif" alt="Carregando" title="Carregando" style="vertical-align:middle;" />'+
					'	<b class="textos">Carregando...</b></center>';
var msg_Loading_2 = 
				'<div id="loading" style="text-align: center; width:200px; height:25px; border: 1px solid #000000; background: #ffffff; top:50px; left:550px; position: absolute; z-index: 1000">'+
				'	<img src="imgs/c_loading.gif" alt="Carregando" title="Carregando" style="vertical-align:middle;" />'+
				'	<b class="textos">Carregando...</b>'+
				'</div>';
function Online(){
	AjaxRequest.get({
			'url':'online.php',
			'onSuccess':function(req){
				document.getElementById('online').innerHTML = req.responseText;
				setTimeout("Online()",5500);
			},
			'onError':function(req){
				alert(msg_Error + req.statusText);
			}
		});
}

// Pagina grava_noticia.php
function grava_noticia(vlr_quary){
	AjaxRequest.get({
			'url':'noticias/gravar.php?dados='+vlr_quary,
			'onLoading':function(){
				document.getElementById('miolo').innerHTML = msg_LoadingInfo;
			},
			'onSuccess':function(req){
				document.getElementById('miolo').innerHTML = req.responseText;
				
			},
			'onError':function(req){
				alert(msg_Error + req.statusText);
			}
		});
}


// Pagina grava_emp.php
function grava_emp(vlr_quary){
	AjaxRequest.get({
			'url':'clientes/gravar_empresa.php?dados='+vlr_quary,
			'onLoading':function(){
				document.getElementById('miolo').innerHTML = msg_LoadingInfo;
			},
			'onSuccess':function(req){
				document.getElementById('miolo').innerHTML = req.responseText;
				
			},
			'onError':function(req){
				alert(msg_Error + req.statusText);
			}
		});
}




function valida_login(frm){
	var result = AjaxRequest.submit(frm, {
		onLoading:function(){
				document.getElementById('load').style.display = '';
				document.getElementById('load').innerHTML = msg_LoadingInfo;
			},
		'onSuccess':function(req){
			
				var i = 0
				var aux = ""
				var resto = ""
				
				vlr = req.responseText;
				
				for($i = 0;  i <= vlr.length; i++){
					if(vlr.substr(i,2)=="ok"){
				       aux = vlr.substr(i,2);
					   i = i + 2;
					}else{
						resto = resto + vlr.substr(i,1);
					}
				}
			
			if(aux=="ok"){
					document.getElementById('menu_empresa').style.display = "";
					document.getElementById('corpo').style.display = "none"; //desabilita o menu a foto
					document.getElementById('conteudo').innerHTML = resto;
					document.getElementById('load').style.display = "none";
					
				}else{
					document.getElementById('conteudo').innerHTML = req.responseText;
					document.getElementById('msg').innerHTML = document.getElementById('result').innerHTML;
					document.getElementById('result').style.display = "none";
					document.getElementById('load').style.display = "none";
				}
		},
		
		'onError':function(req){
			alert('Error:' + req.statusText);
		}
	});
	return result;
}

function valida_login_empresa(frm){
	var result = AjaxRequest.submit(frm, {
		onLoading:function(){
				document.getElementById('load').style.display = '';
				document.getElementById('load').innerHTML = msg_LoadingInfo;
			},
		'onSuccess':function(req){
			
				var i = 0
				var aux = ""
				var resto = ""
				
				vlr = req.responseText;
				
				for($i = 0;  i <= vlr.length; i++){
					if(vlr.substr(i,2)=="ok"){
				       aux = vlr.substr(i,2);
					   i = i + 2;
					}else{
						resto = resto + vlr.substr(i,1);
					}
				}
			
			if(aux=="ok"){
					document.getElementById('conteudo').innerHTML = resto;
					document.getElementById('load').style.display = "none";
					
				}else{
					document.getElementById('conteudo').innerHTML = req.responseText;
					document.getElementById('msg').innerHTML = document.getElementById('result').innerHTML;
					document.getElementById('result').style.display = "none";
					document.getElementById('load').style.display = "none";
				}
		},
		
		'onError':function(req){
			alert('Error:' + req.statusText);
		}
	});
	return result;
}



function grava_form(frm){
		var result = AjaxRequest.submit(frm, {
			onLoading:function(){
					document.getElementById('load').style.display = '';
					document.getElementById('load').innerHTML = msg_LoadingInfo;
				},
			'onSuccess':function(req){
				//alert(frm.query.value);
				document.getElementById('conteudo').innerHTML = req.responseText;
				document.getElementById('load').style.display = 'none';
			},
			
			'onError':function(req){
				alert('Error:' + req.statusText);
			}
		});
		
		return result;
}


function chama_link(id,vlr_link){	
	AjaxRequest.get({
				
			'url':vlr_link,
					
			'onLoading':function(){
				//alert(id);
				//alert(document.getElementById(id).innerHTML);
				//alert(document.getElementById(id).style.display);
				document.getElementById('msg').innerHTML = '';
				document.getElementById(id).innerHTML = msg_LoadingInfo;
			},
			'onSuccess':function(req){
	            //alert(req.responseText);
				document.getElementById(id).innerHTML = req.responseText;
				document.getElementById('load').style.display = 'none';
			},
			'onError':function(req){
				alert(msg_Error + req.statusText);
			}
		});
}


function getValues(frm){
var result = AjaxRequest.submit(frm, {
			'onLoading':function(){
				document.getElementById('msgloading').innerHTML = msg_Loading;
			},
			'onSuccess':function(req){
				document.getElementById('Change').innerHTML = req.responseText;
 	            document.getElementById('msgloading').style.display = "none";
			},
			'onError':function(req){
				alert('Mensagem de Error...!!!!!!' + req.statusText);
			}
		});
		return result;
}

// Utilizado pra preencher o campo cidade nos cadastros  q utiliza estado e cidade
function atualiza(vlr,vlr2){	
	AjaxRequest.get({
			
			'url':"../includes/modelos.php?id="+vlr+"&modelo="+vlr2,
					
			'onLoading':function(){
				document.getElementById('modelos').innerHTML = msg_LoadingInfo;
			},
			'onSuccess':function(req){
	            document.getElementById('modelos').innerHTML = req.responseText;
			},
			'onError':function(req){
				alert(msg_Error + req.statusText);
			}
		});
}
function atualiza2(vlr,vlr2){	
	AjaxRequest.get({
			
			'url':"includes/modelos2.php?id="+vlr+"&modelo="+vlr2,
					
			'onLoading':function(){
				document.getElementById('modelos').innerHTML = msg_LoadingInfo;
			},
			'onSuccess':function(req){
	            document.getElementById('modelos').innerHTML = req.responseText;
			},
			'onError':function(req){
				alert(msg_Error + req.statusText);
			}
		});
}
function atualiza3(vlr,vlr2){	
	AjaxRequest.get({
			
			'url':"includes/modelos2.php?id="+vlr+"&modelo="+vlr2,
					
			'onLoading':function(){
				document.getElementById('modelos2').innerHTML = msg_LoadingInfo;
			},
			'onSuccess':function(req){
	            document.getElementById('modelos2').innerHTML = req.responseText;
			},
			'onError':function(req){
				alert(msg_Error + req.statusText);
			}
		});
}

function atualiza_alt(vlr,nome){	
	AjaxRequest.get({
			
			'url':"cidades_alt.php?ID="+vlr+"&nome="+nome,
					
			'onLoading':function(){
				document.getElementById('atualiza_'+nome).innerHTML = msg_LoadingInfo;
			},
			'onSuccess':function(req){
	        	var ret
				ret='';
				document.getElementById('atualiza_'+nome).innerHTML = req.responseText;
				ret= document.getElementById('ret').innerHTML;
				document.getElementById('fk_estado').value = ret.replace(' ','');
				document.getElementById('fk_cidade').value = vlr;
				document.getElementById('ret').style.display = "none";
				
			},
			'onError':function(req){
				alert(msg_Error + req.statusText);
			}
		});
}


function busca_veiculo_cad(vlr){	
	AjaxRequest.get({
			
			'url':"../includes/veiculos.php?placa="+vlr,
					
			'onLoading':function(){
				document.getElementById('carrega').innerHTML = msg_LoadingInfo;
			},
			'onSuccess':function(req){
				document.getElementById('carrega').style.display = "none";
	            document.getElementById('veiculo').innerHTML = req.responseText;
				//document.getElementById('veiculo').innerHTML = "FDP";
				
			},
			'onError':function(req){
				alert(msg_Error + req.statusText);
			}
		});
}


function verifica_login(vlr,tipo,id){	
	AjaxRequest.get({
			
			'url':"paginas/verifica_login.php?ID="+vlr+"&TIPO="+tipo,
					
			'onLoading':function(){
				document.getElementById('valida_login').innerHTML = msg_LoadingInfo;
			},
			'onSuccess':function(req){
	            var i = 0
				var aux = ""
				
				vlr = req.responseText;
				
				for($i = 0;  i <= vlr.length; i++){
					if(vlr.substr(i,2)=="ok"){
				       aux = "ok";
					}
				}
			
			if(aux=="ok"){
					document.getElementById('valida_login').innerHTML = "..:: Login &eacute; Valido ::..";
			}else{
					document.getElementById('valida_login').innerHTML = req.responseText;
					document.getElementById(id).value = "";
				}	
			},
			'onError':function(req){
				alert(msg_Error + req.statusText);
			}
		});
}


// Fotos Ampliadas
function Ampliar(veiculo,foto){
	width=648;
	heidth=521;
	window.open("foto.php?id_veiculo="+veiculo+"&id_foto="+foto+"","Fotos", "toolbar=no,menubar=no,width="+width+",height="+heidth+",resizable=no");
}
function Ampliar2(veiculo,foto){
	width=648;
	heidth=521;
	window.open("../foto.php?id_veiculo="+veiculo+"&id_foto="+foto+"","Fotos", "toolbar=no,menubar=no,width="+width+",height="+heidth+",resizable=no");
}
function simula_financiamento(){
	width=400;
	heidth=250;
	preco = document.simulacao.preco_carro.value;
	entrada = document.simulacao.entrada.value;
	ano = document.simulacao.ano_carro.value;
	veiculo = document.simulacao.veiculo.value;
	valida = true;
	
	if(entrada == '') {
		alert("Você de entrada não deve ficar em branco!");
		valida = false;
	}
	
	if(valida == true) {
		window.open("financiamento.php?preco="+preco+"&entrada="+entrada+"&ano="+ano+"&veiculo="+veiculo+"","Financiamento", "toolbar=no,menubar=no,width="+width+",height="+heidth+",resizable=no");
	}
}

