function ProdutosOnload(){LoadPesquisaPRD()}

function LoadPesquisaPRD(){
	var url="PRO_Box_ListaProd_AJX.asp?ID="+Math.random()+"&O=PRDLOD"; 		
	xmlHttp_Prd_Load = GetXmlHttpObject(stChged_Load); 
	xmlHttp_Prd_Load.open("GET", url , true); 
	xmlHttp_Prd_Load.send(null);
	}

function stChged_Load()
{ 
	if (xmlHttp_Prd_Load.readyState==4 || xmlHttp_Prd_Load.readyState=="complete") 
	{ 
		var rsp_Prd 				= xmlHttp_Prd_Load.responseText; 
		var rsp_PrdIndice 		= rsp_Prd.split("#!#");
		
		// var rsp_PrdFamilia 		= rsp_PrdIndice[0].split("#@#");
		var rsp_PrdCategoria		= rsp_PrdIndice[1].split("#@#");
		var rsp_PrdSubcategoria	= rsp_PrdIndice[2].split("#@#");
		
		// monta a familia
		//document.getElementById('Prd_Familia').options[0] = new Option('',''); 
		//var b		= 1; 
		//var ind_fam	= '-';
		//for(a=0;a<=(rsp_PrdFamilia.length-1);a+=2)
		//{
		//	if (rsp_PrdFamilia[a+1].substring(0,3) == "!!!") 
		//		{
		//		document.getElementById('Prd_Familia').options[b] = new Option(rsp_PrdFamilia[a+1].substring(3),rsp_PrdFamilia[a]); 
		//		ind_fam = b;
		//		}
		//	else
		//		{
		//		document.getElementById('Prd_Familia').options[b] = new Option(rsp_PrdFamilia[a+1],rsp_PrdFamilia[a]); 
		//		}
		//	b+=1;
		//}
		//if (ind_fam !='-') {document.getElementById('Prd_Familia').options[ind_fam].selected = true;}
		
		if (rsp_PrdIndice[1] != '-') // se tiver familia setada
		{ 
			//monta categorias
			document.getElementById('Prd_Categoria').options[0] = new Option('',''); 
			var b		= 1; 
			var ind_cat	= '-';
			for(a=0;a<=(rsp_PrdCategoria.length-1);a+=2)
			{
				if (rsp_PrdCategoria[a+1].substring(0,3) == "!!!") 
					{
					document.getElementById('Prd_Categoria').options[b] = new Option(rsp_PrdCategoria[a+1].substring(3),rsp_PrdCategoria[a]); 
					ind_cat = b;
					}
				else
					{
					document.getElementById('Prd_Categoria').options[b] = new Option(rsp_PrdCategoria[a+1],rsp_PrdCategoria[a]); 
					}	
				b+=1;
			}
			if (ind_cat !='-') {document.getElementById('Prd_Categoria').options[ind_cat].selected = true;}
			
			if (rsp_PrdIndice[2] != '-') //se tiver categoria setada
			{
				// libera o botão de pesquisa
				LiberaPesquisa('SIM');
				// monta subcategorias
				document.getElementById('Prd_SubCategoria').options[0] = new Option('',''); 
				var b		= 1; 
				var ind_sub	= '-';
				for(a=0;a<=(rsp_PrdSubcategoria.length-1);a+=2)
				{
					if (rsp_PrdSubcategoria[a+1].substring(0,3) == "!!!") 
						{
						document.getElementById('Prd_SubCategoria').options[b] = new Option(rsp_PrdSubcategoria[a+1].substring(3),rsp_PrdSubcategoria[a]); 
						ind_sub = b;
						}
					else
						{
						document.getElementById('Prd_SubCategoria').options[b] = new Option(rsp_PrdSubcategoria[a+1],rsp_PrdSubcategoria[a]); 
						}	
					b+=1;
				}
				if (ind_sub !='-') {document.getElementById('Prd_SubCategoria').options[ind_sub].selected = true;}
			}
			else //senao
			{
				DesabilitaCampoPrd('Prd_SubCategoria'); // desabilita subcategoria
				LiberaPesquisa('NAO');
			}	
		}
		else // senao
		{		
			DesabilitaCampoPrd('Prd_Categoria'); // desabilita categoria
			DesabilitaCampoPrd('Prd_SubCategoria'); // desabilita subcategoria
			LiberaPesquisa('NAO');
		}
	}
}	

//------------------------------------------------

function HabilitaCampoPrd(HCampoPrd) 
{
	document.getElementById(HCampoPrd).disabled = false;
}
	
function DesabilitaCampoPrd(DCampoPrd) 
{
	document.getElementById(DCampoPrd).length = 1;
	document.getElementById(DCampoPrd).options[0]=new Option('','');
	document.getElementById(DCampoPrd).disabled = true;
}
	
function LiberaPesquisa(v_resposta) { if(v_resposta == 'SIM')	{var rsp_pesquisa="<a href=javascript:PesquisarPrd()><img src=Images/bt_exibir.gif width=55 height=15 border=0></a>";} else {var rsp_pesquisa="<img src=Images/bt_exibir_off.gif width=55 height=15 border=0>";} document.getElementById('s_PesquisarPrd').innerHTML=rsp_pesquisa; }

//-----------------------------------------------------------------------------------------

