window.status = "LMS DTCOM - Ambiente Virtual de Aprendizagem" ;

function validaCPFLogin(cpf) {		
		erro = new String;
		if (cpf.length < 11) erro += "Sao necessarios 11 digitos para verificacao do CPF! \n\n"; 
		var nonNumbers = /\D/;
		if (nonNumbers.test(cpf)) erro += "A verificacao de CPF suporta apenas numeros! \n\n "; 
		if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
		erro += "Numero de CPF invalido!  "
		}
		var a = [];
		var b = new Number;
		var c = 11;
		for (i=0; i<11; i++){
		a[i] = cpf.charAt(i);
		if (i < 9) b += (a[i] * --c);
		}
		if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
		b = 0;
		c = 11;
		for (y=0; y<10; y++) b += (a[y] * c--); 
		if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
		if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
		erro +="Digito verificador com problema!";
		}
		if (erro.length > 0){
		erro = " CAMPO LOGIN : " + erro;
		erro = erro + " Digite o CPF no campo Login ";
		alert(erro);
		return false;
		}
		return true;
}		

function mostrarFoto(caminho)
{
	if (caminho.replace(' ', '') != '')
	{
		caminho = caminho.replace('\\', '\\\\');
		document.frmInclusaoAlunos.fotoView.src = caminho;
	}
}



function fx_OpenNewWindow(url, myWidth, myHeight)
{
	if( navigator.appName == 'Netscape' )
	{ 
		winProps = "HEIGHT=" + myHeight + ",WIDTH=" + myWidth; 
		newWindow = window.open( url, "", winProps ); 
		newWindow.moveTo(400,300); 
		newWindow.focus(); 
	} 
	else 
	{ 
		winProps = "status:no;center:yes;help:no;minimize:no;maximize:no;border:thin;"; 
		winProps += "statusbar:no;scroll:yes;dialogWidth:" + myWidth + "px;dialogHeight:"+ myHeight +"px" 
		newWindow = window.showModalDialog( url , null , winProps ); 
	} 
	return newWindow; 
		
}


function fx_Preload() {
	var d=document; 
	if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=fx_Preload.arguments; 
	for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function fx_RestauraImagem() {
	var i,x,a=document.MM_sr; 
	for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function fx_ProcuraObjeto(n, d) {
	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=fx_ProcuraObjeto(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); 
	return x;
}

function fx_AlteraImagem() {
	var i,j=0,x,a=fx_AlteraImagem.arguments; 
	document.MM_sr=new Array; 
	for(i=0;i<(a.length-2);i+=3)
	if ((x=fx_ProcuraObjeto(a[i]))!=null){
		document.MM_sr[j++]=x; 
		if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];
	}
}

function fx_Popup(URL, winName, features, myWidth, myHeight, isCenter) 
{ 
	
	if(window.screen)if(isCenter)if(isCenter=="true")
	{
		
		var myLeft = (screen.width-myWidth)/2;
		var myTop = (screen.height-myHeight)/2;
		features+=(features!='')?',':'';
		features+=',left='+myLeft+',top='+myTop + ',scrollbars = yes';
	}
	window.open(URL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight+ ',resizable=yes,scrollbars = yes');
	
}


/*
--------------------------------------------------------------------------------------------------------
INFO! 
	$AUTOR..............: Órion Rigel - orion@dtcom.com.br
	$DATA CRIAÇÃO.......: 09/08/2004
	$DESCRIÇÃO..........: Função para validação de campos Nulos no Formulário
	$UTILIZAÇÃO.........: Recebe o Campo a ser tratado e retorna true pra preenchido e false para vazio
-------------------------------------------------------------------------------------------------------
*/
function CheckCampo(campo, nome)
{
	if (campo.value == "")
	{
		alert("Por favor preencha o campo " + nome); //Alterado por Marcia 11/08/2004 para mostrar o nome do campoe não o id
		campo.focus();//Incluído por Marcia 11/08/2004
		return false;
	}
	else
		return true;
}

function validaCPF() {
		cpf = document.getElementById('cpf').value;
		erro = new String;
		if (cpf.length < 11) erro += "Sao necessarios 11 digitos para verificacao do CPF! \n\n"; 
		var nonNumbers = /\D/;
		if (nonNumbers.test(cpf)) erro += "A verificacao de CPF suporta apenas numeros! \n\n"; 
		if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
		erro += "Numero de CPF invalido!"
		}
		var a = [];
		var b = new Number;
		var c = 11;
		for (i=0; i<11; i++){
		a[i] = cpf.charAt(i);
		if (i < 9) b += (a[i] * --c);
		}
		if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
		b = 0;
		c = 11;
		for (y=0; y<10; y++) b += (a[y] * c--); 
		if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
		if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
		erro +="Digito verificador com problema!";
		}
		if (erro.length > 0){
		alert(erro);
		return false;
		}
		return true;
}	
function abre_pop_up(pagina)
	
	{	
	
	window.open(pagina,'HiperMasters', 'width=300,height=350,top='+(window.screen.height/2-600/2)+',left='+(window.screen.width/2-800/2)+', scrollbars=yes, toolbar=no, menubar=no, status=no, location=no, resizable=no');

	

	
	}	
	
	function txtBoxFormat(objForm, strField, sMask, evtKeyPress) {
var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

if(document.all) { // Internet Explorer
    nTecla = evtKeyPress.keyCode;
} else if(document.layers) { // Nestcape
    nTecla = evtKeyPress.which;
} else {
    nTecla = evtKeyPress.which;
    if (nTecla == 8) {
        return true;
    }
}

sValue = objForm[strField].value;
// Limpa todos os caracteres de formatação que
// já estiverem no campo.
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( " ", "" );
sValue = sValue.toString().replace( " ", "" );
fldLen = sValue.length;
mskLen = sMask.length;

i = 0;
nCount = 0;
sCod = "";
mskLen = fldLen;

while (i <= mskLen) {
bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ":") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

if (bolMask) {
    sCod += sMask.charAt(i);
    mskLen++;
} else {
    sCod += sValue.charAt(nCount);
    nCount++;
}
i++;
}

