function popuphelp() { mywin = window.open('formulario/fotocopia/fotocopiahelp.htm','AddressBook','width=480,height=220,top=200,left=180'); }
function AddAddress(strType,strAddress) {
		obj = eval('document.composeForm.'+strType);
		if(obj.value == '') obj.value = strAddress
		else  document.composeForm.reset
		libera();
		obj.value = strAddress
	}

function FormataData(Campo, teclapres)
{
	var tecla = teclapres.keyCode;
	var vr = new String(Campo.value);
	vr = vr.replace("/", "");
	vr = vr.replace("/", "");
	tam = vr.length + 1;
	
	if (tecla != 9 && tecla != 8) 
 		{
		if (tam > 2 && tam < 5)
			Campo.value = vr.substr(0, 2) + '/' + vr.substr(2, tam);
		if (tam >= 5 && tam <=10)
			Campo.value = vr.substr(0,2) + '/' + vr.substr(2,2) + '/' + vr.substr(4,4);
		
		}
}

function valida() {
	var garesim = document.preco.gare.selectedIndex;

	if (document.preco.gare.options[garesim].value == 'nao'){ 
	    document.preco.valor.disabled = true;}

	var assunto = document.preco.tipo1.selectedIndex;

	if (document.preco.tipo1.options[assunto].value == ' '){ 
	    document.preco.n_1.disabled = true;
	    document.preco.n_dt_1.disabled = true;}
else {
	    document.preco.n_1.disabled = false;
	    document.preco.n_dt_1.disabled = false;}

	var assunto2 = document.preco.tipo2.selectedIndex;

	if (document.preco.tipo2.options[assunto2].value == ' '){ 
	    document.preco.n_2.disabled = true;
	    document.preco.n_dt_2.disabled = true;}
else {
	    document.preco.n_2.disabled = false;
	    document.preco.n_dt_2.disabled = false;}

	var assunto3 = document.preco.tipo3.selectedIndex;

	if (document.preco.tipo3.options[assunto3].value == ' '){ 
	    document.preco.n_3.disabled = true;
	    document.preco.n_dt_3.disabled = true;}
else {
	    document.preco.n_3.disabled = false;
	    document.preco.n_dt_3.disabled = false;}

	var assunto4 = document.preco.tipo4.selectedIndex;

	if (document.preco.tipo4.options[assunto4].value == ' '){ 
	    document.preco.n_4.disabled = true;
	    document.preco.n_dt_4.disabled = true;}
else {
	    document.preco.n_4.disabled = false;
	    document.preco.n_dt_4.disabled = false;}

	var assunto5 = document.preco.tipo5.selectedIndex;

	if (document.preco.tipo5.options[assunto5].value == ' '){ 
	    document.preco.n_5.disabled = true;
	    document.preco.n_dt_5.disabled = true;}
else {
	    document.preco.n_5.disabled = false;
	    document.preco.n_dt_5.disabled = false;}

	var assunto6 = document.preco.tipo6.selectedIndex;

	if (document.preco.tipo6.options[assunto6].value == ' '){ 
	    document.preco.n_6.disabled = true;
	    document.preco.n_dt_6.disabled = true;}
else {
	    document.preco.n_6.disabled = false;
	    document.preco.n_dt_6.disabled = false;}

	var assunto7 = document.preco.tipo7.selectedIndex;

	if (document.preco.tipo7.options[assunto7].value == ' '){ 
	    document.preco.n_7.disabled = true;
	    document.preco.n_dt_7.disabled = true;}

else {
	    document.preco.n_7.disabled = false;
	    document.preco.n_dt_7.disabled = false;}

	var assunto8 = document.preco.tipo8.selectedIndex;

	if (document.preco.tipo8.options[assunto8].value == ' '){ 
	    document.preco.n_8.disabled = true;
	    document.preco.n_dt_8.disabled = true;}

else {
	    document.preco.n_8.disabled = false;
	    document.preco.n_dt_8.disabled = false;}

	var assunto9 = document.preco.tipo9.selectedIndex;

	if (document.preco.tipo9.options[assunto9].value == ' '){ 
	    document.preco.n_9.disabled = true;
	    document.preco.n_dt_9.disabled = true;}

else {
	    document.preco.n_9.disabled = false;
	    document.preco.n_dt_9.disabled = false;}

	var assunto10 = document.preco.tipo10.selectedIndex;

	if (document.preco.tipo10.options[assunto10].value == ' '){ 
	    document.preco.n_10.disabled = true;
	    document.preco.n_dt_10.disabled = true;}
else {
	    document.preco.n_10.disabled = false;
	    document.preco.n_dt_10.disabled = false;}

        }
        