function PesquisarPrd()
{
	var url="PRO_Box_ListaProd_AJX.asp?ID="+Math.random()+"&O=SCHPRD&CT="+document.getElementById('Prd_Categoria').value+"&SB="+document.getElementById('Prd_SubCategoria').value; 
	xmlHttp_SrcPrd=GetXmlHttpObject(stChged_PesquisarPrd); 
	xmlHttp_SrcPrd.open("GET", url , true); 
	xmlHttp_SrcPrd.send(null);
}

//-----------------------------------------------------------------------------------------

function stChged_PesquisarPrd()
{
	if (xmlHttp_SrcPrd.readyState==4 || xmlHttp_SrcPrd.readyState=="complete")
	{
		var rsp_retornoPrd = xmlHttp_SrcPrd.responseText; 
		if(rsp_retornoPrd == 'OK')
		{
			window.location="PRO_Produtos_Relacao.asp?ID="+Math.random()+"&CAT_Ukey="+document.getElementById('Prd_Categoria').value+"&SUB_Ukey="+document.getElementById('Prd_SubCategoria').value; 
		}
	}
}

//-----------------------------------------------------------------------------------------

function popPrdCategoria(){
	if (document.getElementById('Prd_Familia').value =='-' || document.getElementById('Prd_Familia').value == '') 
	{
		DesabilitaCampoPrd('Prd_Categoria'); 		// desabilita categoria
		DesabilitaCampoPrd('Prd_SubCategoria'); 	// desabilita subcategoria
		LiberaPesquisa('NAO');
	}
	else
	{
		DesabilitaCampoPrd('Prd_SubCategoria'); 	// desabilita subcategoria
		HabilitaCampoPrd('Prd_Categoria'); 			// habilita categoria
		LiberaPesquisa('NAO');
		var url="PRO_Box_ListaProd_AJX.asp?ID="+Math.random()+"&O=PRDCAT&FM="+document.getElementById('Prd_Familia').value;
		xmlHttp_Prd_Cat=GetXmlHttpObject(stChged_popPrdCategoria); 
		xmlHttp_Prd_Cat.open("GET", url , true); 
		xmlHttp_Prd_Cat.send(null)
	}
	}

function stChged_popPrdCategoria(){
	if (xmlHttp_Prd_Cat.readyState==4 || xmlHttp_Prd_Cat.readyState=="complete"){
		var rsp_Prd_Cat=xmlHttp_Prd_Cat.responseText;
		if(rsp_Prd_Cat != '-')
		{
			HabilitaCampoPrd('Prd_Categoria'); 			// habilita categoria
			LiberaPesquisa('NAO');
			splitString=rsp_Prd_Cat.split("#@#"); 
			document.getElementById('Prd_Categoria').length = (splitString.length/2);
			document.getElementById('Prd_Categoria').options[0]=new Option('',''); 
			var ind_Categoria 	= '-';
			var b				= 1; 
			for(a=0;a<=(splitString.length-1);a+=2)
			{
				document.getElementById('Prd_Categoria').options[b]=new Option(splitString[a+1],splitString[a]); 
				if (splitString[a+1].substring(0,3) == "!!!") 
					{ 
					var ind_Categoria = b; 
					}
				b+=1;
			}
			if (ind_Categoria !='-') {document.getElementById('Prd_Categoria').options[ind_Categoria].selected = true;}
			}
		}
	}

//-----------------------------------------------------------------------------------------	
	
function popPrdSubCategoria() {
	
	if (document.getElementById('Prd_Categoria').value =='-' || document.getElementById('Prd_Categoria').value == '') 
	{
		DesabilitaCampoPrd('Prd_SubCategoria'); // desabilita subcategoria
		LiberaPesquisa('NAO');
	}
	else
	{
		HabilitaCampoPrd('Prd_SubCategoria'); 			// habilita subcategoria
		LiberaPesquisa('SIM');
		var url="PRO_Box_ListaProd_AJX.asp?ID="+Math.random()+"&O=PRDSUB&CT="+document.getElementById('Prd_Categoria').value;
		xmlHttp_Prd_SubCategoria=GetXmlHttpObject(stChged_popPrdSubCategoria); 
		xmlHttp_Prd_SubCategoria.open("GET", url , true); 
		xmlHttp_Prd_SubCategoria.send(null);
	}
}

function stChged_popPrdSubCategoria(){
	if (xmlHttp_Prd_SubCategoria.readyState==4 || xmlHttp_Prd_SubCategoria.readyState=="complete"){
		var rsp_PrdSubCat=xmlHttp_Prd_SubCategoria.responseText; 
		if(rsp_PrdSubCat != '-'){
			var b=0; 
			splitString=rsp_PrdSubCat.split("#@#"); 
			document.getElementById('Prd_SubCategoria').length = (splitString.length/2);
			document.getElementById('Prd_SubCategoria').options[0]=new Option('',''); 
			var ind_SubCategoria 	= 1;
			var b						= 1; 
			for(a=0;a<=(splitString.length-1);a+=2){
				
				if (splitString[a+1].substring(0,3) == "!!!") 
					{ 
					document.getElementById('Prd_SubCategoria').options[b]=new Option(splitString[a+1],splitString[a]); 
					var ind_SubCategoria = b; 
					}
				else
					{
					document.getElementById('Prd_SubCategoria').options[b]=new Option(splitString[a+1],splitString[a]); 
					//var ind_SubCategoria = b;
					}	
				b+=1;
			}
			//document.getElementById('Prd_SubCategoria').options[ind_SubCategoria].selected = true;
			if (b ==2) {	document.getElementById('Prd_SubCategoria').options[ind_SubCategoria].selected = true;}
			}
		}
	}


	

