String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
//**************************************************************************
function fFiltrar(){
	document.getElementById("TxtAc").value="F";
	document.getElementById("Frm").submit();
}
//**************************************************************************
function fCancelar(){
	FrmCls("TxtNom");
	//
	document.getElementById("CmdE").disabled =true;
	document.getElementById("CmdG").value="Guardar";
	document.getElementById("TxtId").value="";
	document.getElementById("TxtAc").value="";
}

function fGuardar(){
	var Nom=document.getElementById("TxtNom").value;
	var Ruc=document.getElementById("TxtRuc").value;
	if(Nom.trim().length==0){
		alert("Ingrese el nombre del Cliente");
		document.getElementById("TxtNom").focus();
		return;
	}
	if(Ruc.trim().length>0){
		if(Ruc.trim().length!=11){
			alert("El numero de ruc debe tener 11 digitos");
			document.getElementById("TxtRuc").focus();
			return;
		}
	}

	if(document.getElementById("CmdG").value=="Guardar"){
		document.getElementById("TxtAc").value="G";
	}else{
		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 fGetNIC(){	
	var DL=document.getElementById("DivLAST");	
	DL.innerHTML="";
	ajax=CreateAJAX();
	var StrU="sunat.php?C=C&P1=1";
	ajax.open("GET",StrU);	
	ajax.onreadystatechange=function() {
		   if (ajax.readyState==4) {
					var StrDatos=ajax.responseText;
					if(StrDatos.trim().length==0){
						alert("Ningun dato registrado");
					}else{
						DL.innerHTML=decodeURIComponent(StrDatos);
						document.getElementById("TxtNom").value=document.getElementById("CLI_TXT").value;
						document.getElementById("TxtDir").value=document.getElementById("DIR_TXT").value;
						document.getElementById("TxtRuc").value=document.getElementById("RUC_TXT").value;
					}					
		   }
	}
	ajax.send(null);	
}

function fGetLOR(){	
	var DL=document.getElementById("DivLAST");	
	DL.innerHTML="";
	ajax=CreateAJAX();
	var StrU="sunat.php?C=C&P1=2";
	ajax.open("GET",StrU);	
	ajax.onreadystatechange=function() {
		   if (ajax.readyState==4) {
					var StrDatos=ajax.responseText;
					if(StrDatos.trim().length==0){
						alert("Ningun dato registrado");
					}else{
						DL.innerHTML=decodeURIComponent(StrDatos);
						document.getElementById("TxtNom").value=document.getElementById("CLI_TXT").value;
						document.getElementById("TxtDir").value=document.getElementById("DIR_TXT").value;
						document.getElementById("TxtRuc").value=document.getElementById("RUC_TXT").value;
					}					
		   }
	}
	ajax.send(null);	
}


/*function fGetSunat(){
	var Ruc=document.getElementById("TxtRuc").value;
	if(Ruc.trim().length==0){
		alert("Ingrese numero de Ruc");
		document.getElementById("TxtRuc").focus();
		return;
	}
	ajax=CreateAJAX();
	ajax.open("GET", "ajax_funciones.php?Cmd=ST_RUC&TxtPar="+Ruc);	
	ajax.onreadystatechange=function() {
		   if (ajax.readyState==4) {
var StrD=ajax.responseText;	
if (StrD.indexOf("invalido") != -1) {						
	alert("Numero de ruc NO VALIDO");
}else{
	document.getElementById("DivSunat").innerHTML=StrD;
	document.getElementById("TxtNom").value=document.getElementById("T_RS").value;	
	document.getElementById("TxtDir").value=document.getElementById("T_DI").value;	
	document.getElementById("TxtTel").value=document.getElementById("T_TE").value;
	alert("Los datos han sido cargados CORRECTAMENTE");	
}				    
		   }
	}
    ajax.send(null);
}*/
