var xmlhttp,xmlhttp2,xmlhttp3,xmlhttpH,xmlhttpN ;
var loader = '<img src="admin/images/loading.gif"/>';
var loader2 = '<img src="admin/images/loading2.gif"/>';
var pag, div, obj, lista_body_aux, aux_seq, auxN=0;

function enter_login1(tecla)
{
	if(tecla.keyCode==13) logar1();	
}
/*---------------------------------*/
function enter_login2(tecla)
{
	if(tecla.keyCode==13) logar2();	
}
/*---------------------------------*/
function logar1() 
{     		
	atribui_XMLHttpRequest();
	pag = 'autentica.php?login='+document.form1.login.value+'&senha='+document.form1.senha.value;
    xmlhttp.open("GET", pag, true); 	
    xmlhttp.onreadystatechange = processlogar1; 
    xmlhttp.send(null); 
}
/*---------------------------------*/

function processlogar1() 
{ 
     if (xmlhttp.readyState == 1) 
	 {          
		 loading(2);
	 }
	if (xmlhttp.readyState == 4) 
	{ 
       if (xmlhttp.status == 200) 
	   {            
		   if(xmlhttp.responseText == '1')
		   {
				window.location = 'contratante_logado.php';
		   }else
		   {
				alert('Login e/ou senha incorreta!!');			
				fecha_loading();
		   }
      }else 
	  { 
	  		alert('Problemas ao carregar a p&aacute;gina, tente mais tarde.');
			fecha_loading();
      } 
    } 
}
/*---------------------------------*/
function logar2() 
{     		
	atribui_XMLHttpRequest();
	pag = 'autentica2.php?login='+document.form1.login.value+'&senha='+document.form1.senha.value;
    xmlhttp.open("GET", pag, true); 	
    xmlhttp.onreadystatechange = processlogar2; 
    xmlhttp.send(null); 
}
/*---------------------------------*/

function processlogar2() 
{ 
     if (xmlhttp.readyState == 1) 
	 {          
		 loading(2);
	 }
	if (xmlhttp.readyState == 4) 
	{ 
       if (xmlhttp.status == 200) 
	   {            
		   if(xmlhttp.responseText == '1')
		   {
				window.location = 'imprensa_logado.php';
		   }else
		   {
				alert('Login e/ou senha incorreta!!');			
				fecha_loading();
		   }
      }else 
	  { 
	  		alert('Problemas ao carregar a p&aacute;gina, tente mais tarde.');
			fecha_loading();
      } 
    } 
}

/*---------------------------------*/
function verifica_login(valor) 
{     		
	document.getElementById("email").value = document.getElementById("login").value;
	atribui_XMLHttpRequest();
	pag = 'verifica_login.php?login='+valor;
    xmlhttp.open("GET", pag, true); 	
    xmlhttp.onreadystatechange = processverifica_login; 
    xmlhttp.send(null); 
}
/*---------------------------------*/

function processverifica_login() 
{ 
     if (xmlhttp.readyState == 1) 
	 {          
		 //loading(2);
	 }
	if (xmlhttp.readyState == 4) 
	{ 
       if (xmlhttp.status == 200) 
	   {            
		   if(xmlhttp.responseText == '1')
		   {
				alert('O email '+document.getElementById("login").value+' existe em nosso cadastro. Por favor coloque outro.');
				document.getElementById("login").value = '';
				document.getElementById("email").value = '';
		   }else
		   {
				
		   }
      }else 
	  { 
	  		
      } 
    } 
}
/*---------------------------------*/
function atribui_XMLHttpRequest()
{
	if (window.XMLHttpRequest) { 
    	xmlhttp = new XMLHttpRequest(); 
   	} else if (window.ActiveXObject) { 
     	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
   	} else { 
       	alert("Seu navegador n&atilde;o suporta XMLHttpRequest."); 
    	return; 
   	}		
}
function fecha_loading()
{
	document.getElementById("overlayTB").style.height = '100%';
	document.getElementById("overlayTB").style.display = 'none';	
	document.getElementById("divloading").innerHTML = '';	
}
/*---------------------------------*/

