''Cambia de color el texto y el fondo
sub Blink(Control, Frame)
	on error resume next
	if Frame <> "" then
		with parent.frames(Frame)
			with .document.all.item(Control)
				if .value = "" then 
					.Color = "Black"
					.backgroundColor = "white"
					exit sub
				end if
				if .style.Color = "black" then  
					.style.Color = "white"
					.style.backgroundColor = "red"
				else
					.style.Color = "Black"
					.style.backgroundColor = "white"
				end if
			end with
		end with	
	else
		if document.all.item(Control).value = 0 or document.all.item(Control).value = "" then exit sub
		with document.all.item(Control).style
			if .Color = "black" then  
				.Color = "white"
				.backgroundColor = "red"
			else
				.Color = "Black"
				.backgroundColor = "white"
			end if
		end with	
	end if
end sub

''FUNCIONES DEL ENTER
sub txtCotizacion_onKeyPress()
	on error resume next
	if window.event.keyCode = 13 then
		
		if document.all.item("txtCotizacion").value="" then
			window.parent.frames("CotizacionENC").document.all.item("txtCantidad").focus()
		else
			with window.parent.frames("CotizacionGrid")
				.document.all.item("txtPaso").value=""
				.document.all.item("txtConservaFocus").value="false"
				.document.all.item("IndiceColor").value=1
				.document.all.item("txtCotizacion").value = document.all.item("txtCotizacion").value
				.document.forms(0).submit()
				
				'with window.parent.frames("ProcesaPedido")
				'	.window.location = "../Contenido/ConsultaPartidasColocadas.asp"
				'end with
			end with
		end if
	end if
end sub

sub txtCantidad_onKeyPress()
	on error resume next
	if window.event.keyCode = 13 then
		if document.all.item("txtCantidad").value ="" then
			window.parent.frames("CotizacionENC").document.all.item("txtCantidad").focus()
		else
			
			''VALIDAR CUANDO YA HAYAN SIDO COLOCADAS TODAS LAS PARTIDAS DE LA COTIZACION 
			with window.parent.frames("CotizacionGRID")
				if .document.all.item("Recordcount").value = 0  then 
					if document.all.item("txtCotizacion").value <> "" then
						msgbox "La cotización esta colocada o no existe, no se pueden agregar partidas", vbCritical, "Aviso"
						exit sub
					end if
				end if
			end with
			
			window.parent.frames("CotizacionENC").document.all.item("txtNoParte").focus()
		end if
	end if
end sub

sub txtCantidad_onKeyUp()
	on error resume next
	if window.event.keyCode = 40 then
		window.parent.frames("CotizacionGRID").document.all.item("txtCantidadGrid1").focus()
	end if
end sub



sub GrabarCantidad(IdDCot,index)
'	on error resume next
'	if document.all.item("txtCantidadGrid" & index).value < 0 or trim(document.all.item("txtCantidadGrid" & index).value) ="" then
'		MsgBox "La cantidad debe ser mayor o igual a cero, verifique por favor",vbExclamation 
'		document.all.item("txtCambioCantidad").value="false"
'	end if	
'	if document.all.item("txtCambioCantidad").value="true" then
'		document.all.item("txtIdDCot").value = IdDCot
'		document.all.item("txtOtraCantidad").value = document.all.item("txtCantidadGrid" & index).value
'		document.forms(0).submit()	
'	end if
end sub



sub validaEnteros(Control)
	dim i
	dim s
	dim s2
	on error resume next
	
	Codigo = window.event.keycode
	if Codigo = 8 or Codigo = 37 or codigo = 39 then exit sub
	
	if Codigo = 40 then 
		document.all.item("txtCantidadGrid1").focus()
	else
		s = trim(document.all.item(Control).value)
		for i = 1 to len(s)
			if mid(s,i,1)>= "0" and mid(s,i,1) <="9" then
				s2 = s2 + mid(s,i,1)
			end if
		next
		document.all.item(Control).value = s2
	end if
end sub