objForm[strField].value = sCod;
if (nTecla != 8) { // backspace
    if (sMask.charAt(i-1) == "9") { // apenas números...
    return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
else { // qualquer caracter...
    return true;
}
} else {
    return true;
}
}

//Fim da Função Máscaras Gerais

//exemplo da Função Máscaras Gerais


      /*  <label>CEP:</label><br />
            <input type="text" name="str_cep" maxlength="10" size="10" onkeypress="return txtBoxFormat(this.form, this.name, '99.999-999', event);" onKeyUp="return autoTab(this, 10, event);" /><br />
        <label>CPF:</label><br />
            <input type="text" name="str_cpf" maxlength="14" size="14" onkeypress="return txtBoxFormat(this.form, this.name, '999.999.999-99', event);" onKeyUp="return autoTab(this, 14, event);"><br />
        <label>CNPJ:</label><br />
            <input type="text" name="str_cnpj" maxlength="18" size="18" onkeypress="return txtBoxFormat(this.form, this.name, '99.999.999/9999-99', event);" onKeyUp="return autoTab(this, 18, event);"><br />
        <label>Data:</label><br />
            <input type="text" name="str_data" maxlength="10" size="10" onkeypress="return txtBoxFormat(this.form, this.name, '99/99/9999', event);" onKeyUp="return autoTab(this, 10, event);"><br />
        <label>Telefone Residencial:</label><br />
            <input type="text" name="str_tel2" maxlength="13" size="13" onkeypress="return txtBoxFormat(this.form, this.name, '(99) 999-9999', event);" onKeyUp="return autoTab(this, 13, event);"><br />
        <label>Telefone Celular:</label><br />
            <input type="text" name="str_tel" maxlength="14" size="14" onkeypress="return txtBoxFormat(this.form, this.name, '(99) 9999-9999', event);" onKeyUp="return autoTab(this, 14, event);"><br />
        <label>Conta Corrente:</label><br />
            <input type="text" name="str_cc" maxlength="6" size="10" onkeypress="return txtBoxFormat(this.form, this.name, '9999-!', event);" onKeyUp="return autoTab(this, 10, event);"><br />
			*/
			
