jQuery.fn.jquerydform = function(){
    var formID = jQuery(this).attr('ID');
    //override form submit action
    jQuery(this).submit(function(){        
        //add a Loading msg to show
        var formHeight = jQuery(this).height();
        var formWidth = jQuery(this).width();
        jQuery(this).css('position','relative');
        jQuery(this).prepend('<div id="jquerydform_trans" style="position:absolute;z-index:1000;width:' + formWidth + 'px;height:' + formHeight + 'px;background-image:url(trans.png);background-position:left top;background-repeat:repeat;"><!-- EMPTY --></div>');
        jQuery('#jquerydform_trans').append('<div id="jquerydform_loading" style="line-height:1.6;border:2px solid #fff;position:absolute;z-index:1010;background-color:#000;color:#fff;text-shadow:none;padding:10px;font-size:11px;">PROCESSING . . . </div>');
        jQuery('#jquerydform_loading').css('left',Math.round((formWidth-20-jQuery('#jquerydform_loading').width())/2) + 'px');
        jQuery('#jquerydform_loading').css('top',Math.round((formHeight-20-jQuery('#jquerydform_loading').height())/2) + 'px');
        
        //post the form to the server script as identified by the "Action" attribute on the form
        jQuery.post(jQuery(this).attr('action'),jQuery(this).serialize(),function(data){
            if(data!='success'){
                //if form validation faild - show error message
                jQuery('#jquerydform_loading').html(data + '<a style="color:#000000;float:right;font-size:11px;" href="JavaScript:jquerydform_remove();">CLOSE [X]</a>');
                jQuery('#jquerydform_loading').css('left',Math.round((formWidth-20-jQuery('#jquerydform_loading').width())/2) + 'px');
                jQuery('#jquerydform_loading').css('top',Math.round((formHeight-20-jQuery('#jquerydform_loading').height())/2) + 'px');
                jQuery('#jquerydform_loading').css('backgroundColor','#FF9595');
                jQuery('#jquerydform_loading').css('border','2px solid #fff');
                jQuery('#jquerydform_loading').css('text-transform','uppercase');
                jQuery('#jquerydform_loading').css('font-size','11px');
            }else{
                //if form was successful
                jQuery('#jquerydform_loading').html('Form submitted successfully. . . <br/><a style="color:#000000;float:right;font-size:11px;" href="JavaScript:jquerydform_remove();">CLOSE [X]</a>');
                jQuery('#jquerydform_loading').css('left',Math.round((formWidth-20-jQuery('#jquerydform_loading').width())/2) + 'px');
                jQuery('#jquerydform_loading').css('top',Math.round((formHeight-20-jQuery('#jquerydform_loading').height())/2) + 'px');
                jQuery('#jquerydform_loading').css('backgroundColor','#00CC00');
                jQuery('#jquerydform_loading').css('border','2px solid #fff');
                jQuery('#jquerydform_loading').css('textAlign','center');
                jQuery('#jquerydform_loading').css('text-transform','uppercase');
                jQuery('#jquerydform_loading').css('font-size','11px');
            }
        });
        
        //stop form from submitting normaly
        return false;
    });
};

function jquerydform_remove(){
    jQuery('#jquerydform_trans').fadeOut(300,function(){jQuery(this).remove();});
}