''DESPLAZAMIENTO CON LAS FLECHAS Y AFECTACION SI PRESIONAN ENTER
sub Grid_OnKeyup(Control, IdDCot, index, Partida, IdCot, Vendedor, PrecioVta, Transporte)
	on error resume next
	
	''Borrar las Existencias y Tiempos de Entrega
	Codigo = window.event.keycode
	if Codigo <> 39 and Codigo <> 37 then LimpiaExistencias 
		Select case Codigo 
			case 40 ''FLECHA PARA ABAJO
				if cint(index) < cint(document.all.item("RecordCount").value) then
					if document.all.item(Control & (index + 1)).disabled then
						for i = index + 1  to cint(document.all.item("RecordCount").value)
							index = index + 1
							if not document.all.item(Control & (index + 1)).disabled then exit for
						Next 
					end if
					
					document.all.item(Control & (index + 1)).focus()
					document.all.item(Control & (index + 1)).select()
				else
					document.all.item(Control & 1).focus()
					document.all.item(Control & 1).select()
					window.scrollTo 0,0 
				end if
			case 38 ''FLECHA PARA ARRIBA
				if index > 1 then
					if document.all.item(Control & (index - 1)).disabled then
						for i = index - 1  to cint(document.all.item("RecordCount").value)
							index = index - 1
							if not document.all.item(Control & (index - 1)).disabled then exit for
						Next 
					end if
					document.all.item(Control & (index - 1)).focus()
					document.all.item(Control & (index - 1)).select()
				else
					window.scrollTo 0,0 
					parent.frames("CotizacionEnc").document.all.item("txtCantidad").focus()
				end if
			case 39	''FLECHA DERECHA
				if Control = "Pedido" then
					document.all.item("txtCantidadGrid" & index).focus()
					document.all.item("txtCantidadGrid" & index).select()
				elseif Control = "txtNoParteGrid" then
					if not document.all.item("Precio" & index).readonly then
						document.all.item("Precio" & index).focus()
						document.all.item("Precio" & index).select()
					end if
				else
					document.all.item("txtNoParteGrid" & index).focus()
					document.all.item("txtNoParteGrid" & index).select()
				end if
			case 37 ''FLECHA IZQUIERDA
				if control = "txtCantidadGrid" then
					document.all.item("Pedido" & index).focus()
					document.all.item("Pedido" & index).select()
				elseif control = "Precio" then
					document.all.item("txtNoParteGrid" & index).focus()
					document.all.item("txtNoParteGrid" & index).select()
				elseif control <> "Pedido" then
					document.all.item("txtCantidadGrid" & index).focus()
					document.all.item("txtCantidadGrid" & index).select()
				end if
		end select

	if Codigo = 13 then
		if Vendedor then
			CalculaDiferencia index, IdDCot, Transporte, PrecioVta
			exit sub
		end if
	end if

	if Codigo = 13 and Control <> "Pedido" and Control <> "Precio" then
		if document.all.item("txtCantidadGrid" & index).value < 0 or trim(document.all.item("txtCantidadGrid" & index).value) ="" or not isnumeric(document.all.item("txtCantidadGrid" & index).value) then
			MsgBox "Cantidad inválida, verifique por favor",vbExclamation 
			document.all.item("txtCambioCantidad").value="false"
			document.all.item("txtCambioNoParte").value="false"
			document.all.item("txtCantidadGrid" & index).select()
		end if
		if document.all.item("txtCambioCantidad").value="true" then
			if document.all.item("txtCantidadGrid" & index).value > 0 then
				document.all.item("txtIdDCot").value = IdDCot
				document.all.item("txtOtraCantidad").value = document.all.item("txtCantidadGrid" & index).value
				document.forms(0).submit()	
			else
				MsgBox "Cantidad inválida, verifique por favor",vbExclamation 
			end if
		end if
		
		if len(document.all.item("txtNoParteGrid" & index).value) < 3 or trim(document.all.item("txtNoParteGrid" & index).value) = "" then
			MsgBox "Número de parte inválido, verifique por favor",vbExclamation 
			document.all.item("txtCambioCantidad").value="false"
			document.all.item("txtCambioNoParte").value="false"
			document.all.item("txtNoParteGrid" & index).select()
		end if	
		if document.all.item("txtCambioNoParte").value="true" then
			''Buscar si el NoParte o el NoNuevo ya existe en la cotizacion 
			Posicion = 0
			Posicion = ExisteNoParte(index)
			if cint(Posicion) <> 0 then
				document.all.item("txtNoParteGrid" & Posicion).focus()
				msgbox "El NoParte ya existe en la cotización", vbExclamation, "Aviso"
				document.all.item("txtCambioNoParte").value="false"
				document.all.item("txtCambioCantidad").value="false"
				document.forms(0).submit()	
				exit sub
			end if
			''
			document.all.item("txtNoParteGrid" & index).value = ucase(document.all.item("txtNoParteGrid" & index).value)
			document.all.item("txtIdCot").value = IdCot
			document.all.item("txtOtraCantidad").value = document.all.item("txtCantidadGrid" & index).value
			document.all.item("txtOtroNoParte").value = document.all.item("txtNoParteGrid" & index).value
			document.all.item("txtPartida").value = Partida
			document.forms(0).submit()	
		end if
	else
		document.all.item(Control & index).value = ucase(document.all.item(Control & index).value)
	end if
