
var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
function LZ(x) {return(x<0||x>9?"":"0")+x}

function isDate(val,format) {
	var date=getDateFromFormat(val,format);
	if (date==0) { return false; }
	return true;
	}

function compareDates(date1,dateformat1,date2,dateformat2) {
	var d1=getDateFromFormat(date1,dateformat1);
	var d2=getDateFromFormat(date2,dateformat2);
	if (d1==0 || d2==0) {
		return -1;
		}
	else if (d1 > d2) {
		return 1;
		}
	return 0;
	}

function formatDate(date,format) {
	format=format+"";
	var result="";
	var i_format=0;
	var c="";
	var token="";
	var y=date.getYear()+"";
	var M=date.getMonth()+1;
	var d=date.getDate();
	var H=date.getHours();
	var m=date.getMinutes();
	var s=date.getSeconds();
	var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
	var value=new Object();
	if (y.length < 4) {y=""+(y-0+1900);}
	value["y"]=""+y;
	value["yyyy"]=y;
	value["yy"]=y.substring(2,4);
	value["M"]=M;
	value["MM"]=LZ(M);
	value["MMM"]=MONTH_NAMES[M-1];
	value["d"]=d;
	value["dd"]=LZ(d);
	value["H"]=H;
	value["HH"]=LZ(H);
	if (H==0){value["h"]=12;}
	else if (H>12){value["h"]=H-12;}
	else {value["h"]=H;}
	value["hh"]=LZ(value["h"]);
	if (H>11){value["K"]=H-12;} else {value["K"]=H;}
	value["k"]=H+1;
	value["KK"]=LZ(value["K"]);
	value["kk"]=LZ(value["k"]);
	if (H > 11) { value["a"]="PM"; }
	else { value["a"]="AM"; }
	value["m"]=m;
	value["mm"]=LZ(m);
	value["s"]=s;
	value["ss"]=LZ(s);
	while (i_format < format.length) {
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		if (value[token] != null) { result=result + value[token]; }
		else { result=result + token; }
		}
	return result;
	}
function _isInteger(val) {
	var digits="1234567890";
	for (var i=0; i < val.length; i++) {
		if (digits.indexOf(val.charAt(i))==-1) { return false; }
		}
	return true;
	}
function _getInt(str,i,minlength,maxlength) {
	for (var x=maxlength; x>=minlength; x--) {
		var token=str.substring(i,i+x);
		if (token.length < minlength) { return null; }
		if (_isInteger(token)) { return token; }
		}
	return null;
	}
function getDateFromFormat(val,format) {
	val=val+"";
	format=format+"";
	var i_val=0;
	var i_format=0;
	var c="";
	var token="";
	var token2="";
	var x,y;
	var now=new Date();
	var year=now.getYear();
	var month=now.getMonth()+1;
	var date=now.getDate();
	var hh=now.getHours();
	var mm=now.getMinutes();
	var ss=now.getSeconds();
	var ampm="";
	
	while (i_format < format.length) {
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		if (token=="yyyy" || token=="yy" || token=="y") {
			if (token=="yyyy") { x=4;y=4; }
			if (token=="yy")   { x=2;y=2; }
			if (token=="y")    { x=2;y=4; }
			year=_getInt(val,i_val,x,y);
			if (year==null) { return 0; }
			i_val += year.length;
			if (year.length==2) {
				if (year > 70) { year=1900+(year-0); }
				else { year=2000+(year-0); }
				}
			}
		else if (token=="MMM"){
			month=0;
			for (var i=0; i<MONTH_NAMES.length; i++) {
				var month_name=MONTH_NAMES[i];
				if (val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()) {
					month=i+1;
					if (month>12) { month -= 12; }
					i_val += month_name.length;
					break;
					}
				}
			if ((month < 1)||(month>12)){return 0;}
			}
		else if (token=="MM"||token=="M") {
			month=_getInt(val,i_val,token.length,2);
			if(month==null||(month<1)||(month>12)){return 0;}
			i_val+=month.length;}
		else if (token=="dd"||token=="d") {
			date=_getInt(val,i_val,token.length,2);
			if(date==null||(date<1)||(date>31)){return 0;}
			i_val+=date.length;}
		else if (token=="hh"||token=="h") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>12)){return 0;}
			i_val+=hh.length;}
		else if (token=="HH"||token=="H") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>23)){return 0;}
			i_val+=hh.length;}
		else if (token=="KK"||token=="K") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>11)){return 0;}
			i_val+=hh.length;}
		else if (token=="kk"||token=="k") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>24)){return 0;}
			i_val+=hh.length;hh--;}
		else if (token=="mm"||token=="m") {
			mm=_getInt(val,i_val,token.length,2);
			if(mm==null||(mm<0)||(mm>59)){return 0;}
			i_val+=mm.length;}
		else if (token=="ss"||token=="s") {
			ss=_getInt(val,i_val,token.length,2);
			if(ss==null||(ss<0)||(ss>59)){return 0;}
			i_val+=ss.length;}
		else if (token=="a") {
			if (val.substring(i_val,i_val+2).toLowerCase()=="am") {ampm="AM";}
			else if (val.substring(i_val,i_val+2).toLowerCase()=="pm") {ampm="PM";}
			else {return 0;}
			i_val+=2;}
		else {
			if (val.substring(i_val,i_val+token.length)!=token) {return 0;}
			else {i_val+=token.length;}
			}
		}
	if (i_val != val.length) { return 0; }
	if (month==2) {
		if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
			if (date > 29){ return false; }
			}
		else { if (date > 28) { return false; } }
		}
	if ((month==4)||(month==6)||(month==9)||(month==11)) {
		if (date > 30) { return false; }
		}
	if (hh<12 && ampm=="PM") { hh+=12; }
	else if (hh>11 && ampm=="AM") { hh-=12; }
	var newdate=new Date(year,month-1,date,hh,mm,ss);
	return newdate.getTime();
	}


