jQuery(document).ready(function(){
var container = jQuery('div.error-container');
var contact_loading,
contact_loadingTimer,
contact_loadingFrame = 1,
animate_contact_loading = function() {
  if (!contact_loading.is(':visible')){
    clearInterval(contact_loadingTimer);
    return;
  }
  jQuery('div', contact_loading).css('top', (contact_loadingFrame * -40) + 'px');
  contact_loadingFrame = (contact_loadingFrame + 1) % 12;
};


jQuery("#contact-us").validate({
    errorContainer: container,
    errorLabelContainer: jQuery("ol", container),
    wrapper: 'li',
    meta: "validate",
    submitHandler: function(form) {
        var formAction = jQuery("#contact-us").attr("action");
        var str = jQuery("#contact-us").serialize();
        //<![CDATA[
        var dataString = str + "&action=" + formAction;
        // ]]>
        
        jQuery("#contact-error").hide();
        jQuery("#contact-confirmation").hide();
        jQuery.contact.showActivity();
        
        jQuery.getJSON("http://data.intalio.com/contact.php?" + dataString + "&jsoncallback=?", function(data) {
            jQuery.contact.hideActivity();
            if (data.status == "OK") {
                jQuery("#contact-us").hide();
                jQuery("#contact-confirmation").slideDown("slow");
                jQuery("#contact-confirmation").tabIndex = -1;
                jQuery("#contact-confirmation").focus();
            } else {
                jQuery("#contact-error").slideDown("slow");
                jQuery("#contact-error").tabIndex = -1;
                jQuery("#contact-error").focus();
            }
        });
    }
});


contact_loading = jQuery('#contact-loading');

jQuery.contact = function() {
};

jQuery.contact.showActivity = function() {
  clearInterval(contact_loadingTimer);
  contact_loading.show();
  contact_loadingTimer = setInterval(animate_contact_loading, 66);
};

jQuery.contact.hideActivity = function() {
  contact_loading.hide();
};

var subTableDiv = jQuery(".subTableDiv");
if (jQuery("#cb_country option:selected").text() == "United States") {
	subTableDiv.show();
	jQuery('#cb_state').addClass("required");
} else {
	subTableDiv.hide();
	jQuery('#cb_state').removeClass("required");
}
jQuery("#cb_country").change(function() {
	if (this.options[this.selectedIndex].value != "United States") {
		subTableDiv.hide();
		jQuery('#cb_state').removeClass("required");
	} else {
		subTableDiv.show();
		jQuery('#cb_state').addClass("required");
	}
});
});
