jQuery(function() {

  jQuery(".find").click(function() {
  
  //show processing gif
  
        jQuery('#finding').html("<img id='processingGif' src='../wp-includes/images/ajax-loader.gif' width='10' height='10' border='0' style='border:0px;' />");
		// validate and process form
		// first hide any error messages
    jQuery('.error').hide();
		
	  var twitterer = jQuery("input#findTwitterer").val().toLowerCase();
		if (twitterer == "") {
      jQuery("label#findTwitterer_error").show();
      jQuery("input#findTwitterer").focus();
      jQuery('#finding').html("<small>Empty!</small>");
      return false;
    }
    	jQuery("#row\\.name\\["+twitterer+"\\]").hide();
    	jQuery("#row2\\.name\\["+twitterer+"\\]").hide();
	  var wordpress_ID = jQuery("input#wi").val();
	  var user_id = jQuery("input#u").val();
		
		
		//alert (dataString);return false;
		
	
		jQuery("#ThisTweeter").load("../find_tweeter.php", {"twitterer":twitterer, "wi":wordpress_ID, "u":user_id}, function() {
      jQuery("#findTwitterer").val("");
      jQuery('#finding').html("");
      });
			

    return false;
	});
});


//verify and update new password
jQuery(function() {

  jQuery(".newPassword").click(function() {
  
  //show processing gif
  
        jQuery('#updatePassword').html("<img id='processingGif' src='../wp-includes/images/ajax-loader.gif' width='10' height='10' border='0' style='border:0px;' />");
		// validate and process form
		// first hide any error messages
    jQuery('.error').hide();
		
	  var twitterPassword = jQuery("input#updatedPassword").val();
		if (twitterPassword == "") {
      jQuery("label#updatedPassword_error").show();
      jQuery("input#updatedPassword").focus();
      jQuery('#updatePassword').html("<small>Empty!</small>");
      return false;
    }
	  var wordpress_ID = jQuery("input#wi").val();
	  var user_id = jQuery("input#u").val();
	  var screenname = jQuery("input#s").val();
		
		
		//alert (dataString);return false;
		
	
		jQuery("#updating").load("../updated.php", {"p":twitterPassword, "wi":wordpress_ID, "u":user_id, "s":screenname}, function() {
      jQuery("#updatedPassword").val("");
      jQuery('#updatePassword').html("");
      });
			

    return false;
	});
});

//input max counter
jQuery.fn.counter = function() {
  jQuery(this).each(function() {
    var max = jQuery(this).attr('maxlength');
    var val = jQuery(this).attr('value');
    var cur = 0;
    if(val) // value="", or no value at all will cause an error
      cur = val.length;
    var left = max-cur;
    jQuery(this).after("<div class='counter' id='TweetCounter'>"
      + left.toString()+"</div>");
    // You can use something like this to align the
    // counter to the right of the input field.
    var c = jQuery(this).next(".counter");
    c.width(40);
    c.css("position","relative");
    c.css("top",-jQuery(this).height()-8);
    c.css("left",jQuery(this).width()+8);
    c.css("background","white");
 
    jQuery(this).keyup(function(i) {
      var max = jQuery(this).attr('maxlength');
      var val = jQuery(this).attr('value');
      var cur = 0;
      if(val)
        cur = val.length;
      var left = max-cur;
      jQuery(this).next(".counter").text(left.toString());
      return this;
    });
  });
  return this;
}

jQuery(document).ready(function() {
  jQuery("#messageBox").counter();
  jQuery("#screenname").counter();
});
