// JavaScript Document

var ajx;
var ajx_url;
var ajx_form;


function preloader(ar_img) 

	{
	
	Imagem = new Array();
	
			for(x=0;x<ar_img.length;x++){
				imagem_carrega = ar_img[x];
				Imagem[x] = new Image(); 
				Imagem[x].src = imagem_carrega;
				
			
			}
	
	}

function init(){
	
	
}

function FormataData(Campo,teclapres) {
		var tecla = teclapres.keyCode;
		vr = document.form1[Campo].value;
		vr = vr.replace( ".", "" );
		vr = vr.replace( ".", "" );
		vr = vr.replace( "/", "" );
		vr = vr.replace( "/", "" );
		tam = vr.length + 1;
		if ( tecla != 9 && tecla != 8 ){
			if ( tam > 2 && tam < 5 )
				document.form1[Campo].value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
			if ( tam >= 5 && tam <= 10 )
				document.form1[Campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); 
		}
}	




function ajax()
{
var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Seu browser não tem acesso ao  AJAX!");
      return false;
      }
    }
  }
  
  
  return  xmlHttp;
}


function coleta_form(form){
	
		formId=document.getElementById(form)
	var postStr= '';
	for (i = 0; i < formId.elements.length; i++) {
		formElem = formId.elements[i];
		switch (formElem.type) {
			case 'text':
			case 'select-one':
			case 'hidden':
			case 'password':
			case 'textarea':
			case 'checkbox':
			case 'radio':
			if(formElem.type == 'checkbox' || formElem.type == 'radio'){
			   
			   if(formElem.checked == true){
			
			postStr += formElem.name + '=' + escape(formElem.value) + '&';
			   }
			
			}else{
				
				postStr += formElem.name + '=' + escape(formElem.value) + '&'
				
			}
		break;
		}
	}
	
	return postStr;
	
	
}



function verifica_dados(){
	
	ajx = ajax();
	
	dados = coleta_form(ajx_form);
	
	
	ajx.onreadystatechange = verificado;
	tipo_texto = 'Carregando';
	mostra_p = setInterval('mostra_processo()',0555);
        ajx.open("POST", ajx_url, true);
		ajx.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ajx.setRequestHeader("Content-length", dados.length);
		ajx.setRequestHeader("Connection", "close"); 
        ajx.send(dados);
		
		return false;
}
function verifica_login(){
	
	ajx = ajax();
	
	login = escape(document.login.login.value);
	senha = escape(document.login.senha.value);
	dados = 'email='+login+'&senha='+senha;
	url = 'verifica_login.php';
	tipodeverificacao = 'login';
	
	ajx.onreadystatechange = verificado;
	tipo_texto = 'Carregando';
	mostra_p = setInterval('mostra_processo()',0555);
        ajx.open("POST", url, true);
		ajx.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ajx.setRequestHeader("Content-length", dados.length);
		ajx.setRequestHeader("Connection", "close") 
        ajx.send(dados);
		
		return false;
}



function verificado(){
	mostra_processo(ajx.readyState)
	
	
	
if(ajx.readyState == 4){
				if(ajx.status == 200){
					clearInterval(mostra_p);
					tipo_texto = 'erro';
					eval(ajx.responseText);
				}
	}
	
	
	
}
var tipo_texto;
var mostra_p;
var tipodeverificacao;

function mostra_processo(tipo){
	if(tipo_texto != 'erro'){
	if(!div_msg){
	

	
	
		
		
	
	
	var ht = "<div align='center'><img src='carregando.gif' style='margin-top:10%'></div>";
	}else{
		var ht = "<div align='center' class='simbous' style='margin:20px'>"+ '<img src="../icones/alerta.gif" alt="" width="33" height="34" align="left" />'+div_msg+"</div>";
	}
		
		
	if(tipodeverificacao != 'login'){
	//document[ajx_form].enviar.disabled = true;
	
	}
	document.getElementById('carrega').style.visibility= 'visible';

	var top = document.body.scrollTop;
	
	//var baixo = document.body.clientHeight;
	var baixo = document.body.clientHeight;
	var horizontal = document.body.clientWidth/ 2 - 200;
	
	posicao = Math.round(baixo + top) - 100;
	
	
	document.getElementById('carrega').style.left = horizontal+'px';
	document.getElementById('carrega').style.top = posicao+"px";
	document.getElementById('carrega').innerHTML = ht;
	
	}
}

var mostra_msg;
var div_msg;
function add_msg($msg){

	
}

function send_mensagem($msg){
	tipo_texto = false;
	div_msg = $msg;
	document.getElementById('carrega').style.visibility = 'visible';
	document.getElementById('carrega').style.width = '300px';
	mostra_p = setInterval('mostra_processo()',0555);
	setTimeout('close_carrega()',4000);
}
function send_focus(f){
	document[ajx_form][f].focus();
}

function close_carrega(){
	document.getElementById('carrega').style.visibility = 'hidden';
	document.getElementById('carrega').style.width = '100px';
	clearInterval(mostra_p);
	tipo_texto = 'erro';
	div_msg = false;
}



function redirect(url){
	
	location.href = url;	
}
	
	

window.onload = init;