var API = {};

API.addLoadEvent = function(func)
{
	var oldonload = window.onload;
	
	if (typeof window.onload !== 'function')
	{
		window.onload = func; 
	}
	else
	{
		window.onload = function()
		{
			if (oldonload)	
			{
				oldonload();
			}
			func();
		}
	}
}

API.moveSocial = function()
{
	var elemSocial = document.getElementById('midia-social-float');	
	var scrollPos = window._pageYOffset;
	
	if (scrollPos == null) {
		scrollPos = window.pageYOffset || document.documentElement.scrollTop;
	}
	
	if(scrollPos > 70)
	{
		elemSocial.style.top = (scrollPos + 10) + "px";
	}
	else
	{
		elemSocial.style.top = "42px";
	}
}

window.onscroll = API.moveSocial;


API.eventClick = function(elem, func)
{
	elem.onclick = func;
	
	if (typeof(elem.captureEvents) !== "undefined")
	{
		elem.captureEvents(Event.CLICK);
	}
}

API.addBorder = function(elem)
{
	el = API.getClass("border", elem);
	el[0].style.borderBottom = "4px solid #91c53d";
}

API.removeBorder = function(elem)
{
	el = API.getClass("border", elem);
	el[0].style.borderBottom = "none";
}


API.getClass = function(pclass, content)
{
	var content = content || document.body;
	var elems = content.getElementsByTagName("*");
	var elArray = [];
	
	for(var i = 0; i < elems.length; i++)
	{
		if(elems[i].className.indexOf(pclass) !== -1)
		{
			elArray[elArray.length] = elems[i];
		}
	}
	
	return elArray;
}

API.getPageHeight = function()
{
	return document.getElementsByTagName('body')[0].offsetHeight + "px";
}

API.openPopup = function(pagina, largura, altura) 
{
	//API.openPopup('html/ferramentas-esignal.html', 940, 700);
	var esquerda = (screen.width - largura) / 2;
	var topo = (screen.height - altura) / 2;
	window.open(pagina,'','height=' + altura + ', width=' + largura + ', top=' + topo + ', left=' + esquerda + 'status=no, toolbar=no, location=no, directories=no, resisable=no, scrollbars=yes, menubar=no, copyhistory=no'); 
}

API.queryString = function(name)
{
	name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
	var regexS = "[\\?&]" + name + "=([^&#]*)";
	var regex = new RegExp(regexS);
	var results = regex.exec(window.location.href);
	
	if (results == null)
	{
		return false;
	}
	else
	{
		return results[1];
	}
}

API.hashUrl = function(conteudo)
{
	var url = '?produto=' + conteudo;
	var urlHash = '#?produto=' + conteudo;
	var local =  document.location.toString();

	var key = /\?/i;
	var verifica = local.search(key);
	
	var key2 = /\#/i;
	var verifica2 = local.search(key2);
	
	if(verifica > 1 && verifica2 < 1)
	{
		if (local.indexOf("?") > -1)
			local = local.substr(0, local.indexOf("?"));
		
		window.location = local + urlHash;
	}
	else
	{
		window.location.hash = url;
	}
	
	API.loadTab();
}

API.loadTab = function()
{
	var content = API.queryString("produto");
	
	if( (content) && (content === "delay" || content === "premier" || content === "premier-plus") )
	{
		var aba = "";
		
		if(aba == "" && content == "delay")
			aba = 0;
			
		if(aba == "" && content == "premier")
			aba = 1;
			
		if(aba == "" && content == "premier-plus")
			aba = 2;
		
		if(aba !== "")
			API.changeTab(aba);
	}
	
}

API.changeTab = function(tab)
{
	var tabs = [];
	tabs[0] = document.getElementById("prd-delay"),
	tabs[1] = document.getElementById("prd-realtime"),
	tabs[2] = document.getElementById("prd-realtime-plus");

	if(tab !== "")
	{
		//abre conteudo
		for(var i = 0; i < tabs.length; i++)
		{
			tabs[i].style.display = "none";
		}
		tabs[tab].style.display = "block";
		
		//muda active das abas
		tabsActive = API.getClass("tab", document.getElementById("tabs"));
		
		for(var i = 0; i < tabsActive.length; i++)
		{
			tabsActive[i].className = "tab";
		}
		tabsActive[tab].className = "tab active";
	}
}

