// JavaScript Document
//Esta funcion es llamada desde el archivo mod_popup.php
function popInit(titulo,ancho)
{
	Modalbox.show("_jqpooop.php", {title: titulo, width: ancho});
}
function no_puede_cursar_compra(page_id,_IDCAT,_IDSUBCAT,_IDIOMA)
{
	alert("Para generar un pedido debe ingresar estar registrado");
	url="_login_usuario.php?page_id="+page_id+"&idcat="+_IDCAT+"&idsubcat="+_IDSUBCAT+"&idioma="+_IDIOMA;
	Modalbox.show(url, {title: "LOGIN USUARIO", width: 720});
}
function cursar_pedido(page_id,_IDCAT,_IDSUBCAT,_IDIOMA)
{
	if(confirm("Usted generara un pedido, esta seguro de realizar esta operacion?"))
	{
		location.href = "index.php?page_id="+page_id+"&idcat="+_IDCAT+"&idsubcat="+_IDSUBCAT+"&idioma="+_IDIOMA+"&cur_ped=true";
	}
}
function registro_log_in()
{
	nick=trim(document.getElementById("nick").value);
	pass=trim(document.getElementById("password").value);
	if(nick=="")
	{
		alert("Debe ingresar su nick/usuario");
		return
	}
	if(pass=="")
	{
		alert("Debe ingresar su clave/password");
		return
	}
	document.getElementById('form_login_usuario').submit();
}
function registro_nuevo_usuario()
{
	nick=trim(document.getElementById("nick_reg").value);
	pass=trim(document.getElementById("password_reg").value);
	email=trim(document.getElementById("email").value);
	nombre=trim(document.getElementById("nombre").value);
	nombre_empresa=trim(document.getElementById("nombre_empresa").value);
	rut_empresa=trim(document.getElementById("rut_empresa").value);
	
	if(nick=="")
	{
		alert("Debe ingresar su nick/usuario");
		return;
	}
	if((email=="") || (email.indexOf("@") < 0) || (email.length < 6))
	{
		alert("Debe ingresar su correo electronico");
		return;
	}
	
	if(nombre_empresa=="")
	{
		alert("Debe ingresar su nombre");
		return;
	}
	if(rut_empresa=="")
	{
		alert("Debe ingresar su nombre");
		return;
	}
	if(pass=="")
	{
		alert("Debe ingresar su clave/password");
		return;
	}
	if(pass!=document.getElementById("password_reg_rep").value)
	{
		alert("Las claves no coinciden");
		return;
	}
	if(nombre=="")
	{
		alert("Debe ingresar un nombre de contacto");
		return;
	}
	document.getElementById('form_registra_usuario').submit();
}
/*FUNCION TRIM PARA JSCRIPT*/
function trim(str)
{
  return ( (""+str).replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') );
}

function muestraDiv(id_div,id_micro,dir)
{

	var cadena=document.images["img_"+id_micro+""].src;
	if (cadena.indexOf('boton_mas_display.gif')!=-1)
		document.images["img_"+id_micro+""].src= dir+"boton_menos_display.gif";
	else
		document.images["img_"+id_micro+""].src = dir+"boton_mas_display.gif";
	
	if(document.getElementById(id_div).style.display=='none'){
    document.getElementById(id_div).style.display='';
    }else{
    document.getElementById(id_div).style.display='none';
    }

}
function contacto() {
	if ((document.newsform.nombre.value == "") || (document.newsform.nombre.value== null))
	{
		alert("Por favor escriba su nombre.");
		document.newsform.nombre.focus();
		return false;
	}
	if ((document.newsform.apellido.value == "") || (document.newsform.apellido.value== null))
	{
		alert("Por favor escriba su apellido.");
		document.newsform.apellido.focus();
		return false;
	}
	if ((document.newsform.rut.value == "") || (document.newsform.rut.value== null))
	{
		alert("Por favor escriba su rut.");
		document.newsform.rut.focus();
		return false;
	}
	if ((document.newsform.telefono.value == "") || (document.newsform.telefono.value== null))
	{
		alert("Por favor ingrese su telefono.");
		document.newsform.telefono.focus();
		return false;
	}
	if ((document.newsform.pais.value == "") || (document.newsform.pais.value== null))
	{
		alert("Por favor escriba su país.");
		document.newsform.pais.focus();
		return false;
	 }
	if ((document.newsform.email.value == "") || (document.newsform.email.value.indexOf("@") < 0) || (document.newsform.email.value.length < 6))
	{
		alert("Por favor escriba su email.");
		document.newsform.email.focus();
		return false;
	}
	
	return true;
} 
var menuAnterior;
function function_mostmenudivhorizontal(mitem_id)
{
	if(menuAnterior!=null)
		document.getElementById("div_menu_float_"+menuAnterior).style.visibility='hidden';	
	document.getElementById("div_menu_float_"+mitem_id).style.visibility='';
	menuAnterior=mitem_id;
}

var menuAnteriorHijo;
function function_mostmenuhijo(mitem_id)
{
	if(menuAnteriorHijo!=null)
		document.getElementById("div_menuhijo_float_"+menuAnteriorHijo).style.visibility='hidden';	
	document.getElementById("div_menuhijo_float_"+mitem_id).style.visibility='';
	menuAnteriorHijo=mitem_id;
}

/*MODULO PRODUCTOS*/
function addtobasquet(id)
{
	if(isNaN(parseInt(document.getElementById('cant_'+id).value)))
	{
		alert("Ingrese una cantidad");
		document.getElementById('cant_'+id).focus();
		return;
	}
	if(parseInt(document.getElementById('cant_'+id).value)<1)
	{
		alert("Ingrese un numero mayor que 1");
		document.getElementById('cant_'+id).focus();
		return;
	}
	document.getElementById('producto').value=id;
	document.getElementById('cantidad').value=document.getElementById('cant_'+id).value;
	document.getElementById('productos_form').submit();
}
function addtobasquet_modal(id)
{
	if(isNaN(parseInt(document.getElementById('cant_'+id).value)))
	{
		alert("Ingrese una cantidad");
		document.getElementById('cant_'+id).focus();
		return;
	}
	if(parseInt(document.getElementById('cant_'+id).value)<1)
	{
		alert("Ingrese un numero mayor que 1");
		document.getElementById('cant_'+id).focus();
		return;
	}
	document.getElementById('producto').value=id;
	document.getElementById('cantidad').value=document.getElementById('cant_'+id).value;
	document.getElementById('carro').value="false";
	document.getElementById('productos_form').submit();
}
function deletetobasquet(id)
{
	if(confirm("Ha seleccionado un producto para eliminar. Desea continuar?"))
	{
		document.getElementById('producto').value=id;
		document.getElementById('cantidad').value='';
		document.getElementById('delete').value="true";
		document.getElementById('carro').value="true";
		document.getElementById('productos_form').submit();	
	}
}
