// +----------------------------------------------------------------------+
// | Autor:  Daniel Figueroa J. <daniel@comuniterra.com>                  |
// +----------------------------------------------------------------------+
// | Descripcion:                                                         
// |     Libreria de funciones JScript para funciones especificas del sistema
// +----------------------------------------------------------------------+

function preAgregaCarrito(idproducto) {
 document.getElementById('span_cantidad_'+idproducto).style.display='block';
 document.getElementById('cantidad_'+idproducto).focus();
}

function agregarToCarrito(e,idproducto,precio) { 
 var tecla = (document.all) ? e.keyCode : e.which;
 //alert(tecla);
 //if(tecla==13) {
  var cantidad=document.getElementById('cantidad_'+idproducto).value;  
  if(!isNaN(cantidad)) {  
   var url="doAccionesCarrito.php?task=agregar&idproducto="+idproducto+"&precio="+precio+"&cantidad="+cantidad;
   abreSeccionEval(url);
   limpiaCantidadesCarrito(idproducto);
  }
  else
   alert(msg_error_cantidad);
 //} //if tecla  
} //funcion

function limpiaCantidadesCarrito(idproducto) {
 document.getElementById('cantidad_'+idproducto).value='';
 document.getElementById('span_cantidad_'+idproducto).style.display='none';	
} //funcion


function postAgregarCarrito(notifica) {
 if(notifica=="si") alert("OK");	
 var url="resumenTotalesCarrito.php";
 abreSeccion(url,'divTotalesCarrito');
}

function eliminarDeCarrito(iddc) {
 var url="doAccionesCarrito.php?task=eliminar&iddc="+iddc;
 abreSeccionEval(url);	
} //funcion

function verificaDuplicado(loginPropuesto) {
 var url="doAccionesRegistro.php?task=verifica_duplicado&loginPropuesto="+loginPropuesto;
 abreSeccionEval(url);	 
} //funcion

function validaRegistro() {  
   var login=document.getElementById('login').value; 
   var password=document.getElementById('password').value;
   var nombre=document.getElementById('nombre').value;   
   var calle=document.getElementById('calle').value;
   /*var no_ext=document.getElementById('no_ext').value;
   var cp=document.getElementById('cp').value;
   var ciudad=document.getElementById('ciudad').value;
   var estado=document.getElementById('estado').value;   */
   var telefono=document.getElementById('telefono').value;  
   //var colonia=document.getElementById('colonia').value;  
   var email=document.getElementById('email').value;
        
  var errores="";
  if(login=="") errores=errores+"Debes llenar el campo: Usuario\n";
  if(password=="") errores=errores+"Debes llenar el campo: Contrasena\n";
  if(nombre=="") errores=errores+"Debes llenar el campo: Nombre completo\n";  
  /*if(calle=="") errores=errores+"Debes llenar el campo: Calle\n";
  if(no_ext=="") errores=errores+"Debes llenar el campo: No ext\n";  
  if(cp=="") errores=errores+"Debes llenar el campo: CP\n";
  if(estado=="") errores=errores+"Debes llenar el campo: Estado\n";
  if(ciudad=="") errores=errores+"Debes llenar el campo: Ciudad\n";*/
  if(telefono=="") errores=errores+"Debes llenar el campo: Telefono\n";  
  //if(colonia=="") errores=errores+"Debes llenar el campo: Colonia\n";  
  if(email=="") errores=errores+"Debes llenar el campo: Email\n";      
  //Si no hay vacios, enviar form
  if(errores=="")
   document.formreg.submit();
  else alert(errores);
} //funcion

function checkout() {
 if(confirm(msg_checkout)) {	  
  var url="doAccionesCarrito.php?task=checkout";
  abreSeccionEval(url);
  
 }
} //funcion

function logout() {
 if(confirm(msg_logout)) {	
  document.location.href='unreg_cliente.php';	
 }
} //funcion

function eliminaVenta(sesion) {
 var url="../doAccionesCarrito.php?task=eliminar_compra&sesion="+sesion;
 abreSeccionEval(url);	
} //funcion

function filtraVentas(estatus) {
 var url="administrarVentas.php?estatus="+estatus;
 abreSeccion(url,'spanPrincipal');
} //funcion

function cambiaEstatusVenta(estatus,idcompra) {
 var url="../doAccionesCarrito.php?task=cambiar_estatus&estatus="+estatus+"&idcompra="+idcompra;
 abreSeccionEval(url);	
} //funcion

function filtraProductos(categoria) {
 var url="administrarProductos.php?categoria="+categoria;
 abreSeccion(url,'spanPrincipal');
} //funcion

function activaBotonRegistro(estatus) {
 document.getElementById('botonRegistro').disabled=estatus;	
} //funcion

function guardarTC(idmoneda) {
 var tc=document.getElementById('tc-'+idmoneda).value;
 var url="doAccionesCarrito.php?task=cambiar_tc&idmoneda="+idmoneda+"&tc="+tc;
 abreSeccionEval(url);	
} //funcion

function filtraMunicipios(idestado,idmunicipio) {  
  var url="listaMunicipios.php?idestado="+idestado+"&idmunicipio="+idmunicipio;
  abreSeccion(url,'listaMunicipios');  
} //funcion


function eliminarPagina(idpagina,lang) {
 if(confirm("Eliminar esta pagina?")) {
  var url="doEditarPagina.php?task=eliminar&idpagina="+idpagina+"&lang="+lang;
  abreSeccionEval(url);
 } //if confirm
} //funcion

function setMostrarEnCarrito(textbox) {
 if(document.getElementById(textbox+'_check').checked==1)
  document.getElementById(textbox+'-').value=1;
 else
  document.getElementById(textbox+'-').value=0; 
} //funcion

function setMostrarEnCarritoEditar(textbox,clave) {
 if(document.getElementById(textbox+'_check-'+clave).checked==1)
  document.getElementById(textbox+'-'+clave).value=1;
 else
  document.getElementById(textbox+'-'+clave).value=0; 
} //funcion

function modificaCantidadCarrito(e,idproducto,precio) { 
 var tecla = (document.all) ? e.keyCode : e.which;
 //alert(tecla);
 if(tecla==13) {
  var cantidad=document.getElementById('cantidad_'+idproducto).value;  
  if(!isNaN(cantidad)) {  
   var url="doAccionesCarrito.php?task=modificar_cantidad&idproducto="+idproducto+"&precio="+precio+"&cantidad="+cantidad;
   abreSeccionEval(url);   
  }
  else
   alert(msg_error_cantidad);
 } //if tecla  
} //funcion

