<!-- Arquivo de Fun es Diversas em Javascript -->
<!-- Verso 1.0 -->
<!-- Criado por Alexandre Verta Eiras - alexandre.verta@gmail.com -->
<!-- Data de cria o: 09/07/2006 -->
<!-- Modificado por: -->
<!-- Data de modifica o -->

var checkflag = "false";
function checkTodos( field ) {
	if (checkflag == "false") {
		if (field.length == null) {
			field.checked = true;
		}
		for (i = 0; i < field.length; i++) {
			field[i].checked = true;
		}
		checkflag = "true";
		return "Desmarcar Todos";
	} else {
		if (field.length == null) {
			field.checked = false;
		}
		for (i = 0; i <field.length; i++) {
			field[i].checked = false;
		}
		checkflag = "false";
		return "Marcar Todos";
	}
}

var checkflag = "false";
function checkTodosAlternativo() {
	field = document.getElementById("id_cupom");
	if (checkflag == "false") {
		if (field.length == null) {
			field.checked = true;
		}
		for (i = 0; i < field.length; i++) {
			field[i].checked = true;
		}
		checkflag = "true";
		return "Desmarcar Todos";
	} else {
		if (field.length == null) {
			field.checked = false;
		}
		for (i = 0; i <field.length; i++) {
			field[i].checked = false;
		}
		checkflag = "false";
		return "   Marcar Todos   ";
	}
}

function TrimLeft( str ) {
	var resultStr = "";
	var i = len = 0;
	// Return immediately if an invalid value was passed in
	if (str+"" == "undefined" || str == null) 
		return null;
	// Make sure the argument is a string
	str += "";
	if (str.length == 0) 
		resultStr = "";
	else { 
		// Loop through string starting at the beginning as long as there
		// are spaces.
		// len = str.length - 1;
		len = str.length;

		while ((i <= len) && (str.charAt(i) == " "))
			i++;
		// When the loop is done, we're sitting at the first non-space char,
		// so return that char plus the remaining chars of the string.
		resultStr = str.substring(i, len);
	}
	return resultStr;
}

function TrimRight( str ) {
	var resultStr = "";
	var i = 0;
	// Return immediately if an invalid value was passed in
	if (str+"" == "undefined" || str == null) 
		return null;
	// Make sure the argument is a string
	str += "";

	if (str.length == 0) 
		resultStr = "";
	else {
		// Loop through string starting at the end as long as there
		// are spaces.
		i = str.length - 1;
		while ((i >= 0) && (str.charAt(i) == " "))
			i--;

		// When the loop is done, we're sitting at the last non-space char,
		// so return that char plus all previous chars of the string.
		resultStr = str.substring(0, i + 1);
	}

	return resultStr; 
}

function Trim( str ) {
	var resultStr = "";

	resultStr = TrimLeft(str);
	resultStr = TrimRight(resultStr);

	return resultStr;
}

function VerificaCaixaSelecao(input){
	if(input.options[0].selected){
		return false;
	} else {
		return true;
	}
}

function somente_numero(campo){
var digits="0123456789"
var campo_temp
for (var i=0;i<campo.value.length;i++){
  campo_temp=campo.value.substring(i,i+1)
  if (digits.indexOf(campo_temp)==-1){
     campo.value = campo.value.substring(0,i);
	//campo.value = '';
	 break;
   }
}
}

function somente_alpha(campo){
var digits="0123456789AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuWwVvYyXxZz"
var campo_temp
for (var i=0;i<campo.value.length;i++){
  campo_temp=campo.value.substring(i,i+1)
  if (digits.indexOf(campo_temp)==-1){
     campo.value = campo.value.substring(0,i);
	//campo.value = '';
	 break;
   }
}
}

function Contador(field,MaxLength) { 
      obj = document.all(field); 
      if (MaxLength !=0) { 
         if (obj.value.length > MaxLength)  {
            obj.value = obj.value.substring(0, MaxLength); 
            }
      }
      document.getElementById('contador').value = obj.value.length + " de 250";
  }
