// JavaScript Document
function AlteraTipo(valor){
	if((valor == 'N')||(valor == 'M')){
		var sprytextfield1 = null;
		var sprytextfield3 = null;
		sprytextfield1 = new Spry.Widget.ValidationTextField("spryNotaMin", "integer", {minValue:0, maxValue:10});
		sprytextfield3 = new Spry.Widget.ValidationTextField("spryNMax", "integer", {minValue:0, maxValue:10});
		document.getElementById('Notas').style.display = 'table';
	}else{
		if((valor == 'D')||(valor == 'A')){
			var sprytextfield1 = null;
		    var sprytextfield3 = null;
			sprytextfield1 = new Spry.Widget.ValidationTextField("spryNotaMin", "integer", {minValue:0, maxValue:10, isRequired:false});
			sprytextfield3 = new Spry.Widget.ValidationTextField("spryNMax", "integer", {minValue:0, maxValue:10, isRequired:false});	
			document.getElementById('NMin').value = 0;
			document.getElementById('NMax').value = 0;
			document.getElementById('Notas').style.display = 'none';
		}
	}
}

function TipoPergunta(valor_temp){
	
	valor1 = valor_temp.split('_');
	valor = valor1[1];
	//alert(valor);
	
	if((valor == 'N')||(valor == 'M')){
		var sprytextfield1 = new Spry.Widget.ValidationTextField("spryQtde", "integer",{isRequired:false});
		//document.getElementById('QtdeQuestoes').value = 0;
		document.getElementById('QtdeQuestoes').disabled = true;
	}else{
		if((valor == 'D')||(valor == 'A')){
			var sprytextfield1 = new Spry.Widget.ValidationTextField("spryQtde", "integer");
			document.getElementById('QtdeQuestoes').disabled = false;	
		}
	}
}



function AlteraStatus(valor){
	if(valor == 'A'){
		document.getElementById('LinAgenda').style.display = 'table';
		document.getElementById('LinTrad').style.display = 'none';
		var sprytextfield1 = new Spry.Widget.ValidationTextField("spryDataInicioAgenda", "date", {format:"dd/mm/yyyy"});
		var sprytextfield10 = new Spry.Widget.ValidationTextField("DataFinalAgenda", "date", {format:"dd/mm/yyyy"});
		var sprytextfield11 = new Spry.Widget.ValidationTextField("spryAgHoraInicio", "time");
		var sprytextfield12 = new Spry.Widget.ValidationTextField("spryAgHoraFinal", "time");
		var sprytextfield13 = new Spry.Widget.ValidationTextField("spryAgIntervalo", "time");
		
		var sprytextfield5 = new Spry.Widget.ValidationTextField("spryDataProva", "date", {format:"dd/mm/yyyy", isRequired:false});
		var sprytextfield7 = new Spry.Widget.ValidationTextField("spryHora", "time", {isRequired:false});
		var sprytextfield8 = new Spry.Widget.ValidationTextField("spryVencimentoLimite", "date", {format:"dd/mm/yyyy", isRequired:false});
		
	}else{
		document.getElementById('LinTrad').style.display = 'table';
		document.getElementById('LinAgenda').style.display = 'none';
		var sprytextfield1 = new Spry.Widget.ValidationTextField("spryDataInicioAgenda", "date", {format:"dd/mm/yyyy", isRequired:false});
		var sprytextfield10 = new Spry.Widget.ValidationTextField("DataFinalAgenda", "date", {format:"dd/mm/yyyy", isRequired:false});
		var sprytextfield11 = new Spry.Widget.ValidationTextField("spryAgHoraInicio", "time", {isRequired:false});
		var sprytextfield12 = new Spry.Widget.ValidationTextField("spryAgHoraFinal", "time", {isRequired:false});
		var sprytextfield13 = new Spry.Widget.ValidationTextField("spryAgIntervalo", "time", {isRequired:false});
		
		var sprytextfield5 = new Spry.Widget.ValidationTextField("spryDataProva", "date", {format:"dd/mm/yyyy"});
		var sprytextfield7 = new Spry.Widget.ValidationTextField("spryHora", "time");
		var sprytextfield8 = new Spry.Widget.ValidationTextField("spryVencimentoLimite", "date", {format:"dd/mm/yyyy"});
		
	}
}



