<!--
	// --------------------------------------------------------------------------
	// << whatbrowser >>
	// --------------------------------------------------------------------------
	function whatbrowser() {
      if(document.layers)
         return "NN4";
      else
         if(document.all)
            return "ie";
         else
            if(!document.all && document.getElementById)
               return "NN6";
            else
               return "";
	}

	// --------------------------------------------------------------------------
	// << get_obj >>
	// --------------------------------------------------------------------------
	function get_obj(objid, style, strfrm) {

      mybrowser = whatbrowser();

      if (!(strfrm=="")) strfrm = strfrm + ".";

      if (mybrowser=="NN4") {
         return eval(strfrm + "document." + objid);
      }
      else
         if (mybrowser=="NN6")
            if (style==true)
               return eval(strfrm + "document.getElementById(objid).style");
            else
               return eval(strfrm + "document.getElementById(objid)");
         else
            if (style==true)
               return eval(strfrm + "document.all." + objid + ".style");
            else
               return eval(strfrm + "document.all." + objid);
	}

	// --------------------------------------------------------------------------
	// << ExtractFieldValueStyle >>
	// --------------------------------------------------------------------------
	function ExtractFieldValueStyle(style, fieldname) {
		fieldname+= ": ";
		index = style.indexOf(fieldname);
		if (index>=0) {
			index+= fieldname.length;
			style = style.substring(index, style.length);
			
			index = style.indexOf(";");
			if (index==-1) index = style.length;
			return style.substring(0, index);
		} 
		else
			return "";
	}

	// --------------------------------------------------------------------------
	// << AjustaCorRegistro >>
	// --------------------------------------------------------------------------
	function AjustaCorRegistro(qtdecol, reg, bcg) {				
//		alert(qtdecol);
		for(col=1; col<=qtdecol; col++) {
			var objname = "col" + reg + col;
			document.getElementById(objname).style.background = bcg;
		}
	}

//----------------------------------------------------------------------------

		function isValidDate (myDate,sep) 
		{
			if (myDate.length == 10) 
			{
				if (myDate.substring(2,3) == sep && myDate.substring(5,6) == sep)
				{
					dia = myDate.substring(0,2) ;
					ano = parseInt( myDate.substring(6,10));

					mes = parseInt( myDate.substring(3,5) );
					if ( myDate.substring(3,4) == '0' )
					{ mes = parseInt( myDate.substring(4,5) ); }

					var test = new Date(ano,mes-1,dia,0,0,0);

					adia = parseInt(test.getDate());
					ames = parseInt(test.getMonth());
					aano = parseInt(test.getYear());

					if ( aano < 1900 ) aano = aano + 1900;

					if ( aano.length == 2 ) { aano = aano + 1900; }

//					alert( "Ano : "+aano+"/"+ano+" Mes : "+ames+"/"+mes+" Dia : "+adia+"/"+dia+" - 03" );

					if ( (aano == ano ) && (ames == mes-1 ) && ( dia == adia ) ) {
						return 1;
					}
					else 
					{ return 0; }
				}
				else 
				{ return 0; }
			}
			else 
			{ return 0; }
		}

//----------------------------------------------------------------------------

	function checadata( form , campo ) {
		data = "document."+form+"."+campo+".value";
		campo = "document."+form+"."+campo+".focus()";
		data = eval(data);
		//alert("Data : "+data);
		if ( data != "" ) {
			data = isValidDate(data,"/");
			if ( data == 0 ) {
				alert("A data informada é inválida !!! ");
				eval(campo);
				return ;
			}
		}
		return true;
	}

//-------------------------------------------------------------------------------
//
//		funções para adicionar e remover inputs
//

a = 0;

function remover( bl ) {
	a = document.getElementById('cirurgialista')
	b = document.getElementById('spammers['+bl+']')
	a.removeChild(b);
}

function remover2( quadro , bl ) {
	a = document.getElementById(quadro)
	b = document.getElementById('spammers['+bl+']')
	a.removeChild(b);
}

