//Máscara em o text em Moeda
//Variaveis
var yoshi_error='';
//--------------------------
String.prototype.currencyFormat = function (f, d, t) {
var n = (n = this.match(/\d/g)) ? n.join('').replace(/^0+/,'') : '0', f = (f) ? f : 2, d = (d) ? d : ',', t = (t) ? t : '.';
if (n.length < f + 1) return '0' + d + ((n.length < f) ? new Array(f - n.length + 1).join('0') + n : n)
else return n.substr(0, n.length - f).split('').reverse().join('').match(/\d{1,3}/g).join(t).split('').reverse().join('') + d + n.substr(n.length - f)
}

//Bloqueia teclado só funciona números Double
function fncValidateFloat(event){
var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
var caract = new RegExp(/^[.,\d\b\t\r]*$/);
var caract = caract.test(String.fromCharCode(keyCode));
if (!(keyCode > 36 && keyCode < 41) && (!(keyCode == 46))){
	if(!caract){
		alert("Caracter invalido: " +String.fromCharCode(keyCode) +"\n Somente numericos");
		return false;
	}
}	
return true;
}
//Bloqueia teclado só funciona números inteiros
function fncValidateInt(event){
var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
var caract = new RegExp(/^[\d\b\t\r]*$/);
var caract = caract.test(String.fromCharCode(keyCode));
if (!(keyCode > 36 && keyCode < 41) && (!(keyCode == 46))){
	if(!caract){
		//alert("Caracter inválido: " +String.fromCharCode(keyCode) +"\n Somente numericos");
		return false;
	}
}

return true;
}
//Bloqueia teclado só funciona números inteiros
function fncValidateIntNoMsg(event){
var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
var caract = new RegExp(/^[\d\b\t\r]*$/);
var caract = caract.test(String.fromCharCode(keyCode));
if (!(keyCode > 36 && keyCode < 41) && (!(keyCode == 46))){
	if(!caract){
		return false;
	}
}

return true;
}
function fncEMailCheckCharKeyPress(event){
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	var caract = new RegExp(/^[a-z@.\-_\d\b\t\r]*$/);
	var checkKey = caract.test(String.fromCharCode(keyCode));
	if (!(keyCode > 36 && keyCode < 41) && (!(keyCode == 46))){
		if(!checkKey){
			//alert("Caracter inválido: " +String.fromCharCode(keyCode)+"\n Os caracteres especiais válidos: \n  _ (underline) e - (sinal de menos) ");
			keyCode=0;
			return false;
		}
	}
}
function fncEMailCheckCharKeyPress2(event){
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	var caract = new RegExp(/^[a-z@.\-_\d\b\t\r]*$/);
	var checkKey = caract.test(String.fromCharCode(keyCode));
	if (!(keyCode > 36 && keyCode < 41) && (!(keyCode == 46))){
		if(!checkKey){
			//alert("Caracter inválido: " +String.fromCharCode(keyCode)+"\n Os caracteres especiais válidos: \n  _ (underline) e - (sinal de menos) ");
			keyCode=0;
			return false;
		}
	}
}
function fncCheckCharKeyPress(event){
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	var caract = new RegExp(/^[\-_ & \w\d\b\t\r]*$/);
	var checkKey = caract.test(String.fromCharCode(keyCode));
	if (!(keyCode > 36 && keyCode < 41) && (!(keyCode == 46))){
		if(!checkKey){
			//alert("Caracter inválido: " +String.fromCharCode(keyCode)+"\n Os caracteres especiais válidos: \n  _ (underline) e - (sinal de menos) ");
			keyCode=0;
			return false;
		}
	}
}
function fncCheckNumber(e){
e = e.toLowerCase();
var validChar = "0987654321.,";
	for(var i = 0; i < e.length; i++){
		if (validChar.indexOf(e.charAt(i)) == -1) return false
	}
}
function fncCheckInt(e){
e = e.toLowerCase();
var validChar = "0987654321";
	for(var i = 0; i < e.length; i++){
		if (validChar.indexOf(e.charAt(i)) == -1) return false;
	}
return true;
}

