﻿////////////////////////////////////////////////
//               J'AIME !!
///////////////////////////////////////////////

function ilike(id,contenu,action)
{
	$(document).ready(function () 
	{ 
        $.post("/ajax/ilike.php",{media_id: id, type_contenu: contenu, nocache: Math.random()},
        function success(data)
        { 
        	tooltip("off","150","ilike-"+id+"-"+contenu,data);
        	setTimeout("tooltip_close()",2000);
        	
	        $.post("/ajax/ilike_count.php",{media_id: id, type_contenu: contenu, nocache: Math.random()},
	        function success(data2)
	        { 
				var val_jaime = parseInt(data2);
				var imgt;
				
				if(val_jaime == 0) imgt="-0";
				if(val_jaime >= 1 && val_jaime <= 9) imgt="-1";
				if(val_jaime >= 10 && val_jaime <= 19) imgt="-10";
				if(val_jaime >= 20 && val_jaime <= 49) imgt="-20";
				if(val_jaime >= 50 && val_jaime <= 99) imgt="-50";
				if(val_jaime >= 100 && val_jaime <= 499) imgt="-100";
				if(val_jaime >= 500) imgt="-500";
				
				$("#val-ilike-"+id+"-"+contenu).html(val_jaime);
				
				$("#img-ilike-"+id+"-"+contenu).attr({src: "/images/fr/icones/jaime"+imgt+".png"});				
				$("#img-ilike-"+id+"-"+contenu).mouseout(function(){
					$("#img-ilike-"+id+"-"+contenu).attr({src: "/images/fr/icones/jaime"+imgt+".png"});
				});				
		    });
	    });
	});
}

////////////////////////////////////////////////
//           PUBLIER CONTENU
///////////////////////////////////////////////
function publier(id,contenu)
{
    $.post("/ajax/publier.php",{media_id: id, type_contenu: contenu, nocache: Math.random()},
    function success(data)
    { 
    	if($('#bt-publier-'+id+'-'+contenu).html() == "Publier")
    		$('#bt-publier-'+id+'-'+contenu).html("Dépublier");
    	else
    		$('#bt-publier-'+id+'-'+contenu).html("Publier");
    });
}

////////////////////////////////////////////////
//           AFFICHER BOUTON
///////////////////////////////////////////////
function affichBouton(btid,affich)
{
	if(affich)
		$('#'+btid).show();
	else
		$('#'+btid).hide();
}

////////////////////////////////////////////////
//               POPUP AJAX
///////////////////////////////////////////////
function dialogbox(url,width,btclose,title)
{
	window.location.href = '#';
	document.getElementById('dialogbox').style.width = width + "px";
	$('#dialogbox_title').html(title);
	$('#dialogbox_content').html('<img height="11" src="/images/interface/ajax-loader.gif" width="43" alt="Chargement...">');
	
	if(btclose == "off")
		$("#dialogbox_btclose").hide();
	else
		$("#dialogbox_btclose").show();
	
	var windowHeight = document.body.scrollHeight;
	var windowWidth = document.body.scrollWidth;
	
	document.getElementById('dialogbox').style.marginLeft = "-" + (width/2) + "px";
	$("#dialogbox").css({"top": document.body.scrollTop + 30});
    
	$("#global").css({"height": windowHeight,"width": windowWidth});
	$("#global").fadeIn(400);
	setTimeout("$('#dialogbox').slideDown(400)",500);
	
	$("#global").click(function(){dialogbox_off();});
	
	/*
	$.get(url,{nocache : Math.random()},
    function success(data)
    { 
    	$('#dialogbox_content').html(data);
    });	
    */
    
    var myurl = url;
    
	$.ajax({
		type: "GET",
		url : myurl,
		cache: false,
		success: function(data) 
		{
			$('#dialogbox_content').html(data);
		}
	});
}

var timeout;

function dialogbox_off()
{
	window.location.href = '#';
	clearTimeout(timeout);
	$('#dialogbox').fadeOut(400);
	setTimeout("$('#global').fadeOut(400)",400);
}

