//*******************************************************
  function VerCPF(cCPF, form)  
//*******************************************************
{
 var cDIG       = ""
 var ZERO       = "000000000000000"
 var cDIG2      = 0
 var cTEMP      = 0
 var soma       = 0 
 var tamanho    = cCPF.length
 var aControle = new Array( 02 )
 var aCPF      = new Array( 11 )
 var aDigito   = new Array( 11 )
 
 if ( tamanho < 11 )
   {
  cTEMP = 11-tamanho
  ZERO  = ZERO.substring(0,cTEMP)  
  cCPF = ZERO + cCPF 
 }
 
 cCPF = cCPF.substring( 0 , 11 )
 
 if ( parseFloat( cCPF ) > 0 ) 
 {
  form.cpf.value = cCPF
 } 
 
 cDIG  = cCPF.substring( 9 , 11 )
 
 if ( cCPF == "" )
 {
   return true
 }
 
 for ( var i=0 ; i<=10 ; i++ ) 
 {
  aCPF[i] = parseFloat(cCPF.substring(i , i+1 ) ) 
    }
 
 // Cálculo do primeiro Digito  - Inicio
 
 
 aDigito[8]= aCPF[8] * 2
 aDigito[7]= aCPF[7] * 3 
 aDigito[6]= aCPF[6] * 4
 aDigito[5]= aCPF[5] * 5
 aDigito[4]= aCPF[4] * 6
 aDigito[3]= aCPF[3] * 7
 aDigito[2]= aCPF[2] * 8
 aDigito[1]= aCPF[1] * 9
 aDigito[0]= aCPF[0] * 10 
 

 
 soma = 0 
 
   for ( var i = 0 ; i < 9 ; i++ ) 
 {
  soma = soma + aDigito[i]
 }
 
 aControle[0] = 11 - ( soma - ( Math.floor( soma/11)*11 ) )  
 
 if ( aControle[0] > 9 )
 {
  aControle[0]= 0
 }
 
 // FIM do cálculo do primeiro Digito
 
   // Cálculo do segundo Digito  - Inicio
  aDigito[9]= aCPF[9] * 2
 aDigito[8]= aCPF[8] * 3
 aDigito[7]= aCPF[7] * 4 
 aDigito[6]= aCPF[6] * 5
 aDigito[5]= aCPF[5] * 6
 aDigito[4]= aCPF[4] * 7
 aDigito[3]= aCPF[3] * 8
 aDigito[2]= aCPF[2] * 9
 aDigito[1]= aCPF[1] * 10
 
 soma = 0
 
 for ( var i = 1 ; i < 10 ; i++ ) 
 {
  soma = soma + aDigito[i]
 }
 
 aControle[1] = 11 - ( soma - ( Math.floor( soma/11)*11 ) )  
 
 if ( aControle[1] > 9 )
 {
  aControle[1]= 0
 }
 
 cDIG2   = ( aControle[0] * 10 ) + aControle[1]  
 
 if( parseFloat( cDIG ) != cDIG2 )
 {
  alert( "Digito de controle do CPF inválido !!!!")
  return false
 }
 
 return true
}

<!--
//window.onload=desmonta;
function montar(id) {
var d = document.getElementById(id);
	if (d) {
	var status = d.style.display;
	if(status == "" || status == "none"){
		for (var i = 1; i<=10; i++) {
			if (document.getElementById('smenu'+i)){
				document.getElementById('smenu'+i).style.display='none';
			}
		}
		d.style.display = 'block';
	} else {
	
		d.style.display = 'none';
	}
	
	}
}
function desmonta() {
		for (var i = 1; i<=10; i++) {
			if (document.getElementById('smenu'+i)){
				document.getElementById('smenu'+i).style.display='none';
			}
		}
}

function alterClass(obj) {

strObjClass = obj.className.substring(5,11);
classOld = obj.className.replace("Active","")

clearClass();

if(strObjClass == 'Active'){
	obj.className = classOld;
} else {
	obj.className = classOld + 'Active';
}

}

function clearClass() {
	divmenu = document.getElementById("menu")
	elemento = divmenu.getElementsByTagName("a")

	for(i=0; i < elemento.length; i++){
		if(elemento[i].className.substring(5,11) == 'Active'){
			elemento[i].className = elemento[i].className.replace("Active","")
		}
		
	}

}


function validaFormLogin(){

	if ( document.forms["loginForm"].elements["cpf"].value == "" ){
		alert( "O campo 'CPF' não pode ficar em branco.");
		document.forms["loginForm"].elements["cpf"].focus();
		return false;
	}


	if (document.forms["loginForm"].elements["senha"].value == ""){
		alert("O campo 'Senha' não pode ficar em branco.");
		document.forms["loginForm"].elements["senha"].focus();
		return false ;
	}

	
	document.forms["loginForm"].submit();
	

}



