// Mensagem de Error Geral e Mensagem de Carregamento
var msg_Error = "Ops... There was a problem getting data:\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="Loading" title="Loading" style="vertical-align:middle;" />'+
				'	<b class="textoblack">Loading...</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="Loading" title="Loading" style="vertical-align:middle;" />'+
				'	<b class="textoblack">Loading...</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="Loading" title="Loading" style="vertical-align:middle;" />'+
				'	<b class="textoblack">Loading...</b>'+
				'</div>';
var  msg_LoadingInfo = 
					'<center><img src="../imgs/c_loading.gif" alt="Loading" title="Loading" style="vertical-align:middle;" />'+
					'	<b class="textoblack">Loading...</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="Loading" title="Loading" style="vertical-align:middle;" />'+
				'	<b class="textoblack">Loading...</b>'+
				'</div>';

function valida_login(frm){
	//alert('entro');
	var result = AjaxRequest.submit(frm, {
		onLoading:function(){
				document.getElementById('load_login').style.display = '';
				document.getElementById('load_login').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('msg_login').style.display = "";
					document.getElementById('msg_login').innerHTML = resto;
				}else{
					document.getElementById('load_login').innerHTML = req.responseText;
				}
		},
		'onError':function(req){
			alert('Error:' + req.statusText);
		}
	});
	return result;
}
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 is valid ::..";
			}else{
					document.getElementById('valida_login').innerHTML = req.responseText;
					document.getElementById(id).value = "";
					document.getElementById(id).focus();
				}	
			},
			'onError':function(req){
				alert(msg_Error + req.statusText);
			}
		});
}
function add_estatistica(id,tipo){	
	AjaxRequest.get({
			'url':"paginas/grava_estatistica.php?id="+id+"&tipo="+tipo,
			'onLoading':function(){
				
			},
			'onSuccess':function(req){
				
	        },
			'onError':function(req){
				alert(msg_Error + req.statusText);
			}
		});
}


function envia_contato(frm){
	var result = AjaxRequest.submit(frm, {
		onLoading:function(){
				document.getElementById('load_con').style.display = '';
				document.getElementById('load_con').innerHTML = msg_LoadingInfo;
			},
		'onSuccess':function(req){
				document.getElementById('msg_con').innerHTML = req.responseText;
				document.getElementById('load_con').style.display = "none";
				document.getElementById('msg_con').style.display = '';
				
		},
		'onError':function(req){
			alert('Error:' + req.statusText);
		}
	});
	return result;
}
function chama_link(id,vlr_link,tipo){	
	AjaxRequest.get({
			'url':vlr_link,
			'onLoading':function(){
				document.getElementById('msg').innerHTML = '';
				if(tipo=='usr'){
				    document.getElementById('paginas').innerHTML = msg_LoadingInfo;
				}else{document.getElementById(tipo).innerHTML = msg_LoadingInfo;}
			},
			'onSuccess':function(req){
				var sql
				sql = "select * from tb_cliente where pk_cliente="+id;
				if(tipo=='usr'){
					document.getElementById('paginas').innerHTML = req.responseText;
					document.getElementById('id_user').value = id;
					alimenta_form(sql);
				}else{
					document.getElementById(tipo).innerHTML = req.responseText;	
					//document.getElementById(tipo).style.display = 'none';
				}
			},
			'onError':function(req){
				alert(msg_Error + req.statusText);
			}
		});
}

function alt_status(status,vlr_link,tipo){	
	AjaxRequest.get({
			'url':vlr_link+status,
			'onLoading':function(){
				document.getElementById('msg').innerHTML = '';
				if(tipo=='usr'){
				    document.getElementById('paginas').innerHTML = msg_LoadingInfo;
				}else{document.getElementById(tipo).innerHTML = msg_LoadingInfo;}
			},
			'onSuccess':function(req){
				var sql
				if(status==1){status=0;}else{status=1;}
				document.getElementById(tipo).innerHTML = req.responseText;	
				document.getElementById('id_'+tipo).value = status;
			},
			'onError':function(req){
				alert(msg_Error + req.statusText);
			}
		});
}

