var Custom = '';

function addColorsToProduct(thatForm){
	// This function will take all values from Colors_Selected
	// and add them to product hidden field

	var strProductDelimeter = "{br}"; // can be {br} or ,
	var strProduct = "";
	
	// Selects all items in Colors_Selected
	for(i=0;i<(thatForm.Colors_Selected.length);i++){
		thatForm.Colors_Selected.options[i].selected = true;

		if (thatForm.Colors_Selected.options[i].value != 'null'){
			strProduct = strProduct + strProductDelimeter + thatForm.Colors_Selected.options[i].value;
		}
	}
	
	// Adds items to products hidden value	
	thatForm.product.value = thatForm.elements['product[]'].value + strProductDelimeter + strProduct;
}

function Select_Color(thatForm,thatValue,thatIndex)
 {
   var Max_Colors = thatForm.Colors_Selected.length; //Your maximum # of colors allowed to select
   var Num_Colors = (thatForm.Colors_Unselected.length-1); //Number of colors avalible to select from

   var i;
   var colors_left=0;
   var Room_Aval;
  
  if(thatValue != -1)
   {
     
     //Figure out how many colors are left;
     for(i=1;i<(Num_Colors+1);i++)
      {
       if(thatForm.Colors_Unselected.options[i].value)
        {
         colors_left++;
        }
      }

    Room_Aval = (Num_Colors-colors_left);
    
    if(Room_Aval == Max_Colors)
     {
      alert('Your ' + Max_Colors + ' color max has been reached');
     }
    else
     {   
      thatForm.Colors_Selected.options[Room_Aval] = new Option(thatValue);
      thatForm.Colors_Selected.options[Room_Aval].value = thatValue;

      Custom += '|' + thatValue;
      
      thatForm.Colors_Unselected.options[thatIndex] = new Option(' ');
      thatValue = null;
      
      thatForm.os0.value = Custom;
     }

   }
 }

function Reset(thatForm)
  {
   var Max_Colors = thatForm.Colors_Selected.length; //You maximum # of colors allowed to select
   var Num_Colors = (thatForm.Colors_Unselected.length-1); //Number of colors avalible to select from

   var i;
   var t;
   
   for(i=0;i<Max_Colors;i++)
    {
      if(thatForm.Colors_Selected.options[i].value != 'null')
        {
         for(t=1;t<(Num_Colors+1);t++)
          {
            if(!thatForm.Colors_Unselected.options[t].value)
              {
               thatForm.Colors_Unselected.options[t] = new Option(thatForm.Colors_Selected.options[i].value);
               thatForm.Colors_Unselected.options[t].value = thatForm.Colors_Selected.options[i].value;
               t=(Num_Colors+2);
              }
          }
        }

       thatForm.Colors_Selected.options[i] = new Option('--------------');
       thatForm.Colors_Selected.options[i].value = null;
       
    }
   Custom='';
   thatForm.os0.value = Custom;
  }

function check_max(thatForm)
 {
  var Max_Colors = (thatForm.Colors_Selected.length-1);

  if(thatForm.Colors_Selected.options[Max_Colors].value == 'null')
   {
    alert('Please select ' + ++Max_Colors + ' colors');
    return false;
   }
  else
   {
    return true;
   }
  
 }

