/************************** GALERIE AJAX ***************************/

// Lightbox
$(function()
{
	//$('#gallery a').lightBox({fixedNavigation:true});
	$('#img_store_banne a').lightBox({fixedNavigation:true});
	//$('#gallery3 a').lightBox({fixedNavigation:true});
});

$(document).ready(function(){
	var coloris_choose = $("#id_coloris").val();
	$('#zoom_on').bind('click',function(){
		imgLight('/images/stores_mesure/store_exterieur_mesure/background/g_'+coloris_choose+'.jpg');
	});
    calculPrix();

    // Popup choix de la toile :
    $.post('../sb_treatment.php',
        {'action': 'list_textile'},
        function(datas) {
            $('#button_textile_choice').bind('click', function() {
                lightBox2(datas.list_textile);

                $('#all_cats').bind('change', function() {
                    if($(this).attr('checked')) {
                        $('input[type="checkbox"][id^="textile_cat-"]').each(function() {
                            $(this).attr('checked', '');
                        });

                        $('div[id^="list_textile_cat-"]').each(function() {
                            $(this).show();
                        });

                        $('#need_cat').hide();
                    }
                    else {
                        $('div[id^="list_textile_cat-"]').each(function() {
                            $(this).hide();
                        });

                        $('#need_cat').show();
                    }
                });

                $('input[type="checkbox"][id^="textile_cat-"]').bind('change', function() {
                    if($(this).attr('checked')) {

                        if($('#all_cats').attr('checked')) {
                            $('#all_cats').attr('checked', '');
                            $(this).attr('checked', 'checked');
                            var catId=$(this).attr('id').split('-')[1];
                            $('div[id^="list_textile_cat-"]').each(function() {
                                if($(this).attr('id').split('-')[1]!=catId)
                                    $(this).hide();
                            });
                        }
                        else {
                            $('#list_textile_cat-'+$(this).attr('id').split('-')[1]).show();
                            $('#need_cat').hide();
                        }
                    }
                    else {
                        $('#list_textile_cat-'+$(this).attr('id').split('-')[1]).hide();

                        var catLeft=false;
                        $('input[type="checkbox"][id^="textile_cat-"]').each(function() {
                            if($('input[type="checkbox"][id^="textile_cat-'+$(this).attr('id').split('-')[1]+'"]').attr('checked'))
                                catLeft=true;
                        });

                        if(!catLeft)
                            $('#need_cat').show();
                    }
                });
            });
        },
        'json'
    );

    $('#bt_info_treuilSecour2').bind('click', function() {
        lightBox('<div class="tRight" style="margin-bottom: 3px; margin-top: 5px;margin-right: 5px;"><img src="/images/rideaux/picto/bt-fermer-pop-up-rideaux.png" alt="" /></div><div style="padding: 10px;"><strong>Treuil de secours</strong><br />Permet en cas de panne de courant de manoeuvrer manuellement votre store motoris&eacute;.<br /><strong>NOTE :</strong> Pour les motorisations SOMFY la pr&eacute;sence du treuil est syst&eacute;matique.</div>','280','140');
    }).bind('mouseout', function(){
        hideAideOn('bt_info_treuilSecour','2', '1', 'popupTreuilSecour');
    });

    $('#bt_info_motorOut2').bind('click', function() {
        lightBox('<div class="tRight" style="margin-bottom: 3px; margin-top: 5px; margin-right: 5px;"><img src="/images/rideaux/picto/bt-fermer-pop-up-rideaux.png" alt="" /></div><div style="padding :10px;"><strong>C&ocirc;t&eacute; de sortie de motorisation</strong><br />Choisissez le c&ocirc;t&eacute; de sortie du raccordement &eacute;lectrique de votre store banne. Le C&ocirc;t&eacute; de sortie est vu depuis l\'ext&eacute;rieur de l\'habitation.</div>','300','120');
    }).bind('mouseout', function(){
        hideAideOn('bt_info_motorOut','2', '1', 'popupCoteSortieMoteur');
    });
    
      $('.popupImgDroite').click(function(){
	 nomImg = $(this).attr('id');
	 content = '<img class="popupImg" src="/images/stores_mesure/store_exterieur_mesure/fiche_produit/popup/'+nomImg+'.jpg" width="550" height="450" alt="'+nomImg+'"/>';
	 $('#popupImgDroite').empty();
	 $('#popupImgDroite').append(content);
	 $('.appli_store').hide();
 
        new dialogBox({
             content: $('#popupImgDroite').html(),
             boxId:'DialogBox',
	     close_txt:'<img src="/images/rideaux/picto/bt-fermer-pop-up-rideaux.png" width="50" height="11" alt="fermer">',
	     callback:function(){
		 $('.appli_store').show();
	     }
       });
  });
});

function SwitchImg(path, m_img, g_img, p_img)
{
	document.getElementById("zoom1").src = path + m_img;
	document.getElementById("lienZoom").href = path + g_img;
	document.getElementById("mini_img_caddie").src = path + p_img;
}

function hidePopup(idDiv)
{
	$('#'+idDiv).hide();
}

function showPopup(idDiv)
{
	//alert("test");
	$('#'+idDiv).show();
}

function ChangeSt(valeur)
{
	RedirectLink(valeur);
}

function ChangeGal(liste_coloris,coloris_choose,path,liste_img)
{
	//alert(liste_coloris+' | '+coloris_choose+' | '+path+' | '+liste_img);
	TabImg=liste_img.split(',');
	//return_miniature='';
	// for(id in TabImg)
	// {
		// return_miniature+='<img class="imgmini" src="'+ path +'gallerie/'+ coloris_choose +'/p_'+ TabImg[id] +'" onclick="SwitchImg(\''+ path +'gallerie/\',\''+ coloris_choose +'/m_'+ TabImg[0] +'\',\''+ coloris_choose +'/g_'+ TabImg[0] +'\', \''+ coloris_choose +'/p_'+ TabImg[0] +'\')" style="cursor:pointer;" >';
	// }
	SwitchImg(path+'gallerie/'+coloris_choose+'/', 'm_'+TabImg[0], 'g_'+TabImg[0], 'p_'+TabImg[0]);
	//document.getElementById('miniatures').innerHTML=return_miniature;
}

function ChangeBackColoris(liste_coloris,coloris_choose,path, prix)
{
	TabColoris=liste_coloris.split(',');
	for(id in TabColoris)
	{
		document.getElementById('img_coloris_'+TabColoris[id]).src=path+'background/p_'+TabColoris[id]+'.jpg';
	}
	document.getElementById('img_coloris_'+coloris_choose).src=path+'background/p_'+coloris_choose+'.jpg';
	document.getElementById('coloris_choose').style.backgroundImage='url('+ path+'/background/p_'+ coloris_choose +'.jpg)';
	$('#nomColoris').html(coloris_choose);
	document.getElementById('prixCouleur').value = prix;
	coloris_back_gal = coloris_choose;
	$('#id_coloris').val(coloris_choose);
	$('#zoom_on').bind('click',function(){
		imgLight('/images/stores_mesure/store_exterieur_mesure/background/g_'+coloris_choose+'.jpg');
	});
	document.getElementById("id_coloris").value = coloris_choose;
	$('#feuilletColoris').hide();
	calculPrix();
}