function adicionar( paramform , xform ) { 

	a++;

	x = document.createElement('span');
  	x.setAttribute('id', 'spammers[' + a + ']');

	if ( paramform == 1 ) { 

		if ( (xform.dt_cirur.value == "")  ) { // || (xform.cirur_equipe.value=="") || (xform.cirur_tipo.value=="") ) { 
			alert("Favor preencher todos os campos para adicionar uma cirurgia !");
			xform.dt_cirur.focus();
			return ;
		} 

		bloco  = "<table border=0 cellspacing=1 cellpadding=1>";
		bloco += "	<tr>";
		bloco += "		<td><input type='text' class='edit' onBlur='checadata('form','dt_cirur["+a+"]') name='dt_cirur["+a+"]' value='"+xform.dt_cirur.value+"' size='10' maxlength=10></td>";
		bloco += "		<td><input type='text' class='edit' name='cirur_tipo["+a+"]' value='"+xform.cirur_tipo.value+"' size='20' maxlength=20></td>";
		bloco += "		<td><input type='text' class='edit' name='cirur_equipe["+a+"]' value='"+xform.cirur_equipe.value+"' maxlength=45 size='45'></td>";
		bloco += "	  <td><a href='javascript:remover("+a+")'><img src='themes/default/img/botao_excluir.gif' border='0' alt='Excluir esta cirurgia'></a><td>";
		bloco += "	</tr>";
		bloco += "</table>";

		xform.dt_cirur.value = "";
		xform.cirur_equipe.value = "";
		xform.cirur_tipo.value = "";

		x.innerHTML = bloco;
	  	document.getElementById("cirurgialista").appendChild(x);
		xform.dt_cirur.focus();
	} else if ( paramform == 2 ) {
		//
		//	Diagnósticos ( primeiro formulário usuário )
		//

		bloco  = "<table border=0 cellspacing=0 cellpadding=1>\n";
		bloco += "	<tr>\n";
		bloco += "		<td width=69><input type='text' name='diagdatas["+a+"]' readonly size=10 maxlength=10 class='edit' value='"+info[2]+"'></td>\n";
		bloco += "		<td width=320><input type='text' name='diagdescrs["+a+"]' readonly size=59 class='edit' value='"+info[1]+"'></td>\n";
		bloco += "		<input type='hidden' name='diagids["+a+"]' value="+info[0]+"></td>\n";
		bloco += "		<td width=16><a href='javascript:remover2(\"diagdetail\","+a+")'><img src='themes/default/img/botao_excluir.gif' border=0></a></td>\n";
		bloco += "	</tr>\n";
		bloco += "</table>\n";

		xform.diagdata.value = "";

		x.innerHTML = bloco;
  		document.getElementById('diagdetail').appendChild(x);

	} else if ( paramform == 3 ) {
		//
		//	Diagnósticos ( primeiro formulário usuário )
		//
		bloco  = "<table border=0 bordercolor=red cellspacing=1 cellpadding=1 width=609 align='center'>\n";
		bloco += "	<tr>\n";
		bloco += "		<td width=108 class='sbquadro' align='center'>"+xform.histdata.value+"</td>\n";
		bloco += "		<td width=160 class='sbquadro' align='center'>"+periodicidade[ xform.compperiod.value ]+"</td>\n";
		bloco += "		<td width=160 class='sbquadro' align='center'>"+xform.histrenda.value+"</td>\n";
		bloco += "		<td width=160 class='sbquadro' align='center'>"+ vestadocivil[ xform.histec.value ] +"</td>\n";

		bloco += "			<input type='hidden' name='compdatas["+a+"]'	value='"+xform.histdata.value+"'> ";
		bloco += "			<input type='hidden' name='compperiod["+a+"]'	value='"+xform.compperiod.value+"'> ";
		bloco += "			<input type='hidden' name='comprenda["+a+"]'	value='"+xform.histrenda.value+"'> ";
		bloco += "			<input type='hidden' name='compestado["+a+"]'	value='"+xform.histec.value+"'> ";

		bloco += "		<td width=11><a href='javascript:remover2(\"compdetail\","+a+")'><img src='themes/default/img/botao_excluir.gif' border=0></a></td>\n";
		bloco += "	</tr>\n";
		bloco += "</table>\n";
		bloco += "";

		xform.histdata.value = "";
		xform.histrenda.value = "0.00";

		x.innerHTML = bloco;
  		document.getElementById('compdetail').appendChild(x);

	}else if ( paramform == 4 ) {
		//
		//	Diagnósticos ( primeiro formulário usuário )
		//
		est="";
		switch (xform.histec.value){
			case "1":
				est="CASADO(A)";
				break;
			case "2":
				est="SOLTEIRO(A)";
				break;
			case "3":
				est="UNIÃO ESTÁVEL";
				break;
			case "4":
				est="CASADO(A)";
				break;
			case "5":
				est="DESQUITADO(A)";
				break;
			case "6":
				est="DIVORCIADO(A)";
				break;
			case "7":
				est="VIÚVO";
				break;
			case "8":
				est="SEPARADO(A)";
				break;
			case "9":
				est="NÃO DEFINIDO";
				break;
			default:
				est="NÃO DEFINIDO";
		}

		bloco  = "<table border=0 cellspacing=0 cellpadding=1>\n";
		bloco += "	<tr>\n";
		bloco += "		<td width=124><input type='text' name='compdatas["+a+"]' readonly size=42 maxlength=10 class='edit' value='"+xform.compparente.value+"'></td>\n";
		bloco += "		<td width=50><input type='text' name='compperiod["+a+"]' readonly size=21 class='edit' value='"+xform.compperiod.value+"'></td>\n";
		bloco += "		<td width=60><input type='text' name='comprenda["+a+"]'	readonly size=20 class='edit' value='"+xform.histrenda.value+"'></td>\n";
		bloco += "		<td width=80><input type='text' name='compestado["+a+"]'	readonly size=17 class='edit' value='"+est+"'></td>\n";		
		bloco += "		<td width=200><input type='hidden' name='compestado2["+a+"]'	readonly size=59 class='edit' value='"+xform.histec.value+"'></td>\n";

		bloco += "		<td width=16><a href='javascript:remover2(\"compdetail\","+a+")'><img src='themes/default/img/botao_excluir.gif' border=0></a></td>\n";
		bloco += "	</tr>\n";
		bloco += "</table>\n";

		xform.compperiod.value = "";

		x.innerHTML = bloco;
  		document.getElementById('compdetail').appendChild(x);

	} else if ( paramform == 5 ) { 

		bloco  = "<table border=0 cellspacing=1 cellpadding=1>\n";
		bloco += "	<tr>\n";
		bloco += "		<td width=300 class='sbquadro'>"+ xform[1] +"</td>\n";
		bloco += "		<td width=70 class='sbquadro' align='center'>"+ xform[3] +"</td>\n";
		bloco += "		<td width=70 class='sbquadro' align='right'>"+ xform[4] +"</td>\n";
		bloco += "		<td width=100 class='sbquadro' align='center'>"+ xform[6] +"</td>\n";
		bloco += "		<td width=16><a href='javascript:remover2(\"compdetail\","+a+")'><img src='themes/default/img/botao_excluir.gif' border=0></a></td>\n";
		bloco += "	</tr>\n";
		bloco += "</table>\n";
		bloco += "<input type='hidden' name='parentid["+a+"]' value="+xform[0]+">";
		bloco += "<input type='hidden' name='parentperiodo["+a+"]' value="+xform[2]+">";
		bloco += "<input type='hidden' name='parentrenda["+a+"]' value="+xform[4]+">";
		bloco += "<input type='hidden' name='parentestciv["+a+"]' value="+xform[5]+">";

		x.innerHTML = bloco;
  		document.getElementById('compdetail').appendChild(x);
	} else { 
  		document.getElementById('cirurgias').appendChild(x);
	}

  }

