Subscribe.MicroSite = {

	Init : function() {
	
		//enable datepicker on the form
		Subscribe.Base.EnableDatepicker();
		
		//enable boolean fields
		Subscribe.Base.EnableBoolean();
		
		//enable education institution filter
		Subscribe.Base.EnableDropDownFilter('cb_applicant_education_type', 'cb_applicant_education_institution');
		
		//enable/disable institution other field
		Subscribe.MicroSite.ToggleInstitutionOther();
		$('#cb_applicant_institution_enter_other_checkbox').click(function() {
			Subscribe.MicroSite.ToggleInstitutionOther();
		});
		
		$('input').keydown(function() {
			progress = false;
		});
		
		$('select').change(function() {
			progress = false;
		});
		
		$('input[type="checkbox"][type="text"]').change(function() {
			progress = false;
		});
		
		$('#prof-click-next').click(function() {
			if (!progress) {
				if (!confirm('You have made some changes on the form. Please click add record if you want to save those changes. Otherwise click Ok to continue to the next step.')) {
					return false;
				}
			}
		});
		
		$('#share-job').click(function() {
			var $el = $('<div id="frm-overlay"></div>').appendTo($('body')).addClass('ui-widget-overlay');
			$el.bgiframe();
			
			// to position #confirmDialogue, we need the window height/width
    		var sCont = $('#sharer-container');
    		$('body').append(sCont);
    		var height = $(window).height();
    		var width = $(document).width();

		    sCont.css({
		        'left' : width/2 - (sCont.width() / 2),
		        'top' : height/2 - (sCont.height() / 2),
		        'z-index' : 15
		    });
			
			sCont.show();
			
			//$('body').append(sCont.show());
			return false;
		});
		
		$('#ref-close').click(function() {
			$('#frm-overlay').remove(); 
			$('#sharer-container').hide();
			
			var iFrm = $('#sharer-container iframe');
    		iFrm.attr('src', iFrm.attr('src'));
			
			return false;
		});
	},
	 
	 ToggleInstitutionOther : function() {
		if ($('#cb_applicant_institution_enter_other_checkbox').attr('checked')) {
			Subscribe.Base.Show('cb_applicant_institution_other');
			Subscribe.Base.Hide('cb_applicant_education_institution');
			$('#cb_applicant_institution_other').focus();
			$('#cb_applicant_education_institution').attr('value', '');			
		} else {
			Subscribe.Base.Hide('cb_applicant_institution_other');
			Subscribe.Base.Show('cb_applicant_education_institution');
			$('#cb_applicant_institution_other').attr('value', '');
		}		
	}
};

$(document).ready(function() {
	Subscribe.MicroSite.Init();
	
	 $('input[type="text"],textarea').keyup(function() {
	 	$(this).attr('value', $(this).attr('value').toUpperCase());
	 });
});

progress = true;
