// $Id: products_with_attributes_stock_ajax.js 389 2008-11-14 16:02:14Z hugo13 $

$(document).ready(function() { 
    // bind form using ajaxForm 
    $('#pwas-search').ajaxForm({

		
        // target identifies the element(s) to update with the server response 
        target: '#pwa-table',
        url: 'products_with_attributes_stock_ajax.php', 
        success:  addEvent
 
        // success identifies the function to invoke when the server response 
        // has been received; here we apply a fade-in effect to the new content 
    });
});

$(document).ready(function() { 
    // bind form using ajaxForm 
    $('#store').ajaxForm({ 
        // target identifies the element(s) to update with the server response 
        target: '#hugo1', 
        success: saved
 
        // success identifies the function to invoke when the server response 
        // has been received; here we apply a fade-in effect to the new content 
    }); 
});


function processJasonFree(data) { 
    //processLocations(data);

    //var paragraphCount = document.evaluate( 'count(/html/body/div[2]/div[3]/div/div[2]/div/div/iframe)', document, null, XPathResult.ANY_TYPE, null );
    //alert( 'This document contains ' + paragraphCount.numberValue + ' paragraph elements' );    
}

$(document).ready(function(){
    $("#btnrandom").click(function(e){
        e.preventDefault(); // Normales Submit unterdrücken

        $.ajax({ // AJAX Request auslösen
            type: "POST",
            url: '/data/random/5a0bc3836e07a7be06a2fc3109b9d9daaffeafda/1',
            dataType: 'json',
            global: 'false',
            success: processJason
        });
    });
    $("#loading").hide();    // Das Loding Element verstecken
	
	$(".barcode").click(function(event){
        var $tgt = $(event.target);
        var $id = this.id;
        var $inner = this.innerHTML.replace(/\s/g, "");
        if (!$tgt.is('input')) {
            if(!this.hasEventHander){
			
            var $newLi = '<input onblur="update_barcode(this.value,\'' + $id + '\' )" type="text" name="' + $id + '" id="' + $id + '" value="' + $inner + '" size="8"/>';
            this.innerHTML = $newLi;
                this.hasEventHander = true;
        }
        }        
    })
    
    $(".manufactureredit").click(function(event){
        var $tgt = $(event.target);
        var $id = this.id;
        var $inner = this.innerHTML;
        if (!$tgt.is('input')) {
            if(!this.hasEventHander){
			
            var $newLi = '<select name="' + $id + '" id="' + $id + '" onchange="update_manufacturer(this.value,\'' + $id + '\' )">';
            var i = 0;
            $newLi += '<option value="">-';
			for (var key in manufacturers)
			{
				if($inner == manufacturers[key])
				{
					$newLi += '<option value="'+ key +'" selected>'+manufacturers[key];
    			
				}else{
					$newLi += '<option value="'+ key +'">'+manufacturers[key];
    			}
    			i++;
			}
            $newLi += '</select>';
            this.innerHTML = $newLi;
                this.hasEventHander = true;
        }
        }        
    })
    
	
	$(".supplieredit").click(function(event){
        var $tgt = $(event.target);
        var $id = this.id;
        var $inner = this.innerHTML;
        if (!$tgt.is('input')) {
            if(!this.hasEventHander){
			
            var $newLi = '<select name="' + $id + '" id="' + $id + '" onchange="update_supplier(this.value,\'' + $id + '\' )">';
            var i = 0;
            $newLi += '<option value="">-';
			for (var key in suppliers)
			{
				if($inner == suppliers[key])
				{
					$newLi += '<option value="'+ key +'" selected>'+suppliers[key];
    			
				}else{
					$newLi += '<option value="'+ key +'">'+suppliers[key];
    			}
    			i++;
			}
            $newLi += '</select>';
            this.innerHTML = $newLi;
                this.hasEventHander = true;
        }
        }        
    })
	
	
	$(".nameedit").click(function(event){
        var $tgt = $(event.target);
        var $id = this.id;
        var $inner = this.innerHTML;
        $inner = $inner.replace("\"", "&#34;");
        $inner = $inner.replace("\"", "&#34;");
        if (!$tgt.is('input')) {
            if(!this.hasEventHander){
			
            var $newLi = '<textarea onblur="update_name(this.value,\'' + $id + '\' )" name="' + $id + '" id="' + $id + '" style="width:100%"; row="3">' + $inner + '</textarea>';
            this.innerHTML = $newLi;
                this.hasEventHander = true;
        }
        }        
    })
	
	
	$(".modeledit").click(function(event){
        var $tgt = $(event.target);
        var $id = this.id;
        var $inner = this.innerHTML.replace(/\s/g, "");
        if (!$tgt.is('input')) {
            if(!this.hasEventHander){
			
            var $newLi = '<input onblur="update_mainmodel(this.value,\'' + $id + '\' )" type="text" name="' + $id + '" id="' + $id + '" value="' + $inner + '" size="8"/>';
            this.innerHTML = $newLi;
                this.hasEventHander = true;
        }
        }        
    })
	
	$(".costedit").click(function(event){
        var $tgt = $(event.target);
        var $id = this.id;
        var $inner = this.innerHTML.replace(/\s/g, "");
        if (!$tgt.is('input')) {
            if(!this.hasEventHander){
			
            var $newLi = '<input onblur="update_cost(this.value,\'' + $id + '\' )" type="text" name="' + $id + '" id="' + $id + '" value="' + $inner + '" size="8"/>';
            this.innerHTML = $newLi;
                this.hasEventHander = true;
        }
        }        
    })
    
    $(".sellingedit").click(function(event){
        var $tgt = $(event.target);
        var $id = this.id;
        
        var $inner;
        if(this.firstChild.className == "normalprice")
        {
        	$inner = this.firstChild.innerHTML.replace(/\s/g, "");
        }else{
        	$inner = this.innerHTML.replace(/\s/g, "");
        }
        
        
        if (!$tgt.is('input')) {
            if(!this.hasEventHander){
			
            var $newLi = '<input onblur="update_selling(this.value,\'' + $id + '\' )" type="text" name="' + $id + '" id="' + $id + '" value="' + $inner + '" size="8"/>';
            this.innerHTML = $newLi;
                this.hasEventHander = true;
        }
        }        
    })
	
	
    $(".stockAttributesCellQuantity").click(function(event){
        var $tgt = $(event.target);
        var $id = this.id;
        var $inner = this.innerHTML.replace(/\s/g, "");
        if (!$tgt.is('input')) {
            if(!this.hasEventHander){
			
            var $newLi = '<input onblur="update_quantity(this.value,\'' + $id + '\' )" type="text" name="' + $id + '" id="' + $id + '" value="' + $inner + '" size="8"/>';
            this.innerHTML = $newLi;
                this.hasEventHander = true;
        }
        }        
    })
	

	
	 $(".stockAttributesCellLocation").click(function(event){
	 //.click(function(event){
	 
        var $tgt = $(event.target);
        var id = this.id;
        var inner = this.innerHTML.replace(/\s/g, "");
        if (!$tgt.is('input')) {
           if(!this.hasEventHander){
		
		//alert($id);
		
            var newLi = '<input onblur="update_location(this.value,\'' + id + '\' ,this)" type="text" name="' + id + '" id="' + id + '" value="' + inner + '" size="8"/>';
            this.innerHTML = newLi;
                this.hasEventHander = true;
        }
        }        
    })
	
	$(".stockAttributesCellQuantityB1").click(function(event){
        var $tgt = $(event.target);
        var $id = this.id;
        var $inner = this.innerHTML.replace(/\s/g, "");
        if (!$tgt.is('input')) {
            if(!this.hasEventHander){
			
            var $newLi = '<input onblur="update_quantityB1(this.value,\'' + $id + '\' )" type="text" name="' + $id + '" id="' + $id + '" value="' + $inner + '" size="8"/>';
            this.innerHTML = $newLi;
            this.hasEventHander = true;
        }
        }        
    })
	$(".stockAttributesCellQuantityB2").click(function(event){
        var $tgt = $(event.target);
        var $id = this.id;
        var $inner = this.innerHTML.replace(/\s/g, "");
        if (!$tgt.is('input')) {
            if(!this.hasEventHander){
			
            var $newLi = '<input onblur="update_quantityB2(this.value,\'' + $id + '\' )" type="text" name="' + $id + '" id="' + $id + '" value="' + $inner + '" size="8"/>';
            this.innerHTML = $newLi;
                this.hasEventHander = true;
        }
        }        
    })
	$(".stockAttributesCellWarrenty").click(function(event){
        var $tgt = $(event.target);
        var $id = this.id;
        var $inner = this.innerHTML.replace(/\s/g, "");
        if (!$tgt.is('input')) {
            if(!this.hasEventHander){
			
            var $newLi = '<input onblur="update_warrenty(this.value,\'' + $id + '\' )" type="text" name="' + $id + '" id="' + $id + '" value="' + $inner + '" size="4"/>';
            this.innerHTML = $newLi;
                this.hasEventHander = true;
        }
        }        
    })
	$(".stockAttributesCellReorder").click(function(event){
        var $tgt = $(event.target);
        var $id = this.id;
        var $inner = this.innerHTML.replace(/\s/g, "");
        if (!$tgt.is('input')) {
            if(!this.hasEventHander){
			
            var $newLi = '<input onblur="update_reorder(this.value,\'' + $id + '\' )" type="text" name="' + $id + '" id="' + $id + '" value="' + $inner + '" size="4"/>';
            this.innerHTML = $newLi;
                this.hasEventHander = true;
        }
        }        
    })
	$(".stockAttributesCellMinStock").click(function(event){
        var $tgt = $(event.target);
        var $id = this.id;
        var $inner = this.innerHTML.replace(/\s/g, "");
        if (!$tgt.is('input')) {
            if(!this.hasEventHander){
			
            var $newLi = '<input onblur="update_minstock(this.value,\'' + $id + '\' )" type="text" name="' + $id + '" id="' + $id + '" value="' + $inner + '" size="4"/>';
            this.innerHTML = $newLi;
                this.hasEventHander = true;
        }
        }        
    })
	$(".stockAttributesCellNote").click(function(event){
        var $tgt = $(event.target);
        var $id = this.id;
        var $inner = this.innerHTML;
        if (!$tgt.is('input')) {
            if(!this.hasEventHander){
			
            var $newLi = '<input onblur="update_note(this.value,\'' + $id + '\' )" type="text" name="' + $id + '" id="' + $id + '" value="' + $inner + '" size="10"/>';
            this.innerHTML = $newLi;
                this.hasEventHander = true;
        }
        }        
    })
	
	$(".stockAttributesCellModel").click(function(event){
        var $tgt = $(event.target);
        var $id = this.id;
        var $inner = this.innerHTML;
        if (!$tgt.is('input')) {
            if(!this.hasEventHander){
			
            var $newLi = '<input onblur="update_model(this.value,\'' + $id + '\' )" type="text" name="' + $id + '" id="' + $id + '" value="' + $inner + '" size="10"/>';
            this.innerHTML = $newLi;
                this.hasEventHander = true;
        }
        }        
    })
	
	
	
	
	
	
	
    $("#loading")
        .ajaxStart(function(){   // Wird ausgeführt sobald AJAX startet
            $(this).show(00);
        })    
        .ajaxError(function(){   // Wird ausgeführt bei AJAX ERROR
            $(this).show(500);
        })    
        .ajaxSuccess(function(){      // Wird ausgeführt sobald AJAX fertig ist
            $(this).hide(500);
        });
});

