/*
 *  @author Lauffer
 */
function popup(url,w,h,s) {
	var oW=window.open(url,'pop','width='+w+',height='+h+',directories=0,location=0,menubar=0,resizable=0,scrollbars='+s+',status=1,toolbar=0,marginleft=0,margintop=0,left='+(((screen.width-w)/2)+-10)+',top='+(((screen.height-h)/2)+-30));
}

/*
 *  @author Dalton Camargo
 */
function popupWithStatusBar(url,w,h,s) {
	var oW=window.open(url,'pop','width='+w+',height='+h+',directories=0,location=0,menubar=0,resizable=0,scrollbars='+s+',status=0,toolbar=0,marginleft=0,margintop=0,left='+(((screen.width-w)/2)+-10)+',top='+(((screen.height-h)/2)+-30));
}


/*
 *  @author Dalton Camargo
 */
function randomTime(){
	adate = new Date();
	return adate.getMilliseconds();
}

/*
 *  @author Dalton Camargo
 */
function validateRequiredFields(arrFields,msg) {
	for(i=0; i < arrFields.length; i++) {
		if(trim(document.getElementById(arrFields[i]).value) == ""){
			alert(msg);
			document.getElementById(arrFields[i]).focus();
			return false;
		}
	}
	return true;
}

/*
 *  @author Desconhecido (Google Result)
 */
function Limpar(valor, validos) { 
      // retira caracteres invalidos da string 
      var result = ""; 
      var aux; 
      for (var i=0; i < valor.length; i++) { 
          aux = validos.indexOf(valor.substring(i, i+1)); 
          if (aux>=0) { 
               result += aux; 
          } 
       } 
       return result; 
} 

/*
 *  @author Desconhecido (Google Result)
 */
/**
Formata número tipo moeda
Quando for utilizado para divisão, é necessário o toFixed 
informando quantas casas decimais deverá ser usado
Exemplo de utilização: Formata(numero.toFixed(2),100,2)
**/
function Formata(valor,tammax,decimal) { 
  vr = Limpar(valor,"0123456789"); 
	tam = vr.length; 
       dec=decimal;
       var ret = "";
        //if (tam < tammax ){ tam = vr.length + 1 ; } 
       
       if ( tam <= dec ) 
       { ret = vr ; } 
       
       if ( (tam > dec) && (tam <= 5) ){ 
       ret = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ; } 
       if ( (tam >= 6) && (tam <= 8) ){ 
           ret = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; 
       } 
       if ( (tam >= 9) && (tam <= 11) ){ 
       ret = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; } 
       if ( (tam >= 12) && (tam <= 14) ){ 
       ret = vr.substr( 0, tam - 11 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; } 
       if ( (tam >= 15) && (tam <= 17) ){ 
       ret = vr.substr( 0, tam - 14 ) + "." + vr.substr( tam - 14, 3 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam ) ;} 
       
       return ret;
   }

/*
 *  @author Dalton Camargo
 */
function validaNumero(objeto){
	if(objeto.value != ""){
		ereg = new RegExp("^([0-9]{1,3})(,([0-9]{1,3}))?$","");
		if (!ereg.test(objeto.value)) {
			alert("Valor incorreto!\n\nRestrições para este campo:\n-Possuir somente uma vírgula;\n-Possuir somente 3 dígitos;\n-Possuir no máximo 3 casas decimais;\n-Possuir somente valores numéricos;\n-Não deve possuir pontos.\n\n* Ex: 454,455 ou 12,11");
			objeto.focus();
			return false;
		}
	}
	return true;
}

/*
 *  @author Renato Abrahão
 */
function validaDinheiro(objCampo) {
	if(objCampo.value != ""){
		ereg = new RegExp("^([0-9]{1,6})(,)([0-9]{2})([0-9]{0,4})$","");
		if (!ereg.test(objCampo.value)) {
			alert("Valor incorreto!\n\nRestrições para este campo:\n-Possuir somente uma vírgula;\n-Possuir somente 6 dígitos;\n-Possuir no máximo 6 casas decimais;\n-Possuir somente valores numéricos;\n-Não deve possuir pontos.\n\n* Ex: 466654,488544 ou 142,11");
			objCampo.focus();
			return false;
		}
	}
	return true;
}

/*
 *  @author Dalton Camargo
 */
function numberPreSubmit(objeto){
	objeto = objeto.replace('.','');
	objeto = objeto.replace(',','.');
	return objeto;
}

function go(url){
	top.opener.top.location.href=url;
	window.close();
	window.focus();
}

