// JavaScript Document

	var States = new Array('Undefined','Stopped','Paused','Playing','ScanForward','ScanReverse','Buffering','Waiting','MediaEnded','Transitioning','Ready','Reconnecting','');
	var nowSP = new Date();
	showData();

	function begins() {
		var myMin = window.setInterval('showData()',60000);
	}

	function changeAssunto(v) {
		var formAll = document.getElementById('formAll');
		var atividade = document.getElementById('atividade');
		formAll.style.visibility = 'hidden';
		if(v!=0) {
			if(v!=3) {
			  atividade.style.display = "block";
			} else {
			  atividade.style.display = "none";
			}
			formAll.style.visibility = 'visible';
		}
	}

	var erroMail;
	function grava(t) {
		erroMail += '\n' + t;
	}

	function testMail(t, t2) {
		var r,a,b; var l=t.length; r=false; a=false; b=false; 
		if( l > 6 ) {
			if( t == t2 ) {
				for (i=0;i<l;i++) { if(t.substring(i,i+1)=='@') { a=true; } }
				for (i=0;i<l;i++) { if(t.substring(i,i+1)=='.') { b=true; } }
				if((l>6)&&(a&&b)) r = true;  
					else { 
						r = false;
						grava('O EMAIL \'' + t + '\' não é um endereço válido;');
					}
			} else {
				r = false;
				grava('O campos EMAILs precisam ser idênticos;');
			}
		} else {
			r = false;
			grava('O campo EMAIL precisa ter no mínimo 7 caracteres;');
		}
		return r;
	}

	function testDados( d, c, n ) {
		var r = false;
		if ( d.length > n ) r = true;
			else grava('O campo ' + c + ': Precisa ter pelo menos ' + eval(n+1) + ' caracteres;'); 
		return r;
	}

	function loadVars(resultado, objForm) {

			if(resultado) {
				alert('Sua mensagem para Rede Sinai\nfoi enviada com sucesso!\n\n');
				objForm.reset();
			} else { alert('algum problema ocorreu!\ntente novamente mais tarde.'); }

	}

	function sendMyFormNow(obj) {
		var url = obj.action + '?assunto=' + obj.assunto.value;
		obj.action = url;
		sendAndLoadVars(obj, loadVars);
	}

	function enviar() {
		var myForm = document.getElementById('frmSinai');
		var isOK = true;
		erroMail = 'ATENÇÃO:\nAlgun(s) ERRO(s) fora(m) encontrado(s)!\n';
		if(myForm.assunto.value!=0) {
		 if(myForm.ativ.value!=0 || myForm.assunto.value==3) {
			if( !testMail(myForm.mail.value, myForm.mail2.value) ) isOK = false; 
			if( !testDados(myForm.nome.value, 'NOME', 3) ) isOK = false;
			if( !testDados(myForm.cidade.value, 'CIDADE', 4) ) isOK = false; 
			if( !testDados(myForm.uf.value, 'ESTADO', 1) ) isOK = false;
			if( !testDados(myForm.pais.value, 'PAÍS', 2) ) isOK = false;
			if( myForm.assunto.value !=3 ) {
				if( !testDados(myForm.razao.value, 'NOME da Igreja ou da Empresa', 14) ) isOK = false;
				if( !testDados(myForm.ender.value, 'ENDEREÇO', 11) ) isOK = false;
				if( !testDados(myForm.bairro.value, 'BAIRRO', 6) ) isOK = false;
			}
			if( !testDados(myForm.mensa.value, 'MENSAGEM', 19) ) isOK = false; 
			if(isOK) sendMyFormNow(myForm); 
			else alert( erroMail + '\n\nVerifique os dados e em seguida tente novamente!\n' );
		 } else {
			alert('ERRO:\n\nEscolha uma ATIVIDADE!\n\nEm seguida, tente novamente.\n');
		 }
		} else {
			alert('ERRO:\n\nEscolha um ASSUNTO!\n\nEm seguida, tente novamente.\n');
		}
	}

	function trim(tx) {
		return tx.replace(/^\s*/, "").replace(/\s*$/, "");
	}

	function mTrim(obj) {
	var l = obj.value.length; var x=''; var r='';
		for (i=0;i<l;i++) {
			x=obj.value.substring(i,i+1);
			if(x!=' ') { r+=x; } }
		obj.value = r;
	}

	function lowerCs(obj) {
		var t = trim(obj.value.toLowerCase());
		obj.value = t;
	}

	function iniUper(obj) {
	var t = trim(obj.value.toLowerCase()); var r = ''; var l = t.length; var p=false; var x='';
		for (i=0;i<l;i++) {
			x = t.substring(i,i+1);
			if((i==0)||p) { r += x.toUpperCase(); p=false; } else { r += x; }
			if(x==' ') { p=true; } }
		obj.value = r;	
	}