function verificaFaleConosco(){

	if ( document.forms["formContato"].elements["nome"].value == "" ){
		alert( "O campo 'Nome' não pode ficar em branco.");
		document.forms["formContato"].elements["nome"].focus()
		return false 
	}

	if (document.forms["formContato"].elements["email"].value.length <= 0 || document.forms["formContato"].elements["email"].value.indexOf('@') < 1 || document.forms["formContato"].elements["email"].value.indexOf('.') < 3 ){
		alert("O campo 'E-mail' não pode ficar em branco ou está incorreto.");
		document.forms["formContato"].elements["email"].focus();
		return false ;
	}
	
		if (document.forms["formContato"].elements["msg"].value == ""){
		alert("O campo 'Comentários' não pode ficar em branco.");
		document.forms["formContato"].elements["msg"].focus();
		return false ;
	}
	
else {
	
	document.forms["formContato"].submit();
	
	}

}

function verificaFaleDpto(){

	if(document.forms["formContato"].elements["question"].value == ""){
		alert("O campo 'Pergunta' não pode ficar em branco.");
		document.forms["formContato"].elements["question"].focus();
		return false;
		}
	
}

function verificaFaleDiretoria(){
	if (document.forms["formContato"].elements["msg"].value == ""){
		alert("O campo 'Fale com a diretoria' não pode ficar em branco.");
		document.forms["formContato"].elements["msg"].focus();
		return false ;
		}
	else {
		document.forms["formContato"].submit();
		}
}

function verificaBusca(){

objNome = document.forms["searchMed"].elements["nome"].value;
objBairro = document.forms["searchMed"].elements["bairro"].options[document.forms["searchMed"].elements["bairro"].selectedIndex].value;

x = objNome.length;
y = objBairro.length;
z = x + y;

	if (z <= 0){
		alert( "Para realizar a busca é ncessário informar\no BAIRRO ou o NOME do médico desejado.");
		return false; 
	} else {
	
	document.forms["searchMed"].submit()
		
	}

}

 function verificaPasso1()
//*******************************************************
{
	
	if ( document.form1.nome.value == "" )
   {
	   alert( "O campo 'Nome' não pode ficar em branco.");
		form1.nome.focus()
	   return false 
	}

	if ( document.form1.cpf.value == "" )
   {
	   alert( "O campo 'CPF' não pode ficar em branco.");
		form1.cpf.focus()
	   return false 
	}
    else 
    {
  
	 if (!(VerCPF(form1.cpf.value,form1)))
        return false
    }
	
		if (document.form1.email.value.length <= 0 || document.form1.email.value.indexOf('@') < 1 || document.form1.email.value.indexOf('.') < 3 )
   {
	   alert( "O campo 'E-mail' não pode ficar em branco ou está incorreto.");
	   	form1.email.focus()
	   return false 
	}
	
	if (!document.form1.sexo[0].checked && !document.form1.sexo[1].checked )
   {
	   alert( "O campo 'Sexo' não pode ficar em branco.");
	   return false 
	}
	
	if (document.form1.senha.value == "")
   {
	   alert( "O campo 'Senha' não pode ficar em branco.");
	   	form1.senha.focus()
	   return false 
	}
	
	if (document.form1.confsenha.value == "")
   {
	   alert( "O campo 'Confirme a Senha' não pode ficar em branco.");
	   	form1.confsenha.focus()
	   return false 
	}
	
	if (document.form1.confsenha.value != document.form1.senha.value)
   {
	   alert( "As senhas digitadas não coincidem.\nTente novamente");
		form1.senha.value = '';
		form1.confsenha.value = '';
		form1.senha.focus()
	   return false 
	}

	if (document.form1.servcredsbd_pergunta[0].checked){

	 if (form1.servcredsbd_servico.options[document.form1.servcredsbd_servico.selectedIndex].value == "*"){
	   alert( "É necessário selecionar um serviço credenciado.");
	   form1.servcredsbd_servico.focus();
	   return false 
	   }
	   
	}

	if (document.form1.info_associado_sbd[0].checked){

		/*if ( document.form1.info_numero_associado.value == "" )
	   {
		   alert( "É necessário informar o seu número de associação na SBD.");
			form1.info_numero_associado.focus()
		   return false 
		}*/

		 if (form1.info_categoria.options[document.form1.info_categoria.selectedIndex].value == "*"){
		   alert( "É necessário informar sua categoria.");
		   form1.info_categoria.focus();
		   return false 
		   }
	   
	   	if (form1.regional .options[document.form1.regional .selectedIndex].value == "*"){
		   alert( "É necessário informar sua regional.");
		   form1.regional.focus();
		   return false 
		}
	}
	
		else {
			document.form1.submit();
		}
}


