$(document).ready(
    function start()
    {	
		
			
		
	
	
	
	
		reinitialiseScrollPane1 = function()
		{
			$('#pane1').jScrollPane({showArrows:true, scrollbarOnLeft:true,scrollbarWidth: 15});
		}
		reinitialiseScrollPane2 = function()
		{
			$('#pane2').jScrollPane({showArrows:true, scrollbarOnLeft:true,scrollbarWidth: 15});
		}
		reinitialiseScrollPane3 = function()
		{
			$('#pane3').jScrollPane({showArrows:true, scrollbarOnLeft:true,scrollbarWidth: 15});
		}
		reinitialiseScrollPane4 = function()
		{
			$('#pane4').jScrollPane({showArrows:true, scrollbarOnLeft:true,scrollbarWidth: 15});
		}
		reinitialiseScrollPane5 = function()
		{
			$('#paneEquipe').jScrollPane({showArrows:true, scrollbarOnLeft:true,scrollbarWidth: 15});
		}
		reinitialiseScrollPane6 = function()
		{
			$('#panePartenaire').jScrollPane({showArrows:true, scrollbarOnLeft:true,scrollbarWidth: 15});
		}
		 $(window).resize(function(){

			$(function()
			{	
				var uriCourant = document.location.href;
				var file= uriCourant.split('=');
				var nbreTotal = file.length;
				if (file[nbreTotal-1] == 'occasion.html')
				{
						$('#support3').empty().append($("<div id='pane3' class='scroll-pane' style='width: 100%;overflow: auto;background: #ffffff;float: left;'></div>"));
						$('#pane3').load('loadOcaz.php', '', reinitialiseScrollPane3);
			
				}
				else if (file[nbreTotal-1] == 'promotion.html')
				{
						$('#support4').empty().append($("<div id='pane4' class='scroll-pane' style='width: 100%;overflow: auto;background: #ffffff;float: left;'></div>"));
						$('#pane4').load('loadPromo.php', '', reinitialiseScrollPane4);
			
				}
				else if (file[nbreTotal-1] == 'equipe.html')
				{
						$('#supportEquipe').empty().append($("<div id='paneEquipe' class='scroll-pane'  style='width: 100%;overflow: auto;background: #ffffff;float: left;'></div>"));
						$('#paneEquipe').load('loadEquipe.html', '', reinitialiseScrollPane5);
			
				}
				else if (file[nbreTotal-1] == 'partenaire.html')
				{
						$('#supportPartenaire').empty().append($("<div id='panePartenaire' class='scroll-pane'  style='width: 100%;overflow: auto;background: #ffffff;float: left;'></div>"));
						$('#panePartenaire').load('loadPartenaire.html', '', reinitialiseScrollPane6);
			
				}
				else
				{
					$('#support').empty().append($("<div id='pane1' class='scroll-pane'></div>"));
					 $('#support2').empty().append($("<div id='pane2' style='width:490px; margin-left :-10px'></div>"));
					
					$('#pane1').load('savText.html', '', reinitialiseScrollPane1);
					$('#pane2').load('savText2.html', '', reinitialiseScrollPane2);
				}
			});	
			calculPlacement();		
		});
		
		var uriCourant = document.location.href;
		var file= uriCourant.split('/');
		var nbreTotal = file.length;
		if (file[nbreTotal-1] == 'occasion.html')
		{
			
			$('#pane3').load('loadOcaz.php', '', reinitialiseScrollPane3);
		}
		else if (file[nbreTotal-1] == 'promotion.html')
		{
			$('#pane4').load('loadPromo.php', '', reinitialiseScrollPane4);
		}
		else if (file[nbreTotal-1] == 'equipe.html')
		{
			$('#paneEquipe').load('loadEquipe.html', '', reinitialiseScrollPane5);
		}
		else if (file[nbreTotal-1] == 'partenaire.html')
		{
			$('#panePartenaire').load('loadPartenaire.html', '', reinitialiseScrollPane6);
		}
		
		else if (file[nbreTotal-1] == 'visite.html')
		{
			var so = new SWFObject("Bietry.swf", "swfPage", "95%", "350px", 10);
			so.addParam("allowFullScreen", "true");
			so.write("mag");
		}
		else
		{
			$('#pane1').load('savText.html', '', reinitialiseScrollPane1);
			$('#pane2').load('savText2.html', '', reinitialiseScrollPane2);
		}
		
		// appel a la fonction de recherche de la résolution de l'écran
		calculPlacement();
		//open a welcome message as soon as the window loads
		
	}
);

