function registrar()
{
	window.location.href="../Registro/FormularioRegistroNW.aspx?origen=Libro";
}
function acceptNum(evt)
{	
	var nav4 = window.Event ? true : false;
	var key = nav4 ? evt.which : evt.keyCode;
	return (key <= 13 || (key >= 48 && key <= 57));							
}

function limpiar(cbo) 
{	
	cbo.selectedIndex = -1;
	cbo.length = 0;
}


function llenarCiudades(ed) 
{
	var i;
	var edoNuevo = ed;
	var cboCdad = window.document.getElementById("cbociudad");
	if (edoNuevo == "0" ){
		cboCdad.selectedIndex=-1;
		cboCdad.length=0;		
		cboCdad.options[0] = new Option("seleccione un estado","0");
		Cambiocombo("cboestado");
		return;}
	limpiar(cboCdad);
	cboCdad.options[0] = new Option("seleccione una ciudad","0");
	var d = 1;			
	for (var i=0;i<arrCdad.length;i++){				
		if (arrCdad[i][2]==edoNuevo){
			cboCdad.options[d++] = new Option(arrCdad[i][0],arrCdad[i][1]);
		}
	}
	validarMedioEnvio(edoNuevo);
	
	//var tablaEnvio = document.getElementById("TblEnvio");
	
	//if (tablaEnvio != null && tablaEnvio.style.display == "") 
	//{
		//var gridMedioEnvio = document.getElementById("dtgMedioEnvio");
		//gridMedioEnvio.disabled="";
	//}
	
	Cambiocombo("cboestado");
}

function validarMedioEnvio(edoCodigo)
{
	//En caso de que el envío no sea gratuito se debe validar que este seleccionado alguo de los medios de envío
	var tablaEnvio = document.getElementById("TblEnvio");
	var tablaEnvioGratuito = document.getElementById("TblEnvioGratuito");
	var etdCodigo = document.getElementById("codEstadoEnvioGratis");
	var costoEnvio = document.getElementById("LblCostoEnvio");
	var costoCompra = document.getElementById("Totalinput");
	var costoTotal = document.getElementById("LblTotal");
	var medioEnvio = document.getElementById("envproCodigo");
		
	if (edoCodigo == etdCodigo.value)
	{
		if (tablaEnvio != null) 
		{
			tablaEnvio.style.display="none";
			clearCheck('RdBtnMedioEnvio', -1)
			medioEnvio.value=""	
		}
		if (tablaEnvioGratuito != null) 
		{
			tablaEnvioGratuito.style.display="";
		}
		//Actualizando el Total
		costoEnvio.innerText = formatearMonto(0)
		costoTotal.innerText = formatearMonto(0 + parseInt(costoCompra.value));
	}
	else
	{
		if (tablaEnvio != null) 
		{
			tablaEnvio.style.display="";
		}
		if (tablaEnvioGratuito != null) 
		{
			tablaEnvioGratuito.style.display="none";
		}
	}
}

function DirecionSelec()
{
	var ddlist= window.document.getElementById('ddlDireccionP');
	if (ddlist!=null)
		{return ddlist.value;}
	else
		{return -1}
}

