// JavaScript Document

function ValidaVazio(campo,txt) {

	//Valida Título

	if ((campo.value=="") || (campo.value.length==0) || (campo.value=="Null")) {

		alert('Você esqueceu de preencher o campo '+txt);

		//alert('Você esqueceu de preencher o campo '+campo.name);

		campo.focus();

		return false;

	} else return true;

}



//Testa se pelo menos um checkbox ou radio foi selecionado

function testaCheck(campo, mensagem){

	if (typeof(campo.length)!="undefined"){

		for (var i=0; i<campo.length; i++) {

			if (campo[i].checked) {

				if (campo[i].value != '') {return true;}

			}

		}

	}else{

		if (campo.checked) {return true;}

	}

	alert(mensagem);

	return false;		

}



function testaEmail(txtInput) {

	email = txtInput.value;

	if (email == "") {

		return true;

	} else {

  		if ((email.indexOf('@') == email.lastIndexOf('@')) &&	// só tem um @

  			(email.indexOf('@') > 0) &&							// existe @ e não é prim

  			(email.charAt(email.length-1) != '@') &&			// @ não é o último

  			(email.indexOf(' ') == -1) &&						// não existe espaços

  			(email.lastIndexOf('.') > email.indexOf('@')) &&	// existe . após @

  			(email.charAt(email.indexOf('@') + 1) != '.') &&	// sem . logo após @

  			(email.charAt(email.indexOf('@') - 1) != '.') &&	// sem . logo antes @

  			(email.indexOf('.') > 0) &&							// existe . e não é prim

			(email.charAt(email.length-1) != '.')) {			// . não é o último

				

			// verifica se não há pontos seguidos

			sub = email.substring(email.indexOf('.')+1, email.length);

			while (sub.indexOf('.') != -1) {

				if (sub.charAt(0) == '.') {

					alert("Formato de e-mail incorreto!");

					txtInput.focus();

					return false;

				} else {

					sub = sub.substring(sub.indexOf('.')+1, sub.length);

				}

			}

			return true;

			

		} else {

			alert("Formato de e-mail incorreto!");

			txtInput.focus();

			return false;

		}

	}

}



function popEtiquetas() {	

	var url= "../sad/etiquetas.php";

	janelaCenter(url,"janelaEtiquetas","status=no, scrollbars=yes",738,500);

}


function popEscreveMail() {	

	var url= "pop_escreve_mail.php";

	janelaCenter(url,"janelaEmail","status=no, scrollbars=yes",640,480);

}


function popBoletos() {	

	var url= "../boleto/boleto.php";

	janelaCenter(url,"janelaBoletos","status=no, scrollbars=yes",740,500);

}



function popEnviaBoleto(id) {	

	var url= "envia_boleto.php?id="+id;

	janelaCenter(url,"janelaBoletos","status=no, scrollbars=no",400,300);

}



//-->







// JavaScript Document

<!--

function MM_jumpMenu(targ,selObj,restore){ //v3.0

  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");

  if (restore) selObj.selectedIndex=0;

}

//-->

<!-- LIMITE NA TEXTAREA

	

	// EXEMPLO DE USO

	//	<form>

	//		<textarea name=message wrap=physical cols=28 rows=4 onKeyDown="textareaLimite(this.form.message,this.form.remLen,125);" onKeyUp="textareaLimite(this.form.message,this.form.remLen,125);"></textarea>

	// 		<input readonly type=text name=remLen size=3 maxlength=3 value="125"> 

	//	</form>

	function textareaLimite(field, countfield, maxlimit) {

	if (field.value.length > maxlimit) 

		field.value = field.value.substring(0, maxlimit);

	else 

		countfield.value = maxlimit - field.value.length;

	}



//  FIM -->



<!--

function MM_findObj(n, d) { //v4.01

  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

  if(!x && d.getElementById) x=d.getElementById(n); return x;

}



function MM_validateForm() { //v4.0

  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;

  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);

    if (val) { nm=val.id; if ((val=val.value)!="") {

      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');

        if (p<1 || p==(val.length-1)) errors+='- '+nm+' não é válido.\n';

      } else if (test!='R') { num = parseFloat(val);

        if (isNaN(val)) errors+='- '+nm+' deve conter apenas números.\n';

        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');

          min=test.substring(8,p); max=test.substring(p+1);

          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';

    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' é obrigatório.\n'; }

  } if (errors) alert('Atenção!\n'+errors);

  document.MM_returnValue = (errors == '');

}



function MM_jumpMenu(targ,selObj,restore){ //v3.0

  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");

  if (restore) selObj.selectedIndex=0;

}





function validatePwd() {

var invalid = " "; // Invalid character is a space

var minLength = 6; // Minimum length

var pw1 = document.frm.senha_user.value;

var pw2 = document.frm.confirma_senha.value;

/* check for a value in both fields.

if (pw1 == '' || pw2 == '') {

alert('Please enter your password twice.');

return false;

}*/

// check for minimum length

if (document.frm.senha.value.length < minLength) {

alert('A senha deve ter no mínimo ' + minLength + ' caracteres. Tente novamente.');

return false;

}

// check for spaces

	if (document.frm.senha.value.indexOf(invalid) > -1) {

	alert("Atenção! espaço não são permitidos.");

	return false;

	}

	else {

	  if (pw1 != pw2) {

	  alert ("A sua senha está incorreta. Tente novamente.");

	  return false;

	  }

	  else {

	  //alert('Nice job.');

	  return true;

      }

   }

}

//-->
