﻿$(document).ready(function() {
    $('#requestInfoSubmitButton').click(function() {
		displayAppropriateForm();                
        return false;
    });
    
    $('#submitButton').click(function() {
        displayAppropriateForm();
        return false;
    });
    
    $('#whatKindOfInfoDropDown p').click(function() {		
		$('#whatKindOfInfoContainer .errorMessage').hide();
		toggleDropDown();
		return false;
    });
    
    $('#whatKindOfInfo span').click(function() {
		toggleDropDown();
		storeAppropriateFormID(this);
		return false;
    });
});

function storeAppropriateFormID(e) {
	$('#whatKindOfInfoDropDown p').text($(e).text());
	$(e).addClass('selected');
	$('#whatKindOfInfo').data('selectedID', $(e).attr('id'));
}

function toggleDropDown() {
	var quickLinkItems = document.getElementById("whatKindOfInfo");
	      
	      if (quickLinkItems != null) {
			if (quickLinkItems.style.display == "block")
				quickLinkItems.style.display = "none";
			else
				quickLinkItems.style.display = "block";
				$('#whatKindOfInfo span').removeClass('selected');
	      }
}

function showRequestInfoLightbox() {
	$('html').css('overflow', 'hidden');
	$('body').css('overflow', 'hidden');
		
    $('#requestInfoLightboxContent').modal({
		appendTo:'form',
		minHeight:475,
        overlayClose:true,
        opacity:80,
        overlayCss: {backgroundColor: '#000'},
        onClose: function(dialog) {
			$('body').css('overflow', 'auto');
			$('html').css('overflow', 'auto');
			$.modal.close();
        }
    });
}

function displayAppropriateForm() {
	$('.leadCaptureForm').hide();

	var whatKindOfInfo = $('#whatKindOfInfo').data('selectedID');
	
	if (typeof($('#whatKindOfInfo').data('selectedID')) == "undefined") {
		$('#whatKindOfInfoContainer .errorMessage').show();
	} else {
		var webPartToShowID = '#' + String(whatKindOfInfo);
		webPartToShowID = 'div[name=' + String(whatKindOfInfo) + ']';
	    
		$(String(webPartToShowID)).show();
	    
		$(String(webPartToShowID) + ' .contact-us p').show();
		$(String(webPartToShowID) + ' .contact-us table').show();
		$(String(webPartToShowID) + ' .close-form').remove();
		
		showRequestInfoLightbox();
		
		$(String(webPartToShowID) + ' .contact-us input').blur();
		$('#simplemodal-container A.modalCloseImg').focus();
	}
}
