/* comparatif */

cpOptions = new Object;
cpOptions.p = [];
cpOptions.m = [];

function jsError() {
	document.location.href='/comparatif';
}

function jsDrop(wdiv) {
	blur();
	var ids = new Array('idPermis', 'idModele', 'idCons');
	ids.each( function(n) { $(n).hide(); } );
	Effect.SlideDown(wdiv, { duration: 0.5 });
}

function jsPermis(option) {

	var html = '';
	var thisId = 'idPermis';
	var textes = idPermisTextes;

	switch (option) {
		case 0:
			if ($(thisId+'0').checked === false)
				$(thisId+'0').checked = true;
			for (a=1; a<textes.length; a++)
				$(thisId+a).checked = false;
			break;
		case 1: case 2: case 3: case 4:
			if ($(thisId+'0').checked)
				$(thisId+'0').checked = false;
			break;
		case 'ok':
			cpOptions.permis = [];
			/* aucun */
			if ($(thisId+'0').checked) {
				cpOptions.p.push(0);
				html = textes[0];
			} else {
				var html2 = [];
				for (a=1; a<textes.length; a++)
					if ($(thisId+a).checked) { cpOptions.p.push(a); html2.push( textes[a] ); }
				html = html2.join(', ');
			}
			/* aucune selection */
			if (cpOptions.p.length==0) {
				html = textes[0];
			}
			$('res'+thisId).innerHTML = html;
			$(thisId).hide();
			jsCheck();
			break;
	}
}

function jsModele(option) {

	var html = '';
	var thisId = 'idModele';
	var textes = idModeleTextes;

	switch (option) {
		case 0:
			if ($(thisId+'0').checked === false)
				$(thisId+'0').checked = true;
			for (a=1; a<textes.length; a++)
					$(thisId+a).checked = false;
			break;
		case 1: case 2: case 3: case 4: case 5: case 6:
			if ($(thisId+'0').checked)
				$(thisId+'0').checked = false;
			break;
		case 'ok':
			cpOptions.m = [];
			if ($(thisId+'0').checked) {
				html = textes[0];
			} else {
				var html2 = [];
				for (a=1; a<textes.length; a++)
					if ($(thisId+a).checked) { cpOptions.m.push(a); html2.push( textes[a] ); }
				html = html2.join(', ');
			}
			$('res'+thisId).innerHTML = html;
			$(thisId).hide();
			jsCheck();
			break;
	}
}


function jsCons(option) {

	var html = '';
	var thisId = 'idCons';
	var textes = idConsTextes;

	switch (option) {
		case 0:
			if ($(thisId+'0').checked === false)
				$(thisId+'0').checked = true;
			for (a=1; a<textes.length; a++)
				$(thisId+a).checked = false;
			break;
		case 'ok':
			cpOptions.c = [];
			if ($(thisId+'0').checked) {
				html = textes[0];
			} else {
				var html2 = [];
				for (a=1; a<textes.length; a++)
					if ($(thisId+a).checked) { cpOptions.m.push(a); html2.push( textes[a] ); }
				html = html2.join(', ');
			}
			$('res'+thisId).innerHTML = html;
			$(thisId).hide();
			jsCheck();
	}

}

function jsCheck() {
	new Ajax.Updater('jsResult', '/comparatif/ajax/'+Base64.encode(Object.toJSON(cpOptions).split(' ').join('')) , 
		{ onComplete: function() { sorttable.init() } } );
}