function addEvent() {
$('.nameedit').each(
            function(){
                if(!this.hasEventHander)
                    $(this).click(function(event){    
                    /*/ Our Eventhanderl /*/    
                    var $tgt = $(event.target);
                    var $id = this.id;
                    var $inner = this.innerHTML;
                    if (!$tgt.is('input')) {
                        var $newLi = '<input onblur="update_name(this.value,\'' + $id + '\' )" type="text" name="' + $id + '" id="' + $id + '" value="' + $inner + '" size="15"/>';
                        this.innerHTML = $newLi;
                        //this.unbind("click");
                    }        
                });
                this.hasEventHander = true;
            }
        );


$('.modeledit').each(
            function(){
                if(!this.hasEventHander)
                    $(this).click(function(event){    
                    /*/ Our Eventhanderl /*/    
                    var $tgt = $(event.target);
                    var $id = this.id;
                    var $inner = this.innerHTML;
                    if (!$tgt.is('input')) {
                        var $newLi = '<input onblur="update_mainmodel(this.value,\'' + $id + '\' )" type="text" name="' + $id + '" id="' + $id + '" value="' + $inner + '" size="8"/>';
                        this.innerHTML = $newLi;
                        //this.unbind("click");
                    }        
                });
                this.hasEventHander = true;
            }
        );
$('.sellingedit').each(
            function(){
                if(!this.hasEventHander)
                    $(this).click(function(event){    
                    /*/ Our Eventhanderl /*/    
                    var $tgt = $(event.target);
                    var $id = this.id;
                    var $inner = this.innerHTML;
                    if (!$tgt.is('input')) {
                        var $newLi = '<input onblur="update_selling(this.value,\'' + $id + '\' )" type="text" name="' + $id + '" id="' + $id + '" value="' + $inner + '" size="8"/>';
                        this.innerHTML = $newLi;
                        //this.unbind("click");
                    }        
                });
                this.hasEventHander = true;
            }
        );
$('.costedit').each(
            function(){
                if(!this.hasEventHander)
                    $(this).click(function(event){    
                    /*/ Our Eventhanderl /*/    
                    var $tgt = $(event.target);
                    var $id = this.id;
                    var $inner = this.innerHTML;
                    if (!$tgt.is('input')) {
                        var $newLi = '<input onblur="update_cost(this.value,\'' + $id + '\' )" type="text" name="' + $id + '" id="' + $id + '" value="' + $inner + '" size="8"/>';
                        this.innerHTML = $newLi;
                        //this.unbind("click");
                    }        
                });
                this.hasEventHander = true;
            }
        );


 $('.barcode').each(
            function(){
                if(!this.hasEventHander)
                    $(this).click(function(event){    
                    /*/ Our Eventhanderl /*/    
                    var $tgt = $(event.target);
                    var $id = this.id;
                    var $inner = this.innerHTML;
                    if (!$tgt.is('input')) {
                        var $newLi = '<input onblur="update_barcode(this.value,\'' + $id + '\' )" type="text" name="' + $id + '" id="' + $id + '" value="' + $inner + '" size="8"/>';
                        this.innerHTML = $newLi;
                        //this.unbind("click");
                    }        
                });
                this.hasEventHander = true;
            }
        );
		
 $('.stockAttributesCellLocation').each(
            function(){
                if(!this.hasEventHander)
                    //$(this).bind("click tap touchstart", function(event){
                    $(this).click(function(event){    
					
					
                    /*/ Our Eventhanderl /*/    
                    var $tgt = $(event.target);
                    var $id = this.id;
                    var $inner = this.innerHTML;
                    if (!$tgt.is('input')) {
						
						if($inner == '?')
						{
							var $newLi = '<input onblur="update_location(this.value,\'' + $id + '\' ,this)" type="text" name="' + $id + '" id="' + $id + '" value="" size="8"/>';
                        }else{
						var $newLi = '<input onblur="update_location(this.value,\'' + $id + '\' ,this)" type="text" name="' + $id + '" id="' + $id + '" value="' + $inner + '" size="8"/>';
						}
						this.innerHTML = $newLi;
                        //this.unbind("click");
                    }        
                });
                this.hasEventHander = true;
            }
        );
		
		
 $('.stockAttributesCellQuantity').each(
            function(){
                if(!this.hasEventHander)
                    $(this).click(function(event){    
					
					
                    /*/ Our Eventhanderl /*/    
                    var $tgt = $(event.target);
                    var $id = this.id;
                    var $inner = this.innerHTML;
                    if (!$tgt.is('input')) {
                        var $newLi = '<input onblur="update_quantity(this.value,\'' + $id + '\' )" type="text" name="' + $id + '" id="' + $id + '" value="' + $inner + '" size="8"/>';
                        this.innerHTML = $newLi;
                        //this.unbind("click");
                    }        
                });
                this.hasEventHander = true;
            }
        );
	 $('.stockAttributesCellQuantityB1').each(
            function(){
                if(!this.hasEventHander)
                    $(this).click(function(event){    
					
					
                    /*/ Our Eventhanderl /*/    
                    var $tgt = $(event.target);
                    var $id = this.id;
                    var $inner = this.innerHTML;
                    if (!$tgt.is('input')) {
                        var $newLi = '<input onblur="update_quantityB1(this.value,\'' + $id + '\' )" type="text" name="' + $id + '" id="' + $id + '" value="' + $inner + '" size="8"/>';
                        this.innerHTML = $newLi;
                        //this.unbind("click");
                    }        
                });
                this.hasEventHander = true;
            }
        );
		 $('.stockAttributesCellQuantityB2').each(
            function(){
                if(!this.hasEventHander)
                    $(this).click(function(event){    
					
					
                    /*/ Our Eventhanderl /*/    
                    var $tgt = $(event.target);
                    var $id = this.id;
                    var $inner = this.innerHTML;
                    if (!$tgt.is('input')) {
                        var $newLi = '<input onblur="update_quantityB2(this.value,\'' + $id + '\' )" type="text" name="' + $id + '" id="' + $id + '" value="' + $inner + '" size="8"/>';
                        this.innerHTML = $newLi;
                        //this.unbind("click");
                    }        
                });
                this.hasEventHander = true;
            }
        );
		
	$('.stockAttributesCellWarrenty').each(
            function(){
                if(!this.hasEventHander)
                    $(this).click(function(event){    
					
					
                    /*/ Our Eventhanderl /*/    
                    var $tgt = $(event.target);
                    var $id = this.id;
                    var $inner = this.innerHTML;
                    if (!$tgt.is('input')) {
                        var $newLi = '<input onblur="update_warrenty(this.value,\'' + $id + '\' )" type="text" name="' + $id + '" id="' + $id + '" value="' + $inner + '" size="4"/>';
                        this.innerHTML = $newLi;
                        //this.unbind("click");
                    }        
                });
                this.hasEventHander = true;
            }
        );
		
	$('.stockAttributesCellReorder').each(
            function(){
                if(!this.hasEventHander)
                    $(this).click(function(event){    
					
					
                    /*/ Our Eventhanderl /*/    
                    var $tgt = $(event.target);
                    var $id = this.id;
                    var $inner = this.innerHTML;
                    if (!$tgt.is('input')) {
                        var $newLi = '<input onblur="update_reorder(this.value,\'' + $id + '\' )" type="text" name="' + $id + '" id="' + $id + '" value="' + $inner + '" size="4"/>';
                        this.innerHTML = $newLi;
                        //this.unbind("click");
                    }        
                });
                this.hasEventHander = true;
            }
        );
		$('.stockAttributesCellMinStock').each(
            function(){
                if(!this.hasEventHander)
                    $(this).click(function(event){    
					
					
                    /*/ Our Eventhanderl /*/    
                    var $tgt = $(event.target);
                    var $id = this.id;
                    var $inner = this.innerHTML;
                    if (!$tgt.is('input')) {
                        var $newLi = '<input onblur="update_minstock(this.value,\'' + $id + '\' )" type="text" name="' + $id + '" id="' + $id + '" value="' + $inner + '" size="4"/>';
                        this.innerHTML = $newLi;
                        //this.unbind("click");
                    }        
                });
                this.hasEventHander = true;
            }
        );
		$('.stockAttributesCellNote').each(
            function(){
                if(!this.hasEventHander)
                    $(this).click(function(event){    
					
					
                    /*/ Our Eventhanderl /*/    
                    var $tgt = $(event.target);
                    var $id = this.id;
                    var $inner = this.innerHTML;
                    if (!$tgt.is('input')) {
                        var $newLi = '<input onblur="update_note(this.value,\'' + $id + '\' )" type="text" name="' + $id + '" id="' + $id + '" value="' + $inner + '" size="10"/>';
                        this.innerHTML = $newLi;
                        //this.unbind("click");
                    }        
                });
                this.hasEventHander = true;
            }
        );
		$('.stockAttributesCellModel').each(
            function(){
                if(!this.hasEventHander)
                    $(this).click(function(event){    
					
					
                    /*/ Our Eventhanderl /*/    
                    var $tgt = $(event.target);
                    var $id = this.id;
                    var $inner = this.innerHTML;
                    if (!$tgt.is('input')) {
                        var $newLi = '<input onblur="update_model(this.value,\'' + $id + '\' )" type="text" name="' + $id + '" id="' + $id + '" value="' + $inner + '" size="10"/>';
                        this.innerHTML = $newLi;
                        //this.unbind("click");
                    }        
                });
                this.hasEventHander = true;
            }
        );
		
		
		
		
}
function saved(responseText, statusText)  { 
    alert('status: ' + statusText + '\n\nresponseText: \n' + responseText ); 
}