//-----------------------------------------------------------------------------------------------------------
//
//	Calcula a idade e os meses
//
function meses( data1 ) {

	var data = new Date();
	mes = parseInt(data.getMonth());
	ano = parseInt(data.getYear());

	dano = parseInt(data1.substring(6));
	dmes = ( 0 + data1.substring(3,5) ) - 1;

	idade = ano - dano;
	mes   = mes - dmes;

	if ( mes < 0 ) {
		idade = idade - 1;
		mes   = 12 - ( 0 - mes );
	}

	if ( mes > 0 )
	{ return idade+" ano(s) e "+mes+" mês(es)"; }

	return idade+" ano(s)";
}
//-----------------------------------------------------------------------------------------------------------
//
//	Formatação de Data
//
	function inputdata( info , field, event ){
		eeval = "";
		if ( event.keyCode == 8 ){
			if ( info.value.length == 2 ){
				eeval = field+".value = '"+info.value.substring(0,1)+"'";
			}
			else if ( info.value.length == 5 ){
				eeval = field+".value = '"+info.value.substring(0,4)+"'"; 
			}
		}
		else{
			var ajustar = (info.value.length == 2) || (info.value.length == 5);
			if (ajustar){
				//eeval = field+".value = '"+info.value + "/'";
				if (typeof(field) == "string"){ 
					eeval = field+".value = '"+info.value + "/'";
				}
				else{
					field.value = info.value + "/";
				}
			}
		}
		if ( eeval != "" ){
			eval(eeval); 
		}
	}

