document.write('<script language="JavaScript" type="text/javascript" src="'+url+'js/base64.js"></script>');

var buscando=0, urlretorno='', tipologin='';
function login(urldest,tipo)
{
	if(buscando==0)
	{
		urlretorno = urldest;
		tipologin = tipo;
		
		buscando = 1;
		createObjectAjax();
		var dateobject = new Date(); //parâmetro passado para que não haja cache no ie
		
		var email = Base64.encode(document.getElementById('email').value);
		var cpf_cnpj = Base64.encode(document.getElementById('cpf_cnpj').value);
		var senha = Base64.encode(document.getElementById('senha').value);
		
		var urlchamada = url+'login.php?hour='+dateobject.getTime()+'&email='+escape(email)+'&cpf_cnpj='+escape(cpf_cnpj)+'&senha='+escape(senha)+'&xjp=AjAx';
		xmlHttp.open('GET', urlchamada, true);
		xmlHttp.onreadystatechange = atualizar;
		xmlHttp.send(null);
	}
}

function atualizar()
{
	if (xmlHttp.readyState == 4)
	{
		if (xmlHttp.status == 200)
		{
			var resposta = xmlHttp.responseText;
			
			if(resposta == 'true')
			{
				if(tipologin == 'popup')
				{
					if(urlretorno)
					window.opener.location = urlretorno;
					else
					window.opener.location = url;
					window.close();
				}
				else
				{
					if(urlretorno)
					window.location = urlretorno;
					else
					window.location = url;
				}
			}
			else
			{
				alert("Não foi possível realizar seu login\nVerifique se os seus dados estão preenchidos corretamente!");
			}
		}
		buscando = 0;
		urlretorno = '';
		tipologin = '';
	}
}

function valida_login(button)
{
	var email = document.getElementById('email').value;
	var cpf_cnpj = document.getElementById('cpf_cnpj').value;
	var senha = document.getElementById('senha').value;
	
	if(button=='mostrar')
	{
		if(!email.length)
			document.getElementById('email_title').style.color = '#ff0000';
		if(!cpf_cnpj.length)
			document.getElementById('cpf_cnpj_title').style.color = '#ff0000';
		if(!senha.length)
			document.getElementById('senha_title').style.color = '#ff0000';
	}
	else if(button=='sumir')
	{
		document.getElementById('email_title').style.color = '#666666';
		document.getElementById('cpf_cnpj_title').style.color = '#666666';
		document.getElementById('senha_title').style.color = '#666666';
	}
	else
	{
		if(!email.length || !cpf_cnpj.length || !senha.length)
		{
			document.getElementById('botao_login').style.MozOpacity = '0.45';
			document.getElementById('botao_login').style.filter = 'alpha(opacity=45)';
		}
		else
		{
			document.getElementById('botao_login').style.MozOpacity = '1.0';
			document.getElementById('botao_login').style.filter = 'alpha(opacity=100)';
		}
	}
}

function send_login(urldest,tipo)
{
	var email = document.getElementById('email').value;
	var cpf_cnpj = document.getElementById('cpf_cnpj').value;
	var senha = document.getElementById('senha').value;
	if(!email.length || !cpf_cnpj.length || !senha.length)
	{
		alert('Preencha todos os campos corretamente!');
	}
	else
	{
		login(urldest,tipo);
	}
}