// function loadVideo ()
// {

			
	// }
function montre(id, marque) 
{ 
		var d = document.getElementById(id); 
		for (var i = 1; i<=10; i++)
		{ 
			if (document.getElementById('smenu'+i)) 
				document.getElementById('smenu'+i).style.display='none';
			$("#marque" + i).css("color", "red");
		} 
		if (d) 
		{
			d.style.display='block';
			$("#" + marque).css("color", "#a6a6a6");
		} 
} 

function cache() 
{
		for (var i = 1; i<=10; i++)
		{ 
			
				if (document.getElementById('smenu'+i)) 
					document.getElementById('smenu'+i).style.display='none';
		} 
} 


function calculPlacement()
{
	var uriCourant = document.location.href;
	var file= uriCourant.split('=');

	var windowSizeY = $(window).height();
	var windowSizeX = $(window).width();
	var sizeFooter = $("#footer").height();
	var sizeTable = $("#table1").width();
	var newTop = windowSizeY - sizeFooter -1;

	var posAllpage = (windowSizeX/2) - 500;
	var posTable = 500 - (sizeTable/2);

	if (posAllpage < 100)
		posAllpage = 4;
	$("#allpage").css("left",posAllpage+"px");
	var tamp3 = posAllpage-50;
	var posLogo = posAllpage + 500 -(290)
	var posLogo2 = posAllpage + 500 -(148)
	$("#logo").css("left",posLogo+"px");
	$("#tridim").css("left",posLogo2+"px");
	$("#mention").css("left",posLogo2+250+"px");
	$("#tridim").css("top","60px");
	$("#mention").css("top","60px");
	$("#menuGen").css("left",posAllpage+"px");
	$("#menu").css("left",posAllpage+"px");
	$("#contenu").css("left",posAllpage+"px");
		
	$("#table1").css("left",posTable + "px");	
	
	if (windowSizeY >= 800)
	{
		var tamp = windowSizeY-240;
		var tamp2 = newTop -tamp -30 ;
		$("#allpage").css("height",windowSizeY+"px");
		$("#contenu").css("height",tamp +"px");
		$("#doubleBord").css("height",tamp +"px");
		$("#page").css("height",tamp +"px");	
		
		$("#Accessoire").css("height",tamp/2-75+"px");
		$("#Accessoire2").css("height",tamp/2+75 +"px");
		$("#accueil1").css("height",tamp/2 +"px");
		$("#accueil2").css("height",tamp/2 +"px");
		$("#imgBanquette").css("height",tamp*3/4 +"px");

		$("#photoCuivre1").css("top","100px");	
		$("#texteBois").css("top","100px");	
		$("#texteBois1").css("top","100px");	
		$("#photoCuivre2").css("top","130px");	
		$("#lampe").css("top","150px");	
		$("#access").css("top","150px");
		$("#table1").css("top","200px");	
		$("#table2").css("top","150px");	
	
		$("#map").css("height",tamp-150 +"px");
		$("#page").css("font-size","11px");
		$("#textePartition2").css("font-size","11px");
		$("#textePartition1").css("font-size","11px");
		
		
		$("#photo1").css("height",tamp/2-50+"px");

		$("#photo2").css("height",tamp/2-50+"px");
		$("#photo3").css("height",tamp/2-50+"px");
		$("#photo4").css("height",tamp/2-50+"px");

		$("#photo1").css("width","400px");
		$("#photo2").css("width","400px");	

		var newWidth1 = (((tamp/2-50)*373) / 569);
		var newWidth2= (((tamp/2-50)*1000) / 644);
	
		$("#photo3").css("width",newWidth1+"px");
		$("#photo4").css("width",newWidth2+"px");
		
		$("#support").css("height",tamp -40 +"px");
		$("#pane3").css("height",tamp -100 +"px");
		$("#pane1").css("height",tamp -40 +"px");		

		$("#support3").css("height",tamp +"px");

		$("#supportPartenaire").css("height",tamp +"px");
		$("#panePartenaire").css("height",tamp +"px");
		
		$("#support4").css("height",tamp +"px");
		$("#pane4").css("height",tamp+"px");
		
		$("#supportEquipe").css("height",tamp +"px");
		$("#paneEquipe").css("height",tamp+"px");

		$("#support2").css("height",tamp -40 +"px");
		$("#pane2").css("height",tamp -40 +"px");
		
		$("#footer").css("top",newTop+"px");
		$("#menuGen").css("top",newTop+ 5 +"px");
		$("#menu").css("top",newTop -18 +"px");
		$("#contenu").css("top",tamp2 +"px");

		$("#textePartition2").css("top","35px");
		$("#textePartition2").css("height","120px");
		$("#textePartition1").css("top",tamp+"px");
		$("#Accessoire").css("height","100px");	

	
	}
	else if ((windowSizeY > 600) && (windowSizeY < 800))
	{
		var tamp = windowSizeY-240;
		
		var tamp2 = newTop -tamp -30 ;
		$("#allpage").css("height",windowSizeY+"px");
		$("#contenu").css("height",tamp +"px");
		$("#access").css("top","25px");
		$("#accueil1").css("height",tamp/2 +"px");
		$("#accueil2").css("height",tamp/2 -15 +"px");
		$("#page").css("height",tamp +"px");
		$("#doubleBord").css("height",tamp +"px");
		$("#table1").css("top","100px");	
		$("#table2").css("top","50px");	
		$("#imgBanquette").css("height",tamp*3/4  +"px");
		$("#photoCuivre1").css("top","20px");	
		$("#texteBois").css("top","20px");	
		$("#texteBois1").css("top","20px");	
		$("#photoCuivre2").css("top","50px");
		
		$("#map").css("height",tamp-150 +"px");
		$("#page").css("font-size","11px");
		$("#textePartition2").css("font-size","11px");
		$("#textePartition1").css("font-size","11px");
		$("#Accessoire").css("height",tamp/2-75+"px");
		$("#Accessoire2").css("height",tamp/2+75 +"px");
	
		$("#photo1").css("height",tamp/2-50+"px");

		$("#photo2").css("height",tamp/2-50+"px");
		$("#photo3").css("height",tamp/2-50+"px");
		$("#photo4").css("height",tamp/2-50+"px");

		$("#photo1").css("width","400px");
		$("#photo2").css("width","400px");	

		var newWidth1 = (((tamp/2-50)*373) / 569);
		var newWidth2= (((tamp/2-50)*1000) / 644);
	
		$("#photo3").css("width",newWidth1+"px");
		$("#photo4").css("width",newWidth2+"px");
		
		$("#supportPartenaire").css("height",tamp +"px");
		$("#panePartenaire").css("height",tamp +"px");
		
		$("#support").css("height",tamp -40 +"px");
		$("#pane1").css("height",tamp -40 +"px");		

		
		$("#support3").css("height",tamp +"px");
		$("#pane3").css("height",tamp+"px");
		
		$("#supportEquipe").css("height",tamp +"px");
		$("#paneEquipe").css("height",tamp+"px");
		
		$("#support4").css("height",tamp +"px");
		$("#pane4").css("height",tamp+"px");

		$("#support2").css("height",tamp -40 +"px");
		$("#pane2").css("height",tamp -40 +"px");
		
		$("#footer").css("top",newTop+"px");
		$("#menuGen").css("top",newTop+ 5 +"px");
		$("#menu").css("top",newTop -18 +"px");
		$("#contenu").css("top",tamp2 +"px");
		
		$("#textePartition2").css("top","35px");
		$("#textePartition2").css("height","120px");
		$("#textePartition1").css("top",tamp+"px");

	}
	else
	 {
		$("#allpage").css("height","600px");
		$("#contenu").css("height","360px");

		$("#accueil1").css("height","105px");
		$("#accueil2").css("height","100px");
		$("#imgBanquette").css("height"," 300px");
		
		$("#page").css("font-size","10px");
		$("#textePartition2").css("font-size","10px");
		$("#textePartition1").css("font-size","10px");
		$("#page").css("height","360px");
		$("#Accessoire").css("height","144px");
		$("#Accessoire2").css("height","216px");
		$("#supportAcces").css("width","100px");
		$("#supportAcces2").css("width","100px");
		$("#supportAcces3").css("width","100px");
		$("#table1").css("top","50px");	
		$("#doubleBord").css("height","360px");
		$("#map").css("height","250px");
		$("#support").css("height","310px");
		$("#pane1").css("height","310px");
		
		$("#photo1").css("height","180px");
		$("#photo2").css("height","180px");
		
		$("#photo3").css("height","180px");
		$("#photo4").css("height","180px");
		
		$("#photo3").css("width","118px");
		$("#photo4").css("width","279px");
		
		$("#photo1").css("width","363px");
		$("#photo2").css("width","310px");
			
		$("#support3").css("height","350px");
		$("#pane3").css("height","350px");
		
		$("#support4").css("height","350px");
		$("#pane4").css("height","350px");

		$("#supportEquipe").css("height","350px");
		$("#paneEquipe").css("height","350px");
		
		$("#supportPartenaire").css("height","350px");
		$("#panePartenaire").css("height","350px");
		
		$("#support2").css("height","310px");
		$("#pane2").css("height","310px");

			
		$("#footer").css("top","520px");
		$("#menuGen").css("top","525px");
		$("#menu").css("top","504px");
		$("#contenu").css("top","130px");
		$("#textePartition2").css("top","20px");
		$("#textePartition1").css("top",tamp+"px");

	}

	if (windowSizeX > 1200)
	{
		$("#entete").css("width",windowSizeX+"px");
		$("#footer").css("width",windowSizeX+"px");
	}
	else
	{
		var sizeallPage = $("#allpage").width();
		var newWidth = posAllpage + sizeallPage;
		
		$("#entete").css("width",newWidth+"px");
		$("#footer").css("width",newWidth+"px");
	}

}

