function prepareCommit (){
	sasieToSubmit_zoneTxt ("idUsrNameSource","idUsrNameCommit");
	sasieToSubmit_zoneTxt ("idPwd1Source","idPwd1Commit");
	sasieToSubmit_zoneTxt ("idPwd2Source","idPwd2Commit");
	sasieToSubmit_zoneTxt ("idEmailSource","idEmailCommit");
	
	sasieToSubmit_zoneTxt ("idCodePostalSource","idCodePostalCommit");
	sasieToSubmit_zoneTxt ("idAnNaissanceSource","idAnNaissanceCommit");
	sasieToSubmit_zoneSexe ();	
	
	sasieToSubmit_zoneChkBx (nwsLtrSiteCodeArray,'infoSites','idInfoSitesCommit');
	sasieToSubmit_zoneChkBx (nwsLtrPartenaireCodeArray,'infoNwsLrtPartenaire','idNwsLrtPartenaireCommit');
	// les zones
	sasieToSubmit_zoneChkBx (nwsLtrZone1CodeArray,'zone1','idzone1Commit');
	// sasieToSubmit_zoneChkBx (nwsLtrZone2CodeArray,'zone2','idzone2Commit');
	// sasieToSubmit_zoneChkBx (nwsLtrZone3CodeArray,'zone3','idzone3Commit');
	// sasieToSubmit_zoneChkBx (nwsLtrZone4CodeArray,'zone4','idzone4Commit');

	sasieToSubmit_zoneSelect('idzone11Subscription', 'idzone11Commit');
	/*sasieToSubmit_zoneSelectUnique('idOccupationSource', 'idOccupationCommit');*/
	sasieToSubmit_zoneSelectUnique('idAbonJournalPapierSource', 'idAbonJournalPapierCommit');
	
	mergeFieldsCustomNwsLtrCode ();

}
function commitToServWeb (){
	prepareCommit ();
	document.forms['formCommit'].submit();
}

function mergeFieldsCustomNwsLtrCode (){
	var nlCustStringCommit = "";
	//var customNwsLtrCodeArray = new Array("idzone1Commit","idzone2Commit");
	// var customNwsLtrCodeArray = new Array("idzone1Commit", "idzone2Commit", "idzone3Commit", "idzone4Commit",'idzone11Commit');
	var customNwsLtrCodeArray = new Array("idzone1Commit", 'idzone11Commit');
	var arrayLength = customNwsLtrCodeArray.length;
	for (i=0; i< arrayLength ;i++) {
		var currentValue = document.getElementById(customNwsLtrCodeArray[i]).value;
		if (currentValue != ""){
			if (nlCustStringCommit != ""){
				nlCustStringCommit = nlCustStringCommit+"," + currentValue;
			}
			else {
				nlCustStringCommit = currentValue;
			}
		}
	}// FIN :: for (i=...
	document.getElementById("idNlCustCommit").value = nlCustStringCommit;
}

function removeFromSelect (idOfSelect,indexToRemove){
	var oSelect = document.getElementById(idOfSelect);
	oSelect.remove(indexToRemove);
}

function addToSelect (idOfSelectDestination,indexWhereToAdd,optionObj){
	var destinationElement = document.getElementById(idOfSelectDestination);
	destinationElement.options[indexWhereToAdd] = optionObj;
}

function swap (idOfSelectSource,idOfSelectDestination){
	var sourceElementSelectedIndex = getSelectedIndex (idOfSelectSource);
	if (sourceElementSelectedIndex > -1){
		var destinationElement = document.getElementById(idOfSelectDestination);
		var sourceElement = document.getElementById(idOfSelectSource);
		var destinationElementLength = destinationElement.length;
		var optionsValue = sourceElement.options[sourceElementSelectedIndex].value;
		var optionsText = sourceElement.options[sourceElementSelectedIndex].text;
		var newOption = new Option(optionsText,optionsValue);
		removeFromSelect (idOfSelectSource,sourceElementSelectedIndex);
		// FIXME :: use addToSelect (idOfSelectDestination,indexWhereToAdd,optionObj)
		// ca vaut la peine ???
		destinationElement.options[destinationElementLength] = newOption;
	}
}