function afficheSelectColoris()
{
	var obj;
	obj = document.getElementById('feuilletColoris').style;
	openLightBoxDevis($('#feuilletColoris').html());
	//obj.display="block";
}
function getPageSize()
{
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY)
	{
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight)
	{
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}
	else
	{
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight)
	{
		if(document.documentElement.clientWidth)
		{
			windowWidth = document.documentElement.clientWidth;
		}
		else
		{
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	if(yScroll < windowHeight)
	{
		pageHeight = windowHeight;
	}
	else
	{
		pageHeight = yScroll;
	}

	if(xScroll < windowWidth)
	{
		pageWidth = xScroll;
	}
	else
	{
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

function getPageScroll()
{
	var xScroll, yScroll;
	if (self.pageYOffset)
	{
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
	{
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	}
	else if (document.body)
	{
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;
	}
	arrayPageScroll = new Array(xScroll,yScroll)
	return arrayPageScroll;
}

var save_uniqid_use=new Array();
var aKeyCode=new Array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','1','2','3','4','5','6','7','8','9');
function uniqid()
{
	var verif=false;
	var final_id='';
	while(verif!=true)
	{
		verif=true;
		aKeyGenerate=new Array();

		for(i=0; i<=13; i++)
		{
			aKeyGenerate[i]=aKeyCode[Math.round(Math.random()*aKeyCode.length)];
		}
		final_id=aKeyGenerate.join('');

		for(id in save_uniqid_use)
		{
			if(save_uniqid_use[id]==final_id)
			{
				verif=false;
				break;
			}
		}
	}

	save_uniqid_use.push(final_id);
	return final_id;
}

function openLightBoxDevis(texte)
{
	id=uniqid();
	var arrPageSizes = getPageSize();
	var arrScroll=getPageScroll()

	$('body').append('<div onclick="closeLightBoxDevis(\''+ id +'\')" id="lightBoxShadow_'+ id +'" style="position:absolute;top:0px;left:0px;display:none;"></div><div onclick="closeLightBoxDevis(\''+ id +'\')" id="lightBox_'+ id +'" style="position:absolute; overflow:auto; height: 600px; width: 950px;background-color:#FFFFFF;color:#000000;">'+ texte +'</div>');

	var arrLightSizes = new Array($('#lightBox_'+id).width(),$('#lightBox_'+id).height());

	$('#lightBox_'+id).css({
	top :  parseInt((arrPageSizes[3]/2)-(arrLightSizes[1]/2),10)+arrScroll[1],
	left :parseInt((arrPageSizes[2]/2)-(arrLightSizes[0]/2),10)+arrScroll[0]
	}).show();

	$('#lightBoxShadow_'+id).css({
	height : arrPageSizes[1],
	width : arrPageSizes[0],
	backgroundColor: '#000000',
	opacity: 0.7,
	color : '#FFFFFF'}).fadeIn();/*

	$('#lightBox_'+id).toggle(0);
	$('#lightBox_'+id).toggle("slow");

	$('#lightBox_'+id).animate({
	color : '#000000'},500);*/

	/*
		$('#lightBox_'+ id).animate({'height': arrImageSizes[1]},500);
		$('#lightBox_'+ id).animate({'width': arrImageSizes[0]},500);
	*/
}


function closeLightBoxDevis(id)
{
	$('#lightBox_'+id).fadeOut().remove();
	$('#lightBoxShadow_'+id).remove();
}

function changeBordercolor(idImage, type, idStrImage, idTitleImage)
{
	if(type == 1)
	{
		//obj.bordercolor = "#ff0000";
		ChangeBorderColor(idImage,"#ff5d12");
		ChangeBorderColor(idStrImage,"#ff5d12");
		//idTitleImage
	}
	if(type == 2)
	{
		//obj.bordercolor = "#666666";
		ChangeBorderColor(idImage,"#666666");
		ChangeBorderColor(idStrImage,"#666666");
		//idTitleImage
	}
}

function changeFond(idDiv, colBack, colStr)
{
	obj = document.getElementById(idDiv).style;

	obj.background = colBack;
	obj.color = colStr;
}

function btZoomIn(type)
{
	obj01 = document.getElementById("zoom_off").style;
	obj02 = document.getElementById("zoom_on").style;
	if(type == 1)
	{
		obj01.display = "none";
		obj02.display = "block";
	}
	if(type == 2)
	{
		obj01.display = "block";
		obj02.display = "none";
	}
}

function makeZoomIn(idDiv, occDivOff, path)
{
	if(idDiv != "")
	{
		obj = document.getElementById(idDiv).style;
		if(occDivOff == "1")
		{
			nameColor = document.getElementById("id_coloris").value;
			img_resume = "g_"+nameColor+".jpg";
			url = path+"/background/"+img_resume;
			displayZoomCouleur = "";
			displayZoomCouleur = "<div style=\"background-color:#edeef0;width:796px; height:21px;\">";
			displayZoomCouleur = displayZoomCouleur + "<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">";
			displayZoomCouleur = displayZoomCouleur + "<tr><td width=\"10\" valign=\"middle\"></td>";
			displayZoomCouleur = displayZoomCouleur + "<td align=\"left\"><strong>"+nameColor+"</strong></td>";
			displayZoomCouleur = displayZoomCouleur + "<td align=\"right\"><img src=\"/images/volets_roulants/bt_fermer_popup.png\" onclick=\"makeZoomIn('zoomCouleur', 2, '', '');\" style=\"cursor:pointer;\" /></td>";
			displayZoomCouleur = displayZoomCouleur + "</tr></table></div><img src=\""+url+"\" style=\"cursor:pointer;\" onclick=\"makeZoomIn('zoomCouleur', 2, '', '');\" />";
			document.getElementById(idDiv).innerHTML = displayZoomCouleur;
			obj.display = "block";
		}
		else
		{
			obj.display = "none";
		}
	}
}

function restaureBackColoris() {
	//document.getElementById('zoom1').src='../images/volets_roulants/texture_volet/'+coloris_back_gal+'.png';
}

function btPanierIn()
{
	document.getElementById("btpanier1").src="/images/films/bt_ajout_panier_on.jpg";
}


function btPanierOut()
{
	document.getElementById("btpanier1").src="/images/films/bt_ajout_panier_off.jpg";
}
function ChangeQte(iDQte,ope)
{
	if(ope == "plus")
	{
		document.getElementById(iDQte).value++;
		$('#qtpopup').val(document.getElementById(iDQte).value);
	}
	else
	{
		if(document.getElementById(iDQte).value > 1)
		{
			document.getElementById(iDQte).value--;
			$('#qtpopup').val(document.getElementById(iDQte).value);
		}
	}
}

function changeMat(id_mat, path) {
	//alert("id_mat : "+id_mat);
	$.post('/ajax/store_ext_mesure.php', {action:'reloadTxt',idmat:id_mat}, function(response, status, xhr){
            if(status == 'success')
            {
                $('#store_exterieur_mesure').html(response.descriptif);
            }
        },'json');
	listMat = AjaxRequest('/ajax/ajax_function.php', 'action=change_ex_store&id_mat='+id_mat+'&path='+path);
	if(listMat) {
		tabListMat = listMat.split('|');
		//document.getElementById("colorisGal").innerHTML = tabListMat[0];
		//alert("tabListMat[0] : "+tabListMat[0]);
		document.getElementById('img_store_banne').innerHTML = tabListMat[1];
		//alert("tabListMat[1] : "+tabListMat[1]);
		document.getElementById('td_avancee').innerHTML = tabListMat[2];
		//alert("tabListMat[2] : "+tabListMat[2]);
		document.getElementById('id_td_commType').innerHTML = tabListMat[3];
		//alert("tabListMat[3] : "+tabListMat[3]);
		document.getElementById('zoomImg').innerHTML = tabListMat[4];
		//alert("tabListMat[4] : "+tabListMat[4]);
		document.getElementById('id_aff_colMeca1').innerHTML = tabListMat[5];
		//alert("tabListMat[5] : "+tabListMat[5]);
		document.getElementById('id_aff_Lambrequin').innerHTML = tabListMat[6];
		//alert("tabListMat[5] : "+tabListMat[5]);
		MinMaxW = document.getElementById('id_avancee').value;
		tabMinMaxW = MinMaxW.split('_')


		document.getElementById('id_min_store_width').value = parseInt(tabMinMaxW[1])*10;
		document.getElementById('id_max_store_width').value = parseInt(tabMinMaxW[2])*10;
		document.getElementById('mini_img_caddie').src = '/images/stores_mesure/store_exterieur_mesure/panier/exterieur_'+id_mat+'.jpg';
		//'../images/stores_mesure/store_exterieur_mesure/panier/exterieur_'++'.jpg';
		var valLargStore;
		valLargStore = document.getElementById("id_volet_width").value;
		//alert("valLargStore : "+valLargStore);
		if(valLargStore != "" && isNaN(parseInt(valLargStore, 10)))
		{
			checkWidth(parseInt(valLargStore, 10));
			/*
			if(parseInt(valLargStore, 10) < parseInt(tabMinMaxW[1], 10)  || parseInt(valLargStore, 10) > parseInt(tabMinMaxW[2], 10))
			{
				alert("valeur de largeur trop grande");
				document.getElementById("id_volet_width").value = "";
			}
			*/
		}
		$('#motorOutmain01').show();
		$('#motorOut_title').hide();
		$('#motorOut_help').hide();
		$('#motorOutmain02').hide();

		$('#treuilSecourMain01').show();
		$('#treuilSecour_title').hide();
		$('#treuilSecour_help').hide();
		$('#treuilSecourMain02').hide();

		$('#anemometreMain01').show();
		$('#anemometre_title').hide();
		$('#anemometre_help').hide();
		$('#anemometreMain02').hide();

		checkWidth(document.getElementById('id_volet_width').value);

		calculPrix();
	}
}

function calculCoffre(height, id_mat) {
	mat = document.getElementById(id_mat).value;
	tailleCoffre = AjaxRequest('/ajax/ajax_function.php', 'action=calcul_taille_coffre&height='+height+'&mat='+mat);
	if(tailleCoffre != 0) {
		document.getElementById("id_ht_coffre").innerHTML = '( Hauteur du coffre : '+tailleCoffre+' mm )';
		document.getElementById("id_ht_coffre").style.color = '#FF4E00';
		document.getElementById("id_ht_coffre").style.textAlign = 'center';
		document.getElementById("id_ht_coffre").style.backgroundColor = '';
		//document.getElementById("id_ht_coffre").style.display = 'block';
	} else {
		document.getElementById('id_volet_height').value='';
		document.getElementById('id_volet_height').style.backgroundColor="#FFA0A0";
		document.getElementById("id_ht_coffre").innerHTML = '<b>Hauteur : </b>Mini 600 mm - Maxi 3500 mm';
		document.getElementById("id_ht_coffre").style.color = '#515151';
		document.getElementById("id_ht_coffre").style.textAlign = 'center';
		document.getElementById("id_ht_coffre").style.backgroundColor = '#FFA0A0';
		//document.getElementById("id_ht_coffre").style.display = 'block';
	}
	//$('#id_ht_coffre').hide();
	$('#id_ht_coffre').fadeIn('slow');
}

function changeAvancee(idChamps)
{
	var strValue;
	strValue = document.getElementById(idChamps).value;
	MinMaxW = document.getElementById('id_avancee').value;
	tabMinMaxW = MinMaxW.split('_')

	document.getElementById('id_valAvancee').value = parseInt(tabMinMaxW[0])*10;
	document.getElementById('id_min_store_width').value = parseInt(tabMinMaxW[1])*10;
	document.getElementById('id_max_store_width').value = parseInt(tabMinMaxW[2])*10;

	var valLargStore;
	valLargStore = document.getElementById("id_volet_width").value;

	if(valLargStore != "" && isNaN(parseInt(valLargStore, 10)))
	{
		if(parseInt(valLargStore, 10) < parseInt(tabMinMaxW[1], 10)  || parseInt(valLargStore, 10) > parseInt(tabMinMaxW[2], 10))
		{
			checkWidth(parseInt(valLargStore, 10));
		}
	}
}

function displayTest(valTest)
{
	//alert("valTest : "+valTest);
	apparo = valTest;
}

function displayMotor(type, id_store) {
	//alert("dusplayMotor type : "+type);
	if(type == '2' || type == '3' || type == '5' || type == '6' || type == '8' || type == '9'
		|| type == '10' || type == '11' || type == '12')
	{
		//$('#motorOutmain01').hide();
		$('#motorOut_title').show();
		$('#motorOut_help').show();
		$('#motorOutmain02').show();

		$('#coteManoeuvre_title').hide();
		$('#coteManoeuvre_help').hide();
		$('#coteManoeuvre02').hide();

		//$('#treuilSecourMain01').hide();
		$('#treuilSecour_title').show();
		$('#treuilSecour_help').show();
		$('#treuilSecourMain02').show();
		if(type == '3' || type == '6' || type == '9'
			|| type == '10' || type == '11' || type == '12' )
		{
			//$('#anemometreMain01').hide();
			$('#anemometre_title').show();
			$('#anemometre_help').show();
			$('#anemometreMain02').show();
		}else{
			$('#anemometre_title').hide();
			$('#anemometre_help').hide();
			$('#anemometreMain02').hide();
		}
	}else{
		//$('#motorOutmain01').show();
		$('#motorOut_title').hide();
		$('#motorOut_help').hide();
		$('#motorOutmain02').hide();

		$('#coteManoeuvre_title').show();
		$('#coteManoeuvre_help').show();
		$('#coteManoeuvre02').show();

		//$('#treuilSecourMain01').show();
		$('#treuilSecour_title').hide();
		$('#treuilSecour_help').hide();
		$('#treuilSecourMain02').hide();

		//$('#anemometreMain01').show();
		$('#anemometre_title').hide();
		$('#anemometre_help').hide();
		$('#anemometreMain02').hide();
	}

	if(type==11 || type==10 || type==12){
		$("#id_treuilSecour").val('yes');
		$("#id_treuilSecour").attr('disabled',true);
	}else{
		$("#id_treuilSecour").val('empty');
		$("#id_treuilSecour").attr('disabled',false);
	}
}

function displayVerrou(valid) {
	if(valid == 'yes') {
		$('#verrou_pose').fadeIn('slow');
		$('#verrou_title').fadeIn('slow');
	} else {
		$('#verrou_pose').fadeOut('fast');
		$('#verrou_title').fadeOut('fast');
	}
}

function checkWidth(width)
{
	widthMin = document.getElementById('id_min_store_width').value;
	widthMax = document.getElementById('id_max_store_width').value;
	if(width >= parseInt(widthMin, 10) && width <= parseInt(widthMax, 10))
	{
		document.getElementById("width_volet").style.display = 'none';
	}
	else
	{
		/*document.getElementById("width_volet").style.display = 'block';
		$('#width_volet').hide();*/
		$('#width_volet').fadeIn('slow');
		document.getElementById('id_volet_width').style.backgroundColor="#FFA0A0";
		document.getElementById('id_volet_width').value='';
		document.getElementById("width_volet").innerHTML = "<b>Largeur :</b>  Mini "+parseInt(widthMin)+" mm - Maxi "+parseInt(widthMax)+" mm";
	}

	// Alerte si store sup a 300
	if(width > 3000) {
		lightBox('<img src="/images/stores_exterieurs/aide-transporteur-store-banne-exterieur.png"  />');
	}
}

function onFocusWidth() {
	//document.getElementById('zoom1').src = '/images/volets_roulants/dessin_volet_roulant_largeur.png';
	//document.getElementById('lienZoom').href = '/images/volets_roulants/volet-roulant-popup-largeur.png';
}

function onFocusHeight() {
	//document.getElementById('zoom1').src = '/images/volets_roulants/dessin_volet_roulant_hauteur.png';
	//document.getElementById('lienZoom').href = '/images/volets_roulants/volet-roulant-popup-hauteur.png';
}

function calculPrix() {
	//Formule de calcul : (L x H) x Tarif couleur + option 1 + option 2 + etc
	// Recuperation des valeurs document.getElementById('id_valAvancee').value
	id_matter = $('#id_matiere').val();
	id_matter = parseFloat(id_matter);

	avancerr = $('#id_valAvancee').val();
	avancerr = parseFloat(avancerr);

	height = avancerr;

	width = $('#id_volet_width').val();
	width = parseFloat(width);

	color = $('#prixCouleur').val();
	color = parseFloat(color);

	quantite = $('#qtBT').val();
	quantite = parseFloat(quantite);

	commande = $('#id_commType').val();

	fixationie = $('#id_fixation').val();

	if(commande != 'empty') {
		prixCommande = AjaxRequest('/ajax/ajax_function.php', 'action=get_prix_manoeuvre&id_comm='+commande);
		prixCommande = parseFloat(prixCommande);
	} else {
		prixCommande = parseFloat(0);
	}

	if(commande != "1" && commande != "4" && commande != "7" && commande != 'empty')
	{
		idtreuilSecour = $('#id_treuilSecour').val();
		if(idtreuilSecour == 'yes') {
			if(commande == '10' || commande == '11' || commande == '12' ) {
				idprixTreuil = parseFloat(20.40);
			} else {
				idprixTreuil = AjaxRequest('/ajax/ajax_function.php', 'action=get_prix_treuil&id_matter='+id_matter+'&id_comm='+commande);
				idprixTreuil = parseFloat(idprixTreuil);
			}

		} else {
			idprixTreuil = parseFloat(0);
		}

		if(commande != "2" && commande != "5" && commande != "8") {
			idanemometre = $('#id_anemometre').val();
			if(idanemometre != 'no' && idanemometre != 'empty') {
				idprixAnemometre = $('#id_prixAnemometre').val();
				idprixAnemometre = parseFloat(idprixAnemometre);
			} else {
				idprixAnemometre = parseFloat(0);
			}
		} else {
			idprixAnemometre = parseFloat(0);
		}
	}
	else
	{
		idprixTreuil = parseFloat(0);
		idprixAnemometre = parseFloat(0);
	}

	if(fixationie != 'murale' && fixationie != 'empty')
	{
		if(id_matter == 9)
		{
			if(fixationie == 'plafond')
			{
				if( (width >= parseFloat(2450)) && (width <= parseFloat(3500)) )
				{
						prixFixation = parseFloat(25);
				}
				if( (width >= parseFloat(3501)) && (width <= parseFloat(4700)) )
				{
						prixFixation = parseFloat(38);
				}
				if( (width >= parseFloat(4701)) && (width <= parseFloat(5900)) )
				{
						prixFixation = parseFloat(51);
				}
				if( (width >= parseFloat(5901)) && (width <= parseFloat(7000)) )
				{
						prixFixation = parseFloat(64);
				}
			}
			if(fixationie == 'sous-toiture')
			{
				if( (width >= parseFloat(2450)) && (width <= parseFloat(3500)) )
				{
						prixFixation = parseFloat(51);
				}
				if( (width >= parseFloat(3501)) && (width <= parseFloat(4700)) )
				{
						prixFixation = parseFloat(76);
				}
				if( (width >= parseFloat(4701)) && (width <= parseFloat(5900)) )
				{
						prixFixation = parseFloat(101);
				}
				if( (width >= parseFloat(5901)) && (width <= parseFloat(7000)) )
				{
						prixFixation = parseFloat(132);
				}
			}
		}

		if(id_matter == 10)
		{
			if(fixationie == 'plafond')
			{
				if( (width >= parseFloat(2600)) && (width <= parseFloat(3500)) )
				{
						prixFixation = parseFloat(25);
				}
				if( (width >= parseFloat(3501)) && (width <= parseFloat(4700)) )
				{
						prixFixation = parseFloat(38);
				}
				if( (width >= parseFloat(4701)) && (width <= parseFloat(5900)) )
				{
						prixFixation = parseFloat(51);
				}
				if( (width >= parseFloat(5901)) && (width <= parseFloat(7000)) )
				{
						prixFixation = parseFloat(64);
				}
			}
			if(fixationie == 'sous-toiture')
			{
				if( (width >= parseFloat(2600)) && (width <= parseFloat(3500)) )
				{
						prixFixation = parseFloat(51);
				}
				if( (width >= parseFloat(3510)) && (width <= parseFloat(4700)) )
				{
						prixFixation = parseFloat(76);
				}
				if( (width >= parseFloat(4710)) && (width <= parseFloat(5900)) )
				{
						prixFixation = parseFloat(101);
				}
				if( (width >= parseFloat(5910)) && (width <= parseFloat(7000)) )
				{
						prixFixation = parseFloat(132);
				}
			}
		}

		if(id_matter == 11)
		{
			if(fixationie == 'plafond')
			{
				if( (width >= parseFloat(2600)) && (width <= parseFloat(4100)) )
				{
						prixFixation = parseFloat(25);
				}
				if( (width >= parseFloat(4101)) && (width <= parseFloat(6000)) )
				{
						prixFixation = parseFloat(38);
				}
			}
			if(fixationie == 'sous-toiture')
			{
				if( (width >= parseFloat(2600)) && (width <= parseFloat(4100)) )
				{
						prixFixation = parseFloat(51);
				}
				if( (width >= parseFloat(4101)) && (width <= parseFloat(6000)) )
				{
						prixFixation = parseFloat(76);
				}
			}
		}
		/**/
	}
	else
	{
		prixFixation = parseFloat(0);
	}

	//alert("width : "+width+", color : "+color+"\navancee : "+avancee+", height : "+height+"\nquantite : "+quantite+", prixCommande : "+prixCommande+"\nidprixTreuil : "+idprixTreuil+", prixFixation : "+prixFixation+"\n");

	totalHT = 0;
	totalTTC = 0;

	// Calcul des prix
	if(!isNaN(parseFloat(height)) && height > 0
			&& !isNaN(parseFloat(width)) && width > 0
			&& !isNaN(parseFloat(color)) && color >= 0
			&& !isNaN(parseFloat(quantite)) && quantite >= 0) {

		// Setage d'une superficie minimale pour le prix.
		//Monobloc
		if(id_matter == 9 ) {
			prixsuperficie = getPrixSuperficieMonoBloc(avancerr, width);
		} else if (id_matter == 10) {
			prixsuperficie = getPrixSuperficieSemiCoffre(avancerr, width);
		} else if (id_matter == 11) {
			prixsuperficie = getPrixSuperficieCoffre(avancerr, width);
		}

		totaluHT = Math.round((prixsuperficie + idprixTreuil + idprixAnemometre + prixCommande + prixFixation) * 100) / 100;
		//prixpromHT = Math.round(totaluHT *0.75 * 100) / 100;
		prixpromHT = totaluHT;
		totalHT = Math.round(prixpromHT * quantite * 100) / 100;
		totalTTC = Math.round(totalHT * (119.6/100) * 100) / 100;
		$('#prixuHT').html(totaluHT+' \u20ac');
		//document.getElementById('titleuHT').style.textDecoration = 'line-through';
		//document.getElementById('prixuHT').style.textDecoration = 'line-through';
		//$('#prixuHT').style('text-decoration: overline');
		$('#prixpromoHT').html(prixpromHT+' \u20ac');
		//$('#titlepromoHT').fadeIn('slow');
		//$('#prixpromoHT').fadeIn('slow');
		$('#prixttHT').html(totalHT+' \u20ac');
		$('#prixttTTC').html(totalTTC+' \u20ac');
	} else if(isNaN(quantite)) {
		$('#prixttHT').html(totalHT+'0 \u20ac');
		$('#prixttTTC').html(totalTTC+'0 \u20ac');
		//$('#titlepromoHT').fadeOut('fast');
		//$('#prixpromoHT').fadeOut('fast');
	} else {
		$('#prixttHT').html(totalHT+'0 \u20ac');
		$('#prixttTTC').html(totalTTC+'0 \u20ac');
		//$('#titlepromoHT').fadeOut('fast');
		//$('#prixpromoHT').fadeOut('fast');
	}
}

function getPrixSuperficieCoffre(avancee, width) {
	var prixsuperficie = parseFloat('0');
	if(avancee == 2100) {
		if((width >= 2600) && (width < 2900)) {
			prixsuperficie = parseFloat('1099.25');
		} else if((width >= 2900) && (width < 3500)) {
			prixsuperficie = parseFloat('1188.18');
		} else if((width >= 3500) && (width < 4100)) {
			prixsuperficie = parseFloat('1331.02');
		} else if((width >= 4100) && (width < 4700)) {
			prixsuperficie = parseFloat('1541.03');
		} else if((width >= 4700) && (width < 5300)) {
			prixsuperficie = parseFloat('1683,88');
		} else if((width >= 5300) && (width <= 6000)) {
			prixsuperficie = parseFloat('1957.27');
		}
	} else if(avancee == 2600) {
		if((width >= 2900) && (width < 3500)) {
			prixsuperficie = parseFloat('1242.10');
		} else if((width >= 3500) && (width < 4100)) {
			prixsuperficie = parseFloat('1394.40');
		} else if((width >= 4100) && (width < 4700)) {
			prixsuperficie = parseFloat('1604.42');
		} else if((width >= 4700) && (width < 5300)) {
			prixsuperficie = parseFloat('1756.72');
		} else if((width >= 5300) && (width <= 6000)) {
			prixsuperficie = parseFloat('2030.12');
		}
	} else if(avancee == 3100) {
		if((width >= 2900) && (width < 3500)) {
			prixsuperficie = parseFloat('1372.65');
		} else if((width >= 3500) && (width < 4100)) {
			prixsuperficie = parseFloat('1533.47');
		} else if((width >= 4100) && (width < 4700)) {
			prixsuperficie = parseFloat('1743.48');
		} else if((width >= 4700) && (width < 5300)) {
			prixsuperficie = parseFloat('1905.24');
		} else if((width >= 5300) && (width <= 6000)) {
			prixsuperficie = parseFloat('1993.22');
		}
	} else if(avancee == 3600) {
		if((width >= 3500) && (width < 4100)) {
			prixsuperficie = parseFloat('1629.01');
		} else if((width >= 4100) && (width < 4700)) {
			prixsuperficie = parseFloat('1839.02');
		} else if((width >= 4700) && (width < 5300)) {
			prixsuperficie = parseFloat('2009.30');
		} else if((width >= 5300) && (width <= 6000)) {
			prixsuperficie = parseFloat('2098.23');
		}
	}

	return prixsuperficie;
}


function getPrixSuperficieSemiCoffre(avancee, width) {
	var prixsuperficie = parseFloat('0');
	if(avancee == 2100) {
		if((width >= 2600) && (width < 2900)) {
			prixsuperficie = parseFloat('964.92');
		} else if((width >= 2900) && (width < 3500)) {
			prixsuperficie = parseFloat('981.00');
		} else if((width >= 3500) && (width < 4100)) {
			prixsuperficie = parseFloat('1118.17');
		} else if((width >= 4100) && (width < 4700)) {
			prixsuperficie = parseFloat('1200.47');
		} else if((width >= 4700) && (width < 5300)) {
			prixsuperficie = parseFloat('1348.05');
		} else if((width >= 5300) && (width < 5900)) {
			prixsuperficie = parseFloat('1573.20');
		} else if((width >= 5900) && (width <= 6000)) {
			prixsuperficie = parseFloat('1721.72');
		} /*else if((width >= 6500) && (width <= 7000)) {
			prixsuperficie = parseFloat('1544');
		} */
	} else if(avancee == 2600) {
		if((width >= 2900) && (width < 3500)) {
			prixsuperficie = parseFloat('1002.76');
		} else if((width >= 3500) && (width < 4100)) {
			prixsuperficie = parseFloat('1168.31');
		} else if((width >= 4100) && (width < 4700)) {
			prixsuperficie = parseFloat('1249.67');
		} else if((width >= 4700) && (width < 5300)) {
			prixsuperficie = parseFloat('1414.27');
		} else if((width >= 5300) && (width < 5900)) {
			prixsuperficie = parseFloat('1639.42');
		} else if((width >= 5900) && (width <= 6000)) {
			prixsuperficie = parseFloat('1797.40');
		} /*else if((width >= 6500) && (width <= 7000)) {
			prixsuperficie = parseFloat('1608.4');
		} */
	} else if(avancee == 3100) {
		if((width >= 3500) && (width < 4100)) {
			prixsuperficie = parseFloat('1227.91');
		} else if((width >= 4100) && (width < 4700)) {
			prixsuperficie = parseFloat('1310.21');
		} else if((width >= 4700) && (width < 5300)) {
			prixsuperficie = parseFloat('1474.281');
		} else if((width >= 5300) && (width < 5900)) {
			prixsuperficie = parseFloat('1551.44');
		} else if((width >= 5900) && (width <= 6000)) {
			prixsuperficie = parseFloat('1885.38');
		} /*else if((width >= 6500) && (width <= 7000)) {
			prixsuperficie = parseFloat('1682.6');
		} */
	} else if(avancee == 3600) {
		if((width >= 3500) && (width < 4100)) {
			prixsuperficie = parseFloat('1328.18');
		} else if((width >= 4100) && (width < 4700)) {
			prixsuperficie = parseFloat('1402.92');
		} else if((width >= 4700) && (width < 5300)) {
			prixsuperficie = parseFloat('1568.47');
		} else if((width >= 5300) && (width < 5900)) {
			prixsuperficie = parseFloat('1677.26');
		} else if((width >= 5900) && (width <= 6000)) {
			prixsuperficie = parseFloat('1917.54');
		} /*else if((width >= 6500) && (width <= 7000)) {
			prixsuperficie = parseFloat('1787.6');
		} */
	}

	return prixsuperficie;
}

function getPrixSuperficieMonoBloc(avancee, width) {
	var prixsuperficie = parseFloat('0');
	if(avancee == 2100) {
		if((width >= 2450) && (width < 2900)) {
			prixsuperficie = parseFloat('586.52');
		} else if((width >= 2900) && (width < 3500)) {
			prixsuperficie = parseFloat('613.95');
		} else if((width >= 3500) && (width < 4100)) {
			prixsuperficie = parseFloat('734.10');
		} else if((width >= 4100) && (width < 4700)) {
			prixsuperficie = parseFloat('806.94');
		} else if((width >= 4700) && (width < 5300)) {
			prixsuperficie = parseFloat('1008.44');
		} else if((width >= 5300) && (width < 5900)) {
			prixsuperficie = parseFloat('1090.74');
		} else if((width >= 5900) && (width <= 6000)) {
			prixsuperficie = parseFloat('1222.23');
		} /*else if((width >= 6500) && (width <= 7000)) {
			prixsuperficie = parseFloat('1132.4');
		} */
	} else if(avancee == 2600) {
		if((width >= 2900) && (width < 3500)) {
			prixsuperficie = parseFloat('641.39');
		} else if((width >= 3500) && (width < 4100)) {
			prixsuperficie = parseFloat('751.12');
		} else if((width >= 4100) && (width < 4700)) {
			prixsuperficie = parseFloat('855.18');
		} else if((width >= 4700) && (width < 5300)) {
			prixsuperficie = parseFloat('1058.57');
		} else if((width >= 5300) && (width < 5900)) {
			prixsuperficie = parseFloat('1150.34');
		} else if((width >= 5900) && (width <= 6000)) {
			prixsuperficie = parseFloat('1271.42');
		} /*else if((width >= 6500) && (width <= 7000)) {
			prixsuperficie = parseFloat('1154.8');
		} */
	} else if(avancee == 3100) {
		if((width >= 2900) && (width < 3500)) {
			prixsuperficie = parseFloat('690.58');
		} else if((width >= 3500) && (width < 4100)) {
			prixsuperficie = parseFloat('788.96');
		} else if((width >= 4100) && (width < 4700)) {
			prixsuperficie = parseFloat('915.73');
		} else if((width >= 4700) && (width < 5300)) {
			prixsuperficie = parseFloat('1118.17');
		} else if((width >= 5300) && (width < 5900)) {
			prixsuperficie = parseFloat('1128.58');
		} else if((width >= 5900) && (width <= 6000)) {
			prixsuperficie = parseFloat('1348.05');
		} /*else if((width >= 6500) && (width <= 7000)) {
			prixsuperficie = parseFloat('1233.2');
		} */
	} else if(avancee == 3600) {
		if((width >= 3500) && (width < 4100)) {
			prixsuperficie = parseFloat('880.73');
		} else if((width >= 4100) && (width < 4700)) {
			prixsuperficie = parseFloat('1002.76');
		} else if((width >= 4700) && (width < 5300)) {
			prixsuperficie = parseFloat('1206.15');
		} else if((width >= 5300) && (width < 5900)) {
			prixsuperficie = parseFloat('1243.99');
		} else if((width >= 5900) && (width <= 6000)) {
			prixsuperficie = parseFloat('1365.08');
		} /*else if((width >= 6500) && (width <= 7000)) {
			prixsuperficie = parseFloat('1294.8');
		} */
	}

	return prixsuperficie;
}

function initcalcul()
{
	calculPrix();
}

function updateBtDevis(display) {
	if(display == 'show') {
		show = '_on';
	} else {
		show = '_off';
	}
	$('#bt_devis').attr("src",  "/images/volets_roulants/bt_devis"+show+".png");

}

function updateBtQt(button, display) {
	if(display == 'show') {
		show = '_on';
	} else {
		show = '';
	}
	if(button == 'plus') {
		$('#btQtPlus').attr("src",  "/images/volets_roulants/bt_quantite_plus"+show+".gif");
	} else if(button == 'minus') {
		$('#btQtMinus').attr("src", "/images/volets_roulants/bt_quantite_moins"+show+".gif");
	}
}


/*******************************************************************/

// pop up d'aide

function hideAideOn(idDiv, occDivOff, occDivOn, idDivAide)
{
	obj1 = document.getElementById(idDiv+occDivOff).style;
	obj2 = document.getElementById(idDiv+occDivOn).style;
	obj1.display="none";
	obj2.display="block";
}

function affHideAide(idDiv, occDivOff, occDivOn, idDivAide)
{
	//alert("idDivAide : "+idDivAide);
	obj1 = document.getElementById(idDiv+occDivOff).style;
	obj2 = document.getElementById(idDiv+occDivOn).style;
	obj1.display="none";
	obj2.display="block";
	//document.getElementById("aideMesureLargeur").style.display = "none";
	document.getElementById("aideMesureHauteur").style.display = "none";
	//document.getElementById("aideMesureTypeCommande").style.display = "none";
	//document.getElementById("aideMesureTypePose").style.display = "none";
	if(idDivAide != "")
	{
		obj3 = document.getElementById(idDivAide).style;
		if(occDivOff == "1")
		{
			obj3.display = "block";
		}
		else
		{
			obj3.display = "none";
		}
	}
}

function unHideAll()
{
	affHideAide('bt_info_lar','2', '1', 'aideMesureLargeur');
	affHideAide('bt_info_lar','2', '1', 'aideMesureHauteur');
	affHideAide('bt_info_lar','2', '1', 'aideMesureTypeCommande');
	affHideAide('bt_info_lar','2', '1', 'aideMesureTypePose');
}
//*****************************
// page catï¿?gorie

function changefond(elem){
//ONMOUSEOVER
	document.getElementById(elem).style.borderColor  = "#FF9600";
}
function changefond2(elem){
//ONMOUSEOUT
	document.getElementById(elem).style.borderColor  = "#008000";
}
		function rolloverIn(elem){
	document.getElementById(elem).src="/images/films/bt_en_savoir_plus_on.png";
}
function rolloverOut(elem){
	document.getElementById(elem).src="/images/films/bt_en_savoir_plus_off.png";
}
function changecouleurcontour1(elem){
//ONMOUSEOVER
	document.getElementById(elem).style.borderColor = "#87CC01";
	document.body.style.cursor = "pointer";
}
function changecouleurcontour2(elem){
//ONMOUSEOUT
	document.getElementById(elem).style.borderColor = "#c7c7c7";
	document.body.style.cursor = "default";
}

var xhr= null;
//Crï¿?ons une fonction de crï¿?ation d'objet XMLHttRequest
function get_Xhr()
{
	if (window.XMLHttpRequest) xhr = new XMLHttpRequest (); // Firefox
	else if (window.ActiveXObject)xhr = new ActiveXObject ('Microsoft.XMLHTTP'); //IE
	else
	{
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest\nVeuillez le mettre ï¿? jour");
	}
	return xhr;
}


function btPanierIn()
{
	document.getElementById("btpanier1").src="/images/films/bt_ajout_panier_on.jpg";
	//document.getElementById("btpanier2").src="/images/films/bt_ajout_panier_on.jpg";
}

function btPanierOut()
{
	document.getElementById("btpanier1").src="/images/films/bt_ajout_panier_off.jpg";
	//document.getElementById("btpanier2").src="/images/films/bt_ajout_panier_off.jpg";
}
function btpop1In()
{
	document.getElementById("btpop1").src="/images/films/bt_continuez_on.png";
}

function btpop2In()
{
	document.getElementById("btpop2").src="/images/films/bt_panier_on.png";
}
function btpop1Out()
{
	document.getElementById("btpop1").src="/images/films/bt_continuez_off.png";
}

function btpop2Out()
{
	document.getElementById("btpop2").src="/images/films/bt_panier_off.png";
}

function popupPanier()
{
	window.scrollTo(0,0);

	var alpha = 50;
	document.getElementById('popup_panier').style.display = 'block';
	document.getElementById('popup_panier_ombre').style.display = 'none';
	document.getElementById('text_popup').style.display = 'block';
	//document.getElementById('listeVelux').style.display = 'none';
	var idMatiere = document.getElementById('id_matiere').value;
	var Matiere = "";
	if(idMatiere == 9)
	{
		Matiere = "Banne monobloc";
	}
	else if(idMatiere == 10)
	{
		Matiere = "Banne demi-coffre";
	}
	else if(idMatiere == 11)
	{
		Matiere = "Banne coffre";
	}
	//nomVoletRoulant
	document.getElementById('libelle2').innerHTML = Matiere;
	var prixttTTC = document.getElementById('prixttTTC').innerHTML;
	prixttTTC = prixttTTC.substring(0,prixttTTC.length-2);

	document.getElementById('ttcpopup').value = prixttTTC;
	var qtVolet = document.getElementById('qtBT').value;
	document.getElementById('qtpopup').value = qtVolet;
	document.getElementById('popup_panier').style.opacity = alpha / 100;
	/** Test pour notre cher IE */
	if (document.body.filters != undefined)
	{
		document.getElementById('popup_panier').style.filter = 'alpha(opacity:' + alpha + ')';
	}
}

function killPopup() {
	document.getElementById('popup_panier').style.display = 'none';
	document.getElementById('popup_panier_ombre').style.display = 'none';
	document.getElementById('text_popup').style.display = 'none';
	validerVoletroulant('stop');
	reset();
}

function desacError(idCombobox, value) {
	var status = value;
	if(status == 'empty') {
		$('#'+idCombobox).css('background-color', '#FFFFFF');
	}
}

function valider(typeDevis){
	var onError = 0;
	var strError = "";

	//nom du produit
	var id_nomProduit = $('#id_nomProduit').val();
	// id du produit dans la table produit
	var id_tabProduit = $('#id_tabProduit').val();
	// type de banne
	var id_matiere = $('#id_matiere').val();
	// coloris du produit
	var id_coloris = $('#id_coloris').val();
	// largeur de la banne
	var id_volet_width = $('#id_volet_width').val();
	// avancee de la banne
	var id_volet_height = $('#id_avancee').val();
	// type de moteur
	var id_commType = $('#id_commType').val();
	var type;
	type = id_commType;
	// cote de manoeuvre
	var id_commSide = $('#id_commSide').val();
	//alert('id_commSide : '+id_commSide);
	// coloris du mecanisme
	var id_colMeca = $('#id_colMeca').val();
	// sortie motorisation
	var id_motorOutSide = $('#id_motorOutSide').val();
	// option treuil de secours
	var id_treuilSecour = $('#id_treuilSecour').val();
	//option anemometre
	var id_anemometre =$('#id_anemometre').val();
	//Lambrequin
	var id_lambrequin = $('#id_lambrequin').val();
	// Fixation
	var id_fixation = $('#id_fixation').val();
	//quantite
	var qtBT = $('#qtBT').val();
	var prixuHT = $('#prixuHT').html();
	if(typeof(prixuHT)=='undefined')prixuHT='0,00';
	prixuHT = prixuHT.substring(0,prixuHT.length-2);
	//var prixpromoHT = document.getElementById('prixpromoHT').innerHTML;
	//prixpromoHT = prixpromoHT.substring(0,prixpromoHT.length-2);
	var prixttHT = document.getElementById('prixttHT').innerHTML;
	prixttHT = prixttHT.substring(0,prixttHT.length-2);
	var prixttTTC = document.getElementById('prixttTTC').innerHTML;
	prixttTTC = prixttTTC.substring(0,prixttTTC.length-2);

	if(id_volet_width == "")
	{
		onError = 1;
		strError = strError + "Veuillez renseigner la largeur de la banne\n";
		$('#id_volet_width').css('background-color', '#FFA0A0');
	}
	if(id_volet_height == "")
	{
		onError = 1;
		strError = strError + "Veuillez renseigner la longueur d\'avancée de la banne\n";
		$('#id_volet_height').css('background-color', '#FFA0A0');
	}
	if(id_colMeca == "empty")
	{
		onError = 1;
		strError = strError + "Veuillez renseigner le coloris du mécanisme de la banne\n";
		$('#id_colMeca').css('background-color', '#FFA0A0');
	}
	if(id_commType == "empty")
	{
		onError = 1;
		strError = strError + "Veuillez renseigner le type de moteur de la banne\n";
		$('#id_commType').css('background-color', '#FFA0A0');
	}
	if(id_commSide == "empty" && (id_commType == 1 || id_commType == 4 || id_commType == 7) )
	{
		onError = 1;
		strError = strError + "Veuillez renseigner le côté de commande de la banne\n";
		$('#id_commSide').css('background-color', '#FFA0A0');
	}
	if(id_commType == '2' || id_commType == '3' || id_commType == '5' || id_commType == '6' || id_commType == '8' || id_commType == '9')
	{
		// Moteur
		if(id_motorOutSide == "empty")
		{
			onError = 1;
			strError = strError + "Veuillez renseigner le côté de sortie de la motorisation de la banne\n";
			$('#id_motorOutSide').css('background-color', '#FFA0A0');
		}
		if(id_treuilSecour == "empty")
		{
			onError = 1;
			strError = strError + "Veuillez indiquez si vous désirez oui ou non le treuil de secours\n";
			$('#id_treuilSecour').css('background-color', '#FFA0A0');
		}
		if(type == '3' || type == '6' || type == '9')
		{
			// moteur telecommande
			if(id_anemometre == "empty")
			{
				onError = 1;
				strError = strError + "Veuillez indiquez si vous désirez oui ou non l\'anémomètre\n";
				$('#id_anemometre').css('background-color', '#FFA0A0');
			}
		}
	}
	if(id_lambrequin == "empty")
	{
		onError = 1;
		strError = strError + "Veuillez indiquez le type de lambrequin\n";
		$('#id_lambrequin').css('background-color', '#FFA0A0');
	}
	if(id_fixation == "empty")
	{
		onError = 1;
		strError = strError + "Veuillez indiquez si vous désirez oui ou non l\'anémomètre\n";
		$('#id_fixation').css('background-color', '#FFA0A0');
	}

	if(onError == 1)
	{
		alert(strError);
	} else if(typeDevis == 'devis'){
		validerVoletroulant('devis');
	}
	else
	{
		popupPanier();
	}
}

function validerVoletroulant(popup) {
	//var popup ="";
	// Nous creons un objet XMLHttpRequest
	//alert("validerVoletroulant(popup)");
	get_Xhr();
	// Nous definissons ce que fera AJAX (avant mï¿?me de lui dire quoi transmettre)
	xhr.onreadystatechange = function() {
		//Si la requete est terminee
		if(xhr.readyState == 4 && xhr.status == 200) {
			// Recuperation de la reponse
			//var nbstore =  xhr.responseText ;// nbstore
			if(popup=="panier") {
				window.location.href= "/recapitulatifcaddie.php";
			}
		}
	}
	// Nous recuperons les valeurs et On remplace les , par des . pour le calcul dans le panier
	var onError = 0;
	var strError = "";

	//nom du produit
	var id_nomProduit = document.getElementById('id_nomProduit').value;
	// id du produit dans la table produit
	var id_tabProduit = document.getElementById('id_tabProduit').value;
	// type de banne
	var id_matiere = document.getElementById('id_matiere').value;
	// coloris du produit
	var id_coloris = document.getElementById('id_coloris').value;
	// largeur de la banne
	var id_volet_width = document.getElementById('id_volet_width').value;
	// avancï¿?e de la banne
	var id_volet_height = document.getElementById('id_avancee').value;
	// type de moteur
	var id_commType = document.getElementById('id_commType').value;
	var type;
	type = id_commType;
	// cote de manoeuvre
	var id_commSide = document.getElementById('id_commSide').value;
	// coloris du mecanisme
	var id_colMeca = document.getElementById('id_colMeca').value;
	// sortie motorisation
	var id_motorOutSide = document.getElementById('id_motorOutSide').value;

	// option treuil de secours
	var id_treuilSecour = document.getElementById('id_treuilSecour').value;
	//option anemometre
	var id_anemometre = document.getElementById('id_anemometre').value;
	//Lambrequin
	var id_lambrequin = document.getElementById('id_lambrequin').value;
	// Fixation
	//alert("id_lambrequin : "+id_lambrequin);
	var id_fixation = document.getElementById('id_fixation').value;
	var qtBT = document.getElementById('qtBT').value;
	var prixuHT = document.getElementById('prixuHT').innerHTML
	prixuHT = prixuHT.substring(0,prixuHT.length-2);
	//var prixpromoHT = document.getElementById('prixpromoHT').innerHTML;
	//prixpromoHT = prixpromoHT.substring(0,prixpromoHT.length-2);
	var prixttHT = document.getElementById('prixttHT').innerHTML;
	prixttHT = prixttHT.substring(0,prixttHT.length-2);
	var prixttTTC = document.getElementById('prixttTTC').innerHTML;
	prixttTTC = prixttTTC.substring(0,prixttTTC.length-2);

	if(id_volet_width == "")
	{
		onError = 1;
		strError = strError + "Veuillez renseigner la largeur de la banne\n";
		$('#id_volet_width').css('background-color', '#FFA0A0');
	}
	if(id_volet_height == "")
	{
		onError = 1;
		strError = strError + "Veuillez renseigner la longueur d\'avancée de la banne\n";
		$('#id_volet_height').css('background-color', '#FFA0A0');
	}
	if(id_colMeca == "empty")
	{
		onError = 1;
		strError = strError + "Veuillez renseigner le coloris du mécanisme de la banne\n";
		$('#id_colMeca').css('background-color', '#FFA0A0');
	}
	if(id_commType == "empty")
	{
		onError = 1;
		strError = strError + "Veuillez renseigner le type de moteur de la banne\n";
		$('#id_commType').css('background-color', '#FFA0A0');
	}
	if(id_commSide == "empty" && (id_commType == 1 || id_commType == 4 || id_commType == 7) )
	{
		onError = 1;
		strError = strError + "Veuillez renseigner le côté de commande de la banne\n";
		$('#id_commSide').css('background-color', '#FFA0A0');
	}
	if(id_commType == '2' || id_commType == '3' || id_commType == '5' || id_commType == '6' || id_commType == '8' || id_commType == '9')
	{
		// Moteur
		if(id_motorOutSide == "empty")
		{
			onError = 1;
			strError = strError + "Veuillez renseigner le côté de sortie de la motorisation de la banne\n";
			$('#id_motorOutSide').css('background-color', '#FFA0A0');
		}
		if(id_treuilSecour == "empty")
		{
			onError = 1;
			strError = strError + "Veuillez indiquez si vous désirez oui ou non le treuil de secours\n";
			$('#id_treuilSecour').css('background-color', '#FFA0A0');
		}
		if(type == '3' || type == '6' || type == '9')
		{
			// moteur telecommande
			if(id_anemometre == "empty")
			{
				onError = 1;
				strError = strError + "Veuillez indiquez si vous désirez oui ou non l\'anémomètre\n";
				$('#id_anemometre').css('background-color', '#FFA0A0');
			}
		}
	}
	if(id_lambrequin == "empty")
	{
		onError = 1;
		strError = strError + "Veuillez indiquez le type de lambrequin\n";
		$('#id_lambrequin').css('background-color', '#FFA0A0');
	}

	if(onError == 1)
	{
		alert(strError);
	}
	else
	{
		xhr.open('GET',"/store-exterieur/sur-mesure/valider.php?qtBT="+qtBT+"&prixuHT="+prixuHT+"&prixttHT="+prixttHT+"&prixttTTC="+prixttTTC+"&id_nomProduit="+id_nomProduit+"&id_tabProduit="+id_tabProduit+"&id_matiere="+id_matiere+"&id_coloris="+id_coloris+"&id_volet_width="+id_volet_width+"&id_volet_height="+id_volet_height+"&id_commType="+id_commType+"&id_commSide="+id_commSide+"&id_colMeca="+id_colMeca+"&id_motorOutSide="+id_motorOutSide+"&id_treuilSecour="+id_treuilSecour+"&id_anemometre="+id_anemometre+"&id_lambrequin="+id_lambrequin+"&id_fixation="+id_fixation);
		xhr.send("qtBT="+qtBT+"&prixuHT="+prixuHT+"&prixttHT="+prixttHT+"&prixttTTC="+prixttTTC+"&id_nomProduit="+id_nomProduit+"&id_tabProduit="+id_tabProduit+"&id_matiere="+id_matiere+"&id_coloris="+id_coloris+"&id_volet_width="+id_volet_width+"&id_volet_height="+id_volet_height+"&id_commType="+id_commType+"&id_commSide="+id_commSide+"&id_colMeca="+id_colMeca+"&id_motorOutSide="+id_motorOutSide+"&id_treuilSecour="+id_treuilSecour+"&id_anemometre="+id_anemometre+"&id_lambrequin="+id_lambrequin+"&id_fixation="+id_fixation);
	}

	if(popup == 'devis') {
		window.location.href= "/recapitulatifdevis.php";
	}
}

function downloadNotices(idDiv)
{
	$('#'+idDiv).show();
}

function changeTextile(textileId) {
    $.post(
        '../sb_treatment.php',
        {'action': 'change_colour', 'textile_id': textileId},
        function(datas)  {
            $('#textile_small_picture').attr('src', '/images/store-projection/coloris/'+datas.nameSmallPicture);
            $('#id_coloris').val(datas.label);
            $('#textile_name').html(datas.label);
            $('#button_textile_zoom').attr('onClick', 'imgLight("/images/store-projection/coloris/'+datas.nameBigPicture+'");');
            closeLightBox2();
            $(document).scrollTop(0);
        },
        'json'
    );
}