function LlenarDirecciones(valor)
{
	var i
	
	//Controles asociados a la Dirección Principal
	var txNombre = window.document.getElementById("TexNombre");
	var txTelefono = window.document.getElementById("TexTelefono");
	var txCiudad = window.document.getElementById("Texciudad");
	var txEstado = window.document.getElementById("TexEstado");
	
	if (valor==0) //Este item se corresponde con "Seleccione una dirección"
	{
		//Limpiando los controles asociados a la Dirección Principal
		txNombre.innerText=""
		txTelefono.innerText=""
		txCiudad.innerText=""
		txEstado.innerText=""
	}
	
	//Cargando los controles asociados a la Dirección Principal
	for (var i=0;i<arrDirecc.length;i++)
	{				
		if (arrDirecc[i][5]==valor)
		{	
		
			if (arrDirecc[i][3] != "") //validando la inclusión de la ","
			{
			txNombre.innerText=arrDirecc[i][0] + ", "
			}
			else
			{
			txNombre.innerText=arrDirecc[i][0];
			}	
			
			if (arrDirecc[i][4] != "") //validando la inclusión de la ","
			{
			txCiudad.innerText=arrDirecc[i][3] + ", "
			}
			else
			{
			txCiudad.innerText=arrDirecc[i][3];
			}
			txCiudad.title=arrDirecc[i][6];
			
			if (arrDirecc[i][1] != "") //validando la inclusión de la ","
			{
			txEstado.innerText=arrDirecc[i][4] + ", "
			}
			else
			{
			txEstado.innerText=arrDirecc[i][4];
			}
			txEstado.title=arrDirecc[i][7];	
			
			txTelefono.innerText=arrDirecc[i][1];				
		}
	}
	
	if (txEstado!= null && txEstado.innerText!= "") 
	{
		validarMedioEnvio(txEstado.title);	
	}
	
	focotexto();
	
	//Controles asociados a la Dirección Secundaria
	var ndir = window.document.getElementById("rdbtnDireccionNueva").checked;
	var textNombre = window.document.getElementById("TxtNombreE");
	var textTelefono = window.document.getElementById("TxtTelefonoE");
	var cmboEstado = window.document.getElementById("cboestado");
	var cmboCiudad = window.document.getElementById("cbociudad");
	var textDireccion = window.document.getElementById("TxtDireccionE");
	if (ndir == true) //Dirección Secundaria
	{
		//Habilitando los controles asociados a la Direcció Secundaria
		textNombre.disabled="";
		textTelefono.disabled="";
		cmboEstado.disabled="";
		cmboCiudad.disabled="";	
		textDireccion.disabled="";		
	}
	//NuevaDireccion()			
}

function focotexto()
{
	var grid,filfo, total,prec,totalcan,totalCosto,obInput,obCantidad,obCosto;
	var i,pos,prec;
	var cant=0;
	totalcan=0;
	totalCosto=0;
	var label;
	grid=document.getElementById("dtgLibros");
	obInput=document.getElementById("Totalinput");
	obCantidad = document.getElementById("lblTotalCant");
	obCosto = document.getElementById("lblTotalCosto");
	
	var costoCompra = document.getElementById("LblCostoCompra");
	
	filfo=grid.rows.length-1;				
	for (i=1;i<=filfo;i++)
	{
		cant=grid.rows[i].cells[1].childNodes[0].value;							
		if (cant=="")
		{
			cant=0;
			grid.rows[i].cells[1].childNodes[0].value=0;
		}
		prec=grid.rows[i].cells[2].childNodes[0].innerText;
		prec=prec.replace(".","")
		pos=prec.indexOf(",",0)
		prec=prec.substring(0,pos)
		total= cant*prec;
		totalCosto=totalCosto+total;
		cant=parseInt(cant);
		totalcan=totalcan + cant;
		grid.rows[i].cells[3].childNodes[0].innerText=formatearMonto(total);					
	}				
	obCantidad.innerText=totalcan;
	obCosto.innerText=formatearMonto(totalCosto);
	costoCompra.innerText=formatearMonto(totalCosto);
	obInput.value=totalCosto;
	
	var costoEnvio = document.getElementById("LblCostoEnvio"); 
	var costoTotal = document.getElementById("LblTotal"); 
	
	//prec=costoEnvio.innerText;
	//prec=prec.replace(".","")
	//pos=prec.indexOf(",",0)
	//prec=prec.substring(0,pos)	

	costoTotal.innerText=formatearMonto(parseInt(quitarFormatoMonto(costoEnvio.innerText)) + parseInt(totalCosto));
}

function js_editarDirecccion(obj){
				obj.style.display="none";
				document.getElementById("sp_boton").style.display="";
				document.getElementById("TexNombre").disabled="";
				document.getElementById("TexNombre").focus();
				document.getElementById("TexTelefono").disabled="";
				document.getElementById("cboestado").disabled="";
				document.getElementById("cbociudad").disabled="";
				document.getElementById("TxtDireccionE").disabled="";
				//Habilitando la sección de Medio de Envío
				//var tablaEnvio = document.getElementById("TblEnvio");

				//if (tablaEnvio != null && tablaEnvio.style.display == "") 
				//{
				//	document.getElementById("dtgMedioEnvio").disabled = "";		
				//}	
}

