
    url           = document.location.href;
    xend          = url.lastIndexOf("/") + 1;
    var base_url  = url.substring( 0, xend );

//  ----------------------------------------------------------- ::: - ::: - ::: ------------
//  ----------------------------------------------------------- ::: - ::: - ::: ------------
    function ark_accion( url ) {

      if ( url.substring(0, 4) != 'http' ) {
        url       = base_url + url;
      }

      var jsElem  = document.createElement('SCRIPT');
      jsElem.type = 'text/javascript';
      jsElem.src  = url;

      document.body.appendChild( jsElem );
    }
    
    function sendPassword(email){
		ajax = new  Ajax();
		ajax.handleResp = function(resp) {
			$("#div_enviar_clave").html(resp);
		};	
		ajax.doSyncRequest("_ajax.php","POST","text","opc=enviarPass&email="+email+"&login");
    }
    
    function checkMaskOnFocus(id,mask){
    	if(document.getElementById(id).value == mask){
    		document.getElementById(id).value = '';
    	}
    }
    
    function checkMaskOnBlur(id,mask){
    	if(document.getElementById(id).value == ''){
    		document.getElementById(id).value = mask;
    	}
    }


//  registro cliente
//  ----------------------------------------------------------- ::: - ::: - ::: ------------
//  ----------------------------------------------------------- ::: - ::: - ::: ------------
    function ark_validarCliente( form, txt_campos_incompletos, txt_email_invalido, txt_claves_distintas ) {

//    que todos los campos estén completos
      if ( ark_validar( form, txt_campos_incompletos ) ) {

//      que el email sea válido
        if ( ark_validarEmail( document.getElementById('email') ) ) {

//        que las claves concuerden entre sí
          if ( document.getElementById('clave').value == document.getElementById('clave_confirma').value ) {
            form.submit();
          }
          else {
            alert( txt_claves_distintas.replace(/\+/g,' ') );
            document.getElementById('clave').focus();
          }
        }
        else {
          alert( txt_email_invalido.replace(/\+/g,' ') );
          document.getElementById('email').focus();
        }
      }
    }

    function ark_validarEmail( email ) {
      return email.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.info)|(\.edu)|(\.gov)|(\.org)|(\.info)|(\.biz)|(\.tv)|(\.tk)|(\.es)|(\.cl)|(\.ch)|(\..{2,2}))$)\b/gi);
    }


//  modificación datos
//  ----------------------------------------------------------- ::: - ::: - ::: ------------
//  ----------------------------------------------------------- ::: - ::: - ::: ------------
    function ark_validarDatosCliente( form, txt_campos_incompletos, txt_email_invalido, txt_claves_distintas ) {

//    que todos los campos estén completos
      if ( ark_validar( form, txt_campos_incompletos ) ) {

//      que el email sea válido
        if ( ark_validarEmail( document.getElementById('email') ) ) {

//        que las claves concuerden entre sí
          if ( document.getElementById('clave').value == '' || document.getElementById('clave').value == document.getElementById('clave_confirma').value ) {
            form.submit();
          }
          else {
            alert( txt_claves_distintas.replace(/\+/g,' ') );
            document.getElementById('clave').focus();
          }
        }
        else {
          alert( txt_email_invalido.replace(/\+/g,' ') );
          document.getElementById('email').focus();
        }
      }
    }


//  ----------------------------------------------------------- ::: - ::: - ::: ------------
//  ----------------------------------------------------------- ::: - ::: - ::: ------------
    function ark_validar( form, txt_campos_incompletos ) {

      var error = false;
      var first = -1;
      var chain = '';

      for ( var i = 0; i < form.elements.length; i++ ) {
        if ( form.elements[i].title != '' && form.elements[i].value == '' ) {
          if ( first < 0 ) {
            first   = i;
          }
          chain = chain + '- ' + form.elements[i].title + '\n';
          error = true;
        }
      }

      if ( error ) {
        alert( txt_campos_incompletos.replace(/\+/g,' ') + ':\n' + chain );
        form.elements[first].focus();
        return false;
      }
      else {
        return true;
      }
    }


    function ark_validarEmail( email ) {
      return email.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.info)|(\.edu)|(\.gov)|(\.org)|(\.info)|(\.biz)|(\.tv)|(\.tk)|(\.es)|(\.cl)|(\.ch)|(\..{2,2}))$)\b/gi);
    }


//  ingreso al sistema
//  ----------------------------------------------------------- ::: - ::: - ::: ------------
//  ----------------------------------------------------------- ::: - ::: - ::: ------------
    function ark_validarRegistro( form, txt_mensaje, txt_email, txt_clave ) {

      if ( document.getElementById('reg_email') && document.getElementById('reg_clave') ) {
        var email = document.getElementById('reg_email').value;
        var clave = document.getElementById('reg_clave').value;
        if ( email == '' || email == txt_email || clave == '' || clave == txt_clave ) {
          alert( txt_mensaje );
          return false;
        }
      }
      return true;
    }

//  compra
//  ----------------------------------------------------------- ::: - ::: - ::: ------------
//  ----------------------------------------------------------- ::: - ::: - ::: ------------
    function ark_recalcular( ) {
      document.compra.accion.value  = 'recalcular';
      document.compra.submit();
    }

    function ark_continuar( ) {
      document.compra.accion.value  = 'continuar';
      document.compra.submit();
    }

    function ark_realizarPedido( txt_confirmacion ) {
      if ( confirm( txt_confirmacion.replace(/\+/g,' ') ) ) {
        //document.envio.accion.value  = 'aceptar';
        document.envio.submit();
      }
    }


//  formularios
//  ----------------------------------------------------------- ::: - ::: - ::: ------------
//  ----------------------------------------------------------- ::: - ::: - ::: ------------
    function ark_borrar( form ) {
      form.reset();
    }


//  general
//  ----------------------------------------------------------- ::: - ::: - ::: ------------
//  ----------------------------------------------------------- ::: - ::: - ::: ------------
    function ark_ayuda( tipo ) {
      // nada por ahora
      // estaría bueno usar un lightbox o similar para los cuadritos de ayuda
    }


//  ----------------------------------------------------------- ::: - ::: - ::: ------------
//  ----------------------------------------------------------- ::: - ::: - ::: ------------
    function ark_vinculo( url ) {
      window.open( url );
    }