//função que abre o login
API.showLoginHeader = function()
{
    esqueciDiv = document.getElementById("esqueci-div");
	esqueciDiv.style.display = "none";
	API.esqueciOpen = false;
	
	if(!API.loginDiv)
    {
        API.loginDiv = document.getElementById("login-div");
        API.loginDivForm = API.loginDiv.getElementsByTagName("form")[0];
        if(API.loginDivForm)
        {
            API.validaLogin({ form: API.loginDivForm, inputLogin: "header-login", inputSenha: "header-senha" });
        }
    }
    
    if(!API.loginOpen)
    {
        API.loginDiv.style.display = "inline";
        API.loginOpen = true;
    }
    else
    {
        API.loginDiv.style.display = "none";
        API.loginOpen = false;
    }
}

API.showEsqueciHeader = function()
{
     loginDiv = document.getElementById("login-div");
	 loginDiv.style.display = "none";
	 API.loginOpen = false;
	 
	if(!API.esqueciDiv)
    {
        API.esqueciDiv = document.getElementById("esqueci-div");
        API.esqueciDivForm = API.esqueciDiv.getElementsByTagName("form")[0];
    }
    
    if(!API.esqueciOpen)
    {
        API.esqueciDiv.style.display = "inline";
        API.esqueciOpen = true;
    }
    else
    {
        API.esqueciDiv.style.display = "none";
        API.esqueciOpen = false;
    }
}

API.showMaisHeader = function()
{
    if(!API.maisDiv)
    {
        API.maisDiv = document.getElementById("mais-div");
    }
    
    if(!API.maisOpen)
    {
        API.maisDiv.style.display = "inline";
        API.maisOpen = true;
    }
    else
    {
        API.maisDiv.style.display = "none";
        API.maisOpen = false;
    }
}

API.showModal = function(id)
{
	API.modal = document.getElementById(id);
	API.modal.style.height = API.getPageHeight();
	API.modal.style.display = "block";
}

API.showNewsletter = function(bt)
{
    if(!API.newsletterInput)
    {
        API.newsletterInput = bt.parentNode.getElementsByTagName("input")[0];
    }
    
    if(API.newsletterInput.value != "Digite o seu email aqui" && API.newsletterInput.value != "")
    {
        
        if(!API.validaEmail(API.newsletterInput.value))
        {
            alert("Digite um email válido!");
        }
        else
        {
            if(!API.newsletterForm)
            {
                API.newsletterForm = document.getElementById("newsletter-form");
            }
            API.newsletterFormEmail = document.getElementById("newsletter-email");
            API.newsletterFormEmail.value = API.newsletterInput.value;
            
            API.newsletterForm.style.height = API.getPageHeight();
            API.newsletterForm.style.display = "block";
        }
    }
    else
    {
        alert("Você precisa digitar um email!");
    }
}

API.showLogin = function()
{
    if(!API.loginForm)
    {
        API.loginForm = document.getElementById("login-form");
    }
    
    API.loginForm.style.height = API.getPageHeight();
    API.loginForm.style.display = "block";
    
    API.loginFormEl = API.loginForm.getElementsByTagName("form")[0];
    if(API.loginFormEl)
    {
        API.validaLogin({ form: API.loginFormEl, inputLogin: "login", inputSenha: "senha" });
    }
}

API.esqueciMinhaSenha = function()
{
    if(!API.EsqueciSenha)
    {
        API.EsqueciSenha = document.getElementById("esqueci-senha");
    }
    
    if(!API.esqueciSenhaOpen)
    {
        API.EsqueciSenha.style.display = "block";
        API.esqueciSenhaOpen = true;
        if(API.esqueciLoginOpen)
        {
            API.esqueciMeuLogin();
        }
    }
    else
    {
        API.EsqueciSenha.style.display = "none";
        API.esqueciSenhaOpen = false;
    }
}

API.esqueciMeuLogin = function()
{
    if(!API.EsqueciLogin)
    {
        API.EsqueciLogin = document.getElementById("esqueci-login");
    }
    
    if(!API.esqueciLoginOpen)
    {
        API.EsqueciLogin.style.display = "block";
        API.esqueciLoginOpen = true;
        if(API.esqueciSenhaOpen)
        {
            API.esqueciMinhaSenha();
        }
    }
    else
    {
        API.EsqueciLogin.style.display = "none";
        API.esqueciLoginOpen = false;
    }
}

