function requestItem(div)	{
	var qtyname = 'qty';
	var idname = 'requestSupply_';
	var divid = 'reqeuested_item';
	var productname = 'requestName_';
	this.contentdiv = div;
	var hatch = 'close';
	_selfRI = this;
	
    
    
	this.init = function(){
	   
        $('#'+_selfRI.contentdiv).html('loading content..');
        
		$('.requestLink').click(function()	{
										 
			$('#reqeuested_item').fadeIn("slow");			
			var id = this.id.split("_");
			var pid = id[1];
			var qty='';
			var rid='';
           
			
			var name = document.getElementById(productname+pid).value;			

			$('#ajaxstat').ajaxStart(function() {
				$(this).text("Processing Request ... ");
                $(this).fadeIn("fast");
                  		
			});
			
			$('#ajaxstat').ajaxComplete(function() {
			     $(this).html("Process complete.");
				$(this).fadeOut("fast");
			});
			
            _selfRI.add(pid, name);      
			
			
		});
	}
	
	this.add = function(pid, name)	{
		
		if($('#closeopen').text()=='open')	{
			$('#closeopen').text('close');
			$('#rContent').slideDown("slow");
			$('#rFoot').slideDown("slow");			
		}
		
		$.ajax({
				url: "process.php?module=dealer&task=item-request&pid="+pid+"&name="+name+"&action=add",
				success: function(msg){
				    
                    var msg = _selfRI.extractMessage(msg);                    
				 
					$('#'+_selfRI.contentdiv).html(msg.message);
                    $("#requestRow_"+pid).effect("highlight", {}, 3000);
				}
				
	   });		
		
	}	
	this.remove = function(id, name)	{
		if(confirm("Remove "+name+" in your request list?")==true)	{
			$.ajax({
					url: "process.php?module=dealer&task=item-request&pid="+id+"&action=remove",
					success: function(msg){
                        
                        var msg = _selfRI.extractMessage(msg);    
						$('#'+_selfRI.contentdiv).html(msg.message);
					}
					
			});		
		}
		
	}
	this.minus = function(id)	{
		$.ajax({
				url: "process.php?module=dealer&task=item-request&pid="+id+"&action=minus",
				success: function(msg){
				    var msg = _selfRI.extractMessage(msg);   
					$('#'+_selfRI.contentdiv).html(msg.message);
				}
				
		});		
		
	}
	
	this.close = function()	{
		
		if($('#closeopen').text()=='close')	{
			$('#closeopen').text('open');
			$('#rContent').slideUp("slow");
			$('#rFoot').slideUp("slow");	
            $.cookie('requestStatus','close');          
		}	else	{
			$('#closeopen').text('close');
			$('#rContent').slideDown("slow");
			$('#rFoot').slideDown("slow");			
            $.cookie('requestStatus','open');          
		}
		
		
	}
	this.load = function()	{
		$('#reqeuested_item').fadeIn("slow");
        
        
        if($.cookie('requestStatus')=='close') {
            $('#rContent').css('display','none');
            $('#rFoot').css('display','none');   
            $('#closeopen').text('open');       
        }
		//alert(_selfRI.contentdiv);
		$.ajax({
				url: "process.php?module=dealer&task=item-request&action=load",
				success: function(msg){
				    var msg = _selfRI.extractMessage(msg);   
                    
                    if(msg.total==0)    {
                        setTimeout(function()   {
                            _selfRI.close();
                        },3000);
                    }   
                                     
					$('#'+_selfRI.contentdiv).html(msg.message);
				}
				
		});		
	}
    
    this.submit = function()  {
       if(confirm("Are you sure you want to request this items?")==true)    {
            $.ajax({
    				url: "process.php?module=dealer&task=item-request&action=submit",
    				success: function(msg){
    				     var msg = _selfRI.extractMessage(msg);   
    					$('#'+_selfRI.contentdiv).html(msg.message);
    				}
    				
    		});	
       }
    }
    
    this.approve = function(rid)  {
        $.ajax({
				url: "process.php?module=dealer&task=item-request&action=approve&rid="+rid,
				success: function(msg){
                    var msg = _selfRI.extractMessage(msg);   
                    $('#'+_selfRI.contentdiv).html(msg.message);
				}				
		});
    }
    
    this.verify = function(rid)  {
        var code = $('#verificationcode').val();
        $.ajax({
				url: "process.php?module=dealer&task=item-request&action=verify&rid="+rid+"&code="+code,
				success: function(msg){
                    var msg = _selfRI.extractMessage(msg);   
                    $('#'+_selfRI.contentdiv).html(msg.extramessage+msg.message);
                    $("#verifiederror").effect("highlight", {}, 3000);                    
				}				
		});
    }
    
    this.extractMessage = function(msg)    {
        
        var result = msg.split(':::');
        var msg = [];
        msg.total = result[0];
        msg.message = result[1];
        msg.extramessage = (result[3]) ? result[3] : '';
        return msg;
    }
}