function afficheType(strthis)
{
if (strthis== "num")
	document.getElementById('sousType').style.display = 'block';
else document.getElementById('sousType').style.display = 'none';
}

function checkType(strthis)
{
	if (strthis== "queu")
	{
		$("#marque").empty().append("<option value='Bechstein'>Bechstein</option><option value='Sauter'>Sauter</option><option value='Seiler'>Seiler</option><option value='Kieffer'>Kieffer</option><option value='Petrof'>Petrof</option><option value='Kawai'>Kawai</option><option value='Brodmann'>Brodmann</option><option value='Hermann Jacobi'>Hermann Jacobi</option><option value='Samick'>Samick</option><option value='Schulze'>Schulze & Pollmann</option>");
	}
	else if (strthis== "num")
	{
		$("#marque").empty().append("<option value='Yamaha'>Yamaha</option><option value='Casio'>Casio</option><option value='Korg'>Korg</option><option value='kawai'>Kawai</option><option value='Roland'>Roland</option>");
	}

	
}

function checkQualite(strthis)
{

	if ((strthis== "promotion") || (strthis== "occasion"))
	{
		document.getElementById('marque').style.display = 'none';
		document.getElementById('autreMarque').style.display = 'block';
		checkType($("#type").value);
	}
	else
	{
		document.getElementById('marque').style.display = 'block';
		document.getElementById('autreMarque').style.display = 'none';
		checkType($("#type").value);
	}
		

}

