image1 = new Image();
image1.src = "<?php bloginfo('template_directory'); ?>/images/loading.gif";

$(function(){
  $("#client-login-open").click(function(event){
    event.preventDefault();
    $("#loginForm").slideDown("slow");
  });
  
  $("#client-login-close").click(function(event){
    event.preventDefault();
    $("#loginForm").slideUp("slow");
  });
  
  $("#client-login-form").submit(function(event){
    domain = $("#domain").attr("value");
    event.preventDefault();
    if (domain == "")
    {
      alert("Please enter a valid domain name.");
    }
    else {
      $.ajax({
        url: "http://nj.fyntest.com/api/domains/" + domain,
        type: "GET",
        cache: false,
        success: function(res){
          response = $(res.responseText);
          text = response.text();
          admin_url = text.match(/admin-[a-zA-z0-9]+\.fynanz\.com/);
          if (admin_url){
            window.location = "https://" + admin_url;
		    $("#domain").hide();
			$("#client-login-submit").hide();
		    $("#loading").removeClass('hidden');
          }
          else {
            alert("Sorry. This is not a valid domain.");
            $("#domain").focus();
          }
        }
      });      
    }

  });
  
})