

function enviar_pesquisa_em_noticias(){
	if (document.tp.f_texto_pesquisar.value==""){
		alert('Falta preencher campo');
		document.tp.f_texto_pesquisar.focus();
		return false;
	}
	document.secundario.elements[0].name="f_texto_pesquisar";
	document.secundario.elements[0].value=document.tp.f_texto_pesquisar.value;
	document.secundario.submit();
	return false;
}

function carregar_os_campos(){
	if (! stimed_validar_campos('login2,senha2','tp')){
		return false;
	}
	if (document.cookie.indexOf("s=") !=-1){
		document.tp.senha2.value=getCookie("s");
	}
	if (document.tp.___armazenar_senha__.value=="1"){
		setCookie("s",document.tp.senha2.value);
		setCookie("u",document.tp.login2.value);
	}
	document.tp.login.value=document.tp.login2.value;
	document.tp.senha.value=document.tp.senha2.value;
	document.tp.login2.value="";
	document.tp.senha2.value="";
	navegar('tp','web_frame','tudo');
	return false;
}
function setCookie(NameOfCookie ,value){
	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (30 * 24 * 3600 * 1000));
	document.cookie = NameOfCookie + "=" + escape(value) + "; expires=" + ExpireDate.toGMTString();
}
function getCookie(NameOfCookie)
{
	if (document.cookie.length > 0) { 
		begin = document.cookie.indexOf(NameOfCookie+"="); 
		if (begin != -1){ 
			begin += NameOfCookie.length+1; 
			end = document.cookie.indexOf(";", begin);
			if (end == -1){
				end = document.cookie.length;
			}
			return unescape(document.cookie.substring(begin, end)); 
		} 
	}
	return null; 
}
function delCookie (NameOfCookie) 
{
	if (getCookie(NameOfCookie)) {
		document.cookie = NameOfCookie + "=" +"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
} 
function verificar_cookie(){
	if (document.cookie.indexOf("s=") !=-1){
		document.tp.senha2.value="senha";
		document.tp.login2.value=getCookie("u");
		document.tp.___armazenar_senha__.value="1";
	}
}
function lembrar(){
	if (document.tp.___armazenar_senha__.value == ""){
		document.tp.___armazenar_senha__.value="1";
		alert("Ok! Será Lembrado");
	}else{
		delCookie("s");
		delCookie("u");
		document.tp.___armazenar_senha__.value="";
		document.tp.senha2.value="";
		alert("Cancelado a opção de lembra a senha");	
	}
	return false;
}
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

var http_request = false;
/*sis.atualizacao
responsavel:Marcelo Reis
descricao:SE existir ajax_tag:funcao, indica que este processo será manual, definindo nesta tag
a função de retorno.
SE existir ajax_tag:id, informa que o processo será automárico,retornando 
o conteúdo para ser escrito dento do Id informado
	
*/
function alertContents() {

    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
			
			txt=http_request.responseText;
			tem_funcao_retorno=false;
			tem_id=false;
			if (txt.indexOf("<!--ajax_tag:teste-->")>-1){
				pop_up("",800,600,"debug",txt);
			}
			if (txt.indexOf("<!--ajax_tag:funcao:")>-1){
				funcao_retorno=txt.substring(txt.indexOf("<!--ajax_tag:funcao:")+20,txt.length);
				txt=funcao_retorno.substring(funcao_retorno.indexOf("-->")+3);
				funcao_retorno=funcao_retorno.substring(0,funcao_retorno.indexOf("-->"));
				
				tem_funcao_retorno=true;
			}
			if (txt.indexOf("<!--ajax_tag:msg:")>-1){
				funcao_retorno=txt.substring(txt.indexOf("<!--ajax_tag:msg:")+17,txt.length);
				texto=funcao_retorno.substring(0,funcao_retorno.indexOf("-->"));
				alert(texto);
				//pop_up("",800,600,"debug",texto);
				return;
			}			
			if (txt.indexOf("<!--ajax_tag:id:")>-1){
				tag_id=txt.substring(txt.indexOf("<!--ajax_tag:id:")+16,txt.length);
				tag_id=tag_id.substring(0,tag_id.indexOf("-->"));
				tem_id=true;
			}
			if (txt.indexOf("<!--ajax_tag:sem_acao-->")==-1){
				if ((tem_id) && (!tem_funcao_retorno)){
					dhtml_setar_texto(tag_id,txt);
				}else{
					if (tem_funcao_retorno){
						//txt=limpar_codigo(txt);
						//alert(txt);
						 eval(funcao_retorno+"(txt)");
					}else{
			            eval(funcao_retorno+"(http_request.responseText)");
					}
				}
			}
			
        } else {
            pop_up("",800,600,"erro",http_request.responseText);
        }
    }

}
var funcao_retorno = "alert";
function dhtml_setar_texto(nome_objeto,texto){
	try{
		document.getElementById(nome_objeto).innerHTML=texto;
	}catch(e){
		try{
			document.all[nome_objeto].innerHTML=texto
		}catch(e){
			window.status='Não localizado o objeto:' + nome_objeto;
		}
	}
}
function pop_up(n,x,y,target,texto_a_escrever,novos_parametros,atributos){
	if(target==null){target="pop_up";}
	x=(x==null ? 700 : x);
	y=(y==null ? 400 : y);
    esquerda  = ( screen.width  ) ? ( screen.width  - parseInt( x )  ) / 2 : 0;
    topo	  = ( screen.height ) ? ( screen.height - parseInt( y ) ) / 2 : 0; 
	
	//
	if (atributos == null)
		atributos = 1;
	try{
		if (novos_parametros==null){
			var desktop = window.open(n, target, 'width='+ x + ',height='+y +  ',left='+ esquerda + ', top=' + topo + ',toolbar=no,location=no,status=yes,directories=no,menubar=no,scrollbars='+atributos+',resizable=yes,copyhistory=no');
		}else{
			var desktop = window.open(n, target, 'width='+ x + ',height='+y +  ',left='+ esquerda + ', top=' + topo + ','+novos_parametros);
		}
		if (texto_a_escrever!=null){
			desktop.document.write(texto_a_escrever);
		}
		desktop.focus();
	}catch(e){
		alert("Não foi possível abrir a tela porque seu browser tem um programa chamado ANTI POP-UP. Por favor queira desativar para que o STIMED funcione normalmente.");
	}
	return false;
}