function Envia() {
          Ireg  = document.preco.tipo.selectedIndex
          Vreg  = document.preco.tipo.options[Ireg].value
          if (Vreg == 'negativa') {
              if (confirm('Antes de Gerar o formulario para emissao da certidão negativa de pessoa fisica verifique se os campos: Nome da Mãe e RG do Requerente estão corretamente preenchidos. Deseja continuar ?'))
	              {alert('É necessario anexar cópia do RG e CPF');       
		      return true }
              else {
                      alert('FORMULÁRIO NÃO ENVIADO !')
                      return false }
          }
          if (Vreg == 'apsocio') {
              if (confirm('Antes de Gerar o formulario para emissao da certidao de breve relato verifique se o campo: Nome do Sócio esta devidamente preenchido. Deseja continuar ?'))
	              { return true }
              else {
                      alert('FORMULÁRIO NÃO ENVIADO !')
                      return false }
          }
          if (Vreg == 'apdiretor') {
              if (confirm('Antes de Gerar o formulario para emissao da certidao de breve relato verifique se o campo: Nome do Diretor esta devidamente preenchido. Deseja continuar ?'))
	              { return true }
              else {
                      alert('FORMULÁRIO NÃO ENVIADO !')
                      return false }
          }
      }

function nire() {
           	alert('IMPORTANTE => O preenchimento do NIRE é obrigatório.');
		}

function simples() {
          Lreg  = document.preco.operacao.selectedIndex
          Xreg  = document.preco.operacao.options[Lreg].value
          if (Xreg == 'R$ 9,00') {
		 if (confirm("Antes de Gerar o formulário para emissão da certidão, obtenha informações do tipo: Valores das taxas, preenchimento, recomendações e tempo do serviço. Deseja obter agora essas informações ?")) {
		 vote();
		                 }
		 else  cancel();
				 }
		 function vote () {
		 parent.principal.location.href = "../certidoes/certidoes.htm#top";
				 }
		 function cancel () {
		 alert('Além do preenchimento do Pedido de Certidão de Breve Relato, o usuário deverá ainda, preencher em 02 vias sem rasuras, utilizando máquina de escrever o formulário Certidão Simplificada, adquirido em qualquer papelaria.'); 
				 }              
		      }