function ListInventory()    {
    
    
    $.ajax({
    	url: "process.php?module=dealer&task=inventory&action=list",
    	success: function(msg){
            	      
    		$('#requestContent').html(msg);
    	}
    				
    });	
}
//======================================================================================================
//	CHECKOUT DEALER FLOAT
//======================================================================================================


function checkOutItem()	{
	var qtyname = 'qty';
	var idname = 'requestSupply_';
	var divid = 'reqeuested_item';
	var productname = 'requestName_';
	this.contentdiv = 'cContent';
	var hatch = 'close';
	_selfCO = this;
	
	this.init = function(){
		
		$('.ButtonsCart').click(function()	{
										 
			$('#checkoutList').fadeIn("slow");			
			var id = this.id.split("_");
			var pid = id[1];
			var rid=(id[2]== null) ? '' : id[2];	
            
            var qty = '0';
            if(document.getElementById('qty'+rid+pid))  {
                qty= document.getElementById('qty'+rid+pid).value;    
            }   else    {
                qty= '0';
            }
			
            var qty_ship = document.getElementById('qty_ship'+rid+pid).value;
			//alert('qty : '+qty+' | qty_ship : '+qty_ship);
			var name = document.getElementById(productname+pid).value;			

			$('#ajaxstat').ajaxStart(function() {
				$(this).text("Processing Shopping cart items. Please wait. ");
                $(this).fadeIn("fast");
			});
			
			$('#ajaxstat').ajaxComplete(function() {
			     $(this).text("Process complete.");
				$(this).fadeOut("fast");
			});
			
			
            if(qty!=0 || qty_ship!=0) 	_selfCO.add(pid, qty, qty_ship);
			
		});
	}
	
	this.add = function(pid, qty, qty_ship)	{
		
		if($('#ccloseopen').text()=='open')	{
			$('#ccloseopen').text('close');
			$('#cContent').slideDown("slow");
			$('#cFoot').slideDown("slow");			
		}
		
		$.ajax({
				url: "processcheckout.php?pid="+pid+"&qty="+qty+"&qty_ship="+qty_ship,
				success: function(msg){
					$('#'+_selfCO.contentdiv).html(msg);
                    $(".productList_"+pid).effect("highlight", {}, 5000);
				}
				
	   });		
		
		_selfCO.checkScr();
		
	}	
	this.remove = function(pid, delivery)	{
		var action = (delivery=='pickup') ? "pick-up" : "drop-ship";
        if(confirm("Are you sure you want to remove this item for "+action+"?")==true)    {
			$.ajax({
					url: "processcheckout.php?task=deleteminicart&pid="+pid+"&delivery="+delivery,
					success: function(msg){
						$('#'+_selfCO.contentdiv).html(msg);
					}					
			});		
        }		
	}
 

	this.close = function()	{
		
		if($('#ccloseopen').text()=='close')	{
			$('#ccloseopen').text('open');
			$('#cContent').slideUp("slow");
			$('#cFoot').slideUp("slow");	
            $.cookie('dealerCart','close');
		}	else	{
			$('#ccloseopen').text('close');
			$('#cContent').slideDown("slow");
			$('#cFoot').slideDown("slow");	
            $.cookie('dealerCart','open');		
		}
		
		
	}
	
	this.load = function()	{
	   
        if($.cookie('dealerCart')=='close') {
             $('#cContent').css('display','none');
             $('#cFoot').css('display','none');   
             $('#ccloseopen').text('open');       
        }
        
		$('#checkoutList').fadeIn("slow");			
		$.ajax({
				url: "processcheckout.php",
				success: function(msg){
					$('#'+_selfCO.contentdiv).html(msg);
				}
				
		});		
		
		_selfCO.checkScr();
	}
	
	this.checkScr = function()	{
		var windowH = (window.innerHeight);

		var adjustH = windowH - 200;
		var compare = $('#checkoutList').offset();
		//alert(compare.top);
    	if(compare.top < 10)	{
			$('#'+_selfCO.contentdiv).css("height", adjustH);		
			$('#'+_selfCO.contentdiv).css("overflow", "auto");		
		}
	}
}

