$(document).ready(function() {
	$('#tweet_first_nameLoading').hide();
	$('#tweet_first_name').blur(function(){
	  if(this.value != this.lastValue) {
		  if(this.value == "") {
		   	this.lastValue = this.value;
				matched['tweet_first_nameResult'] = 0;
				str = '';
        $('#tweet_first_nameResult').fadeOut();
        setTimeout("finishAjax('tweet_first_nameResult', 'tweet_first_nameLoading', '"+escape(str)+"')", 400);
		   	return false;
		  }
			$('#tweet_first_nameResult').hide(); // fadeOut();
		  $('#tweet_first_nameLoading').show();
      $.post("check_name.php", {
        field: $('#tweet_first_name').val()
      }, function(response){
        setTimeout("finishAjax('tweet_first_nameResult', 'tweet_first_nameLoading', '"+escape(response)+"')", 400);
      });
	   	this.lastValue = this.value;
    }
   	return false;
	});

	$('#tweet_last_nameLoading').hide();
	$('#tweet_last_name').blur(function(){
	  if(this.value != this.lastValue) {
		  if(this.value == "") {
		   	this.lastValue = this.value;
				matched['tweet_last_nameResult'] = 0;
				str = '';
        $('#tweet_last_nameResult').fadeOut();
        setTimeout("finishAjax('tweet_last_nameResult', 'tweet_last_nameLoading', '"+escape(str)+"')", 400);
		   	return false;
		  }
			$('#tweet_last_nameResult').hide(); // fadeOut();
		  $('#tweet_last_nameLoading').show();
      $.post("check_name.php", {
        field: $('#tweet_last_name').val()
      }, function(response){
        setTimeout("finishAjax('tweet_last_nameResult', 'tweet_last_nameLoading', '"+escape(response)+"')", 400);
      });
	   	this.lastValue = this.value;
    }
   	return false;
	});

	$('#tweet_emailLoading').hide();
	$('#tweet_email').blur(function(){
	  if(this.value != this.lastValue) {
		  if(this.value == "") {
		   	this.lastValue = this.value;
				matched['tweet_emailResult'] = 0;
				str = '';
        $('#tweet_emailResult').fadeOut();
        setTimeout("finishAjax('tweet_emailResult', 'tweet_emailLoading', '"+escape(str)+"')", 400);
		   	return false;
		  }
			$('#tweet_emailResult').hide(); // fadeOut();
		  $('#tweet_emailLoading').show();
      $.post("check_email.php", {
        email: $('#tweet_email').val()
      }, function(response){
        setTimeout("finishAjax('tweet_emailResult', 'tweet_emailLoading', '"+escape(response)+"')", 400);
      });
	   	this.lastValue = this.value;
    }
   	return false;
	});

	$('#twitter_usernameLoading').hide();
	$('#twitter_username').blur(function(){
	  if(this.value != this.lastValue) {
		  if(this.value == "") {
		   	this.lastValue = this.value;
				matched['twitter_usernameResult'] = 0;
				str = '';
        $('#twitter_usernameResult').fadeOut();
        setTimeout("finishAjax('twitter_usernameResult', 'twitter_usernameLoading', '"+escape(str)+"')", 400);
		   	return false;
		  }
			$('#twitter_usernameResult').hide(); // fadeOut();
		  $('#twitter_usernameLoading').show();
      $.post("check_username.php", {
        username: $('#twitter_username').val()
      }, function(response){
        setTimeout("finishAjax('twitter_usernameResult', 'twitter_usernameLoading', '"+escape(response)+"')", 400);
      });
	   	this.lastValue = this.value;
    }
   	return false;
	});

	$('#twitter_passwordLoading').hide();
	$('#twitter_password').blur(function(){
	  if(this.value != this.lastValue) {
		  if(this.value == "") {
		   	this.lastValue = this.value;
				//matched['twitter_passwordResult'] = 0;
				str = '';
        $('#twitter_passwordResult').fadeOut();
        setTimeout("finishAjax('twitter_passwordResult', 'twitter_passwordLoading', '"+escape(str)+"')", 400);
		   	return false;
		  }
			$('#twitter_passwordResult').hide(); // fadeOut();
		  $('#twitter_passwordLoading').show();
      $.post("check_name.php", {
        field: $('#twitter_password').val()
      }, function(response){
        setTimeout("finishAjax('twitter_passwordResult', 'twitter_passwordLoading', '"+escape(response)+"')", 400);
      });
	   	this.lastValue = this.value;
    }
   	return false;
	});

	$('#password1Loading').hide();
	$('#password1').blur(function(){
	  if(this.value != this.lastValue) {
		  if(this.value == "") {
		   	this.lastValue = this.value;
				matched['password1Result'] = 0;
				str = '';
        $('#password1Result').fadeOut();
        setTimeout("finishAjax('password1Result', 'password1Loading', '"+escape(str)+"')", 400);
		   	return false;
		  }
			$('#password1Result').hide(); // fadeOut();
		  $('#password1Loading').show();
      $.post("check_password.php", {
        password: $('#password1').val()
      }, function(response){
        setTimeout("finishAjax('password1Result', 'password1Loading', '"+escape(response)+"')", 400);
      });
	   	this.lastValue = this.value;
			if(this.value != password2Save && password2Save != "") {
				matched['password2Result'] = 0;
				str = ''; // '<span id="password2Result-bad" style="color:#f00">The Passwords Do Not Match</span>';
        setTimeout("finishAjax('password2Result', 'password2Loading', '"+escape(str)+"')", 400);
        document.getElementById( "password2" ).value = "";
			}
    }
   	return false;
	});

	$('#password2Loading').hide();
	$('#password2').blur(function(){
	  if(this.value != this.lastValue) {
		  if(this.value == "") {
		   	this.lastValue = this.value;
				matched['password2Result'] = 0;
				str = '';
        $('#password2Result').fadeOut();
        setTimeout("finishAjax('password2Result', 'password2Loading', '"+escape(str)+"')", 400);
		   	return false;
		  }
			$('#password2Result').hide(); // fadeOut();
		  $('#password2Loading').show();
      $.post("check_cpassword.php", {
        password: $('#password1').val(),
        cpassword: $('#password2').val()
      }, function(response){
        setTimeout("finishAjax('password2Result', 'password2Loading', '"+escape(response)+"')", 400);
      });
	   	this.lastValue = this.value;
	   	password2Save = this.value;
    }
   	return false;
	});

	$('#cbaffidLoading').hide();
	$('#cbaffid').blur(function(){
	  if(this.value != this.lastValue) {
		  if(this.value == "") {
		   	this.lastValue = this.value;
				//matched['cbaffidResult'] = 0;
				str = '';
        $('#cbaffidResult').fadeOut();
        setTimeout("finishAjax('cbaffidResult', 'cbaffidLoading', '"+escape(str)+"')", 400);
		   	return false;
		  }
			$('#cbaffidResult').hide(); // fadeOut();
		  $('#cbaffidLoading').show();
      $.post("check_field.php", {
        field: $('#cbaffid').val()
      }, function(response){
        setTimeout("finishAjax('cbaffidResult', 'cbaffidLoading', '"+escape(response)+"')", 400);
      });
	   	this.lastValue = this.value;
    }
   	return false;
	});

	$('#pdcaffidLoading').hide();
	$('#pdcaffid').blur(function(){
	  if(this.value != this.lastValue) {
		  if(this.value == "") {
		   	this.lastValue = this.value;
				//matched['pdcaffidResult'] = 0;
				str = '';
        $('#pdcaffidResult').fadeOut();
        setTimeout("finishAjax('pdcaffidResult', 'pdcaffidLoading', '"+escape(str)+"')", 400);
		   	return false;
		  }
			$('#pdcaffidResult').hide(); // fadeOut();
		  $('#pdcaffidLoading').show();
      $.post("check_field.php", {
        field: $('#pdcaffid').val()
      }, function(response){
        setTimeout("finishAjax('pdcaffidResult', 'pdcaffidLoading', '"+escape(response)+"')", 400);
      });
	   	this.lastValue = this.value;
    }
   	return false;
	});

	$('#ppeLoading').hide();
	$('#ppe').blur(function(){
	  if(this.value != this.lastValue) {
		  if(this.value == "") {
		   	this.lastValue = this.value;
				matched['ppeResult'] = 0;
				str = '';
        $('#ppeResult').fadeOut();
        setTimeout("finishAjax('ppeResult', 'ppeLoading', '"+escape(str)+"')", 400);
		   	return false;
		  }
			$('#ppeResult').hide(); // fadeOut();
		  $('#ppeLoading').show();
      $.post("check_email2.php", {
        email: $('#ppe').val()
      }, function(response){
        setTimeout("finishAjax('ppeResult', 'ppeLoading', '"+escape(response)+"')", 400);
      });
	   	this.lastValue = this.value;
    }
   	return false;
	});

	$('#gvoaffidLoading').hide();
	$('#gvoaffid').blur(function(){
	  if(this.value != this.lastValue) {
		  if(this.value == "") {
		   	this.lastValue = this.value;
				//matched['gvoaffidResult'] = 0;
				str = '';
        $('#gvoaffidResult').fadeOut();
        setTimeout("finishAjax('gvoaffidResult', 'gvoaffidLoading', '"+escape(str)+"')", 400);
		   	return false;
		  }
			$('#gvoaffidResult').hide(); // fadeOut();
		  $('#gvoaffidLoading').show();
      $.post("check_field.php", {
        field: $('#gvoaffid').val()
      }, function(response){
        setTimeout("finishAjax('gvoaffidResult', 'gvoaffidLoading', '"+escape(response)+"')", 400);
      });
	   	this.lastValue = this.value;
    }
   	return false;
	});

	$('#couponLoading').hide();
	$('#coupon').blur(function(){
	  if(this.value != this.lastValue) {
		  if(this.value == "") {
		   	this.lastValue = this.value;
				//matched['couponResult'] = 0;
				str = '';
        $('#couponResult').fadeOut();
        setTimeout("finishAjax('couponResult', 'couponLoading', '"+escape(str)+"')", 400);
		   	return false;
		  }
			$('#couponResult').hide(); // fadeOut();
		  $('#couponLoading').show();
      $.post("check_coupon.php", {
        coupon: $('#coupon').val()
      }, function(response){
        setTimeout("finishAjax('couponResult', 'couponLoading', '"+escape(response)+"')", 400);
      });
	   	this.lastValue = this.value;
    }
   	return false;
	});

	$('#check_numberLoading').hide();
	$('#check_number').blur(function(){
	  if(this.value != this.lastValue) {
		  if(this.value == "") {
		   	this.lastValue = this.value;
				matched['check_numberResult'] = 0;
				str = '';
        $('#check_numberResult').fadeOut();
        setTimeout("finishAjax('check_numberResult', 'check_numberLoading', '"+escape(str)+"')", 400);
		   	return false;
		  }
			$('#check_numberResult').hide(); // fadeOut();
		  $('#check_numberLoading').show();
      $.post("check_number.php", {
        num1: $('#num1').val(),
        num2: $('#num2').val(),
        action: $('#action').val(),
        answer: $('#check_number').val()
      }, function(response){
        setTimeout("finishAjax('check_numberResult', 'check_numberLoading', '"+escape(response)+"')", 400);
      });
	   	this.lastValue = this.value;
    }
   	return false;
	});

	$('#codeLoading').hide();
	$('#code').blur(function(){
	  if(this.value != this.lastValue) {
		  if(this.value == "") {
		   	this.lastValue = this.value;
				//matched['codeResult'] = 0;
				str = '';
        $('#codeResult').fadeOut();
        setTimeout("finishAjax('codeResult', 'codeLoading', '"+escape(str)+"')", 400);
		   	return false;
		  }
			$('#codeResult').hide(); // fadeOut();
		  $('#codeLoading').show();
      $.post("check_code.php", {
        code: $('#code').val()
      }, function(response){
        setTimeout("finishAjax('codeResult', 'codeLoading', '"+escape(response)+"')", 400);
      });
	   	this.lastValue = this.value;
    }
   	return false;
	});

	$('#emailLoading').hide();
	$('#email').blur(function(){
	  if(this.value != this.lastValue) {
		  if(this.value == "") {
		   	this.lastValue = this.value;
				//matched['emailResult'] = 0;
				str = '';
        $('#emailResult').fadeOut();
        setTimeout("finishAjax('emailResult', 'emailLoading', '"+escape(str)+"')", 400);
		   	return false;
		  }
			$('#emailResult').hide(); // fadeOut();
		  $('#emailLoading').show();
      $.post("check_email3.php", {
        email: $('#email').val()
      }, function(response){
        setTimeout("finishAjax('emailResult', 'emailLoading', '"+escape(response)+"')", 400);
      });
	   	this.lastValue = this.value;
    }
   	return false;
	});

	$('#passwordLoading').hide();
	$('#password').blur(function(){
	  if(this.value != this.lastValue) {
		  if(this.value == "") {
		   	this.lastValue = this.value;
				//matched['passwordResult'] = 0;
				str = '';
        $('#passwordResult').fadeOut();
        setTimeout("finishAjax('passwordResult', 'passwordLoading', '"+escape(str)+"')", 400);
		   	return false;
		  }
			$('#passwordResult').hide(); // fadeOut();
		  $('#passwordLoading').show();
      $.post("check_name.php", {
        field: $('#password').val()
      }, function(response){
        setTimeout("finishAjax('passwordResult', 'passwordLoading', '"+escape(response)+"')", 400);
      });
	   	this.lastValue = this.value;
    }
   	return false;
	});

	$('#email2Loading').hide();
	$('#email2').blur(function(){
	  if(this.value != this.lastValue) {
		  if(this.value == "") {
		   	this.lastValue = this.value;
				//matched['email2Result'] = 0;
				str = '';
        $('#email2Result').fadeOut();
        setTimeout("finishAjax('email2Result', 'email2Loading', '"+escape(str)+"')", 400);
		   	return false;
		  }
			$('#email2Result').hide(); // fadeOut();
		  $('#email2Loading').show();
      $.post("check_email3.php", {
        email: $('#email2').val()
      }, function(response){
        setTimeout("finishAjax('email2Result', 'email2Loading', '"+escape(response)+"')", 400);
      });
	   	this.lastValue = this.value;
    }
   	return false;
	});



});

