// Fonction d'exécution des scripts Javascript asynchrones
function evalScript(scripts) {
	try	{
		if (scripts != '') {
			var script = "";
			scripts = scripts.replace(/<script[^>]*>([\s\S]*?)<\/script>/gi, function() {if (scripts !== null) script += arguments[1] + '\n'; return '';});
			if (script) (window.execScript) ? window.execScript(script) : window.setTimeout(script, 0);
		}
		return false;
	} catch(e) {
		alert(e);
	}
}

function swapImage(IdImg, parentDivId) {
	var obj1 = document.getElementById(parentDivId);
	var next = obj1.hasChildNodes();
	var xhr_object;
		   
	if(window.XMLHttpRequest) {
		xhr_object = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	} else { 
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");   
		return;
	}
	
	if(IdImg!=''){
		xhr_object.open("POST", "vtp_medias.php", true);
	} else{
		alert("pas d'id image"); 
	}
	
	xhr_object.onreadystatechange = function() {
		if(xhr_object.readyState == 4 && xhr_object.status == 200) {
			var divToChange = document.getElementById(parentDivId);
			divToChange.innerHTML = xhr_object.responseText;
			evalScript(xhr_object.responseText);
			//alert(divToChange.innerHTML);
		}
	}
	
	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
	var data = "IdImg="+IdImg;
	xhr_object.send(data);
}

//lien sur l'URL du site de l'image passée dans Title	
function getImageURL() {
	var obj = document.getElementById('contentFull');
	var titleUrl = obj.title;
	if (titleUrl=='') {
   		titleUrl = '#';
	}
   	window.open(titleUrl,"showURL","");
}
