String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
//**************************************************************************
function fGetTabla(){
Cod=document.getElementById("TxtCod").value;	
lpStrDes=document.getElementById("TxtDes").value;
//
Cod=Cod.replace("+", "@");
lpStrDes=lpStrDes.replace("+", "@");
//
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=KARDEX_PROD_FILTRAR&TxtPar="+lpStrDes+"&TxtPar3="+Cod);	
		ajax.onreadystatechange=function() {
			   if (ajax.readyState==4) {
				   		var StrDatos=ajax.responseText;
						if(StrDatos.trim().length>0){
																
							StrDatos = replaceAll(StrDatos,"@", "<tr class=\"zz\" ");
							StrDatos = replaceAll(StrDatos,"#", "</tr>");
							StrDatos = replaceAll(StrDatos,";", "</td>");
							StrDatos = replaceAll(StrDatos,"%", "<td>");
							StrDatos = replaceAll(StrDatos,":", "ondblclick=");
							
							DivDatos.innerHTML = StrDatos;
							DivCaption.style.visibility="visible";
							DivDatos.style.visibility="visible";	
							document.getElementById("TAB_AJAX").scrollTop=0;
							
							PINTAR_ZZ();
						}else{
							DivCaption.style.visibility="hidden";
							DivDatos.style.visibility="hidden";	
						}
			   }
		}
		ajax.send(null);
	}
}
//**************************************************************************

function PINTAR_ZZ(){
	//alert("OK1");
	$('.zz').focus(function() {	
		this.style.backgroundColor="#FFCC00";
	}).blur(function() {
	   this.style.backgroundColor="white";
	});
	$('.zz').keydown(function(e) {
		if(e.which == 40) {
			var r=this.id;
			r=r.replace("z","");
			r=parseInt(r)+1;
			try {
				document.getElementById("z"+r).focus();
				e.preventDefault();
			} catch (e) {
				
			}
		}

		if(e.which == 38) {
			var r=this.id;
			r=r.replace("z","");
			r=parseInt(r)-1;
			if(r==0){
				r=1;
			}
			document.getElementById("z"+r).focus();
			e.preventDefault();
		}
		if(e.which == 13) {
			this.ondblclick();
			e.preventDefault();
		}
		if(e.which == 27) {
			CerrarDIV();			
			e.preventDefault();
			sv("TxtHora","0");
		}
	});	
	//alert("OK2");
}
//**************************************************************************

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 fGetProdDatos_Id(lpStrId){
	if(lpStrId>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();				   
				   }
				   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 Alm=document.getElementById("CboAlm").value;
	var IdPro=document.getElementById("Pro_TxtId").value;	
	var Des=document.getElementById("TxtDes").value;
	
	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(Des.trim().length==0){
		alert("No se puede determinar el producto seleccionado, vuelva a seleccionar");
		document.getElementById("TxtDes").focus();
		return;
	}	
	document.getElementById("TxtAc").value="G";
	document.getElementById("Frm").submit();
}
//**************************************************************************

//**************************************************************************
function cCod(e){	
	var k;
	k=(document.all) ? e.keyCode :e.which;
	DivDatos = document.getElementById("TAB_AJAX");
	DivCaption = document.getElementById("TAB_CAPTION");
	if(k==40){
		if(DivDatos.style.visibility!="hidden"){
			document.getElementById("z1").focus();
			event.preventDefault();
			
		}
		return true;
	}
	if(k==13){
		var cod=gv("TxtCod");		
		/*if(cod==""){
			//jF("TxtDes");				
			return;			
		}*/
		event.preventDefault();
		return true;
	}
}
function cCodUP(e){	
	var k;
	k=(document.all) ? e.keyCode :e.which;	
	if(k==40 || k==27 || k==13){
		
	}else{
		sv('TxtHora',GetHora());
	}
}
//**************************************************************************
function cDes(e){	
	var k;
	k=(document.all) ? e.keyCode :e.which;
	DivDatos = document.getElementById("TAB_AJAX");
	DivCaption = document.getElementById("TAB_CAPTION");
	if(k==40){
		if(DivDatos.style.visibility!="hidden"){
			document.getElementById("z1").focus();
			event.preventDefault();			
		}
		return true;
	}
	if(k==13){
		//jF("TxtPre");		
		DivCaption.style.visibility="hidden";
		DivDatos.style.visibility="hidden";	
		event.preventDefault();
		return true;
	}
}
function cDesUP(e){	
	var k;
	k=(document.all) ? e.keyCode :e.which;	
	if(k==40 || k==27 || k==13){
		
	}else{
		sv('TxtHora',GetHora());
	}
}
//**************************************************************************