function update_supplier(stock_value, stock_id)
{
	if (window.ActiveXObject) 
      httpObject =  new ActiveXObject("Microsoft.XMLHTTP");
   else if (window.XMLHttpRequest) 
      httpObject =  new XMLHttpRequest();
   else {
      httpObject = null;
   }
   if (httpObject != null) {
		httpObject.open("GET", "update_supplier.php?id="+stock_id+"&supplier="+stock_value, true);

      httpObject.send(null);

      httpObject.onreadystatechange = function (){
		if(httpObject.readyState == 4){
				

		}
	  }
   }
}

function update_manufacturer(stock_value, stock_id)
{
	if (window.ActiveXObject) 
      httpObject =  new ActiveXObject("Microsoft.XMLHTTP");
   else if (window.XMLHttpRequest) 
      httpObject =  new XMLHttpRequest();
   else {
      httpObject = null;
   }
   if (httpObject != null) {
		httpObject.open("GET", "update_manufacturer.php?id="+stock_id+"&manufacturer="+stock_value, true);

      httpObject.send(null);

      httpObject.onreadystatechange = function (){
		if(httpObject.readyState == 4){
				

		}
	  }
   }
}


function update_name(stock_value, stock_id)
{
	if (window.ActiveXObject) 
      httpObject =  new ActiveXObject("Microsoft.XMLHTTP");
   else if (window.XMLHttpRequest) 
      httpObject =  new XMLHttpRequest();
   else {
      httpObject = null;
   }
   if (httpObject != null) {
		httpObject.open("GET", "update_name.php?id="+stock_id+"&name="+encodeURIComponent(stock_value), true);

      httpObject.send(null);

      httpObject.onreadystatechange = function (){
		if(httpObject.readyState == 4){
				

		}
	  }
   }
}