function dialogbox_wait()
{
	timeout = setTimeout("dialogbox_off()",5000); 
}

////////////////////////////////////////////////
//               INFO BULLES
///////////////////////////////////////////////
function tooltip(url,width,idref,reponse)
{
	$("#"+idref).append($("#tooltip"));
	$("#tooltip").css({"width": width, "margin-left": -(width/2)});
	$(".tooltip_border").css({"width": (width-24)/2 });
	$("#tooltip").css({"margin-top": -($("#tooltip").height()+10),"margin-left":-($("#tooltip").width()/2)});
	$('#tooltip').fadeIn(400);
	
	if(url == "off")
		$('#tooltip_content').html(reponse);        
	else
	{
		$.get(url+"&nocache="+Math.random(),{},
        function success(data)
        {	  
	    	$('#tooltip_content').html(data);		    	
	    });
	}
}

function tooltip_close()
{
	$('#tooltip').fadeOut(400);
}


////////////////////////////////////////////////
//        MODULE UPLOAD PROGRESS BAR
///////////////////////////////////////////////
function etatUpload(pt,func) 
{  
	var thekey = document.getElementById('keyFile').value;
  
	$.post(pt + "/ajax/upload_state.php",{keyFile: thekey, nocache: Math.random()},
	function success(data)
	{ 
		if(data != "false")
		{
			var response = eval('('+data+')');
			
			if(response.current != response.total)
			{
				currentOK = Math.round(response.current);
				if(currentOK <= 1000000000 && currentOK >= 1000000) 
				{
					currentOK = response.current/1000000;
					currentOK = currentOK.toFixed(2)+" Mo"
				} 
				else 
					if(currentOK <= 1000000 && currentOK >= 1000) 
					{
						currentOK = response.current/1000;
						currentOK = Math.round(currentOK)+" Ko"
					} 
					else 
						if(currentOK <= 1000 && currentOK >= 0)
							currentOK = Math.round(response.current)+" Octets"
				
				document.getElementById('currentVar').innerHTML = currentOK;
				
				totalOK = Math.round(response.total);
				if(totalOK <= 1000000000 && totalOK >= 1000000) 
				{
					totalOK = response.total/1000000;
					totalOK = totalOK.toFixed(2)+" Mo"
				} 
				else 
					if(totalOK <= 1000000 && totalOK >= 1000)
						totalOK = Math.round(response.total/1000)+" Ko"
					else 
						if(totalOK <= 1000 && totalOK >= 0)
							totalOK = Math.round(response.total)+" Octets"
				
				document.getElementById('total').innerHTML = totalOK;
				document.getElementById('progress').innerHTML = Math.round(response.current / response.total * 100) + '%';
				//$('#progressBar').animate({width : (response.current / response.total * 100) + '%'},500);
				$('#progressBar').css({"width" : (response.current / response.total * 100) + '%'});
				
				setTimeout("etatUpload('"+pt+"',"+func+")",200);
			}
			else
			{
				document.getElementById('progress').innerHTML = '100%';
				//$('#progressBar').animate({width : '100%'},500);
				$('#progressBar').css({"width" : '100%'});
				
				func();
			}
		} 
			
	});
}


////////////////////////////////////////////////
//        MODULE AJOUTER IMAGE
///////////////////////////////////////////////
function openSelect()
{
	document.getElementById("bouton-image-ajout").style.display = "none";
	document.getElementById("bouton-image-annuler").style.display = "";
	ouvrir("image-ajout");
}

function selectImage(id,src)
{
	document.getElementById("photo-selected").innerHTML = '<img id="mod-photo" src="'+src+'" width="70"/>';
	document.getElementById("photo-selected").innerHTML += '<input type="hidden" id="photo_id" name="photo_id" value="'+id+'"/>';
	document.getElementById("bouton-image-ajout").style.display = "none";
	document.getElementById("bouton-image-annuler").style.display = "";
	fermer("image-ajout");
	ouvrir("image-selected");
}

function urlImage()
{
	fermer("image-ajout");
	ouvrir("image-url");
}

