



$(document).ready(function() 
{
	jQueryInit();
});



var jQueryInit = function()
{
	
     
	$('.jq_btn').button();
	
	$('.jq_btn_save').button({
		icons: {
			primary: 'ui-icon-disk'
		}
	});
	
	$('.jq_btn_check').button({
		icons: {
			primary: 'ui-icon-check'
		}
	});
	
	$('.jq_btn_document').button({
		icons: {
			primary: 'ui-icon-document'
		}
	});
	
	$('.jq_btn_back').button({
		icons: {
			primary: 'ui-icon-arrowreturnthick-1-w'
		}
	});
	
	$('.jq_btn_hide').button({
		icons: {
			primary: 'ui-icon-triangle-1-s'
		}
	});
	$('.jq_btn_show').button({
		icons: {
			primary: 'ui-icon-triangle-1-n'
		}
	});
	
	
	
	
};

var jqBtnMouseover = function(this0)
{
	this0.addClass('ui-state-hover');
	this0.removeClass('ui-state-default');
	return false;
}

var jqBtnMouseout = function(this0)
{
	this0.removeClass('ui-state-hover');
	this0.addClass('ui-state-default');
	return false;
}


var jqBtnMouseover2 = function(this0)
{
	this0.css( 'display', 'block');
	//this0.addClass('ui-state-hover');
	return false;
}

var jqBtnMouseout2 = function(this0)
{
	this0.css( 'display', 'none');
	//this0.removeClass('ui-state-hover');
	return false;
}


var onFocus = function(this0) 
{

	//document.getElementById('posfocusid').value = id;
	//if(document.getElementById('inh'+id).value == 0) {
	//document.getElementById('tr'+id).style.backgroundColor = '#efefef';
	//}
	this0.addClass('ui-state-active');
	this0.removeClass('ui-state-default');
	return false;
};


var onBlur = function(this0) 
{

	//document.getElementById('posfocusid').value = "";
	/*if(indice==0) {*/
	//if(document.getElementById('inh'+id).value == 0) {
	//document.getElementById('tr'+id).style.backgroundColor = '#ffffff';
	//}
	/*} else {
	document.getElementById('tr'+id).style.backgroundColor = '#D9F4FF';
	}*/
	this0.removeClass('ui-state-active');
	this0.addClass('ui-state-default');
	return false;
};



var popupinfo = function( top, ref )
{
	if(document.getElementById('loadingid')) 
	{
		document.getElementById('loadingid').style.display = 'block';
	}
	
	$.ajax({
		  url: '/src/php/__popupinfo.php',
		  type: "GET",
		  data: 'ref='+ref,
		  success: function(data) 
		  { 
			
			$('#popupinfo').css('top', (top-20)+'px');
			$('#popupinfo').show();
			$('#popupinfo').html(data);
			$('#popupinfoselector').css('top', Math.floor(top+205)+'px');
			$('#popupinfoselector').show();
			
			if(document.getElementById('loadingid')) 
			{
				document.getElementById('loadingid').style.display = 'none';
			}
					jQueryInit();
			
		  }});
};


var upQu = function(id_art, id_page, id_article, ref, quantite) {
	
	var Quantity, ID, Stocks, Oldvalue, QuantityTotal;
	
	if(document.getElementById('loadingid')) 
	{
		document.getElementById('loadingid').style.display = 'block';
	}
	

	$.ajax({
		  url: '/src/php/__upQu.php',
		  type: "GET",
		  data: 'id_art='+id_art+'&id_article='+id_article+'&ref='+ref+'&quantite='+quantite,
		  success: function(data) 
		  { 
			Quantity = $(data).find('quantite').text();
			ID = $(data).find('idarticle').text();
			Stocks = $(data).find('stocks').text();
			QuantityTotal = $(data).find('QuantityTotal').text();
			Oldvalue = $('#inh'+id_page+'_'+ID).val();
			Currentvalue = $('#in'+id_page+'_'+ID).val();
			
			if(Oldvalue!=Quantity)
			{
				$('.inh'+ID).each(function(){ $(this).val(Quantity); });
			}
			if(Quantity==Stocks)
			{
				$('.in'+ID).each(function(){ $(this).val(Stocks); });
				$('.inh'+ID).each(function(){ $(this).val(Stocks) });
			}
			$('.in'+ID).each(function(){
							  
								if($(this).val() != Currentvalue)
								{
									if(Quantity!=0)
									{
										$(this).val(Quantity);
									} else
									{
										$(this).val('');
									}
								}
							  
							  });
			
			if(QuantityTotal>0)
			{
				$('.in'+ID).parent().parent().parent().addClass('div_line_selected');
			} else
			{
				$('.in'+ID).parent().parent().parent().removeClass('div_line_selected');	
			}
			
			$.ajax({
				  url: '/src/php/__upCa.php',
				  type: "GET",
				  data: '',
				  success: function(data) 
				  { 
				  
				  	$('#div_cart').show();
				  	$('#div_cart').html(data);
				  	
					document.getElementById('loadingid').style.display = 'none';
					
					jQueryInit();
					
				  }});
			//$('#articleimagesdiv').html(data);
			//jQueryINIT();
			//document.getElementById("loading2").style.display = "none";

/*
	var idarticle = xhr.responseXML.getElementsByTagName("idarticle")[0].firstChild.nodeValue;
	var quantite = xhr.responseXML.getElementsByTagName("quantite")[0].firstChild.nodeValue;
	var stocks = xhr.responseXML.getElementsByTagName("stocks")[0].firstChild.nodeValue;
	
	document.getElementById('inh'+idarticle).value = quantite;
	if(quantite!=0) {
		//message = "<p>"+message+"</p>";
		//document.getElementById('inc'+idarticle).style.display = 'block';
		document.getElementById('tr'+idarticle).style.backgroundColor = '#66FFCC';
	} else {
		//document.getElementById('inc'+idarticle).style.display = 'none';
		if(document.getElementById('posfocusid').value==idarticle) {
			document.getElementById('tr'+idarticle).style.backgroundColor = '#efefef';
		} else {
			document.getElementById('tr'+idarticle).style.backgroundColor = '#ffffff';
		}
	}
	if(Number(stocks) < Number(document.getElementById('in'+idarticle).value)) {
		window.setTimeout('changeValueQuantity(\''+idarticle+'\', \''+stocks+'\');', 1000);
	}
	//document.getElementById('inc'+idarticle).innerHTML = message;
	//alert(idarticle+" "+quantite);
	//alert(xhr.responseText);
	//document.getElementById("contenu").innerHTML = xhr.responseText;
	//window.scrollTo(0, 0);
	//alert('ok !');
	
	
	
		//new Ajax_request('/src/php/upCa.php',{method:'get',params:'',onSuccess:successUpCa});
*/
		  }
		 });
		
	
};