function SelecionarTudo(Contener,obj,Name,Status){
	var Comp = document.getElementById(Contener).getElementsByTagName(obj);
	var i;
	for(i = 0; i < Comp.length; i++) {
		identificacao = Comp[i].id;
		ident = identificacao.split('_');
		if(ident[0] == Name){
			inputs = document.getElementById(Comp[i].id).getElementsByTagName('input');
			//alert(inputs[0].id);
			inputs[0].checked = Status;
		}
	}
}

function AbreFechaMenu(obj){
	var item_menu = document.getElementById("leftmenu").getElementsByTagName("div");
	var i;
	var PortalExists = false;
	for(i = 0; i < item_menu.length; i++) {
		identificacao = item_menu[i].id;
		if(identificacao == 'elements_Portal'){
			PortalExists = true;
		}
		IdNew = identificacao.split('_');
		//alert(identificacao + " --> "+ IdNew);
		if(IdNew[0] == 'elements'){
			item_menu[i].className = 'ElementClose';
		}
	}
		
	for(i = 0; i < item_menu.length; i++) {
		identificacao = item_menu[i].id;
		IdNew = identificacao.split('_');
		//alert(IdNew[1] + " --> "+ obj);
		if(IdNew[1] == obj){
			item_menu[i].className = 'ElementOpen';
			 AlteraCorMenu(obj);
			break;
		}
	}
	if(PortalExists == true){
		document.getElementById('elements_Portal').className = 'ElementOpen';
	}
}
function AbreFechaDiv(content,obj){
	var item_menu = document.getElementById(content).getElementsByTagName("div");
	var i;
	for(i = 0; i < item_menu.length; i++) {
		identificacao = item_menu[i].id;
		IdNew = identificacao.split('_');
		//alert(identificacao + " --> "+ IdNew);
		if(IdNew[0] == 'content'){
			item_menu[i].className = 'ElementClose';
		}
	}	
	for(i = 0; i < item_menu.length; i++) {
		identificacao = item_menu[i].id;
		IdNew = identificacao.split('_');
		if(IdNew[1] == obj){
			item_menu[i].className = 'ElementOpen';
			break;
		}
	}
}

function MostraDiv(div,value){
document.getElementById(div).className = 'ElementClose';
if(value=='S'){
	document.getElementById(div).className = 'ElementOpen';
}
}
function Tipo(campo){
	var id = document.getElementById('SelTipo').value;
	document.getElementById('URL').className = 'ElementClose';
	document.getElementById('Texto').className = 'ElementClose';
	if(id == 'U'){
		txtid = 'URL';
	}else{
		txtid = 'Texto';
	}
	document.getElementById(txtid).className = 'ElementOpen';
	
}

function AlteraCorMenu(obj){
	var item_menu = document.getElementById("leftmenu").getElementsByTagName("div");
	var i;
	for(i = 0; i < item_menu.length; i++) {
		var Classe = item_menu[i].className;
		ClassCurrent = Classe.substr(4,Classe.length);
		ClassNew = ClassCurrent.split('_');
		if(item_menu[i].id == obj){
			if(ClassNew.length==1){
				item_menu[i].className = "btn "+ClassNew[0]+'_Hover';
			}else{
				item_menu[i].className = "btn "+ClassNew[0];
			}
		}else{
			//alert(item_menu[i].className.substr(0,3));
			if((item_menu[i].id != obj)&&(item_menu[i].className.substr(0,3)=='btn')){
				item_menu[i].className = "btn "+ClassNew[0];
			}
		}
	}
}
function heightDiv(div){
	return document.getElementById(div).offsetHeight;
}
function widthDiv(div){
	return document.getElementById(div).offsetWidth;
}
function antiCacheRand(aurl){
    //Adiciona um parametro randomico a querystring. By Micox (micoxjcgATyahooPONTOcomPONTObr).
    var dt = new Date();
    if(aurl.indexOf("?")>=0){// ja tem parametros
        return aurl + "&" + encodeURI(Math.random() + "_" + dt.getTime());
    }else{ return aurl + "?" + encodeURI(Math.random() + "_" + dt.getTime());}
}

