String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
//**************************************************************************
function fGetTabla(){
Cod=document.getElementById("TxtCod").value;	
lpStrDes=document.getElementById("TxtDes").value;
DivDatos = document.getElementById("TAB_AJAX");
DivCaption = document.getElementById("TAB_CAPTION");

	if(lpStrDes.trim().length>0 || Cod.trim().length>0){
		ajax=CreateAJAX();
		ajax.open("GET", "ajax_funciones.php?Cmd=K_PROD_FILTRAR&TxtPar="+lpStrDes+"&TxtPar3="+Cod);	
		ajax.onreadystatechange=function() {
			   if (ajax.readyState==4) {
				   		var StrDatos=ajax.responseText;
						if(StrDatos.trim().length>0){			  
						   DivDatos.innerHTML = StrDatos;
						   DivCaption.style.visibility="visible";
						   DivDatos.style.visibility="visible";	
						}else{
							DivCaption.style.visibility="hidden";
							DivDatos.style.visibility="hidden";	
						}
			   }
		}
		ajax.send(null);
	}
}
function CerrarDIV(){
	DivDatos = document.getElementById("TAB_AJAX");
	DivCaption = document.getElementById("TAB_CAPTION");
	DivCaption.style.visibility="hidden";
	DivDatos.style.visibility="hidden";	
	document.getElementById("TxtDes").focus();
}
//**************************************************************************
function z(lpStrId){
	fGetProdDatos_Id(lpStrId);
}
//**************************************************************************
function GetPie(){
	var Alm=document.getElementById("CboAlm").value;
	var Cod=document.getElementById("TxtCod").value;
	CBO_CLS('CboPre');
	var URL="aj.php?Cmd=LP&P1="+Alm+"&P2="+Cod;	
	var R=AJ(URL);	
	if(jLen(R)>0){
		CBO_FILL('CboPre',R);
	}
}

function fGetProdDatos_Id(lpStrId){
	if(lpStrId.trim().length>0){
	DivDatos = document.getElementById("DivDatosProd");
	ajax=CreateAJAX();
	ajax.open("GET", "ajax_funciones.php?Cmd=COMPRAS_GET_PROD_DATOS_X_ID&TxtPar="+lpStrId);	
	ajax.onreadystatechange=function() {
		   if (ajax.readyState==4) {			  
				   DivDatos.innerHTML = ajax.responseText
				   var Des=document.getElementById("Pro_TxtDes").value;
				   if(Des.trim().length==0){
   				   document.getElementById("Pro_TxtId").value="";
				   document.getElementById("Pro_TxtDes").value="";
				   document.getElementById("Pro_TxtCod").value="";
				   document.getElementById("Pro_TxtPre").value="";
   				   document.getElementById("TxtDes").value="";
				   document.getElementById("TxtCod").value="";				   
				   alert("Codigo no registrado");
				   document.getElementById("TxtCod").focus();
				   }else{
document.getElementById("TxtCod").value=document.getElementById("Pro_TxtCod").value;
document.getElementById("TxtDes").value=document.getElementById("Pro_TxtDes").value;
document.getElementById("TxtDes").focus();				   
GetPie();
				   }
				   DivDatos = document.getElementById("TAB_AJAX");
				   DivCaption = document.getElementById("TAB_CAPTION");
				   DivCaption.style.visibility="hidden";
				   DivDatos.style.visibility="hidden";		
				   		   
		   }
	}
    ajax.send(null);
	}
}
//**************************************************************************
function fGetProdDatos(lpStrCod){
	if(lpStrCod.trim().length>0){
	DivDatos = document.getElementById("DivDatosProd");
	ajax=CreateAJAX();
	ajax.open("GET", "ajax_funciones.php?Cmd=VEN_GET_PROD_DATOS&TxtPar="+lpStrCod);	
	ajax.onreadystatechange=function() {
		   if (ajax.readyState==4) {			  
				   DivDatos.innerHTML = ajax.responseText
				   var Des=document.getElementById("Pro_TxtDes").value;
				   if(Des.trim().length==0){
   				   document.getElementById("Pro_TxtId").value="";
				   document.getElementById("Pro_TxtDes").value="";
				   document.getElementById("Pro_TxtPre").value="";
   				   document.getElementById("TxtDes").value="";
				   document.getElementById("TxtCod").value="";				   
				   alert("Codigo no registrado");
				   document.getElementById("TxtCod").focus();
				   }else{					   
document.getElementById("TxtDes").value=document.getElementById("Pro_TxtDes").value;
document.getElementById("TxtDes").focus();
				   }
				   
		   }
	}
    ajax.send(null);
	
	}
}
//**************************************************************************
function fGetRuc(lpStrPro,Obj){
	var StrProveedor=lpStrPro;
	ajax=CreateAJAX();
	ajax.open("GET", "ajax_funciones.php?Cmd=GET_RUC&TxtPar="+StrProveedor);	
	ajax.onreadystatechange=function() {
		   if (ajax.readyState==4) {			   	   
				   document.getElementById(Obj).value=ajax.responseText;
				   Obj=Obj+"_";
				   document.getElementById(Obj).value=ajax.responseText;
		   }
	}
    ajax.send(null);
}
//**************************************************************************
function fCancelarPHP(){
	document.getElementById("TxtAc").value="C";
	document.getElementById("Frm").submit();
}
//**************************************************************************
function fGuardar(){
	var Emp=gv("CboEmp");
	var Alm=document.getElementById("CboAlm").value;
	var IdPro=document.getElementById("Pro_TxtId").value;	
	var Des=document.getElementById("TxtDes").value;
	var Cod=gv("TxtCod");
	var Des=gv("TxtDes");
	var Pre=gv("CboPre");
	if(jL(Emp)==0){
		alert("Seleccione una empresa");
		return jF("CboEmp");
	}
	if(Alm.trim().length==0){
		alert("Seleccione un almacen");
		document.getElementById("CboAlm").focus();
		return;
	}
	/*
	if(IdPro.trim().length==0){
		alert("No se puede determinar el Id de producto seleccionado, vuelva a seleccionar");
		document.getElementById("TxtDes").focus();
		return;
	}	
	*/
	if(jLen(Cod)==0){
		alert("Ingrese un codigo");
		jFocus("TxtCod");
		return;
	}
	if(Des.trim().length==0){
		alert("No se puede determinar el producto seleccionado, vuelva a seleccionar");
		document.getElementById("TxtDes").focus();
		return;
	}	
	if(jLen(Pre)==0){
		alert("Seleccione una presentacion");
		jFocus("CboPre");
		return;
	}
	document.getElementById("TxtAc").value="G";
	document.getElementById("Frm").submit();
}
//**************************************************************************
function EM_OC(){
	var Emp=gv("CboEmp");	
	var r=AX("02",Emp);
	if(r=="X"){
		CBO_CLS("CboAlm",1);
	}else{
		CBO_FILL("CboAlm",r,0);
	}
}