function testa_form_cad_user(){
	teste_mail = /^(([0-9a-zA-Z!\#\x24%&\x27\*\+\-\/\?=^_\x60\x7B\x7D\|~]+(\.[0-9a-zA-Z!\#$%&\x27\*\+\-\/\?=^_\x60\x7B\x7D\|~]+)*)|(\"([\x01-\x08\x0B-\x0C\x0E-\x20\x21\x23-\x5B\x5D-\x7F]|\\[\x01-\x09\x0B-\x0C\x0E--\x7F])*\"))@([0-9a-zA-Z!\#$%&\x27\*\+\-\/\?=^_\x60\x7B\x7D\|~]+(\.[0-9a-zA-Z!\#$%&\x27\*\+\-\/\?=^_\x60\x7B\x7D\|~]+)*|\[([\x01-\x08\x0A\x0B\x0E-\x20\x21-\x5A\x5E-\x7F]|\\[\x01-\x09\x0A-\x0B\x0D-\x7F])*\])$/;
	tlogin  = document.myform.ulogin.value.length;
	email   = document.myform.email.value;
	tsenha  = document.myform.senha.value.length;
	senha   = document.myform.senha.value;
	csenha  = document.myform.csenha.value;
	email   = document.myform.email.value;
	if (tlogin<3){
		alert("O Login deve conter no mínimo 3 caracteres.");
		document.myform.ulogin.value='';
		document.myform.ulogin.focus();
		return;
	}
	if (!teste_mail.test(email)){
		alert("E-mail inválido.");
		document.myform.email.value='';
		document.myform.email.focus();
		return;
	}
	if (tsenha<4){
		alert("A senha deve conter no mínimo 4 caracteres.");
		document.myform.senha.value='';
		document.myform.csenha.value='';
		document.myform.senha.focus();
		return;
	}
	else{
		if (senha!=csenha){
			alert("Confirmação de senha inválida.");
			document.myform.senha.value='';
			document.myform.csenha.value='';
			document.myform.senha.focus();
			return;
		}
	}
	vinfo=" ";
	for (x=0;x<tot;x++){
		if (document.myform.abc.options[x].selected==true){
			vinfo=vinfo+ document.myform.abc.options[x].value+",";
		}
	}
	document.myform.vls.value=vinfo;
	document.myform.submit();
}

function testa_cad_cli2(){
	tnome = document.myform.nome.value.length;
	if (tnome<3){
		alert("O Nome da Pasta deve conter no mínimo 3 caracteres.");
		document.myform.nome.value='';
		document.myform.nome.focus();
		return;
	}
	document.myform.submit();
}

function testa_cad_projeto(){
	tnome = document.myform.projeto.value.length;
	if (tnome<3){
		alert("O Nome do Projeto deve conter no mínimo 3 caracteres.");
		document.myform.projeto.value='';
		document.myform.projeto.focus();
		return;
	}
	document.myform.submit();
}

function v_ex_cli(id){
	resp = confirm("Deseja realmente excluir esta Pasta?");
	if (resp){
		window.location='adm_menu.php?tela=exc&id='+id;
	}
}

function v_ex_prj(id,id2){
	resp = confirm("Deseja realmente excluir este Projeto?");
	if (resp){
		window.location='adm_menu.php?tela=excp&prj_id='+id+'&cli_id='+id2;
	}
}

function testa_cad_arquivo(){
	tnome = document.myform.atext.value.length;
	if (tnome<3){
		alert("O Texto do Link deve conter no mínimo 3 caracteres.");
		document.myform.atext.value='';
		document.myform.atext.focus();
		return;
	}
	document.myform.submit();
}

function v_ex_arq(id,id2){
	resp = confirm("Deseja realmente excluir este Arquivo?");
	if (resp){
		window.location='adm_menu.php?tela=exca&pst_id='+id+'&arq_id='+id2;
	}
}
function testa_logoff(user){
	resp = confirm("Deseja efetuar logoff de "+user+"?");
	if (resp){
		parent.location="logoff.php?user="+user;
	}
}

function testa_logoff_qlt(user){
	resp = confirm("Deseja efetuar logoff de "+user+"?");
	if (resp){
		parent.location="logoff_qlt.php?email="+user;
	}
}

function testa_exc_nws(id,tipo){
	resp = confirm("Deseja realmente excluir esta Notícia?");
	if (resp){
		window.location='adm_news.php?tela=exc&nws_id='+id+'&nws_tipo='+tipo;
	}
}

function valida_exc_forumm(id){
	resp = confirm("Deseja realmente excluir esta Mensagem?");
	if (resp){
		window.location='/admin/forumm.php?tela=exc&frm_id='+id;
	}
}

function valida_exc_forum(id){
	resp = confirm("Deseja realmente excluir esta Mensagem?");
	if (resp){
		window.location='/forum.php?tela=exc&frm_id='+id;
	}
}

function testa_cad_news(){
	
	datae = document.myform.datae.value;
	vef=isDate(datae,"dd/mm/yyyy");
	if (!vef){
		alert("Data de Entrada Inválida");
		document.myform.datae.value="";
		document.myform.datae.focus();
		return;
	}
	/*
	datas = document.myform.datas.value;
	vef2=isDate(datas,"dd/mm/yyyy");
	if (!vef2){
		alert("Data de Saída Inválida");
		document.myform.datas.value="";
		document.myform.datas.focus();
		return;
	}
	*/
	chamada = document.myform.chamada.value.length;
	if (chamada<3){
		alert("A chamada deve ter no mínimo 3 caracteres.");
		document.myform.chamada.value="";
		document.myform.chamada.focus();
		return;
	}
	
	texto = document.myform.texto.value.length;
	if (texto<3){
		alert("O texto deve ter no mínimo 3 caracteres");
		document.myform.texto.value="";
		document.myform.texto.focus();
		return;
	}
	document.myform.submit();	
}

function testa_exc_chm(id){
	resp = confirm("Deseja realmente excluir este Destaque?");
	if (resp){
		window.location='adm_chamada.php?tela=exc&chm_id='+id;
	}
}

function testa_cad_chamada(){
	texto = document.myform.chm_texto.value.length;
	if (texto<3){
		alert("O texto deve ter no mínimo 3 caracteres");
		document.myform.chm_texto.value="";
		document.myform.chm_texto.focus();
		return;
	}
	url = document.myform.chm_url.value.length;
	if (url<2){
		alert("Preencha a URL corretamente");
		document.myform.chm_url.value="http://";
		document.myform.chm_url.focus();
		return;
	}
	/*
	tmb = document.myform.tmb.value.length;
	if (tmb<12){
		alert("Selecione a imagem para Thumbnail");
		document.myform.tmb.value="";
		document.myform.tmb.focus();
		return;
	}
	*/
	document.myform.submit();
}

function verifica(){
	cont = document.myform.chm_texto.value.length;
	document.myform.qtde.value=cont;
	if (cont==110){
		//alert("Limite máximo de caracteres excedido");
		document.myform.chm_texto.value=document.myform.chm_texto.value.substring(0,109);
		return;
	}
}

function testa_faleconosco(){
	teste_mail = /^(([0-9a-zA-Z!\#\x24%&\x27\*\+\-\/\?=^_\x60\x7B\x7D\|~]+(\.[0-9a-zA-Z!\#$%&\x27\*\+\-\/\?=^_\x60\x7B\x7D\|~]+)*)|(\"([\x01-\x08\x0B-\x0C\x0E-\x20\x21\x23-\x5B\x5D-\x7F]|\\[\x01-\x09\x0B-\x0C\x0E--\x7F])*\"))@([0-9a-zA-Z!\#$%&\x27\*\+\-\/\?=^_\x60\x7B\x7D\|~]+(\.[0-9a-zA-Z!\#$%&\x27\*\+\-\/\?=^_\x60\x7B\x7D\|~]+)*|\[([\x01-\x08\x0A\x0B\x0E-\x20\x21-\x5A\x5E-\x7F]|\\[\x01-\x09\x0A-\x0B\x0D-\x7F])*\])$/;
	nome = document.myform.nome.value.length;
	if (nome<3){
		alert("Digite seu nome corretamente");
		document.myform.nome.value="";
		document.myform.nome.focus();
		return;
	}
	email = document.myform.email.value;
	if (!teste_mail.test(email)){
		alert("E-mail inválido.");
		document.myform.email.value='';
		document.myform.email.focus();
		return;
	}
	msg = document.myform.msg.value.length;
	if (msg<3){
		alert("Digite a mensagem corretamente");
		document.myform.msg.value="";
		document.myform.msg.focus();
		return;
	}
	document.myform.submit();
}

function valida_indica(){
	teste_mail = /^(([0-9a-zA-Z!\#\x24%&\x27\*\+\-\/\?=^_\x60\x7B\x7D\|~]+(\.[0-9a-zA-Z!\#$%&\x27\*\+\-\/\?=^_\x60\x7B\x7D\|~]+)*)|(\"([\x01-\x08\x0B-\x0C\x0E-\x20\x21\x23-\x5B\x5D-\x7F]|\\[\x01-\x09\x0B-\x0C\x0E--\x7F])*\"))@([0-9a-zA-Z!\#$%&\x27\*\+\-\/\?=^_\x60\x7B\x7D\|~]+(\.[0-9a-zA-Z!\#$%&\x27\*\+\-\/\?=^_\x60\x7B\x7D\|~]+)*|\[([\x01-\x08\x0A\x0B\x0E-\x20\x21-\x5A\x5E-\x7F]|\\[\x01-\x09\x0A-\x0B\x0D-\x7F])*\])$/;
	mnome = document.myform.mnome.value.length;
	if (mnome<2){
		alert("Digite seu nome corretamente");
		document.myform.mnome.value="";
		document.myform.mnome.focus();
		return;
	}
	memail = document.myform.memail.value;
	if (!teste_mail.test(memail)){
		alert("Digite seu e-mail corretamente.");
		document.myform.memail.value='';
		document.myform.memail.focus();
		return;
	}
	anome = document.myform.anome.value.length;
	if (anome<2){
		alert("Digite o nome do seu amigo corretamente");
		document.myform.anome.value="";
		document.myform.anome.focus();
		return;
	}
	aemail = document.myform.aemail.value;
	if (!teste_mail.test(aemail)){
		alert("Digite o e-mail do seu amigo corretamente.");
		document.myform.aemail.value='';
		document.myform.aemail.focus();
		return;
	}
	msg = document.myform.msg.value.length;
	if (msg<2){
		alert("Digite uma mensagem para enviar a seu amigo");
		document.myform.msg.value="";
		document.myform.msg.focus();
		return;
	}
	document.myform.submit();
}

function muda_sel(){
	fc = document.myform.nws_aurl.checked;
	if (fc==true){
		document.myform.nws_url.disabled=false;
	}
	else{
		document.myform.nws_url.disabled=true;
	}
}

function testa_exc_cli(id){
	resp = confirm("Deseja realmente excluir este Cliente?");
	if (resp){
		window.location='adm_cli.php?tela=exc&cli_id='+id;
	}
}

function testa_exc_paginas(id){
	resp = confirm("Deseja realmente excluir este nome de página?");
	if (resp){
		window.location='adm_paginas.php?tela=exc&id='+id;
	}
}

function testa_cad_cli(){
	teste_mail = /^(([0-9a-zA-Z!\#\x24%&\x27\*\+\-\/\?=^_\x60\x7B\x7D\|~]+(\.[0-9a-zA-Z!\#$%&\x27\*\+\-\/\?=^_\x60\x7B\x7D\|~]+)*)|(\"([\x01-\x08\x0B-\x0C\x0E-\x20\x21\x23-\x5B\x5D-\x7F]|\\[\x01-\x09\x0B-\x0C\x0E--\x7F])*\"))@([0-9a-zA-Z!\#$%&\x27\*\+\-\/\?=^_\x60\x7B\x7D\|~]+(\.[0-9a-zA-Z!\#$%&\x27\*\+\-\/\?=^_\x60\x7B\x7D\|~]+)*|\[([\x01-\x08\x0A\x0B\x0E-\x20\x21-\x5A\x5E-\x7F]|\\[\x01-\x09\x0A-\x0B\x0D-\x7F])*\])$/;
	nome = document.myform.cli_nome.value.length;
	if (nome<3){
		alert("O nome deve ter no mínimo 3 caracteres");
		document.myform.cli_nome.value="";
		document.myform.cli_nome.focus();
		return;
	}
	
	empresa = document.myform.cli_empresa.value.length;
	if (empresa<3){
		alert("A empresa deve ter no mínimo 3 caracteres");
		document.myform.cli_empresa.value="";
		document.myform.cli_empresa.focus();
		return;
	}
	
	cargo = document.myform.cli_cargo.value.length;
	if (cargo<3){
		alert("O cargo deve ter no mínimo 3 caracteres");
		document.myform.cli_cargo.value="";
		document.myform.cli_cargo.focus();
		return;
	}
	
	email = document.myform.cli_email.value;
	if (!teste_mail.test(email)){
		alert("Digite o e-mail do cliente corretamente.");
		document.myform.cli_email.value='';
		document.myform.cli_email.focus();
		return;
	}
	
	senha = document.myform.cli_senha.value.length;
	if (senha<4){
		alert("A senha deve ter no mínimo 4 caracteres");
		document.myform.cli_senha.value="";
		document.myform.cli_senha.focus();
		return;
	}
	document.myform.submit();
}


function testa_alt_scli(){
	asenha = document.myform.asenha.value.length;
	if (asenha<1){
		alert("Digite a senha atual");
		document.myform.asenha.value="";
		document.myform.asenha.focus();
		return;
	}
	nsenha = document.myform.nsenha.value.length;
	if (nsenha<4){
		alert("A nova senha deve ter no mínimo 4 caracteres");
		document.myform.nsenha.value="";
		document.myform.nsenha.focus();
		return;
	}
	csenha  = document.myform.nsenha.value;
	ccsenha = document.myform.csenha.value;
	if (csenha!=ccsenha){
		alert("Confirmação de senha inválida");
		document.myform.csenha.value="";
		document.myform.nsenha.value="";
		document.myform.nsenha.focus();
		return;
	}
	document.myform.submit();
}

function testa_rmail(){
	teste_mail = /^(([0-9a-zA-Z!\#\x24%&\x27\*\+\-\/\?=^_\x60\x7B\x7D\|~]+(\.[0-9a-zA-Z!\#$%&\x27\*\+\-\/\?=^_\x60\x7B\x7D\|~]+)*)|(\"([\x01-\x08\x0B-\x0C\x0E-\x20\x21\x23-\x5B\x5D-\x7F]|\\[\x01-\x09\x0B-\x0C\x0E--\x7F])*\"))@([0-9a-zA-Z!\#$%&\x27\*\+\-\/\?=^_\x60\x7B\x7D\|~]+(\.[0-9a-zA-Z!\#$%&\x27\*\+\-\/\?=^_\x60\x7B\x7D\|~]+)*|\[([\x01-\x08\x0A\x0B\x0E-\x20\x21-\x5A\x5E-\x7F]|\\[\x01-\x09\x0A-\x0B\x0D-\x7F])*\])$/;
	rmail = document.myform.rmail.value;
	if (!teste_mail.test(rmail)){
		alert("Digite seu e-mail corretamente.");
		document.myform.rmail.value='';
		document.myform.rmail.focus();
		return;
	}
	document.myform.submit();
}

function testa_caf(){
	assunto = document.myform.frm_assunto.value.length;
	if (assunto<3){
		alert("Digite o assunto desejado");
		document.myform.frm_assunto.value="";
		document.myform.frm_assunto.focus();
		return;
	}
	texto = document.myform.frm_texto.value.length;
	if (texto<3){
		alert("Digite o texto desejado");
		document.myform.frm_texto.value="";
		document.myform.frm_texto.focus();
		return;
	}
	document.myform.submit();
}

function testa_crf(){
	texto = document.myform.frm_texto.value.length;
	if (texto<3){
		alert("Digite o texto desejado");
		document.myform.frm_texto.value="";
		document.myform.frm_texto.focus();
		return;
	}
	document.myform.submit();
}

function testa_cad_pagina(){
	npagina = document.myform.npagina.value.length;
	if (npagina<2){
		alert("Digite o nome da página corretamente.");
		document.myform.npagina.value="";
		document.myform.npagina.focus();
		return;
	}
	npath = document.myform.npath.value.length;
	if (npath<3){
		alert("Digite a path corretamente.");
		document.myform.npath.value="";
		document.myform.npath.focus();
		return;
	}
	document.myform.submit();
}