function extraiScript(texto){
//Criada por: SkyWalker.
    var ini = 0;
    while (ini!=-1){
        ini = texto.indexOf('<script', ini);
        if (ini >=0){
            ini = texto.indexOf('>', ini) + 1;
            var fim = texto.indexOf('<'+'/script>', ini);
            codigo = texto.substring(ini,fim);
            /**********************
            * Alterado por Micox - micoxjcg@yahoo.com.br
            * Alterei pois com o eval nao executava funcoes.
            ***********************/
            novo = document.createElement("script")
            novo.text = codigo;
			//alert(codigo);
            document.body.appendChild(novo);
        }
    }
}


var xmlhttp = getXmlHttpRequest();
	
function getXmlHttpRequest() {
	if (window.XMLHttpRequest) {
			return new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			return new ActiveXObject("Microsoft.XMLHTTP");
	}
}

function alteraURL(url,div){
	url = antiCacheRand(url);
	xmlhttp.open("GET", url, true);
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState==4){
			document.getElementById(div).innerHTML = xmlhttp.responseText;
			//alert(xmlhttp.responseText);	
			extraiScript(xmlhttp.responseText);
			//alert(extraiScript(xmlhttp.responseText));
		}
	}	
	xmlhttp.send(null);
}

function alteraURLPost(url,div){
	url = antiCacheRand(url);
	alert('Post');
	xmlhttp.open("POST", url, true);
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState==4){
			document.getElementById(div).innerHTML = xmlhttp.responseText;
			//alert(xmlhttp.responseText);	
			extraiScript(xmlhttp.responseText);
			//alert(extraiScript(xmlhttp.responseText));
		}
	}	
	xmlhttp.send(null);
}

function GetUpdateFunc(divID){ 
	return function(req) { 
		//Spry.Utils.setInnerHTML(divID, req.xhRequest.responseText);
		document.getElementById(divID).innerHTML = req.xhRequest.responseText;
		extraiScript(req.xhRequest.responseText); 
	}; 
} 


function updateResponseDiv(req,local) {
	document.getElementById(local).innerHTML = req.xhRequest.responseText;
	//Spry.Utils.InnerHTML('conteudo', req.xhRequest.responseText);
	extraiScript(req.xhRequest.responseText);
}

function SendForm(form,dest) {
   var theForm = typeof form != 'object' ? document.getElementById(form): form;
   var ret = Spry.Widget.Form.validate(theForm);
   if (ret) {
      Spry.Utils.submitForm(theForm, GetUpdateFunc(dest));
   }
   return false;
};

