$(document).ready(function() {
	
	 typeID = $('#typeID').val();
	 limoID = $('#limoID').val();
	 
	 $('#filesB').val( limoID );
	
	
	
	 brand = $('#filesB').val();
     
     // Send an AJAX request to get all the states.
	    $.get("/php/request.php?type="+ typeID +"&brand=" + brand, function(response)
	    {
	        // Append the response to the div.
	        $("#allModels").html('');
	        $("#allModels").html(response);
	        $("#packageDetails").html('<div id="packageDetails">Choisir votre package pour obtenir le prix / description</div>');
	        
	        $('#filesA').attr('name', "filesA");
	        $('#filesA').attr('id', 'filesA');
	
	        // Enable the state drop-down.
	        $('#filesA').attr('disabled', false);
	        
	        $('#filesA').change(function () {
        
		        id = $('#filesA').val();
		     
		     // Send an AJAX request to get all the states.
			    $.get("/php/request.php?id=" + id, function(response)
			    {
			        // Append the response to the div.
			        $("#packageDetails").html('');
			        $("#packageDetails").html(response);
			        
			    });    
		  
		    });
	    });    

	
	 $('#filesB').change(function () {
        
        brand = $('#filesB').val();
     
     // Send an AJAX request to get all the states.
	    $.get("/php/request.php?type="+ typeID +"&brand=" + brand, function(response)
	    {
	        // Append the response to the div.
	        $("#allModels").html('');
	        $("#allModels").html(response);
	        $("#packageDetails").html('<div id="packageDetails">Choisir votre package pour obtenir le prix / description</div>');
	        
	        $('#filesA').attr('name', "filesA");
	        $('#filesA').attr('id', 'filesA');
	
	        // Enable the state drop-down.
	        $('#filesA').attr('disabled', false);
	        
	        $('#filesA').change(function () {
        
		        id = $('#filesA').val();
		     
		     // Send an AJAX request to get all the states.
			    $.get("/php/request.php?id=" + id, function(response)
			    {
			        // Append the response to the div.
			        $("#packageDetails").html('');
			        $("#packageDetails").html(response);
			        
			    });    
		  
		    });
	    });    
  
    });
    
   	
	$('#filesA').change(function () {
        
        id = $('#filesA').val();
     
     // Send an AJAX request to get all the states.
	    $.get("/php/request.php?id=" + id, function(response)
	    {
	        // Append the response to the div.
	        $("#packageDetails").html('');
	        $("#packageDetails").html(response);
	        
	    });    
  
    });
     
});

$(function(){
	
	$('select#filesA').selectmenu({maxHeight: 300,menuWidth: 390});
	
	$('select#filesB').selectmenu({
		maxHeight: 300,
		menuWidth: 390,
		icons: [
			{find: '.xx'},
			{find: '.aa'},
			{find: '.bb'},
			{find: '.cc'},
		]
	});
	
});


//a custom format option callback
var addressFormatting = function(text){
	var newText = text;
	//array of find replaces
	var findreps = [
		{find:/^([^\-]+) \- /g, rep: '<span class="ui-selectmenu-item-header">$1</span>'},
		{find:/([^\|><]+) \| /g, rep: '<span class="ui-selectmenu-item-content">$1</span>'},
		{find:/([^\|><\(\)]+) (\()/g, rep: '<span class="ui-selectmenu-item-content">$1</span>$2'},
		{find:/([^\|><\(\)]+)$/g, rep: '<span class="ui-selectmenu-item-content">$1</span>'},
		{find:/(\([^\|><]+\))$/g, rep: '<span class="ui-selectmenu-item-footer">$1</span>'}
	];
	
	for(var i in findreps){
		newText = newText.replace(findreps[i].find, findreps[i].rep);
	}
	return newText;
}