function CalcularFooter()
{
	var grid,filfo, total,prec,totalcan,totalCosto,obInput,obCantidad,obCosto;
	var i;
	var cant=0;
	totalcan=0;
	totalCosto=0;
	var label;
	grid=document.getElementById("dtgLibros");
	obInput=document.getElementById("Totalinput");
	obCantidad = document.getElementById("lblTotalCant");
	obCosto = document.getElementById("lblTotalCosto");
	
	//Actualizando costoCompra
	var costoCompra = document.getElementById("LblCostoCompra");
	
	filfo=grid.rows.length-1				
	for (i=1;i<=filfo;i++)
	{
		cant=grid.rows[i].cells[1].childNodes[0].value;					
		if (cant=="")
		{
			cant=0;
			grid.rows[i].cells[1].childNodes[0].value=0;
		}
		prec=grid.rows[i].cells[2].childNodes[0].innerText;
		prec=prec.replace(".","")
		pos=prec.indexOf(",",0)
		prec=prec.substring(0,pos)
		total= cant*prec;
		totalCosto=totalCosto+total;
		cant=parseInt(cant);
		totalcan=totalcan + cant;
		grid.rows[i].cells[3].childNodes[0].innerText=formatearMonto(total);					
	}				
	obCantidad.innerText=totalcan;
	obCosto.innerText=formatearMonto(totalCosto);
	obCosto.style.color="#a9a9a9"
	costoCompra.innerText=formatearMonto(totalCosto);
	obCantidad.style.color="#a9a9a9"
	obInput.value=totalCosto;
	
	//Actualizando costoEnvio
	var tablaEnvio = document.getElementById("TblEnvio");
	var medioEnvio = document.getElementById("envproCodigo");
	var costoEnvio = document.getElementById("LblCostoEnvio");
	var costoTotal = document.getElementById("LblTotal"); 
	var grid = document.getElementById("dtgMedioEnvio");

	if (medioEnvio!= null && medioEnvio != "") 
	{
		filfo=grid.rows.length-1				
		for (i=1;i<=filfo;i++)
		{
			if (grid.rows[i].cells[0].childNodes[0].value == medioEnvio.value)
			{
				if (grid.rows[i].cells[1].childNodes[0].innerText != "") { costoEnvio.innerText= grid.rows[i].cells[1].childNodes[0].innerText; }
				else { costoEnvio.innerText=formatearMonto(0); }
			}
		}
	}
	else
	{
		costoEnvio.innerText=formatearMonto(0);
	}
	costoTotal.innerText=formatearMonto(parseInt(quitarFormatoMonto(costoEnvio.innerText)) + parseInt(totalCosto));
}

function formatearMonto(monto)
{
	var mon=monto.toString()
	var t=mon.length;
	var resi,pri,veces,inicio,fin,resul,taux;
	resi=t%3;
	veces=t/3;
	inicio=0
	resul="";
	if (resi==0)
	{
		fin=3
		for (i=0;i<veces;i++) 
		{
			pri=mon.substring(inicio,fin)
			pri=pri+"."
			resul=resul+pri
			inicio=inicio+3;
			fin=fin+3;
		}	
		taux=resul.length;
		resul=resul.substring(0,taux-1)
		resul=resul+",00";
	}
	else
	{
		fin=resi
		pri=mon.substring(inicio,fin)
		pri=pri+"."
		resul=resul+pri
		inicio=inicio+resi;
		fin=fin+3;
		for (i=1;i<=veces;i++) 
		{
			pri=mon.substring(inicio,fin)
			pri=pri+"."
			resul=resul+pri
			inicio=inicio+3;
			fin=fin+3;			
		}	
		taux=resul.length;
		resul=resul.substring(0,taux-1)
		resul=resul+",00";
	}	
	return resul;
}

function quitarFormatoMonto (monto)
{
	var pos;
	monto=monto.replace(".","")
	pos=monto.indexOf(",",0)
	monto=monto.substring(0,pos)	
	return monto;
}

