function AbrirCentro(url,nompopup,popW,popH,resizable,scroll){
	w = screen.availWidth;
	h = screen.availHeight;
	var leftPos = (w-popW)/2; topPos = (h-popH)/2;
	leftPos = leftPos - 20;
	topPos = topPos - 20;
	window.open(url,nompopup,'width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos + ',resizable=' + resizable + ',scrollbars=' + scroll );
}

function CantidadPag(origen) {
	
	/*location.reload(true);*/
	//alert(origen);
/*    location.reload(true); 	*/
    //document.perufarma.cantpag.value();
	//alert("<%=origen?cantpag="+document.perufarma.cantpag.value+"%>");
	document.perufarma.action = origen.replace("?", "?flag=1&cantpag=" + document.perufarma.cantpag.value + "&") ;
	//document.perufarma.action = origen.replace("?", "?cantpag=" + "" + "&") ;
	//document.perufarma.action = origen
	document.perufarma.submit();
}

function Busqueda() {
	document.perufarma.action = "busqueda.asp";
	if (document.perufarma.buscador.value == "") {
		alert("Debe ingresar un valor para iniciar la búsqueda.");
		document.perufarma.buscador.focus();
		return;
	}
	document.perufarma.submit();
}

/* busqueda de Recetas */
function BuscaReceta() {
	document.perufarma.action = "RecetasFind.asp";	
	document.perufarma.submit();
}
/* busqueda de listas */
function BusquedaLista() {
	document.perufarma.action = "lista_productos.asp";	
	document.perufarma.submit();
}
/* impresion de listas */
function ImprimeLista() {
	document.perufarma.action = "ImprimirLista.asp";	
	document.perufarma.submit();
}

function BusquedaAvanzada() {
	document.perufarma.action = "busquedaavan.asp";	
	document.perufarma.submit();
}

function BusquedaVinos() {
	document.perufarma.action = "busquedavin.asp";	
	document.perufarma.submit();
}
/*
function BusquedaAvanzada() {
	document.perufarma.action = "busquedaavan.asp";
	if (document.perufarma.palabraclave.value == "") {
		alert("Debe ingresar un valor para iniciar la búsqueda avanzada.");
		document.perufarma.palabraclave.focus();
		return;
	}
	document.perufarma.submit();
}
*/
function Imprimible(tipo,codigo) {
	url = "impresion.asp?tipo=" + tipo + "&codigo=" + codigo
	ventana = "PF" + codigo
	AbrirCentro(url,ventana,550,300,'no','yes');
}
function Imprimir() {
	window.print()
}
function EnvioMail(tipo,codigo) {
	url = "MailProducto.aspx?tipo=" + tipo + "&codigo=" + codigo
	ventana = "PF" + codigo
	AbrirCentro(url,ventana,650,450,'no','yes');
}
function Agregar(codigo,stock)
{
	xCantidad = "document.perufarma.cantidad" + codigo + ".value"
	if (eval(xCantidad) > eval(stock))
	{
		alert("Cantidad solicitada excede Stock: " + stock);
	}
	else
	{
		document.perufarma.action = "verifica_carrito.asp"		
		xCantidad = "document.perufarma.cantidad" + codigo + ".value"
		document.perufarma.xcantidad.value = eval(xCantidad)
		if (document.perufarma.xcantidad.value == "")
		{
			document.perufarma.xcantidad.value = 1
		}
		document.perufarma.producto.value = codigo
		document.perufarma.submit()
	}
}


function Marcas(codigo) {
	document.perufarma.action = "productosm.asp";
	document.perufarma.marca.value = codigo
	document.perufarma.submit();
}
function MarcasC(categoria,codigo) {
	document.perufarma.action = "productoscxm.asp";
	document.perufarma.categoria.value = categoria
	document.perufarma.marca.value = codigo
	document.perufarma.submit();
}
function Productos(codigo) {
	document.perufarma.action = "productos.asp";
	document.perufarma.division.value = codigo
	document.perufarma.submit();
}
function Categorias(codigo) {
	document.perufarma.action = "productosc.asp";
	document.perufarma.categoria.value = codigo

	document.perufarma.submit();
}
function SubCategorias(codigo) {
	document.perufarma.action = "productossc.asp";
	document.perufarma.subcategoria.value = codigo
	document.perufarma.submit();
}
function Producto(codigo) {
	document.perufarma.action = "dproductos.asp";
	document.perufarma.producto.value = codigo
	document.perufarma.submit();
}
function Imagen(codigo,ventana){
	url = "dimagenes.asp?id=" + codigo
	AbrirCentro(url,ventana,50,50,'no','no');
}
function Promos()
{
	url = "promo.html"
	AbrirCentro(url,"promo",50,50,'no','no');
}
function Lineas(codigo) {
	document.perufarma.action = "recetaspxm.asp";
	document.perufarma.linea.value = codigo
	document.perufarma.submit();
}
function Recetas(codigo) {
	document.perufarma.action = "recetasrxp.asp";
	document.perufarma.producto.value = codigo
	document.perufarma.submit();
}
function Tipos(codigo) {
	document.perufarma.action = "recetasp.asp";
	document.perufarma.tipo.value = codigo
	document.perufarma.submit();
}
function Receta(codigo) {
	document.perufarma.action = "drecetas.asp";
	document.perufarma.receta.value = codigo
	document.perufarma.submit();
}
function Entrar() {
	document.perufarma.action = "validar.asp";
	if (document.perufarma.usuario.value == "") {
		alert("Debe ingresar su Nombre de Usuario.");
		document.perufarma.usuario.focus();
		return;
	}
	if (document.perufarma.contrasena.value == "") {
		alert("Debe ingresar su Contraseña.");
		document.perufarma.contrasena.focus();
		return;
	}
	document.perufarma.proceso.value = "login"
	document.perufarma.submit();
}
function Registrar() {	
	document.perufarma.action = "validar.asp";
	if (document.perufarma.usuarioA.value == "") {
		alert("Debe ingresar su Nombre de Usuario.");
		document.perufarma.usuarioA.focus();
		return;
	}
	if (!EsEmail(document.perufarma.emailA.value)) {
		alert("Debe ingresar un Email válido.");
		document.perufarma.emailA.focus();
		return;
	}
	if (document.perufarma.clave.value == "") {
		alert("Debe ingresar una contraseña.");
		document.perufarma.clave.focus();
		return;
	}
	document.perufarma.proceso.value = "registro"
	document.perufarma.submit();
}

function Eventos(codigo) {
	document.perufarma.action = "eventosd.asp";
	document.perufarma.division.value = codigo
	document.perufarma.submit();
}
function Evento(codigo) {
	document.perufarma.action = "deventos.asp";
	document.perufarma.evento.value = codigo
	document.perufarma.submit();
}

function Promociones(codigo) {
	document.perufarma.action = "productosxp.asp";
	document.perufarma.division.value = codigo
	document.perufarma.submit();
}
function MarcasP(codigo) {
	document.perufarma.action = "productosmxp.asp";
	document.perufarma.marca.value = codigo
	document.perufarma.submit();
}
function CategoriasP(codigo) {
	document.perufarma.action = "productoscxp.asp";
	document.perufarma.categoria.value = codigo
	document.perufarma.submit();
}
function SubCategoriasP(codigo) {
	document.perufarma.action = "productosscxp.asp";
	document.perufarma.subcategoria.value = codigo
	document.perufarma.submit();
}

function Novedades(codigo) {
	document.perufarma.action = "productosxn.asp";
	document.perufarma.division.value = codigo
	document.perufarma.submit();
}
function MarcasN(codigo) {
	document.perufarma.action = "productosmxn.asp";
	document.perufarma.marca.value = codigo
	document.perufarma.submit();
}
function CategoriasN(codigo) {
	document.perufarma.action = "productoscxn.asp";
	document.perufarma.categoria.value = codigo
	document.perufarma.submit();
}
function SubCategoriasN(codigo) {
	document.perufarma.action = "productosscxn.asp";
	document.perufarma.subcategoria.value = codigo
	document.perufarma.submit();
}

function Aviso(codigo) {
	if (codigo == "EA") {
		alert("Usuario y/o Contraseña incorrectos.\nPor favor verifique la información ingresada.")
	}
	if (codigo == "ER") {
		alert("Usuario y/o Email ya están en nuestro sistema.\nPor favor verifique la información ingresada.")
	}
	if (codigo == "CO") {
		alert("La clave fue cambiada correctamente.")
	}
	if (codigo == "EC") {
		alert("La Clave Actual ingresada es incorrecta.\nPor favor verifique la información ingresada.")
	}
	if (codigo == "PC") {
		alert("Su información fue procesada correctamemte.\nGracias por enviarnos su información.")
	}
}
function Salir() {
	document.perufarma.action = "validar.asp";
	document.perufarma.proceso.value = "logout"
	document.perufarma.submit();
}
function EsEmail(string) {
	if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) {
		return true;
	} else {
		return false;
	}
}
function Montos(string) {
    var valid = "0123456789.";
    var rpta = '';
    for (var i=0; i<string.length; i++){
        val = string.substring(i, i+1);
        if (valid.indexOf(val) > -1) rpta += val;
    }
    return rpta;
}
function Enteros(string) {
    var valid = "0123456789";
    var rpta = '';
    for (var i=0; i<string.length; i++){
        val = string.substring(i, i+1);
        if (valid.indexOf(val) > -1) rpta += val;
    }
    return rpta;
}
function Caracteres(string) {
    var invalid = "!ñÑ´áéíóúÁÉÍÓÚ{}[]";
    var rpta = '';
    for (var i=0; i<string.length; i++){
        inval = string.substring(i, i+1);
        if (invalid.indexOf(inval) > -1) rpta += inval;
    }
    return rpta;
}
function Espacio(string) {
    var invalid = " ";
    var rpta = '';
    for (var i=0; i<string.length; i++){
        inval = string.substring(i, i+1);
        if (invalid.indexOf(inval) > -1) rpta += inval;
    }
    return rpta;
}
function Puntos(string) {
    var invalid = ".";
    var rpta = '';
    for (var i=0; i<string.length; i++){
        inval = string.substring(i, i+1);
        if (invalid.indexOf(inval) > -1) rpta += inval;
    }
    return rpta;
}


