f=0;
p=0;
// variavel que servira para guardar o objeto que conterá a data durante a edição
var recebeObjetoData = new Object();
<!--
function FormataReal(nvalor){
nvalor = nvalor.replace(".","");
nvalor = nvalor.replace(",",".");
return nvalor;
}
function FormataValor(objeto,teclapres,tammax,decimais) 
{
	var tecla			= teclapres.keyCode;
	var tamanhoObjeto	= objeto.value.length;
	if ((tecla == 8) && (tamanhoObjeto == tammax))
	{
		tamanhoObjeto = tamanhoObjeto - 1 ;
	}
    if (( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) && ((tamanhoObjeto+1) <= tammax))
	{
		vr	= objeto.value;
		vr	= vr.replace( "/", "" );
		vr	= vr.replace( "/", "" );
		vr	= vr.replace( ",", "" );
		vr	= vr.replace( ".", "" );
		vr	= vr.replace( ".", "" );
		vr	= vr.replace( ".", "" );
		vr	= vr.replace( ".", "" );
		tam	= vr.length;
		if (tam < tammax && tecla != 8)
		{
			tam = vr.length + 1 ;
		}
		if ((tecla == 8) && (tam > 1))
		{
			tam = tam - 1 ;
			vr = objeto.value;
			vr = vr.replace( "/", "" );
			vr = vr.replace( "/", "" );
			vr = vr.replace( ",", "" );
			vr = vr.replace( ".", "" );
			vr = vr.replace( ".", "" );
			vr = vr.replace( ".", "" );
			vr = vr.replace( ".", "" );
		}
		if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
		{
			if (decimais > 0)
			{
				if ( (tam <= decimais) )
				{ 
					objeto.value = ("0," + vr) ;
				}
				if( (tam == (decimais + 1)) && (tecla == 8))
				{
					objeto.value = vr.substr( 0, (tam - decimais)) + ',' + vr.substr( tam - (decimais), tam ) ;	
				}
				if ( (tam > (decimais + 1)) && (tam <= (decimais + 3)) &&  ((vr.substr(0,1)) == "0"))
				{
					objeto.value = vr.substr( 1, (tam - (decimais+1))) + ',' + vr.substr( tam - (decimais), tam ) ;
				}
				if ( (tam > (decimais + 1)) && (tam <= (decimais + 3)) &&  ((vr.substr(0,1)) != "0"))
				{
				    objeto.value = vr.substr( 0, tam - decimais ) + ',' + vr.substr( tam - decimais, tam ) ; 
				}
				if ( (tam >= (decimais + 4)) && (tam <= (decimais + 6)) )
				{
			 		objeto.value = vr.substr( 0, tam - (decimais + 3) ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
				}
			 	if ( (tam >= (decimais + 7)) && (tam <= (decimais + 9)) )
				{
			 		objeto.value = vr.substr( 0, tam - (decimais + 6) ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
				}
				if ( (tam >= (decimais + 10)) && (tam <= (decimais + 12)) )
				{
			 		objeto.value = vr.substr( 0, tam - (decimais + 9) ) + '.' + vr.substr( tam - (decimais + 9), 3 ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
				}
				if ( (tam >= (decimais + 13)) && (tam <= (decimais + 15)) )
				{
			 		objeto.value = vr.substr( 0, tam - (decimais + 12) ) + '.' + vr.substr( tam - (decimais + 12), 3 ) + '.' + vr.substr( tam - (decimais + 9), 3 ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
				}
			}
			else if(decimais == 0)
			{
				if ( tam <= 3 )
				{ 
			 		objeto.value = vr ;
				}
				if ( (tam >= 4) && (tam <= 6) )
				{
					if(tecla == 8)
					{
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
					}
					objeto.value = vr.substr(0, tam - 3) + '.' + vr.substr( tam - 3, 3 ); 
				}
				if ( (tam >= 7) && (tam <= 9) )
				{
					if(tecla == 8)
					{
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
					}
					objeto.value = vr.substr( 0, tam - 6 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ); 
				}
				if ( (tam >= 10) && (tam <= 12) )
				{
			 		if(tecla == 8)
					{
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
					}
					objeto.value = vr.substr( 0, tam - 9 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ); 
				}

				if ( (tam >= 13) && (tam <= 15) )
				{
					if(tecla == 8)
					{
						objeto.value = vr.substr(0, tam);
						window.event.cancelBubble = true;
						window.event.returnValue = false;
					}
					objeto.value = vr.substr( 0, tam - 12 ) + '.' + vr.substr( tam - 12, 3 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ) ;
				}			
			}
		}
	}
	else if((window.event.keyCode != 8) && (window.event.keyCode != 9) && (window.event.keyCode != 13) && (window.event.keyCode != 35) && (window.event.keyCode != 36) && (window.event.keyCode != 46))
		{
			window.event.cancelBubble = true;
			window.event.returnValue = false;
		}
}
//-->
//------------------------------------------------ Funções de Crítica -----------------------------

function validaCGC(id){
	//Campo CGC deve estar vazio
    formulario = eval('document.FORM'+id);
    nomeCGC = 'CGC';
	valorCampoCGC = formulario[nomeCGC].value;
	limpaEspacosVariavel('valorCampoCGC');
	if(valorCampoCGC==''){
		alert('O campo CGC deve estar preenchido .');
		return false;
	}
    else{
        sim = true;
    }
            formulario.submit();
            return true;
    if (valorCampoCGC.length!=14){
		alert('O campo CGC deve estar preenchido com 14 dígitos.');
		return false;
	}
    else{
        sim = true;
    }
    if (sim){
      // verifica se e numero
      for (i=0;((i<=(valorCampoCGC.length-1))&& sim); i++){
         val = valorCampoCGC.charAt(i);
         if ((val!="9")&&(val!="0")&&(val!="1")&&(val!="2")&&(val!="3")&&(val!="4")&&(val!="5")&&(val!="6")&&(val!="7")&&(val!="8"))
            {sim = false;}
      }//Fim do For
      if (sim){
         m2 = 2;
         soma1 = 0;
         soma2 = 0;
         for (i=11;i>=0;i--){
            val = eval(valorCampoCGC.charAt(i));
            m1 = m2;
            if (m2 < 9)
               {m2 = m2+1;}
            else
               {m2 = 2;}
            soma1 = soma1 + (val * m1);
            soma2 = soma2 + (val * m2);
         }// fim do for de soma
         soma1 = soma1 % 11;
         if (soma1 < 2)
            {d1 = 0;}
         else
            {d1 = 11- soma1;}
         soma2 = (soma2 + (2 * d1)) % 11;
         if (soma2 < 2)
            {d2 = 0;}
         else
            {d2 = 11- soma2;}
         if ((d1==valorCampoCGC.charAt(12)) && (d2==valorCampoCGC.charAt(13))){
            formulario.submit();
            return true;
         }else{
       		alert('O campo CGC não representa um CGC Válido.');
            return false;
         }//Fim do else
      }else{
		alert('O campo CGC deve conter somente números.');
		return false;
      }//Fim do else
    }//Fim do If
};

function eliminaEspacos(nome){
	b='';
	c='';
	for(f=0;f<document.FORM[nome].value.length;f++){b=document.FORM[nome].value.charAt(f);if(b!=' '){c+=b};};
	document.FORM[nome].value = c;
};
function limpaEspacosVariavel(nome){
	b='';
	c='';
	for(f=0;f<window[nome].length;f++){b=window[nome].charAt(f);if(b!=' '){c+=b};};
	window[nome] = c;
};
function testeGeral(nome,label,tipo,vazio){
        //alert(nome);
	valorCampo = document.FORM[nome].value;
	limpaEspacosVariavel('valorCampo');
	//if((tipo!='memo')&& ((document.FORM[nome].value.indexOf(",")!=-1)||(document.FORM[nome].value.indexOf(";")!=-1))){
	//	alert('O campo ' + label + ' não pode conter vírgula nem ponto e vírgula.\nSubstitua por ponto(.)');
	//	return false;
	//};
	if(vazio){
		if(valorCampo==''){
			alert('O campo ' + label + ' precisa ser preenchido.');
			return false;
		};
	};
	if(tipo=='numero'){
		eliminaEspacos(nome);
		numeroVirgula = document.FORM[nome].value.replace(',','.');
		if(isNaN(numeroVirgula)){
			alert('O campo ' + label + ' é do tipo numérico.');
			return false;
		};		
	};
	//if(tipo=='numero'){
	//	eliminaEspacos(nome);
	//	for(f=0;f<document.FORM[nome].value.length;f++){
	//		if((document.FORM[nome].value.charAt(f)=='.')||(document.FORM[nome].value.charAt(f)==',')){
	//			alert('O campo ' + label + ' é do tipo numérico inteiro.');
	//			return false;
	//		};
	//	};		
	//};
	if(tipo=='data'){
		if(document.FORM[nome].value!=''){
			if(!testaData(document.FORM[nome].value)){
                if(!testaData2(document.FORM[nome].value)){
                   alert('O campo ' + label + ' não possui uma data válida. \n O formato aceito é dd/mm/aaaa.');
				   return false;
                };
			};
		};
	};
	if(tipo=='dataHora'){
		if(document.FORM[nome].value!=''){
			if(!testaDataHora(document.FORM[nome].value)){
				alert('O campo ' + label + ' não possui uma data válida. \n O formato aceito é dd/mm/aaaa hh:mm:ss.');
				return false;
			};
		};
	};
	return true;
};
//----------------------------- Script incluidos por Guilherme ------------------------

<!--
function confirm_delete(form) {
if (confirm("Tem certeza que deseja excluir?")) {
document[form].submit();
}
}

function abre_janela(width, height, nome) {
var top; var left;
top = ( (screen.height/2) - (height/2) )
left = ( (screen.width/2) - (width/2) )
window.open('',nome,'width='+width+',height='+height+',scrollbars=no,toolbar=no,location=no,status=no,menubar=no,resizable=no,left='+left+',top='+top);
}
function recebe_imagem(campo, imagem){
var foto = 'img_' + campo
document.FORM[campo].value = imagem;
document.FORM[foto].src = imagem;
}
function verifica_form(form) {
var passed = false;
var ok = false
var campo
for (i = 0; i < form.length; i++) {
  campo = form[i].name;
  if (form[i].df_verificar == "sim") {
    if (form[i].type == "text"  | form[i].type == "textarea" | form[i].type == "select-one") {
      if (form[i].value == "" | form[i].value == "http://") {
		form[campo].className='campo_alerta'
        form[campo].focus();
        alert("Preencha corretamente o campo");
        return passed;
        stop;
      }
    }
    else if (form[i].type == "radio") {
      for (x = 0; x < form[campo].length; x++) {
        ok = false;
        if (form[campo][x].checked) {
          ok = true;
          break;
        }
      }
      if (ok == false) {
        form[campo][0].focus();
		form[campo][0].select();
        alert("Informe uma das opcões");
        return passed;
        stop;
      }
    }
    var msg = ""
    if (form[campo].df_validar == "cpf") msg = checa_cpf(form[campo].value);
    if (form[campo].df_validar == "cnpj") msg = checa_cnpj(form[campo].value);
    if (form[campo].df_validar == "cpf_cnpj") {
	  msg = checa_cpf(form[campo].value);
	  if (msg != "") msg = checa_cnpj(form[campo].value);
	}
    if (form[campo].df_validar == "email") msg = checa_email(form[campo].value);
    if (form[campo].df_validar == "numerico") msg = checa_numerico(form[campo].value);
    if (msg != "") {
	  if (form[campo].df_validar == "cpf_cnpj") msg = "informe corretamente o número do CPF ou CNPJ";
	  form[campo].className='campo_alerta'
      form[campo].focus();
      form[campo].select();
      alert(msg);
      return passed;
      stop;
    }
  }
}
passed = true;
return passed;
}

function desabilita_cor(campo,classecampo) {
campo.className=classecampo
}
function checa_numerico(String) {
var mensagem = "Este campo aceita somente números"
var msg = "";
if (isNaN(String)) msg = mensagem;
return msg;
}
function checa_email(campo) {
var mensagem = "Informe corretamente o email"
var msg = "";
var email = campo.match(/(\w+)@(.+)\.(\w+)$/);
if (email == null){
  msg = mensagem;
  }
return msg;
}
function checa_cpf(CPF) {
var mensagem = "informe corretamente o número do CPF"
var msg = "";
if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
  CPF == "22222222222" ||	CPF == "33333333333" || CPF == "44444444444" ||
  CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
  CPF == "88888888888" || CPF == "99999999999")
msg = mensagem;
soma = 0;
for (y=0; y < 9; y ++)
soma += parseInt(CPF.charAt(y)) * (10 - y);
resto = 11 - (soma % 11);
if (resto == 10 || resto == 11)resto = 0;
if (resto != parseInt(CPF.charAt(9)))
  msg = mensagem; soma = 0;
for (y = 0; y < 10; y ++)
  soma += parseInt(CPF.charAt(y)) * (11 - y);
resto = 11 - (soma % 11);
if (resto == 10 || resto == 11) resto = 0;
if (resto != parseInt(CPF.charAt(10)))
  msg = mensagem;
return msg;
}
function checa_cnpj(s) {
var mensagem = "informe corretamente o número do CNPJ"
var msg = "";
var y;
var c = s.substr(0,12);
var dv = s.substr(12,2);
var d1 = 0;
for (y = 0; y < 12; y++)
{
d1 += c.charAt(11-y)*(2+(y % 8));
}
if (d1 == 0) msg = mensagem;
d1 = 11 - (d1 % 11);
if (d1 > 9) d1 = 0;
if (dv.charAt(0) != d1)msg = mensagem;
d1 *= 2;
for (y = 0; y < 12; y++)
{
d1 += c.charAt(11-y)*(2+((y+1) % 8));
}
d1 = 11 - (d1 % 11);
if (d1 > 9) d1 = 0;
if (dv.charAt(1) != d1) msg = mensagem;
return msg;
}
function mascara_data(data){ 
var mydata = ''; 
mydata = mydata + data; 
if (mydata.length == 2){ 
mydata = mydata + '/'; 
} 
if (mydata.length == 5){ 
mydata = mydata + '/'; 
} 
return mydata; 
} 
function verifica_data(data) { 
if (data.value != "") {
dia = (data.value.substring(0,2));
mes = (data.value.substring(3,5)); 
ano = (data.value.substring(6,10)); 
situacao = ""; 
if ((dia < 01)||(dia < 01 || dia > 30) && (  mes == 04 || mes == 06 || mes == 09 || mes == 11 ) || dia > 31) { 
situacao = "falsa"; 
} 
if (mes < 01 || mes > 12 ) { 
situacao = "falsa"; 
}
if (mes == 2 && ( dia < 01 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) { 
situacao = "falsa"; 
} 
if (situacao == "falsa") { 
data.focus();
data.select();
alert("Data inválida!"); 
}
} 
}
//-->

function ajuda_admin(pagina, campo){
alert(pagina+','+campo)
}
function moveModule(o_col, d_col) 
{
  o_sl = document.form_alterar[o_col].selectedIndex;
  d_sl = document.form_alterar[d_col].length;
  if (o_sl != -1 && document.form_alterar[o_col].options[o_sl].value > "") {
    oText = document.form_alterar[o_col].options[o_sl].text;
    oValue = document.form_alterar[o_col].options[o_sl].value;
    document.form_alterar[o_col].options[o_sl] = null;
    document.form_alterar[d_col].options[d_sl] = new Option (oText, oValue, false, true);
  } else {
    alert("Selecione um ítem");
  }
}  

function orderModule(down, col) 
{
  sl = document.form_alterar[col].selectedIndex;
  if (sl != -1 && document.form_alterar[col].options[sl].value > "") {
    oText = document.form_alterar[col].options[sl].text;
    oValue = document.form_alterar[col].options[sl].value;
    if (document.form_alterar[col].options[sl].value > "" && sl > 0 && down == 0) {
      document.form_alterar[col].options[sl].text = document.form_alterar[col].options[sl-1].text;
      document.form_alterar[col].options[sl].value = document.form_alterar[col].options[sl-1].value;
      document.form_alterar[col].options[sl-1].text = oText;
      document.form_alterar[col].options[sl-1].value = oValue;
      document.form_alterar[col].selectedIndex--;
    } else if (sl < document.form_alterar[col].length-1 && document.form_alterar[col].options[sl+1].value > "" && down == 1) {
      document.form_alterar[col].options[sl].text = document.form_alterar[col].options[sl+1].text;
      document.form_alterar[col].options[sl].value = document.form_alterar[col].options[sl+1].value;
      document.form_alterar[col].options[sl+1].text = oText;
      document.form_alterar[col].options[sl+1].value = oValue;
      document.form_alterar[col].selectedIndex++;
    }
  } else {
    alert("Selecione um ítem");
  }
}

function doSub()
{
  document.form_alterar.ordem.value = 0
  for (i=0; i<document.form_alterar.N0.length; i++) {
   document.form_alterar.ordem.value = document.form_alterar.ordem.value + "-" + document.form_alterar.N0.options[i].value;
  }
}

// Insere valores da origem para o destino (multi-select)
function Inserir(pForm, pFrom, pTo){
	// Obtendo referência dos objetos

	var frm 	= document.forms[pForm];

	var origem 	= frm.elements[pFrom];
	var destino = frm.elements[pTo];
	var bTeste 	= false;
	var position = -1;
	var position = 0;
	var numRepetidos=0;
	var repetidos='';

	// Deseleciona todos na listagem de destino
	for(var i = 0; i < destino.options.length; i++){
		destino.options[i].selected=false;
	}

	// Varrendo o objeto de origem
	for(var i = 0; i < origem.options.length; i++){
		//Item na origem esta selecionado
		if (origem.options[i].selected == true){

			//Verifica se ele ja existe no destino
			position = OrderedAlreadyExist(destino, origem.options[i].text);
            
			if(Len()==0)
			{
				alert("O número de itens selecionados deve ser menor que 4!");
				return;
			}
 
			if (position!=-1){
				//Inclusão de item no objeto de destino
				var option = new Option();
				option.value = origem.options[i].value;
				option.text = origem.options[i].text;
				destino.options.add(option,position);

				option.selected = true;
			}else{
				numRepetidos++;
				if(numRepetidos<12)
					repetidos+='\n'+origem.options[i].text;
				else
				if(numRepetidos==12)
					repetidos+='\n...';
			}
			bTeste = true;
		}
     }
     if(!bTeste) alert('Selecione um ítem.');

     if(numRepetidos==1)window.alert('O ítem:\n'+repetidos+'\n\n já foi incluído anteriormente.');

     if(numRepetidos>1)window.alert('Os ítens:\n'+repetidos+'\n\n já foram incluídos anteriormente.');

}

function OrderedAlreadyExist(selectDestino, valor){
	var exists = false;
	for(i=0; i<selectDestino.options.length; i++){
		if(selectDestino.options[i].text == valor){
			return -1;
		}

		if(selectDestino.options[i].text > valor){
			return i;
		}
	}

	return selectDestino.options.length;

}

// Remove valores da origem para o destino (multi-select)
function Remover(pForm,pFrom){
	// Obtendo referência dos objetos
	var frm = document.forms[pForm];
	var origem = frm.elements[pFrom];
	var bTeste 	= false;
	for (var i = origem.options.length - 1; i > -1; i--){
		if (origem.options[i].selected == true){
			origem.remove(i);
			bTeste = true;
		}
	}
	if(!bTeste) alert('Selecione um ítem.');
}


// Remove todos os valores de uma só vez da origem para o destino 
function RemoverTodos(pForm,pFrom){
	// Obtendo referência dos objetos
	var frm = document.forms[pForm];
	var origem = frm.elements[pFrom];
	for (var i = origem.options.length - 1; i > -1; i--){
		origem.remove(i);
	}
}

function Len(){
var len = 0;
len = document.forms['form_alterar'].N0.length;
    if(len >= 4)
      return 0;
    else
     return 1;
}

function ValidaForm(){
var lista=""
var len = 0;
      //Captura os valores da Lista(combo)
      for(c = 0; c < document.forms['form_alterar'].N0.length; c++) 
      {
         lista = lista + (lista== ""?document.forms['form_alterar'].N0.options[c].value : "|"+document.forms['form_alterar'].N0.options[c].value)
      }
      
      //Aqui é o campo hidden que você deve postar para página ASP. Na página ASP você vai ler esse valor(Request["tit"]),
      //separar em um Array(.Split) e colocar as respectivas ordens.
      document.forms['form_alterar'].tit.value = lista;
      alert(lista);
      
      //document.forms['form_alterar'].submit();  // Trocar o action para postar para sua página ASP
      alert('Submit');
}

function montaFlash(swf, width, height, wmode, cache)
{
noCache = cache || cache == undefined ? "" : "?" + new Date();

monta_swf = "";
monta_swf += "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\""+ width +"\" height=\""+ height +"\" title=\"\">";
monta_swf += "<param name=\"movie\" value=\""+ swf + noCache +"\" />";
monta_swf += "<param name=\"allowScriptAccess\" value=\"always\" />";
monta_swf += "<param name=\"quality\" value=\"high\" />";
monta_swf += "<param name=\"menu\" value=\"false\" />";
monta_swf += "<param name=\"wmode\" value=\"" + wmode + "\" />";
monta_swf += "<embed src=\""+ swf + noCache +"\" allowScriptAccess=\"always\" quality=\"high\" wmode=\""+ wmode +"\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""+ width +"\" height=\""+ height +"\" swLiveConnect=\"true\"></embed>";
monta_swf += "</object>";

document.write(monta_swf);
}


//----------------------------- Testa Data ------------------------
function converteData(data){
	data = data.split(' ');
	data2 = data[0].split('/');
	var data3 = new Date(data2[2],data2[1],data2[0]);
	return data3
}
function testeDataMaior(data1,data2){
	data1 = converteData(data1);
	data2 = converteData(data2);
	if(data2.getTime()<data1.getTime()){
		alert('Data Inicial Maior de a Data Final!');
		return false;
	} else {
		return true;
	};
};
function testaData(recebeData){
	recebeData = recebeData.split('/');
	if(recebeData.length!=3){
		return false;
	};
	var arrayMeses = new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
	testaAnoBicesto = recebeData[2] /4 + ' ';
	if(testaAnoBicesto.indexOf('.')==-1){
		arrayMeses[2]=29;
	};
	if((recebeData[0]>arrayMeses[recebeData[1] - 0])||(recebeData[1]>12)){
		return false;
	};
	return true;
};
function testaData2(recebeData){
	recebeData = recebeData.split('-');
	if(recebeData.length!=3){
		return false;
	};
	var arrayMeses = new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
	testaAnoBicesto = recebeData[2] /4 + ' ';
	if(testaAnoBicesto.indexOf('.')==-1){
		arrayMeses[2]=29;
	};
	if((recebeData[0]>arrayMeses[recebeData[1] - 0])||(recebeData[1]>12)){
		return false;
	};
	return true;
};

function testaDataHora(recebeData){

	dataHora = recebeData.split(' ');
	if(dataHora.length<2){return false};
	if(!testaData(dataHora[0])) {return false};
	Hora = dataHora[1].split(':');
	horario = new Array(24,59,59);
	if(Hora.length<2){return false};
	for(f=0;f<horario.length;f++){
		if(Hora[f]>horario[f]){return false};
	};
	if((Hora[0]==24)&&(Hora[1]>0)){return false};
	return true;
};
// --------------------------- Funções para Layers ---------------------------
function moveLayer(strLayer,valorX,valorY) {
	if (document.layers) {
    		document.layers[strLayer].top = valorY;
    		document.layers[strLayer].left = valorX;
	} else {
    		document.all[strLayer].style.top = valorY;
    		document.all[strLayer].style.left = valorX;
	};
};

function exibeLayer(strLayer) {
	if (document.layers) {
    		document.layers[strLayer].visibility = 'show'; 
	} else {
    		document.all[strLayer].style.visibility = 'visible';
	};
};

function escondeLayer(strLayer) {
	if (document.layers){
    		document.layers[strLayer].visibility = 'hide';
	} else {
    		document.all[strLayer].style.visibility = 'hidden';
	};
};
// ---------------------------------- scripts de estilo ------------------------------------------

// trocam o estilo da tag quando no mouseOver

function EstOn(a){
	a.className = "textosCandidatosOver";
	if(typeof(f)=='object'){
		f.className = "textosCandidatosDestaque";
	};
};
function EstOff(a){
	a.className = "textosCandidatos";
	if(typeof(f)=='object'){
		f.className = "textosCandidatosDestaque";
	};
};
function numerico(){
	g = event.keyCode;
	if(((((g<48)||(g>57))&&((g<96)||(g>105)))&&(g!=8)||(event.shiftKey)||(event.shiftLeft)||(event.altLeft))&&(g!=37)&&(g!=39)&&(g!=9)&&(g!=46)){
		event.keyCode = 0;
		event.returnValue = false;
	};
};
//------------------------------------ script's para o menu  -------------------------------------
//  nenhuma layer nesta página pode ter um nome começado por 'L'
var Ybasico = 17; //altura de todas as células das layers
var Xbasico = 127; //largura de todas as layers
var aLayersInvisiveis = new Array(); //Array de layers invisíveis
var layerCod = 0 // Variável que guarda o valor da Layer do sub-menu que está sendo executada exibida para poder ser apagada
function fExibeLayer(strLayer) {
	retornaValorX(strLayer)
	if (document.layers) {
    		document.layers[strLayer].visibility = 'show'; 
	} else {
    		document.all[strLayer].style.visibility = 'visible';
	};
};
function fEscondeLayer(strLayer) {
	if (document.layers){
    		document.layers[strLayer].visibility = 'hide';
	} else {
    		document.all[strLayer].style.visibility = 'hidden';
	};
};
function fMoveLayer(strLayer,valorX,valorY) {
	if (document.layers) {
    		document.layers[strLayer].top = valorY;
			document.layers[strLayer].left = valorX;
	} else {
    		document.all[strLayer].style.top = valorY;
			document.all[strLayer].style.left = valorX;
	};
};
function fMenu(e){
	if(document.layers){
		if (e.target.name.charAt(0)=='L'){
			fExibeMenu(e.target.name);
		};
	} else {
		fExibeMenu(e.id);
	};
};
function removeL(a){
	a = a.substring(0,a.lastIndexOf('L'));
	a = a.substring(0,a.lastIndexOf('L')+1);
	return a
}
if(document.layers){
	window.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT)
	window.onmouseover = fMenu;
	window.onmouseout = fEscondeMenu;
}
function verificaLayer(nLayer){
	if(document.layers){
		if(typeof(document.layers[nLayer])=='undefined'){
			return false;
		} else {
			return true;
		};
	} else {
		if(typeof(window[nLayer])=='undefined'){
			return false;
		} else {
			return true;
		};
	};
};
function retornaX(LAYER){
	if(document.layers){
		valor = document.layers[LAYER].pageX;
	} else {
		valor = removePxValor(document.all[LAYER].style.left);
	};
	return valor;
};
function retornaY(LAYER){
	if(document.layers){
		valor = document.layers[LAYER].pageY;
	} else {
		valor = removePxValor(document.all[LAYER].style.top);
	};

	return valor;
};
function removePxValor(valor){
	if(valor.indexOf('px')!=-1){
		return valor.substring(0,valor.length-2);
	};
	return valor;
};
function retornaValorY(nome){
	nome2 = nome.split('L');
	valor = retornaY('L' + nome2[1]);
	for(f=2;f<nome2.length;f++){
		valor = valor - 0 + Ybasico - 0;
	};
	return valor;
};
function retornaValorX(nome){
	//alert(nome);
	nome2 = nome.split('L');
	valor = retornaX('L' + nome2[1]);
	//for(f=2;f<nome2.length;f++){
	//	valor = valor - 0 + (Xbasico * (nome2[f] - 1));
	//};
	return valor;
};
function fEscondeMenu(e){
	if(document.layers){
		if (e.target.name.charAt(0)=='L'){
			for(f=0;f<aLayersInvisiveis.length;f++){
				fEscondeLayer(aLayersInvisiveis[f]);
			};
		};
	} else {
		for(f=0;f<aLayersInvisiveis.length;f++){
			fEscondeLayer(aLayersInvisiveis[f]);
		};
	};
	aLayersInvisiveis = '';
}

function fExibeMenu(nome){
	nome += 'L';
	aLayersInvisiveis = new Array();
	while(nome.length>2){
		layerCod = 1;
		while(verificaLayer(nome + layerCod)){
			fMoveLayer((nome + layerCod),retornaValorX(nome + layerCod),retornaValorY(nome + layerCod));
			fExibeLayer(nome + layerCod);
			aLayersInvisiveis[aLayersInvisiveis.length] = nome + layerCod;
			layerCod ++;
		};
		nome = removeL(nome);
	};
}
//--------------------------------------------- Funções Quarentena -------------------------------------
function janelaManutencao(a,b){
	
	url = "QRDProdS.php?IDCliente=" + a + "&Produto=" + b;
	window.open(url,"JANELA","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=770,height=500,left=20,top=20")

}
function janelaQuarentena(a,c,b){
	
	url = "QRDProdSErr.php?IDCliente=" + a + "&Produto=" + b + "&codigoproduto=" + c;
	window.open(url,"JANELA","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=770,height=500,left=20,top=20")

}
//----------------------------------------------- Funções para combos -----------------------------------
function apagaCombo(OBJ){
	tamanho = OBJ.length;
	for(gf=0;gf<tamanho;gf++){
		OBJ[0] = null;
	}
}
function insereValoresCombo(OBJ,a,b){
	var NovaOpcao = new Option('value','text');
	NovaOpcao.value = a;
	NovaOpcao.text = b;
	OBJ[OBJ.length] = NovaOpcao;
}
//-------------------------------------------------- funções de alteração de campos para a manutenção -----------------------

//------------------------ Funcao de Edicao de Inputs -----------------------------
// V 1.1
var matrizFormType = new Array();	// guarda todos os tipos dos objetos do Form 
var matrizFormName = new Array();	// guarda todos os nomes dos objetos do Form 
var matrizFormHidden = new Array();	// guarda todos os camos hidden em seus tamanhos
var tamanhoForm = 0  //guarda o tamanho do Form
var tamanhoLink = 0  //guarda o tamanho do link
var tamanhoHidden = 0  //guarda o tamanho do hidden
var tamanhoPassword = 0	//guarda o tamanho do password
var correcaoColuna = 0	//guarda a correção da coluna quando não há um campo correspndente

function limpaForm(){
	// reseta o form, desinibe os campos travados, esconde as layers transparentes dos campos.
	document.FORM.reset();
	for(f=0;f<tamanhoForm;f++){
		if(matrizFormName[f].charAt(0)=='K'){
			document.FORM[matrizFormName[f]].onfocus = null;	//	desinibe os campos desativando a função inibidora dos campos chave no evento onFocus
			document.FORM[matrizFormName[f]].className = "textoTabela";
			//escondeLayer('L' + matrizFormName[f].substring(1,matrizFormName[f].length));
		};
	};
	document.FORM.action = document.FORM.action.replace('?edit=1','');
};
function inibidora(){
	//	inibe o campo chave do sistema quando o registro estiver sendo editado
	//	para informar que um campo é chave é necessário que seu nome seja inicializado por 'K'
	//	alert('chegou');
	this.blur();
}
function inicializacao(){
	// identifica o número dos objetos do Form colocando-os em seus arrays e eliminando os radio
	for(f=0;f<document.FORM.length;f++){
		if(f!=0){
			if(document.FORM[f].name!= document.FORM[f-1].name){
				(document.FORM[f].type=='select-one')?(matrizFormType[tamanhoForm]='select'):(matrizFormType[tamanhoForm] = document.FORM[f].type);
				matrizFormName[tamanhoForm] = document.FORM[f].name;
				tamanhoForm ++;
			};
		} else {
			(document.FORM[f].type=='select-one')?(matrizFormType[tamanhoForm]='select'):(matrizFormType[tamanhoForm] = document.FORM[f].type);
			matrizFormName[tamanhoForm] = document.FORM[f].name;
			tamanhoForm ++;
		};
	};
	for(f=0;f<tamanhoForm;f++){
		if(matrizFormType[f]!='hidden'){
			tamanhoLink++;
		} else {
			matrizFormHidden[f] = tamanhoHidden;
			tamanhoHidden++;
		};
		if((matrizFormType[f]=='password')||(matrizFormType[f]=='file')){
			tamanhoPassword++;
		};
	};
};

// encontra os valores nos links
function recolheValoresLink(numero){
	if(document.layers){
		return document.links[numero - correcaoColuna -  tamanhoPassword * ( linhaClicada - 1 )].text;
	} else {
		//alert('numero = ' + numero);
		//alert('linha clicada = ' + (correcaoColuna + tamanhoPassword * ( linhaClicada - 1 )));
		//alert('correcaoColuna = ' + correcaoColuna + ' tamanhoPassword = ' + tamanhoPassword + ' linhaClicada = ' + linhaClicada);
		//alert(numero - correcaoColuna - tamanhoPassword * ( linhaClicada - 1 ));
		eval('valorResultante=document.all.a' + (numero - correcaoColuna - tamanhoPassword * ( linhaClicada - 1 )) + '.innerText');
		return valorResultante;
	};
};

function rDados(numero){

	document.FORM.action = document.FORM.action + "?edit=1";
	linhaClicada = numero;
	valorLink = (numero - 1) * tamanhoLink;	
	for(f=0;f<tamanhoForm;f++){
		eval('F' + matrizFormType[f] + '(valorLink)'); 										// desvia a execução para a função correspondente com o typo do campo
		if(matrizFormName[f].charAt(0)=='K'){ 												//  verifica se o campo é chave e desvia para funções apropriadas
			document.FORM[matrizFormName[f]].onfocus = inibidora;  							// trava o campo para edição
			document.FORM[matrizFormName[f]].className = "caixasChave";
			//exibeLayer('L' + matrizFormName[f].substring(1,matrizFormName[f].length));  	// mostra a layer transparente sobre o campo chave na edição
		};
	};
	correcaoColuna = 0;
};
function Ftext(valor){	//	coloca o valor do link correspondente no campo texto
	document.FORM[matrizFormName[f]].value = recolheValoresLink(valor + f);
};
function Ftextarea(valor){	//	coloca o valor do link correspondente no campo texto
	document.FORM[matrizFormName[f]].value = recolheValoresLink(valor + f);
};
function Fcheckbox(valor){  //  marca o desmarca o checkbox caso o seu valor seja igual ao do link correspondente
	(document.FORM[matrizFormName[f]].value==recolheValoresLink(valor + f))?(document.FORM[matrizFormName[f]].checked = true):(document.FORM[matrizFormName[f]].checked = false);
};
function Fselect(valor){	//	seleciona o valor que seja igual ao do link no select, verificando o texto e depois o value
	tTeste=true;
	for(g=0;g<document.FORM[matrizFormName[f]].length;g++){
		if(document.FORM[matrizFormName[f]][g].text==recolheValoresLink(valor + f)){
			document.FORM[matrizFormName[f]][g].selected = true;
			tTeste = false;
		} else {
			document.FORM[matrizFormName[f]][g].selected = false
		};
	};
	if(tTeste){
		for(g=0;g<document.FORM[matrizFormName[f]].length;g++){
			(document.FORM[matrizFormName[f]][g].value==recolheValoresLink(valor + f))?(document.FORM[matrizFormName[f]][g].selected = true):(document.FORM[matrizFormName[f]][g].selected = false);
		};
	};
};
function Fradio(valor){  //	seta o campo que possuir o mesmo value do select, caso nenhum exista desmarca todos
	for(g=0;g<document.FORM[matrizFormName[f]].length;g++){
		(document.FORM[matrizFormName[f]][g].value==recolheValoresLink(valor + f))?(document.FORM[matrizFormName[f]][g].checked = true):(document.FORM[matrizFormName[f]][g].checked = false);
	};
};
function Fhidden(valor){	//	procura e iguala os campos hidden do for com os do frame de dados
	posicaoHidden = (valor/tamanhoLink)*tamanhoHidden + matrizFormHidden[f] + (valor/tamanhoLink); // descobre a posição do campo hidden a der copiado para o form
	document.FORM[matrizFormName[f]].value = document.deletar[posicaoHidden].value;
};
function Fpassword(valor){  //	apaga o valor que existir dentro do campo pois nos campos de leitura não haverão valores para preenche-los
	document.FORM[matrizFormName[f]].value = '';
	correcaoColuna = 1;	//	faz com que o número de localização da coluna da tabela seja subtraída de um, pois não há coluna para o campo
};
function Ffile(valor){  //	apaga o valor que existir dentro do campo pois nos campos de leitura não haverão valores para preenche-los
	document.FORM[matrizFormName[f]].value = '';
	correcaoColuna = 1;	//	faz com que o número de localização da coluna da tabela seja subtraída de um, pois não há coluna para o campo
};

