function js_SetWindowStatus(strTxt) {
	if (typeof(strTxt) == 'string' && strTxt != null)
		window.status = strTxt;
}
function js_SetHelp(strTxt) { js_SetWindowStatus(strTxt) }
function js_OpenURL(url, option) { js_OpenWindows(url, option) }
function js_OpenWindows(sURL, sName, sFeatures, bReplace) {
	if (typeof(sFeatures) == 'undefined') sFeatures = '';
	if (sFeatures.indexOf('top=') == -1) sFeatures+=',top=0';
	if (sFeatures.indexOf('left=') == -1) sFeatures+=',left=0';
	if (sFeatures.indexOf('toolbar=') == -1) sFeatures+=',toolbar=no';
	if (sFeatures.indexOf('menubar=') == -1) sFeatures+=',menubar=no';
	if (sFeatures.indexOf('location=') == -1) sFeatures+=',location=no';
	if (sFeatures.indexOf('directories=') == -1) sFeatures+=',directories=no';
	if (sFeatures.indexOf('status=') == -1) sFeatures+=',status=yes';
	if (sFeatures.indexOf('scrollbars=') == -1) sFeatures+=',scrollbars=yes';
	if (sFeatures.indexOf('resizable=') == -1) sFeatures+=',resizable=yes';
	if (sFeatures.indexOf('width=') == -1) sFeatures+=',width=screen.availwidth';
	if (sFeatures.indexOf('height=') == -1) sFeatures+=',height=screen.availheight';
	if (typeof(sName) == 'undefined' || sName == '') sName='_blank';
	if (typeof(bReplace) == 'undefined') bReplace=true;
	window.open(sURL, sName, sFeatures, bReplace);
}
function js_OpenUrlMD(url, option) {
	if (typeof(option) == 'undefined')
		option = 'dialogWidth:240,dialogHeight:300,center:yes';
	window.showModalDialog(url);
}
function js_FlipImage(url)
{
    if (window.event.srcElement.tagName == "INPUT" || window.event.srcElement.tagName == "IMG") {
        window.event.srcElement.src = url;
    }
}
function js_FlipColor(color)
{
    if (window.event.srcElement.tagName == "INPUT") {
        window.event.srcElement.style.color = color;
    }
}
function js_IndexOfField(FieldName) {
	if (document.MeForm.elements.length != 0) {
		for (var i = 0; i < document.MeForm.elements.length; i++) {
		   	if (FieldName + '' == document.MeForm[i].name) {
		   		return i;
		   	}
		}
	}
	return -1;
}
function js_SetFocusField(FieldName) {
	var i = js_IndexOfField(FieldName);
	if (i != -1) {
		if (document.MeForm[i]) document.MeForm[i].focus();
	}
}
function js_FieldClean(s,c) {
	if (typeof(s) == 'string' && s != null) {
		var i = s.indexOf(c);
		if (i != -1) {
			s = s.replace( c, "" );
			s = js_FieldClean(s,c);
		}
	}
	return s;
}
function js_FormatDate(FieldName,KeyPress) {
	var kc = KeyPress.keyCode;
	var i = js_IndexOfField(FieldName)
	var s = document.MeForm[i].value;
	s = js_FieldClean(s,"/");
	var Size = s.length;
	if (Size < 8 && kc != 8)	{ Size = s.length + 1 ; }
	if (kc == 8 )			{ Size = Size - 1 ; }
	if ( kc != 9 && kc != 8 ){
		if ( Size > 2 && Size < 5 ) {
			document.MeForm[i].value = s.substr( 0, Size - 2  ) + '/' + s.substr( Size - 2, Size );
		}
		if ( Size >= 5 && Size <= 10 ) {
			document.MeForm[i].value = s.substr( 0, 2 ) + '/' + s.substr( 2, 2 ) + '/' + s.substr( 4, 4 );
		}
	}
}
function js_FormatMoney(FieldName,KeyPress) {
	var kc = KeyPress.keyCode;
	var i = js_IndexOfField(FieldName)
	var s = document.MeForm[FieldName].value;
	var Size = s.length;
	s = js_FieldClean(s,",");
	s = js_FieldClean(s,".");
	if (Size < 16 && kc != 8)	{ Size = s.length + 1 ; }
	if (kc == 8 )			{ Size = Size - 1 ; }
	if (kc == 8 || kc >= 48 && kc <= 57 || kc >= 96 && kc <= 105 ) {
		if ( Size <= 2 ) {
	 		document.MeForm[FieldName].value = s ; 
	 	}
	 	if ( (Size > 2) && (Size <= 5) ) {
	 		document.MeForm[FieldName].value = s.substr( 0, Size - 2 ) + '.' + s.substr( Size - 2, Size ) ; 
	 	}
	 	if ( (Size >= 6) && (Size <= 8) ) {
	 		document.MeForm[FieldName].value = s.substr( 0, Size - 5 ) + ',' + s.substr( Size - 5, 3 ) + '.' + s.substr( Size - 2, Size ) ; 
	 	}
	 	if ( (Size >= 9) && (Size <= 11) ) {
	 		document.MeForm[FieldName].value = s.substr( 0, Size - 8 ) + ',' + s.substr( Size - 8, 3 ) + ',' + s.substr( Size - 5, 3 ) + '.' + s.substr( Size - 2, Size ) ; 
	 	}
	 	if ( (Size >= 12) && (Size <= 14) ) {
	 		document.MeForm[FieldName].value = s.substr( 0, Size - 11 ) + ',' + s.substr( Size - 11, 3 ) + ',' + s.substr( Size - 8, 3 ) + ',' + s.substr( Size - 5, 3 ) + '.' + s.substr( Size - 2, Size ) ; 
	 	}
	 	if ( (Size >= 15) && (Size <= 17) ) {
	 		document.MeForm[FieldName].value = s.substr( 0, Size - 14 ) + ',' + s.substr( Size - 14, 3 ) + ',' + s.substr( Size - 11, 3 ) + ',' + s.substr( Size - 8, 3 ) + ',' + s.substr( Size - 5, 3 ) + '.' + s.substr( Size - 2, Size ) ;
		}
	}
}

