$(document).ready(function(){

    var matiere = $('#id_matiere').val();
    if(matiere == 1) {
	//PVC
	minWidth = 655;
	maxWidth = 1694;
	minHeight = 605;
	maxHeight = 2395;
    }
    else if(matiere == 2) {
	// ALU
	minWidth = 655;
	maxWidth = 2694;
	minHeight = 605;
	maxHeight = 3295;
    }
    $('.lMin').html(minWidth);$('.lMax').html(maxWidth);
    $('.hMin').html(minHeight);$('.hMax').html(maxHeight);
	
    pic1=new Image(600,800);
    pic1.onload=function(){
	lightBox2('<img src="'+ this.src +'" />');
	$('#lightBox').css({
	    'top':'50px',
	    'position':'fixed'
	})
    }
    $('#lightBox').live('click',function(){
	closeLightBox2();
    })
    $('#zoom1').live('click',function(){
	aPathImg=$(this).attr('src').split('/');
	if(aPathImg[aPathImg.length-1]!='dessin_volet_roulant_largeur.png' && aPathImg[aPathImg.length-1]!='dessin_volet_roulant_hauteur.png')
	{
	    aPathImg[aPathImg.length-1]='g-'+aPathImg[aPathImg.length-1];
	    pic1.src=aPathImg.join('/');
	}     
    })

//permet d'afficher le texte associé à la matière
    $("#id_matiere").change(function(){
	if($(this).val()==1){
	   $('#pvc').show();
	   $('#alu').hide();
	}else if($(this).val()==2){
	   $('#alu').show();
	   $('#pvc').hide();
	}
    });

    $('#bt_info_coteComm2').bind('mouseout', function(){
        hideAideOn('bt_info_coteComm','2', '1', '');
    }).bind('click', function(){
        lightBox('<div class="tRight" style="margin-bottom: 3px"><img src="/images/rideaux/picto/bt-fermer-pop-up-rideaux.png" alt="" /></div><div style="padding: 10px;">Le c&ocirc;t&eacute; de commande (gauche ou droite) est vu depuis l\'int&eacute;rieur de l\'habitation.</div>','300','80');
    });
    
    
    $('.popupImgDroite').bind('click',function(){
	 nomImg = $(this).attr('id');
	 content = '<img class="popupImg" src="/images/appli_store/volet_roulant/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();
	     }
       });
    });
    
    calculPrix();
});
/************************** GALERIE AJAX ***************************/

var coloris_back_gal = 'blanc';
// Lightbox
$(function()
{
	//$('#gallery a').lightBox({fixedNavigation:true});
	$('#img_volet_roulant a').lightBox({fixedNavigation:true});
	//$('#gallery3 a').lightBox({fixedNavigation:true});
});

function showPoseRegion(){
    if(regionPose.isRegionPose()){
	$('#poseVolet').html(regionPose.getHtmlInfo()).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 downloadNotices(idDiv)
{
	$('#'+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(',');
	//alert(liste_coloris);
	for(id in TabColoris)
	{
		if(id!='indexOf'){
			document.getElementById('img_coloris_'+TabColoris[id]).src=path+'coloris/'+TabColoris[id]+'_off.png';
		}
	}
	//alert(path+'coloris/'+coloris_choose+'_on.png');

	document.getElementById('img_coloris_'+coloris_choose).src=path+'coloris/'+coloris_choose+'_on.png';
	document.getElementById('coloris_choose').style.backgroundImage='url('+ path+'/background/'+ coloris_choose +'.jpg)';
	document.getElementById('zoom1').src=path+'texture_volet/volet-roulant-renovation-'+coloris_choose+'.jpg';
	document.getElementById('prixVolet').value = prix;
	coloris_back_gal = coloris_choose;
	$('#id_coloris').val(coloris_choose);
	calculPrix();
}

function restaureBackColoris() {
    document.getElementById('zoom1').src='/images/volets_roulants/texture_volet/volet-roulant-renovation-'+coloris_back_gal+'.jpg';
}

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) {
	listMat = AjaxRequest('/ajax/ajax_function.php', 'action=change_rolling_store&id_mat='+id_mat+'&path='+path);
	if(listMat) {
		tabListMat = listMat.split('|');
		document.getElementById("colorisGal").innerHTML = tabListMat[0];
		document.getElementById('img_volet_roulant').innerHTML = tabListMat[1];
		document.getElementById('verrou_pose').innerHTML = tabListMat[2];
		document.getElementById('id_td_commType').innerHTML = tabListMat[3];
		//document.getElementById('id_td_width').innerHTML = tabListMat[4];
		calculPrix();
		$('#colorisGal img').triggerHandler('click');
		$(' #id_volet_height, #id_volet_width').focus().blur();
	}
}

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 et profondeur 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';
	    $('#id_ht_coffre').fadeIn('slow');
	} 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();
	}
}