function finishAjax(id, id2, response) {
  $('#'+id2).hide();
  $('#'+id).html(unescape(response));
  $('#'+id).fadeIn();
	if(response.match(/good/)) {
		matched[id]=1;
	}
	else {
		matched[id]=0;
	}
	var matched3 =	matched['tweet_first_nameResult'] +
									matched['tweet_last_nameResult'] +
									matched['tweet_emailResult'] +
									matched['twitter_usernameResult'] +
									matched['password1Result'] +
									matched['password2Result'] +
									matched['check_numberResult'];

	if(matched3 > 6) {
		document.getElementById( "register" ).disabled = false;
		document.getElementById( "register" ).value = "Register Your Account";
	}
	else {
		var displayStr = "Register Your Account";
		document.getElementById( "register" ).disabled = true;
		document.getElementById( "register" ).value = displayStr;
	}
//  document.getElementById( "matched2" ).value = matched3;
} //finishAjax

var matched = new Array(); //0; // global var
matched['tweet_first_nameResult'] = 0;
matched['tweet_last_nameResult'] = 0;
matched['tweet_emailResult'] = 0;

matched['twitter_usernameResult'] = 0;
//matched['twitter_passwordResult'] = 0;

matched['password1Result'] = 0;
matched['password2Result'] = 0;
matched['check_numberResult'] = 0;
//matched['couponResult'] = 0;
var password2Save = "";

// 			<p><input type="text" name="matched2" id="matched2" size="5" value="..." /></p>