function validar()
{
	var textNombre =document.getElementById("TxtNombreE").value;
	var textTelefono =document.getElementById("TxtTelefonoE").value;
	var cmboEstado =document.getElementById("cboestado").value;
	var cmboCiudad =document.getElementById("cbociudad").value;
	var textDireccion =document.getElementById("TxtDireccionE").value;
	
	var cmboDireccP;
	var cmboDireccPri =document.getElementById("ddlDireccionP"); 
	var rbnDirNueva =document.getElementById("rdbtnDireccionNueva").checked;
	

	/*alert (rbnDirNueva)	
	if (cmboDireccPri==null)
	{
		cmboDireccP=0;
	}
	else
	{
		cmboDireccP=cmboDireccPri.value;
	}*/
	
	var labeDirP=document.getElementById("lblvalidarDir");
	var labeNombreA=document.getElementById("lblerrorNombre");
	var labeTelefonoA=document.getElementById("lblerrorTelefono");
	var labeEdoCiu =document.getElementById("lblerror");
	var labeDirS =document.getElementById("lblerrorDireccion");
	var obInput=document.getElementById("Totalinput");
	var respuesta;
	
				
		if (rbnDirNueva==false)
		{
			if (obInput.value==0)
			{
				alert('Debe solicitar un libro al menos')
				respuesta=false;
			}
			else
			{
				if ((cmboDireccPri.value<=0))
				{
					labeDirP.innerText="Debe seleccionar una direccion o agregar una nueva"
					respuesta=false;
				}
				else
				{
					var txNombre = window.document.getElementById("TexNombre");
					var txTelefono = window.document.getElementById("TexTelefono");
					var txCiudad = window.document.getElementById("Texciudad");
					var txEstado = window.document.getElementById("TexEstado");
					
					txCiudad.value=txCiudad.title
					txEstado.value=txEstado.title
									
					txNombre.disabled="";
					txTelefono.disabled="";
					txEstado.disabled="";
					txCiudad.disabled="";
					respuesta=true;
				}
			}
		}
		else
		{	
			if (textNombre=="")
			{
				labeNombreA.innerText="Debes agregar el nombre del destinatario";
				if (labeDirP!=null)
					{labeDirP.innerText=""}
				respuesta=false;							
			}
			else
			{
				labeNombreA.innerText="";													
			}
			if (textTelefono=="")
			{
				labeTelefonoA.innerText="Debes agregar el telefono del destinatario";
				if (labeDirP!=null)
					{labeDirP.innerText=""}
				respuesta=false;							
			}
			else
			{
				labeTelefonoA.innerText="";													
			}
			if (textDireccion=="")
			{
				labeDirS.innerText="Debes agregar la direccion del destinatario";
				if (labeDirP!=null)
					{labeDirP.innerText=""}
				respuesta=false;
			}
			else
			{
				labeDirS.innerText="";
			}
			if (cmboEstado>0)
			{
				if (cmboCiudad>0)
				{
					labeEdoCiu.innerText="";
					if ((textNombre!="") && (textTelefono!="") && (textDireccion!=""))
					{
						if (obInput.value==0)
						{
							alert('Debes solicitar un libro al menos')
							respuesta=false;
						}
						else
						{
							respuesta=true;
						}
					}
				}
				else
				{
					labeEdoCiu.innerText="Debes selecionar la ciudad del destinatario";
					if (labeDirP!=null)
					{labeDirP.innerText=""}
					respuesta=false;
				}
			}
			else
			{
				labeEdoCiu.innerText="Debes selecionar el estado del destinatario";
				if (labeDirP!=null)
					{labeDirP.innerText=""}
				respuesta=false;							
			}					
		}


		//En caso de que el envío no sea gratuito se debe validar que este seleccionado alguo de los medios de envío
		var tabla = document.getElementById("TblEnvio");
		var medioEnvio = document.getElementById("envproCodigo");
		if (tabla.style.display=="")
		{
			if (medioEnvio.value=="")
			{
				alert('Debe seleccionar el medio de env'+'\xED'+'o')
				respuesta=false;
			}
		}
		
	return respuesta;
}

