function delGrid(tab){
	var form = "formList"+tab;
	eval("document."+form).delAll.value='1';
	eval("document."+form).tab.value=tab;
	eval("document."+form).submit();
}
function selectAll(tab,fields){
	var form = "formList"+tab;
	for(i = 0; i < fields; i++){
		var field = "del"+i;
		var line = tab+"Line"+i;
		document.getElementById(line).style.background = "#BFC4C4";
		eval("document."+form+"."+field).checked = true;
	}
}
function revertSelection(tab,fields){
	var form = "formList"+tab;
	for(i = 0; i < fields; i++){
		var field = "del"+i;
		var line = tab+"Line"+i;
		document.getElementById(line).style.background = "white";
		eval("document."+form+"."+field).checked = false;
	}
}
function changeLineColor(tab,field,line){
	var form = "formList"+tab;
	if(eval("document."+form+"."+field).checked == true){
		document.getElementById(line).style.background = "#BFC4C4";
	}
	else
		document.getElementById(line).style.background = "white";
}
function changeBg(type,line,field,tab,multiOff){
	var form = "formList"+tab;
	var fieldNumber = field.split('del');
	fieldNumber = fieldNumber[1];
	if(multiOff != "true"){	
		if(eval("document."+form+"."+field) && eval("document."+form+"."+field).checked == false){
			if(type == 'on')
				document.getElementById(line).style.background = "#BFC4C4";
			else
				if(fieldNumber % 2 != 0)
					document.getElementById(line).style.background = "white";
				else
					document.getElementById(line).style.background = "#F0F0F0";
		}
	}else{
		if(type == 'on')
			document.getElementById(line).style.background = "#BFC4C4";
		else
			if(fieldNumber % 2 != 0)
				document.getElementById(line).style.background = "white";
			else
				document.getElementById(line).style.background = "#F0F0F0";
	}
}
function goInsertView(){
	window.location("?cmd=insertView");
	var form = "formList"+tab;
	eval("document."+form).submit();
}
function onCancel(){
	window.location = "?action=dataGrid";
}
function changePage(tab){
	var form = "formList"+tab;
	eval("document."+form).page.value = eval("document."+form).pages.value;
	eval("document."+form).submit();
}
function mascaraData(campoData){              
	var data = campoData.value; 
	if (data.length == 2){                  
		data = data + '/';
		document.getElementById(campoData.name).value = data;      
		return true;                            
	}              
	if (data.length == 5){                  
		data = data + '/';                  
		document.getElementById(campoData.name).value = data;      
		return true;              
	}
    return false;
}


function abreMenu(idMenu,nMenus) 
{
	document.getElementById('subMenu').style.display = "block";
	for(var i = 1; i <= nMenus; i++){
		if(i != idMenu)
			document.getElementById(i).style.display = "none";	
		else
			if(document.getElementById(i).style.display = "none")
				document.getElementById(i).style.display = "block";	
			else
				document.getElementById(i).style.display = "none";	
	}	
}
function fechaMenu(name) {
	document.getElementById(name).style.display = "none";
	document.getElementById('subMenu').style.display = "none";
}
function onDel(condition){
	if(confirm("Deseja realmente DESTRUIR este registro?"))
		window.location = "?action=del&"+condition;
}
// public method for url encoding
function encode(string) {
	string = string.replace(/\r\n/g,"\n");
	var utftext = "";

	for (var n = 0; n < string.length; n++) {

		var c = string.charCodeAt(n);

		if (c < 128) {
			utftext += String.fromCharCode(c);
		}
		else if((c > 127) && (c < 2048)) {
			utftext += String.fromCharCode((c >> 6) | 192);
			utftext += String.fromCharCode((c & 63) | 128);
		}
		else {
			utftext += String.fromCharCode((c >> 12) | 224);
			utftext += String.fromCharCode(((c >> 6) & 63) | 128);
			utftext += String.fromCharCode((c & 63) | 128);
		}

	}

	return utftext;
}

    // public method for url decoding
function decode(utftext) {
	var string = "";
	var i = 0;
	var c = c1 = c2 = 0;

	while ( i < utftext.length ) {

		c = utftext.charCodeAt(i);

		if (c < 128) {
			string += String.fromCharCode(c);
			i++;
		}
		else if((c > 191) && (c < 224)) {
			c2 = utftext.charCodeAt(i+1);
			string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
			i += 2;
		}
		else {
			c2 = utftext.charCodeAt(i+1);
			c3 = utftext.charCodeAt(i+2);
			string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
			i += 3;
		}

	}

	return string;
}
			
