function select_deselectAll (chkVal, idVal,ControlName,ControlChildren) 
{
	if(ControlName=="" || ControlName==undefined) ControlName = "CheckAll";
	if(ControlChildren=="" || ControlChildren==undefined) ControlChildren="cbAdd";
	var frm = document.forms[0];
	var idxCheckAll; // Indice do CheckBox que seleciona todos
	var blnCheckAll;

	//loop para obter o índice do CheckBox que seleciona todos
	for (i=0; i<frm.length; i++) 
	{
		if (frm.elements[i].id.indexOf(ControlName) != -1) {
			idxCheckAll=i;
			blnCheckAll=frm.elements[i].checked; 
		}
	}
	// loop through all elements
	for (i=0; i<frm.length; i++) 
	{
		// Look for our Header Template's Checkbox
		if ((idVal.indexOf(ControlName) != -1) && (frm.elements[i].id.indexOf(ControlChildren) != -1) )
		{
			frm.elements[i].checked = chkVal;
		} 
		else
		{
			if (chkVal==false) 
			{
				blnCheckAll=false
			}
		}
	}
	// Check if any of the checkboxes are not checked, and then uncheck top select all checkbox\n" 
	frm.elements[idxCheckAll].checked = blnCheckAll; 
}

//Anderson Ikuo Nakamoto
//pobj_Field = nome do campo
//plng_Integer = Parte inteira do número
//plng_Decimal = Parte decimal do número
//pstr_Decimal = separador decimal [default = ,]
//Usar no evento onkeypress
function onlyNumeric(pobj_Field,plng_Integer,plng_Decimal,pstr_Decimal) {
  try {
    this.bln_Verify = true;
    this.bln_IsDecimal = (plng_Decimal != null) ? (plng_Decimal > 0) ? true : false : false;
    this.str_Decimal = (pstr_Decimal != null) ? pstr_Decimal : "," ;
    if (this.bln_Verify) {
      if (event.keyCode >= 48 && event.keyCode <= 57) {
        this.bln_Verify = false;
      }
    }
    if (this.bln_IsDecimal) {
      if (event.keyCode == this.str_Decimal.charCodeAt()) {
        if (pobj_Field.getAttribute("value").indexOf(this.str_Decimal) == -1) {
          this.bln_Verify = false;
        }
      }
    }
    if (this.bln_Verify) {
      event.cancelBubble = true;
      event.returnValue = false;
    }
  }
  catch(obj_Exception) {
    //alert('erro');
    //exception(obj_Exception,"General[onlyNumeric]");
    alert(obj_Exception);
  }
  finally {
    this.bln_Verify = null;
    this.bln_IsDecimal = null;
    this.str_Decimal = null;
    this.bln_Verify = null;
  }
}