function escreve_msg(msg)
{
	document.getElementById("msg").innerHTML = msg;
	/*Effect.Shake('msg');
	fecha_loading();*/
}
/*---------------------------------*/

function escreve(msg,divi)
{
	document.getElementById(divi).innerHTML = msg;
}
/*---------------------------------*/

function loading(aux)
{	
	var aux = getPageSize();
	document.getElementById("overlayTB").style.height = aux[1];
	document.getElementById("overlayTB").style.display = 'block';
	if(aux == 1) document.getElementById("divloading").innerHTML = loader;
		else document.getElementById("divloading").innerHTML = loader2;
}


function muda_pagina1(pagina)
{
	//alert(pagina);
	self.location=pagina;
}

function mascara(tecla,src,mask) {
    var _TXT = tecla.keyCode; 
	if(_TXT != 8 && _TXT !=46)
	{
	    var i = src.value.length; 
		var saida = mask.substring(0,1); 
		var texto = mask.substring(i);
 		if(texto.substring(0,1) != saida)
		{ 
			src.value += texto.substring(0,1); 
		} 
	}
    return true; 	
}
/*---------------------------------*/

function so_numeros(tecla) {
    var _TXT = tecla.keyCode; 
    if((_TXT > 47 && _TXT < 58) || (_TXT > 34 && _TXT < 41) || (_TXT > 95 && _TXT < 106) || _TXT==46 || _TXT==9) 
	{  		
    	return true; 
	}else 
	{ 
		if(_TXT != 8) return false; 
			else return true; 
    }
}

/*---------------------------------*/

function enviar()
{
	loading(2);
	var form = document.forms[0];
	/*var i=0;
	for (var x = 0,y = form.length-1; x<y;x++) 
	{    
		form.elements[x].style.backgroundImage = "";
		if (form.elements[x].value == "" && form.elements[x].type != "hidden" && form.elements[x].type != "file" && form.elements[x].type != "checkbox" && form.elements[x].lang != "pt") 
		{    
			i++;				
			form.elements[x].style.backgroundImage = "url(images/alert.png)";
			form.elements[x].style.backgroundRepeat = "no-repeat";
			form.elements[x].style.backgroundPosition = "right top";
		}
	}
	if(i == 0){ 
	form.submit(); }else{escreve_msg('Preencha os campos obrigat&oacute;rios.');}*/
	form.submit();
	//alert('oi');
	//document.getElementById("form1").submit();
}
/*---------------------------------*/

function enviar_obrigatorios()
{	
	var form = document.forms[0];
	var i=0;
	for (var x = 0,y = form.length-1; x<y;x++) 
	{    
		form.elements[x].style.backgroundImage = "";
		if (form.elements[x].value == "" && form.elements[x].type != "hidden" && form.elements[x].type != "file" && form.elements[x].type != "checkbox" && form.elements[x].lang != "pt") 
		{    
			i++;				
			form.elements[x].style.backgroundImage = "url(admin/images/alert.png)";
			form.elements[x].style.backgroundRepeat = "no-repeat";
			form.elements[x].style.backgroundPosition = "right top";
		}
	}
	if(i == 0){ 
	form.submit(); }else{escreve_msg('Preencha os campos obrigat&oacute;rios.');}
	//form.submit();
	//alert('oi');
	//document.getElementById("form1").submit();
}
/*---------------------------------*/

function esconde(a)
{				
	document.getElementById(a).style.display = 'none';	
}
/*---------------------------------*/

function mostra(a)
{				
	if(document.getElementById(a).style.display == 'none') document.getElementById(a).style.display = '';
		else document.getElementById(a).style.display = 'none';
}
/*---------------------------------*/