var upQu2 = function(id_art, id_article, ref, quantite) {
	
	var Quantity, ID, Stocks, Oldvalue, QuantityTotal;
	
	if(document.getElementById('loadingid')) 
	{
		document.getElementById('loadingid').style.display = 'block';
	}

	$.ajax({
		  url: '/src/php/__upQu.php',
		  type: "GET",
		  data: 'id_art='+id_art+'&id_article='+id_article+'&ref='+ref+'&quantite='+quantite,
		  success: function(data) 
		  { 
		  
			Quantity = $(data).find('quantite').text();
			ID = $(data).find('idarticle').text();
			Stocks = $(data).find('stocks').text();
			QuantityTotal = $(data).find('QuantityTotal').text();
			Oldvalue = $('#inh'+ID).text();
			
			
			if(Quantity==0) Quantity = '';
			
			$('.in'+ID).val(Quantity);
			$('.inh'+ID).val(Quantity);
			if(QuantityTotal>0)
			{
				$('.in'+ID).parent().parent().parent().addClass('div_line_selected');
			} else
			{
				$('.in'+ID).parent().parent().parent().removeClass('div_line_selected');	
			}
					
					
					
			$.ajax({
				  url: '/src/php/__upCa.php',
				  type: "GET",
				  data: '',
				  success: function(data) 
				  { 
				  
				  	$('#div_cart').show();
				  	$('#div_cart').html(data);
				  	
					document.getElementById('loadingid').style.display = 'none';
					
					jQueryInit();
					
				  }});
			//$('#articleimagesdiv').html(data);
			//jQueryINIT();
			//document.getElementById("loading2").style.display = "none";

/*
	var idarticle = xhr.responseXML.getElementsByTagName("idarticle")[0].firstChild.nodeValue;
	var quantite = xhr.responseXML.getElementsByTagName("quantite")[0].firstChild.nodeValue;
	var stocks = xhr.responseXML.getElementsByTagName("stocks")[0].firstChild.nodeValue;
	
	document.getElementById('inh'+idarticle).value = quantite;
	if(quantite!=0) {
		//message = "<p>"+message+"</p>";
		//document.getElementById('inc'+idarticle).style.display = 'block';
		document.getElementById('tr'+idarticle).style.backgroundColor = '#66FFCC';
	} else {
		//document.getElementById('inc'+idarticle).style.display = 'none';
		if(document.getElementById('posfocusid').value==idarticle) {
			document.getElementById('tr'+idarticle).style.backgroundColor = '#efefef';
		} else {
			document.getElementById('tr'+idarticle).style.backgroundColor = '#ffffff';
		}
	}
	if(Number(stocks) < Number(document.getElementById('in'+idarticle).value)) {
		window.setTimeout('changeValueQuantity(\''+idarticle+'\', \''+stocks+'\');', 1000);
	}
	//document.getElementById('inc'+idarticle).innerHTML = message;
	//alert(idarticle+" "+quantite);
	//alert(xhr.responseText);
	//document.getElementById("contenu").innerHTML = xhr.responseText;
	//window.scrollTo(0, 0);
	//alert('ok !');
	
	
	
		//new Ajax_request('/src/php/upCa.php',{method:'get',params:'',onSuccess:successUpCa});
*/
		  }
		 });
		
	
};













var maskLoadingCursor = function() {
	document.getElementById('loadingid').style.display = 'none';	
};

function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}

function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}


var mouseMove = function (evt) { 
		var x=0; var y=0;
		if (document.layers) {
			x=evt.x; y=evt.y;
		} 
		if (document.all) {
			x=event.clientX; y=event.clientY;
		} else {
			if (document.getElementById) {
				x=evt.clientX; y=evt.clientY; 
			}
		}
		var scrollTop = f_scrollTop();
		
		document.getElementById('loadingid').style.left = Number(x + 10)+"px";
		document.getElementById('loadingid').style.top = Number(y + 10)+"px";
		
}; 


window.onload = function() {
if (document.layers) 
document.captureEvents(Event.MOUSEMOVE); 
if (document.layers || document.all) 
document.onmousemove = mouseMove; 
if (document.addEventListener) 
document.addEventListener('mousemove', mouseMove, true); 
}


