function ById(id){return document.getElementById(id);}
function getBrowser(){if(window.XMLHttpRequest){return "mozilla";}else if(window.ActiveXObject){return "ie";}}
function doXMLRequester()
{
	if(getBrowser() == "ie")
	{
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if(getBrowser() == "mozilla")
	{
		return new XMLHttpRequest();
	}
}

//Função Para Replace!
function replaceAll( str, from, to ) {
    var idx = str.indexOf( from );

    while ( idx > -1 ) {
        str = str.replace( from, to ); 
        idx = str.indexOf( from );
    }

    return str;
}


/* ====================================================== */
//Contador de caracteres nos campos de inserção de novo anuncio
function textCounter(field,cntfield,maxlimit) {
if (field.value.length > maxlimit)
field.value = field.value.substring(0, maxlimit);
else
cntfield.value = "  "+(maxlimit - field.value.length);
}
/* ====================================================== */


/* ====================================================== */
var cell
var colorCell

// funções pera hover das ceculas
function CellOver(cell,colorCell){
eval("document.all."+cell+".bgColor='"+colorCell+"';");
}
function CellOut(cell,colorCell){
eval("document.all."+cell+".bgColor='"+colorCell+"';");
}
/* ====================================================== */


/* ====================================================== */
var Layer
// funções pera exibição dos submenus
function showLayer(Layer){
eval("document.all."+Layer+".style.visibility='visible'")
}
function hideLayer(Layer){
eval("document.all."+Layer+".style.visibility='hidden'")
}
/* ====================================================== */

/* ====================================================== */
function deleteAnuncio(num){
if(confirm('Você tem certeza que deseja excluir este anúncio?')){
	eval("window.location.href='meus.anuncios.asp?deletar=ok&idAnuncio="+num+"';");
	}
else{
	return false;
	}
}
/* ====================================================== */
//Checa se uma data é válida

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2078;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strDay=dtStr.substring(0,pos1)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("O formato da data terá de ser: dd/mm/aaaa")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Entre com um mês válido!")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Entre com um dia válido!")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Entre com um ano de quatro dígitos válido entre  "+minYear+" e "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Entre com uma data válida!");
		return false
	}
return true
}


function isDateNoaValida(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strDay=dtStr.substring(0,pos1)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		return false
	}
return true
}



/*
Função para validação de CPF
*/
function isCPF(st) {
if (st == "")
return (false);
l = st.length;

//aleterado para se usuário não digitar os zeros na frente do CPF, completar sozinho
if ((l == 9) || (l == 8))
{
for (i = l ; i < 10; i++)
{
st = '0' + st
}
}
l = st.length;
st2 = "";
for (i = 0; i < l; i++) {
caracter = st.substring(i,i+1);
if ((caracter >= '0') && (caracter <= '9'));
st2 = st2 + caracter;
}
if ((st2.length > 11) || (st2.length < 10))
return (false);
if (st2.length==10)
st2 = '0' + st2;
digito1 = st2.substring(9,10);
digito2 = st2.substring(10,11);
digito1 = parseInt(digito1,10);
digito2 = parseInt(digito2,10);
sum = 0; mul = 10;
for (i = 0; i < 9 ; i++) {
digit = st2.substring(i,i+1);
tproduct = parseInt(digit ,10) * mul;
sum += tproduct;
mul--;
}
dig1 = ( sum % 11 );
if ( dig1==0 || dig1==1 )
dig1=0;
else
dig1 = 11 - dig1;
if (dig1!=digito1)
return (false);
sum = 0;
mul = 11;
for (i = 0; i < 10 ; i++) {
digit = st2.substring(i,i+1);
tproduct = parseInt(digit ,10)*mul;
sum += tproduct;
mul--;
}
dig2 = (sum % 11);
if ( dig2==0 || dig2==1 )
dig2=0;
else
dig2 = 11 - dig2;
if (dig2 != digito2)
return (false);
return (true);
}
/*
Fim da Função para validação do CPF
*/