function update_mainmodel(stock_value, stock_id)
{
	if (window.ActiveXObject) 
      httpObject =  new ActiveXObject("Microsoft.XMLHTTP");
   else if (window.XMLHttpRequest) 
      httpObject =  new XMLHttpRequest();
   else {
      httpObject = null;
   }
   if (httpObject != null) {
		httpObject.open("GET", "update_mainmodel.php?id="+stock_id+"&model="+stock_value, true);

      httpObject.send(null);

      httpObject.onreadystatechange = function (){
		if(httpObject.readyState == 4){
				

		}
	  }
   }
}

function update_cost(stock_value, stock_id)
{
	if (window.ActiveXObject) 
      httpObject =  new ActiveXObject("Microsoft.XMLHTTP");
   else if (window.XMLHttpRequest) 
      httpObject =  new XMLHttpRequest();
   else {
      httpObject = null;
   }
   if (httpObject != null) {
		httpObject.open("GET", "update_cost.php?id="+stock_id+"&cost="+stock_value.replace("S$",""), true);

      httpObject.send(null);

      httpObject.onreadystatechange = function (){
		if(httpObject.readyState == 4){
				

		}
	  }
   }
}
function update_selling(stock_value, stock_id)
{
	if (window.ActiveXObject) 
      httpObject =  new ActiveXObject("Microsoft.XMLHTTP");
   else if (window.XMLHttpRequest) 
      httpObject =  new XMLHttpRequest();
   else {
      httpObject = null;
   }
   if (httpObject != null) {
		httpObject.open("GET", "update_selling.php?id="+stock_id+"&selling="+stock_value.replace("S$",""), true);

      httpObject.send(null);

      httpObject.onreadystatechange = function (){
		if(httpObject.readyState == 4){
				

		}
	  }
   }
}

