/**
 * @file
 * Custom javascript utilities.
 * 
 * @author Shannon M. Rause <shannon.rause@creativeflavor.com>
 * @version $Revision: 1.9 $
 * @version $Name: STOR-N-LOCK_2009-07-29_7 $
 * @version $Id: main.js,v 1.9 2008/12/12 21:27:00 bfinch Exp $
 *
 * These files are copyrighted to Creative Flavor Inc. and are
 * subject to the terms of the applicable Service Agreement.
 * If no service agreement is available you must contact us at
 * legal@creativeflavor.com or 303-379-9450.
 * 
 * These files may be watermarked to ensure traceability.
 */
function calculate(good, empty, too_big)
{
   var form = document.forms['calculatorForm'];
   var total = parseFloat(form.elements['other'].value);

   if (isNaN(total))
   {
      total = 0.0;
   } // if

   for (var i = 0; i < form.elements.length; i++)
   {
      if ((form.elements[i].type == 'text') &&
            (form.elements[i].name != 'other'))
      {
         var qty = parseInt(form.elements[i].value);

         if ((!isNaN(qty)) &&
               (qty > 0))
         {
            var temp = form.elements[i].name.split('_', 2);
            var f = parseFloat(temp[1].replace(/_/g, '.'));

            if (!isNaN(f))
            {
               total += (f * qty);
            } // if
         } // if
      } // if
   } // for

   var s = good;
   var rec = '10x30 or 15x20';

   if (total > 2400.0)
   {
      s = too_big;
   } // if
   else if (total > 1800.0)
   {
      rec = '10x30 or 15x20';
   } // else if
   else if (total > 1500.0)
   {
      rec = '10x30 or 15x20';
   } // else if
   else if (total > 1200.0)
   {
      rec = '10x25';
   } // else if
   else if (total > 900.0)
   {
      rec = '10x20';
   } // else if
   else if (total > 600.0)
   {
      rec = '10x15';
   } // else if
   else if (total > 450.0)
   {
      rec = '10x10';
   } // else if
   else if (total > 300.0)
   {
      rec = '5x15';
   } // else if
   else if (total > 150.0)
   {
      rec = '5x10';
   } // else if
   else if (total > 0.0)
   {
      rec = '5x5';
   } // else if
   else
   {
      s = empty;
   } // else

   s = s.replace(/\[\[cubicFeet\]\]/g, total);
   s = s.replace(/\[\[recommend\]\]/g, rec);
   document.getElementById('results').innerHTML = s;
   Popup.show('resultsPopup');
   return (false);
} // calculate


function change_location(select)
{
   if (select.value.charAt(0) == '_')
   {
      document.location = '/locations/' + select.value.substring(1);
   } // if
   else
   {
      document.location = '/' + select.value;
   } // else
} // change_location


function submit_search()
{
   var select = document.getElementById('search_location');

   if (!select.options[select.selectedIndex].value)
   {
      return (true);
   } // if

   return (select.options[select.selectedIndex].value == 'Select Location');
} // submit_search
