jQuery.noConflict();


jQuery(document).ready(function() { 
	
	jQuery("#notjsflag").val("nottrue");
    var options1 = { 
       beforeSubmit:  validate,  // pre-submit callback 
       success:       showResponse1  // post-submit callback 

    }; 
    
 	
    // bind to the form's submit event 
    jQuery('#contact').submit(function() { 
        // inside event callbacks 'this' is the DOM element so we first 
        // wrap it in a jQuery object and then invoke ajaxSubmit 
        jQuery(this).ajaxSubmit(options1); 
 		
        // !!! Important !!! 
        // always return false to prevent standard browser submit and page navigation 
        return false; 
    });
    
    
});

function validate(formData, jqForm, options) { 
    // formData is an array of objects representing the name and value of each field 
    // that will be sent to the server;  it takes the following form: 
    // 
    // [ 
    //     { name:  username, value: valueOfUsernameInput }, 
    //     { name:  password, value: valueOfPasswordInput } 
    // ] 
    // 
    // To validate, we can examine the contents of this array to see if the 
    // username and password fields have values.  If either value evaluates 
    // to false then we return false from this method.
    


    for (var i=0; i < formData.length-1; i++) {
    	if (formData[i].name!="company"){
	        if (!formData[i].value) { 
	            jQuery("#leader").fadeOut("fast", function() {
		    		jQuery("#leader").html('<p style="color:#D51721;">Please complete all the fields... </p>');
		    		//should be able to do this iteratively...
		    		jQuery(".required").append('<font style="color:#D51721;">*</font>');
	    			jQuery("#leader").fadeIn("fast");
	    		});
	            return false; 
	        } 
	    }
		
    }
}

function showResponse1(responseText, statusText){
	
	
	jQuery("#leader").fadeOut("slow");
	jQuery("#instruct").fadeOut("slow");
	jQuery('#contactfields').fadeOut('slow', function() {
	
	jQuery('#contactfields').html('Thanks for that! We\'ll get back to you as soon as we can.');
	jQuery('#contactfields').fadeIn('slow');
	jQuery('#contact').animate( { height:"170px"}, 600 );
	});
}


    