API.showCadastro = function()
{
    if(API.loginForm && API.loginForm.style.display == "block")
    {
        API.loginForm.style.display = "none";
    }
    
    if(!API.CadastroForm)
    {
        API.CadastroForm = document.getElementById("cadastro-form");
    }
    
    API.CadastroForm.style.height = API.getPageHeight();
    API.CadastroForm.style.display = "block";
}

API.openVideo = function(id, tituloVideo, urlSwf, urlFrame)
{
	idVideo = "video"+id;
	API.embedVideo(urlSwf, urlFrame, idVideo);
	
	var video = document.getElementById("video-lightbox-x");
	var titulo = document.getElementById("titulo-video-modal");
	var videoContainer = document.getElementById("alinha-video");
	
	videoContainer.className = idVideo;
	titulo.innerHTML = tituloVideo;
    video.style.height = API.getPageHeight();
    video.style.display = "block";
}

API.embedVideo = function(urlSwf, urlFrame, idVideo)
{
	if (!window.document.getElementById("my-video"))
	{ 
		//swfobject.removeSWF(idVideo);
		var d = document.createElement("div");
		d.setAttribute("id", "my-video");
		document.getElementById("alinha-video").appendChild(d);
	}
	
	var flashvars = { autostart: "false", thumb: urlFrame, thumbscale: "45", showendscreen: "false", color: "0x1A1A1A,0x1A1A1A" };
	var params = { /*wmode:"transparent",*/ allowfullscreen:"true", allowscriptaccess:"always" };
	var attributes = { id: idVideo, name: idVideo };
	
	swfobject.embedSWF(urlSwf, "my-video", "778", "468", "9.0.0", "videos/expressInstall.swf", flashvars, params, attributes);
}

API.openVideoYT = function(id, tituloVideo)
{
	API.embedVideoYT(id);
	
	var video = document.getElementById("video-lightbox-yt");
	var titulo = document.getElementById("titulo-video-modal");
	
	titulo.innerHTML = tituloVideo;
    video.style.height = API.getPageHeight();
    video.style.display = "block";
}

API.embedVideoYT = function(id)
{
	var url = "http://www.youtube.com/v/" + id,
		divVideo = document.getElementById("my-videoyt"),
		video = document.createElement("iframe");
		
	divVideo.innerHTML = '<iframe id="videoyt" width="770" height="450" src="'+ url +'" frameborder="0" allowfullscreen></iframe>';
}

API.removeYT = function()
{
	document.getElementById('my-videoyt').removeChild(document.getElementById('videoyt'));
}
	
/* slideshow da home */
API.slideshowHome = function(slideTime)
{
    API.slideshowHomeTime = slideTime;
    
    API.bannerList = document.getElementById("header-esquerda");
    API.bannerNav = document.getElementById("header-direita");
    
    if(API.bannerNav)
    {
        API.bannersNav = API.bannerNav.getElementsByTagName("li");
    }
    
    if(API.bannerList)
    {
        var bannersAll = API.bannerList.getElementsByTagName("li");
        API.banners = [];
        
        if(bannersAll.length > 0)
        {
            for(var i = 0; i < bannersAll.length; i++)
            {
                if(bannersAll[i].parentNode === API.bannerList)
                {
                    API.banners.push(bannersAll[i]);
                }
            }
        }
        
        if(API.banners.length > 1)
        {
            API.slideshowHomeCurrent = 0;
            API.slideshowHomeTroca(API.slideshowHomeCurrent++, false);
            API.slideshowHomeInterval = setInterval(function()
            {
                API.slideshowHomeTroca(API.slideshowHomeCurrent++, false);
            }, API.slideshowHomeTime);
        }
    }
}

API.slideshowHomeTroca = function(indice, clique)
{
    if(API.slideshowHomeCurrent > API.banners.length)
    {
        API.slideshowHomeCurrent = indice = 0;
    }
    
    if(clique)
    {
        clearInterval(API.slideshowHomeInterval);
        API.slideshowHomeCurrent = indice;
    }
    
    if(!API.bannerList || API.banners.length < 1 ||  indice === undefined)
    {
        return false;
    }
    
    for(var i = 0; i < API.banners.length; i++)
    {
        if(i == indice)
        {
            API.banners[i].className = "ativo";
            API.bannersNav[i].className = "ativo";
        }
        else
        {
            API.banners[i].className = "";
            API.bannersNav[i].className = "";
        }
    }
    
    if(clique)
    {
        API.slideshowHomeInterval = setInterval(function()
        {
            API.slideshowHomeTroca(API.slideshowHomeCurrent++, false);
        }, API.slideshowHomeTime);
    }
}