function controleData()
{
	tinyMCE.triggerSave();
	var array = ['ref','prix','description','caractP'];
	var array1 = ['reference','prix','description','caracteristique principale'];
	for (i=0;i<array.length;i++)
	{
			
		if ($("#" + array[i]).val() == "")
		{
			alert("Vous n'avez pas rempli le champ : " + array1[i]);
			$("#"+ array[i]).focus();
			return false;
			
		}
		
	}
	
	if ($("#autreMarque").val() =="")
	{
			if (document.getElementById('marque').style.display == 'none')
			{
				alert("Vous n'avez pas rempli le champ : Marque");
				$("#autreMarque").focus();
				return false;
			}
	}
}

function add_value(strthis)
{

	$.post("loadModif.php", { marque: strthis},  
	
      function success(data){  
	 
			var liste = document.getElementById('touRef');
			var separateur = data.split("~");
			
			liste.options.length=1;
			for (i=0;i<separateur.length-1;i++)
			{
			//	separateur[i] = unescape(separateur[i])
			
				liste.length++;
				liste.options[liste.length-1].text =  separateur[i];
				//$("#touRef").length++;
			//	d.options[d.length-1].text = generMarque[i];
			//	$("#touRef").options[$("#touRef").length-1].text = separateur[i];
				
			}
	
			liste.style.display = 'block';
		}); 

}
	