function CarregaTurma(valor){
	  //AjaxInit();
	  try {
 		ajax = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(e){
 			try{
  				ajax = new ActiveXObject("Msxml2.XMLHTTP");
 				}catch(ex){
  					try{
   						ajax = new XMLHttpRequest();
  					}catch(exc){
   						alert("Esse browser nao tem recursos para uso do Ajax");
   						ajax = null;
  						}
 			}
		}
	  if(ajax) {
	     //deixa apenas o elemento 1 no option, os outros sao excluidos
		 document.getElementById('SelTurma').options.length = 1;
	     
		 idOpcao  = document.getElementById("opcoes");
		 
	     ajax.open("POST", "../Include/Turmas.php", true);
		 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		 
		 ajax.onreadystatechange = function() {
            if(ajax.readyState == 4 ) {
			   if(ajax.responseXML) {
			      processXML(ajax.responseXML);
			   }
            }
         }
		 //passa o codigo do estado escolhido
	     var params = "idCurso="+valor;
         //alert(params);
		 ajax.send(params);
	}

function processXML(obj){
	var dataArray   = obj.getElementsByTagName("Turma");
    if(dataArray.length > 0) {
	  for(var i = 0 ; i < dataArray.length ; i++) {
            var item = dataArray[i];
			//conteudo dos campos no arquivo XML
			var codigo    =  item.getElementsByTagName("idTurma")[0].firstChild.nodeValue;
			var descricao =  item.getElementsByTagName("descricao")[0].firstChild.nodeValue;
			
	        //alert('idTurma='+codigo);
			
			idOpcao.innerHTML = " ";
			
			//cria um novo option dinamicamente  
			var novo = document.createElement("option");
			    //atribui um ID a esse elemento
			    novo.setAttribute("id", "opcoes");
				//atribui um valor
			    novo.value = codigo;
				//atribui um texto
			    novo.text  = descricao;
				//finalmente adiciona o novo elemento
				document.getElementById('SelTurma').options.add(novo);
		 }
	  }
   }
 }

function CarregaProfessor(Curso,Turma){
	  //AjaxInit();
	  try {
 		ajaxProfessor = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(e){
 			try{
  				ajaxProfessor = new ActiveXObject("Msxml2.XMLHTTP");
 				}catch(ex){
  					try{
   						ajaxProfessor = new XMLHttpRequest();
  					}catch(exc){
   						alert("Esse browser nao tem recursos para uso do Ajax");
   						ajaxProfessor = null;
  						}
 			}
		}
	  if(ajaxProfessor) {
	     //deixa apenas o elemento 1 no option, os outros sao excluidos
		 document.getElementById('SelProfessor').options.length = 1;
	     
		 idOpcao  = document.getElementById("opcoesp");
	     ajaxProfessor.open("POST", "../Include/Professores.php", true);
		 ajaxProfessor.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		 
		 ajaxProfessor.onreadystatechange = function() {
            if(ajaxProfessor.readyState == 4 ) {
			   if(ajaxProfessor.responseXML) {
			      processXMLProfessor(ajaxProfessor.responseXML);
			   }
            }
         }
		 //passa o codigo do estado escolhido
	     var params = "idCurso="+Curso+"&idTurma="+Turma;
		 //alert(params);
		 
         ajaxProfessor.send(params);
	}

function processXMLProfessor(obj){
	var dataArray   = obj.getElementsByTagName("Professor");
    if(dataArray.length > 0) {
	  for(var i = 0 ; i < dataArray.length ; i++) {
            var item = dataArray[i];
			//conteudo dos campos no arquivo XML
			var codigo    =  item.getElementsByTagName("idProfessor")[0].firstChild.nodeValue;
			var nome =  item.getElementsByTagName("NomeProfessor")[0].firstChild.nodeValue;
	        idOpcao.innerHTML = " ";
			//alert('Professor='+nome);
			//cria um novo option dinamicamente  
			var novo = document.createElement("option");
			    //atribui um ID a esse elemento
			    novo.setAttribute("id", "opcoesp");
				//atribui um valor
			    novo.value = codigo;
				//atribui um texto
			    novo.text  = nome;
				//finalmente adiciona o novo elemento
				document.getElementById('SelProfessor').options.add(novo);
		 }
	  }
   }
 }

function CarregaUsuario(Grupo){
	  //AjaxInit();
	  try {
 		ajaxUsuario = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(e){
 			try{
  				ajaxUsuario = new ActiveXObject("Msxml2.XMLHTTP");
 				}catch(ex){
  					try{
   						ajaxUsuario = new XMLHttpRequest();
  					}catch(exc){
   						alert("Esse browser nao tem recursos para uso do Ajax");
   						ajaxUsuario = null;
  						}
 			}
		}
	  if(ajaxUsuario) {
	     //deixa apenas o elemento 1 no option, os outros sao excluidos
		 document.getElementById('usuario').options.length = 1;
	     
		 idOpcao  = document.getElementById("opcoesu");
	     ajaxUsuario.open("POST", "../Include/Usuarios.php", true);
		 
		 //window.open('../Include/Usuarios.php');
		 
		 ajaxUsuario.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		 
		 ajaxUsuario.onreadystatechange = function() {
            if(ajaxUsuario.readyState == 4 ) {
			   if(ajaxUsuario.responseXML) {
			      processXMLUsuario(ajaxUsuario.responseXML);
				  Esconde();
			   }
            }
         }
		 //passa o codigo do estado escolhido
	     var params = "Grupo="+Grupo;
		 //alert(params);
         ajaxUsuario.send(params);
	}

function processXMLUsuario(obj){
	var dataArray   = obj.getElementsByTagName("Usuario");
    if(dataArray.length > 0) {
	  for(var i = 0 ; i < dataArray.length ; i++) {
            var item = dataArray[i];
			//conteudo dos campos no arquivo XML
			var codigo    =  item.getElementsByTagName("idUsuario")[0].firstChild.nodeValue;
			var nome =  item.getElementsByTagName("Nome")[0].firstChild.nodeValue;
	        idOpcao.innerHTML = " ";
			
			//cria um novo option dinamicamente  
			var novo = document.createElement("option");
			    //atribui um ID a esse elemento
			    novo.setAttribute("id", "opcoesu");
				//atribui um valor
			    novo.value = codigo;
				//atribui um texto
			    novo.text  = nome;
				//finalmente adiciona o novo elemento
				document.getElementById('usuario').options.add(novo);
		 }
	  }
   }

 }

function MostraConsulta() {
	// Define arrays de submenus
	
	var submenus = document.getElementById("Controle").getElementsByTagName("div");
	var i;
	
	// Varre o array de submenus.
	// Inverte a condicao do submenu clicado.
	// Oculta os outros submenus.
		
	for(i = 0; i < submenus.length; i++) {
		if(submenus[i].id == "Consulta") {
			if(submenus[i].style.display == "block") {
				submenus[i].style.display = "none";
				document.imgControle.src='../Vestibular/img/mais.gif';
				//document.getElementById("Msg").innerHTML ="Mostrar Notas";
				break;
			}else {
				submenus[i].style.display = "block";
				document.imgControle.src='../Vestibular/img/menos.gif';
				//document.getElementById("Msg").innerHTML ="Ocultar Notas";
			}
		}
	}
}

function MostraConsArq(Contener,TagName,idDiv,idImg) {
	// Define arrays de submenus
	
	var submenus = document.getElementById(Contener).getElementsByTagName(TagName);
	var i;
	
	// Varre o array de submenus.
	// Inverte a condicao do submenu clicado.
	// Oculta os outros submenus.
		
	for(i = 0; i < submenus.length; i++) {
		if(submenus[i].id == idDiv) {
			if(submenus[i].style.display == "block") {
				submenus[i].style.display = "none";
				document.getElementById(idImg).src='../GerenciadorArquivos/img/mais.gif';
				break;
			}else {
				submenus[i].style.display = "block";
				document.getElementById(idImg).src='../GerenciadorArquivos/img/menos.gif';
			}
		}
	}
}

function CarregaConsArq(Contener,TagName,idDiv,idImg) {
	// Define arrays de submenus
	
	var submenus = document.getElementById(Contener).getElementsByTagName(TagName);
	var i;
	
	// Varre o array de submenus.
	// Inverte a condicao do submenu clicado.
	// Oculta os outros submenus.
		
	for(i = 0; i < submenus.length; i++) {
		if(submenus[i].id == idDiv) {
				submenus[i].style.display = "block";
				document.getElementById(idImg).src='../GerenciadorArquivos/img/menos.gif';
		}
	}
}

function StatusComp(obj,status){
	document.getElementById(obj).disabled=status;
}

function startSubmit(ProcessSubmit,ContentFormSubmit,theForm){
	var ret = Spry.Widget.Form.validate(theForm);
   	  if (ret) {
	    document.getElementById('Result').innerHTML = '';
	    document.getElementById(ProcessSubmit).style.display = 'block';
        document.getElementById(ContentFormSubmit).style.visibility = 'hidden';
	    return true;
	  }else{
	    return false;
		}
}

function stopSubmit(success,ProcessSubmit,ContentFormSubmit,FileAttach,RealFileAttach,msg,DescFileAttach){
      var result = '';
	  var pagina = document.getElementById(ContentFormSubmit).innerHTML;
	  
	  
	  if (success == 1){
		 if (typeof msg == "undefined") { 
         	result = '<span class="msg">Arquivo anexado com sucesso!<\/span><br/><br/>';
		 }else{
		 		result = '<span class="msg">'+msg+'<\/span><br/><br/>';
		 }
      }else {
		  if (typeof msg == "undefined") {
         	result = '<span class="emsg">Nao foi possivil anexar o arquivo<\/span><br/><br/>';
		  }else{
			  	result = '<span class="msg">'+msg+'<\/span><br/><br/>';
		  }
      }
	  
      document.getElementById(ProcessSubmit).style.display = 'none';
      document.getElementById('Result').innerHTML = result;
	  document.getElementById('arquivo').value = '';
      document.getElementById(ContentFormSubmit).style.visibility = 'visible';
	  
	  
	  
	  
	  
	  if (success == 1){
	    if(typeof DescFileAttach != "undefined"){
	  		DescTemp = Array();
			if(document.getElementById('DescricaoAnexo').value !=''){
				DescTemp.push(document.getElementById('DescricaoAnexo').value);
			}
			DescTemp.push(DescFileAttach);
			document.getElementById('DescricaoAnexo').value = DescTemp;
	    }
	  	document.getElementById('TotalAnexo').innerHTML = document.getElementById('TotalAnexo').innerHTML +"<div style=\"margin-left:20px;\">"+ FileAttach+" - "+DescFileAttach+"</div>";
		
		ArqTemp = Array();
		if(document.getElementById('Anexo').value !=''){
			ArqTemp.push(document.getElementById('Anexo').value);
		}
		ArqTemp.push(RealFileAttach);
		document.getElementById('Anexo').value = ArqTemp;
	  }
	  
      return true;   
}

/*** 
* Descricao.: formata um campo do formulario de 
* acordo com a mascara informada... 
* Parametros: - objForm (o Objeto Form) 
* - strField (string contendo o nome 
* do textbox) 
* - sMask (mascara que define o 
* formato que o dado sera apresentado, 
* usando o algarismo "9" para 
* definir numeros e o simbolo "!" para 
* qualquer caracter... 
* - evtKeyPress (evento) 
* Uso.......: <input type="textbox" 
* name="xxx"..... 
* onkeypress="return txtBoxFormat(document.rcfDownload, 'str_cep', '99999-999', event);"> 
* Observacao: As mascaras podem ser representadas como os exemplos abaixo: 
* CEP -> 99.999-999 
* CPF -> 999.999.999-99 
* CNPJ -> 99.999.999/9999-99 
* Data -> 99/99/9999 
* Tel Resid -> (99) 999-9999 
* Tel Cel -> (99) 9999-9999 
* Processo -> 99.999999999/999-99 
* C/C -> 999999-! 
* E por ai vai... 
***/

function txtBoxFormat(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;
     }

     
	 
	 //sValue = objForm[strField].value;
	 
	 sValue = document.getElementById(strField).value;
	 
	 //alert(sValue);
	
     // Limpa todos os caracteres de formatacao que
     // ja 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) == "/"))
       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;
	 document.getElementById(strField).value = sCod;

     if (nTecla != 8) { // backspace
       if (sMask.charAt(i-1) == "9") { // apenas numeros...
         return ((nTecla > 47) && (nTecla < 58)); } // numeros de 0 a 9
       else { // qualquer caracter...
         return true;
       } }
     else {
       return true;
     }
   }
//Fim da Funcao Mascaras Gerais


function VerificaData(digData){
  alert(digData);	
  var bissexto = 0;
  var data = digData; 
  var tam = data.length;
  if (tam == 10){
    var dia = data.substr(0,2)
    var mes = data.substr(3,2)
    var ano = data.substr(6,4)
    if ((ano > 1900)||(ano < 2100)){
      switch (mes){
        case '01':
        case '03':
        case '05':
        case '07':
        case '08':
        case '10':
        case '12':
          if  (dia <= 31){
            return true;
          }
        break
        case '04':              
        case '06':
        case '09':
        case '11':
          if  (dia <= 30){
            return true;
          }
        break
        case '02':
          /* Validando ano Bissexto / fevereiro / dia */ 
          if ((ano % 4 == 0) || (ano % 100 == 0) || (ano % 400 == 0)){ 
            bissexto = 1; 
          } 
          if ((bissexto == 1) && (dia <= 29)){ 
            return true;                             
          } 
          if ((bissexto != 1) && (dia <= 28)){ 
            return true; 
          }                       
          break                                           
      }
    }
  }       
  alert("A Data "+data+" e invalida!");
  return false;
}
function PegaConteudoEditor(Org,Dest,frm,div){
	alert(Org+ ' - '+Dest);
	document.getElementById(Dest).value = 	tinyMCE.get(Org).getContent();
	alert(document.getElementById(Dest).value);
	return SendForm(frm,div);
}

function loadMask(src, mask){
	if(src.value == ''){
		var campo =mask;
		for(x = 0; x <= campo.length; x++){ 
		campo = campo.replace('#','_');
		}
		src.value = campo;
	}

}
function DateConverte(data){
	return data.substr(6,4)+data.substr(3,2)+data.substr(0,2);
}

function VerificaData(obj,d_1,d_2,op){
  var R = DateCompare(d_1,d_2,op);
  if(R == false){
    alert('Verifique as datas.');
  }
}

function LocalizaItem(Vetor,Valor){
	var Result = false
	for(x = 0; x<=Vetor.length - 1;x++){
		if(Vetor[x] == Valor){
			Result = true;
			break;
		}
	}
	return Result;
}

function formatar(src, mask,event){
  var Result = true;
  var QtdeKeys = (mask.length);
  var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
  var i = src.value.length;
  keyAllow = new Array(9,8,46,37,38,39,40,48,49,50,51,52,53,54,55,56,57);
  keyNotMask = new Array(9,8,46,37,38,39,40);
  var keyExists = LocalizaItem(keyAllow,keyCode);
  if((keyExists == true)&&(i <= QtdeKeys)){
  	var saida = mask.substring(0,1);
  	var texto = mask.substring(i);
	keyExists = LocalizaItem(keyNotMask,keyCode);
  	if((texto.substring(0,1) != saida)&&(keyExists==false)){
		return src.value += texto.substring(0,1);
  	} //fechando o if
  }else{
  	Result = false;
  }
  event.returnValue = Result;
  return Result;
}//fechando a funcao

function ShowGreyFull(caption,url){
	GB_showFullScreen(caption,url);
}

function showGrey(url,w,h){
	GB_show('',url,w,h);
}

<!--
function startUpload(){
      document.getElementById('f1_upload_process').style.display = 'table';
      document.getElementById('f1_upload_form').style.visibility = 'hidden';
      return true;
}

function stopUpload(success){
      var result = '';
	  var pagina = document.getElementById('f1_upload_form').innerHTML;
	  if (success == 1){
         result = '<span class="msg" align="center">Arquivo publicado com sucesso!<\/span><br/><br/>';
      }
      else {
         result = '<span class="emsg" align="center">Ocorreram erros durante a publicacao do arquivo!<\/span><br/><br/>';
      }
      document.getElementById('f1_upload_process').style.display = 'none';
      document.getElementById('f1_upload_form').innerHTML = pagina+result;
      document.getElementById('f1_upload_form').style.visibility = 'visible';      
      return true;   
}
function delay(millis){
    var date = new Date();
    var curDate = null;
    do { curDate = new Date(); }
    while(curDate-date < millis);

}
function hideTip() {
	var t = document.getElementById(id).style;
	t.display = "none";
}

function validarCPF(objname,form,dest){
   //var cpf = document.cadastro.cpf.value;
   var cpf = objname;
    
   var filtro = /^\d{3}.\d{3}.\d{3}-\d{2}$/i;
   if(!filtro.test(cpf)){
     window.alert("CPF incorreto. Tente novamente.");
	 return false;
   }
   
   cpf = remove(cpf, ".");
   cpf = remove(cpf, "-");
   
   if(cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" ||
	  cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" ||
	  cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" ||
	  cpf == "88888888888" || cpf == "99999999999"){
	  window.alert("CPF incorreto. Tente novamente.");
	  return false;
   }

   soma = 0;
   for(i = 0; i < 9; i++)
   	 soma += parseInt(cpf.charAt(i)) * (10 - i);
   resto = 11 - (soma % 11);
   if(resto == 10 || resto == 11)
	 resto = 0;
   if(resto != parseInt(cpf.charAt(9))){
	 window.alert("CPF incorreto. Tente novamente.");
	 return false;
   }
   soma = 0;
   for(i = 0; i < 10; i ++)
	 soma += parseInt(cpf.charAt(i)) * (11 - i);
   resto = 11 - (soma % 11);
   if(resto == 10 || resto == 11)
	 resto = 0;
   if(resto != parseInt(cpf.charAt(10))){
     window.alert("CPF inválido. Tente novamente.");
	 return false;
   }
   //return true;
   return SendForm(form,dest);
 }
 
 function remove(str, sub) {
   i = str.indexOf(sub);
   r = "";
   if (i == -1) return str;
   r += str.substring(0,i) + remove(str.substring(i + sub.length), sub);
   return r;
 }
 
 function RemoveMask(str,f){
   var cpf = str;
   var formulario = f;
   cpf = remove(cpf, ".");
   cpf = remove(cpf, "-");
   document.getElementById("hfCPF").value = cpf;
 }
 
function DelWithConf(page,msg,target){
	if (confirm(msg)==1){
		alteraURL(page,target);
  	}
}
function Confirmacao(msg){
	if(confirm(msg)==1){
		return true;
	}else{
		return false;
		}
}

function MinMax(vlMin,vlMax){
  if(vlMin >= vlMax){
  	alert('O campo valor Nota max deve ser maior que o Nota min.');
	document.getElementById('NMax').focus();
	return false;
  }else{
    return true;
  }
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


function AdicionarRemover(FormPerg,Status){
	if(Status==true){
		MM_openBrWindow('AvaliacaoInstitucional/AdicionarRemover.php?FormPerg='+FormPerg+'&Acao=A','AdicionarRemover');
	}else{
		MM_openBrWindow('AvaliacaoInstitucional/AdicionarRemover.php?FormPerg='+FormPerg+'&Acao=R','AdicionarRemover');
	}
}
function LimpaCurAvalAplForm(){
	document.getElementById('BPeriodo').style.display = 'block'; 
	document.getElementById('SelCurso').innerHTML = '';
	document.getElementById('SelAvaliacao').innerHTML = '';
	document.getElementById('SelAplicacao').innerHTML = ''; 
	document.getElementById('SelForm').innerHTML = '';
}
function LimpaAvalAplForm(){
	document.getElementById('BCurso').style.display = 'block'; 
	document.getElementById('SelAvaliacao').innerHTML = '';
	document.getElementById('SelAplicacao').innerHTML = ''; 
	document.getElementById('SelForm').innerHTML = '';
}
function LimpaAplForm(){
	document.getElementById('BAvaliacao').style.display = 'block'; 
	document.getElementById('SelAplicacao').innerHTML = ''; 
	document.getElementById('SelForm').innerHTML = '';
}
function LimpaForm(){
	document.getElementById('BAplicacao').style.display = 'block'; 
	document.getElementById('SelForm').innerHTML = '';
}

function MarcaItens(){
	//alert(document.getElementById('FormsTemp').value);
	var temp = document.getElementById('FormsTemp').value;
	var itens = temp.split('@');
	var Comp = document.getElementById('PaginaMontada').getElementsByTagName('input');
	var Valor = '';
	for(i = 0; i < Comp.length; i++){
		if((Comp[i].type == 'checkbox')&&(itens.indexOf(Comp[i].id)> -1)){
			document.getElementById(Comp[i].id).checked = true;
		}else{
			document.getElementById(Comp[i].id).checked = false;
		}
	}
}
function PegaValor(Org,Dest){
	
	alert(document.getElementById(Org).value);
	document.getElementById(Dest).value = document.getElementById(Org).value;
	alert(document.getElementById(Dest).value);
}
function Esconde(){
	document.getElementById('fundo').style.display = "none";
	document.getElementById('img').style.display = "none";
}
function Aparece(){
   	document.getElementById('fundo').style.display = "block";
  	document.getElementById('img').style.display = "block";
}