//<!--

// Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl>
// Distributable under LGPL license. See terms of license at gnu.org.

// Creates a fixed size pop-up window without status, scroll/toolbars
function openBareWindow(id, url, width, height) {
   window.open(url,id, "status=no,resizable=no,scrollbars=no,toolbar=no,WIDTH="+width+",HEIGHT="+height)
}

// Creates a fixed size full screen scrollable window without status, scroll/toolbars
function openBareFullscreenWindow(id, url) {
   window.open(url, id, "status=no,resizable=yes,scrollbars=yes,toolbar=no,HEIGHT="+screen.height+",WIDTH="+screen.width)
}

// Creates a fixed size pop-up window without status, toolbars but with scroll.
function openBareScrollingWindow(id, url, width, height) {
   window.open(url,id, "status=no,resizable=no,scrollbars=yes,toolbar=no,WIDTH="+width+",HEIGHT="+height)
}

// Returns a blank HTML page with the specified color
function blankPage(color) {
	return "<HTML><HEAD><META HTTP-EQUIV='Pragma' CONTENT='no-cache'></HEAD><BODY BGCOLOR="+color+"></BODY></HTML>"
}

// Parse parameter out of a string.
function getParameter(string, parm, delim) {
     // returns value of parm from string
     if (string.length == 0) {return '';}
	 var sPos = string.indexOf(parm + "=");
     if (sPos == -1) {return '';}
     sPos = sPos + parm.length + 1;
     var ePos = string.indexOf(delim, sPos);
     if (ePos == -1) {ePos = string.length;}
     return unescape(string.substring(sPos, ePos));
}

// Get parameter from query string passed to my page
function getPageParameter(parameterName, defaultValue) {
	var s = self.location.search;
	if ((s == null) || (s.length < 1)) {
		return defaultValue;
	}
	s = getParameter(s, parameterName, '&');
	if ((s == null) || (s.length < 1)) {
		s = defaultValue;
	}
	return s;	
}

function Sum(valor1, valor2) {
	a = Math.round((valor1 + valor2)*100);
	return a/100;
}

function Mask(Valor) {
	var decimal = new String(Math.abs(Math.round(100*Valor)%100));
	if ( decimal.length == 1 ) {
		decimal = "0" + decimal;
	}
	var integ = Math.abs(Number(Valor));
	var milhar = new String (parseInt ( integ % 1000 ));
	if (integ >= 1000) {
		milhar = "000".substr(0, 3 - milhar.length) + milhar;
	}
	var formatValor = milhar + "," + decimal;
	integ = parseInt(integ / 1000);
	while(integ != 0) {
		milhar = new String (parseInt(integ % 1000));
		integ = parseInt(integ / 1000);
		if (integ > 0) {
			milhar = "000".substr(0, 3 - milhar.length) + milhar;
		}
		formatValor = milhar + "." + formatValor;
	}
	if (Valor < 0) {
		formatValor = "-" + formatValor;
	}
	return formatValor;
}

function UnMask(Valor) {
	desmascarado = new String(Valor);
	var regexp = /\./g;
	desmascarado = desmascarado.replace(regexp, '');
	desmascarado = desmascarado.replace(',', '.');
	return desmascarado;
}

/*
 * Devolve o menor índice dentro do array onde
 * se encontra, na coluna col do array, o 
 * text passado  Se não for encontrado o elemento
 * no array será retornado -1.
 */
function getIndex(array, text, col) {
	if ( !(array instanceof Array))
		throw "array não é do tipo Array";
	
	for (var i=0; i<array.length; i++) {
		if (array[i].length < col) {
			throw "O array[" + i + "] não tem tantas colunas!";
		}
		
		var arrText;
		arrText = array[i][col];
		if (arrText == text) {
			return i;
		}
	}
	return -1;
}

/**
 * $Log: util.js,v $
 * Revision 1.1.1.1  2009/04/13 19:31:27  rodrigo
 * no message
 *
 * Revision 1.3  2003/08/15 08:39:01  justb
 * fix/add copyright + LGPL in file headers
 *
 *
 */
/**
 * $Log: util.js,v $
 * Revision 1.1.1.1  2009/04/13 19:31:27  rodrigo
 * no message
 *
 * Revision 1.4  2004/04/17 14:44
 * add getIndex
 * @author Valdemar 
 *
 */
 function FormataData(campo, teclapres) {
	var tecla = teclapres.keyCode;
	var Campo = campo.name
	eval("vr = document.forms[0]." + Campo + ".value;");
	if ( (tecla < 48 || tecla > 57) && ( tecla<95 || tecla >105)  && tecla != 8  ) {
		vr = vr.substring(0, vr.length-1)
		eval("document.forms[0]."+ Campo + ".value=vr;");
		return;
	}
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;
	if ( tecla != 9 )
	{
		if ( tam > 2 && tam < 5 )
			eval("document.forms[0]." + Campo + ".value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );");
		if ( tam >= 5 )
			eval("document.forms[0]." + Campo + ".value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 );");
	}
}

/*
 * String - Remove espaços em branco e retorna string.
 */
function trim( string ) {
	string = new String( string );
	var curChar = '';
	while ( (curChar = string.charAt( string.length - 1 )) == ' ' ) {
		string = string.substr(0, string.length - 1);
	}
	while ( (curChar = string.charAt( 0 )) == ' ' ) {
		string = string.substr(1, string.length - 1);
	}
	return string;
}

/*
 * String - Verifica se string é branca
 */
function isBlank( string ) {
	string = trim( string );
	return (string=='')?true:false;
}

/*
 * String - Verifica se string é não-branca
 */
function isNotBlank( string ) {
	return !(isBlank(string));
}

/*
 * String - Verifica se string é referente à um valor numérico
 */
function isNumeric( string ) {
	string = trim(string);
	return (!isNaN(string));
}

/*
 * String - Verifica se string é referente à um valor não-numérico
 */
function isNotNumeric( string ) {
	string = trim(string);
	return (isNaN(string));
}

/*
 * String - Remove caracteres especiais
 */
function removeSpecChars( string ) {
	string = new String( string );
	var regExp = '/[,./-]/gi';
	return string.replace( regExp, '' );
}

// -->