function update_quantity(stock_value, stock_id)
{
	if (window.ActiveXObject) 
      httpObject =  new ActiveXObject("Microsoft.XMLHTTP");
   else if (window.XMLHttpRequest) 
      httpObject =  new XMLHttpRequest();
   else {
      httpObject = null;
   }
   if (httpObject != null) {
		httpObject.open("GET", "update_attribute.php?stock_attribute="+stock_id+"&stock_quantity="+stock_value, true);

      httpObject.send(null);

      httpObject.onreadystatechange = function (){
		if(httpObject.readyState == 4){
				

		}
	  }
   }
}

function update_location(stock_value, stock_id, obj)
{
	if (window.ActiveXObject) 
      httpObject =  new ActiveXObject("Microsoft.XMLHTTP");
   else if (window.XMLHttpRequest) 
      httpObject =  new XMLHttpRequest();
   else {
      httpObject = null;
   }
   if (httpObject != null) {
		httpObject.open("GET", "update_location.php?stock_attribute="+stock_id+"&stock_location="+stock_value, true);

      httpObject.send(null);

      httpObject.onreadystatechange = function (){
		if(httpObject.readyState == 4){
			obj.parentNode.innerHTML = stock_value;
		}
	  }
   }
}

function update_flag(stock_id, stock_value , obj,reload = false)
{
	if (window.ActiveXObject) 
      httpObject =  new ActiveXObject("Microsoft.XMLHTTP");
   else if (window.XMLHttpRequest) 
      httpObject =  new XMLHttpRequest();
   else {
      httpObject = null;
   }
   if (httpObject != null) {
		httpObject.open("GET", "update_flag.php?stock_attribute="+stock_id+"&action="+stock_value, true);

      httpObject.send(null);

      httpObject.onreadystatechange = function (){
		if(httpObject.readyState == 4){
		
			if(reload)
			{
				window.location.reload(1);
			}
			obj.style.backgroundColor = "grey";
		
		}
			
		}
   }
}


