/*
Highlight Link script
*/
if(typeof JotPad5 == 'undefined') { // since the dashlet can be included multiple times a page, don't redefine these functions
	JotPad5 = function() {
	    return {
	    	/**
	    	 * Called when the textarea is blurred
	    	 */
	        exibe: function(id) {
	        	ajaxStatus.showStatus('Carregando ...'); // show that AJAX call is happening
	        	// what data to post to the dashlet
    	    	postData = 'modulo=Home';
				var cObj = YAHOO.util.Connect.asyncRequest('POST','pensamentodiario.php', 
								  {success: JotPad5.saved, failure: JotPad5.saved}, postData);
	        },
		    /**
	    	 * handle the response of the saveText method
	    	 */
	        saved: function(data) {
				xxx = data.responseText; // Texto retornado pela requisição do ajax.
//				xxx = xxx.replace(/\+/g," "); // Substitui o “+” por um espaço.
//				xxx = unescape(xxx); // Desfaz o que a função urlencode(); do PHP fez.
//				xxx = xxx.replace(/00/g,"");
	        	eval(xxx);
				result=new Array();
				result['header']='Pensamentos Di&aacute;rios - (Pressione a tecla ESC para sair)';
				result['body']="N&atilde;o foi poss&iacute;vel carregar o registro";
	           	ajaxStatus.showStatus('Carregado');
	           	if(typeof resultado != 'undefined') {
					result['body']=resultado;
//					alo = nl2br(resultado2);
				}
//				ta.style.display = 'none';
				configureDlg.setHeader(result['header']);
				configureDlg.setBody(result['body']);
				var listeners=new YAHOO.util.KeyListener(document,{keys:27},{fn:function(){this.hide();},scope:configureDlg,correctScope:true});
				configureDlg.cfg.queueProperty("keylisteners",listeners);
				configureDlg.render(document.body);
				configureDlg.show();
				configureDlg.configFixedCenter(null,false);
	           	window.setTimeout('ajaxStatus.hideStatus()', 2000);
	        }
	    };
	}();
}
function JanelaEspecial() {
//	ajaxStatus.showStatus("Carregando...");
	configureDlg=new YAHOO.widget.SimpleDialog("dlg",{visible:false,width:"600",effect:[{effect:YAHOO.widget.ContainerEffect.SLIDETOP,duration:0.5},{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.5}],fixedcenter:true,modal:true,draggable:false});
//	fillInConfigureDiv=function(data){ajaxStatus.hideStatus();try{eval(data.responseText);}
	JotPad5.exibe();
//		ajaxStatus.showStatus("Carregado...");
// 		window.setTimeout('ajaxStatus.hideStatus()', 2000);
}
function AbreJanela2() {
	var navegador = navigator.appName;
	if (navegador == "Netscape" || navegador == "Opera") {
		window.open('http://www.rccg.biz/cadastro/register.php', 'registerwindow', config='height=320,width=600,toolbar=no,resizable=yes,menubar=no,scrollbars=no,location=no,directories=no,status=no');
	}
	else {
		window.open('http://www.rccg.biz/cadastro/register.php', 'registerwindow', config='height=400,width=600,toolbar=no,resizable=yes,menubar=no,scrollbars=no,location=no,directories=no,status=no');
	}
}
function AbreJanela1() {
	var navegador = navigator.appName;
	if (navegador == "Netscape") {
		window.open('http://www.rccg.biz/contatoX.php?acao=preencher&n=2','contato','width=450, height=230,toolbar=no,resizable=no,menubar=no,scrollbars=no,location=no,directories=no,status=no');
	}
	else {
		if (navegador == "Opera") {
			window.open('http://www.rccg.biz/contatoX.php?acao=preencher&n=3','contato','width=475, height=200,toolbar=no,resizable=no,menubar=no,scrollbars=no,location=no,directories=no,status=no');
		}
		else {
			window.open('http://www.rccg.biz/contatoX.php?acao=preencher&n=1','contato','width=480, height=260,toolbar=no,resizable=no,menubar=no,scrollbars=no,location=no,directories=no,status=no');
		}
	}
}
function MascaraMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    if (whichCode == 13) return true;
    key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida
    len = objTextBox.value.length;
    for(i = 0; i < len; i++)
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
    aux = '';
    for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) objTextBox.value = '';
    if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
    if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;
    if (len > 2) {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
                aux2 += SeparadorMilesimo;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        objTextBox.value += aux2.charAt(i);
        objTextBox.value += SeparadorDecimal + aux.substring(len-2);
    }
    return false;
}
function Formatadata(Campo, teclapres) {
	    var strCheck = '0123456789';
//	    var whichCode = (window.Event) ? teclapres.which : teclapres.keyCode;
		var whichCode = teclapres.keyCode ? teclapres.keyCode : teclapres.which ? teclapres.which : teclapres.charCode;
		if (whichCode > 94 && whichCode < 106) whichCode = whichCode - 48;
//	    if (whichCode == 13) return true;
	    key = String.fromCharCode(whichCode); // key recebe em ASCII
//		var tecla = teclapres.keyCode;
		var vr = new String(Campo.value);
	    if (strCheck.indexOf(key) == -1 && whichCode != 8 && whichCode != 9) {
			teclapres.returnValue = false;
			tam = vr.length-1;
			Campo.value = vr.substring(0,tam);
	    	return false; // Chave inválida
	    }
		vr = vr.replace("/", "");
		vr = vr.replace("/", "");
		vr = vr.replace("/", "");
		tam = vr.length+1;
		if (whichCode != 8 && whichCode != 9) {
//			alert(tam);
			if (tam > 0 && tam < 4) {
//				alert(vr.substring(0,2));
				if (parseInt(vr.substring(0,2)) > 31) {
					Campo.value = vr.substring(0,1);
				}
				else {
					Campo.value = vr.substring(0, 2);
				}
			}
			else if (tam > 3 && tam < 6) {
//				alert(vr.substring(2,4));
				if (parseInt(vr.substring(2,4)) > 12) {
					Campo.value = vr.substring(0,3);
				}
				else {
					Campo.value = vr.substring(0, 2) + '/' + vr.substring(2,4);
				}
			}
			else if (tam > 5) {
				Campo.value = vr.substr(0, 2) + '/' + vr.substring(2, 4) + '/' + vr.substr(4,10);
			}
		}
}
function MascaraTelefone(objTextBox, sepTel, e){
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    if (whichCode == 13) return true;
    key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida
    len = objTextBox.value.length;
    for(i = 0; i < len; i++)
        if (objTextBox.value.charAt(i) != sepTel) break;
    aux = '';
    if (len == 12) {
    	return false;
    }
    for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
    aux += key;
    len = aux.length;
    switch (len) {
    	case 0:
    		objTextBox.value='';
    		break;
    	case 2:
    		objTextBox.value = aux + sepTel;
    		break;
    	case 6:
    		objTextBox.value = aux.substring(0,2) + sepTel + aux.substring(2,6) + sepTel;
    		break;
    	default:
    		ttt = objTextBox.value;
    		objTextBox.value = ttt+key;
    }
    return false;
}
function highlight(which,color) {
	if (document.all||document.getElementById)
	which.style.backgroundColor=color
}
 function blockError(){return true;}
 function disableselect(e)
 {
    return false
 }
 function reEnable()
 {
    return true
 }
 //if IE4+
 