function editarValidar(form){			

			if (form == null) 
			{
				if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) 
				{
					form = document.formFecha;	
				}
				else 
				{
					form = document.forms["formFecha"];
				}
			}

			var no_error = true;			
			if (form.TexNombre.value==""){
				document.getElementById("lblerrorNombre").innerText="indique un nombre de destinatario";
				no_error = false;
			}
			else
				document.getElementById("lblerrorNombre").innerText="";
			
			if (form.TexTelefono.value==""){
				document.getElementById("lblerrorTelefono").innerText="indique un telefono de destinatario";
				no_error = false;
			}
			else
				document.getElementById("lblerrorTelefono").innerText="";
				
			if (form.cboestado.selectedIndex < 1){
				document.getElementById("lblerror").innerText="indique un estado";
				no_error = false;
			}
			else if (form.cbociudad.selectedIndex < 1){
					document.getElementById("lblerror").innerText="indique una ciudad";
					no_error = false;
				}
				else
					document.getElementById("lblerror").innerText="";
				
			if (form.TxtDireccionE.value==""){
				document.getElementById("lblerrorDireccion").innerText="indique una direccion";
				no_error = false;
			}
			else
				document.getElementById("lblerrorDireccion").innerText="";	
				
		//En caso de que el envío no sea gratuito se debe validar que este seleccionado alguo de los medios de envío
		var tabla = document.getElementById("TblEnvio");
		var medioEnvio = document.getElementById("envproCodigo");
		if (tabla != null && tabla.style.display=="")
		{
			if (medioEnvio.value=="")
			{
				alert('Debe seleccionar el medio de env'+'\xED'+'o')
				no_error=false;
			}
		}			
			return no_error;
}		

function Cambiocombo(Combo)
{
	var objeto1 =document.getElementById(Combo).value;
	var errorlabe =document.getElementById("lblerror")
	if (objeto1>0)
	{
		errorlabe.innerText=""
	}
	else
	{
		if (Combo=="cboestado")
			errorlabe.innerText="Debe selecionar un estado"
		else
			errorlabe.innerText="Debe selecionar una ciudad"
	}
}

var HelpVenta = new Array();
HelpVenta[0]="";
HelpVenta[1]=""; 
HelpVenta[2]="";
HelpVenta[3]="";
HelpVenta[4]="";
HelpVenta[5]="";
HelpVenta[6]="";
HelpVenta[7]="Formas de Pago: <br>1.-Deposito bancario a nombre de Mateo Soluciones Educativas C.A. <br> &#149; BANESCO cta. ctte. Nro 01340473904731026071<br>&#149; BANCO MERCANTIL cta. ctte. Nro 01050251901251017762. <br><br> 2.- Tarjeta de Credito";

function LoadPopUp(aTit,aRef)
{
	popupWinbChangeTexts = true;
	popupWinnTitle = aTit;			
	popupWinespopup_winLoad();
	document.getElementById('popupWin').style.bottom ='15%';
	document.getElementById('popupWin').style.left ='2%';
	document.getElementById('popupWin_content').innerHTML=HelpVenta[aRef];
}

function LoadPopUp2(aTit,aRef)
{
	popupWinbChangeTexts = true;
	popupWinnTitle = aTit;			
	popupWinespopup_winLoad();
	document.getElementById('popupWin').style.bottom ='2%';	
	document.getElementById('popupWin_content').innerHTML=HelpVenta[aRef];
}

