function deleteElement(redirect, id, el) {
	var q = confirm ( "Voulez vous vraiment supprimer " + el + " ?" ) ;
	if (q) {
		document.location.href = redirect + ".php?id=" + id ;
	}
}

function showHide(layer) { 
	if (YAHOO.util.Dom.getStyle(layer,'display') == 'none')
		YAHOO.util.Dom.setStyle(layer,'display','block');
	else
		YAHOO.util.Dom.setStyle(layer,'display','none');
}

function selectSwitch(mSel,mValue,pId) {
	var mySelect = document.getElementById(mSel);
	var myValue = mySelect.options[mySelect.selectedIndex].value;
	if (myValue == mValue) {
		document.getElementById(pId).style.display = "block";
	}
	else {
		document.getElementById(pId).style.display = "none";
	}
}

function OpenNewWindow(lien,x,y) { 
      new_Window = window.open(lien,"new","toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes,menubar=yes,width="+x+",height="+y+",dependent=yes");
      new_Window.focus();
      new_Window.document.close(); 
}

function choix_img (img) {
	opener.document.ajoutNouvelle.image.value = img;
	window.close();
}

function add_user (user) {
	var txtAreLenght = opener.document.getElementById("dest").value;
	if (txtAreLenght == "") {
		opener.document.getElementById("dest").value += user;		
	}
	else {
		opener.document.getElementById("dest").value += "\n"+user;	
	}
	window.close();
}

function suppr_img (img) {
	var confirmation = confirm ( "Voulez vous vraiment supprimer " + img + " ?" ) ;
	if (confirmation) {
		document.location.href = "suppr-image.php?img=" + img ;
	}
}

function popup(url) {
	window.open(url,'popup',
	'alwaysRaised=yes,toolbar=no,height=420,width=500,menubar=no,resizable=yes,scrollbars=yes,status=no');

}

function makeThisCollectionMain (table,id) {
	var handleSuccess = function(o) {
		allImgs = YAHOO.util.Dom.getElementsByClassName('is_main_el','a');
		allImgs.forEach(function(e){
			YAHOO.util.Dom.replaceClass(e,'main','not_main');
		});
		YAHOO.util.Dom.replaceClass('is_main_el_' + id,'not_main','main');
	}
	
	var handleFailure = function(o) {
		return false;
	}

	var callback =	{ success:handleSuccess, failure:handleFailure }
	YAHOO.util.Connect.asyncRequest('GET', 'collection_make_it_main.php?id=' + id + '&table=' + table, callback);
}

function makeThisModelMain (id,id_coll) {
	var handleSuccess = function(o) {
		allImgs = YAHOO.util.Dom.getElementsByClassName('is_main_el','a');
		allImgs.forEach(function(e){
			YAHOO.util.Dom.replaceClass(e,'main','not_main');
		});
		YAHOO.util.Dom.replaceClass('is_main_el_' + id,'not_main','main');
	}
	
	var handleFailure = function(o) {
		return false;
	}

	var callback =	{ success:handleSuccess, failure:handleFailure }
	YAHOO.util.Connect.asyncRequest('GET', 'model_make_it_main.php?id=' + id + '&id_coll=' + id_coll, callback);
}

function onlineOffline (action,table,id) {
	var handleSuccess = function(o) {		
		var elt = YAHOO.util.Dom.get('online_offline_el_' + id);
		if (YAHOO.util.Dom.hasClass(elt,'offline')) {
			YAHOO.util.Dom.replaceClass(elt,'offline','online');
		}
		else {
			YAHOO.util.Dom.replaceClass(elt,'online','offline');
		}
		return true;
	}
	
	var handleFailure = function(o) {
		return false;
	}

	var callback =	{ success:handleSuccess, failure:handleFailure }
	YAHOO.util.Connect.asyncRequest('GET', '../inc/online_offline.php?action=' + action + '&table=' + table + '&id=' + id, callback);
}
var modelDlg;
function openModelBox(elt,fromElt,closeLabel,loadingLabel,title,url) {
	if (modelDlg == null) {
		modelDlg = new Ext.BasicDialog(elt, { 
										modal:true,
										width:550,
										height:420,
										shadow:false,
										syncHeightBeforeShow: true,
										constraintoviewport: true,
										fixedcenter: true,
										resizable: false,
										collapsible: false,
										proxyDrag: true
								});
	}
	
	modelDlg.body.load({
        url: url,
        scripts:true, 
        text: loadingLabel
   });
	modelDlg.setTitle(title);
	modelDlg.show(fromElt);
}