//Anderson Ikuo Nakamoto
//pobj_Field = nome do campo
//plng_Integer = Parte inteira do número
//plng_Decimal = Parte decimal do número
//pstr_Decimal = separador decimal [default = ,]
//Usar no evento onblur
function maskNumeric(pobj_Field,plng_Integer,plng_Decimal,pstr_Decimal) {
  try {
    this.bln_IsDecimal = (plng_Decimal != null) ? (plng_Decimal > 0) ? true : false : false;
    this.str_Decimal = (pstr_Decimal != null) ? pstr_Decimal : "," ;
    this.str_AcceptChr = "0123456789" + this.str_Decimal;
    this.str_FieldValue = "";
    this.str_NewValue = "";
    if (pobj_Field.getAttribute("value") != "") {
      for (var int_C = 0; int_C < pobj_Field.getAttribute("value").length; int_C++) {
        if (this.str_AcceptChr.indexOf(pobj_Field.getAttribute("value").charAt(int_C)) != -1) {
          this.str_FieldValue += pobj_Field.getAttribute("value").charAt(int_C);
        }
      }
    }
    if (this.str_FieldValue.indexOf(this.str_Decimal) != -1) {
      this.str_FieldValue = this.str_FieldValue.substring((this.str_FieldValue.indexOf(this.str_Decimal) - plng_Integer),this.str_FieldValue.indexOf(this.str_Decimal))
                + this.str_Decimal + this.str_FieldValue.substring((this.str_FieldValue.indexOf(this.str_Decimal) + 1),(this.str_FieldValue.indexOf(this.str_Decimal) + 1) + plng_Decimal);
      if (this.str_FieldValue.charAt((this.str_FieldValue.length - 1)) == ",") {
        this.str_FieldValue = this.str_FieldValue.substring(0,(this.str_FieldValue.length - 1));
      }
    }
    else {
      if (!this.bln_IsDecimal) {
        this.str_FieldValue = this.str_FieldValue.substring(0,plng_Integer);
      }
      else
      {
        this.str_FieldValue = this.str_FieldValue.substring((this.str_FieldValue.length - plng_Integer),this.str_FieldValue.length);
      }
    }
    pobj_Field.setAttribute("value",this.str_FieldValue);
  }
  catch(obj_Exception) {
    exception(obj_Exception,"General[maskNumeric]");
  }
  finally {
    this.bln_IsDecimal = null;
    this.str_Decimal = null;
    this.str_AcceptChr = null;
    this.str_FieldValue = null;
    this.str_NewValue = null;
  }
}

function trimAll(sString) 
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}
//Rafael Sussel
//Checar a data para verifica-la se eh valida
//data = objeto texto
function checkDate(data)
  {
 	var strdate = data.value;
 	var obr=0;
 	if((obr == 1) || (obr == 0 && strdate != "")){
 		//qtd digits
 		if (strdate.length != 10){
 			data.value="";
 			data.focus();
 			return false
 		}
 		//mask
 		if ("/" != strdate.substr(2,1) || "/" != strdate.substr(5,1)){
 			data.value="";
 			data.focus();
 			return false
 		}
 		day = strdate.substr(0,2)
 		month = strdate.substr(3,2);
 		year = strdate.substr(6,4);
 		// day
 		if (isNaN(day) || day > 31 || day < 1){
 			data.value="";
 			data.focus();
 			return false
 		}
 		if (month == 4 || month == 6 || month == 9 || month == 11){
 			if (day == "31"){
 				data.value="";
 				data.focus();
 				return false
 			}
 		}
 		if (month == "02"){
 			bissexto = year % 4;
 			if (bissexto == 0){
 				if (day > 29){
 					data.value="";
 					data.focus();
 					return false
 				}
 			}else{
 				if (day > 28){
 					data.value="";
 					data.focus();
 					return false
 				}
 			}
 		}
 	//month
 		if (isNaN(month) || month > 12 || month < 1){
 			data.value="";
 			data.focus();
 			return false
 		}
 		// year
 		if (isNaN(year)){
 			data.value="";
 			data.focus();
 			return false
 		}
 	}
 }

//Anderson Ikuo Nakamoto
//Permite a digitação de números somente.
function onlyNumber()
{
	if (event.keyCode < 48 || event.keyCode > 57) 
	{
		if (event.keyCode != 8) 
		{
			event.returnValue = false;
		}
	}
}

