 //   jQuery.noConflict(); 
     	
// $() is a css selector. First I choose what triggers the event. In this case when 
// you CLICK on a LINK with the js-ajax CLASS. I changed the example to use the live()
// function so that any javascript-generated html will be binded too instead of click().
$('a.js-ajax').live('click', function() {

    url = $(this).attr('href');
  
	eltCible = $(this).parent();

	eltCible.html($("#ajaxLoader").html());
	
	var nbrCaractere = 25;
	var testUrl = "/commandes/modifier_quantite/";
	var testPresence = url.toLowerCase().indexOf(testUrl.toLowerCase());
	if( testPresence > -1)
  		{ 
		var tdNomFichier = eltCible.parent().parent().children('.nomFichier');
		var nomFichier = tdNomFichier.html();
		var longueur = nomFichier.length;
		if (  longueur > nbrCaractere && nomFichier.indexOf(' ') == -1) {
			var result='';
			nbreDeSeparation = Math.round(longueur/nbrCaractere);
			for(i=0;i<nbreDeSeparation+1;i++)
			{
			 result += nomFichier.substring(i*nbrCaractere, i*nbrCaractere+nbrCaractere) + "\n";	
				 	
			}
			tdNomFichier.text(result);
		
		}
	}
	else 
	{ 
	
	
	}
	 // Now we simply make the ajax call. load($url) will pull the url's VIEW and put it
	 // into ther innerhtml of whatever tag you called load on. In this case, I want to fill
	 // up my #overlayer div with the results of the ajax.	 
	 eltCible.load(
		
	     // Here is the tricky part. Instead of hard-coding a url to pass, I just had jquery
	     // go look at what the link (from the outside scope, .click() part) was already going
	     // to (href) and used that as the argument.
	     url
	 , function (data) {
	     // This is a callback, after the ajax gets loaded, the #overlayer div gets faded in at 300 miliseconds.	
		eltCible.jNice();
	 });
	 // And finally to prevent actually making the link go anywhere
	 return false;
});

$(document).ready(function() { 
	
	var options = { 
		   beforeSubmit:  beforeSubmitCallback, 
	       success:       successCallback  	    
	    }; 
	 // bind 'myForm' and provide a simple callback function 
    $('#FormImpressionfichier').ajaxForm(options); 
    return false;
}); 
function successCallback(responseText, statusText)
{	
	var aResultat = responseText.split("||");
	if(aResultat[1]=="echec"){
		$('#loadAjaxSubmit').hide();
		$('#FormImpressionfichier .submit').show();
	}
	$("#blocLeft").after(aResultat[0]);	
}

function beforeSubmitCallback(){	
	$("#flashMessage").remove();
	$('#FormImpressionfichier .submit').hide();
	$('#loadAjaxSubmit').show();
	
}

function moduleNonDisponnible()
{
	alert('module non disponible');
	
}


function changeSelect(url,id,div,divUpload,asynck) {
	if(asynck=="undefined")
		asynck=true;
		
	if( id != '') {	
		url=url+id;
		$heightAjax = $(div).offsetHeight;
		setTimeout( $.blockPage, 500);
		$(divUpload).css({opacity:'0'});
		$(div).animate({opacity: 0} , 1000 , "swing" , function(){			
			$(div).empty();
			$(divUpload).css({opacity:'0',display:'inline',height:$heightAjax});
			$(divUpload).animate({opacity: 100} , 1000 , "swing")
		} );
   if(div=="#optionFinition")
		$('.selecLeft').css('padding','10px 0px 0px 0px ');
		
	 if(div=="#optionFinition"){
		
		$('.selecLeft').css('padding','10px 0px 0px 0px ');	
		
		}
	$.ajax({
			//type: "POST",
			url: url,
			async: asynck,
			contentType: "application/x-www-form-urlencoded;charset=UTF-8",
			success: function(msg){
				$(div).empty();
				$(div).prepend(msg);
				$(div).jNice();
				$(div).css({opacity: 0} );
				 
				$(divUpload).animate({opacity: 0} ,1000 , "swing",function(){
					$(divUpload).css('display','none');
					if(div=="#listTypeImpression" || div=="#blocFinition" ){
						InitRadio();
					}
					
					
					$(div).css('display','inline');if(div=="#listTypeImpression"||div=="#premierPageCouleur") {
						$(div).css('display','block');
						$(div).css('float','left');
					}
					
					$(div).animate({opacity: 100} ,1000 , "swing",function(){
						
						
						orderDivIndex();
						$.unblockUI();
						
					})
				
				})
				
			}
			
		}); 

	}
}

	
function orderDivIndex() {
	var order = 5000; 
	$(".jNiceWrapper").each(function(){
		$(this).css("z-index",order);
		order -= 50;
	});
}

function is_bat_exists(url,div) {

		setTimeout( $.blockPage, 500);
		$heightAjax = $(div).offsetHeight;
		$.ajax({
			url: url,
			contentType: "application/x-www-form-urlencoded;charset=UTF-8",
	
			success: function(msg){
				
				$(div).empty();
				$(div).prepend(msg);
				$(div).jNice();
				$(div).css('display','inline');
			 }
		});
		
}

function valideLigneCommande(url, key) {

	$('#loadAjax_'+key).css('display','inline');
	$('#valid_BAT_'+key).css('display','none');
	
	$.ajax({
		
		url: url,
		contentType: "application/x-www-form-urlencoded;charset=UTF-8",

		success: function(msg){
			$('#valid_BAT_'+key).empty();
			$('#valid_BAT_'+key).prepend(msg);
			$('#valid_BAT_'+key).jNice();
			$('#loadAjax_'+key).css('display','none');
			$('#valid_BAT_'+key).css('display','inline');
		 }
	}); 
	
}

function updateQuantite(url, key) {

	$('#loadAjaxUpdate_'+key).css('display','inline');
	$('#image_update_'+key).css('display','none');
	
	$.ajax({
		
		url: url,
		contentType: "application/x-www-form-urlencoded;charset=UTF-8",

		success: function(msg){
			$('#image_update_'+key).empty();
			$('#image_update_'+key).prepend(msg);
			$('#loadAjaxUpdate_'+key).css('display','none');
			$('#image_update_'+key).css('display','inline');
		 }
	}); 
	
}

function updateQuantiteExec(url, iLignecommandeId, iNbrExemplaire) {
	
	$('#loadAjaxUpdate_'+iLignecommandeId).css('display','inline');
	$('#image_update_'+iLignecommandeId).css('display','none');
	
	$.ajax({
		url: url+iNbrExemplaire,
		contentType: "application/x-www-form-urlencoded;charset=UTF-8",
		success: function(msg){
			$('#image_update_'+iLignecommandeId).empty();
			$('#image_update_'+iLignecommandeId).prepend(msg);
			$('#loadAjaxUpdate_'+iLignecommandeId).css('display','none');
			$('#image_update_'+iLignecommandeId).css('display','inline');
		 }
	}); 
	
}

//** page business services **//
var zindex = 2005; 
var precedent = false
function loadFrame(id) {
	if(precedent) {
		$(precedent).slideToggle("slow");
		}
	linkFermer = '<a  onclick="javascript:precedent=false; $(\''+id+'\').slideToggle(\'slow\');" class="fermer">fermer la fenetre</a>';
	$(id).css({zIndex: zindex});
	$(id).prepend(linkFermer);
	$(id).slideToggle("slow");
	precedent = id;
	}