end sub

''Validar que no duplique los Numeros de parte en la cotizacion
function ExisteNoParte(index)
	Existe = 0
	NoParte = ucase(document.all.item("txtNoParteGrid" & index).value)
	if document.all.item("RecordCount").value <> "" then
		For i = 1 to cint(document.all.item("RecordCount").value)
			if cint(index) <> cint(i) then
				if trim(document.all.item("txtNoParteGRID" & i).value) = NoParte or trim(document.all.item("NoNuevo" & i).value) = NoParte then  
					Existe = i
					exit for
				end if
			end if
		Next
	end if
	ExisteNoParte = Existe
end function

sub CotizaAlternativa(IdDCot, PrecioAereo, Transporte, index, Consec, ExistenciaE, PrecioE, ExistenciaN, PrecioN)
	on error resume next
	document.all.item("txtConservaFocus").value="true"
	document.all.item("IndiceColor").value=index
	document.all.item("Consecutivo").value = Consec
	CambioDeCelda IdDCot, PrecioAereo, Transporte, index, Consec, ExistenciaE, PrecioE, ExistenciaN, PrecioN
	document.forms(0).submit()
end sub

sub CambioDeCelda(IdDCot, PrecioAereo, Transporte, index, Consec, ExistenciaE, PrecioE, ExistenciaN, PrecioN)
	on error resume next
	''Borrar las Existencias y Tiempos de Entrega
	if document.all.item("IndiceColor").value <> index then	LimpiaExistencias 
	colorea index, Consec
	document.all.item("txtIdDCot").value = IdDCot
	MuestraPrecioAereo "CotizacionENC", PrecioAereo, Transporte
	'Precios de Europa
	'MuestraPrecioEspNormal ExistenciaE, PrecioE, ExistenciaN, PrecioN
end sub

sub	MuestraPrecioEspNormal(ExistenciaE, PrecioE, ExistenciaN, PrecioN)
	on error resume next
	with parent.frames("ProcesaPedido")
		'E: Precio Especial, N: Precio Normal
		  
		if ExistenciaE = "" then ExistenciaE = 0
		if PrecioE = "" then PrecioE = 0
		if ExistenciaN = "" then ExistenciaN = 0
		if PrecioN = "" then PrecioN = 0
		
		.TablaPreciosEuropa.cells("ExistenciaE").innertext  = ExistenciaE
		.TablaPreciosEuropa.cells("PrecioE").innertext  = PrecioE
		.TablaPreciosEuropa.cells("ExistenciaN").innertext  = ExistenciaN
		.TablaPreciosEuropa.cells("PrecioN").innertext  = PrecioN
	end with
end sub

''APLICAR O DESAPLICAR FLETE AEREO 
sub AplicarAereo(Frame)
	on error resume next	
	if document.all.item("txtPrecioAereo").value <> "" then
		with parent.frames(Frame) 
			if document.all.item("Aereo").checked then
				.document.all.item("Aereo").value = "true"
			else
				.document.all.item("Aereo").value = "false"
			end if
			.document.all.item("txtConservaFocus").value="true"
			.document.forms(0).submit()
		end with
	end if
