<!--
/*
.
.       RPC - Rede Paranaense de Comunicacao
.       Projeto: Classificados GP/JL
.       Modulo: JS
.       Criado em: 22/02/2007
.       Autor: pauloh@rpc.com.br
.       Revisado por: ...
.       Ultima alteracao em:
*/

function PopUp(url,largura,altura,nome,topo,esquerda,bar,scroll,res) {
        if (!(esquerda)) esquerda = 100;
        if (!(topo)) topo = 100;
        if (!(altura)) altura = 500;
        if (!(largura)) largura = 618;
        if (!(bar)) scroll = 1;
        if (!(nome)) nome = "Pesquisa";
        if (!(res)) res = 1;

        window.open( url, nome, "left=" + esquerda + ",top=" + topo + ",width=" + largura + ",height=" + altura + ",resizable=" + res + ",scrollbars=" + scroll + ",toolbar=0,status=0,location=0,directories=0,menubar=0");
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function RPC_Menu(layer)
{
	var nets = navigator.appName == "Netscape";
	var ns4 = (nets && parseInt(navigator.appVersion) == 4);
	var rpclayer = MM_findObj(layer);

	if (!ns4)
	{
		if (rpclayer.style['visibility']=='visible' || rpclayer.style['visibility']=='show')
		{
			MM_showHideLayers(layer,'','hide');
			rpclayer.style['height'] = '1px';
		}
		else
		{
			MM_showHideLayers(layer,'','show');
			rpclayer.style['height'] = '';
		}
	}
}

// Funcoes de adicionar imoveis a lista

function SetCookie (name, value)    {
   var argv = SetCookie.arguments;
   var argc = SetCookie.arguments.length;
   var expires = (argc > 2) ? argv[2] : null;
   var path = "/";
   var domain = (argc > 4) ? argv[4] : null;
   var secure = (argc > 5) ? argv[5] : false;
   document.cookie = name + "=" + escape (value) +
        ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
        ((path == null) ? "" : ("; path=" + path)) +
        ((domain == null) ? "" : ("; domain=" + domain)) +
        ((secure == true) ? "; secure" : "");
   }

function SetTheCookie()   {
   if(document.forms[0].elements[0].value.length != 0)        {
      var expdate = new Date ();
      expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 365));
      SetCookie('DemoName', document.forms[0].elements[0].value, expdate);
      alert('Cookie has been set to ' + document.forms[0].elements[0].value + '.');
      document.forms[0].elements[0].value = " ";
            return false;
      }    else       {
      alert('You must sign-in first.');
      return false;
      }
   }
function getCookieVal (offset)    {
     var endstr = document.cookie.indexOf (";", offset);
     if (endstr == -1)
     endstr = document.cookie.length;
     return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name)    {
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;
   while (i < clen)       {
      var j = i + alen;
      if (document.cookie.substring(i, j) == arg)
         return getCookieVal (j);
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0) break; 
      }
   return "";
   }

function getListaAnuncios() {

   var arrayLista = new Array();
   var cookie = GetCookie("GazetaClassificados")

   if (cookie != "") {
       arrayLista =  montaResultadoXmlRequest(cookie);
   }
	return arrayLista;
}

function enviarEmail(anuncio) {
	document.location="./verLista.phtml?Anunci_ID="+anuncio;
}

function adicionarLista(valor) {

   if (testaValor(valor) == 0) {
      alert("Este anúncio já foi selecionado e se encontra em sua lista.")
      return
   }

   var arrayLista = getListaAnuncios();
   if(valor != "") {
		arrayLista.push(valor);
   
		cookie = arrayLista.toJSONString();
		SetCookie("GazetaClassificados", cookie);
   }
	
   atualizaContador();
}


function esvaziarLista(reload) {
	SetCookie("GazetaClassificados", "")
	$('total_lista').innerHTML = 0
	if (reload == 1) {
		document.location.href=document.location.href;
	}
}

function removerAnuncio(anuncio) {

	var arrayLista = getListaAnuncios();
	var arrayAux = new Array();
	for (i=0; i < arrayLista.length; i++ ) {
		if(arrayLista[i] != anuncio) {
			arrayAux.push(arrayLista[i]);
		}
	}

 	cookie = arrayAux.toJSONString();
	SetCookie("GazetaClassificados", cookie);
	
	document.location.href=document.location.href;
}

