/*<![CDATA[*/
		   
/*****************************************************************************
//-> START GENERAL FUNCTIONS
*****************************************************************************/


// --> FORM pre-submit callback
function showRequest3(formData, jqForm, options) {
	//$('div.warning2').remove();
	$('.msg3').fadeIn(500).html("<img src='images/loadinfo.gif' width='16' height='16' alt='' /> Please wait, processing...");
	$('#newsletter-form').slideUp();
	//$.fancybox.resize();
}

// --> FORM post-submit callback
function showResponse3()  {
	$('.msg3').fadeIn(500).html('<img class="png_bg" src="images/success.png" width="16" height="16" alt="" /> <strong>Thank You!</strong><br />Your registration completed successfully.');
	//$.fancybox.resize();
}
/*
 * label2value
 * using form labels as text field values
 */
this.label2value = function(){

	// CSS class names
	// put any class name you want
	// define this in external css (example provided)
	//var inactive = "inactive";
	//var active = "active";
	//var focused = "focused";

	// function
	$("label.newsletter").each(function(){
		obj = document.getElementById($(this).attr("for"));
		if(($(obj).attr("type") == "text") || (obj.tagName.toLowerCase() == "textarea")){
			//$(obj).addClass(inactive);
			var text = $(this).text();
			$(this).css("display","none");
			$(obj).val(text);
			$(obj).focus(function(){
				//$(this).addClass(focused);
				//$(this).removeClass(inactive);
				//$(this).removeClass(active);
				if($(this).val() == text) $(this).val("");
			});
			$(obj).blur(function(){
				//$(this).removeClass(focused);
				if($(this).val() == "") {
					$(this).val(text);
					//$(this).addClass(inactive);
				} else {
					//$(this).addClass(active);
				};
			});
		};
	});
};

/*****************************************************************************
//-> END GENERAL FUNCTIONS
*****************************************************************************/

/*****************************************************************************
//-> START Window Load
*****************************************************************************/

$(window).load(function () {
    
// --> START FORM VALIDATION
	
	// Insert the form error container
	//$("#newsletter-form").before("<div class=\"warning2\"><h4>There are errors in your form submission, please see below for details.</h4><ol></ol></div>");						  
	
	// Assaign this element as the error container
	//var container = $("div.warning2");
	
	// Init Form Validation
    $("#newsletter-form").validate({
		
		//errorContainer: container,
		//errorLabelContainer: $("ol", container),
		//wrapper: 'li',
		errorClass: "error",
		meta: "validate",
		errorPlacement: function(error, element) {
			   error.insertAfter(element.next());
		},

        showErrors: function(errorMap, errorList) {
			
        	this.defaultShowErrors();
			
        },
		
		submitHandler: function(form) {
			
			// Send the form via ajax form
			jQuery(form).ajaxSubmit({
        		url:              "/newsletter.asp",
                //target:           ".msg3",        // Get the server response here
                beforeSubmit:     showRequest3,   // pre-submit callback
                success:          showResponse3, // post-submit callback                    
        		clearForm:        true,        // clear all form fields after successful submit
        		resetForm:        true        // reset the form after successful submit
			});
		},
		rules: {
            newsletter_email: {
                email: true
            }
		},
        messages: {
            newsletter_email: {
                email: "Enter a valid e-mail address."
            }
        }
		
	});

// --> Init Label2Value
	label2value();
});

/*****************************************************************************
//-> END Window Load
*****************************************************************************/

/*]]>*/
