

function update_support (id) {
	var allSpan = document.getElementById('option_support').getElementsByTagName('span');
	for ( var i=0; i<allSpan.length; i++) {
		allSpan[i].style.backgroundPosition = '0 0';
	}
	var parent = document.getElementById('option_support_' + id);
	parent.getElementsByTagName('input')[0].checked = true;
	parent.getElementsByTagName('span')[0].style.backgroundPosition = '0 -170px';
	update_price('support', id);
}


function update_format (id) {
	var allP = document.getElementById('option_format').getElementsByTagName('p');
	for ( var i=0; i<allP.length; i++) {
		allP[i].style.backgroundPosition = '0 -100px';
	}
	document.getElementById('format_' + id).style.backgroundPosition = '0 0';
	document.getElementById('input_format_' + id).checked = true;
	
	display_nbr_face();
	display_dimension();
	update_price('format', id);
	document.getElementById('alert_choix_format').style.display='none'
	return;	
}



function option_carte_perso(carte) {
	if ( carte.checked == true ) {
		update_price('carte_perso', carte.value );
	}
	else {
		update_price('carte_perso', 0 );
	}
	return;
}

function option_emballage(emballage) {
	if ( emballage.checked == true ) {
		update_price('emballage', emballage.value );
	}
	else {
		update_price('emballage', 0 );
	}
	return;
}




function option_promotion ( promotionID, codeClient ) {

	var xhr = getXhr();
	xhr.onreadystatechange = function(){
		if(xhr.readyState == 4 && xhr.status == 200){
		alert(xhr.responseText);
		}
	}
	xhr.open('POST', 'include/is_promo_valide.php', true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	
	xhr.send( 'promotionID=' + promotionID + '&codeClient=' + codeClient );
	
}














function  display_nbr_face () {
	if ( document.getElementById('option_nbr_faces') != null ) {
		var inputList = document.getElementById('option_format').getElementsByTagName('input');
		var sizeList = inputList.length;
		for (var i=0; i<sizeList; i++) {
					var formatID = inputList[i].value;
					var blocDimensions = document.getElementById('nbr_faces_format_' + formatID);
					blocDimensions.style.display = 'none';
					if ( inputList[i].checked ) blocDimensions.style.display = 'block';
		}
		return;
	}
}

function  display_dimension () {
	var inputList = document.getElementById('option_format').getElementsByTagName('input');
	var sizeList = inputList.length;
	for (var i=0; i<sizeList; i++) {
				var formatID = inputList[i].value;
				var blocDimensions = document.getElementById('dimension_format_' + formatID);
				blocDimensions.style.display = 'none';
				if ( inputList[i].checked ) blocDimensions.style.display = 'block';
	}
	return;
}

function add_color() {
	var couleur = document.getElementById('color_picker').value;
	var area = document.getElementById('commentaire');
	area.value =  "Couleur : " + couleur + "\n" + area.value;
}















function __update_format (id) {
	var allP = document.getElementById('option_format').getElementsByTagName('p');
	for ( var i=0; i<allP.length; i++) {
		allP[i].style.backgroundPosition = '0 -100px';
	}
	document.getElementById('format_' + id).style.backgroundPosition = '0 0';
	document.getElementById('input_format_' + id).checked = true;
	
	
	display_nbr_face();
	display_dimension();
	update_price('format', id);
	
	/* 
	var inputList = document.getElementById('option_format').getElementsByTagName('input');
	// Update des faces Warhol
	if ( document.getElementById('option_nbr_faces') != null ) {
		for (var i=0; i<inputList.length; i++) {
			var formatID = inputList[i].value;
			document.getElementById('nbr_faces_format_' + formatID).style.display = 'none';
		}
		document.getElementById('nbr_faces_format_' + id).style.display = 'block';
	}
	
	// Update des dimensions
	for (var i=0; i<inputList.length; i++) {
			var formatID = inputList[i].value;
			document.getElementById('dimension_format_' + formatID).style.display = 'none';
	}
	document.getElementById('dimension_format_' + id).style.display = 'block';
	
	 */
	
	
	return;	
}
	