//Anderson Ikuo Nakamoto
//Máscara de Data
function Fu_FormataData_keyup(paObj)
{
	var data   = paObj.value;
	var mydata = '';
	var vwPos; 
	var vwMes;
	var vwPosBarDia;
	var vwPosBarMes; 
	mydata = mydata + data;
              
	if (mydata.length == 2)//Dia
	{
		vwPos  =  mydata.indexOf('/');
		if(vwPos == 1)
		{
			paObj.value  =  mydata.substr(0,vwPos);
			return;
		}
		if(parseInt(mydata) > 31)
		{
			paObj.value  =  '';
			return;
		}
		paObj.value = mydata + '/'; 
		return;
	}
              
	if (mydata.length == 5)
	{
		vwPos  =  mydata.indexOf('/');
		vwMes  =  mydata.substr(vwPos+1,2);
				
		if(vwMes.length != 2)
		{
			paObj.value  =  mydata.substr(0,vwPos+1);
			return;
		} 
				
		if(parseInt(vwMes) > 12 )
		{
			paObj.value  =  mydata.substr(0,vwPos+1);
			return;
		}
				
		vwPosBarDia  = mydata.indexOf('/');
		vwPosBarMes  = mydata.lastIndexOf('/');
				
		if (vwPosBarMes == vwPosBarDia)
		{
			vwPosBarMes  = mydata.length  -vwPosBarDia;
		}
		vwMes =     mydata.substr(vwPosBarDia+1,  vwPosBarMes-1);
		vwPos =  vwMes.indexOf('/');
		if(vwPos != -1)
		{
			vwMes  = vwMes.substr(0,vwPos);
			paObj.value  = paObj.value.substr(0,paObj.value.length-1);
		}
		if(vwMes.length == 2)
		{
			paObj.value = mydata + '/';
		}
		return;
	}
	//Verifica se a quantidade de caracteres informados para o mes está correta
	if (mydata.length >= 5)
	{
		vwPosBarDia  = mydata.indexOf('/');
		vwPosBarMes  = mydata.lastIndexOf('/');
		vwMes =     mydata.substr(vwPosBarDia+1,  (vwPosBarMes - vwPosBarDia)-1);
		if(vwMes.length > 2)
		{
			paObj.value  =  mydata.substr(0,vwPosBarDia+1);
			return;
		}
		else
		{
			if(vwMes.length == 1)
			{
				paObj.value  =  mydata.substr(0,vwPosBarDia+2);
				return;
			}
		}
		
		if(parseInt(vwMes) > 12 )
		{
			paObj.value  =  mydata.substr(0,vwPosBarDia+1);
			return;
		}
	}
}



/*
function corrigeDataSimples(valor)
{
var mData_array=valor.split("/");
	if(mData_array.length==3)
	{
		var dia = mData_array[0];
		var mes = mData_array[1];
		var ano = mData_array[2];
		if(dia.length==1)
		{
			dia= '0'+dia;
		}
		if(mes.length==1)
		{
			mes= '0'+mes;
		}
		valor=dia+'/'+mes+'/'+ano;
	}else
	{
	valor='';
	}
	return valor;
}
*/