function add_favorito(status,vlr_link,tipo,obj){	
	AjaxRequest.get({
			'url':vlr_link+status,
			'onLoading':function(){
				document.getElementById('msg').innerHTML = '';
				if(tipo=='usr'){
				    document.getElementById('paginas').innerHTML = msg_LoadingInfo;
				}else{document.getElementById(tipo).innerHTML = msg_LoadingInfo;}
			},
			'onSuccess':function(req){
				var sql
				if(status==1){status=0;}else{status=1;}
				alert(req.responseText);	
				document.getElementById(tipo).style.display = 'none';
				obj.src='../imgs/ico_mesa_.jpg';
				
			},
			'onError':function(req){
				alert(msg_Error + req.statusText);
			}
		});
}



function exc_favorito(status,vlr_link,tipo){	
	AjaxRequest.get({
			'url':vlr_link+status+"&exc=1",
			'onLoading':function(){
				document.getElementById('msg').innerHTML = '';
				if(tipo=='usr'){
				    document.getElementById('paginas').innerHTML = msg_LoadingInfo;
				}else{document.getElementById(tipo).innerHTML = msg_LoadingInfo;}
			},
			'onSuccess':function(req){
				var sql
				alert(req.responseText);	
				document.getElementById(tipo).style.display = 'none';
				document.getElementById('img_'+status).style.display = 'none';
				
			},
			'onError':function(req){
				alert(msg_Error + req.statusText);
			}
		});
}

function retorna_session(tipo){	
    AjaxRequest.get({
			'url':"paginas/retorna_session.php?tipo="+tipo,
			'onLoading':function(){
				document.getElementById('load').innerHTML = msg_LoadingInfo;
			},
			'onSuccess':function(req){
				alert(req.responseText);
				document.getElementById('palavra_chave_imagem').value = req.responseText;
			},
			'onError':function(req){
				alert(msg_Error + req.statusText);
			}
		});
}

function get_palavra_chave(id,id_idioma){	
    AjaxRequest.get({
			'url':"paginas/get_palavra_chave.php?id="+id+"&id_idioma="+id_idioma,
			'onLoading':function(){
				document.getElementById('load_pl').innerHTML = msg_LoadingInfo;
			},
			'onSuccess':function(req){
				document.getElementById('palavra_chave_imagem').value += req.responseText;
				document.getElementById('load_pl').style.display = "none";
			},
			'onError':function(req){
				alert(msg_Error + req.statusText);
			}
		});
}

function valida_img(id){	
    AjaxRequest.get({
			'url':"paginas/get_id_imagem.php?id="+id,
			'onLoading':function(){
				document.getElementById('img_load_views').innerHTML = msg_LoadingInfo;
				document.getElementById('load_img').style.display = "block";
			},
			'onSuccess':function(req){
				
				if(req.responseText.length<=1){document.getElementById('load_img').style.display = "none"};
				document.getElementById('img_load_views').innerHTML  = req.responseText;
			},
			'onError':function(req){
				alert(msg_Error + req.statusText);
			}
		});
}


function set_color(tipo){	
   
	//document.getElementById('td_conteudo').className = tipo;
	 AjaxRequest.get({
			'url':"paginas/set_color.php?id="+tipo,
			'onLoading':function(){
			},
			'onSuccess':function(req){
			document.getElementById('td_conteudo').className=req.responseText;
			},
			'onError':function(req){
				alert(msg_Error + req.statusText);
			}
		});
	
}
function check(obj){
	if(obj.checked){
		obj.value=1;
	}else{
		obj.value=0;
	}
}

function check_vlr(obj){
	if(obj.value==1){
		obj.checked=true;
	}else{
		obj.checked=false;
	}
}