function addValue2()
{	
	strthis2 =  document.getElementById('touRef').options[document.getElementById('touRef').selectedIndex].text
	
	tinyMCE.triggerSave();
	var liste1 = document.getElementById('touMarque');
	var chooseMarque = document.getElementById('chooseMarque');
	var liste2 = document.getElementById('touRef');
	var modifLoaded = document.getElementById('modifLoaded');
	
	liste1.style.display = 'none';
	chooseMarque.style.display = 'none';
	liste2.style.display = 'none';
	modifLoaded.style.display = 'block';

	
	$.post("loadModif_suite.php", {ref: strthis2},  

      function success(data){
	  
		
			var listeQualite = document.getElementById('qualite');
			var listeType = document.getElementById('type');
			var listeMarque = document.getElementById('marque');
			var listeSousType = document.getElementById('sousType');
		
			var separateur = data.split("~");

				for (j=0;j<listeQualite.length; j++)
				{
				
					var textListe = listeQualite[j].value.toLowerCase();
					
					var text = separateur[12].toLowerCase();
					var promo = separateur[15];
				
					if (textListe == text)
					{
						checkQualite(text);
						if (promo == 1)
						{
							checkQualite("promotion");
							listeQualite.options[2].selected = true;
						}
						else
							listeQualite.options[j].selected = true;
						
					}
				
					
				}
				
				var texte = separateur[9].toLowerCase();
				texte = trim(texte);
				
				if ((texte == "queu") || (texte == "droit"))
					listeType.options[0].selected = true;

				else if (texte == "num")
				{
					listeType.options[1].selected = true;
					
					var typeNum = separateur[10].toLowerCase();
					typeNum = trim(typeNum);
					
					if (typeNum == "salon") listeSousType.options[0].selected = true;
					else if (typeNum == "boite") listeSousType.options[1].selected = true;
					else  listeSousType.options[2].selected = true;
									
					afficheType("num");
					checkType("num");
				}				
				for (j=0;j<listeMarque.length; j++)
				{
					var textListe = listeMarque[j].value.toLowerCase();
					var marque = separateur[1].toLowerCase();
					
					
					marque = trim(marque);
					separateur[14] = separateur[14].replace("&eacute;","é");
					
					if (textListe == marque)
					{
						listeMarque.options[j].selected = true;
						
					}
					else
					{
						
						 document.getElementById('autreMarque').value= separateur[1];
					}
				}
				
				
				ed = window.tinyMCE.get("description"); // cible le champ à traiter
				ed.setContent(ed.getContent() + separateur[2]); // Ajoute du texte au texte déjà existant
				ed2 = window.tinyMCE.get("caractP"); // cible le champ à traiter
				ed2.setContent(ed2.getContent() + separateur[3]); // Ajoute du texte au texte déjà existant

				document.getElementById('photoPiano').src=  "./images/"+separateur[8];
				
				 document.getElementById('ref').value= separateur[0];
				 document.getElementById('id_piano').value= separateur[16];
				 document.getElementById('urlPhoto').value= separateur[8];
				 document.getElementById('hauteur').value= separateur[4];
				 document.getElementById('largeur').value= separateur[5];
				 document.getElementById('longueur').value= separateur[6];
				 document.getElementById('poids').value= separateur[7];
				 document.getElementById('finition').value= separateur[14];
				 document.getElementById('prix').value= separateur[13];

		}); 

}

function trim (myString)
{
	return myString.replace(/^\s+/g,'').replace(/\s+$/g,'');
} 