function testaValor(numero) {

   count = 0
   var arrayLista = getListaAnuncios();
   for (i=0; i < arrayLista.length; i++ ) { 
       if (arrayLista[i] == numero) {  
           return 0;
       }
   }
   return 1
}
   
function contarAnuncios() {
   
   var arrayLista = getListaAnuncios();
   return arrayLista.length;

}

function atualizaContador() {

    var valores = GetCookie("GazetaClassificados")
	if (valores == "") {
		$('total_lista').innerHTML = "0";
	} else {
		$('total_lista').innerHTML = contarAnuncios();
	}

}

/*FUNCOES ANTIGAS*/
/*
function adiciona(valor,pop) {

   if (testar(valor) == 0) { 
      alert("Este anúncio já foi selecionado e se encontra em sua lista.")
      return
   }
   var valorantigo = GetCookie("GazetaClassificados")
      
   if (valorantigo != "") {
	var valornovo = valorantigo + "|" + valor

//	document.lista.qtde.value = eval(document.lista.qtde.value) + 1
//	if(pop)opener.document.lista.qtde.value = eval(opener.document.lista.qtde.value) + 1

	SetCookie("GazetaClassificados", valornovo)
   } else {

//	document.lista.qtde.value = eval(document.lista.qtde.value) + 1
//	if(pop)opener.document.lista.qtde.value = eval(opener.document.lista.qtde.value) + 1

	SetCookie("GazetaClassificados", valor) 
   }
   ler();
}

function testar(numero) {
   
   count = 0
   vari = GetCookie("GazetaClassificados") //document.lista.valor.value
   var inicio = 0
   for (i=0;i < vari.length;i++ ) { 
       if (vari.substring(i,i+1) == "|") {  
          if (numero == vari.substring(inicio,i)) { return 0 }
          inicio = i+1     
       }
   }
   if (numero == vari.substring(inicio,i)) { return 0 }
   return 1
}

function contar() {
   
   ar = new Array
   count = 0
   vari = GetCookie("GazetaClassificados") //document.lista.valor.value
	if (vari == "") {
		return 0;
	} else {
		   var inicio = 0
		   for (i=0;i < vari.length;i++ ) { 
			   if (vari.substring(i,i+1) == "|") {  
				  ar[count++] = vari.substring(inicio,i)
				  inicio = i+1     
			   }
		   }
		   ar[count++] = vari.substring(inicio,i)
		   return count
	}
}

function ler() {

    var valores = GetCookie("GazetaClassificados")
	if (valores == "") {
		var valores = ""
		$('total_lista').innerHTML = "0";
	} else {
		$('total_lista').innerHTML = contar();
	}

}
*/


function FormataMoeda(campo) {
	vr = campo.value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( ",", "" );
	tam = vr.length ;

	campo.value='';
	if (tam > 2) campo.value += vr.substr(0 ,(tam - 2)) + '.';
	if (tam) campo.value += vr.substr( (tam -2), 2 );
	if (tam  == 1) campo.value = vr + '.00' ;
	if (tam  == 2) campo.value = vr + '.00' ;

}

function apaga(numero) {
   
   novalista = ""
   count = 0
   vari = GetCookie("GazetaClassificados") //document.lista.valor.value
   var inicio = 0
   for (i=0;i < vari.length;i++ ) { 
       if (vari.substring(i,i+1) == "|") {  
          if (vari.substring(inicio,i) != numero) { 
                    count++
					if (novalista == "") {
						novalista = vari.substring(inicio,i)
					} else {
					    novalista = novalista + "|" + vari.substring(inicio,i)
					}               
           }
           inicio = i+1
	    }
	}
   

   if (vari.substring(inicio,i) != numero) {
		count++ 
		if (novalista == "") {
				novalista = vari.substring(inicio,i)
		} else {
				novalista = novalista + "|" + vari.substring(inicio,i)
		}  
   }

   SetCookie("GazetaClassificados", novalista)
   opener.document.lista.qtde.value = count
   //document.lista.submit()
   //document.location.reload();
   document.location.href=document.location.href;
}


function combo(targ,selObj,restore)
{
 eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
 if (restore) selObj.selectedIndex=0;
}

function ContaObs(campo, contacampo, total)
{
	if(campo.value.length > total)
	{
		alert ("O campo de observação deve ter no máximo "+total+" caracteres.");
		campo.value = campo.value.substring(0, total);
	}
    contacampo.innerHTML = campo.value.length;
}