function possuiCam(){
var POSSUI_CAM = "<TABLE cellSpacing=0  class=fonte_padrao cellPadding=0 width=100% border=0><TR><TD vAlign=top width=0%>&nbsp;</TD><TD class=conteudo_fonte_padrao width=100%>Digital <INPUT type=radio value=digital name=possui> &nbsp;&nbsp;Analógica <INPUT type=radio value=analogica name=possui><TABLE cellSpacing=0 class=fonte_padrao cellPadding=3 width=100% border=0><TR><TD class=conteudo_fonte_padrao width=25%>Marca<BR><INPUT class=box id=marca style=WIDTH:95% name=marca></TD><TD class=conteudo_fonte_padrao width=25%>Modelo <BR><INPUT class=box id=modelo style=WIDTH:95% name=modelo></TD><TD class=conteudo_fonte_padrao width=25%>Zoom<BR><INPUT id=zoom type=checkbox value=1 name=zoom></TD><TD class=conteudo_fonte_padrao width=25%><BR></TD></TR></TBODY></table></TD></TR><TR><TD>&nbsp;</TD><TD class=conteudo_fonte_padrao><INPUT type=checkbox value=1 name=trocar> Pretende trocar sua câmara por uma mais moderna nos próximos seis meses.</TD></TR></TBODY></table>";

if (document.all.possuicam.checked){
document.all.conteudo.innerHTML=POSSUI_CAM;
}
else{
document.all.conteudo.innerHTML='&nbsp;';
}
}

function loadUpload(){
document.all.enviar.value='Aguarde o envio da foto...';
}


/*
Função para validação de e-mail
*/
function eh_email(mail){
var ret = false;
if (typeof(mail) != "undefined"){
mail = mail.match(/(\w+)@(.+)\.(\w+)$/);
if (mail != null){
if ((mail[3].length==2) || (mail[3].length==3))
ret = true;
}
}
return ret;
}
/*
Fim da função de validação de e-mail
*/



/*
Função para verificar o prenchimento dos campos de autenticação
*/
function validaDados(form){
var email = document.all.email.value;
var senha = document.all.senha.value;

if(email == ""){
alert("Digite seu e-mail!")
document.all.email.focus();
}
else if(!eh_email(email)){
alert("E-mail inválido ("+email+")!")
document.all.email.focus();
}
else if(senha == ""){
alert("Digite a senha!")
document.all.senha.focus();
}
else{
eval("document."+form+".submit();");
}
}
/*
================================================
*/


/*
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Função para validação de preenchimento dos campos do formulário de cadastro
*/
function enviar(){

var CADASTRO_NOME = document.all.pnome.value;
var CADASTRO_EMAIL = document.all.email.value;

if (CADASTRO_NOME == ""){
alert("Campo Requerido (Nome)!")
document.all.pnome.focus();
}
else if(CADASTRO_EMAIL == ""){
alert("Campo Requerido (E-mail)!")
document.all.email.focus();
}
else if(!eh_email(CADASTRO_EMAIL)){
alert("E-mail inválido!")
document.all.email.focus();
}
else{
//alert("Tudo Ok!")
document.sisadmin_cadastro.submit();
}
}
/*
Fim da função de validação de preenchimento dos campos do formulário de cadastro
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/


//<--
function neoConfirm(){
if(confirm('As informações associadas as imagens (quantidade, tamanho, papel, cor e etc.) serão perdidas!')){
window.location.href='impressao.asp?pasta=10&pagina=24';
}
else{
return false;
}
}
//-->

//<--
function janelaMaster(){
var vpos;
vpos=window.open('','vpos','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=no,copyhistory=no,width=780,height=460');
document.formMaster.submit();

window.location.href='impressao.fechar.pedido.asp?pasta=10&pagina=24&idmsg=1';
}
//-->

//<--
function janelaClassi(){
var vpos;
vpos=window.open('','vpos','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=no,copyhistory=no,width=600,height=420');
document.formClassi.submit();
window.formClassi.reset();
}
//-->

//<--
function SolicitaSenha(){
var email = document.all.email.value;
var cpf = document.all.cpf.value;

if(email == ""){
alert("Preencha os campos (E-mail)");
document.all.email.focus();
}
else if(!eh_email(email)){
eval("alert('E-mail inválido ("+email+")');");
document.all.email.focus();
}
else if(cpf == ""){
alert("Preencha os campos (RG)");
document.all.rg.focus();
}
else if(isNaN(cpf)){
alert("O campo (CPF) aceita somente numeros!")
document.all.cpf.focus();
}
else{
document.solicitaSenhaForm.submit();
}
}
//-->