function displayMotor(type) {
 if(type==19 || type==18)
    {
	lightBox('<table cellpadding="0" cellspacing="0" width="100%" style="background-color:#edeef0">\
			<tr>\
			    <td align="right"><img src="/images/volets_roulants/bt_fermer_popup.png"></td>\
			</tr>\
		    </table><img src="/images/volets_roulants/pop_motorisation_Telis-4-RTS.jpg">','558');
	$('#id_commType').val('empty');

    }
	// DEBUG : Trouver une solution pour éviter les id en dur. C'est mal!
	if(type == '3' || type == '4' || type == '7' || type == '8') {
		//$('#motor_title').colSpan = 1;
		$('#motor_title').html('6. Sortie motorisation :');
		$('#motor_help').html("<div id=\"bt_info_typeMeca1\" style=\"background:url(/images/volets_roulants/bt_info_off.jpg); width:18px; height:18px; cursor:pointer; display:block;\" onmouseover=\"hideAideOn('bt_info_typeMeca','1', '2', '');\"></div><div id=\"bt_info_typeMeca2\" style=\"background:url(/images/volets_roulants/bt_info_on.jpg); width:18px; height:18px; cursor:pointer; display:none;\" onmouseout=\"hideAideOn('bt_info_typeMeca','2', '1', '');\" onclick=\"affHideAide('bt_info_typeMeca','1', '2', 'aideMesureTypeMeca');\"></div>");
	} else {
		//$('#motor_title').colSpan = 2;
		$('#motor_title').html('6. Côté de commande :');
		$('#motor_help').html("<div id=\"bt_info_coteComm1\" style=\"background:url(/images/volets_roulants/bt_info_off.jpg); width:18px; height:18px; cursor:pointer; display:block;\" onmouseover=\"hideAideOn('bt_info_coteComm','1', '2', '');\"></div><div id=\"bt_info_coteComm2\" style=\"background:url(/images/volets_roulants/bt_info_on.jpg); width:18px; height:18px; cursor:pointer; display:none;\" onmouseout=\"hideAideOn('bt_info_coteComm','2', '1', '');\" onclick=\"affHideAide('bt_info_coteComm','1', '2', 'aideMesureCoteComm');\"></div>");
	}

	// Non affichage du verroy pour le cas du verrou machin
	if(type == '16' || type == '15') {
		displayVerrouChoice('no');
		displayCoteCommande('no');
	} else {
		displayVerrouChoice('yes');
		displayCoteCommande('yes');
	}
}

function displayCoteCommande(valid) {
	if(valid == 'yes') {
		$('#id_cote_commande').fadeIn('slow');
	} else {
		$('#id_cote_commande').fadeOut('fast');
	}
}

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

function displayVerrouChoice(valid) {
	if(valid == 'yes') {
		$('#id_lock').fadeIn('slow');
		$('#lock_title').fadeIn('slow');
	} else {
		$('#id_lock').val('no');
		displayVerrou('false');
		$('#id_lock').fadeOut('fast');
		$('#lock_title').fadeOut('fast');
	}
}

