// 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 loadestado(uf){
	ajx = ajax();
	//mostra_p = setInterval('mostra_processo()',0555);
 	ajx.onreadystatechange = abreEstado;
	tipo_texto = 'Carregando'
	document.getElementById('lista_estados').innerHTML = '<img src=\'/images/loader.gif\'>';

	u = 'abre_estado.php?uf='+uf;
	ajx.open("GET", u, true);
		ajx.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ajx.setRequestHeader("Connection", "close"); 
        ajx.send(null);

}

function abreEstado(){
	if(ajx.readyState == 4){
				if(ajx.status == 200){
					
					document.getElementById('lista_estados').innerHTML = ajx.responseText;
				}
	}
	
	
}



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;	
}

function set_position_iframe(){
	
temp = document.body.cumulativeScrollOffset();
w = temp[1]+50;
//$('div_frame').setStyle({top:w+'px'});
//$('div_frame').morph('top:'+w+'px')

new Effect.Morph('div_frame', {
	style: {
     top:w+'px'
  }
 , // CSS class name
  duration: 0.9 // Core Effect properties
});
/*
$('div_frame').morph('top:'+w+'px');
*/


}

function recarregar(){
	
	window.history.go(0);
}

function troca_senha(){
	cria_sombra('troca_senha.php');
	
}

function open_maps(id_clinica){
	
	cria_sombra('abre_mapa.php?id_clinica='+id_clinica);

	set_dimencion_frame()
	
}

function set_dimencion_frame(){
	
new Effect.Morph('frame', {
	style: {
     height:470+'px',
	 width:880+'px'
  }
 , 
  duration: 0.9 
});

temporario = document.body.clientWidth;
left = (temporario/2) -440;


new Effect.Morph('div_frame', {
	style: {
     left:left +'px',
	 width:880+'px'
  }
 , 
  duration: 0.9 
});

	
}

function openwin(URLtoOpen,windowName,width,height)
{
windowFeatures ="menubar=no,scrollbars=yes,location=no,favorites=no,resizable=no,status=no,toolbar=no,directories=no";
var test = "'";
winLeft = (screen.width-width)/2;
winTop = (screen.height-(height+110))/2;
myWin= open(URLtoOpen,windowName,"width=" + width +",height=" + height + ",left=" + winLeft + ",top=" + winTop + test + windowFeatures + test);
myWin.focus();

//myWin.document.open();
//myWin.document.close();
}

	
	

window.onload = init;
