jQuery.noConflict();

var icts = {
	tooltipConfig : {
		'showURL' : false,
		'track'   : true,
		'top'     : 15,
		'left'    : 5,
		delay     : 0
	},
	generalOpportunityId : 4
};

(function($){
	$(function(){

		// Add help tooltips and make help links open in popup.
		$('a.form-help').Tooltip(icts.tooltipConfig).click(function(){
			window.open(
				this.href + '?popup=1',
				'ictshelpwindow',
				'width=500,height=600,resizable=1'
			);
			return false;
		});

		// Only show opportunity type select when the appropriate opportunity
		// class is selected.
		$('#opportunity_type').parent().hide();
		$('#opportunity_class').change(function(){
			if($(this).val() && ($.inArray(icts.generalOpportunityId, $(this).val()) != -1)){
				$('#opportunity_type').parent(':hidden').show();
			} else {
				$('#opportunity_type').parent(':visible').hide();
			}
			$('form').submit(function(){
				$('div:hidden #opportunity_type').val('');
			});
		});


		// Don't make people enter the same email address twice
		var contactEmailChanged
			= $('#contact_details_email').val() == $('email').val();
		$('#email').blur(function(){
			if(!contactEmailChanged){
				$('#contact_details_email').val($(this).val());
			}
		});
		$('#contact_details_email').change(function(){
			contactEmailChanged = true;
		});

});
})(jQuery);


