var navigationOk = false;

jQuery(document).ready(function() { 
	navigationOk = true;
});

var id_bouton;

function submitEtape(etape_en_cours,etape_destination)
{
	if(!navigationOk)
	{
		jAlert('Veuillez attendre la fin de chargement de la page.');
		return;
	}
	
	//les controles sont faits dans le receiveFormulaire du produit
	
	if(etape_destination > etape_en_cours) id_bouton = "BOUTON_NEXT";
	else id_bouton = "BOUTON_BEFORE";
	
	document.getElementById('etape_en_cours').value=etape_en_cours;
	document.getElementById('etape_destination').value=etape_destination;
	jQuery('#myform').submit();
	//document.myform.submit();	
}



function submitContrat(type_contrat,numOnglet,numEtape)
{		
	if(!navigationOk)
	{
		jAlert('Veuillez attendre la fin de chargement de la page.');
		return;
	}
	
	id_bouton = "BOUTON_TARIF";
	
	document.getElementById('type_contrat').value=type_contrat;	
	document.getElementById('num_onglet').value=numOnglet;	
	document.getElementById('etape_en_cours').value=numEtape;
	document.getElementById('etape_destination').value="";
	
	//if (!document.getElementById('FRACTION_M').checked && !document.getElementById('FRACTION_A').checked) {
	//	alert("Veuillez sélectionner le fractionnement du paiement");
	//	return false;
	//} else {
	//	jQuery('#myform').submit();
	//}                            
	
	jQuery('#myform').submit();
	
	//document.myform.submit();	
}



// on va mettre le contenu html du bouton de navigation
var html_boutons = "";

// pre-submit callback 
function hiddenBouton()
{ 
	if(document.getElementById(id_bouton))
	{
	 html_boutons = document.getElementById(id_bouton).innerHTML;
	 document.getElementById(id_bouton).innerHTML='<img src="/Site/images/ajax-loader-cercle_noir.gif" class="nav">';
	}
	return true; 
} 

// post-submit callback 
/*
function showResponse(responseText, statusText)  { 
    // for normal html responses, the first argument to the success callback 
    // is the XMLHttpRequest object's responseText property 
 
    // if the ajaxSubmit method was passed an Options Object with the dataType 
    // property set to 'xml' then the first argument to the success callback 
    // is the XMLHttpRequest object's responseXML property 
 
    // if the ajaxSubmit method was passed an Options Object with the dataType 
    // property set to 'json' then the first argument to the success callback 
    // is the json data object returned by the server 
 
    alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
        '\n\nThe output div should have already been updated with the responseText.'); 
} 
*/
function processXml(responseXML) 
{ 
    // 'responseXML' is the XML document returned by the server; we use 
    // jQuery to extract the content of the message node from the XML doc 
		url_retour = gestionErreurXML(responseXML);
		
		
		if(url_retour=="")	
			document.getElementById(id_bouton).innerHTML=html_boutons;
		else
		{
			window.location.assign(url_retour);
		}
}	 


// lorsque qu'on submit le form via les bouton suivant/precedent
jQuery(document.myform).ready(function() { 
	    var options = { 
	        beforeSubmit:  hiddenBouton,    // pre-submit callback 
	        success:       processXml,      //showResponse,  // post-submit callback  
	        url:           'receiveFormulaire.php?AJAX=OUI',
	        type:          'post'
	    }; 
	    // bind form using 'ajaxForm' 
	    jQuery('#myform').ajaxForm(options); 	   	    
});


/*********************/
/*   RELOAD ETAPE    */
/*********************/

function reloadEtape(idBloc)
{	
	var codeForm    = jQuery("#CODE_NOM_FORM").val();
	var codeproduit = jQuery("#CODEPRODUIT").val();
	var myBloc; 
	
	if(idBloc!="ALL")	myBloc = "#MYBLOC_"+idBloc;
	else myBloc = "#BLOC_ETAPE";
		
	var hauteur = 	jQuery(myBloc).height();
	var largeur = 	jQuery(myBloc).width();
	
	var strData = jQuery("#myform").serialize();
	var strArrayData = jQuery("#myform").serializeArray();
	
	//alert(myBloc);
	
	jQuery(myBloc).before("<table id='DISABLED_ETAPE' style='height:"+hauteur+"px;width:"+largeur+"px'><tr><td><img src='/Site/images/ajax-loader-etape-circle_blanc.gif'></td></tr></table>");
	
	// on cache les select d'iE6
	if ( jQuery.browser.msie && jQuery.browser.version < 7 ) jQuery(myBloc+' select').css('visibility','hidden');
	
	jQuery(myBloc).load(
			"/Site/templates/reloadEtapeAjax.php?AJAX=OUI&idBloc="+idBloc,
		
			//{'codeForm':codeForm,'codeproduit':codeproduit,'idBloc':idBloc,'valObj':valObj} ,
			//'?codeForm='+codeForm+'&codeproduit='+codeproduit+'&idBloc='+idBloc+"&"+strData,
					
			strArrayData,
			
			function(){
				jQuery("#DISABLED_ETAPE").remove();
				//jQuery('select').css('visibility','show');
				//jQuery("#TESTOBJECT").load("/Site/templates/reloadTestObject.php?AJAX=OUI");
			}

	);
	
}

/*********************/
/* RELOAD TESTOBJECT */
/*********************/

function reloadTestObject()
{
	jQuery("#TESTOBJECT").html('loading');
	jQuery("#TESTOBJECT").load("/Site/templates/reloadTestObject.php?AJAX=OUI"
															,function(){jQuery.scrollTo(jQuery("#TESTOBJECT"),1000,{axis:"y"});	}
														);
	
	
	
}

/*********************/
/* RELOAD TRACE AUTO */
/*********************/

function reloadTraceAuto(idTrace)
{
	var trace = jQuery("#"+idTrace).val();
	
	jQuery("#RESULT_TRACE").html('loading');
	jQuery("#RESULT_TRACE").load("/Site/templates/reloadTraceAuto.php?AJAX=OUI&TRACE="+trace);
	
	
	
}
