String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

//**************************************************************************
function fCancelar(){
	document.getElementById("TxtAc").value="L";
	document.getElementById("Frm").submit();
}
//**************************************************************************
function fLimDet(){
	document.getElementById("D_Cod").value="";
	document.getElementById("D_Des").value="";
	document.getElementById("D_Lin").value="";
	document.getElementById("D_Caj").value="";
	document.getElementById("D_Pie").value="";
	document.getElementById("D_Can").value="";
	document.getElementById("D_Cod").focus();
}
//**************************************************************************
function fFiltrar(){
	document.getElementById("TxtAc").value="F";
	document.getElementById("Frm").submit();
}
//**************************************************************************
function fGenPDF(){
	document.getElementById("TxtAc").value="GEN_PDF_1";
	document.getElementById("Frm").submit();
}
//**************************************************************************
function fKiller(lpIndex){
	document.getElementById("TxtKill").value=lpIndex;
	document.getElementById("TxtAc").value="KILLER";
	document.getElementById("Frm").submit();
}

function fEditar(lpIndex,StrHW){
	var hw=document.getElementById("TxtHW").value;
	Ow("ajustes_piezas_editar.php?I="+lpIndex+"&H="+StrHW,550*ZO(),280*ZO());	
}

function fLoad(){
	document.getElementById("TxtAc").value="UP";
	document.getElementById("Frm").submit();
}
//**************************************************************************
function fGetTabla(){
var Cod = document.getElementById("D_Cod").value;
var Des = document.getElementById("D_Des").value;
var Mar = document.getElementById("D_Lin").value;
var Alm = document.getElementById("CboAlm").value;

if(Des.trim().length>0 || Mar.trim().length>0 || Cod.trim().length>0){
	DivDatos = document.getElementById("TAB_AJAX");
	DivCaption = document.getElementById("TAB_CAPTION");
	ajax=CreateAJAX();
	var StrU="aj_aju.php?C=T&P1="+Des+"&P2="+Mar+"&P3="+Cod+"&P4="+Alm;
	ajax.open("GET", StrU);	
	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("D_Des").focus();
}

//**************************************************************************
function z(lpStrId){
	fGetProdDatos_Id(lpStrId);
}
//**************************************************************************
function fGetProdDatos_Id(lpStrId){
	if(lpStrId.trim().length>0){
	//
	var ip=lpStrId.indexOf(".");
	var IDD=lpStrId.substring(0,ip);	
	var UNI=lpStrId.substring(ip+1,jLen(lpStrId));
	//
	DivDatos = document.getElementById("DivDatosProd");
	ajax=CreateAJAX();
	ajax.open("GET", "ajax_funciones.php?Cmd=COMPRAS_GET_PROD_DATOS_X_ID&TxtPar="+IDD);	
	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("Pro_TxtMarca").value="";
					   document.getElementById("TxtDes").value="";  				  	   
					   document.getElementById("TxtCant").value="";
					   document.getElementById("TxtMarca").value="";
					   document.getElementById("TxtCod").value="";
					   document.getElementById("TxtUCAN").value="";				   
					   alert("Codigo no registrado");
					   document.getElementById("TxtCod").focus();
				   }else{
	
						document.getElementById("D_Lin").value=document.getElementById("Pro_TxtMarca").value;
						document.getElementById("D_Cod").value=document.getElementById("Pro_TxtCod").value;
						document.getElementById("D_Des").value=document.getElementById("Pro_TxtDes").value;
						document.getElementById("D_Pie").value=UNI;
						document.getElementById("D_Caj").value="1";
						document.getElementById("D_Can").value="1";
						document.getElementById("D_Caj").focus();	
			   
				   }
				   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=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("Pro_TxtMarca").value="";
   				   document.getElementById("TxtDes").value="";
				   document.getElementById("TxtMarca").value="";
				   document.getElementById("TxtCant").value="";
				   document.getElementById("TxtCod").value="";				   
				   alert("Codigo no registrado");
				   document.getElementById("TxtCod").focus();
				   }else{
document.getElementById("TxtMarca").value=document.getElementById("Pro_TxtMarca").value;
document.getElementById("TxtDes").value=document.getElementById("Pro_TxtDes").value;
document.getElementById("TxtCant").value="1";
document.getElementById("TxtCant").focus();
				   }
				   
		   }
	}
    ajax.send(null);
	}
}
//**************************************************************************
function fCancelarPHP(){
	document.getElementById("TxtAc").value="C";
	document.getElementById("Frm").submit();
}
//**************************************************************************
function fAgregar(){	
	var Cod=document.getElementById("D_Cod").value;
	var D_Caj=document.getElementById("D_Caj").value;
	var D_Pie=document.getElementById("D_Pie").value;
	var D_Can=document.getElementById("D_Can").value;
	
	if(Cod.trim().length==0){
		alert("Seleccione un producto");
		document.getElementById("D_Cod").focus();
		return;
	}

	if(D_Caj.trim().length==0){
		alert("Ingrese Una Cantidad");
		document.getElementById("D_Caj").focus();
		return;
	}

	if(D_Pie.trim().length==0){
		alert("Ingrese Una Cantidad");
		document.getElementById("D_Pie").focus();
		return;
	}

	if(D_Can.trim().length==0){
		alert("Ingrese Una Cantidad");
		document.getElementById("D_Can").focus();
		return;
	}

	document.getElementById("TxtAc").value="ADD";
	document.getElementById("Frm").submit();
}
//**************************************************************************
function fGuardar(){
	var Emp=gv("CboEmp");
	var Alm=document.getElementById("CboAlm").value;
	var Acc=document.getElementById("CboAcc").value;
	var Fec=document.getElementById("TxtFec").value;
	var Num=document.getElementById("TxtNum").value;
	if(jL(Emp)==0){
		alert("Seleccione una empresa");
		return jF("CboEmp");
	}
	if(Fec.trim().length==0){
		alert("Ingrese una fecha");
		document.getElementById("TxtFec").focus();
		return;
	}
	if(EsFecha(Fec)==false){
		alert("Fecha no valida, la fecha debe ser ingresada segun el formato");
		document.getElementById("TxtFec").focus();
		return;
	}
	if(Alm.trim().length==0){
		alert("Seleccione el almacen");
		document.getElementById("CboAlm").focus();
		return;
	}	
	
	if(Acc.trim().length==0){
		alert("Seleccione la accion correspondiente");
		document.getElementById("CboAcc").focus();
		return;
	}	
	if(document.getElementById("CmdG").value=="Guardar"){
		var Rpta = confirm("Esta seguro que desea guardar?")		
		if (Rpta==false){
			return;
		}
		document.getElementById("TxtAc").value="G";
	}else{
		var Rpta = confirm("Esta seguro que desea modificar?")		
		if (Rpta==false){
			return;
		}
		document.getElementById("TxtAc").value="M";
	}
	document.getElementById("Frm").submit();
}
/**************************************************************************
	onkeypress="return pulsar(event);"
**************************************************************************/
function pulsar(e) { 	
	var tecla = (document.all) ? e.keyCode :e.which; 
	var Obj=event.srcElement.name;	
	if(Obj=="TxtNom"){
		if(tecla==13){			
			document.getElementById('CmdG').click();			
		}
	}	
	return (tecla!=13); 
} 
//**************************************************************************
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);
	}
}