function js_FormatMMYYYY(FieldName,KeyPress) {
	var kc = KeyPress.keyCode;
	var i = js_IndexOfField(FieldName)
	var s = document.MeForm[i].value;
	s = js_FieldClean(s,"/");
	var Size = s.length;
	if (Size < 6 && kc != 8)	{ Size = s.length + 1 ; }
	if (kc == 8 )			{ Size = Size - 1 ; }
	if ( kc != 9 && kc != 8 ){
		if ( Size > 2 ) {
			document.MeForm[i].value = s.substr( 0, 2  ) + '/' + s.substr( 2, 6 );
		}
	}
}
function js_fmtNro(s,d) {
	if (typeof(s) == 'undefined' || s == '' ) { return (''); } 
	if (typeof(d) == 'undefined') d = 2;  
	if (s.length <= d) { return (s); } 
	s = s.toString();
	var j, sf = '', size = s.length-1;
	d = d - 1;
	j = d + 3;
	for (var i = 0 ; i <= size ; i++) {
		sf = s.substr(size - i, 1) + sf;
		if ( i == d && i < size ) sf = '.' + sf;
		if ( i == j && i < size ) {sf = ',' + sf; j += 3;}
	}
	return (sf);
}
function js_ValidTxt(vTxt, bDefault){  	/* revisada em 13ago2001 */
	if (typeof(vTxt) == "undefined") { vTxt = "";}
	if (typeof(bDefault) == "undefined") { bDefault = false; }
	if (vTxt + "" == "" ) { return bDefault; }
	for (var i=0 ; i < vTxt.length; i++) {
		if (vTxt.charCodeAt(i) > 255 ) { return false; }
	}
	return true;
}
function js_ValidNro(vTxt, bDefault, nMin, nMax){
	if (typeof(vTxt) == "undefined") { vTxt = "";}
	if (typeof(bDefault) == "undefined") { bDefault = false;}
	if (typeof(nMin) == "undefined") { nMin = Number.NEGATIVE_INFINITY;}
	if (typeof(nMax) == "undefined") { nMax = Number.POSITIVE_INFINITY;}
	if (vTxt + "" == "") { return bDefault; }
	vTxt = js_FieldClean(vTxt,",");
	if (isNaN(vTxt)) { return false; }
	if (parseFloat(vTxt) < parseFloat(nMin)) { return false; }
	if (parseFloat(vTxt) > parseFloat(nMax)) { return false; }
	return true;
}
function js_ValidBrDate(vDta, bDefault){
	if (typeof(vDta) == "undefined") { vDta = ""; }
	if (typeof(bDefault) == "undefined") { bDefault = false; }
	if (vDta + "" == "" && bDefault) { return bDefault;	}
	if (vDta.length != 10) { return false; }
	if (vDta.substr(2,1) != "/" || vDta.substr(5,1) != "/") { return false; }
	var vEndMonthDay = new String("312831303130313130313031");
	var nYear = parseInt(vDta.substr(6,4),10);
	if (isNaN(nYear) || nYear < 1753 || nYear > 2079) { return false; }
	var nMonth = parseInt(vDta.substr(3,2),10);
	if (isNaN(nMonth) || nMonth < 1 || nMonth > 12) { return false; }
	var nLastDay = parseInt(vEndMonthDay.substr( (nMonth - 1) * 2, 2),10);
	if (nMonth == 2 && nYear % 4 == 0) { nLastDay = 29; }
	var nDay = parseInt(vDta.substr(0,2),10);
	if (isNaN(nDay) || nDay < 1 || nDay > nLastDay) { return false; }
	return true;
}
	