/**
 * Biblioteca de mascaras de formatacao
 *
 * @author Giorgio
 * @version $Revision: 1.1 $, $Date: 2006/07/20 02:07:45 $
 */
Format = function() {};

/**
 * formatacao generia para uma ocorrencia
 * @param strValue
 * @param objRegExp
 * @param strReplace
 * @return
 */
Format.format = function(strValue, objRegExp, strReplace) {
	if(objRegExp.test(strValue))
		return strValue.replace(objRegExp, strReplace);
	return strValue;
};

/**
 * formatacao generica para varias ocorrencias
 * @param strValue
 * @param objRegExp
 * @param strReplace
 * @return
 */
Format.formatAll = function(strValue,objRegExp,strReplace) {
	while(objRegExp.test(strValue))
		strValue = strValue.replace(objRegExp,strReplace);
	return strValue;
};

/**
 * formatacao de Numeros
 * @param strValue
 * @return
 */
Format.number = function (strValue) {
	return Format.format(strValue, new RegExp('[^0-9]*', 'g'), '');
};
/**
 * formatacao de em formato de texto 10.100.100 ou -10.100.100
 * @param strValue
 * @return
 */
Format.textNumber = function(strValue) {
	strValue = Format.format(strValue, new RegExp('^(-?)([^0-9]*)', 'g'), '$1');;
	return Format.formatAll(strValue, new RegExp('(-?[0-9]+)([0-9]{3})'), '$1.$2');
};
/**
 * formatacao de CEP
 * @param strValue
 * @return
 */
Format.cep = function (strValue) {
	strValue = Format.number(strValue);
	if(strValue.length>8) strValue = strValue.substring(0,8);
 	return Format.format(strValue, new RegExp('^([0-9]{5})([0-9])'), '$1-$2');
};

/**
 * formatacao de DATA 88/88/8888
 * @param strValue
 * @return
 */
Format.date = function (strValue) {
	p = new RegExp('^([0-9]{2})/([0-9]{2})/([0-9]{4})$')
	if(p.test(strValue)) strValue;
	strValue = Format.number(strValue);
	if(strValue.length>8) strValue = strValue.substring(0,8);
	strValue = Format.format(strValue, new RegExp('([0-9]{2})([0-9])'), '$1/$2');
 	return Format.format(strValue, new RegExp('([0-9]{2})/([0-9]{2})([0-9])'), '$1/$2/$3');
};

/**
 * formatacao de Hora 88:88
 * @param strValue
 * @return
 */
Format.time = function (strValue) {
	strValue = Format.number(strValue);
	if(strValue.length>4) strValue = strValue.substring(0,4);
 	return Format.format(strValue, new RegExp('([0-9]{2})([0-9])'), '$1:$2');
};