function selectVideo()
{
	fermer("image-ajout");
	ouvrir("video-selected");
}

function uploadImage()
{
	document.getElementById("photo-selected").innerHTML = '<span class="txt11 gray">Fichier JPEG(.jpg) Max : 1,5 Mo</span><br/>';
	document.getElementById("photo-selected").innerHTML += '<input type="file" id="mod-photo-new" name="photo" class="contour_gris classic"/>';
	document.getElementById("bouton-image-ajout").style.display = "none";
	document.getElementById("bouton-image-annuler").style.display = "";
	fermer("image-ajout");
	ouvrir("image-selected");
}

function annulerSelect()
{
	fermer("image-ajout");
	fermer("image-selected");
	fermer("image-url");
	fermer("video-selected");
	
	document.getElementById("mod-video").value = "";
	document.getElementById("mod-imgurl").value = "";
	
	if(document.getElementById("mod-photo-new"))
		document.getElementById("mod-photo-new").value = "";
	if(document.getElementById("photo_id"))
		document.getElementById("photo_id").value = "";
		
	document.getElementById("bouton-image-annuler").style.display = "none";
	document.getElementById("bouton-image-ajout").style.display = "";
	setTimeout('document.getElementById("photo-selected").src = ""',400);
}


////////////////////////////////////////////////
//               COMPARE DATES
///////////////////////////////////////////////
function compareDate(dated,datef)
{
	for(i = (10 - dated.length); i >= 1; i--)
	{
		if(i == 3 || i == 6)
			c = "/";
		else
			c = "0";
			
		dated = c + dated;	
	}
	for(i = (10 - datef.length); i >= 1; i--)
	{
		if(i == 3 || i == 6)
			c = "/";
		else
			c = "0";
			
		datef = c + datef;	
	}
	var str1 = dated;
	var str2 = datef;		
	var dt1  = parseInt(str1.substring(0,2),10);
	var mon1 = parseInt(str1.substring(3,5),10);
	var yr1  = parseInt(str1.substring(6,10),10);
	var dt2  = parseInt(str2.substring(0,2),10);
	var mon2 = parseInt(str2.substring(3,5),10);
	var yr2  = parseInt(str2.substring(6,10),10);
	var date1 = new Date(yr1, mon1, dt1);
	var date2 = new Date(yr2, mon2, dt2);
	
	if(date2 < date1)
		return false;
	else
		return true;
}


////////////////////////////////////////////////
//     COMPARE DATES INFINITE (150 ans)
///////////////////////////////////////////////
function compareDateInfinite(dated)
{
	aujourdhui = new Date(); 
	
	for(i = (10 - dated.length); i >= 1; i--)
	{
		if(i == 3 || i == 6)
			c = "/";
		else
			c = "0";
			
		dated = c + dated;	
	}
	var str1 = dated;
	var yr1  = parseInt(str1.substring(6,10),10);
	var yr2  = aujourdhui.getFullYear();
	
	if(yr1 > (yr2+150))
		return false;
	else
		return true;
}

////////////////////////////////////////////////
//               OVER IMAGES
///////////////////////////////////////////////
function imageChange(img2replace,imgNew)
{
	document.getElementById(img2replace).className = "invisible";
	document.getElementById(imgNew).className = "visible";
}

////////////////////////////////////////////////
//               CHANGER TEXTE
///////////////////////////////////////////////
function textChange(id,txt1,txt2)
{
	if(document.getElementById(id).innerHTML == txt1)
		document.getElementById(id).innerHTML = txt2;
	else
		document.getElementById(id).innerHTML = txt1;
}

////////////////////////////////////////////////
//               POPUP HTML
///////////////////////////////////////////////
function popup(page,largeur,hauteur)
{
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+",scrollbars=yes,resizable=yes,toolbar=no,status=no,menubar=no,location=no,directories=no");
}


////////////////////////////////////////////////
//               DEPLIER JQUERY
///////////////////////////////////////////////
function slide(id) {
      $('#'+id).slideToggle(300);
};
function ouvrir(id) {
      $('#'+id).slideDown(300);
};
function fermer(id) {
      $('#'+id).slideUp(300);
};


