/* Função que deixa marcado somente o 1º item da lista */
function limpaLista(pLista)
{	for (i=0; i<pLista.length; i++) pLista.options[i].selected = false;
	return true;
}

/* Função que retira edição do cep */
function inCep(pCep)
{  if (pCep.value.length == 9)
   {  pCep.value = pCep.value.substring(0,5) + pCep.value.substring(6,9);
      pCep.select();
   }
   return true;
}

/* Função que coloca edição no cep */
function outCep(pCep)
{  if (pCep.value.length == 8)
   {  pCep.value = pCep.value.substring(0,5) + "-" + pCep.value.substring(5,8);
   }
   else
   {  if (pCep.value.length == 9)
	     {  pCep.value = pCep.value.substring(0,5) + "-" + pCep.value.substring(6,9);
		 }
   }
   return true;
}

function novaJanela(pURL,pOpc)
{  
   var now = new Date();
   newWindow= "W" + now.getHours().toString() + now.getMinutes().toString() + now.getSeconds().toString();
   eval("var " + newWindow);
   eval(newWindow + " = window.open(pURL,null,pOpc)");
   eval(newWindow + ".focus()");
   return false;
}

function novaJanela2(pURL,pOpc)
{  
   var  newWindow2;
   newWindow2 = window.open(pURL,"new",pOpc);
   newWindow2.focus();
   return false;
}

function ampliaFoto(pURL,pWidth,pHeight,pWin)
{  var newWindow;
   newWindow = window.open(pURL,pWin,'height='+pHeight+',width='+pWidth);
   newWindow.moveTo(25,25);
   newWindow.focus();
   return false;
}

/* função para checar campos obrigatórios não preenchidos. */
function checaVazio(pElemento, pNome)
	{
	 strBranco = ""; // as String
	 for (i = 1; i <= pElemento.value.length; i = i + 1)
	     {
	      strBranco = strBranco + " "
	     }  
	 if (pElemento.value.length < 1 || pElemento.value == strBranco)
	    {
		 alert("O Campo " + pNome + " não pode ser vazio.");
		 pElemento.focus();
		 pElemento.select();
		 return false;
		}
	 else
		{ 
		 return true;
		}
	}
/* função para checar UF */
function checaUF(pElemento)
{
	 var uf = new Array("AC","AL","AM","AP","BA","CE","DF","ES","GO","MA","MG","MS","MT","PA","PB","PE","PI","PR","RJ","RN","RO","RR","RS","SC","SE","SP","TO");
	 for (i = 1; i <= 27; i = i + 1)
	 {
	    if (pElemento.value == uf[i])
	    {  return true;
	    }
	 }
	 alert("A UF não foi preenchida corretamente.");
	 pElemento.focus();
	 pElemento.select();
	 return false;
}

/* função para checar se o email é válido */
function checaEmail(pElemento)
	{
	if (pElemento.value.lastIndexOf("@") == -1)
		{
		 alert("Formato ilegal de E-mail.");
		 pElemento.focus();
		 pElemento.select();
		 return false;
		}
	else
		{
		 if ((pElemento.value.lastIndexOf("@") == 0) || (pElemento.value.lastIndexOf("@") == pElemento.value.length-1)) 
		    {
		     alert("Formato ilegal de E-mail.");
		     pElemento.focus();
		     pElemento.select();
		     return false;
	    	}
		 else
		    {
		     return true;
			}
		}
	}

/* Função que critica data */
function validaData(pData)
{
    if ((pData.value.length == 10) &&
        (pData.value.substring(2,3) == "/") &&
        (pData.value.substring(5,6) == "/"))
    {
        pData.value = pData.value.substring(0,2) + 
                      pData.value.substring(3,5) + 
                      pData.value.substring(6,10);
    }
    
    var pDia = pData.value.substring(0,2);
    var pMes = pData.value.substring(2,4);
    var pAno = pData.value.substring(4,8);
    var numDias = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
    
    if (pAno % 4 == 0) 
    {   numDias[01] = 29;
    }

    if (pData.value.length != 0)
    {  
       if ((pData.value.length != 8) ||
          (isNaN(pData.value)) || 
          (pAno < 1900) || 
          (pDia == 0) ||
          (pMes == 0) ||
          (pMes > 12) || 
          (pDia > numDias[pMes-1]))
       {
          alert("Data inválida. Utilize formato ddmmaaaa.");
          pData.focus(); 
          pData.select();
       }
       else
       {
          pData.value = pDia + "/" + pMes + "/" + pAno;
       }
    }
}

/* Função que retira as barras do campo data quando em foco */
function retiraBarras(pData)
{
   if ((pData.value.length == 10) && (pData.value.substring(2,3) == "/") && (pData.value.substring(5,6) == "/"))
   {
      pData.value = pData.value.substring(0,2) + 
                    pData.value.substring(3,5) + 
                    pData.value.substring(6,10);
   }
   pData.select();
}

/* Função que monta os campos a serem enviados via QueryString
function montarQS(pValor)
{	var Cr = String.fromCharCode(13);
	var aspa=String.fromCharCode(34); 
	pValor = substituir(pValor,"%", "¥0"); //958
	pValor = substituir(pValor,Cr,  "¥1");
	pValor = substituir(pValor," ", "¥2");
	pValor = substituir(pValor,aspa,"¥3");
	pValor = substituir(pValor,"&", "¥4");
	pValor = substituir(pValor,"+", "¥5");
	pValor = substituir(pValor,"=", "¥6");
	pValor = substituir(pValor,"?", "¥7");
	return pValor;
}
*/
 
/* Função que substitui strings dentro de strings */
function substituir(pValor,pInp,pOut)
{	i   = 0;
	out = "";
	len = pValor.length;
	while (i < len)
	{	pos = pValor.indexOf(pInp,i);
		if (pos >= 0)
		{	out = out + pValor.substring(i,pos) + pOut;
			i = pos + 1;
		}
		else
		{	out = out + pValor.substring(i,len);
			i = len;
		}
	}
	return out;
}

/* Função para chamar a página de contato do site */
/**************************************************/
function fazerContato(pNv, pNm, pId, pAss)
{
	if (document.frmCt == null)
	{
		document.write("<Form name='frmCt' action='" + pNv + "scripts/contato.asp' method=post>");
		document.write("<input type=hidden name=hidCallNome value='" + pNm + "'>");
		document.write("<input type=hidden name=hidCallId value='" + pId + "'>");
		document.write("<input type=hidden name=hidCallAssunto value='" + pAss + "'>");
	}
	document.frmCt.hidCallNome.value = pNm;
	document.frmCt.hidCallId.value = pId;
	document.frmCt.hidCallAssunto.value = pAss;
	document.frmCt.submit();
	return false;
}