//-----------------------------------------------------------------------------------------------------------
//
//	Formatação de Data
//
	function inputcpf( info , field ){
			eeval = "";
			if ( window.event.keyCode == 8 ){
				if ( info.value.length == 3 ){
					eeval = field+".value = '"+info.value.substring(0,1)+"'";
				}
				else if ( info.value.length == 7 ){
					eeval = field+".value = '"+info.value.substring(0,4)+"'"; 
				}
				else if ( info.value.length == 11 ){
					eeval = field+".value = '"+info.value.substring(0,4)+"'"; 
				}
			}
			else{
				if ( info.value.length == 3 ){
					eeval = field+".value = '"+info.value + ".'";
				}
				else if ( info.value.length == 7 ){
					eeval = field+".value = '"+info.value + ".'"; 
				}
				else if ( info.value.length == 11 ){
					eeval = field+".value  = '"+info.value + "-'"; 
				}
			}
			if ( eeval != "" ){
				eval(eeval);
			}
		}


//-----------------------------------------------------------------------------------------------------------

	function daysElapsed(date1,date2){
		var difference = Date.UTC(y2k(date1.getYear()),date1.getMonth(),date1.getDate(),0,0,0)
		  - Date.UTC(y2k(date2.getYear()),date2.getMonth(),date2.getDate(),0,0,0);
		return difference/1000/60/60/24;
	}

	function y2k(number) { return (number < 1000) ? number + 1900 : number; }


//-----------------------------------------------------------------------------------------------------------


		function exibe_oculta_div(divnome,altura,nome2){
			var objdiv = get_obj(divnome, true, "");
			if ( nome2 != "" )
			{ janela2 = get_obj(nome2, true, ""); }

			if (objdiv.visibility=="visible") 
			{
				objdiv.visibility = "hidden"; 
				objdiv.height = 1;
				if ( nome2 != "" ) {
				janela2.visibility = "hidden"; 
				janela2.height = 1; }
			}
			else 
			{
				objdiv.visibility = "visible";
				objdiv.height = altura;
				if ( nome2 != "" ) {
				janela2.visibility = "visible";
				janela2.height = altura; }
			}
/*
				  if (status.style.visibility == 'hidden')
					 {
					  status.style.visibility = 'visible';
						 if (status != "[object]")
						 status.style.height = '110px'; //prevendo metodo do firefox.
						else
						 status.style.height = '135px'; //ie precisa de mais espaços.
					}
					else
					{
					 status.style.height = '0px';
					 status.style.visibility = 'hidden';
					}
*/
		}
		function get_obj(objid, style, strfrm){

		  mybrowser = whatbrowser();
		 
		  if (!(strfrm=="")) strfrm = strfrm + ".";

		  if (mybrowser=="NN4") {
			 return eval(strfrm + "document." + objid);
		  }
		  else
			 if (mybrowser=="NN6")
				if (style==true)
				   return eval(strfrm + "document.getElementById(objid).style");
				else
				   return eval(strfrm + "document.getElementById(objid)");
			 else
				if (style==true)
				   return eval(strfrm + "document.all." + objid + ".style");
				else
				   return eval(strfrm + "document.all." + objid);
		}

		function whatbrowser(){
		  if(document.layers)
			 return "NN4";
		  else
			 if(document.all)
				return "ie";
			 else
				if(!document.all && document.getElementById)
				   return "NN6";
				else
				   return "";
		}

