// JavaScript Document
var userAgent=navigator.userAgent;
     if (userAgent.indexOf('MSIE') != -1) {
          window.attachEvent("onload", IE_CorrectAlpha_PNG);
}

function IE_CorrectAlpha_PNG(){
	for(i=0; i<document.images.length; i++){
		img    = document.images[i];
		imgExt  = img.src.substring(img.src.length-3, img.src.length);
		imgExt  = imgExt.toUpperCase();
		if (imgExt == "PNG"){
			imgID    = (img.id) ? "id='" + img.id + "' " : "";
			imgClass= (img.className) ? "class='" + img.className + "' " : "";
			imgTitle= (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
			imgStyle= "display:inline-block;" + img.style.cssText;
			if (img.align == "left") { imgStyle = "float:left;"  + imgStyle; } else if (img.align == "right"){ imgStyle = "float:right;" + imgStyle; }
			if (img.parentElement.href)   { imgStyle = "cursor:hand;" + imgStyle; }       
			strNewHTML    = '<span '+imgID+imgClass+imgTitle+' style="width:'+img.width+'px; height:'+img.height+'px;'+imgStyle+';'+'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+img.src+'\', sizingMethod=\'scale\');"></span>';
			img.outerHTML = strNewHTML;
			i = i-1;
		}
	}
}

function createXmlHttpRequestObject(){
//Récupération de XMLHttpRequest object
var xmlHttp;
	//Cela fonctionnera pour tous les navigateur excepté IE6 et plus vieux
	try{
	//On essaie de créer le XMLHttpRequest object
	xmlHttp = new XMLHttpRequest();
	}
	catch(e){
	// Prend en compte IE6 et plus vieu
	var XmlHttpVersions = new Array('MSXML2.XMLHTTP.6.0',
	'Msxml2.XMLHTTP.5.0',
	'Msxml2.XMLHTTP.4.0',
	'Msxml2.XMLHTTP.3.0',
	'Msxml2.XMLHTTP',
	'Microsoft.XMLHTTP');
	//On essai tout les prog jusqu'a ce qu'il fonctionne
		for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++)
		{
	  		try{
	  		// On essaie de créer XMLHttpRequest object
	 		 xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
	 		}
	  		catch (e) {} // On ignore les erreurs potentiel
	  	}
	}
//On retourne l'objet créé ou on affiche un message d'erreur.
	if (!xmlHttp)
	alert("Error creating the XMLHttpRequest object.");
	else
	return xmlHttp;
}

//On définit la variable xmlHttp pour qu'elle puisse être exploitée dans la fonction process, sinon les scripts utilisant AJAX ne fonctionne pas
var xmlHttp = createXmlHttpRequestObject();

function actualiserBlocZoomVisuel(value){

    var displayRecherche = value.responseText;
	v = displayRecherche.split('|')
    var blocAfficheText = document.getElementById('textVisuel');
    var blocAfficheVisuel = document.getElementById('visuel');
	var sourceImage = document.getElementById('imgVisuel').src;
	
	var tblimg = sourceImage.split('/');
	var longueur = tblimg.length;

	var src = '';
	var y = 0;
	for (var i = 0; i < longueur; ++i){
		
		y = y+1;
		
		if(longueur == y){
		tblimg[i] = v[1];	
		}
		src += tblimg[i];
			
		if(longueur > y){
		src += '/';
		}
		
	}
	
	blocAfficheText.innerHTML = v[0];
	blocAfficheVisuel.innerHTML = '<img id="imgVisuel" src="'+src+'" alt="Novabresse - Zoom sur les produits de notre gamme" />';
	
}
function displayVisuel(id){

	var xmlHttpEnvie = createXmlHttpRequestObject();
	xmlHttpEnvie.open('GET',url+'?num='+id,true);
	
	document.getElementById('textVisuel').innerHTML = 'loading process...';
	
		xmlHttpEnvie.onreadystatechange = function(){
			
			if(xmlHttpEnvie.readyState == 4){
						
				if(xmlHttpEnvie.status == 200){
				document.getElementById('textVisuel').innerHTML = 'Patientez...';
				actualiserBlocZoomVisuel(xmlHttpEnvie)
				}
						
			}
		
		}
	xmlHttpEnvie.send(null);
}