end sub

sub MuestraPrecioAereo(Frame, PrecioAereo, Transporte)
	on error resume next
	with parent.frames(Frame)
		if Transporte = "E" then
			.document.all.item("txtPrecioAereo").value = FormatNumber(0, 2)
		else
			.document.all.item("txtPrecioAereo").value = FormatNumber(PrecioAereo, 2)
		end if
		.document.all.item("Aereo").checked = Transporte="A"
		''''Desabilitar el checkbox cuando no aplique el Flete Aereo por el peso
		.document.all.item("Aereo").disabled = (PrecioAereo="" or PrecioAereo=0 or Transporte = "E")
	end with
end sub
'''''''''''

sub Existencias(NoParte, index)
	on error resume next
	colorea index, 0
	document.all.item("txtConservaFocus").value="true"
	document.all.item("IndiceColor").value = Index
	document.all.item("txtPaso").value = NoParte 'Guardar el NoParte en un hidden
	document.all.item("txtClick").value = "true" 'Marcar que dio click sobre un renglon
	with window.parent.frames("CotizacionExistSuc")
		.document.all.item("NoParte").value = NoParte 'Guardar el NoParte en un hidden
		.document.forms(0).submit() 		
	end with
	document.all.item("txtCantidadGrid" & index).focus()

end sub

sub LimpiaExistencias()
	if trim(window.parent.frames("CotizacionExistSuc").document.all.item("RegistrosExist").value) <> "0" then
	''Borrar las Existencias y Tiempos de Entrega
	on error resume next
	with window.parent.frames("CotizacionExistSuc")
		Exi = .document.all.item("RegistrosExist").value
		if trim(Exi)="" then Exi=0
		i=0
		do while cint(i) <= cint(Exi)
			i=i+1
			.document.all.item("Suc" & i).innertext=""
			.document.all.item("Exist" & i).innertext=""
			.document.all.item("RegistrosExist").value = 0
		loop
	end with
	'''
	end if
end sub

sub LimpiaCotizacion()
	on error resume next
	
	document.all.item("txtCotizacion").value = ""
	document.all.item("txtCantidad").value = ""
	document.all.item("txtNoParte").value = ""
	document.all.item("Aereo").checked=false
	document.all.item("txtPrecioAereo").value=""
	document.all.item("txtPartidaBUSCAR").value=""
	document.all.item("txtNoParteBUSCAR").value=""
	document.all.item("ExisteBusqueda").value=""
	with window.parent.frames("CotizacionGrid")
		.document.all.item("txtPaso").value=""
		.document.all.item("txtClick").value="false"
		.document.all.item("txtNueva").value="Nueva"
		.document.all.item("IndiceColor").value = 1
		.document.all.item("txtIdDCot").value=""
		.document.all.item("Aereo").value = "false"
		.document.all.item("txtCambioNoParte").value = "false"
		.document.all.item("txtConservaFocus").value="false"
		.document.all.item("txtCotizacion").value = ""
		.document.forms(0).submit() 
	end with
	
	with window.parent.frames("CotizacionExistSuc")
		.document.all.item("NoParte").value=""
		.document.forms(0).submit()
	end with
	
	with window.parent.frames("ProcesaPedido")
		'.window.location = "../Contenido/ConsultaPartidasColocadas.asp"		
		.document.forms(0).submit()
	end with
	
end sub

sub CopiaCotizacion()
	document.all.item("CopiaCot").value="true"
	document.forms(0).submit()
end sub

sub CambioCantidad(Control)
	on error resume next
	if document.all.item(Control).value < 0 or trim(document.all.item(Control).value)="" then
		document.all.item("txtCambioCantidad").value = "false"
		document.all.item("txtConservaFocus").value="false"
	else
		document.all.item("txtCambioCantidad").value = "true"
		document.all.item("txtConservaFocus").value="true"
	end if
end sub

sub CambioNoParte(index)
	on error resume next
	if len( document.all.item("txtNoParteGrid" & index).value ) = 1 then  
		document.all.item("txtCambioNoParte").value = "true"
		document.all.item("txtConservaFocus").value = "true"
	end if
end sub

sub Colorea(index, Consec)
''Colorear los renglones
	on error resume next
	Indice = document.all.item("IndiceColor").value
	Clave = document.all.item("Consecutivo" & Indice).value
	if Clave >= 50 then
		Color = "MediumAquamarine"
	else
		Color = "White"
	end if

	document.all.item("Partida" & Indice).style.backgroundColor=Color
	if Consec < 50 then
		document.all.item("Partida" & index).style.backgroundColor="PowderBlue"
	end if		

	document.all.item("Consecutivo" & Indice).style.backgroundColor=Color
	document.all.item("Consecutivo" & index).style.backgroundColor="PowderBlue"
	document.all.item("ExiSucursal" & Indice).style.backgroundColor=Color
	document.all.item("ExiSucursal" & index).style.backgroundColor="PowderBlue"
	document.all.item("NoNuevo" & Indice).style.backgroundColor=Color
	document.all.item("NoNuevo" & index).style.backgroundColor="PowderBlue"
	document.all.item("Descripcion" & Indice).style.backgroundColor=Color
	document.all.item("Descripcion" & index).style.backgroundColor="PowderBlue"
	document.all.item("Precio" & Indice).style.backgroundColor=Color
	document.all.item("Precio" & index).style.backgroundColor="PowderBlue"
	document.all.item("Total" & Indice).style.backgroundColor=Color
	document.all.item("Total" & index).style.backgroundColor="PowderBlue"
	
	''Para los Vendedores
	document.all.item("PrecioLista" & Indice).style.backgroundColor=Color
	document.all.item("PrecioLista" & index).style.backgroundColor="PowderBlue"
	document.all.item("Diferencia" & Indice).style.backgroundColor=Color
	document.all.item("Diferencia" & index).style.backgroundColor="PowderBlue"
	
	''''
	document.all.item("IndiceColor").value = index
	
	document.all.item("txtCambioCantidad")="false"
	document.all.item("txtCambioNoParte")="false"