API.slideshowHomeStop = function()
{
    clearInterval(API.slideshowHomeInterval);
}

API.slideshowHomeReturn = function()
{
    API.slideshowHomeInterval = setInterval(function()
    {
        API.slideshowHomeTroca(API.slideshowHomeCurrent++, false);
    }, API.slideshowHomeTime);
}

/* funcoes de validacao  */

API.validaContato = function(form)
{
	var nome 		= form.nome.value, 
		email 		= form.email.value,
		telefone 	= form.telefone.value,
		estado 		= form.estado.value,
		cidade 		= form.cidade.value,
		mensagem 	= form.mensagem.value,
		newsletter 	= form.newsletter.checked,
		erro 		= "";
		msgErro 	= "Os seguintes campos precisam ser preenchidos corretamente: \n\n";
		
	if(nome == "")
	{
		erro += "Digite um nome. \n";
	}
	if(email == "" || !API.validaEmail(email))
	{
		erro += "Digite um email válido. \n";
	}
	if(telefone == "" || telefone.length > 10 || telefone.length < 9)
	{
		erro += "Digite um telefone de 9 até 10 caracteres com o ddd. \n";
	}
	if(estado == "")
	{
		erro += "Selecione um estado. \n";
	}
	if(cidade == "")
	{
		erro += "Digite uma cidade. \n";
	}
	if(mensagem == "")
	{
		erro += "Digite um comentário. \n";
	}
	
	if(erro == "")
	{
		form.submit();
	}
	else
	{
		alert(msgErro+erro);
		return false;
	}
}

API.validaNewsletter = function(form)
{
	var nome 		= form.nome.value, 
		email 		= form.email.value,
		estado 		= form.estado.value,
		cidade 		= form.cidade.value,
		erro 		= "";
		msgErro 	= "Os seguintes campos precisam ser preenchidos corretamente: \n\n";
		
	if(email == "" || !API.validaEmail(email))
	{
		erro += "Digite um email válido. \n";
	}
	if(nome == "")
	{
		erro += "Digite um nome. \n";
	}
	if(cidade == "")
	{
		erro += "Digite uma cidade. \n";
	}
	if(estado == "")
	{
		erro += "Selecione um estado. \n";
	}
	
	if(erro == "")
	{
		form.submit();
	}
	else
	{
		alert(msgErro+erro);
		return false;
	}
}

API.ajustaLogin = function(login, valor)
{
	if(valor.indexOf('pq_') === -1 || valor.substring(0, 3) != "pq_")
	{
		loginSemPQ = valor.replace("pq_", "");
		loginFinal = "pq_" + loginSemPQ;
		
		login.value = loginFinal;
		alert("O login deve iniciar sempre com \"pq_\", seu login foi alterado para: \""+loginFinal+"\".");
	}
}