//----------------------------------------------------------------------------
function inputnumber(info, mascara, event) {

	pontoinfo	= info.value;
	preinfo		= pontoinfo.indexOf(".");

	pontomascara= mascara.indexOf('.');

	tamantesponto = mascara.substr(0,pontomascara);
	tamantesponto = tamantesponto.length;

	posinfo = pontoinfo.substr(preinfo+1);
	posinfo = posinfo.length;

	tamdepoisponto = mascara.substr(pontomascara+1);
	tamdepoisponto = tamdepoisponto.length;

	if (document.all) // Internet Explorer
		var tecla = event.keyCode;
	else
		if (document.layers) // Nestcape
			var tecla = e.which;

	if ((pontomascara == -1) && (tecla == 46)) {
		//event.keyCode = 0;
		return true ;
	}

	if ((tecla > 47 && tecla < 58) || (tecla == 46)) { // numeros de 0 a 9
		if ((preinfo == -1) && (tamantesponto > 0) && (pontoinfo.length >= tamantesponto) && (tecla != 46)) {
			event.keyCode = 0;
		} else {
			if ((pontomascara > 0) && (tecla == 46)) {
				//
				//	Existe ponto na máscara
				//
				if (preinfo > 0) {
					return true ;
					//event.keyCode = 0;
				}
			} // mascara com ponto
			if ((pontomascara > 0) && (tecla != 46) && (posinfo > 0) && (preinfo != -1) && (posinfo >= tamdepoisponto)) {
				return true;
				//event.keyCode = 0;
			}
			return false ;
		}
	} else {
		if (tecla != 8) // backspace
			return false ;
			//event.keyCode = 0;
		else
			return true;
	}
	return true;
}
//----------------------------------------------------------------------------

function inputdata(info, field, event) {
	var eeval = "";
	if (event.keyCode == 8) {
		if (info.value.length == 2) {
			eeval = field+".value = '"+info.value.substring(0,1)+"'";
		} else {
			if (info.value.length == 5) {
				eeval = field+".value = '"+info.value.substring(0,4)+"'";
			}
		}
	} else {
		if (info.value.length == 2) {
			eeval = field+".value = '"+info.value + "/'";
		} else {
			if (info.value.length == 5) {
				eeval = field+".value = '"+info.value + "/'";
			}
		}
	}

	if (eeval != "") {
		eval(eeval);
	}
}
//---------------------------------------------------------------------------------
		function split(string,delimitador){
			vetor = new Array();
			atual = "";
			sequencia = 0;
			for(i=0;i<string.length;++i){
				if ( string.substr(i,1) == delimitador )
				{ vetor[sequencia] = atual;
				  atual = "";
				  ++sequencia; } 
				 else { atual += string.substr(i,1); }
			}
			if ( atual != "" ) { vetor[sequencia] = atual }
			return vetor;
		}

function validaemail(email) {
	var er = /[A-Za-z0-9_.-]+@([A-Za-z0-9_]+\.)+[A-Za-z]{2,4}/;
	return er.test(email);
}

//----------------------------------------------------------------------------