//Anderson Ikuo Nakamoto
//Valida a Data
function Fu_ValidaData_blur(paObj) 
{
try
{
	var vwDataValor   =  paObj.value;
//	vwDataValor = corrigeDataSimples(vwDataValor);
	if(vwDataValor == '')
	{
		return; 
	}
	var vwPosBarDia  = vwDataValor.indexOf('/');
	var vwPosBarMes  = vwDataValor.lastIndexOf('/');
		
	var dia = vwDataValor.substr(0,vwPosBarDia);
	var mes = vwDataValor.substr(vwPosBarDia +1,(vwPosBarMes - vwPosBarDia)-1); 
	var ano = vwDataValor.substr(vwPosBarMes +1,vwDataValor.lenght); 
	if(ano.length == 0)
	{
		msgBoxG('Ano informado é inválido!');
		paObj.focus(); 
		return;
	}

	if(ano.length < 4)
	{
		if(ano.length == 3 || ano.length == 1)
		{
			msgBoxG('O Ano informado é inválido!');
			paObj.focus(); 
			return; 
		}
		if(ano.length == 2)
		{
			if(parseInt(ano) >= 0 && parseInt(ano) <= 50)
			{
				paObj.value = dia + '/' + mes + '/' + '20' + ano; 
				ano  =  '20' + ano;
			}
		
			if(parseInt(ano) >= 51 && parseInt(ano) <= 99)
			{
				paObj.value = dia + '/' + mes + '/' + '19' + ano;
				ano  =  '19' + ano;
			}
		} 
	}
	situacao = ""; 
	// verifica o dia valido para cada mes 
	if ((dia < 01)||(dia < 01 || dia > 30) && (  mes == 04 || mes == 06 || mes == 09 || mes == 11 ) || dia > 31) 
	{ 
		situacao = "falsa"; 
	} 

	// verifica se o mes e valido 
	if (mes < 01 || mes > 12 ) 
	{ 
		situacao = "falsa"; 
	} 

	// verifica se e ano bissexto 
	if (mes == 2 && ( dia < 01 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) 
	{ 
		situacao = "falsa"; 
	} 

	if (paObj.value == "") 
	{ 
		situacao = "falsa"; 
	} 

	if (situacao == "falsa")
	{ 
		paObj.value= ''; 
		paObj.focus();
		return;  
	} 
	}catch (e) {}
}



//Rafael Sussel Decleva
//Valida Hora
function ValidaHora(objHour)
{
try{
var vValue = objHour.value;
if(vValue!="")
{
	if(vValue.length==5)
	{
		var pPts = vValue.indexOf(':');
		if(pPts <0)
		{
			objHour.value="";
			objHour.focus();	
			return;
		}	
		var horas = vValue.substr(0,pPts);
		var minutos = vValue.substr(pPts+1,vValue.lenght);
		if(parseInt(horas) < 0 || parseInt(horas) >24 || parseInt(minutos)<0 || parseInt(minutos) > 59)
		{
			objHour.value="";
			objHour.focus();	
			return;
		}
		
	}else
	{
		objHour.value="";
		objHour.focus();
		return;
	}
}
}catch (e) {}
}


/*** 
*RAFAEL SUSSEL DECLEVA
* Descrição.: formata um campo do formulário de 
* acordo com a máscara informada... 
* Parâmetros: - objForm (o Objeto Form) 
* - strField (string contendo o nome do textbox) 
* - sMask (mascara que define o formato que o dado será apresentado, 
* usando o algarismo "9" para  definir números e o símbolo "!" para 
* qualquer caracter... 
* - evtKeyPress (evento) 
* Uso.......: <input type="textbox" 
* name="xxx"..... 
* onkeypress="return txtBoxFormat(document.rcfDownload, 'str_cep', '99999-999', event);"> 
* Observação: As máscaras 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 aí vai... 
***/

function txtBoxFormat(textBox, sMask, evtKeyPress) {
      var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;
try{
      if(document.all) { // Internet Explorer
        nTecla = evtKeyPress.keyCode; }
      else if(document.layers) { // Nestcape
        nTecla = evtKeyPress.which;
      }
      sValue = textBox.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( " ", "" );
	 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) == ")") || (sMask.charAt(i) == " "))

        if (bolMask) {
          sCod += sMask.charAt(i);
          mskLen++; }
        else {
          sCod += sValue.charAt(nCount);
          nCount++;
        }

        i++;
      }

      textBox.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;
      }
      }catch (e) {}
    }
    
    
		function Querystring(qs) { 
			this.params = new Object()
			this.get=Querystring_get
			
			if (qs == null)
				qs=location.search.substring(1,location.search.length)

			if (qs.length == 0) return

			qs = qs.replace(/\+/g, ' ')
			var args = qs.split('&') 
			
			for (var i=0;i<args.length;i++) {
				var value;
				var pair = args[i].split('=')
				var name = unescape(pair[0])

				if (pair.length == 2)
					value = unescape(pair[1])
				else
					value = name
				
				this.params[name] = value
			}
		}

		function Querystring_get(key, default_) {
			if (default_ == null) 
			{
				default_ = null;
			}
			var value=this.params[key]
			if (value==null) 
			{
				value=default_;
			}
			return value
		}