API.validaCadastro = function(form)
{
	var nome 		= form.cad_nome.value, 
		sobrenome 	= form.cad_sobrenome.value,		
		email 		= form.cad_email.value,
		conf_email  = form.cad_confirma_email.value,
		login		= form.cad_login.value,
		senha 		= form.cad_senha.value,
		endereco 	= form.cad_endereco.value,
		cidade 		= form.cad_cidade.value,
		estado 		= form.cad_estado.value,
		cep 		= form.cad_cep.value,
		pais		= form.cad_pais.value,
		telefone	= form.cad_telefone.value,
		cpf			= form.cad_cpf.value,
		como		= form.cad_como_conheceu.value,
		profissao	= form.cad_profissao.value,
		minLogin 	= 4,
		minCep 		= 5,
		minSenha 	= 2,
		maxLogin 	= 13,
		maxCep 		= 8,
		maxSenha 	= 13,
		validador   = /^[_a-zA-Z0-9-]+$/,
		charLogin   = validador.test(login);
		charSenha   = validador.test(senha);
		erro 		= "";
		msgErro 	= "Os seguintes campos precisam ser preenchidos corretamente: \n\n";
	
	if(nome == "")
	{
		erro += "Digite um nome. \n";
	}
	if(isNaN(nome) == false)
	{
		erro += "Você não pode utilizar números no campo nome. \n";
	}
	if(sobrenome == "")
	{
		erro += "Digite um sobrenome. \n";
	}
	if(isNaN(sobrenome) == false)
	{
		erro += "Você não pode utilizar números no campo sobrenome. \n";
	}
	if(email == "" || !API.validaEmail(email))
	{
		erro += "Digite um email válido. \n";
	}
	if(email != "" && email != conf_email)
	{
		erro += "Repita o seu email corretamente. \n";
	}
	if(login == "" || login == "pq_" || login.length > maxLogin || login.length < minLogin)
	{
		erro += "Digite um login com " + minLogin + " até " + maxLogin + " caracteres. \n";
	}
	if(charLogin == false)
	{
		erro += "No campo login não são permitidos acentos nem caracteres especiais além de \"-\" ou \"_\". \n";
	}
	if(senha == "" || senha.length > maxSenha || senha.length < minSenha)
	{
		erro += "Digite uma senha com " + minSenha + " até " + maxSenha + " caracteres. \n";
	}
	if(senha != "" && charSenha == false)
	{
		erro += "No campo senha não são permitidos acentos nem caracteres especiais além de \"-\" ou \"_\". \n";
	}
	if(endereco == "")
	{
		erro += "Digite um endereço. \n";
	}
	if(cidade == "")
	{
		erro += "Digite uma cidade. \n";
	}
	if(isNaN(cidade) == false)
	{
		erro += "Você não pode utilizar números no campo cidade. \n";
	}
	if(estado == "")
	{
		erro += "Selecione um estado. \n";
	}
	if(pais == "")
	{
		erro += "Digite um país. \n";
	}
	if(isNaN(pais) == false)
	{
		erro += "Você não pode utilizar números no campo país. \n";
	}
	if(cep == "" || cep.length > maxCep || cep.length < minCep)
	{
		erro += "Digite um cep com " + minCep + " até " + maxCep + " caracteres. \n";
	}
	if(isNaN(cep) == true)
	{
		erro += "Somente números no campo cep. \n";
	}
	if(telefone == "" || telefone.length > 10 || telefone.length < 9)
	{
		erro += "Digite o seu telefone de 9 até 10 caracteres com o DDD. \n";
	}
	if(isNaN(telefone) == true)
	{
		erro += "Somente números no campo telefone. \n";
	}
	if(cpf == "" || !API.validaCPF(cpf))
	{
		erro += "Digite um cpf válido. \n";
	}
	if(isNaN(cpf) == true)
	{
		erro += "Somente números no campo cpf. \n";
	}
	if(isNaN(profissao) == false)
	{
		erro += "Você não pode utilizar números no campo profissão. \n";
	}
	if(como == "")
	{
		erro += "Selecione se algum curso indicou o nosso software. \n";
	}
	
		
	if(erro == "")
	{
		form.submit();
	}
	else
	{
		alert(msgErro+erro);
		return false;
	}
}

API.onlyNumbers = function (campo) {
	var er = /[^0-9]/;
	er.lastIndex = 0;
	if (er.test (campo.value))
		campo.value = campo.value.slice(0, (campo.value.length) - 1);
}

API.notNumbers = function (campo) {
	var er = /[0-9]/;
	er.lastIndex = 0;
	if (er.test (campo.value))
		campo.value = campo.value.slice(0, (campo.value.length) - 1);
}

API.validaLoginSenha = function (campo) {
	var er = /^[_a-zA-Z0-9-]+$/;
	er.lastIndex = 0;
	if (!er.test(campo.value))
		campo.value = campo.value.slice(0, (campo.value.length) - 1);
}

API.getXhr = function(){
	var xhr = new XMLHttpRequest() || new ActiveXObject("Msxml2.XMLHTTP") || new ActiveXObject("Microsoft.XMLHTTP");
	if(!xhr)
		return false;
	else
		return xhr;
}

API.loadContent = function(obj, id, url)
{
	if(url === "adget"){
		url = "html/ferramentas-advanced-get.html";
	} else if(url === "livecharts"){
		url = "html/ferramentas-livecharts.html";
	} else if(url === "esignal") {
		url = "html/ferramentas-esignal.html";
	} else {
		url = "";
	}
	
	var xhr = API.getXhr();
	if(!xhr)
	{
		alert("Não foi possivel carregar o conteúdo solicitado, por favor, tente novamente.");
	}
	else
	{
		xhr.open('GET', url, true);
		xhr.onreadystatechange = function()
		{
			if(xhr.readyState <= 1)
			{
				document.getElementById('loader').style.display = "block";
			}
			
			if(xhr.readyState == 4 || xhr.readyState == 'complete'){
				if(xhr.status == 200)
				{
					div = document.getElementById(obj);
					div.innerHTML = xhr.responseText;
					API.showModal(id);
				}
				
				document.getElementById('loader').style.display = "none";
			}
		}
		
		xhr.send(null);
		return false;
	}
}


