<!DOCTYPE HTML>
<html>
<head>
    
  <title>Squarespace - Trial Website</title>
  <meta http-equiv="X-UA-Compatible" content="chrome=1">

  <script type="text/javascript" src="/universal/scripts-v6/yui-seed.js"></script>

  <style>
    .captcha { font-size: 55px; line-height: 60px; color: #fff; text-align: center; letter-spacing: 6px !important; }
    .bigtext .visitor-login-button { margin-left: 12px;}
  </style>

  <script>

    Y = YUI(YUI_CONFIG).use("squarespace-util", "squarespace-dialog", "squarespace-ui-base",  "squarespace-configuration-css",  function(Y) {
	
      Y.on("domready", function() {
      
        LB = new Y.Squarespace.Lightbox({
          disableNormalClose: true,
          clickAnywhereToExit: false,
          content: '<div class="bigtext"><div class="title">Squarespace Trial</div><div class="description"><strong>Squarespace trial accounts are not visible to the public. </strong>  When you are ready to publish your website, upgrading your trial will make your site active to the world. </div><div class="buttons"><input class="owner-login-button" type="button" name="login" value="Owner Login"/> <input class="visitor-login-button" type="button" name="visitor-login-button" value="Visitor Access"/></div></div>',
          margin: 100,
          noHeightConstrain: true
        });

        LB.on("overlay-visible", function() {

          LB.getContentEl().on("click", function(e) {

            if (e.target.ancestor(".owner-login-button", true)) {
              document.location.href = '/config/';
            }

            if (e.target.ancestor(".visitor-login-button", true)) {
              showVisitorLogin();
            }

          });
          
        });

        LB.show();

      });
          
    }); 

    function makeCaptcha() {
      var text = "";
      var possible = "ABCDEFGHJKLMNOPQRSTUVWXYZ";
      for (var i=0; i < 5; i++) {
        text += possible.charAt(Math.floor(Math.random() * possible.length));
      }
      return text;
    }
    
    // whether the current location contains a query string
    function containsQuery() {
    	return (window.location.search.length > 0);
    }

    function showVisitorLogin() {

      var captcha = makeCaptcha(); // NOTE:  Meant to be annoying, not secure

      var d = new Y.Squarespace.EditingDialog({

        loadingText: "Loading...",
        savingText: "Accessing...",
        closingText: "",
        overlay: 0.9,
        width: 460,
        top: 200,
        closeOthers: false,
        closeable: true,
        disableOverlayCancel: false,
        title: "Visitor Access",
        buttons: [
          { type: "cancel", title: "Cancel" },
          { type: "saveAndClose", title: "View Website" }
        ],

        tabs: [

          {
            icon: "/universal/images-v6/dialog/dialog-icon-member.png",
            fields: [

              { type: "description", text: "This website is in trial mode and has not yet launched.  To log into this trial website, type this word in the box below.", padding: [0, 15] },
              { type: "description", text: '<div class="captcha">' + captcha + '</div>', padding: [0, 15] },

              { type: "text", required: true, name: "captcha", title: "Type the word above...", style: "title", titleStyle: "inline", submitOnEnter: true, mailcheck: true }

            ]
          }
        ]
      });

      d.on("send-requested", function() {

        if (d.getField("captcha").getValue().toLowerCase() == captcha.toLowerCase()) {

          Y.Data.post({
            url: "/api/auth/AuthenticateAsVisitor",
            success : function(data) {

              d.close();
              
              if (containsQuery()) {
            	  document.location.href = document.location.href + "&r=" + Math.floor(Math.random()*99999999+1);  
              }
              else {
            	  document.location.href = document.location.href + "/?r=" + Math.floor(Math.random()*99999999+1);
              }
              

            }

          }, this);

        } else {
          d.getField("captcha").showError("That's not the right word.");
          d.allowEditing();
        }

      }, this);

      d.on("cancel", function() {

        LB.show();

      });

      LB.hide();
      d.show();


    }

  </script> 


</head>
<body class="squarespace-config squarespace-system-page">

  <div class="minimal-logo">&nbsp;</div>

</body>
</html>