// JavaScript Document
function isNum( caractere ) 
  
{ 
  
var strValidos = "0123456789" 
  
if ( strValidos.indexOf( caractere ) == -1 ) 
  
return false; 
  
return true; 
  
} 
  
function validaTecla(campo, event) 
  
{ 
  
var BACKSPACE= 8; 
  
var key; 
  
var tecla; 
  
CheckTAB=true; 
  
if(navigator.appName.indexOf("Netscape")!= -1) 
  
tecla= event.which; 
  
else 
  
tecla= event.keyCode; 
  
key = String.fromCharCode( tecla); 
  
if ( tecla == 13 ) 
  
return false; 
  
if ( tecla == BACKSPACE ) 
  
return true; 
  
return ( isNum(key)); 
  
} 
//*******************************************************
  function alltrim(cString)
//*******************************************************
{
 cRetorno = ""
 
// Percorre a string e verifica se todos os campos sao numéricos
 
for ( var i=0;i<cString.length;i++ ) 
 {
  if ( cString.substring(i,i+1) != " ")
  {
      cRetorno = cRetorno + cString.substring(i,i+1)
  } 
 }
 
return( cRetorno )
}
 
 
 
// associado
function associado(param){
	
	if(param == "yes"){
		document.form1.info_associado_sbd.value='sim';
		//document.form1.info_numero_associado.disabled=false;
		document.form1.info_categoria.disabled=false;
		document.form1.regional.disabled=false;
	} else {
		document.form1.info_associado_sbd.value='não';
		//document.form1.info_numero_associado.disabled=true;
		//document.form1.info_numero_associado.value='';
		document.form1.info_categoria.disabled=true;
		document.form1.info_categoria.value='*';
		document.form1.regional.disabled=true;
		document.form1.regional.value='*';
	}
}

// especialidade
function especial(param){

	if(param == "yes"){
		document.form1.servcredsbd_pergunta.value='sim';
		document.form1.servcredsbd_servico.disabled=false;
	} else {
		document.form1.servcredsbd_pergunta.value='não';
		document.form1.servcredsbd_servico.disabled=true;
		document.form1.servcredsbd_servico.value='*';
	}

}


function mascara_cpf(obj,tecla){
	nomeObj = obj.name;
	valor = tecla.srcElement.value;
	tam = valor.length;

//Testa se não foram digitados números
	if (tecla.keyCode < '48' || tecla.keyCode > '58'){
		alert('Por favor,\ndigite apenas números!');
		tecla.keyCode = '127';
		obj.focus();
	} 
}
function mascara_dn(obj,tecla){
	nomeObj = obj.name;
	valor = tecla.srcElement.value;
	tam = valor.length;

	//Testa se não foram digitados números
	if (tecla.keyCode < '48' || tecla.keyCode > '58'){
		alert('Por favor,\ndigite apenas números!');
		tecla.keyCode = '127';
		obj.focus();
	}else{
		if(tam==2){
			tecla.srcElement.value = valor.substr(0,tam) + '/';
		}//fim if
		if(tam==5){
			tecla.srcElement.value = valor.substr(0,tam) + '/';
		}//fim if
	}//fim if
}

//-->
function postURL(obj, page){
	x = obj;
	catId = x.options[x.selectedIndex].value;
	url = page + ".asp?catId=" + catId;
	location.href = url;
}



// CATEGORIAS BOX


function closeLay(lyr){
	getObj = document.getElementById('testlayer');
	x = getObj;
	x.style.display= "none";
	return false;
}

function setLyr(obj, idobj, cat){

	eleHeight = document.getElementById(idobj).offsetHeight;
	eleWidth = document.getElementById(idobj).offsetWidth;
	writit(cat);
	
	getObj = document.getElementById('testlayer');
	
	var newX = (findPosX(obj) + eleWidth) - eleWidth - 5;
	var newY = (findPosY(obj) + eleHeight)+5;
	
	x = getObj;
	x.style.display= "block";
	x.style.top = newY + 'px';
	x.style.left = newX + 'px';
}