function getPageSize()
{
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) 
	{
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight)
	{ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else 
	{ // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) 
	{	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) 
	{ // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) 
	{ // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight)
	{
		pageHeight = windowHeight;
	} else 
	{
		pageHeight = yScroll;
	}
	//return pageHeight;
}
/*---------------------------------*/
function copiar(auxlink)
{
	var Copied = document.getElementById(auxlink).createTextRange();
	Copied.execCommand('copy', false, null); 
}
/*---------------------------------*/

function abre_pop1(pagina,w,h)
{	
	
	var top = (document.body.clientHeight/2)-(h/2)+document.body.scrollTop;
	var left = (document.body.clientWidth/2)-(w/2);
	var wpag = w;
	//var hpag = h-15;
	var hpag = h;
	var popup;	
	var divi;
	popup = document.getElementById("divpop");
	divi = 'divpop';	
	if(top < 1) top = 1;
	if(left < 1) left = 1;
	//document.getElementById("overlayTB").style.height = document.body.clientHeight;
	var aux = getPageSize();
	document.getElementById("overlayTB").style.height = aux[1];
	document.getElementById("overlayTB").style.display = 'block';
	popup.style.width = w;	
	popup.style.height = h;	
	popup.style.top = top;	
	popup.style.left = left;	
	popup.style.backgroundColor = '#FFFFFF';
	//document.getElementById("divpop").innerHTML = '<div style="width:'+(w-20)+'px;height12px;margin-right:5px;margin-top:2px;position:absolute;top;0;left:0" align="right"><img src="images/x2.png" border="0" style="cursor:pointer;" onclick="fecha_pop()"></div><iframe id="popcontent" src="'+pagina+'" width="'+wpag+'" height="'+hpag+'" hspace="0" align="top" frameborder="0" marginheight="0" marginwidth="0" scrolling="auto" vspace="0"></iframe>';
	popup.innerHTML = '<div style="width:'+(w-5)+'px;height12px;margin-right:5px;margin-top:-15px;position:absolute;top;0;left:0" align="right"><img src="admin/images/x2.png" border="0" style="cursor:pointer;" onclick="fecha_pop()"></div><iframe id="popcontent" src="'+pagina+'" width="'+wpag+'" height="'+hpag+'" hspace="0" align="top" frameborder="0" marginheight="0" marginwidth="0" scrolling="auto" vspace="0"></iframe>';
	Effect.Appear(divi);	
}
/*---------------------------------*/

function fecha_pop()
{	
	document.getElementById("overlayTB").style.height = '100%';
	document.getElementById("overlayTB").style.display = 'none';	
	document.getElementById("divpop").innerHTML = '';
	Effect.Fade('divpop');
}
/*---------------------------------*/
function mostra_outros(valor)
{
	if(valor == 'Outros')
	{
		document.getElementById("divoutros").style.display = '';	
	}else
	{
		document.getElementById("divoutros").style.display = 'none';
		document.getElementById("outros").value = '';	
	}
}

/*---------------------------------*/
function verifica_imprensa(valor) 
{     		
	document.getElementById("email").value = document.getElementById("login").value;
	//alert(document.getElementById("email").value);
	atribui_XMLHttpRequest();
	pag = 'verifica_imprensa.php?login='+valor;
    xmlhttp.open("GET", pag, true); 	
    xmlhttp.onreadystatechange = processverifica_imprensa; 
    xmlhttp.send(null); 
}
/*---------------------------------*/

function processverifica_imprensa() 
{ 
     if (xmlhttp.readyState == 1) 
	 {          
		 //loading(2);
	 }
	if (xmlhttp.readyState == 4) 
	{ 
       if (xmlhttp.status == 200) 
	   {            
		   if(xmlhttp.responseText == '1')
		   {
				alert('O email '+document.getElementById("login").value+' existe em nosso cadastro. Por favor coloque outro.');
				document.getElementById("login").value = '';
				document.getElementById("email").value = '';
		   }else
		   {
				
		   }
      }else 
	  { 
	  		
      } 
    } 
}