function NuevaDireccion() 
{	
	//Controles asociados a la Dirección Secundaria
	var ndir = window.document.getElementById("rdbtnDireccionNueva").checked;
	
	var textNombre =document.getElementById("TxtNombreE");
	var textTelefono =document.getElementById("TxtTelefonoE");
	var cmboEstado =document.getElementById("cboestado");
	var cmboCiudad =document.getElementById("cbociudad");
	var textDireccion =document.getElementById("TxtDireccionE");
	
	//Contenedor de parte de los Controles asociados a la Dirección Principal
	var divobjeto=document.getElementById("datosPrincipal");	
	
	if (ndir == true )
	{
		//Controles asociados a la Dirección Principal
		var ddlDirPrincipal= window.document.getElementById('ddlDireccionP');
		var txNombre = window.document.getElementById("TexNombre");
		var txTelefono = window.document.getElementById("TexTelefono");
		var txCiudad = window.document.getElementById("Texciudad");
		var txEstado = window.document.getElementById("TexEstado");
		var labeDirP = document.getElementById("lblvalidarDir"); //Etiqueta Error asociada al control propio de Dirección Principal
		
		//Limpiando y deshabilitando el control asociado a la Dirección Principal
		if (ddlDirPrincipal!=null)
	    {
		ddlDirPrincipal.selectedIndex=0
		ddlDirPrincipal.disabled="disabled";
		}
		//Limpiando los controles asociados a la Dirección Principal
		if (txNombre!=null)
	    {
		txNombre.innerText=""
		}
		if (txTelefono!=null)
	    {
		txTelefono.innerText=""
		}
		if (txCiudad!=null)
	    {
		txCiudad.innerText=""
		}
		if (txEstado!=null)
	    {
		txEstado.innerText=""
		}
		
		//Deshabilitando los controles asociados a la Dirección Principal
		if (divobjeto!=null)
	    {
		divobjeto.style.display="none";
		}
			
		//Limpiando la etiqueta de error que se encuentra a nivel de Combo Dirección
		if (labeDirP!=null)
	    {
		labeDirP.innerText=""
		}
		//Habilitando los controles asociados a la Dirección Secundaria
		if (textNombre!=null)
	    {
		textNombre.disabled="";
		}
		if (textTelefono!=null)
	    {
		textTelefono.disabled="";
		}
		if (cmboEstado!=null)
	    {
		cmboEstado.disabled="";	
		}
		if (cmboCiudad!=null)
	    {
		cmboCiudad.disabled="";	
		}
		if (textDireccion!=null)
	    {
		textDireccion.disabled="";		
		}
	}
	else
	{
		//Etiquetas de Error asociadas a los controles propios de Dirección Secundaria
		var labeNombreA = document.getElementById("lblerrorNombre");
		var labeTelefonoA = document.getElementById("lblerrorTelefono");
		var labeEdoCiu = document.getElementById("lblerror");
		var labeDirS = document.getElementById("lblerrorDireccion");
		
		//Control asociado a la Dirección Principal
		var ddlDirPrincipal= window.document.getElementById('ddlDireccionP');
		
		//Limpiando y habilitando el control asociado a la Dirección Principal
		ddlDirPrincipal.selectedIndex=1
		ddlDirPrincipal.disabled="";
		
		//Habilitando los controles asociados a la Dirección Principal
		divobjeto.style.display="";
		
		LlenarDirecciones(ddlDirPrincipal.selectedIndex)
		
		//Limpiando las etiquetas de error asociadas a los controles propios de Dirección Secundaria
		labeNombreA.innerText=""
		labeTelefonoA.innerText=""
		labeEdoCiu.innerText=""
		labeDirS.innerText=""
		
		//Limpiando los controles asociados a la Dirección Secundaria
		textNombre.value="";
		textTelefono.value="";
		cmboEstado.selectedIndex=0;
		cmboCiudad.selectedIndex=0;	
		textDireccion.value="";
		
		//Deshabilitando los controles asociados a la Dirección Secundaria
		textNombre.disabled="disabled";
		textTelefono.disabled="disabled";
		cmboEstado.disabled="disabled";
		cmboCiudad.disabled="disabled";
		textDireccion.disabled="disabled";
	}
}

function LlenarDirecciones2(dire)
{
	var i,d
	var valor=dire
	d=0;
	var txNombre = window.document.getElementById("TexNombre");
	var txTelefono = window.document.getElementById("TexTelefono");
	var txCiudad = window.document.getElementById("cbociudad");
	var txEstado = window.document.getElementById("cboestado");
	var txdire = window.document.getElementById("TxtDireccionE");
	for (var i=0;i<arrDirecc.length;i++)
	{				
		if (arrDirecc[i][5]==valor)
		{
			txNombre.value=arrDirecc[i][0];
			txTelefono.value=arrDirecc[i][1];
			txdire.value=arrDirecc[i][2];
			txCiudad.selectedIndex=arrDirecc[i][6];
	
			txEstado.selectedIndex=arrDirecc[i][7];					
		}
	}
	focotexto();				
}