function update_quantityB1(stock_value, stock_id)
{
	if (window.ActiveXObject) 
      httpObject =  new ActiveXObject("Microsoft.XMLHTTP");
   else if (window.XMLHttpRequest) 
      httpObject =  new XMLHttpRequest();
   else {
      httpObject = null;
   }
   if (httpObject != null) {
	  httpObject.open("GET", "update_attributeB1.php?stock_attribute="+stock_id+"&stock_quantity="+stock_value, true);
      httpObject.send(null);
      httpObject.onreadystatechange = function (){
		if(httpObject.readyState == 4){
			//update done, check the total and update on the site
			//check if the other box is a input
			
			
			if(stock_id.indexOf("stockid") > -1) // this is an attribue update
			{
			
				if($('input[id='+stock_id.replace("B1", "B2")+']').length != 0)
				{
					$('.stockAttributesCellQuantity#'+stock_id.replace("B1", "")).html(Number(stock_value) + Number($('input[id='+stock_id.replace("B1", "B2")+']').val())); 
				}else
				{
					$('.stockAttributesCellQuantity#'+stock_id.replace("B1", "")).html(Number(stock_value) + Number($('#'+stock_id.replace("B1", "B2")).html())); 
				}
			}else{
				if($('input[id='+stock_id.replace("B1", "B2")+']').length != 0)
				{
					$('#'+stock_id.replace("B1", "")).html(Number(stock_value) + Number($('input[id='+stock_id.replace("B1", "B2")+']').val())); 
				}else
				{
					$('#'+stock_id.replace("B1", "")).html(Number(stock_value) + Number($('#'+stock_id.replace("B1", "B2")).html())); 
				}
			}
		}
	  }
   }
}