function findPosX(obj){ 
	var curleft = 0;
	if (obj.offsetParent)
	{
	
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
			
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj){
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


function writit(categoria){

text = "<div class='textobox' style='font:10px; width:250px; border:1px solid #00678F; padding:3px;'>";

if (categoria == "EFETIVO"){
text += "<b>Associados Efetivos: </b>são os associados que possuem o Título de Especialista da SBD.";
}

if (categoria == "ASPIRANTE"){
text += "<b>Associados Aspirantes: </b>são os associados que não possuem o Título de Especialista da SBD, com menos de 5 anos de filiação à Sociedade.";
}
if (categoria == "CONTRIBUINTE"){
text += "<b>Associados Contribuintes: </b>são os associados que não possuem o Título de Especialista da SBD, com mais de 5 anos de filiação à Sociedade.";
}

text += "</div>";

	if (document.getElementById)
	{
		x = document.getElementById('testlayer');
		x.innerHTML = '';
		x.innerHTML = text;
	}
	else if (document.all)
	{
		x = document.all['testlayer'];
		x.innerHTML = text;
	}
	else if (document.layers)
	{
		x = document.layers['testlayer'];
		x.document.open();
		x.document.write(text);
		x.document.close();
	}
}

// FIM CATEGORIA BOX

function verificaCadEndereco(){

if (document.forms["form1"].elements["endcom_logradouro"].value == ""){
		alert("O campo 'Endereço' não pode ficar em branco.");
		document.forms["form1"].elements["endcom_logradouro"].focus();
		return false ;
}

if (document.form1.endcom_bairro.options[document.form1.endcom_bairro.selectedIndex].value == ""){
		alert("O campo 'Bairro' não pode ficar em branco.");
		document.forms["form1"].elements["endcom_bairro"].focus();
		return false ;
}		
		
if (document.forms["form1"].elements["telefone"].value == ""){
		alert("O campo 'Telefone' não pode ficar em branco.");
		document.forms["form1"].elements["telefone"].focus();
		return false ;
}	

if (document.forms["form1"].elements["endcom_cep"].value == ""){
		alert("O campo 'CEP' não pode ficar em branco.");
		document.forms["form1"].elements["endcom_cep"].focus();
		return false ;
}	

else {
		document.form1.submit();
		}
}

// script link acrobat

function closeLayPDF(lyr){

	getObj = document.getElementById('lerPDF');

	x = getObj;

	x.style.display= "none";

	return false;

}


function setLyrPDF(obj, idobj, lk){


if(lk == "lk"){
	eleHeight = document.getElementById(idobj).offsetHeight;
	eleWidth = document.getElementById(idobj).offsetWidth;
	writitPDF();
	getObj = document.getElementById('lerPDF');
	var newX = (findPosX(obj) + eleWidth) - eleWidth;
	var newY = (findPosY(obj) + eleHeight)+5;
	x = getObj;
	x.style.display= "block";
	x.style.top = newY + 'px';
	x.style.left = newX + 'px';
} else {
	getObj = document.getElementById('lerPDF');
	x = getObj;
	x.style.display= "block";
}
	
}


function writitPDF(categoria){



text = "<div class='textobox' style='font:10px; width:300px; border:1px solid #00678F; padding:3px;'>";

text += "Para ler o jornal em pdf, é necessário ter instalado o programa Acrobat Reader no seu computador. Se você ainda não tem este programa instalado, <a href='http://www.adobe.com/br/products/acrobat/readstep2.html' target='_blank'><strong>clique aqui</strong></a>, faça o download e instale-o.  O programa é gratuito.";

text += "</div>";

	if (document.getElementById)

	{
		x = document.getElementById('lerPDF');
		x.innerHTML = '';
		x.innerHTML = text;
	}

	else if (document.all)

	{
		x = document.all['lerPDF'];
		x.innerHTML = text;
	}

	else if (document.layers)

	{
		x = document.layers['lerPDF'];
		x.document.open();
		x.document.write(text);
		x.document.close();
	}

}


function trimString(inputString)
			{
				var i, bFound;
		
				if (inputString == null)
					inputString = "";
				else
				{
					bFound = false;
					for (i = 0; i <= inputString.length - 1; i++)
					{
						if (inputString.charAt(i) != " ")
						{
							bFound = true;
							break;
						}
					}
		
					if (!bFound)
						inputString = "";
					else
					{
						inputString = inputString.substr(i, inputString.length - i);
						bFound = false;
						for (i = inputString.length - 1; 0 <= i; i--)
						{
							if (inputString.charAt(i) != " ")
							{
								bFound = true;
								break;
							}
						}
		
						if (!bFound)
							inputString = "";
						else
							inputString = inputString.substr(0, i + 1);
					}
				}
				return inputString;
			}

// end script