function subscriptionAll (idOfSelectSource,idOfSelectDestination){
	var sourceElement = document.getElementById(idOfSelectSource);
	var sourceElementLength = sourceElement.length;
	for (var i = 0; i < sourceElementLength; i++) {
		var destinationElement = document.getElementById(idOfSelectDestination);
		var destinationElementLength = destinationElement.length;
		var optionsValue = sourceElement.options[i].value;
		var optionsText = sourceElement.options[i].text;
		var newOption = new Option(optionsText,optionsValue);
		destinationElement.options[destinationElementLength] = newOption;
	}
	flushSource (idOfSelectSource);
}

function flushSource (idOfSelectSource){
	var sourceElement = document.getElementById(idOfSelectSource);
	var sourceElementLength = sourceElement.length;
	for ( i = sourceElementLength -1 ; i > -1; i--) {
		sourceElement.remove(i);
	}
}

function getSelectedIndex (idOfSelect){
	var someElement = document.getElementById(idOfSelect);
	var someElementSelectedIndex = someElement.options.selectedIndex;
	return someElementSelectedIndex;
}

function sasieToSubmit_zoneSelect(idOfSelectDestination, idFieldCommit) {
	var destinationElement = document.getElementById(idOfSelectDestination);
	var destinationElementLength = destinationElement.length;
	// Construction d'une string a etre submitter
	var hiddenFieldValue = "";
	for (var i = 0; i < destinationElementLength; i++) {
		if (i == destinationElementLength - 1){
			hiddenFieldValue +=  optionsValue = destinationElement.options[i].value;
		}
		else{
			hiddenFieldValue +=  optionsValue = destinationElement.options[i].value +",";
		}
   	}
	document.getElementById(idFieldCommit).value = hiddenFieldValue;
}

function sasieToSubmit_zoneSelectUnique(idOfSelectSource, idFieldCommit) {
	var someElement = document.getElementById(idOfSelectSource);
	var someElementSelectedIndex = someElement.options.selectedIndex;
	var someElementValue = someElement.options[someElementSelectedIndex].value;
	document.getElementById(idFieldCommit).value = someElementValue;
}

function sasieToSubmit_zoneTxt (idTextSource,idTextCommit){
	var textSource = document.getElementById(idTextSource).value;
	document.getElementById(idTextCommit).value = textSource;
}

function sasieToSubmit_zoneChkBx (nwsLtrCodeArray,formName,idFieldCommit){
	var nwsLtrCodeStringCommit = "";
	var nwsLtrCodeArrayLength = nwsLtrCodeArray.length;
	for (i=0; i< nwsLtrCodeArrayLength ;i++) {
	  if (eval("document.forms."+formName+".chkBx_"+nwsLtrCodeArray[i]+".checked == true")){
			nwsLtrCodeStringCommit = nwsLtrCodeStringCommit + nwsLtrCodeArray[i]+",";
	  }
	}// FIN :: for (i=...
	// retirer le dernier . superflu
	var strLng = nwsLtrCodeStringCommit.length;
	if (strLng > 0){
		nwsLtrCodeStringCommit = nwsLtrCodeStringCommit.substr(0,strLng-1);
	}
	document.getElementById(idFieldCommit).value = nwsLtrCodeStringCommit;
}

function sasieToSubmit_zoneSexe (){
	var sexeFem = document.forms.formSexe.sexeSource[0];
	var sexeHom = document.forms.formSexe.sexeSource[1];
	
	if (sexeFem.checked==true){
		document.getElementById("idSexeCommit").value = sexeFem.value;
	}
	if (sexeHom.checked==true){
		document.getElementById("idSexeCommit").value = sexeHom.value;
	}
}

function cancelAndKickBackUlr (nextUrl){
	var answer = confirm("Quitter ?")
	if (answer){
		window.location = nextUrl;
	}
}