/* Volta a foto */
function back() {
	var fotos = $TAG('li', $('fotos'));
	for (i=0; i< fotos.length; i++) {
		if(fotos[i].style.display == 'block') {
			//esconde a foto atual
			fotos[i].style.display = 'none';
			//verifica a prox foto a ser mostrada
			if(i == 0) { //e a primeira foto da lista vai pra ultima
				fotos[fotos.length - 1].style.display = 'block';
			} else {//exibe a prox img da lista
				fotos[i-1].style.display = 'block';
			}
			return;
		}
	}
}

/* Avanca a foto */
function forward() {
	var fotos = $TAG('li', $('fotos'));
	for (i=0; i< fotos.length; i++) {
		if(fotos[i].style.display == 'block') {
			//esconde a foto atual
			fotos[i].style.display = 'none';
			//verifica a prox foto a ser mostrada
			if(i == (fotos.length - 1)) { //e a ultima foto da lista volta pra primeira
				fotos[0].style.display = 'block';
			} else {//exibe a prox img da lista
				fotos[i+1].style.display = 'block';
			}
			return;
		}
	}
}

function verLista() {
	if(contarAnuncios() > 0) {
		document.location="./verLista.phtml";
//		alert(contar());
	} else { 
		alert ('Sua lista está vazia.'); 
	}
}

function imprimir(url) {
	if(url.lastIndexOf('?') > 0) {
		url = url+'&printmode=on';
	} else {
		url = url+'?printmode=on';
	}
	PopUp(url, 790, 600, 'print');
}

function printLista(url) {
	if(contarAnuncios() > 0) {
		imprimir(url);
	} else { 
        alert ('Sua lista está vazia.'); 
    }
}

/* Colocar em um js a parte */
function webIdFocus() {
	if($('webid').value == 'Web ID') {
		$('webid').value = '';
	}
}

function webIdOut() {
	if($('webid').value == '') {
		$('webid').value = 'Web ID';
	}
}


function RPC_ChecaForm()
{
  required = document.formulario.required.value;

  if (required.length > 1 && required.search("|") != -1)  {                     
        required = required.split("|");
                                
        for (i = 1; i <= required.length; i++) {                       
                atual_igual = 0;        
                checa = 1;                      
                                        
                atual_inteiro = required[i-1];
                        
                if (atual_inteiro.search(":") != -1) {       
                        atual_total = atual_inteiro.split(":");
                        atual = atual_total[0];
                        atual_nome = atual_total[1];
                } else {
                        atual = atual_inteiro;
                        atual_nome = atual;
                        atual_igual = 1;
                }

                if (atual.search("/") != -1 && atual.search("=") != -1) {
                        atual_if = atual.split("/");

                        atual = atual_if[0];
                        atual_expr = atual_if[1];
                        atual_expr = atual_expr.split("=");

                        atual_param = atual_expr[0];
                        atual_arg = atual_expr[1];

                        campo_param = eval('document.formulario.'+atual_param);
                        campo_arg = "";

	                    if (campo_param.length > 1) {
                                for (counter = 0; counter < campo_param.length; counter++) {
	                                if (campo_param[counter].checked || (campo_param[counter].selected && campo_param.value.length > 1)) {
                                                campo_arg = campo_param[counter].value;
                                    }
                                }
                        } else {
                                campo_arg = campo_param.value;
                        }

                        if (atual_arg != 'notnull' && campo_arg != atual_arg) {
                                checa = 0;
                        } else if (atual_arg == 'notnull' && campo_arg.length == 0) {
                                checa = 0;
                        }
                }

               if (atual_igual == 1) {
                        atual_nome = atual;
                }

                campo_atual = eval('document.formulario.'+atual);
                valor_atual = campo_atual.value;
                msg_erro = "O campo \"" + atual_nome + "\" parece estar em branco.\nPor gentileza, verifique.";

                if (checa == 1) {
                  if (campo_atual.length > 1) {
                        marcou = 0;
                        for (counter = 0; counter < campo_atual.length; counter++) {
	                        if (campo_atual[counter].checked || (campo_atual[counter].selected && valor_atual.length > 1)) {
    	                        marcou = 1;
                            }
                        }

                        if (marcou < 1) {
                                alert (msg_erro);
                                return false;
                        }
                  } else {
	                  if (valor_atual.length < 1) {
                          alert (msg_erro);
                          return false;
                     }
                  }
               }
        }
  }
}

-->