function checkSurface(matiere) {
	width = $('#id_volet_width').val();
	height = $('#id_volet_height').val();

	// Si on a tous les éléments renseignés
	if(width != '' && height != '') {

		// Cas PVC
		if(matiere == 1) {
			maxSurface = 4300;
		}
		// Cas Aluminium
		else if(matiere == 2) {
			maxSurface = 6000;
		}

		//alert(matiere+','+width+','+height);

		surface = width * height / 1000;

		if(surface > maxSurface) {
			$('#id_surface').html('<strong>Surface :</strong>  Surface maximum de '+maxSurface+' mm² atteinte.');
			$('#id_surface').fadeIn('slow');
			document.getElementById('id_volet_height').style.backgroundColor="#FFA0A0";
			document.getElementById('id_volet_height').value='';
		} else {
			$('#id_surface').fadeOut('fast');
		}

	}


}

function checkWidth(width, matiere) {
	// Cas PVC
	if(matiere == 1) {
		minWidth = 600;
		maxWidth = 2000;
		maxSurface = 4300;
	}
	// Cas Aluminium
	else if(matiere == 2) {
		minWidth = 600;
		maxWidth = 2800;
		maxSurface = 6000;
	}

	if(width >= minWidth && width <= maxWidth) {
		document.getElementById("width_volet").style.display = 'none';
	} else {
		/*document.getElementById("width_volet").style.display = 'block';
		$('#width_volet').hide();*/
		$('#width_volet').html('<strong>Largeur :</strong>  Mini '+minWidth+' mm &agrave; Maxi '+maxWidth+' mm');
		$('#width_volet').fadeIn('slow');
		document.getElementById('id_volet_width').style.backgroundColor="#FFA0A0";
		document.getElementById('id_volet_width').value='';
	}

}