function irpara(form) {
	var assunto = form.tipo1.selectedIndex;

	if (form.tipo1.options[assunto].value == ' '){ 
	    form.n_1.disabled = true;
	    form.n_dt_1.disabled = true;}
else {
	    form.n_1.disabled = false;
	    form.n_dt_1.disabled = false;}

	var assunto2 = form.tipo2.selectedIndex;

	if (form.tipo2.options[assunto2].value == ' '){ 
	    form.n_2.disabled = true;
	    form.n_dt_2.disabled = true;}
else {
	    form.n_2.disabled = false;
	    form.n_dt_2.disabled = false;}

	var assunto3 = form.tipo3.selectedIndex;

	if (form.tipo3.options[assunto3].value == ' '){ 
	    form.n_3.disabled = true;
	    form.n_dt_3.disabled = true;}
else {
	    form.n_3.disabled = false;
	    form.n_dt_3.disabled = false;}

	var assunto4 = form.tipo4.selectedIndex;

	if (form.tipo4.options[assunto4].value == ' '){ 
	    form.n_4.disabled = true;
	    form.n_dt_4.disabled = true;}
else {
	    form.n_4.disabled = false;
	    form.n_dt_4.disabled = false;}

	var assunto5 = form.tipo5.selectedIndex;

	if (form.tipo5.options[assunto5].value == ' '){ 
	    form.n_5.disabled = true;
	    form.n_dt_5.disabled = true;}
else {
	    form.n_5.disabled = false;
	    form.n_dt_5.disabled = false;}

	var assunto6 = form.tipo6.selectedIndex;

	if (form.tipo6.options[assunto6].value == ' '){ 
	    form.n_6.disabled = true;
	    form.n_dt_6.disabled = true;}
else {
	    form.n_6.disabled = false;
	    form.n_dt_6.disabled = false;}

	var assunto7 = form.tipo7.selectedIndex;

	if (form.tipo7.options[assunto7].value == ' '){ 
	    form.n_7.disabled = true;
	    form.n_dt_7.disabled = true;}

else {
	    form.n_7.disabled = false;
	    form.n_dt_7.disabled = false;}

	var assunto8 = form.tipo8.selectedIndex;

	if (form.tipo8.options[assunto8].value == ' '){ 
	    form.n_8.disabled = true;
	    form.n_dt_8.disabled = true;}

else {
	    form.n_8.disabled = false;
	    form.n_dt_8.disabled = false;}

	var assunto9 = form.tipo9.selectedIndex;

	if (form.tipo9.options[assunto9].value == ' '){ 
	    form.n_9.disabled = true;
	    form.n_dt_9.disabled = true;}

else {
	    form.n_9.disabled = false;
	    form.n_dt_9.disabled = false;}

	var assunto10 = form.tipo10.selectedIndex;

	if (form.tipo10.options[assunto10].value == ' '){ 
	    form.n_10.disabled = true;
	    form.n_dt_10.disabled = true;}
else {
	    form.n_10.disabled = false;
	    form.n_dt_10.disabled = false;}
	}
	
function Verifica_campo_CNPJ_CPF(campo) {
     
     var Form, resposta, s;
     Form = document.preco;

if (Form.CNPJ_CPF.value.length == 0) 
        {
	 alert("Por favor, informe CNPJ/CPF do requerente...");
         Form.CNPJ_CPF.focus();
         return false;
        }
     
if (valida_numeros(Form.CNPJ_CPF.value) == false) 
           {
   	    alert("CNPJ/CPF deve ser completamente numérico e sem formatação...");
            Form.CNPJ_CPF.focus();
            return false;
           }           

     s = limpa_string(Form.CNPJ_CPF.value);
     // checa se é cpf
     if (s.length == 11) {
	if (valida_CPF(Form.CNPJ_CPF.value) == false ) {
           alert("CPF inválido!");
           Form.CNPJ_CPF.focus();
           return false;
	}
     }
     // checa se é cgc
     else if (s.length == 14) {
        if (valida_CGC(Form.CNPJ_CPF.value) == false ) {
	   alert("CNPJ inválido!");
           Form.CNPJ_CPF.focus();
           return false;
	}
     }
     else {
        alert("CNPJ/CPF inválido!");
           Form.CNPJ_CPF.focus();
        return false;
     }
     

  
     
     return true;
}
function limpa_string(S){
// Deixa so' os digitos no numero
var Digitos = "0123456789";
var temp = "";
var digito = "";
    for (var i=0; i<S.length; i++){
      digito = S.charAt(i);
      if (Digitos.indexOf(digito)>=0){temp=temp+digito}
    }
    return temp
}
function valida_CPF(s)
{
	var i;
	s = limpa_string(s);
	var c = s.substr(0,9);
	var dv = s.substr(9,2);
	var d1 = 0;
	for (i = 0; i < 9; i++)
	{
		d1 += c.charAt(i)*(10-i);
	}
        if (d1 == 0) return false;
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1)
	{
		return false;
	}

	d1 *= 2;
	for (i = 0; i < 9; i++)
	{
		d1 += c.charAt(i)*(11-i);
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1)
	{
		return false;
	}
        return true;
}

