function animateDiv(name) {
	jQuery("div."+name).stop().animate({"left": '10px'}, 300).animate({"left": "0px"}, 300);	
}
jQuery(document).ready(function() {
	
	jQuery(".loader").hide();
	
	//Providers 
	jQuery("#providers").change(function() {
		jQuery("#loader-providers").show();
		
		jQuery("#program").html('<option value="">- Select your program -</option>').attr('disabled','disabled');
		jQuery("#examtype").val('Select your exam type -').attr('disabled','disabled');
		jQuery("#dates").html('<option value="">- Select a date -</option>').attr('disabled','disabled');
		jQuery("#locations").html('<option value="">- Select a location -</option>').attr('disabled','disabled');
		
		var providerID = jQuery(this).val();
		

		if(providerID != "") {
			jQuery.post('certifications/ajax/ajax.php', {
				action: 'programs',
				providerID: providerID
			}, function(html) {
				jQuery("#program").html(html).attr('disabled','');
				jQuery("#loader-providers").hide();
				animateDiv("programs");
			});
		}
		else {
			jQuery("#program").html('<option value="">- Select your program -</option>').attr('disabled','disabled');
			jQuery("#examtype").val('Select your exam type -').attr('disabled','disabled');
			jQuery("#dates").html('<option value="">- Select a date -</option>').attr('disabled','disabled');
			jQuery("#locations").html('<option value="">- Select a location -</option>').attr('disabled','disabled');
			jQuery("#loader-providers").hide();
		}
	});
	
	//Program
	jQuery("#program").change(function() {		
		jQuery("#examtype").val('Select your exam type -').attr('disabled','disabled');
		jQuery("#dates").html('<option value="">- Select your date/location -</option>').attr('disabled','disabled');
		
		var programID = jQuery(this).val();
		
		if(programID != "") {
			jQuery("#examtype").attr('disabled','');
			animateDiv("examtype");
			
			jQuery.post('certifications/ajax/program-desc.php',{programID: programID}, function(html) {
				jQuery('#program-desc').html(html);
			});
		}
		else {
			jQuery("#examtype").val('Select your exam type -').attr('disabled','disabled');
			jQuery("#locations").html('<option value="">- Select a location -</option>').attr('disabled','disabled');
			jQuery("#dates").html('<option value="">- Select a date -</option>').attr('disabled','disabled');
			jQuery('#program-desc').html('');
		}
	});
	
	//Exam type
	jQuery("#examtype").change(function() 
	{	
		jQuery("#loader-type").show();	
		var examType 	= jQuery(this).val();
		var programID = jQuery("#program").val();
		
		if(examType != "") 
		{
			jQuery.post('certifications/ajax/ajax.php', {
				action: 'locations',
				programID: programID,
				examType: examType
			}, function(html) {
				jQuery("#loader-type").hide();
				jQuery("#locations").html(html).attr('disabled','');
				animateDiv("locations");
			});
			
		}
		else {
			jQuery("#locations").html('<option value="">- Select a location -</option>').attr('disabled','disabled');
			jQuery("#dates").html('<option value="">- Select a date -</option>').attr('disabled','disabled');
			jQuery("#loader-type").hide();
		}
	});
	
	//Locations
	jQuery("#locations").change(function() 
	{
		jQuery("#loader-location").show();	
		var location 	= jQuery(this).val();
		var programID = jQuery("#program").val();
		var examType 	= jQuery("#examtype").val();
		
		if(location != "") 
		{
			jQuery.post('certifications/ajax/ajax.php', {
				action: 'dates',
				programID: programID,
				examType: examType,
				location: location
			}, function(html) {
				jQuery("#loader-location").hide();
				jQuery("#dates").html(html).attr('disabled','');
				animateDiv("dates");
			});
		}
		else {
			jQuery("#dates").html('<option value="">- Select a date -</option>').attr('disabled','disabled');
			jQuery("#loader-location").hide();
		}

	});
	
	//Dates
	jQuery("#dates").change(function() 
	{
		jQuery("#product").html('');
		jQuery("#loader-dates").show();
		
		var productID = jQuery(this).val();
		var programID = jQuery("#program").val();
		
		var URL = 'http://www.cmeceducation.org/index.php?page=shop.product_details&flypage=shop.flypage&product_id='+productID+'&category_id='+programID+'&manufacturer_id=0&option=com_virtuemart&Itemid=101';
				
		jQuery("#product").load(URL+' .product-details', function() {
			jQuery("#loader-dates").hide();
			
			jQuery("#addtocart label").parent().css({'margin-top': '18px'});
		});
		
	});
});