jQuery(function($){
	
	// Select 1 Populate
	$.ajax({
		url: 'omgajax_carmakemodelyear.php?type=1',
		type: 'get',
		success: function(r) {
			$('#ccp0--coform--customone').html(r);
		}
	});
	
	// Select 2 Populate
	$('#ccp0--coform--customone').change(function(){
		var currval = $('option:selected', this).attr('rel');
		$.ajax({
			url: 'omgajax_carmakemodelyear.php?type=2&m=' + currval,
			type: 'get',
			success: function(r) {
				$('#ccp0--coform--customtwo').html(r);
			}
		});
	});
	
	// Select 3 Populate
	$('#ccp0--coform--customtwo').change(function(){
		var currval = $('option:selected', this).attr('rel');
		$.ajax({
			url: 'omgajax_carmakemodelyear.php?type=3&m=' + currval,
			type: 'get',
			success: function(r) {
				$('#ccp0--coform--customthree').html(r);
			}
		});
	});
	
	// Select and Input Switcher
	if($('#ccp0--coform--customfive--1').is(':checked')) {
		$('#ccp0--coform--customone').attr('name', 'ccp0--coform--customone_select').attr('disabled', 'disabled').css('display', 'none');
		$('#ccp0--coform--customone').after('<input type="text" name="ccp0--coform--customone" style="border: 2px solid red;" />');
		$('#ccp0--coform--customtwo').attr('name', 'ccp0--coform--customtwo_select').attr('disabled', 'disabled').css('display', 'none');
		$('#ccp0--coform--customtwo').after('<input type="text" name="ccp0--coform--customtwo" style="border: 2px solid red;" />');
		$('#ccp0--coform--customthree').attr('name', 'ccp0--coform--customthree_select').attr('disabled', 'disabled').css('display', 'none');
		$('#ccp0--coform--customthree').after('<input type="text" name="ccp0--coform--customthree" style="border: 2px solid red;" />');
	} else {
		$('input[type=text][name=ccp0--coform--customone]').remove();
		$('#ccp0--coform--customone').attr('name', 'ccp0--coform--customone').removeAttr('disabled').css('display', 'block');
		$('input[type=text][name=ccp0--coform--customtwo]').remove();
		$('#ccp0--coform--customtwo').attr('name', 'ccp0--coform--customtwo').removeAttr('disabled').css('display', 'block');
		$('input[type=text][name=ccp0--coform--customthree]').remove();
		$('#ccp0--coform--customthree').attr('name', 'ccp0--coform--customthree').removeAttr('disabled').css('display', 'block');
	}
	$('#ccp0--coform--customfive--1').click(function(){
		if($(this).is(':checked')) {
			$('#ccp0--coform--customone').attr('name', 'ccp0--coform--customone_select').attr('disabled', 'disabled').css('display', 'none');
			$('#ccp0--coform--customone').after('<input type="text" name="ccp0--coform--customone" style="border: 2px solid red;" />');
			$('#ccp0--coform--customtwo').attr('name', 'ccp0--coform--customtwo_select').attr('disabled', 'disabled').css('display', 'none');
			$('#ccp0--coform--customtwo').after('<input type="text" name="ccp0--coform--customtwo" style="border: 2px solid red;" />');
			$('#ccp0--coform--customthree').attr('name', 'ccp0--coform--customthree_select').attr('disabled', 'disabled').css('display', 'none');
			$('#ccp0--coform--customthree').after('<input type="text" name="ccp0--coform--customthree" style="border: 2px solid red;" />');
		} else {
			$('input[type=text][name=ccp0--coform--customone]').remove();
			$('#ccp0--coform--customone').attr('name', 'ccp0--coform--customone').removeAttr('disabled').css('display', 'block');
			$('input[type=text][name=ccp0--coform--customtwo]').remove();
			$('#ccp0--coform--customtwo').attr('name', 'ccp0--coform--customtwo').removeAttr('disabled').css('display', 'block');
			$('input[type=text][name=ccp0--coform--customthree]').remove();
			$('#ccp0--coform--customthree').attr('name', 'ccp0--coform--customthree').removeAttr('disabled').css('display', 'block');
		}
	});
	
});