function update_quantityB2(stock_value, stock_id)
{
	if (window.ActiveXObject) 
      httpObject =  new ActiveXObject("Microsoft.XMLHTTP");
   else if (window.XMLHttpRequest) 
      httpObject =  new XMLHttpRequest();
   else {
      httpObject = null;
   }
   if (httpObject != null) {
		httpObject.open("GET", "update_attributeB2.php?stock_attribute="+stock_id+"&stock_quantity="+stock_value, true);

      httpObject.send(null);

      httpObject.onreadystatechange = function (){
		if(httpObject.readyState == 4){
			if(stock_id.indexOf("stockid") > -1) // this is an attribue update
			{
			
				if($('input[id='+stock_id.replace("B2", "B1")+']').length != 0)
				{
					$('.stockAttributesCellQuantity#'+stock_id.replace("B2", "")).html(Number(stock_value) + Number($('input[id='+stock_id.replace("B2", "B1")+']').val())); 
				}else
				{
					$('.stockAttributesCellQuantity#'+stock_id.replace("B2", "")).html(Number(stock_value) + Number($('#'+stock_id.replace("B2", "B1")).html())); 
				}
			}else{
				if($('input[id='+stock_id.replace("B2", "B1")+']').length != 0)
				{
					$('#'+stock_id.replace("B2", "")).html(Number(stock_value) + Number($('input[id='+stock_id.replace("B2", "B1")+']').val())); 
				}else
				{
					$('#'+stock_id.replace("B2", "")).html(Number(stock_value) + Number($('#'+stock_id.replace("B2", "B1")).html())); 
				}
			}
			
		}
	  }
   }
}

