Index: package/hosting_package.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/hosting/package/hosting_package.module,v
retrieving revision 1.14
diff -u -r1.14 hosting_package.module
--- package/hosting_package.module	23 Oct 2008 23:41:45 -0000	1.14
+++ package/hosting_package.module	25 Oct 2008 02:52:05 -0000
@@ -78,33 +78,42 @@
 
 function hosting_get_profiles($platform = NULL) {
   // load profile options: if argument is null, load all profile options
-  $result = db_query('SELECT n.nid FROM {node} n LEFT JOIN {hosting_package} hp ON n.nid = hp.nid 
-                                                 LEFT JOIN {hosting_package_release} hpr ON hp.nid = hpr.package 
-                                                 LEFT JOIN {hosting_package_instance} hpi ON hpr.nid = hpi.release_id 
-                                                 LEFT JOIN {hosting_platform} l ON hpi.rid = l.nid 
-                                                 WHERE '. ($platform ? ' l.nid = %d AND ' : '') .' hp.package_type = "profile"', $platform);
+  $query = 'SELECT n.nid FROM {node} n LEFT JOIN {hosting_package} hp ON n.nid = hp.nid 
+                                       LEFT JOIN {hosting_package_release} hpr ON hp.nid = hpr.package 
+                                       LEFT JOIN {hosting_package_instance} hpi ON hpr.nid = hpi.release_id 
+                                       LEFT JOIN {hosting_platform} l ON hpi.rid = l.nid 
+                                       WHERE '. ($platform ? ' l.nid = %d AND ' : '') .' hp.package_type = "profile"';
+
+  // if there is no result, provide results from default platform
+  if (!(db_result(db_query($query, $platform)))) {
+    $platform = HOSTING_DEFAULT_PLATFORM;
+  }
 
+  $result = db_query($query, $platform);
   while ($nid = db_fetch_object($result)) {
     $profiles[$nid->nid] = node_load(array('nid' => $nid->nid));
   }
-
   foreach ($profiles as $profile) {
     $return[$profile->nid] = $profile->title;
   }
   return $return;
 }
 
-function hosting_get_profile_languages($platform = NULL, $profile = NULL) {
+function hosting_get_profile_languages($profile = NULL, $platform = NULL) {
   // load language options: if argument is null, load all language options
-  $result = db_query("SELECT DISTINCT(language) FROM {hosting_package_languages}". ($profile ? " WHERE iid = %d" : ""), $profile);
+  $result = db_query("SELECT DISTINCT(language) FROM {hosting_package_languages} l". ($profile ? "
+                                                LEFT JOIN {hosting_package_instance} hpi ON l.iid = hpi.iid
+                                                LEFT JOIN {hosting_package_release} hpr ON hpi.release_id = hpr.nid
+                                                LEFT JOIN {hosting_package} hp ON hp.nid = hpr.package
+                                                WHERE hp.nid = %d AND hpi.rid = %d" : ""), $profile, $platform);
+  
   while ($language = db_fetch_object($result)) {
-    $languages[] = $language->language;
+    $languages[$language->language] = $language->language;
   }
-
   if (!is_array($languages)) {
     $languages = array('en');
   }
-  return _hosting_language_names($languages);
+  return $languages;
 }
 
 /**
Index: site/hosting_site.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/hosting/site/hosting_site.module,v
retrieving revision 1.33
diff -u -r1.33 hosting_site.module
--- site/hosting_site.module	23 Oct 2008 23:41:46 -0000	1.33
+++ site/hosting_site.module	25 Oct 2008 02:52:07 -0000
@@ -203,7 +203,7 @@
     );
   }
   else {
-    $form['client'] = array('#type' => 'value', '#value' => key($clients));
+    $form['client'] = array('#type' => 'hidden', '#value' => key($clients));
   }
 
   $platforms = _hosting_get_platforms();
@@ -217,7 +217,7 @@
     );
   }
   else {
-    $form['platform'] = array('#type' => 'value', '#value' => key($platforms));
+    $form['platform'] = array('#type' => 'hidden', '#value' => key($platforms));
   }
 
   $form['profile'] = _hosting_site_form_profile();
@@ -235,7 +235,7 @@
     );
   }
   else {
-    $form['db_server'] = array('#type' => 'value', '#value' => key($db_servers));
+    $form['db_server'] = array('#type' => 'hidden', '#value' => key($db_servers));
   } 
   
   return $form;
@@ -545,7 +545,7 @@
     );
   }
   else {
-    $form['profile'] = array('#type' => 'value', '#value' => key($profiles));
+    $form['profile'] = array('#type' => 'hidden', '#value' => key($profiles), '#attributes' => array('class' => "hosting-site-form-profile-options"));
   }
   return $form['profile'];
 }
@@ -554,7 +554,7 @@
  * generate hosting site node form element 'language'
  */
 function _hosting_site_form_language($profile = NULL, $platform = null) {
-  $languages = hosting_get_profile_languages($profile, $platform = null);
+  $languages = hosting_get_profile_languages($profile, $platform);
   if (sizeof($languages) > 1) {
     $form['language'] = array(
       '#type' => 'radios',
@@ -580,6 +580,7 @@
   print drupal_to_js(
     array(
       'status' => 'TRUE',
+      'type' => $form[$element]['#type'],
       'data' => drupal_render(form_builder('hosting-site-form', $form)),
     )
   );
Index: site/hosting_site_form.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/hosting/site/hosting_site_form.js,v
retrieving revision 1.1
diff -u -r1.1 hosting_site_form.js
--- site/hosting_site_form.js	22 Oct 2008 18:19:57 -0000	1.1
+++ site/hosting_site_form.js	25 Oct 2008 02:52:07 -0000
@@ -1,17 +1,16 @@
 if (Drupal.jsEnabled) {
   $(document).ready(function() {
-/**
- * initialize the form
- */
-    hostingSitePopulate('input[@name=platform]', 'profile');
+    /**
+    * initialize the form
+    */
+    hostingSitePopulate('profile');
     $('div.hosting-site-form-language-options').parent().hide();
-
     $('input[@name=platform]').change(function() {
-      hostingSitePopulate(this, 'profile');
+      hostingSitePopulate('profile');
       $('div.hosting-site-form-language-options').parent().hide();
     });
     $('input[@name=profile]').change(function() {
-      hostingSitePopulate(this, 'language');
+      hostingSitePopulate('language');
     }); 
   });
 }
@@ -19,13 +18,21 @@
 /**
  * populate the form elements through ajax
  */
-function hostingSitePopulate(obj, option) {
-  $(obj).parent().eq(0).append("<div id='hm-processing'>processing</div>");
+function hostingSitePopulate(option) {
+  // initialize variables
+  obj = 'input[@name=' + ((option == 'profile') ? 'platform' : 'profile') + ']:checked';
+  value = $('input[@name=' + option + ']:checked').val();
+  
+  // add loading animation gif pic
+  $(obj).parent().eq(0).append("<div id='hm-processing'></div>");
+
+  // ajax function
   var resultOptions = function (data) {
     var result = Drupal.parseJson(data);
     if (result['status'] == 'TRUE') {
       resultID = 'hosting-site-form-' + option + '-options'; 
       if (result['data']) {
+        // replace form element options
         if ($('div.' + resultID).html()) {
           $('div.' + resultID).parent().after(result['data']).remove(); 
           $('div.' + resultID).parent().show();
@@ -34,17 +41,28 @@
           $('input.' + resultID).after(result['data']).remove();
           $('div.' + resultID).parent().show();
         }
+        // restore choice of last time
+        $('input[@name=' + option + '][@value=' + value + ']').attr("checked", "checked");
+        // bind on-change event
         if (option == 'profile') {
-          $('input[@name=profile]').change(function() {
-            hostingSitePopulate(this, 'language');
-          }); 
+          if (($('input[@name=profile]:checked').val()) || (result['type'] != 'radios')) {
+            hostingSitePopulate('language');
+          }
+          if (result['type'] == 'radios') {
+            $('input[@name=profile]').change(function() {
+              hostingSitePopulate('language');
+            }); 
+          }
         }
       }
       else {
         $('div.' + resultID).parent().hide();
       }
     }
+    // remove the gif animation
     $('div#hm-processing').remove();
   }
-  $.get('/hosting/hosting_site_form_populate/' + option + '/' + $(obj).val(), null, resultOptions);
+  // prepare url params
+  params = (option == 'profile') ? $(obj).val() : ($(obj).val() + '/' + $('input[@name=platform]').val());
+  $.get('/hosting/hosting_site_form_populate/' + option + '/' + params, null, resultOptions);
 }