function valida_CGC(s)
{
	var i;
	s = limpa_string(s);
	var c = s.substr(0,12);
	var dv = s.substr(12,2);
	var d1 = 0;
	for (i = 0; i < 12; i++)
	{
		d1 += c.charAt(11-i)*(2+(i % 8));
	}
        if (d1 == 0) return false;
        d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1)
	{
		return false;
	}

	d1 *= 2;
	for (i = 0; i < 12; i++)
	{
		d1 += c.charAt(11-i)*(2+((i+1) % 8));
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1)
	{
		return false;
	}
        return true;
}


function valida_numeros(s)
{
	var i; 
	var dif = 0;
	for (i = 0; i < s.length; i++)
	{
		var c = s.charAt(i);
		if (!((c >= "0") && (c <= "9")))
		{
			dif = 1;
		}
	}
	if (dif == 1)
	{
		return false;
	}
	return true;
}

function valida_valores(s)
{
	var i; 
	var dif = 0;
	for (i = 0; i < s.length; i++)
	{
		var c = s.charAt(i);
		if (!(  ((c >= "0") && (c <= "9")) || (c==',')    ))
		{
			dif = 1;
		}
	}
	if (dif == 1)
	{
		return false;
	}
	return true;		

	}

function valida_Email()
{
  if (document.preco.email.value.indexOf('@', 0) == -1 || 
  document.preco.email.value.indexOf('.', 0) == -1)
  {
    alert("E-mail invalido!");
    document.preco.email.value = '';
    document.preco.email.focus();
    return false 
  }
}


function MM_swapImgRestore() { //v2.0
  if (document.MM_swapImgData != null)
    for (var i=0; i<(document.MM_swapImgData.length-1); i+=2)
      document.MM_swapImgData[i].src = document.MM_swapImgData[i+1];
}
function MM_preloadImages() { //v2.0
  if (document.images) {
    var imgFiles = MM_preloadImages.arguments;
    if (document.preloadArray==null) document.preloadArray = new Array();
    var i = document.preloadArray.length;
    with (document) for (var j=0; j<imgFiles.length; j++) if (imgFiles[j].charAt(0)!="#"){
      preloadArray[i] = new Image;
      preloadArray[i++].src = imgFiles[j];
  } }
}

function MM_swapImage() { //v2.0
  var i,j=0,objStr,obj,swapArray=new Array,oldArray=document.MM_swapImgData;
  for (i=0; i < (MM_swapImage.arguments.length-2); i+=3) {
    objStr = MM_swapImage.arguments[(navigator.appName == 'Netscape')?i:i+1];
    if ((objStr.indexOf('document.layers[')==0 && document.layers==null) ||
        (objStr.indexOf('document.all[')   ==0 && document.all   ==null))
      objStr = 'document'+objStr.substring(objStr.lastIndexOf('.'),objStr.length);
    obj = eval(objStr);
    if (obj != null) {
      swapArray[j++] = obj;
      swapArray[j++] = (oldArray==null || oldArray[j-1]!=obj)?obj.src:oldArray[j];
      obj.src = MM_swapImage.arguments[i+2];
  } }
  document.MM_swapImgData = swapArray; //used for restore
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}
function setfocus(){
		document.forms[0].operacao.focus();}
function preco(){
          Ireg  = document.preco.gare.selectedIndex
          Vreg  = document.preco.gare.options[Ireg].value
          if (Vreg == 'nao') {
		document.preco.valor.disabled = true;}
          if (Vreg == 'sim') {
		document.preco.valor.disabled = false;}
		}