function voltar(pagina)
{
	
	window.location.href=pagina; 
	
}

 function validaEmail(email_recebido) {
      email = email_recebido;
	
      if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))) {
          alert("Email invalido");
		  return false;
      } else {
          return true;
      }
  }
  
  
function bloquear_letras(e) {
if(window.event) {
  // for IE, e.keyCode or window.event.keyCode can be used
  key = e.keyCode;
}
else if(e.which) {
  // netscape
  key = e.which;
}
if (key!=8 || key < 48 || key > 57) return (((key > 47) && (key < 58)) || (key==8) || (key==45));
{
      return true;
    }
}

function numero_valido( valor, aceitaZero, aceitaMenorZero ) {
	if ( typeof(aceitaZero) == 'undefined' )
		aceitaZero = 0;

	if ( typeof(aceitaMenorZero) == 'undefined' )
		aceitaMenorZero = 0;

	var re = /^-?(\d+)$/;
	var matchArray = re.exec(valor);

	if ( matchArray ) {
		if ( !aceitaZero && parseInt(valor) == 0 )
			return false;
		else {
			if ( !aceitaMenorZero && parseInt(valor) < 0 )
				return false;
			else
				return true;
		}
	} else
		return false;
}


	
function validaData(strData)
{

	//Separa data e guarda na matriz mData
	mData = strData.split("/");
	strDia = mData[0]; //Dia
	strMes = mData[1]; //Mes
	strAno = mData[2]; //Ano   

	//vamos tentar gerar a data, se a data gerada for diferente, a data é inválida, por exemplo,
	//se passar dia 31/04/2009 o javascript vair gerar 01/05/2009 pois abril não tem 31 dias,
	//neste caso o mês e o dia serão diferentes da data informada, o que indicará que a data não está válida.
	strDiaG = mData[0];
	strMesG = mData[1]-1;
	strAnoG = mData[2];


	//Cria a data
	datData = new Date(strAnoG, strMesG, strDiaG, 23, 59, 59);
	
	if (strAno < 1900)
	{
		return false;
	}
	

	//Se o dia/mês da data setada for diferente do dia/mes da data informada, a data está inválida.
	if( (datData.getDate() != strDia) || (datData.getMonth() + 1 != strMes) ) 
	{
		return false;
	}
	return true;
}
/*  MASCARA DATAS*/
function mascara(data){ 
              var mdata = ''; 
              mdata = mdata + data; 
              if (mdata.length == 2){ 
                  mdata = mdata + '/'; 
                  document.forms[0].data.value = mdata; 
              } 
              if (mdata.length == 5){ 
                  mdata = mdata + '/'; 
                  document.forms[0].data.value = mdata; 
              } 
              if (mdata.length == 10){ 
                  return true;
              } 
          } 
		  
/**********************************/  /*  enviar dados por post */		  
  function post(URL, PARAMS) {
	var temp=document.createElement("form");
	temp.action=URL;
	temp.method="POST";
	temp.style.display="none";
	for(var x in PARAMS) {
		var opt=document.createElement("textarea");
		opt.name=x;
		
		opt.value=PARAMS[x];
		temp.appendChild(opt);
	}
	document.body.appendChild(temp);
	temp.submit();
	return temp;
}



function valida_checkbox(objeto,Nome )
{
   selecionado = "";
	cont = 0;	
	
	if(objeto.length!=undefined)
	{
		while (cont < objeto.length)
		{
			if (objeto[cont].checked)
			{	
				if (selecionado == ''){
					selecionado+= objeto[cont].value;												
				}else{
					selecionado+= ',' + objeto[cont].value;								
				}
			}
			cont++;
		}
	}
	else 
	{
		if(objeto.checked)
		{
			if (selecionado == ''){
				selecionado+= objeto.value;
			}else{
				selecionado+= ',' + objeto.value;
			}
		}
	}
	
	if(selecionado=='')
	{		
		alert('Selecione pelo menos 1 ' + Nome + '!')
		return false;
	}	
}

function voltar_historico()
{
  history.back();
	
}