function checkSuperficie(type){
    matierio=$('#id_matiere').val();
    if(matierio == 1) {
	//PVC
	minWidth = 655;
	maxWidth = 1694;
	minHeight = 605;
	maxHeight = 2395;
	maxSurface = 4000000;
    }
    else if(matierio == 2) {
	// ALU
	minWidth = 655;
	maxWidth = 2694;
	minHeight = 605;
	maxHeight = 3295;
	maxSurface = 6000000;
    }
        $('.lMin').html(minWidth);$('.lMax').html(maxWidth);
    $('.hMin').html(minHeight);$('.hMax').html(maxHeight);
    //valeur entre par l'utilisateur'
    valWidth=$('#id_volet_width').val();
    valHeight=$('#id_volet_height').val();
    // si les valeur entre ne sont pas des nombres ont les definit a  0
    if(isNaN(valHeight) || valHeight=='')valHeight=0;
    if(isNaN(valWidth) || valWidth=='')valWidth=0;
    
    if(type=='largeur'){
	// on va stocker la superficie obtenu par nos valeur
	superficieCalcul=valWidth*valHeight;
	maxWidthForSuperficie=maxSurface/(valHeight<=minHeight ? minHeight : valHeight);
	if(maxWidthForSuperficie > maxWidth)maxWidthForSuperficie=maxWidth;
	else maxWidthForSuperficie=Math.floor(maxWidthForSuperficie);
	
	if(valWidth<minWidth || valWidth>maxWidth){
	    // cas  ou la largeur depasse les limite definit
	    $('#width_volet').html('<strong>Largeur :</strong>  Mini '+minWidth+' mm &agrave; Maxi '+maxWidthForSuperficie+' mm<br />(Superficie max : '+ (maxSurface/1000000) +' m&sup2;)');
	    $('#width_volet').fadeIn('slow');
	    $('#id_volet_width').val('').css('background-color','#FFA0A0');
	    
	}
	else if(superficieCalcul>maxSurface){
	    // si on ne depasse pas les limite definit  on va recuperer les valeurs de la hauteur et de la largeur 
	    // puis on regarde si on ne depasse pas la supercifie
	    // sinon on met un message d'erreur
	    $('#width_volet').html('<strong>Largeur :</strong>  Mini '+minWidth+' mm &agrave; Maxi '+maxWidthForSuperficie+' mm<br />(Superficie max : '+ (maxSurface/1000000) +' m&sup2;)');
	    $('#width_volet').fadeIn('slow');
	    $('#id_volet_width').val('').css('background-color','#FFA0A0');
	}
	else{
	    $('#width_volet').hide();
	    $('#id_volet_height').focus();
	    $('#hauteur').focus();
	}
	maxHeightForSuperficie=maxSurface/(valWidth<minWidth ? minWidth : valWidth);
	if(maxHeightForSuperficie > maxHeight) maxHeightForSuperficie=maxHeight; 
	else maxHeightForSuperficie=Math.floor(maxHeightForSuperficie);
	$('#height_volet').html('<strong>Hauteur :</strong>  Mini '+minHeight+' mm &agrave; Maxi '+maxHeightForSuperficie+' mm<br />(Superficie max : '+ (maxSurface/1000000) +' m&sup2;)');
    }
    else if(type=='hauteur'){	
	// on va stocker la superficie obtenu par nos valeur
	superficieCalcul=valWidth*valHeight;
	maxHeightForSuperficie=maxSurface/(valWidth<=minWidth ? minWidth : valWidth);
	if(maxHeightForSuperficie > maxHeight) maxHeightForSuperficie=maxHeight; 
	else maxHeightForSuperficie=Math.floor(maxHeightForSuperficie);
	if(valHeight<minHeight || valHeight>maxHeight){
	    // cas  ou la largeur depasse les limite definit
	    $('#height_volet').html('<strong>Hauteur :</strong>  Mini '+minHeight+' mm &agrave; Maxi '+maxHeightForSuperficie+' mm<br />(Superficie max : '+ (maxSurface/1000000) +' m&sup2;)');
	    $('#height_volet').fadeIn('slow');
	    $('#id_volet_height').val('').css('background-color','#FFA0A0');
	    
	}
	else if(superficieCalcul>maxSurface){
	    // si on ne depasse pas les limite definit  on va recuperer les valeurs de la hauteur et de la largeur 
	    // puis on regarde si on ne depasse pas la supercifie
	    // sinon on met un message d'erreur
	    $('#height_volet').html('<strong>Largeur :</strong>  Mini '+minWidth+' mm &agrave; Maxi '+maxHeightForSuperficie+' mm<br />(Superficie max : '+ (maxSurface/1000000) +' m&sup2;)');
	    $('#height_volet').fadeIn('slow');
	    $('#id_volet_height').val('').css('background-color','#FFA0A0');
	}
	else{
	    $('#height_volet').hide();
	}
	maxWidthForSuperficie=maxSurface/(valHeight<minHeight ? minHeight : valHeight);
	if(maxWidthForSuperficie > maxWidth)maxWidthForSuperficie=maxWidth;
	else maxWidthForSuperficie=Math.floor(maxWidthForSuperficie);
	$('#width_volet').html('<strong>Largeur :</strong>  Mini '+minWidth+' mm &agrave; Maxi '+maxWidthForSuperficie+' mm<br />(Superficie max : '+ (maxSurface/1000000) +' m&sup2;)');
    }
}

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
	// Récupération des valeurs
	height = $('#id_volet_height').val();
	height = parseFloat(height);
	width = $('#id_volet_width').val();
	width = parseFloat(width);
	color = $('#prixVolet').val();
	color = parseFloat(color);
	quantite = $('#qtBT').val();
	quantite = parseFloat(quantite);
	locki = $('#id_lock').val();
	totalHT = 0;
	totalTTC = 0;

	// Si on a choisi un verrou
	
	if(locki=='yes')id_verrou=$('#id_lock_pose').val();
	else id_verrou='none';
	commande = $('#id_commType').val();
	
	//alert('mat : '+$('#id_matiere').val()+"\ncoloris : "+$('#id_coloris')+"\nwidth : "+width+'\nheight : '+height);
	totaluHT=AjaxRequest('/ajax/ajax_function.php', 'action=getSuperficiePrice&idmat='+$('#id_matiere').val()+'&color='+$('#id_coloris').val()+'&width='+width+'&height='+height+'&id_commande='+commande+'&id_verrou='+id_verrou);
	// Calcul des prix
	    if(!isNaN(parseFloat(height)) && height > 0
	    && !isNaN(parseFloat(width)) && width > 0
	    && !isNaN(parseFloat(color)) && color >= 0
	    && !isNaN(parseFloat(quantite)) && quantite >= 0) {
		/*totaluHT = Math.round(parseFloat(superficiePrice) *100) / 100;
		totaluHT = Math.round((totaluHT + prixVerrou + prixCommande) * 100) / 100;*/
		
		prixpromHT = Math.round(totaluHT *0.50 * 100) / 100;
		totalHT = Math.round(prixpromHT * quantite * 100) / 100;
		totalTTC = Math.round(totalHT * (119.6/100) * 100) / 100;
		$('#prixuHT').html(totaluHT+' &euro;');
		//document.getElementById('titleuHT').style.textDecoration = 'line-through';
		document.getElementById('prixuHT').style.textDecoration = 'line-through';
		//$('#prixuHT').style('text-decoration: overline');
		$('#prixpromoHT').html(prixpromHT+' &euro;');
		$('#titlepromoHT').fadeIn('slow');
		$('#prixpromoHT').fadeIn('slow');
		$('#prixttHT').html(totalHT+' &euro;');
		$('#prixttTTC').html(totalTTC+' &euro;');
	} else if(isNaN(quantite)) {
		$('#prixttHT').html(totalHT+'0 &euro;');
		$('#prixttTTC').html(totalTTC+'0 &euro;');
		$('#titlepromoHT').fadeOut('fast');
		$('#prixpromoHT').fadeOut('fast');
	} else {
		$('#prixttHT').html(totalHT+'0 &euro;');
		$('#prixttTTC').html(totalTTC+'0 &euro;');
		$('#titlepromoHT').fadeOut('fast');
		$('#prixpromoHT').fadeOut('fast');
	}
}

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)
{
	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 == 1)
	{
		Matiere = "Volet roulant rénovation PVC";
	}
	else
	{
		Matiere = "Volet roulant rénovation Aluminium";
	}
	//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';
	$('#loading_in_ajax').show();
	validerVoletroulant('');
	//reset();
}

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

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

	var id_nomProduit = document.getElementById('id_nomProduit').value;
	var id_tabProduit = document.getElementById('id_tabProduit').value;
	var id_matiere = document.getElementById('id_matiere').value;
	//var id_tabProduit = document.getElementById('id_tabProduit').value;
	var id_coloris = document.getElementById('id_coloris').value;
	var id_volet_width = document.getElementById('id_volet_width').value;
	var id_volet_height = document.getElementById('id_volet_height').value;
	var id_commType = document.getElementById('id_commType').value;
	//var id_sortieMecha = document.getElementById('id_sortieMecha').value;
	var id_commSide = document.getElementById('id_commSide').value;
	var id_poseType = document.getElementById('id_poseType').value;
	var id_lock = document.getElementById('id_lock').value;
	var id_lock_pose = document.getElementById('id_lock_pose').value;
	var id_poseType = document.getElementById('id_poseType').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 du volet\n";
		$('#id_volet_width').css('background-color', '#FFA0A0');
	}
	if(id_volet_height == "")
	{
		onError = 1;
		strError = strError + "Veuillez renseigner la hauteur du volet\n";
		$('#id_volet_height').css('background-color', '#FFA0A0');
	}
	if(id_commType == "empty")
	{
		onError = 1;
		strError = strError + "Veuillez renseigner le type de commande du volet\n";
		$('#id_commType').css('background-color', '#FFA0A0');
	}
	if(id_commSide == "empty" && id_commType!='16')
	{
		onError = 1;
		strError = strError + "Veuillez renseigner le côté de commande du volet\n";
		$('#id_commSide').css('background-color', '#FFA0A0');
	}
	if(id_poseType == "empty")
	{
		onError = 1;
		strError = strError + "Veuillez renseigner le type de pose du volet\n";
		$('#id_poseType').css('background-color', '#FFA0A0');
	}

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

