/*                                      item_detail_ajax.js */
/* msc 04/13/10 added new js file to add ajax functionality */
/* msc 04/30/10 added code for adding the was pricing       */
/* msc 04/06/11 new way of passing color and size simplified*/
/*              code                                        */
/* msc 08/01/11 made to work without the product class on page*/
/* msc 08/24/11 made to work with ie9 xml parser           */
/* msc 08/28/11 removed another ajax and add clearance     */
/*              category change                            */
/* msc 09/18/11 - dealt with a discreprency of available products */
/* msc 09/20/11 - sort colors when loading only colors    */
/* jlt 09/23/11 - fix swatch errors                                     */
/* jlt 12/28/11 - put swatches in same order as drop-down for color 
                              also format prices not ending in zero.*/

function item_detail_ajax(gRoot,prodID,gImage,gCategory){

   /* define the class functions */
   this.updatePrice_xml = updatePrice_xml;
   this.loadXMLAJAX = loadXMLAJAX; 
   this.priceSizeArea = priceSizeArea;
   this.formatDollar = formatDollar;
   this.loadSizeSelect = loadSizeSelect;
   
   /* define the class properties */
   this.urlencode = urlencode;
   this.gProdID = prodID
   this.gRoot = gRoot;
   this.ajax_page = '';
   this.availability = "";
   this.xmlHttpReq = "";
   this.reqStr = "";
   this.responseText;
   this.parser;
   this.xmlDoc;
   this.sel_qty = '';
   this.sel_size = '';
   this.sel_size_obj = '';
   this.sel_size_type = '';
   this.sel_color = '';
   this.sel_color_obj = '';
   this.sel_color_type = '';
   this.color_list1 = '';
   this.color_codes = '';
   this.size_list1 = '';
   this.size_codes = '';
   this.priceDiv = '';
   this.availabilityDiv = '';
   this.wasDiv = '';
   this.loadingImage = gImage;
   this.category = gCategory;
   this.color_codes = "";
   this.size_codes = "";
   this.color_list = "";
   this.ajaxDetailsArray = new Array();
   this.SizeArray = new Array();
   this.SizePriceArray = new Array();
   this.PriceArray = new Array();
   this.ColorArray = new Array();
   this.ColorPriceArray = new Array();
   this.SizeNames = new Array();
   this.ColorNames = new Array();
   this.SizeColor = new Array();
   this.loaded = 0;
   this.ColorSwatchDisplayArea_HTML = "";
   this.color_list_array;
   this.color_codes_array;
   this.size_list1_array;
   this.size_codes_array;         
   
   
   // Mozilla/Safari
   if (window.XMLHttpRequest)
   { 
   this.xmlHttpReq = new XMLHttpRequest(); 
   }
   // IE
   else if (window.ActiveXObject)
   { 
   this.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); 
   }
   
   function updatePrice_xml()
   {
   
      if(document.getElementById('sel_qty'))
      {
         this.sel_qty = document.getElementById("sel_qty").value; 
      }
      
      if(document.getElementById('sel_size'))
      {
         this.sel_size = document.getElementById("sel_size").value;
         this.sel_size_obj = document.getElementById("sel_size");
      }
      
      if(document.getElementById('sel_color'))
      {
         this.sel_color = document.getElementById("sel_color").value;
         this.sel_color_obj = document.getElementById("sel_color");
      }
      
      if(document.getElementById('color_list1'))
      { 
         this.color_list1 = document.getElementById("color_list1").value; 
      }
      
      if(document.getElementById('color_codes'))
      { 
         this.color_codes = document.getElementById("color_codes").value; 
      }
      
      if(document.getElementById('size_list1'))
      { 
         this.size_list1 = document.getElementById("size_list1").value; 
      }
      
      if(document.getElementById('size_codes'))
      { 
         this.size_codes = document.getElementById("size_codes").value; 
      }

      if(document.getElementById('itemPriceDiv'))
      { 
         this.priceDiv = document.getElementById("itemPriceDiv"); 
      }

      if(document.getElementById('wasdiv'))
      { 
         this.wasDiv = document.getElementById("wasdiv"); 
      }
      
      if(document.getElementById('itemPriceDiv'))
      { 
         this.wasDiv = document.getElementById("wasdiv"); 
      }
            
      if(document.getElementById('availabilityDiv'))
      { 
         this.availabilityDiv = document.getElementById("availabilityDiv"); 
      }
      
      this.ajax_page = this.gRoot + "/ajax/getProductInfo.xml?";
      if(this.sel_size)
         this.ajax_page += "size=" + this.sel_size + "&";
      if(this.sel_color)
         this.ajax_page += "color=" + this.sel_color + "&";
      if(this.gProdID)
         this.ajax_page += "style=" + this.gProdID + "&";
      if(this.sel_qty)
         this.ajax_page += "quantity=" + this.sel_qty + "&";
      if(this.category.length > 2){
         if(this.category.substring(0, 3) == 'xlr' ||
            this.category.substring(0, 2) == 'cl'){
           this.ajax_page += "clearance=Yes";
         }
      }

      var color_cd;
      var color_txt;   
      this.color_list_array = item_detail_ajax.color_list.split(',');
      this.color_codes_array = item_detail_ajax.color_codes.split(',');
      for( var counter = 0; counter < this.color_list_array.length; counter++){
         if(this.color_codes_array[counter])
         {
            color_cd = this.color_codes_array[counter];
            color_txt = this.color_list_array[counter];
            this.ColorNames[color_cd] = color_txt;
         }
      }
      
      var size_cd;
      var size_txt;
      this.size_list1_array = item_detail_ajax.size_list1.split(",");
      this.size_codes_array = item_detail_ajax.size_codes.split(",");  
      for( var counter = 0; counter < this.size_list1_array.length; counter++){
         if(this.size_codes_array[counter])
         {
            size_cd = this.size_codes_array[counter];
            size_txt = this.size_list1_array[counter];
            this.SizeNames[size_cd] = size_txt;
         }
      }      
            
      showLoading();
            
      loadXMLAJAX();
   
   }

   function showLoading()
   {
   
      var lAvailabilityDiv;
      var lPriceDiv;

      lAvailabilityDiv = document.createElement("img");
      lAvailabilityDiv.src = item_detail_ajax.loadingImage;
      item_detail_ajax.availabilityDiv.innerHTML = '';
      item_detail_ajax.availabilityDiv.appendChild(lAvailabilityDiv);
      
      lPriceDiv = document.createElement("img");
      lPriceDiv.src = item_detail_ajax.loadingImage;
      item_detail_ajax.priceDiv.innerHTML = '';
      item_detail_ajax.priceDiv.appendChild(lPriceDiv);
      
   }
      
   function loadXMLAJAX(){
   
      var AVAILABILITY;
      var XML_AVAILABLE_TAG;
      var AVAILABILITY;
      
      var XML_GROUP_PRICE_TAG;
      
      var XML_GROUP_PRICES_TAG_ATTRIBUTES;
      var XML_GROUP_PRICES_TAG_ATTRIBUTES_MAX;
      var XML_GROUP_PRICES_TAG_ATTRIBUTES_MIN;
      var XML_GROUP_PRICES_TAG_ATTRIBUTES_WAS;
      var XML_GROUP_PRICES_TAG_ATTRIBUTES_WAS_TYPE;
      
      var DYNAMIC_DIV_ELEMENT;
      var DYNAMIC_DIV_ELEMENT_HTML;
      
      var color_list_array;
      var color_codes_array;
      var color_codes_array_position = 0;
      var size_list1_array;
      var size_codes_array;
      var size_codes_array_position = 0;
      var sel_size_object;
      var ColorArray_column = 1;
      var color;
      var size;      
      var price;
      
      color_list_array = item_detail_ajax.color_list.split(',');
      color_codes_array = item_detail_ajax.color_codes.split(',');
      size_list1_array = item_detail_ajax.size_list1.split(",");
      size_codes_array = item_detail_ajax.size_codes.split(",");
      sel_size_object = document.getElementById("sel_size");
      

     $.ajax({
         type: "GET",
         url: item_detail_ajax.ajax_page,
         dataType: "xml",
         success: function(data, textStatus ){
          
            var xd = jQuery.isXMLDoc( data );
            if(jQuery.isXMLDoc( data )){
               
               $(data).find("GROUP-PRICE").each(function() {
           
                  XML_GROUP_PRICE_TAG = $(this);
                  AVAILABILITY =  XML_GROUP_PRICE_TAG.attr('AVAILABILITY');
                  color = XML_GROUP_PRICE_TAG.attr("COLOR");
                  price = XML_GROUP_PRICE_TAG.attr("COST");
                  size = XML_GROUP_PRICE_TAG.attr("SIZE");
                  
                  var cpsa_array = Array();
                  cpsa_array["color"] = color;
                  cpsa_array["price"] = price;
                  cpsa_array["size"] = size;
                  cpsa_array["availability"] = AVAILABILITY;
                  item_detail_ajax.ajaxDetailsArray.push(cpsa_array);
                  
                  for (SizeArray_Flag = 1, SizeArray_Counter = 0; SizeArray_Counter < item_detail_ajax.SizeArray.length; SizeArray_Counter++)
                     if (item_detail_ajax.SizeArray[SizeArray_Counter] == size)
                        SizeArray_Flag = 2;
                  if (SizeArray_Flag == 1)
                     item_detail_ajax.SizeArray.push(size);
                  
                  for (PriceArray_Flag = 1, PriceArray_Counter = 0; PriceArray_Counter < item_detail_ajax.PriceArray.length; PriceArray_Counter++)
                     if (item_detail_ajax.PriceArray[PriceArray_Counter] == price)
                        PriceArray_Flag = 2;
                  if (PriceArray_Flag == 1)
                     item_detail_ajax.PriceArray.push(price);
                  
                  for (ColorArray_Flag = 1, ColorArray_position = 0; ColorArray_position < item_detail_ajax.ColorArray.length; ColorArray_position++)
                     if (item_detail_ajax.ColorArray[ColorArray_position] == color)
                        ColorArray_Flag = 2;
                  if (ColorArray_Flag == 1)
                     item_detail_ajax.ColorArray.push(color);
                  
                  if(item_detail_ajax.SizePriceArray[size])
                     item_detail_ajax.SizePriceArray[size].price(price);
                  else
                     item_detail_ajax.SizePriceArray[size] = new Costs(price);
                  
                  if(item_detail_ajax.ColorPriceArray[color])
                     item_detail_ajax.ColorPriceArray[color].price(price);
                  else
                     item_detail_ajax.ColorPriceArray[color] = new Costs(price);                  
                  
               });
               
               if (item_detail_ajax.ajaxDetailsArray.length == 0){
                  document.location = item_detail_ajax.gRoot + '/item_not_found.html?prod=' + item_detail_ajax.gProdID;
               }
               else{ 
                  color_prices_string = "";
                  for (color_codes_array_position = 0; color_codes_array_position < color_codes_array.length; color_codes_array_position++) {
                     
                     if(item_detail_ajax.ColorPriceArray[color_codes_array[color_codes_array_position]])
                        color = item_detail_ajax.ColorPriceArray[color_codes_array[color_codes_array_position]].range();
                     else
                        color = '0';
                        
                     if (color_prices_string != "")
                        color_prices_string += ",";
                     
                     color_prices_string += color;
                  
                  }
                  document.getElementById("color_prices").value = color_prices_string;
                  
                  size_prices_string = "";
                  for (size_codes_array_position = 0; size_codes_array_position < size_codes_array.length; size_codes_array_position++) {
                  
                     if(item_detail_ajax.SizePriceArray[size_codes_array[size_codes_array_position]])
                        color = item_detail_ajax.SizePriceArray[size_codes_array[size_codes_array_position]].range();
                     else
                        color = '0';
                     
                     if (size_prices_string != "") size_prices_string += ",";
                     size_prices_string += color;
                     
                  }
                  document.getElementById("size_prices").value = size_prices_string;
         
                  /* only populate once*/
                  if (item_detail_ajax.ColorSwatchDisplayArea_HTML.length == 0){
                     item_detail_ajax.ColorSwatchDisplayArea_HTML += '<table cellspacing="0" cellpadding="0" border="0" class="idt12">';
                     item_detail_ajax.ColorSwatchDisplayArea_HTML += '<tbody>';
                     item_detail_ajax.ColorSwatchDisplayArea_HTML += '<tr>';
                     item_detail_ajax.ColorSwatchDisplayArea_HTML += '<td valign="top" height="20" align="center" style="font-weight:bold" class="COmaintext">';
                     item_detail_ajax.ColorSwatchDisplayArea_HTML += '<div style="position:relative;top:0px">';
                     item_detail_ajax.ColorSwatchDisplayArea_HTML += 'Hover Over Color for Large View<br>Prices, and Sizes Available';
                     item_detail_ajax.ColorSwatchDisplayArea_HTML += '</div>';
                     item_detail_ajax.ColorSwatchDisplayArea_HTML += '</td>';
                     item_detail_ajax.ColorSwatchDisplayArea_HTML += '</tr>';
                     item_detail_ajax.ColorSwatchDisplayArea_HTML += '</tbody>';
                     item_detail_ajax.ColorSwatchDisplayArea_HTML += '</table>';
                     item_detail_ajax.ColorSwatchDisplayArea_HTML += '<table cellspacing="0px" cellpadding="5px" border="0px">';
                     item_detail_ajax.ColorSwatchDisplayArea_HTML += '<tr>';
                     
                     item_detail_ajax.ColorArray.sort(); // this sorts the swatches into the same order as dropdown
                     
                     for (ColorArray_position = 0; ColorArray_position < item_detail_ajax.ColorArray.length; ColorArray_position++) {
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '<td width="0%" valign="top" align="center" id="sngSwtch' + ColorArray_position + '">';
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '<table cellspacing="0" cellpadding="0" border="0" align="center" class="idt13">';
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '<tr>';
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '<td valign="top" align="center" onmouseout="$(' + "'" + '#color' + ColorArray_position + "'" + ').css(' + "'" + 'display' + "'" + ',' + "'" + 'none' + "'" + ');" onmouseover="position_color(' + ColorArray_position + ');" >';
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '<div id="SingleSwatch" style="width:20px;height:20px;border:1px solid #000;padding-right:0px;padding-left:0px;padding-top:0px;padding-bottom:0px;">';
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '<img onmouseout="$(' + "'" + '#color' + ColorArray_position + "'" + ').css(' + "'" + 'display' + "'" + ',' + "'" + 'none' + "'" + ');" onmouseover="position_color(' + ColorArray_position + ');" width="20" height="20" name="thumNailImg" id="' + item_detail_ajax.gProdID + item_detail_ajax.ColorArray[ColorArray_position] + '" src="/images/' + item_detail_ajax.gProdID.substr(0, 2) + '/' + item_detail_ajax.gProdID.substr(0, 4) + '/smswatch/' + item_detail_ajax.gProdID + item_detail_ajax.ColorArray[ColorArray_position] + '.jpg"/>';
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '</div>';
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '<div style="position:absolute; z-index:100;">';
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '<div class="ColorDescDiv" id="color' + ColorArray_position + '" style="position:absolute;top:-30px;left:30px">';
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '<table border="0px" cellpadding="0px" cellspacing="6px" width="400px">';
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '<colgroup>';
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '<col width="100px">';
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '<col width="*">';
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '</colgroup>';
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '<tr>';
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '<td valign="top" style="border:1px solid black;background:url(/images/swatchsoon.jpg)no-repeat center;" height="100px" width="100px">';
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '<img src="/images/' + item_detail_ajax.gProdID.substr(0, 2) + '/' + item_detail_ajax.gProdID.substr(0, 4) + '/lgswatch/' + item_detail_ajax.gProdID + item_detail_ajax.ColorArray[ColorArray_position] + '.jpg">';
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '</td>';
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '<td valign="top" class="regularText">';
                        color_cd = item_detail_ajax.ColorArray[ColorArray_position];
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '<img border="0" src="/images/next_arrow.gif" width="5px" height"8px" />&nbsp;<b>Color</b>:<font style="padding-left:5px;font-weight:normal;font-style:italic">' + item_detail_ajax.ColorNames[color_cd] + '</font><br>';
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '<img border="0" src="/images/next_arrow.gif" width="5px" height"8px" />&nbsp;<b>Color ID</b>:<font style="padding-left:5px;font-weight:normal;font-style:italic">' + color_cd + '</font><br>';
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '<br style="line-height:5px">';
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '</td>';
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '</tr>';
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '<tr>';
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '<td colspan="2">';
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += item_detail_ajax.priceSizeArea(item_detail_ajax.ColorArray[ColorArray_position]);
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '</td>';
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '</tr>';
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '</table>';
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '</div>';
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '</div>';
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '<td>';
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '</tr>';
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '</table>';
                        item_detail_ajax.ColorSwatchDisplayArea_HTML += '</td>';
                        if (ColorArray_column == 7) {
                           item_detail_ajax.ColorSwatchDisplayArea_HTML += '</tr><tr>';
                           ColorArray_column = 1
                        } else ColorArray_column++;
                     }
                     item_detail_ajax.ColorSwatchDisplayArea_HTML += '</tr>';
                     item_detail_ajax.ColorSwatchDisplayArea_HTML += '</table>';
                     $("#ColorSwatchDisplayArea").html(item_detail_ajax.ColorSwatchDisplayArea_HTML);
                  }               
                  
                  
                  $(data).find("AVAILABLE").each(function() {
                     XML_AVAILABLE_TAG = $(this);
                     item_detail_ajax.availability =  XML_AVAILABLE_TAG.attr('vr-err-message');
                     
                     DYNAMIC_DIV_ELEMENT = document.createElement("div");
                     DYNAMIC_DIV_ELEMENT.innerHTML = item_detail_ajax.availability;
                     item_detail_ajax.availabilityDiv.innerHTML = '';
                     item_detail_ajax.availabilityDiv.appendChild(DYNAMIC_DIV_ELEMENT);
                  });
                  
                  $(data).find("GROUP-PRICES").each(function() {
                  
                     XML_GROUP_PRICES_TAG_ATTRIBUTES = $(this);
                  
                     XML_GROUP_PRICES_TAG_ATTRIBUTES_MAX = XML_GROUP_PRICES_TAG_ATTRIBUTES.attr('MAX');
                     XML_GROUP_PRICES_TAG_ATTRIBUTES_MIN = XML_GROUP_PRICES_TAG_ATTRIBUTES.attr('MIN');
                     XML_GROUP_PRICES_TAG_ATTRIBUTES_WAS = XML_GROUP_PRICES_TAG_ATTRIBUTES.attr('WAS');
                     XML_GROUP_PRICES_TAG_ATTRIBUTES_WAS_TYPE = XML_GROUP_PRICES_TAG_ATTRIBUTES.attr('WAS-TYPE');
                  
                  });
                  
                  DYNAMIC_DIV_ELEMENT = document.createElement("div");
                  DYNAMIC_DIV_ELEMENT_HTML = XML_GROUP_PRICES_TAG_ATTRIBUTES_MIN;
                  if(XML_GROUP_PRICES_TAG_ATTRIBUTES_MIN != XML_GROUP_PRICES_TAG_ATTRIBUTES_MAX)
                  {
                     DYNAMIC_DIV_ELEMENT_HTML += " to " + XML_GROUP_PRICES_TAG_ATTRIBUTES_MAX;
                  }
                  DYNAMIC_DIV_ELEMENT.innerHTML = DYNAMIC_DIV_ELEMENT_HTML ;
                  item_detail_ajax.priceDiv.innerHTML = '';
                  item_detail_ajax.priceDiv.appendChild(DYNAMIC_DIV_ELEMENT);

                  
                   /* Was area */
                  if(item_detail_ajax.wasDiv ){

                     DYNAMIC_SPAN_ELEMENT = document.createElement("span");
                     
                     if( XML_GROUP_PRICES_TAG_ATTRIBUTES_WAS > XML_GROUP_PRICES_TAG_ATTRIBUTES_MAX ){
                        DYNAMIC_SPAN_ELEMENT_HTML = XML_GROUP_PRICES_TAG_ATTRIBUTES_WAS_TYPE + ":&nbsp;&nbsp;";
                        DYNAMIC_SPAN_ELEMENT_HTML += "<font ";
                        
                        if(XML_GROUP_PRICES_TAG_ATTRIBUTES_WAS_TYPE == 'Was'){
                           DYNAMIC_SPAN_ELEMENT_HTML += " style='text-decoration:line-through' ";
                        }
                        
                        DYNAMIC_SPAN_ELEMENT_HTML += ">";
                        DYNAMIC_SPAN_ELEMENT_HTML += XML_GROUP_PRICES_TAG_ATTRIBUTES_WAS;
                        DYNAMIC_SPAN_ELEMENT_HTML += "</font>";
                        
                        DYNAMIC_SPAN_ELEMENT.innerHTML = DYNAMIC_SPAN_ELEMENT_HTML;
                        
                     }
                     item_detail_ajax.wasDiv.innerHTML = '';
                     item_detail_ajax.wasDiv.appendChild(DYNAMIC_SPAN_ELEMENT);
                     
                  }
                  
                  item_detail_ajax.loaded++;
                  if( item_detail_ajax.loaded == 1 )
                     item_detail_ajax.loadSizeSelect();
               }
            }
         },
         error: function(xhr, textStatus, errorThrown){
         }
      });
      
   }
   

   function priceSizeArea(color_parameter) {

      var PriceArray_Counter = 0;
      var ajaxDetailsArray_Counter = 0;
      var return_string = "<table width='100%' cellpadding='3px' cellspacing='0px'>";
      var size, color, price;
      var size_block;
      var price_block;
      var size_list1_array = item_detail_ajax.size_list1.split(",");
      var size_codes_array  = item_detail_ajax.size_codes.split(",");
      var size_codes_array_position  = 0;
      var column = 1;
      
      for (PriceArray_Counter = 0; PriceArray_Counter < item_detail_ajax.PriceArray.length; PriceArray_Counter++) {
         price_block = "<tr><td class='smallText CategoryTopBar' colspan=4>At: $" + item_detail_ajax.PriceArray[PriceArray_Counter] + "</td></tr><tr>";
         size_block = "";
         column = 1;
         for (ajaxDetailsArray_Counter = 0; ajaxDetailsArray_Counter < item_detail_ajax.ajaxDetailsArray.length; ajaxDetailsArray_Counter++) {
            color = item_detail_ajax.ajaxDetailsArray[ajaxDetailsArray_Counter]['color'];
            price = item_detail_ajax.ajaxDetailsArray[ajaxDetailsArray_Counter]['price'];
            size = item_detail_ajax.ajaxDetailsArray[ajaxDetailsArray_Counter]['size'];
            if (color == color_parameter && item_detail_ajax.PriceArray[PriceArray_Counter] == price) {
               item_detail_ajax.SizeColor[size] += "," + color_parameter;
               size_block += "<td class='smallText CategoryRowColor'>" + item_detail_ajax.SizeNames[size]  + "</td>";
               if (column == 4) {
                  size_block += "</tr><tr>";
                  column = 1;
               } else column++;
            }
         }
         if (column > 1) for (ajaxDetailsArray_Counter = (column - 1); ajaxDetailsArray_Counter < 4; ajaxDetailsArray_Counter++)
         size_block += "<td class='smallText CategoryRowColor'>&nbsp;</td>";
         price_block += "</tr>";
         if (size_block != "") return_string += price_block + size_block;
      }
      return_string += "</table>";
      return return_string;
   }

   function urlencode(str){
   
      str = escape(str);
      str = str.replace('+', '%2B');
      str = str.replace('%20', '+');
      str = str.replace('*', '%2A');
      str = str.replace('/', '%2F');
      str = str.replace('@', '%40');
      return str;
   
   }
   
   function formatDollar(price) {

      if(price.indexOf(".") == -1){
         return  "$" + price + ".00";
      }
      else{
         return "$" + parseFloat(price).toFixed(2);
      }
      
   }
   
   function loadSizeSelect () {
   
      var sizename;
      
      if( this.sel_size_obj.options )
      {
          
         //Clear array
         if (this.sel_size_obj.length > 0)
         {
            this.sel_size_obj.remove(this.sel_size_obj.length - 1);
         }
         
         // put in  first option
         var elOptFirst = document.createElement('option');
         sizename = document.getElementById("sizetitle").value;
         elOptFirst.text = sizename + ' - Choose First';
         elOptFirst.value = '';
         try {
            this.sel_size_obj.add(elOptFirst, null); // standards compliant; doesn't work in IE
         }
         catch(ex) {
            this.sel_size_obj.add(elOptFirst); // IE only
         }       
         
         for(var counter = 0; counter < item_detail_ajax.SizeArray.length; counter++)
         {
         
            var SizeOptions = document.createElement('option');
            var SizeCode = item_detail_ajax.SizeArray[counter];
            var SPA = item_detail_ajax.SizePriceArray[SizeCode];
            
            SizeOptions.text = item_detail_ajax.SizeNames[SizeCode] + "\xa0\xa0\xa0-\xa0\xa0\xa0" + SPA.range();
            SizeOptions.value = SizeCode;
            
            try {
               this.sel_size_obj.add(SizeOptions, null); // standards compliant; doesn't work in IE
            }
            catch(ex) {
               this.sel_size_obj.add(SizeOptions); // IE only
            }       
               
         }
         
      }
      else if( this.sel_color_obj.options )
      {
      
         var colorname = document.getElementById("colortitle").value;

         //Clear array
         if (this.sel_color_obj.length > 0)
         {
            this.sel_color_obj.remove(this.sel_color_obj.length - 1);
         }

         // put in  first option
         var elOptFirst = document.createElement('option');
         elOptFirst.text = colorname + ' - Choose First';
         elOptFirst.value = '';
         try {
         this.sel_color_obj.add(elOptFirst, null); // standards compliant; doesn't work in IE
         }
         catch(ex) {
         this.sel_color_obj.add(elOptFirst); // IE only
         }       
      
         item_detail_ajax.ColorArray.sort();

         for(var counter = 0; counter < item_detail_ajax.ColorArray.length; counter++)
         {
            
            var ColorOptions = document.createElement('option');
            var ColorCode = item_detail_ajax.ColorArray[counter];
            var CPA = item_detail_ajax.ColorPriceArray[ColorCode];
 
            if( item_detail_ajax.ColorNames[ColorCode]){
            
               ColorOptions.text = ColorCode + "\xa0\xa0\xa0-\xa0\xa0\xa0" + item_detail_ajax.ColorNames[ColorCode] + "\xa0\xa0\xa0-\xa0\xa0\xa0" + CPA.range();
               ColorOptions.value = ColorCode;
               try {
                  this.sel_color_obj.add(ColorOptions, null); // standards compliant; doesn't work in IE
               }
               catch(ex) {
                  this.sel_color_obj.add(ColorOptions); // IE only
               }
            }
         }
      }
   }
   
}

function Costs(prc){

   this.minimum = prc;
   this.maximum = prc;
    
   this.price = function(pr)
   {
      if(parseInt(pr) < parseInt(this.minimum))
         this.minimum = pr;
      if(parseInt(pr) > parseInt(this.maximum))
         this.maximum = pr;
   };

   this.range = function()
   {
      if(this.minimum != this.maximum)
         return item_detail_ajax.formatDollar(this.minimum) + " - " + item_detail_ajax.formatDollar(this.maximum);
      else
         return item_detail_ajax.formatDollar(this.minimum);
   };
}
 

