// check inventory 

function dispAlert(msg){
 document.getElementById('Alert_div').innerHTML = "<h3>" + msg + "</h3>";
 TB_show("Alert","#TB_inline?height=300&width=300&inlineId=Alert_div")
}
function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}
function format_number(pnumber,decimals) 
{
  var strNumber = new String(pnumber);
  var arrParts = strNumber.split('.');
  var intWholePart = parseInt(arrParts[0],10);
  var strResult = '';
  if (isNaN(intWholePart))
    intWholePart = '0';
  if(arrParts.length > 1)
  {
    var decDecimalPart = new String(arrParts[1]);
    var i = 0;
    var intZeroCount = 0;
     while ( i < String(arrParts[1]).length )
     {
       if( parseInt(String(arrParts[1]).charAt(i),10) == 0 )
       {
         intZeroCount += 1;
         i += 1;
       }
       else
         break;
    }
    decDecimalPart = parseInt(decDecimalPart,10)/Math.pow(10,parseInt(decDecimalPart.length-decimals-1)); 
    Math.round(decDecimalPart); 
    decDecimalPart = parseInt(decDecimalPart)/10; 
    decDecimalPart = Math.round(decDecimalPart); 

    //If the number was rounded up from 9 to 10, and it was for 1 'decimal' 
    //then we need to add 1 to the 'intWholePart' and set the decDecimalPart to 0. 

    if(decDecimalPart==Math.pow(10, parseInt(decimals)))
    { 
      intWholePart+=1; 
      decDecimalPart="0"; 
    } 
    var stringOfZeros = new String('');
    i=0;
    if( decDecimalPart > 0 )
    {
      while( i < intZeroCount)
      {
        stringOfZeros += '0';
        i += 1;
      }
    }
    decDecimalPart = String(intWholePart) + "." + stringOfZeros + String(decDecimalPart); 
    var dot = decDecimalPart.indexOf('.');
    if(dot == -1)
    {
      decDecimalPart += '.'; 
      dot = decDecimalPart.indexOf('.'); 
    } 
    var l=parseInt(dot)+parseInt(decimals); 
    while(decDecimalPart.length <= l) 
    {
      decDecimalPart += '0'; 
    }
    strResult = decDecimalPart;
  }
  else
  {
    var dot; 
    var decDecimalPart = new String(intWholePart); 

    decDecimalPart += '.'; 
    dot = decDecimalPart.indexOf('.'); 
    var l=parseInt(dot)+parseInt(decimals); 
    while(decDecimalPart.length <= l) 
    {
      decDecimalPart += '0'; 
    }
    strResult = decDecimalPart;
  }
  return strResult;
}



function loadItemHandler1(carousel, start, last, available)
{
    if (!available) {
        for (var i = start; i <= last; i++) {
            if (i > itemList.length) {
                break;
            }

            carousel.add(i, getItemHTML(itemList[i - 1],itemTitle[i - 1],itemTagID[i - 1]));						
         }
    }
    // Trigger loaded
    carousel.loaded();
};



function getItemHTML(url,Title,Tagid)
{
	ret = '';
	ret += '<div class="License_Cell_Carousel">';
  	strTitle = Title;
  	linkURL = '/store/t' + Tagid + '/' + strTitle + '-License.html';
  	linkURL = linkURL.replace(/20%/g,'-');
  	linkURL = linkURL.replace(/ /g,'_');
   	linkURL = linkURL.replace(/&amp;/g,'');
   	linkURL = linkURL.replace(/&/g,'');
   	linkURL = linkURL.replace(/\'/g,'');
    linkURL = linkURL.replace(/--/g,'-');
  	ret += '<a href="' + linkURL + '">';
    ret += '<img src="/TGimages/' + url + '" class="Limage" width="100" border="0" title="' + strTitle + '" alt="' + strTitle  + '" />';
    ret += '<div class="LCtitle">' + strTitle + '</div>';
	ret += '</a>';
  	ret += '</div>';
 	return ret;
};

// Next-Button handling...
var nextOver = function() {
    jQuery(this).attr("src", "/Store/images/jcarousel/horizontal-ie7/smbuttons/next-over.gif");
};

var nextOut = function() {
    jQuery(this).attr("src", "/Store/images/jcarousel/horizontal-ie7/smbuttons/next.gif");
};

var nextDown = function() {
    jQuery(this).attr("src", "/Store/images/jcarousel/horizontal-ie7/smbuttons/next-down.gif");
};

function nextButtonStateHandler(carousel, button, enabling)
{
    if (enabling) {
        jQuery(button).attr("src", "/Store/images/jcarousel/horizontal-ie7/smbuttons/next.gif")
                      .bind("mouseover", nextOver)
                      .bind("mouseout", nextOut)
                      .bind("mousedown", nextDown);
    } else {
        jQuery(button).attr("src", "/Store/images/jcarousel/horizontal-ie7/smbuttons/next-disabled.gif")
                      .unbind("unmouseover", nextOver)
                      .unbind("unmouseout", nextOut)
                      .unbind("unmousedown", nextDown);
    }
}

// Prev-Button handling
var prevOver = function() {
    jQuery(this).attr("src", "/Store/images/jcarousel/horizontal-ie7/smbuttons/prev-over.gif");
};

var prevOut = function() {
    jQuery(this).attr("src", "/Store/images/jcarousel/horizontal-ie7/smbuttons/prev.gif");
};

var prevDown = function() {
    jQuery(this).attr("src", "/Store/images/jcarousel/horizontal-ie7/smbuttons/prev-down.gif");
};

function prevButtonStateHandler(carousel, button, enabling)
{
    if (enabling) {
        jQuery(button).attr("src", "/Store/images/jcarousel/horizontal-ie7/smbuttons/prev.gif")
                      .bind("mouseover", prevOver)
                      .bind("mouseout", prevOut)
                      .bind("mousedown", prevDown);
    } else {
        jQuery(button).attr("src", "/Store/images/jcarousel/horizontal-ie7/smbuttons/prev-disabled.gif")
                      .unbind("unmouseover", prevOver)
                      .unbind("unmouseout", prevOut)
                      .unbind("unmousedown", prevDown);
    }
}

