window.onload=function() {
   updateShips(); 
   resetRatings();
}

// TODO: handle case where validation loads regular text fields if user selected custom cline/ship values
function updateShips() {
//window.console.log("I think therefore I code!");
   // get selecte cline   
   if(undefined == $('cline')) {
      cline = 0;
   } else { 
      var cline = ($('cline').value);
   }

   // in case of POST, get selected ship 
   if (undefined == $('sel_ships')) {
	var sel = 0;
   } else {
	var sel = $('sel_ships').value;
   }

   new Ajax.Updater('ships', '/ajax', {
   method: 'get',
   parameters: "f=ships&id=" + cline + "&sel=" + sel
   });	
}

function resetRatings() {
  // new Starbox('overall_r', 0, {stars : 4, buttons : 4, max : 4, rerate : true});
   new Starbox('food_r', 0, {stars : 4, buttons : 4, max : 4, rerate : true});
   new Starbox('servc_r', 0, {stars : 4, buttons : 4, max : 4, rerate : true});
   new Starbox('cabin_r', 0, {stars : 4, buttons : 4, max : 4, rerate : true});
   new Starbox('ent_r', 0, {stars : 4, buttons : 4, max : 4, rerate : true});
   new Starbox('ff_r', 0, {stars : 4, buttons : 4, max : 4, rerate : true});
   new Starbox('shorex_r', 0, {stars : 4, buttons : 4, max : 4, rerate : true});
   new Starbox('value_r', 0, {stars : 4, buttons : 4, max : 4, rerate : true});
}

function addCustomLineShip() {
   $('cline').value = 0;
   $('ships').value = 0;
   $('cline').hide();
   $('ships').hide();
   
   $('add_custom').update('<i>Enter the name of the Cruise Line and Ship in fields above</i>');
     
   var custom_cline = new Element('input', {'name' : 'custom_cline', 'class' : 'inp-text'});	
   $('cline_box').insert(custom_cline);

   var custom_ship = new Element('input', {'name' : 'custom_ship', 'class' : 'inp-text'});
   $('ships_box').insert(custom_ship);
 
   
}
