//====================================================
// PASTE INTO HEAD:
/***
<script type="text/javascript" src="includes/ajax/in_stock.js" ></script>
***/
//
// EXAMPLE:
//    <span id="fred" class="in_stock" manufacturers_id="18" part_code="GD1001" type="text" ></span>
//
//====================================================

function in_stock( settings ){

	var m = jQuery.extend({
	   id               : 'in_stock',
	   manufacturers_id : undefined,
	   part_code        : undefined,
	   span_type        : undefined,
	   container        : this,
	   target           : undefined,
     url              : '/includes/ajax/in_stock.php',
	   guid             : parseInt(Math.random()*1000000)
	}, settings || {});

  m.target = document.getElementById(m.id);

  if ("https:" == window.location.protocol) {
      m.url = 'https://secure.potn.com/~potncom'+m.url;
  } // if

  $.post
  (
    m.url,
    {
      action           : 'in_stock',
      manufacturers_id : m.manufacturers_id,
      part_code        : m.part_code,
      span_type        : m.span_type,
      sizes            : m.sizes
    },
    function(retval){
        m.target.innerHTML = retval;
    } // function(retval)

  ) // $.post

} // function

//====================================================

function in_stock_init(){
    $('.in_stock').each( 
        function(dummy) {
            var id               = this.id;
            var manufacturers_id = '';
            var part_code        = '';
            var span_type        = '';
            
            if (undefined == this.attributes['type']){
                span_type        = '';
            } else {
                span_type        = this.attributes['type'].value;
            }
            try{
                manufacturers_id = this.attributes['manufacturers_id'].value;
                part_code        = this.attributes['part_code'].value;
                
                
            } catch(err) {
                return;
                part_code = '';
                
            }
    
            $('#'+id).html(
                in_stock( 
                    {
                    target           : this, 
                    id               : id,
                    manufacturers_id : manufacturers_id,
                    part_code        : part_code,
                    span_type        : span_type                    
                    } 
                )
            );
        }
    );
} // function

//====================================================

$(document).ready(function() {
    in_stock_init();
} );

//====================================================
