var url = "http://www.ebandlive.com/wp-content/themes/ebandlive/username.php?param=";
    
var http = getHTTPObject();
    
function updateName() {
  /* Print the message to use while checking the database: */
  document.getElementById('checked').innerHTML = "Checking...";
  /* We're assuming your username input ID is "username" */
  var name = document.getElementById("email").value;
  http.open("GET", url + escape(name), true);
  http.onreadystatechange = handleHttpResponse;
  http.send(null);
}

function handleHttpResponse() {
  if (http.readyState == 4) {
    results = http.responseText;
    /* Again, we're assuming your username input ID is "username" */
    var name = document.getElementById("email").value;
    /* If the username is available, Print this message: */
    if(results == "") results = "<font color=\"green\"><i>"+name+"</i> is Available!</font>";
    document.getElementById('checked').innerHTML = results;
  }
}

function getHTTPObject() {
  var xmlhttp;
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}
    
jQuery(document).ready(function($) {
    
    function verifynotify(field1, field2, result_id, match_html, nomatch_html) {
     this.field1 = field1;
     this.field2 = field2;
     this.result_id = result_id;
     this.match_html = match_html;
     this.nomatch_html = nomatch_html;
    
     this.check = function() {
    
       // Make sure we don't cause an error
       // for browsers that do not support getElementById
       if (!this.result_id) { return false; }
       if (!document.getElementById){ return false; }
       r = document.getElementById(this.result_id);
       if (!r){ return false; }
    
       if (this.field1.value != "" && this.field1.value == this.field2.value) {
         r.innerHTML = this.match_html;
         $('.createsubmit').removeClass('disabled').attr('disabled', '');
       } else {
         r.innerHTML = this.nomatch_html;
         $('.createsubmit').addClass('disabled').attr('disabled', 'disabled');
       }
     }
    }

  $('.error').hide();

  $(".createsubmit").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  var bandname = $("input#bandname").val();
		if (bandname == "") {
      $("label#bandname_error").show();
      $("input#bandname").focus();
      return false;
    }
		var email = $("input#email").val();
		if (email == "") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
	  var firstname = $("input#firstname").val();
		if (firstname == "") {
      $("label#firstname_error").show();
      $("input#firstname").focus();
      return false;
    }
	  var lastname = $("input#lastname").val();
		if (lastname == "") {
      $("label#lastname_error").show();
      $("input#lastname").focus();
      return false;
    }
	  var password1 = $("input#password1").val();
		if (password1 == "") {
      $("label#password1_error").show();
      $("input#password1").focus();
      return false;
    }
	  var password2 = $("input#password2").val();
		if (password2 == "") {
      $("label#password2_error").show();
      $("input#password2").focus();
      return false;
    }
		
		var dataString = 'name='+ bandname + '&email=' + email + '&first=' + firstname + '&last=' + lastname + '&pass1=' + password1 + '&pass2=' + password2;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "http://www.ebandlive.com/wp-content/themes/ebandlive/bin/process.php",
      data: dataString,
      success: function() {
        $('#create').html('<div id="thankyou"></div>');
        $('#thankyou').html('<h2 class="ready">Awesome, we&rsquo;re ready for ya.</h2>')
        .append('<h5>Start rocking your site already.</h5>')
        .append('<p class="btn backstage"><a href="http://backstage.ebandlive.com" target="_blank"><img src="http://www.ebandlive.com/wp-content/themes/ebandlive/images/btn_backstage.png" alt="Login to your backstage"></a></p>')
        .append('<img height="1" width="1" border="0" src="https://www.googleadservices.com/pagead/conversion/1025310499/?value=0&amp;label=hkaNCP_cuwEQo_7z6AM&amp;script=0"/>')
        .append("<script type='text/javascript'>"+
          "var pageTracker = _gat._getTracker('UA-6578205-1');"+
          "pageTracker._trackPageview('/trialthankyou');"+
          "</"+"script>");
      }
     });
    return false;
	});

  runOnLoad(function(){
    $("input#bandname").select().focus();
  });

  verify = new verifynotify();
  verify.field1 = document.signup_form.password1;
  verify.field2 = document.signup_form.password2;
  verify.result_id = "password_result";
  verify.match_html = "<SPAN STYLE=\"color:green\">Your passwords match!<\/SPAN>";
  verify.nomatch_html = "<SPAN STYLE=\"color:red\">Passwords do not match!<\/SPAN>";
  
  // Update the result message
  verify.check();

});
