// +----------------------------------------------------------------------+
// | 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 rem_nombre=document.getElementById('rem_nombre').value.replace(/\n/g,"<br>");
  var des_nombre=document.getElementById('des_nombre').value.replace(/\n/g,"<br>");
  var rem_direccion=document.getElementById('rem_direccion').value.replace(/\n/g,"<br>");
  var des_direccion=document.getElementById('des_direccion').value.replace(/\n/g,"<br>");
  var rem_telefonos=document.getElementById('rem_telefonos').value.replace(/\n/g,"<br>");
  var des_telefonos=document.getElementById('des_telefonos').value.replace(/\n/g,"<br>");
  var comentarios=document.getElementById('comentarios').value.replace(/\n/g,"<br>");
  var mensaje_tarjeta=document.getElementById('mensaje_tarjeta').value.replace(/\n/g,"<br>");
  var horario_entrega=document.getElementById('horario_entrega').value.replace(/\n/g,"<br>");
  var url="doAccionesCarrito.php?task=checkout&rem_nombre="+rem_nombre+"&des_nombre="+des_nombre+"&rem_direccion="+rem_direccion+"&des_direccion="+des_direccion+"&rem_telefonos="+rem_telefonos+"&des_telefonos="+des_telefonos+"&comentarios="+comentarios+"&mensaje_tarjeta="+mensaje_tarjeta+"&horario_entrega="+horario_entrega;
  //alert(url);
  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

function validaEnvioContacto() {  
   var nombre=document.getElementById('nombre').value; 
   var email=document.getElementById('email').value;
   var telefono=document.getElementById('telefono').value;   
   var comentarios=document.getElementById('comentarios').value;
        
  var errores="";
  if(nombre=="") errores=errores+"Debes llenar el campo: Nombre\n";
  if(email=="") errores=errores+"Debes llenar el campo: E-mail\n";
  if(telefono=="") errores=errores+"Debes llenar el campo: Telefono\n";  
  if(comentarios=="") errores=errores+"Debes llenar el campo: Comentarios\n";
  //Si no hay vacios, enviar form
  if(errores=="")
   document.formcontacto.submit();
  else alert(errores);
} //funcion

function validaEnvioBoda() {  
   var fecha_evento=document.getElementById('fecha_evento').value; 
   var nombre_novios=document.getElementById('nombre_novios').value;
   var lugar_residencia=document.getElementById('lugar_residencia').value;   
   var telefono_celular=document.getElementById('telefono_celular').value;
   var telefono_casa=document.getElementById('telefono_casa').value;
   var telefono_oficina=document.getElementById('telefono_oficina').value;
   var email=document.getElementById('email').value;
   var ceremonia=document.getElementById('ceremonia').value;
   var recepcion=document.getElementById('recepcion').value;
   var tipo_flor=document.getElementById('tipo_flor').value;
   var color_flor=document.getElementById('color_flor').value;
   var detalles_evento=document.getElementById('detalles_evento').value;
           
  var errores="";
  if(fecha_evento=="") errores=errores+"Debes llenar el campo: Fecha evento\n";
  if(nombre_novios=="") errores=errores+"Debes llenar el campo: Nombre de los novios\n";
  if(lugar_residencia=="") errores=errores+"Debes llenar el campo: Lugar de residencia\n";  
  if(telefono_celular=="") errores=errores+"Debes llenar el campo: Telefono celular\n";
  if(telefono_casa=="") errores=errores+"Debes llenar el campo: Telefono casa\n";
  if(telefono_oficina=="") errores=errores+"Debes llenar el campo: Telefono oficina\n";
  if(email=="") errores=errores+"Debes llenar el campo: E-mail\n";
  if(ceremonia=="") errores=errores+"Debes llenar el campo: Ceremonia\n";
  if(recepcion=="") errores=errores+"Debes llenar el campo: Recepcion\n";
  if(tipo_flor=="") errores=errores+"Debes llenar el campo: Tipo de flor\n";
  if(color_flor=="") errores=errores+"Debes llenar el campo: Color de flor\n";
  if(detalles_evento=="") errores=errores+"Debes llenar el campo: Detalles del evento\n";
  //Si no hay vacios, enviar form
  if(errores=="")
   document.formboda.submit();
  else alert(errores);
} //funcion