function Contacto(codigo){
	url = "contacto.asp?id=" + codigo
	AbrirCentro(url,'Contacto',520,270,'no','no');
}
function FechaActual () {
	marcacion = new Date()
	Hora = marcacion.getHours()
	Minutos = marcacion.getMinutes()
	Segundos = marcacion.getSeconds()

	if (Hora<=9) { Hora = "0" + Hora }
	if (Minutos<=9) { Minutos = "0" + Minutos  }
	if (Segundos<=9) { Segundos = "0" + Segundos }

	var Dia = new Array("Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado","Domingo");
	var Mes = new Array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
	var Hoy = new Date();
	var Anio = Hoy.getFullYear();
	var Fecha = "Lima - Perú, " + Dia[Hoy.getDay()] + " " + Hoy.getDate() + " de " + Mes[Hoy.getMonth()] + " del " + Anio;
	FechaTotal = Fecha

	document.getElementById('FechaReloj').innerHTML = FechaTotal
	setTimeout("FechaActual()",1000)
}
function Over(name) {
	actual = document.getElementById(name).src
	total = actual.length
	tipo = actual.substr(total-3,total)
	if (tipo=="jpg") {
		formato = "jpg"
	} else {
		formato = "gif"
	}
	document.getElementById(name).src = "images/" + name + "_on." + formato;
}
function Out(name) {
	actual = document.getElementById(name).src
	total = actual.length
	tipo = actual.substr(total-3,total)
	if (tipo=="jpg") {
		formato = "jpg"
	} else {
		formato = "gif"
	}
	document.getElementById(name).src = "images/" + name + "." + formato;
}
function PopupHome(url){
	AbrirCentro(url,'popup',297,297,'no','no');
}
function Enter() {
	if(event.keyCode == 13) {
		if (document.perufarma.txtBuscador.value != "") {
			Busqueda();
		}
	}
}


