// (C)2008 addworks

function build_TabNbPagesFixeAvecCouv(ar_NbPagesFixe, nbPagesCouverture)
{
	var nbPagesInternes, nbPagesTotal;
	var TabNbPagesFixeAvecCouv = new Array();
	TabNbPagesFixeAvecCouv["value"] = new Array();
	TabNbPagesFixeAvecCouv["text"] = new Array();
	for (i = ar_NbPagesFixe.length - 1; i >= 0; i--) {
		nbPagesInternes = ar_NbPagesFixe[i];
		nbPagesTotal = (parseInt(nbPagesInternes, 10) + nbPagesCouverture).toString(10);
		TabNbPagesFixeAvecCouv["value"][i] = nbPagesInternes;
		TabNbPagesFixeAvecCouv["text"][i] = nbPagesTotal + ' (' + nbPagesInternes + ' intérieures + ' + nbPagesCouverture + ' de couverture)';
	}
	return TabNbPagesFixeAvecCouv;
}

function devis_display()
{
	// TYPE D'IMPRESSION
	var ar_x_ImpType          = new Array( 'numerique', 'offset' );
	var ar_x_ImpTypeNumerique = new Array( 'numerique'           );
	var ar_x_ImpTypeOffset    = new Array(              'offset' );

	// ORIGINAUX
	var ar_x_Originaux = new Array(
		'docpdf',
		'docword',
		'docxls',
		'docppt',
		'docpub',
		'docpshop',
		'docillus',
		'docindes',
		'docxps',
		'docautre');

	// FORMATS
	var ar_x_Format = new Array('a4fnc', 'a4fc', 'a5fnc', 'a5fc');

	// PAPIERS
	var ar_x_PapierStd = new Array(
		'i80g',
		'i100g',
		'ib100',
		'ib120',
		'icb135',
		'icm135',
		'i80c',
		'i120c',
		'ifluo');
	var ar_x_PapierCouv = new Array(
		'i80g',
		'i100g',
		'ib100',
		'ib120',
		'ib160',
		'ib200',
		'ib220',
		'ib250',
		'ib300',
		'icb135',
		'icb170',
		'icb200',
		'icb250',
		'icb300',
		'icm135',
		'icm170',
		'icm200',
		'icm250',
		'icm300',
		'ipp160',
		'ipp250',
		'i80c',
		'i120c',
		'i160c',
		'ifluo');
	var ar_x_PapierIriso 	= new Array('i80g','i100g','ib100','ib120','i80c','i120c');
	var ar_x_PapierCarton 	= new Array(
		'ipgc',
		'igc',
		'i160c',
		'ib250',
		'ib300',
		'icb250',
		'icb300',
		'icm250',
		'icm300');
	var ar_x_PapierOff       = new Array('icb135', 'ocdm135');
	var ar_x_PapierOffCouvB  = new Array('icb300');
	var ar_x_PapierOffCouvDM = new Array('ocdm300');

	// MODES
	var ar_x_Mode = new Array('rectoverso');
	
	// IMPRESSIONS
	var ar_x_ImpStd       = new Array('inb','ic','iriso');
	var ar_x_ImpCouvR     = new Array('inb','ic');
	var ar_x_ImpCouvRV    = new Array('inb','ic','imix');
	var ar_x_ImpCouvIriso = new Array('iriso');
	var ar_x_ImpOff       = new Array('oquadri');

	// COUVERTURES
	var ar_x_CdvCouverture    = new Array('c14','c1234');
	var ar_x_CdvNoCouverture  = new Array('aucune');
	var ar_x_CdvCouvertureOff = new Array('c1234');

	// FINITION
	var ar_x_NoFinition = new Array('inofini');
	var ar_x_Finition = new Array('ipa');
	var ar_x_FinitionOff = ar_x_NoFinition;
	var ar_x_FinitionOffAvecCouv = new Array('inofini','ocpb','ocpm');

	// NB DE PAGES INTERNES
	var ar_x_NbPagesFixe          = new Array(    '8','12','16','20','24','28','32','36','40','44','48','52','56','60');
	var ar_x_NbPagesFixeAvecCouv  = new Array('4','8','12','16','20','24','28','32','36','40','44','48','52','56'     );
	var ar_x_NbPagesFixeOff       = new Array(    '8','12','16','20','24',     '32');
	var TabNbPagesFixeAvecCouv    = build_TabNbPagesFixeAvecCouv(ar_x_NbPagesFixeAvecCouv, 4);
	var TabNbPagesFixeOffAvecCouv = build_TabNbPagesFixeAvecCouv(ar_x_NbPagesFixeOff,      4);

	// NB EXEMPLAIRES
	var ar_x_NbExemplairesFixeOff = new Array('100','200','300','400','500','1000','2000','3000','4000','5000','10000');

	// Initialisation des variables
	var theForm = document.forms['fdevis_impadd'];
	var nbExemplaires = theForm.elements['x_NbExemplaires'].value;
	var nbExemplairesFixe = theForm.elements['x_NbExemplairesFixe'].value;
	var impType = theForm.elements['x_ImpType'].value;
	var papier = theForm.elements['x_Papier'].value;
	var imp = theForm.elements['x_Impression'].value;
	var format = theForm.elements['x_Format'].value;
	var mode = theForm.elements['x_Mode'].value;
	var nbPages = parseInt(theForm.elements['x_NbPagesFixe'].value, 10);
	var nbPagesC = parseInt(theForm.elements['x_NbPagesCouleur'].value, 10);
	var typeCouv = theForm.elements['x_CouvertureDevant'].value;
	var impCouv = theForm.elements['x_CdvImpression'].value;
	var papierCouv = theForm.elements['x_CdvPapier'].value;

	// Initialistion des listes de choix
	if (impType == "offset" || nbExemplaires >= 90)
		my_updatecombo(theForm.elements['x_ImpType'], this.TabImpType, ar_x_ImpType);
	else
		my_updatecombo(theForm.elements['x_ImpType'], this.TabImpType, ar_x_ImpTypeNumerique);
	my_updatecombo(theForm.elements['x_Originaux'], this.TabOriginaux, ar_x_Originaux);
	my_updatecombo(theForm.elements['x_Mode'], this.TabMode, ar_x_Mode);
	my_updatecombo(theForm.elements['x_Format'], this.TabFormat, ar_x_Format);
	if (impType == "offset") {
		my_updatecombo(theForm.elements['x_Impression'], this.TabImpression, ar_x_ImpOff);
		my_updatecombo(theForm.elements['x_Papier'], this.TabPapier, ar_x_PapierOff);
		my_updatecombo(theForm.elements['x_NbExemplairesFixe'], this.TabNbExemplairesFixe, ar_x_NbExemplairesFixeOff);
		if (papier == "icb135")
			my_updatecombo(theForm.elements['x_CdvPapier'], this.TabPapier, ar_x_PapierOffCouvB);
		else
			my_updatecombo(theForm.elements['x_CdvPapier'], this.TabPapier, ar_x_PapierOffCouvDM);
		if (format == "a4fc" || format == "a5fc") {
			my_updatecombo(theForm.elements['x_CouvertureDevant'], this.TabCouverture, ar_x_CdvCouvertureOff);
			my_updatecombo(theForm.elements['x_CdvImpression'], this.TabImpression, ar_x_ImpOff);
			my_updatecombo(theForm.elements['x_NbPagesFixe'], TabNbPagesFixeOffAvecCouv, ar_x_NbPagesFixeOff);
			my_updatecombo(theForm.elements['x_Finition'], this.TabFinition, ar_x_FinitionOffAvecCouv);
		} else {
			my_updatecombo(theForm.elements['x_CouvertureDevant'], this.TabCouverture, ar_x_CdvNoCouverture);
			my_updatecombo(theForm.elements['x_NbPagesFixe'], this.TabNbPagesFixe, ar_x_NbPagesFixeOff);
			my_updatecombo(theForm.elements['x_Finition'], this.TabFinition, ar_x_FinitionOff);
		}
	} else {
		my_updatecombo(theForm.elements['x_Impression'], this.TabImpression, ar_x_ImpStd);
		if (imp != "" || papier != "")
			my_updatecombo(theForm.elements['x_Finition'], this.TabFinition, ar_x_Finition);
		else
			my_updatecombo(theForm.elements['x_Finition'], this.TabFinition, ar_x_NoFinition); // Retarder l'affichage du prix
		if (format == "a4fc" || format == "a5fc") {
			my_updatecombo(theForm.elements['x_NbPagesFixe'], TabNbPagesFixeAvecCouv, ar_x_NbPagesFixeAvecCouv);
			my_updatecombo(theForm.elements['x_CouvertureDevant'], this.TabCouverture, ar_x_CdvCouverture);
		} else {
			my_updatecombo(theForm.elements['x_NbPagesFixe'], this.TabNbPagesFixe, ar_x_NbPagesFixe);
			my_updatecombo(theForm.elements['x_CouvertureDevant'], this.TabCouverture, ar_x_CdvNoCouverture);
		}
		if (imp == "iriso") {
			my_updatecombo(theForm.elements['x_Papier'], this.TabPapier, ar_x_PapierIriso);
			my_updatecombo(theForm.elements['x_CdvPapier'], this.TabPapier, ar_x_PapierIriso);
			my_updatecombo(theForm.elements['x_CdvImpression'], this.TabImpression, ar_x_ImpCouvIriso);
		} else {
			my_updatecombo(theForm.elements['x_Papier'], this.TabPapier, ar_x_PapierStd);
			my_updatecombo(theForm.elements['x_CdvPapier'], this.TabPapier, ar_x_PapierCouv);
			if (typeCouv == "c14")
				my_updatecombo(theForm.elements['x_CdvImpression'], this.TabImpression, ar_x_ImpCouvR);
			else
				my_updatecombo(theForm.elements['x_CdvImpression'], this.TabImpression, ar_x_ImpCouvRV);
		}
	}

	// Initialisations des champs
	theForm.elements['x_NbPages'].value = nbPages.toString(10);
	if (typeCouv == "c14" || typeCouv == "c1234") { // Fusion des libelles des couvertures
		document.getElementById('l_CouvertureDevant').innerHTML = 'Couverture devant et derrière';
		document.getElementById('l_CdvImpression').innerHTML = 'Impression couv.';
		document.getElementById('l_CdvPapier').innerHTML = 'Papier couv.';
		document.getElementById('l_CdvCouleur').innerHTML = 'Couleur couv.';
	}
	if (imp == "icnb") {
		if (nbPagesC < 0 || nbPagesC > nbPages) {
			theForm.elements['x_NbPagesCouleur'].value = '0';
			alert("Nombre de Pages couleur doit etre <= au nombre de pages");
		}
		theForm.elements['x_NbPagesNB'].value = nbPages - nbPagesC;
	} else
		theForm.elements['x_NbPagesNB'].value = ''; /* RAZ */
	if (impType != "offset" && nbExemplaires <= 0)
		theForm.elements['x_ImpType'].value = '';

	// Enchainement
	var displayNext = true;
	if (impType == "offset")
		devisStep('NbExemplaires', 'clean', nbExemplairesFixe);
	else
		displayNext = devisStep('NbExemplaires', displayNext, '0');
	displayNext = devisStep('ImpType', displayNext);
	if (impType == "offset" || nbExemplaires >= 90)
		document.getElementById('ImpTypeAide').style.display = iif(displayNext, 'none', 'block');
	else
		document.getElementById('ImpTypeAide').style.display = 'none';
	displayNext = devisStep('Originaux', displayNext);
	displayNext = devisStep('Format', displayNext);
	displayNext = devisStep('NbPagesFixe', displayNext, '0');
	displayNext = devisStep('Mode', displayNext);
	displayNext = devisStep('Impression', displayNext);
	if (imp == "icnb")
		displayNext = devisStep('NbPagesCouleur', displayNext, '0');
	else
		devisStep('NbPagesCouleur', 'clean', '0');
	displayNext = devisStep('Papier', displayNext);
	if (papier == "i80c" || papier == "i120c" || papier == "i160c" || papier == "ifluo")
		displayNext = devisStep('Couleur', displayNext);
	else
		devisStep('Couleur', 'clean');
	if (format == "a4fc" || format == "a5fc") {
		displayNext = devisStep('CouvertureDevant', displayNext);
		displayNext = devisStep('CdvImpression', displayNext);
		displayNext = devisStep('CdvPapier', displayNext);
		if (papierCouv == "i80c" || papierCouv == "i120c" || papierCouv == "i160c" || papierCouv == "ifluo")
			displayNext = devisStep('CdvCouleur', displayNext);
		else
			devisStep('CdvCouleur', 'clean');
	} else {
		devisStep('CouvertureDevant', 'clean');
		devisStep('CdvImpression', 'clean');
		devisStep('CdvPapier', 'clean');
		devisStep('CdvCouleur', 'clean');
	}
	devisStep('CouvertureDerriere', 'clean');
	devisStep('CdrImpression', 'clean');
	devisStep('CdrPapier', 'clean');
	devisStep('CdrCouleur', 'clean');
	displayNext = devisStep('Finition', displayNext);
	if (impType == "offset") {
		displayNext = devisStep('NbExemplairesFixe', displayNext, '0');
		fdevis_finalise(displayNext, 'J+5');
	} else {
		devisStep('NbExemplairesFixe', 'clean');
		fdevis_finalise(displayNext);
	}
}