API.verificaLogin = function(login){
	var xhr = API.getXhr();
	if(!xhr)
	{
		alert("Não foi possivel carregar o conteúdo solicitado, por favor, tente novamente.");
	}
	else
	{
		xhr.open('GET', 'inc/verificaLogin.php?login='+login, true);
		xhr.onreadystatechange = function()
		{
			if(xhr.readyState == 4 || xhr.readyState == 'complete'){
				if(xhr.status == 200)
				{
					div = API.getClass("respAjaxLogin", "");
					resultado = xhr.responseText;
					
					if(resultado == 1)
					{
						for(var i = 0; i < div.length; i++)
						{
							div[i].style.color = "#696";
							div[i].innerHTML = "\""+login+"\" está disponivel!";
						}
					}
					else
					{
						for(var i = 0; i < div.length; i++)
						{
							div[i].style.color = "#F00";
							div[i].innerHTML = "\""+login+"\" não está disponivel, tente outro usuário.";
						}
					}
				}
			}
		}
		
		xhr.send(null);
		return false;
	}
}

API.verificaCpf = function(cpf){
	var xhr = API.getXhr();
	if(!xhr)
	{
		alert("Não foi possivel carregar o conteúdo solicitado, por favor, tente novamente.");
	}
	else
	{
		xhr.open('GET', 'inc/verificaCpf.php?cpf='+cpf, true);
		xhr.onreadystatechange = function()
		{
			if(xhr.readyState == 4 || xhr.readyState == 'complete'){
				if(xhr.status == 200)
				{
					div = API.getClass("respAjaxCpf", "");
					resultado = xhr.responseText;

					if(resultado != 1)
					{
						for(var i = 0; i < div.length; i++)
						{
							div[i].innerHTML = "CPF já cadastrado, verifique o cpf digitado ou faça login.";
						}
					}
					else
					{
						for(var i = 0; i < div.length; i++)
						{
							div[i].innerHTML = "";
						}
					}
				}
			}
		}
		
		xhr.send(null);
		return false;
	}
}

API.verificaEmail = function(email){
	var xhr = API.getXhr();
	if(!xhr)
	{
		alert("Não foi possivel carregar o conteúdo solicitado, por favor, tente novamente.");
	}
	else
	{
		xhr.open('GET', 'inc/verificaEmail.php?email='+email, true);
		xhr.onreadystatechange = function()
		{
			if(xhr.readyState == 4 || xhr.readyState == 'complete'){
				if(xhr.status == 200)
				{
					div = API.getClass("respAjaxEmail", "");
					resultado = xhr.responseText;
					if(resultado != 1)
					{
						for(var i = 0; i < div.length; i++)
						{
							div[i].innerHTML = "Email já cadastrado, verifique o email digitado ou faça login.";
						}
					}
					else
					{
						for(var i = 0; i < div.length; i++)
						{
							div[i].innerHTML = "";
						}
					}
				}
			}
		}
		
		xhr.send(null);
		return false;
	}
}

	
API.validaLogin = function(options)
{
    options.form.onsubmit = function(e)
    {
        e.preventDefault();
		
        var login = options.form[options.inputLogin].value,
			senha = options.form[options.inputSenha].value,
			elemLogin = options.form[options.inputLogin];
		
		if(login == "" || login == "pq_" || senha == "")
        {
            alert("Digite um login e uma senha!");
        }
		else
        {
            options.form.submit();
        }
    };
}

API.validaCPF = function(cpf)
{
	var numberCPF = cpf.replace(" ", "").replace("-", "").replace(".", "").replace(".", "");

	var i;
	s = numberCPF;
	var c = s.substr(0, 9);
	var dv = s.substr(9, 2);
	var d1 = 0;

	for (i = 0; i < 9; i++) {
		d1 += c.charAt(i) * (10 - i);
	}

	if (d1 == 0) {
		return false;
	}

	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1) {
		return false;
	}

	d1 *= 2;
	for (i = 0; i < 9; i++) {
		d1 += c.charAt(i) * (11 - i);
	}

	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1) {
		return false;
	}

	return true;
}

API.validaEmail = function(str)
{
    var validaEmail = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
    if(validaEmail.test(str))
    {
        return true;
    }
    else
    {
        return false;
    }
}