function Protege() {
 window.onerror = blockError;

 document.onselectstart=new Function ("return false")
 //if NS6
 if (window.sidebar)
 {
    document.onmousedown=disableselect
    document.onclick=reEnable
 }
}
function ajax_coment(url) {
	req = null;
	var ax="";
/* (Mozilla/Safari) */
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		req.onreadystatechange = processReqChangeComent;
		var navegador = navigator.appName;
		if (navegador == "Opera") {
			req.open("GET",url,false);
		}
		else {
			req.open("GET",url,true);		/* modo síncrono não está funcionando no Firefox */
		}
		req.send(null);
/* Procura por uma versão ActiveX (IE) */
	}
	else if (window.ActiveXObject) {
		try {
            http_request = new ActiveXObject("Microsoft.XMLHTTP");
        }
		catch (e) {
            try {
		          http_request = new ActiveXObject("Msxml2.XMLHTTP");
            }
			catch (e) {}
        }
		req = new ActiveXObject("Microsoft.XMLHTTP"); 
		if (req) { 
			req.onreadystatechange = processReqChangeComent;
			req.open("GET",url,false);		/* false indica que a execução vai esperar a resposta */
			req.send();
		}
	}
}
function processReqChangeComent() {
/* apenas quando o estado for "completado" */
	if (req.readyState == 4) { /* apenas se o servidor retornar "OK" */
		if (req.status ==200) {
/* procura pela div id="pagina" e insere o conteudo <BR>// retornado nela, como texto HTML */
/*			document.getElementById('pagina').innerHTML = req.responseText; */
/*			document.register_user.resposta_ajax.value=req.responseText; */
			var navegador = navigator.appName;
			var ID = document.register_user.iid.value;
			var ID2 = document.register_user.iid2.value;
			var onde = document.register_user.onde.value;
			var n = document.register_user.nn.value
			if (navegador == "xxx") {
				document.getElementById(ID).childNodes[0].nodeValue=req.responseText;
				document.getElementById(ID).style.color="#000080";
			}
			else {
			    var element1 = document.getElementById(ID);
				element1.innerHTML = '<font face="Arial Narrow" size="2" color="#000080"><i>'+req.responseText+'<br></i></font></p>';
			}
		    var element2 = document.getElementById(ID2);
			element2.innerHTML = '<a title="exibir resposta" href="'+onde+'" onClick="Ocultar(\''+ID+'\','+n+',\''+ID2+'\',\''+onde+'\')">Ocultar</a><br>';
		}
		else { 
			alert("Houve um problema ao obter os dados:n" + req.statusText); 
			document.register_user.resposta_ajax.value="erro";
		} 
	} 
}
function ajax(url) {
	req = null;
	var ax="";
/* (Mozilla/Safari) */
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		req.onreadystatechange = processReqChange;
		var navegador = navigator.appName;
		if (navegador == "Opera") {
			req.open("GET",url,false);
		}
		else {
			req.open("GET",url,true);		/* modo síncrono não está funcionando no Firefox */
		}
		req.send(null);
/* Procura por uma versão ActiveX (IE) */
	}
	else if (window.ActiveXObject) {
		try {
            http_request = new ActiveXObject("Microsoft.XMLHTTP");
        }
		catch (e) {
            try {
		          http_request = new ActiveXObject("Msxml2.XMLHTTP");
            }
			catch (e) {}
        }
		req = new ActiveXObject("Microsoft.XMLHTTP"); 
		if (req) { 
			req.onreadystatechange = processReqChange;
			req.open("GET",url,false);		/* false indica que a execução vai esperar a resposta */
			req.send();
		}
	}
}
function processReqChange() {
/* apenas quando o estado for "completado" */
	if (req.readyState == 4) { /* apenas se o servidor retornar "OK" */
		if (req.status ==200) {
/* procura pela div id="pagina" e insere o conteudo <BR>// retornado nela, como texto HTML */
/*			document.getElementById('pagina').innerHTML = req.responseText; */
			document.register_user.resposta_ajax.value=req.responseText;
		}
		else { 
			alert("Houve um problema ao obter os dados:n" + req.statusText); 
			document.register_user.resposta_ajax.value="erro";
		} 
	} 
}
function ajax2(url) {
	req = null;
	var ax="";
/* (Mozilla/Safari) */
	if (window.XMLHttpRequest) { 
		req = new XMLHttpRequest(); 
		req.onreadystatechange = processReqChange2; 
		if (navegador == "Opera") {
			req.open("GET",url,true);
		}
		else {
			req.open("GET",url,true);		/* modo síncrono não está funcionando no Firefox */
		}
/*		req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); */
/*		req.send('url='+document.register_user.value); */
		req.send(null);
/* Procura por uma versão ActiveX (IE) */
	}
	else if (window.ActiveXObject) {
		try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
        }
		catch (e) {
            try {
		        req = new ActiveXObject("Msxml2.XMLHTTP");
            }
			catch (e) {}
        }
/*		req = new ActiveXObject("Microsoft.XMLHTTP");	*/
		if (req) { 
			req.onreadystatechange = processReqChange2;
			req.open("GET",url,true);		/* false indica que a execução vai esperar a resposta */
/*			req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); */
/*			req.send('url='+document.register_user.value); */
			req.send();
		}
	}
}
function processReqChange2() {
/* apenas quando o estado for "completado" */
	if (req.readyState == 4) { /* apenas se o servidor retornar "OK" */
		if (req.status == 200) {
/* procura pela div id="pagina" e insere o conteudo <BR>// retornado nela, como texto HTML */
/*			document.getElementById('pagina').innerHTML = req.responseText; */
			a_ajax2 = req.responseText;
			n = 11;
			if (a_ajax2.substring(11,12) == "0") {
				n = 12;
			}
			a_ajax2 = a_ajax2.substring(10,n);
			document.register_user.resposta_ajax.value = a_ajax2;
		}
		else {
			alert("Houve um problema ao obter os dados:n" + req.statusText); 
		} 
	} 
}
function VerifyName(campo) {
	x = campo.value;
	x = x.toUpperCase();
	n = x.length;
	composicao = "";
	contador = 0;
	faltoubranco = "";
	for (i=0;i<n;i++) {
		y = x.substring(i,i+1);
		if ((y < 'A' || y > 'Z') && (y <'0' || y > '9')) {
			if (y != ' ') {
				alert('Por favor, digite somente letras, sem acentua&ccedil;&atilde;o gr&aacute;fica');
				campo.focus();
				return 0;
			}
			else {
				if (contador == 0 && i>0 && i<n) {
					faltoubranco = " ";
				}
				contador++;
			}
		}
		else {
			contador = 0;
			composicao = composicao + faltoubranco + y;
			faltoubranco = "";
		}
	}
	campo.value = composicao;
}
  function playSound(){
    document.sound1.play();
}
// -->
  function stopSound(){
    document.sound1.stop();
}
// -->
function VerifyData() {
	mes = document.previsao.mes_nascimento.value;
	dia = document.previsao.dia_nascimento.value;
	msg = "Essa data não existe";
	erro = 0;
	switch (mes) {
		case '2':
			if (dia > 29) {
				alert(msg);
				erro = 1;
				break;
			}
		case '4':
			if (dia > 30) {
				alert(msg);
				erro = 1;
				break;
			}
		case '6':
			if (dia > 30) {
				alert(msg);
				erro = 1;
				break;
			}
		case '9':
			if (dia > 30) {
				alert(msg);
				erro = 1;
				break;
			}
		case '11':
			if (dia > 30) {
				alert(msg);
				erro = 1;
				break;
			}
	}
	if (erro == 1) {
		document.previsao.dia_nascimento.focus();
		return 0;
	}
}
function VerifyAno() {
	variavel_data=new Date();
	an=variavel_data.getYear();
	if (an < 1900) {
		an = an + 1900;
	}
	if (document.previsao.anonascimento.value < 1900 || document.previsao.anonascimento.value > an) {
		alert('Esse ano não existe');
		document.previsao.anonascimento.value = "";
		document.previsao.anonascimento.focus();
		return 0;
	}
}
function VerifyDados() {
	if (document.previsao.nome.value == "") {
		alert('Por favor, informe seu nome completo');
		document.previsao.nome.focus();
		return 0;
	}
	else {
		var vrr = new String(document.previsao.dtnascimento.value);
		if (vrr.length != 10) {
			alert('Por favor, informe o ano do seu nascimento com 4 algarismos');
			document.previsao.dtnascimento.focus();
			return false
		}
	}
	var vr = new String(document.previsao.dtnascimento.value);
	document.previsao.dia_nascimento.value = vr.substring(0,2);
	if (parseInt(document.previsao.dia_nascimento.value) < 1) {
		alert('Dia invalido');
		document.previsao.dtnascimento.focus();
		return false;
	}
	document.previsao.mes_nascimento.value = vr.substring(3,5);
	var ames = document.previsao.mes_nascimento.value;
	if (ames < 1 || ames > 12) {
		alert('mes invalido');
		document.previsao.dtnascimento.focus();
		return false;
	}
	document.previsao.anonascimento.value = vr.substring(6,10);
	if (parseInt(document.previsao.anonascimento.value) < 1900) {
		alert('Ano invalido');
		document.previsao.dtnascimento.focus();
		return false;
	}
	document.previsao.submit();
}