//======================================================================================================
//	CHECKOUT RETAIL FLOAT
//======================================================================================================

function retailCheckout()	{
    
    
	_selfR = this;
    this.contentdiv = 'RCContent';
	
	this.load = function(purl)	{

		$.ajax({
                url: purl,
				success: function(msg){
				    
                    var msg = _selfR.extractMessage(msg);
                    
                    if(msg.total < 1)   {                        
                        _selfR.empty();                    
                    }
                    
                    
                    $('#cartTotal').text(msg.total);
					$('#'+_selfR.contentdiv).html(msg.message);
                    $('#myspantop').html('You have <span style="color: red; font-weight: bold;">'+msg.total+' item(s)</span> in your shopping cart. <span style="color: red; font-weight: bold;">Checkout Now</span>');
				}				
		});	
	}
	
	this.close = function()	{
		
		if($('#RCcloseopen').text()=='close')	{
			$('#RCcloseopen').text('open');
			$('#RCContent').slideUp("slow");
			$('#RCFoot').slideUp("slow");
            $.cookie('cartStatus','close');	
		}	else	{
			$('#RCcloseopen').text('close');
			$('#RCContent').slideDown("slow");
			$('#RCFoot').slideDown("slow");
            $.cookie('cartStatus','open');            			
		}
		
        //alert($.cookie('cartStatus'));
		
	}
    this.init = function() {
       
        if($.cookie('cartStatus')=='close') {
            $('#RCContent').css('display','none');
            $('#RCFoot').css('display','none');   
            $('#RCcloseopen').text('open');       
        }
       
    }
    
    this.add = function(purl, pid)   {
        if($.cookie('cartStatus')=='close') {
            _selfR.close();
        }
        
    	$.ajax({
                url: purl,
				success: function(msg){
                    var msg = _selfR.extractMessage(msg);
                    $('#cartTotal').text(msg.total);
                    $('#myspantop').html('You have <span style="color: red; font-weight: bold;">'+msg.total+' item(s)</span> in your shopping cart. <span style="color: red; font-weight: bold;">Checkout Now</span>');
					$('#'+_selfR.contentdiv).html(msg.message);                    
                    $("#productList_"+pid).effect("highlight", {}, 5000);
				}				
		});             	
    }
    
    this.remove = function(purl)    {
        
        $.ajax({
                url: purl,
				success: function(msg){
				    var msg = _selfR.extractMessage(msg);
                    
                    if(msg.total < 1)   {                        
                        _selfR.empty();                    
                    }
                                        
                    $('#cartTotal').text(msg.total);
                    $('#myspantop').html('You have <span style="color: red; font-weight: bold;">'+msg.total+' item(s)</span> in your shopping cart. <span style="color: red; font-weight: bold;">Checkout Now</span>');
					$('#'+_selfR.contentdiv).html(msg.message);
                    
                   
				}				
		});
        
    }
    this.empty = function() {
      
        if($.cookie('cartStatus')=='open' || $.cookie('cartStatus')==null) {            
            setTimeout(function()   {
                _selfR.close();
            },3000);
                
        }
        
    }
    this.extractMessage = function(msg)    {
        
        var result = msg.split(':::');
        var msg = [];
        msg.total = result[0];
        msg.message = result[1];
        return msg;
    }
}


jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { 
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {   
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); 
        }

        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { 
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
