// JavaScript Document
function change_area(cod_album) {
	var aux1 = $('categoria')
	if ( cod_album == '' ) {
		var tamanho = categoria.length;
		aux1.length = 0;
		var before = '';
		aux1.options[aux1.options.length] = new Option('','');
		for ( var i = 0; i < tamanho; i++ ) {
			if ( i == 0 || before != categoria[i][2] ) {
				for ( var x = 0; x < area.length; x++ ) {
					if ( categoria[i][2] == area[x][0] ) {
						aux1.options[aux1.options.length] = new Option(area[x][1],'');
						aux1.options[aux1.options.length-1].className = 'texto_d1';
						aux1.options[aux1.options.length-1].style.fontWeight = 'bold';
						break;
					}
				}
			}
			if ( ie ) {
				aux1.options[aux1.options.length] = new Option("     "+categoria[i][1],categoria[i][0]);	
			}
			else {
				aux1.options[aux1.options.length] = new Option(categoria[i][1],categoria[i][0]);
				aux1.options[aux1.options.length-1].style.paddingLeft = '10px';
			}
			before = categoria[i][2];
		}
		change_categ('');
	}
	else {
		var tamanho = categoria.length;
		aux1.length = 0;
		aux1.options[aux1.options.length] = new Option('','');
		for ( var i = 0; i < tamanho; i++ ) {
			if ( categoria[i][2] == cod_album ) {
				aux1.options[aux1.options.length] = new Option(categoria[i][1],categoria[i][0]);
			}
		}
	}
}

function check_pesq_docs() {
	if ( $F('pesq_docs') == '' && $('categoria').value == '' && $('area').value == '' ) {
		return false;
	}
	else {
		return true;
	}
}

function check_pesquisa() {
	if ( $F('pesq_advan') == '' && $('categoria').value == '' && $('area').value == '' ) {
		return false;
	}
	else {
		return true;
	}
}





/* NOVAS */ 
function select_categoria(cod_sub_categ) {
	var categ = $('categoria');
	if ( cod_sub_categ == '' ) {
		categ.selectedIndex = 0;
	}
	else {
		var aux = cod_sub_categ.split('_');
		var s = categ.length;
		for ( var i = 0; i < s; i++ ) {
			if ( categ.options[i].value == aux[0] ) {
				categ.selectedIndex = i;
				break;
			}
		}
	}
}

function select_categoria_global(cod_sub_categ) {
	var categ = $('categoria');
	if ( cod_sub_categ == '' ) {
		categ.selectedIndex = 0;
	}
	else {
		var aux = cod_sub_categ.split('_');
		var s = categ.length;
		for ( var i = 0; i < s; i++ ) {
			if ( categ.options[i].value == aux[0] ) {
				categ.selectedIndex = i;
				break;
			}
		}
		change_categoria(aux[0]);
	}
}

function change_categ(categ) {
	var subc = $('sub_categoria');
	if ( categ == '' ) { //Preencher os outros todos
		subc.length = 0;
		var s = sub_categoria.length;
		var before = 0;
		subc.options[subc.options.length] = new Option('','');
		for ( var i = 0; i < s; i++ ) {
			if ( i == 0 || before != sub_categoria[i][2] ) {
				for ( var x = 0; x < $('categoria').options.length; x++ ) {
					if ( $('categoria').options[x].value == sub_categoria[i][2] ) {
						subc.options[subc.options.length] = new Option($('categoria').options[x].innerHTML.replace(/&nbsp;/g,""),'');
						subc.options[subc.options.length-1].className = 'texto_d1';
						subc.options[subc.options.length-1].style.fontWeight = 'bold';
						break;	
					}
				}
			}
			if ( ie ) {
				subc.options[subc.options.length] = new Option("     "+sub_categoria[i][1],sub_categoria[i][2]+'_'+sub_categoria[i][0]);	
			}
			else {
				subc.options[subc.options.length] = new Option(sub_categoria[i][1],sub_categoria[i][2]+'_'+sub_categoria[i][0]);
				subc.options[subc.options.length-1].style.paddingLeft = '10px';
			}
			before = sub_categoria[i][2]; 
		}
	}
	else {
		subc.length = 0;
		var s = sub_categoria.length;
		subc.options[subc.options.length] = new Option('','');
		for ( var i = 0; i < s; i++ ) {
			if ( categ == sub_categoria[i][2] ) {
				subc.options[subc.options.length] = new Option(sub_categoria[i][1],sub_categoria[i][2]+'_'+sub_categoria[i][0]);
			}
		}
	}
}

function change_categ_global(categ) {
	var subc = $('sub_categoria');
	if ( categ == '' ) { //Preencher os outros todos
		subc.length = 0;
		var s = sub_categoria.length;
		var before = 0;
		subc.options[subc.options.length] = new Option('','');
		for ( var i = 0; i < s; i++ ) {
			if ( i == 0 || before != sub_categoria[i][2] ) {
				for ( var x = 0; x < $('categoria').options.length; x++ ) {
					if ( $('categoria').options[x].value == sub_categoria[i][2] ) {
						subc.options[subc.options.length] = new Option($('categoria').options[x].innerHTML.replace(/&nbsp;/g,""),'');
						subc.options[subc.options.length-1].className = 'texto_d1';
						subc.options[subc.options.length-1].style.fontWeight = 'bold';
						break;	
					}
				}
			}
			if ( ie ) {
				subc.options[subc.options.length] = new Option("     "+sub_categoria[i][1],sub_categoria[i][2]+'_'+sub_categoria[i][0]);	
			}
			else {
				subc.options[subc.options.length] = new Option(sub_categoria[i][1],sub_categoria[i][2]+'_'+sub_categoria[i][0]);
				subc.options[subc.options.length-1].style.paddingLeft = '10px';
			}
			before = sub_categoria[i][2]; 
		}
	}
	else {
		change_categoria(categ);
		subc.length = 0;
		var s = sub_categoria.length;
		subc.options[subc.options.length] = new Option('','');
		for ( var i = 0; i < s; i++ ) {
			if ( categ == sub_categoria[i][2] ) {
				subc.options[subc.options.length] = new Option(sub_categoria[i][1],sub_categoria[i][2]+'_'+sub_categoria[i][0]);
			}
		}
	}
}

function change_categoria(cod_cat) {
	var aux = $('area');
	if ( cod_cat == '' ) {
		aux.selectedIndex = 0;
	}
	else {
		var aux1 = categoria.length;
		for ( var i = 0; i < aux1; i++ ) {
			if ( categoria[i][0] == cod_cat ) {
				aux1 = $('area').length;
				for ( var x = 0; x < aux1; x++ ) {
					if ( $('area').options[x].value == categoria[i][2] ) {
						$('area').selectedIndex = x;
						break;	
					}
				}
				break;
			}
		}
	}
}
