$(function() {
    $.fn.formtext = function() {
        return this.focus(function() {
            if( this.value == this.defaultValue ) {
                this.value = "";
            }
        }).blur(function() {
            if( !this.value.length ) {
                this.value = this.defaultValue;
            }
        });
    };
    
    $("#producersMail").formtext();
    $("#shoppersMail").formtext();

	$('a.new-window').click(function(){
		window.open(this.href);
		return false;
	});
	
	// show a simple loading indicator
	var loader = $('<div id="loader"><img src="images/ajax-loader.gif" alt="loader" /></div>')
		.css({position: "absolute", top: "600px", left: "468px"})
		.appendTo("div.block")
		.hide();
	$().ajaxStart(function() {
		loader.show();
	}).ajaxStop(function() {
		loader.hide();
	}).ajaxError(function(a, b, e) {
		throw e;
	});

	var v = $("#producersForm").validate({
		submitHandler: function(form) {
			$(form).ajaxSubmit({
				target: "#resultP"
			});
		}
	});
	
	var v = $("#shoppersForm").validate({
		submitHandler: function(form) {
			$(form).ajaxSubmit({
				target: "#resultS"
			});
		}
	});
});