end sub

''''FUNCION DE BUSQUEDA
sub Buscar(Partida, NoParte)
	on error resume next
	
	if Partida="" then	
		document.CotizacionENC.txtNoParteBUSCAR.value=ucase(document.CotizacionENC.txtNoParteBUSCAR.value)
	end if
	
	if window.event.keycode = 37 then 
		document.all.item("txtPartidaBUSCAR").focus()
		document.all.item("txtPartidaBUSCAR").select()
	end if
		
	if window.event.keycode = 39 then
		document.all.item("txtNoParteBUSCAR").focus()
		document.all.item("txtNoParteBUSCAR").select()
	end if
	
	if window.event.keycode = 13 then
		Entro=False
		if Partida ="" and NoParte="" then
			msgbox "Favor de teclear la busqueda",vbExclamation
		else
			with window.parent.frames("CotizacionGrid")
				if NoParte="" then
					For i = 1 to cint(.document.all.item("RecordCount").value)
						if trim(.document.all.item("Partida" & i).innertext) = trim(Partida) then 
							.document.all.item("txtCantidadGRID" & i).focus()
							.document.all.item("txtCantidadGRID" & i).Select()
							Entro=true
							exit for
						end if
					Next
					if entro then 
						document.CotizacionENC.ExisteBusqueda.value=""
						document.CotizacionENC.txtPartidaBUSCAR.value=""
					else
						document.CotizacionENC.ExisteBusqueda.value="No Existe"
					end if
				else
					For i = 1 to cint(.document.all.item("RecordCount").value)
						if trim(.document.all.item("txtNoParteGRID" & i).value) = trim(NoParte) or trim(.document.all.item("NoNuevo" & i).innertext) = trim(NoParte) then  
							.document.all.item("txtNoParteGRID" & i).focus()
							.document.all.item("txtNoParteGRID" & i).Select()
							Entro=true
							exit for
						end if
					Next
					if entro then 
						document.CotizacionENC.ExisteBusqueda.value=""
						document.CotizacionENC.txtNoParteBUSCAR.value=""
					else
						document.CotizacionENC.ExisteBusqueda.value="No Existe"
					end if						
				end if
			end with
		end if
	end if
end sub
'''''''''''''''''''''''