function validerVoletroulant(popup)
{
    /*
	if(popup!='panier')
	{
	    $('#id_commType').val('empty').change();
	    $('#id_commSide').val('empty');
	    $('#id_poseType').val('empty');
	    $('#id_volet_width').val('');
	    $('#id_volet_height').val('');
	    calculPrix();
	    //$('#prixuHT').val('').css('text-decoration','normal');
	    $('#text_popup').hide();
	    $('#loading_in_ajax').hide();
	    $('#popup_panier').hide();
	    $('#popup_panier_ombre').hide();
	    $('#text_popup').hide();
	}*/
	//var popup ="";
	// Nous créons un objet XMLHttpRequest
	get_Xhr();
	// Nous définissons ce que fera AJAX (avant même de lui dire quoi transmettre)
	xhr.onreadystatechange = function()
	{
		//Si la requete est terminée
		if(xhr.readyState == 4 && xhr.status == 200)
		{
			// Récupération de la réponse
			//var nbstore =  xhr.responseText ;// nbstore
			if(popup=="panier")
			{
			    window.location.href= "/recapitulatifcaddie.php";
			}
			else
			{
			  $('#id_commType').val('empty').change();
	    $('#id_commSide').val('empty');
	    $('#id_poseType').val('empty');
	    $('#id_volet_width').val('');
	    $('#id_volet_height').val('');
	    calculPrix();
	    //$('#prixuHT').val('').css('text-decoration','normal');
	    $('#text_popup').hide();
	    $('#loading_in_ajax').hide();
	    $('#popup_panier').hide();
	    $('#popup_panier_ombre').hide();
	    $('#text_popup').hide();
			}
		}
	}
	// Nous recuperons les valeurs et On remplace les , par des . pour le calcul dans le panier

	var onError = 0;
	var strError = "";

	var id_nomProduit = document.getElementById('id_nomProduit').value;
	var id_tabProduit = document.getElementById('id_tabProduit').value;
	var id_matiere = document.getElementById('id_matiere').value;
	//var id_tabProduit = document.getElementById('id_tabProduit').value;
	var id_coloris = document.getElementById('id_coloris').value;
	var id_volet_width = document.getElementById('id_volet_width').value;
	var id_volet_height = document.getElementById('id_volet_height').value;
	var id_commType = document.getElementById('id_commType').value;
	//var id_sortieMecha = document.getElementById('id_sortieMecha').value;
	var id_commSide = document.getElementById('id_commSide').value;
	var id_poseType = document.getElementById('id_poseType').value;
	var id_lock = document.getElementById('id_lock').value;
	var id_lock_pose = document.getElementById('id_lock_pose').value;
	var id_poseType = document.getElementById('id_poseType').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 du volet\n";
	}
	if(id_volet_height == "")
	{
		onError = 1;
		strError = strError + "Veuillez renseigner la hauteur du volet\n";
	}
	if(id_commType == "empty")
	{
		onError = 1;
		strError = strError + "Veuillez renseigner le type de commande du volet\n";
	}
	if(id_commSide == "empty" && id_commType!='16')
	{
		onError = 1;
		strError = strError + "Veuillez renseigner le côté de commande du volet\n";
	}
	if(id_poseType == "empty")
	{
		onError = 1;
		strError = strError + "Veuillez renseigner le type de pose du volet\n";
	}

	if(onError == 1)
	{
		alert(strError);
	}
	else
	{
		xhr.open('GET',"/volet-roulant/renovation/valider.php?qtBT="+qtBT+"&prixuHT="+prixuHT+"&prixpromoHT="+prixpromoHT+"&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_poseType="+id_poseType+"&id_lock="+id_lock+"&id_lock_pose="+id_lock_pose);
		xhr.send("qtBT="+qtBT+"&prixuHT="+prixuHT+"&prixpromoHT="+prixpromoHT+"&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_poseType="+id_poseType+"&id_lock="+id_lock+"&id_lock_pose="+id_lock_pose);
	}

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

function helpRenov(urlImg, altImg, urlLink, link) {
    lightBox('\
        <div class="lightbox_help_renov">\
            <img src="'+urlImg+'" alt="'+altImg+'" /><br />\
            <div>\
                <a href="'+urlLink+'">'+link+'</a>\
            </div>\
        </div>\
    ');
}