//Esta función se encarga de mantener en el control envproCodigo el código asociado al medio de envío
function RdBtn_click (valor)
{
	//Asignando el código del medio de envío seleccionado
	var medioEnvio = document.getElementById("envproCodigo");
	medioEnvio.value=valor
	
	clearCheck('RdBtnMedioEnvio', valor) //simulando el comportamiento del RadioButton 
	
	//Asigando el costo de envio 
	var costoEnvio = document.getElementById("LblCostoEnvio");
	var costoTotal = document.getElementById("LblTotal"); 
	var grid = document.getElementById("dtgMedioEnvio");
	var costoCompra = document.getElementById("Totalinput");
	
	var i, filfo, costo, pos;

	filfo=grid.rows.length-1				
	for (i=1;i<=filfo;i++)
	{
	//var valor = grid.rows[i].cells[0].innerText;
		if (grid.rows[i].cells[0].childNodes[0].value == valor)
		{
			if (grid.rows[i].cells[1].childNodes[0].innerText != "") { costoEnvio.innerText= grid.rows[i].cells[1].childNodes[0].innerText; }
			else { costoEnvio.innerText=formatearMonto(0); }	
			//Suprimiendo el formato a nivel del costo de envío
			costo = costoEnvio.innerText;
			costo = costo.replace(".","")
			pos = costo.indexOf(",",0)
			costo=costo.substring(0,pos)
			costoTotal.innerText=formatearMonto(parseInt(costo) + parseInt(costoCompra.value));
		}
	}				
}

/* Funcion que desmarca los items cuyo código es diferente a codigo (este codigo se corresponde con el item que se acaba de seleccionar) */
function clearCheck(nombreControl, codigo){
	var i;
	var form;
	if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) 
	{
		form = document.formFecha;	
	}
	else 
	{
		form = document.forms["formFecha"];
	}
		
	for(i=0;i<form.elements.length;i++)
	{
		if ((form.elements[i].type=="radio") && (form.elements[i].id.indexOf(nombreControl) > -1))
		{
			if (form.elements[i].checked==true && form.elements[i].value != codigo){ form.elements[i].checked=false;}
		}
	}			
}

function _dPostBack(t)
{
	if (t==0)
	{
		document.formdb.sldsCodigo.value = document.formFecha.txtldsCodigo.value;
		document.formdb.pgoMonto.value = document.formFecha.Totalinput.value;
		document.formdb.submit();
	}
	if (t==1)
	{
		document.formtc.sldsCodigo.value = document.formFecha.txtldsCodigo.value;
		document.formtc.pgoMonto.value = document.formFecha.Totalinput.value;						
		document.formtc.submit();
	}
}

function __doPostBack(eventTarget, eventArgument) {
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
		theform = document.formFecha;
	}
	else {
		theform = document.forms["formFecha"];
	}
	theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
	theform.__EVENTARGUMENT.value = eventArgument;
	theform.submit();
}

function lnkBtn_click(link) 
{
			if (validarFormulario ()) {
				__doPostBack(link, '')
			}
}

function validarFormulario ()
{
	var grid = document.getElementById("dtgLibros");
	var filfo = grid.rows.length-1;	
				
	for (i=1;i<=filfo;i++)
	{				
		if (grid.rows[i].cells[4].childNodes[0].value == "Cambiar")
		{
			alert('Los datos de la compra estan en modo de edici' + '\xF3' + 'n');
			return false;
		}					
	}

	var btnEditarEnvio = document.getElementById("sp_boton");

	if (btnEditarEnvio != null) 
	{
		if (btnEditarEnvio.style.display == "")
		{
			alert('Los datos de env' + '\xED' + 'o'+ ' estan en modo de edici' + '\xF3' + 'n');
			return false;
		}
	}
	
	return editarValidar(null);
}