function fncEMailCheckChar(e){
e = e.toLowerCase();
var validChar = "0987654321abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWYXZ.-_@;";
var validCharA = "@";
var bErro=true;
var num=0,num1=0;

num=e.indexOf('@');
num1=e.substr(e.indexOf('@')).indexOf('.');
if (e.length==0){
	yoshi_error='Favor preecher o campo E-Mail';
	return false;
}
for(var i = 0; i < e.length; i++){
	if (validChar.indexOf(e.charAt(i)) == -1) return false
}
for(var i = 0; i < e.length; i++){
	if (validCharA.indexOf(e.charAt(i)) == 0) {bErro = false;}
}
if (bErro) {
	yoshi_error='E-Mail Inválido';
	return false;
}
if ((e.substr(num-1,1).indexOf('.')==0)||(e.substr(num-1,1).indexOf('_')==0)){
	yoshi_error='Não é possível colocar um sublinhado ou ponto (.) junto com o "@" \n exemplo: ".@"';
	return false;
}
if (e.substr(e.indexOf('@')+1).length==0) {
	yoshi_error='E-Mail Inválido';
	return false;
}
if (e.substr(e.indexOf('@')+2).indexOf('.')==-1) {
	yoshi_error='E-Mail Inválido';
	return false;
}

if (e.substr(num+num1+1).length==0){
	yoshi_error='E-Mail Inválido';
	return false;
}
if ((e.substr(e.length-1).indexOf('.')==0)||(e.substr(e.length-1).indexOf('_')==0)){
	yoshi_error='Não é possível terminar com um sublinhado ou ponto (.)';
	return false;
}
return true;
}
function fncRollOverFont(iThis,IOverB,IOverF){ 
var iOutB = iThis.style.backgroundColor;
var iOutF = iThis.style.color;
	iThis.style.backgroundColor=IOverB; 
	iThis.style.color=IOverF; 
	iThis.onmouseout=function(){ 
		iThis.style.backgroundColor=iOutB; 
		iThis.style.color=iOutF; 
	}
}
function fncRollOver(iThis,IOverB){
var iOutB = iThis.style.backgroundColor;
	iThis.style.backgroundColor=IOverB;
	iThis.onmouseout=function(){ 
		iThis.style.backgroundColor=iOutB;
	}
}
function fncButtonOver(iThis,iDir,iOver){
var iOut = iThis.src;
	iThis.src=iDir+iOver; 
	iThis.onmousedown=function(){
		iThis.src=iOut; 
	}
	iThis.onmouseout=function(){
		iThis.src=iOut; 
	}
}
function fncButtonClick(iThis,iDir,iOver,iClick){
var iOut = iThis.src;
	iThis.src=iDir+iOver;
	iThis.onmousedown=function(){
		iThis.src=iDir + iClick;
	}
	iThis.onmouseout=function(){
		iThis.src=iOut; 
	}
}
function fncContador(field,id_contador, MaxLength) { 
  var obj = document.getElementById(field); 
  if (MaxLength !=0) { 
     if (obj.value.length > MaxLength) {
        obj.value = obj.value.substring(0, MaxLength); 
     }
  }
  document.getElementById(id_contador).innerHTML = obj.value.length + ' / ' + MaxLength;
} 
function fncToggle(id){
var tipo = document.getElementById(id).style.display;
document.getElementById(id).style.display = tipo == 'none' ? '' : 'none';
}
function fncShow(id){
var tipo = document.getElementById(id).style.display;
document.getElementById(id).style.display = '';
}
function fncHide(id){
var tipo = document.getElementById(id).style.display;
document.getElementById(id).style.display = 'none';
}
function fncGetErro(){
	return yoshi_error;
}
function convertSendForm(params) {
var result = params.replace(/\%/g,"%25")
.replace(/á/g, "%E1")
.replace(/â/g, "%E2")
.replace(/ã/g, "%E3")
.replace(/Á/g, "%C1")
.replace(/Â/g, "%C2")
.replace(/Ã/g, "%C3") 
.replace(/É/g, "%C9")
.replace(/é/g, "%E9")
.replace(/ê/g, "%EA")
.replace(/Í/g, "%CD")
.replace(/í/g, "%ED")
.replace(/Ó/g, "%D3")
.replace(/Ô/g, "%D4")
.replace(/Õ/g, "%D5")
.replace(/ó/g, "%F3")
.replace(/õ/g, "%F5")
.replace(/ô/g, "%F4")
.replace(/Ú/g, "%DA")
.replace(/Ü/g, "%DC")
.replace(/ú/g, "%FA")
.replace(/ü/g, "%FC")
.replace(/ç/g, "%E7")
.replace(/Ç/g, "%C7")
.replace(/´/g,"%B4")
.replace(/°/g,"%B0")
.replace(/\|/g,"%7C")
.replace(/\+/g,"%2B")
.replace(/\#/g,"%23")
.replace(/\º/g,"%BA")
.replace(/\ª/g,"%AA")
.replace(/\&/g,"%26")
.replace(/\=/g,"%3D")
.replace(/\//g,"%2F")
.replace(/\:/g,"%3A");
return result;
}
function fncKeyPressTime(id, e){
	var BACKSPACE=8;
	var DEL=46;
	var up=39;
	var TRAS=37;
	var TAB=9;
	var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
	var input = $(id).val();
	if (( keyCode == BACKSPACE )||(keyCode == DEL)||(keyCode == up)||(keyCode == TRAS)||(keyCode == TAB)) {
		return true;
	}
	if ( keyCode == 13 ) return false;

if ((keyCode <48)||(keyCode >57)) {
	e.returnValue = false;
	return false;
} else {
	if (input.length==2) {
		 $(id).val(input + "\:");
	}
}
return true;
}
function fncKeyPressDate(id, e){
	var BACKSPACE=8;
	var DEL=46;
	var up=39;
	var TRAS=37;
	var TAB=9;
	var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
	var input = $(id).val();
	if (( keyCode == BACKSPACE )||(keyCode == DEL)||(keyCode == up)||(keyCode == TRAS)||(keyCode == TAB)) {
		return true;
	}
	if ( keyCode == 13 ) {return false};
	if ((keyCode <48)||(keyCode >57)) {
		e.returnValue = false;
		return false;
	} else {
		if ((input.length==2)||(input.length==5)) {
			 $(id).val(input + "/");
		}
	}
return true;
}
function isDate(s){
    // make sure it is in the expected format   
    if (s.search(/^\d{1,2}[\/|\-|\.|_]\d{1,2}[\/|\-|\.|_]\d{4}/g) != 0)   
        return false;   
  
    // remove other separators that are not valid with the Date class              
    s = s.replace(/[\-|\.|_]/g, "/");   
               
    // convert it into a date instance   
    var dt = new Date(Date.parse(s));          
  
    // check the components of the date   
    // since Date instance automatically rolls over each component   
    var arrDateParts = s.split("/");   
    return (   
        dt.getMonth() == arrDateParts[0]-1 &&   
        dt.getDate() == arrDateParts[1] &&   
        dt.getFullYear() == arrDateParts[2]   
    );             
}