/* Copyright (c) 2009 Jon Rohan (http://dinnermint.org)

 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 

 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.

 *

 * Version: 1.0.0

 * Written with jQuery 1.3.2

 */



(function($){$.fn.ghostText = function() {

  return this.each(function(){

    var text = $(this).attr("placeholder");

    if(text!=""&&($(this).val()==""||$(this).val()==text)) {

      $(this).addClass("disabled");

      $(this).val(text);


      $('.ghost_text').live('focus', function(){

       //Make sure the cart has items before re-enabling the submit button
       var cartHasItems = $('td.jcart-item-qty').html();
	
	if(cartHasItems !== null)
		{
		// ENABLE THE PAYPAL CHECKOUT BUTTON
              $('#jcart-paypal-checkout').removeAttr("disabled");
		}
       ///////////////////////////////////////////////////////////////



	  $(this).removeClass("error");
         $(this).removeClass("disabled");

        if($(this).val()==text) {

          $(this).val("");

        }

      });

      $('.ghost_text').live('blur', function(){



        if($(this).val()=="") {

          $(this).val(text);

          $(this).addClass("disabled");
          $('#affiliateinfo').remove();
	   $('#jcart-item-id-1').trigger('keyup');

        }else{
  
	   $('#jcart-item-id-1').trigger('keyup');
          //Need to trigger update
         
	}
      });


$('.ghost_text').live('keyup', function(){
$('#jcart-paypal-checkout').attr('disabled', 'disabled');

var updateDelay = setTimeout(function(){
 $('#jcart-item-id-1').trigger('keyup'); 
 $('#jcart-paypal-checkout').removeAttr("disabled");
 validateCoupon();

}, 1000);

		$(this).keydown(function(){
			window.clearTimeout(updateDelay);
			});


});


    }

  });

};})(jQuery)