////////////////////////////////////////////////
//    MODULE CONFIDENTIALITE DU CONTENU
///////////////////////////////////////////////
function checkConfidentialite(me,iconf)
{
	if(me.value == "MONDE")
	{
		document.getElementById("conf-AMIS-"+iconf).checked = false;
		document.getElementById("conf-FAMILLE-"+iconf).checked = false;
		document.getElementById("conf-FAVORIS-"+iconf).checked = false;
		document.getElementById("conf-MONDE-"+iconf).checked = true;
	}
	else
		document.getElementById("conf-MONDE-"+iconf).checked = false;
}


////////////////////////////////////////////////
//               TRIM
///////////////////////////////////////////////
function trim(stringToTrim) 
{
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) 
{
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) 
{
	return stringToTrim.replace(/\s+$/,"");
}

////////////////////////////////////////////////
//          PLUS / MOINS QUANTITE
///////////////////////////////////////////////
function plus(id) 
{
	document.getElementById(id).value = parseInt(document.getElementById(id).value)+1;
	NbProduit[0]=document.getElementById(id).value
}
function moins(id) 
{
	if (parseInt(document.getElementById(id).value) > 1)
	{
		document.getElementById(id).value = parseInt(document.getElementById(id).value)-1;
		NbProduit[0]=document.getElementById(id).value
	}
}

////////////////////////////////////////////////
//          POPUP IMAGE LIEN EXTERNE
///////////////////////////////////////////////
function PopupImage(img,Titre) {
	w=open("",'image','width=400,height=400,toolbar=no,scrollbars=yes,resizable=yes');	
	w.document.write("<HTML><HEAD><TITLE>"+Titre+"</TITLE></HEAD>");
	w.document.write("<SCRIPT language=javascript>function checksize()  { if (document.images[0].complete) {  window.resizeTo(document.images[0].width+50,document.images[0].height+100); window.focus();} else { setTimeout('check()',250) } }</"+"SCRIPT>");
	w.document.write("<BODY onload='checksize()'><IMG src='"+img+"' border=0>");
	w.document.write("");
	w.document.write("</BODY></HTML>");
	w.document.close();
}

////////////////////////////////////////////////
//          FONCTION ISNUMERIC
///////////////////////////////////////////////
function isNumber(x) 
{ 
  return ( (typeof x === typeof 1) );
}

/** I HATE IE **/
// IE5.5+ PNG Alpha Fix v2.0 Alpha: Background Tiling Support
// (c) 2008-2009 Angus Turnbull http://www.twinhelix.com

// This is licensed under the GNU LGPL, version 2.1 or later.
// For details, see: http://creativecommons.org/licenses/LGPL/2.1/

var IEPNGFix = window.IEPNGFix || {};