function update_barcode(stock_value, stock_id)
{
	if (window.ActiveXObject) 
      httpObject =  new ActiveXObject("Microsoft.XMLHTTP");
   else if (window.XMLHttpRequest) 
      httpObject =  new XMLHttpRequest();
   else {
      httpObject = null;
   }
   if (httpObject != null) {
		httpObject.open("GET", "update_barcode.php?id="+stock_id+"&barcode="+stock_value, true);

      httpObject.send(null);

      httpObject.onreadystatechange = function (){
		if(httpObject.readyState == 4){
				

		}
	  }
   }
}

function update_warrenty(stock_value, stock_id)
{
	if (window.ActiveXObject) 
      httpObject =  new ActiveXObject("Microsoft.XMLHTTP");
   else if (window.XMLHttpRequest) 
      httpObject =  new XMLHttpRequest();
   else {
      httpObject = null;
   }
   if (httpObject != null) {
		httpObject.open("GET", "update_warrenty.php?id="+stock_id+"&warrenty="+stock_value, true);

      httpObject.send(null);

      httpObject.onreadystatechange = function (){
		if(httpObject.readyState == 4){
				

		}
	  }
   }
}

function update_reorder(stock_value, stock_id)
{
	if (window.ActiveXObject) 
      httpObject =  new ActiveXObject("Microsoft.XMLHTTP");
   else if (window.XMLHttpRequest) 
      httpObject =  new XMLHttpRequest();
   else {
      httpObject = null;
   }
   if (httpObject != null) {
		httpObject.open("GET", "update_reorder.php?reorder="+stock_id+"&stock_quantity="+stock_value, true);

      httpObject.send(null);

      httpObject.onreadystatechange = function (){
		if(httpObject.readyState == 4){
				

		}
	  }
   }
}

function update_minstock(stock_value, stock_id)
{
	if (window.ActiveXObject) 
      httpObject =  new ActiveXObject("Microsoft.XMLHTTP");
   else if (window.XMLHttpRequest) 
      httpObject =  new XMLHttpRequest();
   else {
      httpObject = null;
   }
   if (httpObject != null) {
		httpObject.open("GET", "update_minstock.php?minstock="+stock_id+"&stock_quantity="+stock_value, true);

      httpObject.send(null);

      httpObject.onreadystatechange = function (){
		if(httpObject.readyState == 4){
				

		}
	  }
   }
}

function update_note(stock_value, stock_id)
{

	if (window.ActiveXObject) 
      httpObject =  new ActiveXObject("Microsoft.XMLHTTP");
   else if (window.XMLHttpRequest) 
      httpObject =  new XMLHttpRequest();
   else {
      httpObject = null;
   }
   if (httpObject != null) {
		httpObject.open("GET", "update_note.php?note="+stock_id+"&text="+stock_value, true);

      httpObject.send(null);

      httpObject.onreadystatechange = function (){
		if(httpObject.readyState == 4){
				

		}
	  }
   }
   
}

function update_model(stock_value, stock_id)
{

	if (window.ActiveXObject) 
      httpObject =  new ActiveXObject("Microsoft.XMLHTTP");
   else if (window.XMLHttpRequest) 
      httpObject =  new XMLHttpRequest();
   else {
      httpObject = null;
   }
   if (httpObject != null) {
	
		httpObject.open("GET", "update_model.php?model="+stock_id+"&name="+stock_value, true);

      httpObject.send(null);

      httpObject.onreadystatechange = function (){
		if(httpObject.readyState == 4){
				

		}
	  }
   }
}

function updatejslocation(obj,id,value)
{

	$(obj).parent().html('<input onblur="update_location(this.value,\'' + id + '\' ,this)" type="text" name="' + id + '" id="' + id + '" value="'+value+'" size="8"/>');
}

function updatejsquantity(obj,id,value)
{
	$(obj).parent().html('<input onblur="update_quantity(this.value,\'' + id + '\' ,this)" type="text" name="' + id + '" id="' + id + '" value="'+value+'" size="8"/>');
}