function checa_cgc(vcgc) {

	if (vcgc.length < 14) {
		alert("Número do CGC inválido !") ;
		return (0)
	}

	var d = new Array(12);
	var i = 0;
	var df2 = 0;
	var df3 = 0;
	var resto1 = 0;
	var resto2 = 0;
	var temp = 0;
	for (i=0; i < 12; i++) {
		temp = vcgc.substr(i,1) ;
		temp = parseInt(temp, 10) ;
		d[i] = temp ;
	}

	df1 = 5 * d [0];
	df1 += 4 * d [1];
	df1 += 3 * d [2];
	df1 += 2 * d [3];
	df1 += 9 * d [4];
	df1 += 8 * d [5];
	df1 += 7 * d [6];
	df1 += 6 * d [7];
	df1 += 5 * d [8];
	df1 += 4 * d [9];
	df1 += 3 * d [10];
	df1 += 2 * d [11];

	df2 = df1 / 11 ;
	df2 = inteiro(df2) ;
	df3 = df2 * 11 ;
	resto1 = df1 - df3 ;

	if (resto1 == 1 || resto1 == 0)
		pridig = 0 ;
	else
		pridig = 11 - resto1;

	df1 = 6 * d [0];
	df1 += 5 * d [1];
	df1 += 4 * d [2];
	df1 += 3 * d [3];
	df1 += 2 * d [4];
	df1 += 9 * d [5];
	df1 += 8 * d [6];
	df1 += 7 * d [7];
	df1 += 6 * d [8];
	df1 += 5 * d [9];
	df1 += 4 * d [10];
	df1 += 3 * d [11];
	df1 += 2 * pridig ;

	df2 = df1 / 11 ;
	df2 = inteiro(df2) ;
	df3 = df2 * 11 ;
	resto2 = df1 - df3 ;

	if (resto2 == 0 || resto2 == 1)
		segdig = 0 ;
	else
		segdig = 11 - resto2 ;

	resto1 = parseInt(vcgc.substr(12,1));
	resto2 = parseInt(vcgc.substr(13,1));

	if (pridig == resto1 && segdig == resto2) {
		return true ;
	} else {
		alert("O número do CNPJ informado é inválido") ;
		return false ;
	}

}
//----------------------------------------------------------------------------

function inteiro(wValor) {
	wResult = "" ;
	wString = ""+wValor ;
	for (wfor = 0 ; wfor < wString.length ; ++wfor) {
		if (wString.substr(wfor,1) == ".")
			wfor = wString.length + 1;
		else
			wResult += wString.substr(wfor,1);
	}
	return parseInt(wResult, 10);
}

//----------------------------------------------------------------------------

function checa_cpf(vcpf) {

	if (vcpf.length < 10) {
		alert("Número do CPF inválido !");
		return (0)
	}

	var wSx1 = 0 ;
	var wCpfDigit = 0 ;
	var y = 0 ;
	var temp = 0 ;
	var temp2= 0 ;

	var wCpfCalc = vcpf.substr(0,9) ;
	var wSomaCpf = 0 ;

	for (wsx1 = 1; wsx1 < 10; wsx1++) {
		temp = vcpf.substr(wsx1-1,1);
		temp = parseInt(temp, 10) ;
		temp = temp * (11 - wsx1) ;
		wSomaCpf += temp ;
	}

	temp = wSomaCpf%11 ;
	wCpfDigit = 11 - temp ;

	if (wCpfDigit == 10 || wCpfDigit == 11)
		wCpfCalc += "0" ;
	else
		wCpfCalc += wCpfDigit ;

	wSomaCpf = 0 ;
	for (wsx1=1; wsx1 < 11; wsx1++) {
		temp = vcpf.substr(wsx1-1,1);
		temp = parseInt(temp, 10) ;
		temp = temp * (12-wsx1) ;
		wSomaCpf += temp ;
	}

	temp = wSomaCpf%11 ;
	wCpfDigit = 11 - temp ;

	if (wCpfDigit == 10 || wCpfDigit == 11)
		wCpfCalc += "0" ;
	else
		wCpfCalc += wCpfDigit ;

	if (vcpf != wCpfCalc) {
		alert("O número do cpf informado é inválido !");
		return false ;
	} else {
		return true;
	}
}

//----------------------------------------------------------------------------

//-->