IEPNGFix.tileBG = function(elm, pngSrc, ready) {
	// Params: A reference to a DOM element, the PNG src file pathname, and a
	// hidden "ready-to-run" passed when called back after image preloading.

	var data = this.data[elm.uniqueID],
		elmW = Math.max(elm.clientWidth, elm.scrollWidth),
		elmH = Math.max(elm.clientHeight, elm.scrollHeight),
		bgX = elm.currentStyle.backgroundPositionX,
		bgY = elm.currentStyle.backgroundPositionY,
		bgR = elm.currentStyle.backgroundRepeat;

	// Cache of DIVs created per element, and image preloader/data.
	if (!data.tiles) {
		data.tiles = {
			elm: elm,
			src: '',
			cache: [],
			img: new Image(),
			old: {}
		};
	}
	var tiles = data.tiles,
		pngW = tiles.img.width,
		pngH = tiles.img.height;

	if (pngSrc) {
		if (!ready && pngSrc != tiles.src) {
			// New image? Preload it with a callback to detect dimensions.
			tiles.img.onload = function() {
				this.onload = null;
				IEPNGFix.tileBG(elm, pngSrc, 1);
			};
			return tiles.img.src = pngSrc;
		}
	} else {
		// No image?
		if (tiles.src) ready = 1;
		pngW = pngH = 0;
	}
	tiles.src = pngSrc;

	if (!ready && elmW == tiles.old.w && elmH == tiles.old.h &&
		bgX == tiles.old.x && bgY == tiles.old.y && bgR == tiles.old.r) {
		return;
	}

	// Convert English and percentage positions to pixels.
	var pos = {
			top: '0%',
			left: '0%',
			center: '50%',
			bottom: '100%',
			right: '100%'
		},
		x,
		y,
		pc;
	x = pos[bgX] || bgX;
	y = pos[bgY] || bgY;
	if (pc = x.match(/(\d+)%/)) {
		x = Math.round((elmW - pngW) * (parseInt(pc[1]) / 100));
	}
	if (pc = y.match(/(\d+)%/)) {
		y = Math.round((elmH - pngH) * (parseInt(pc[1]) / 100));
	}
	x = parseInt(x);
	y = parseInt(y);

	// Handle backgroundRepeat.
	var repeatX = { 'repeat': 1, 'repeat-x': 1 }[bgR],
		repeatY = { 'repeat': 1, 'repeat-y': 1 }[bgR];
	if (repeatX) {
		x %= pngW;
		if (x > 0) x -= pngW;
	}
	if (repeatY) {
		y %= pngH;
		if (y > 0) y -= pngH;
	}

	// Go!
	this.hook.enabled = 0;
	if (!({ relative: 1, absolute: 1 }[elm.currentStyle.position])) {
		elm.style.position = 'relative';
	}
	var count = 0,
		xPos,
		maxX = repeatX ? elmW : x + 0.1,
		yPos,
		maxY = repeatY ? elmH : y + 0.1,
		d,
		s,
		isNew;
	if (pngW && pngH) {
		for (xPos = x; xPos < maxX; xPos += pngW) {
			for (yPos = y; yPos < maxY; yPos += pngH) {
				isNew = 0;
				if (!tiles.cache[count]) {
					tiles.cache[count] = document.createElement('div');
					isNew = 1;
				}
				var clipR = Math.max(0, xPos + pngW > elmW ? elmW - xPos : pngW),
					clipB = Math.max(0, yPos + pngH > elmH ? elmH - yPos : pngH);
				d = tiles.cache[count];
				s = d.style;
				s.behavior = 'none';
				s.left = (xPos - parseInt(elm.currentStyle.paddingLeft)) + 'px';
				s.top = yPos + 'px';
				s.width = clipR + 'px';
				s.height = clipB + 'px';
				s.clip = 'rect(' +
					(yPos < 0 ? 0 - yPos : 0) + 'px,' +
					clipR + 'px,' +
					clipB + 'px,' +
					(xPos < 0 ? 0 - xPos : 0) + 'px)';
				s.display = 'block';
				if (isNew) {
					s.position = 'absolute';
					s.zIndex = -999;
					if (elm.firstChild) {
						elm.insertBefore(d, elm.firstChild);
					} else {
						elm.appendChild(d);
					}
				}
				this.fix(d, pngSrc, 0);
				count++;
			}
		}
	}
	while (count < tiles.cache.length) {
		this.fix(tiles.cache[count], '', 0);
		tiles.cache[count++].style.display = 'none';
	}

	this.hook.enabled = 1;

	// Cache so updates are infrequent.
	tiles.old = {
		w: elmW,
		h: elmH,
		x: bgX,
		y: bgY,
		r: bgR
	};
};


IEPNGFix.update = function() {
	// Update all PNG backgrounds.
	for (var i in IEPNGFix.data) {
		var t = IEPNGFix.data[i].tiles;
		if (t && t.elm && t.src) {
			IEPNGFix.tileBG(t.elm, t.src);
		}
	}
};
IEPNGFix.update.timer = 0;

if (window.attachEvent && !window.opera) {
	window.attachEvent('onresize', function() {
		clearTimeout(IEPNGFix.update.timer);
		IEPNGFix.update.timer = setTimeout(IEPNGFix.update, 100);
	});
}


