/**
* Action System Installation
*
* @author	  RaphaeL Pralat <raph@plus2.fr>
* @version    CVS: $Id:$
* @uses       http://prototype.conio.net/
* @uses       http://bennolan.com/behaviour/
* @uses       http://script.aculo.us
*/

var						ActionCommon = {

	rules :				{
	
	'#lauchUpload' : function(el) {
		el.onclick = function() {
			$('formUpload').submit();
			if($F('fileToUpload') != '') {
				var uploadId = findParamInClass('uploadId',this);
				beginUpload(uploadId);
			} else {
			}
		}
	},
		
		
	/**
	 * List Order Action
	 *
	 */
	'.listOrderClickAction' : function(el) {
		el.onclick = function() {
			
			var uriType = findParamInClass('type', this);
			ActionCommon.searchAction(uriType);
		}
	},
	
	'.listOrderAction' : function(el) {
		el.onchange = function() {
			
			var uriType = findParamInClass('type', this);
			ActionCommon.searchAction(uriType);
		}
	},
	
	
	/**
	 * List Order Action
	 *
	 */
	'.listSearchAction' : function(el) {
		el.onclick = function() {
			var type = findParamInClass('type', this);
			var id = findParamInClass('id', this);
			var uri = $F('uri' + type);
			
			if ($('searchKeyword' + type + id)) {
				var reg = new RegExp( ".{1}keyword=[a-zA-Z%0-9]*");
				uri = uri.replace(reg, '');
				
				var keyword = $F('searchKeyword' + type + id);
				keyword = encodeURIComponent(keyword);
				
				if (keyword) {
					uri = uri + '&keyword=' + keyword;
				}
			}
			uri = uri.replace('/liste&', '/liste?');
			window.location=uri;
		}
	},
	
	/**
	 * Ajax Search Action
	 *
	 */
	'.ajaxPaginationAction' : function(el) {
		el.onclick = function() {
			var page;
			var action;
			var id;
			var arg;
			
			page = findParamInClass('page', this);
			action = findParamInClass('action', this);
			id = findParamInClass('id', this);
			arg = findParamInClass('arg', this);
			
			if (action && page) {
				var form = "action=pagination&page=" + page + "&id=" + id + "&arg=" + arg;
				new Ajax.Updater(id, action, {
					parameters	: form,
					method		: 'post',
					onComplete	: ActionCommon.reload
				});
			}
		}
	},
	
	/**
	 *Entity (User Or Group) Browser
	 *
	 */
	'.browserAction' : function(el) {
		el.onclick = function() {
			
			var action = findParamInClass("action", this)
			var type = findParamInClass("type", this)
			var id = findParamInClass("id", this)
			var idContent = findParamInClass("idContent", this)
			var path = findParamInClass("path", this)
			var name = findParamInClass("name", this)
			var display = findParamInClass("display", this)
			var page = findParamInClass("page", this)
			var allow = findParamInClass("allow", this)
			var loop = findParamInClass("loop", this)
			var param;
			
			param = "action=" + action + "&type=" + type + "&id=" + id + "&display=" + display + "&page=" + page + "&idContent=" + idContent + "&allow=" + allow + "&loop=" + loop;
			
			
			if ($(type + 'BrowserForm')) {
				param = param + "&" + $(type + 'BrowserForm').serialize();
			}
			
			if (action == 'show') {
				$(type + 'Browser').style.display = "block";
			} else if (action == 'hide') {
				$(type + 'Browser').style.display = "none";
			}
			
			// Return Value From Browser
			if (action == 'return') {
				if (type == 'entity') {
					param = param + "&entityType=" + $F('entityType');
					
					//if (display == 'group' || display == 'event') {
					if (display) {
						if (!$(display + 'EntityContent' + id)) {
							if (loop == 1) {
								$(display + 'EntityContent').innerHTML = '<div id="' + display + 'EntityContent' + id + '" style="margin:5px;"><input type="hidden" name="' + display + 'EntityType' + id +'" value="' + $F('entityType') + '"><input type="hidden" name="' + display + 'EntityId' + id + '" value="' + id + '"><input type="hidden" name="' + display + 'EntityTitleFormat' + id + '" value="' + name + '">' + name + ' <select name="relationStatus' + id + '" style="border:1px solid #000;"><option value="owner">propriétaire</option><option value="user">membre</option></select><span class="textBold">titre</span> <input type="text" name="relationTitle' + id + '" style="border:1px solid #000;" /> <a href="javascript:void(0);" class="browserAction type_entity action_deleteReturn id_' + id + ' display_'+ display +'">delete</a></div>';
							} else {
								$(display + 'EntityContent').innerHTML = $(display + 'EntityContent').innerHTML + '<div id="' + display + 'EntityContent' + id + '" style="margin:5px;"><input type="hidden" name="' + display + 'EntityType' + id +'" value="' + $F('entityType') + '"><input type="hidden" name="' + display + 'EntityId' + id + '" value="' + id + '"><input type="hidden" name="' + display + 'EntityTitleFormat' + id + '" value="' + name + '">' + name + ' <select name="relationStatus' + id + '" style="border:1px solid #000;"><option value="owner">propriétaire</option><option value="user">membre</option></select><span class="textBold">titre</span> <input type="text" name="relationTitle' + id + '" style="border:1px solid #000;" /> <a href="javascript:void(0);" class="browserAction type_entity action_deleteReturn id_' + id + ' display_'+ display +'">delete</a></div>';
							}
						}
					}
					/*
					else if (display == 'event') {
						$('eventEntityContent').innerHTML = $('eventEntityContent').innerHTML + '<div id="eventEntityContent' + id +'" style="margin:5px;"><input type="hidden" name="eventEntityType" value="' + $F('entityType') + '"><input type="hidden" name="eventEntityId" value="' + id + '">' + name + ' <a href="javascript:void(0);" class="browserAction type_entity action_deleteReturn id_' + id + ' display_'+ display +'">delete</a></div>';
					}
					*/
				} else if (type == 'image') {
					$('imageContent').innerHTML = '<div id="eventEntityContent"><input type="hidden" name="imageId" value="' + id + '"><input type="hidden" name="imageThumbnail" value="' + name + '"><img src="' + name + '"></div>';
				} else if (type == 'media' && idContent) {
					$('mediaContent' + idContent).innerHTML = '<img src="'+ path +'" width="80" /><input type="hidden" name="mediaId'+ idContent +'" value="'+ id +'" /><br />' + name;
				}
				
				$(type + 'Browser').style.display = "none";
			}
			
			if (action == 'deleteReturn') {
				if (type == 'entity' || display == 'event') {
					if (display) {
						if (id) {
							$(display + 'EntityContent' + id).innerHTML = "";
						} else {
							$(display + 'EntityContent').innerHTML = "";
						}
					}
				}
			}
			
			// Ajax Action
			new Ajax.Updater(type + 'BrowserContent', '/ajax/browser', {
				parameters	: param,
				method		: 'post',
				onComplete	: ActionCommon.reload
			});
		}
	},
	
	'lastbutnotleast': {}
	}, /** rules **/
	
	'reload' :	function(ajax) {
		 Behaviour.apply(ActionUser.rules);
	},
	
	/**
	 * Redirection à la porc quand la connection n'est pas bonne
	 *
	 *
	 */
	'testLogin' :	function(ajax) {
		
		var testLogin = $('testLogin');
		Behaviour.apply(ActionUser.rules);
		if (testLogin == null) {
			window.location.href = "/membre/connexion"
		}
	},
	
	'searchAction' :	function(uriType) {
		var order;
		var type;
		var connect;
		var town;
		var country;
		var uri;
		
		if ($('uri' + uriType)) {
			uri = $F('uri' + uriType);
		}
		
		if ($('searchKeyword')) {
			var reg = new RegExp( ".{1}keyword=[a-zA-Z%]*");
			var uri = uri.replace(reg, '');
			keyword = $F('searchKeyword');
			if (keyword) {
				uri = uri + '&keyword=' + keyword;
			}
		}
		if ($('searchOrder')) {
			var reg = new RegExp( ".{1}order=[a-zA-Z%]*");
			var uri = uri.replace(reg, '');
			order = $F('searchOrder');
			if (order) {
				uri = uri + '&order=' + order;
			}
		}
		if ($('searchStatus')) {
			var reg = new RegExp( ".{1}status=[a-zA-Z%]*");
			var uri = uri.replace(reg, '');
			status = $F('searchStatus');
			if (status) {
				uri = uri + '&status=' + status;
			}
		}
		if ($('searchConnect')) {
			var reg = new RegExp( ".{1}connect=[a-zA-Z%]*");
			var uri = uri.replace(reg, '');
			connect = $F('searchConnect');
			if (connect) {
				uri = uri + '&connect=' + connect;
			}
		}
		if ($('searchType')) {
			var reg = new RegExp( ".{1}type=[a-zA-Z%]*");
			var uri = uri.replace(reg, '');
			type = $F('searchType');
			if (type) {
				uri = uri + '&type=' + type;
			}
		}
		if ($('searchTown')) {
			var reg = new RegExp( ".{1}town=[a-zA-Z%]*");
			var uri = uri.replace(reg, '');
			town = $F('searchTown');
			if (town) {
				uri = uri + '&town=' + town;
			}
		}
		if ($('searchCountry')) {
			var reg = new RegExp( ".{1}country=[a-zA-Z%]*");
			var uri = uri.replace(reg, '');
			country = $F('searchCountry');
			if (country) {
				uri = uri + '&country=' + country;
			}
		}
		if ($('searchConsult')) {
			var reg = new RegExp( ".{1}consult=[a-zA-Z%]*");
			var uri = uri.replace(reg, '');
			country = $F('searchConsult');
			if (country) {
				uri = uri + '&consult=' + country;
			}
		}
		if ($('searchLength')) {
			var reg = new RegExp( ".{1}length=[a-zA-Z%]*");
			var uri = uri.replace(reg, '');
			length = $F('searchLength');
			if (length) {
				uri = uri + '&length=' + length;
			}
		}
		if ($('searchRecent')) {
			var reg = new RegExp( ".{1}recent=[a-zA-Z%]*");
			var uri = uri.replace(reg, '');
			country = $F('searchRecent');
			if (country) {
				uri = uri + '&recent=' + country;
			}
		}
		
		// Do this
		//uri = uri.replace('/liste&', '/liste?');
		// Or This
		uri = uri.replace('/?', '/&');
		
		window.location=uri;
	},
	
	'redirectHome' :	function(ajax) {
		window.location.href = "/"
	}
}

function findParamInClass(param, el) {
   var regexp = new RegExp(param + '_([A-Za-z0-9/:?&\-\._]+)');
   var mymatch = regexp.exec(el.className);
   if(mymatch) {
       return mymatch[1];
   }
   return false;
}

Behaviour.register(ActionCommon.rules);

/*  v1.1.0, 14:00:00 31 jul 2007 Liang @YOUJOB

	Action Add and Replace Div 
	ParentNode Name must be 'dragdropDiv'
	Need prototype and scriptaculous

	addTags(actionAdd)
	@param Num actonAdd (0:no Alert; 1:Alert All Tags)
*/

sections = [];
var dragobj={};
var tagdivId = 0;
var addToPlace = 'dragdropDiv';
var totalTagsIdSort = '';
var totalTagsTitleSort = '';
var tagdivPos = '';
var mmAllTagsId = '';
var mmAllTagsTitle = '';
var mmAllTagsType = '';


var						EditTagAction = {

	rules :				{
		
		'.editTagAction' : function(el) {
			el.onclick = function() {
				var id;
				var type;
				var action;
				var title;
				var form;
				var db
				
				id = findParamInClass('id', this);
				type = findParamInClass('type', this);
				action = findParamInClass('action', this);
				db = findParamInClass('db', this);
				title = chksafe($F('tagName'));
				
				// just display
				if (action == "add") {
					addTags(0, 0, 0);
				}
				// insert mode
				else if (action == "insert") {
					form = "id=" + id + "&type=" + type + "&action=" + action  + "&title=" + title + "&pos=" +  tagdivId;
					new Ajax.Updater('tagDivAction', "/ajax/tagEdit", {
						parameters	: form,
						method		: 'post',
						onComplete	: EditTagAction.reload,
						asynchronous:false
					});
					// Get Tag Id previously displayed in ajax
					addTags(1, $F('newId'), 1);
				}
				// when move position in insert mode
				else if (action == "update") {
					
					
				}
				else if (action == "delete") {
					if  (db == 1 ){
					var form = "id=" + id + "&type=" + type + "&action=" + action  + "&title=" + title;
					new Ajax.Updater('tagDivAction', "/ajax/tagEdit", {
						parameters	: form,
						method		: 'post',
						onComplete	: EditTagAction.reload,
						asynchronous:false
					});
					}
					deldiv(this);
					// make condition, if id, then ajax to delete in db
				}
			}
		},
		
		
		'.dragdropDiv' : function(el) {
			el.onmouseover = function() {
				
				on_ini_div();	
			
				document.onselectstart=function(){return false}
				window.onfocus=function(){document.onmouseup()}
				window.onblur=function(){document.onmouseup()}
					
					var o=$('dragdropDiv').getElementsByTagName("h1")
					for(var i=0;i<o.length;i++){
						o[i].onmousedown=addevent;
					}
					tagdivId = $('dragdropDiv').getElementsByClassName('tags').length;
					
				document.onmouseup=function(){
					if(dragobj.o!=null){
						dragobj.otemp.parentNode.insertBefore(dragobj.o,dragobj.otemp)
						dragobj.o.style.position=""
						oDel(dragobj.otemp)
						dragobj={}
						if (tagdivPos != ''){
							getAlltags(0,1);
							if(tagdivPos != totalTagsIdSort){
								tagdivPos = totalTagsIdSort;
								updateTagPos(tagdivPos);
							}
						}
						else if (mmAllTagsTitle != ''){
							getAlltags(0,0);
							if(mmAllTagsTitle != totalTagsTitleSort){
								mmAllTagsTitle = totalTagsTitleSort;
								$('mmAllTagsTitle').value = mmAllTagsTitle;
							}
						}
					}
				}

				document.onmousemove=function(e){
					e=e||event
					if(dragobj.o!=null){

						dragobj.o.style.left=(e.x-dragobj.xx[0])+"px"
						dragobj.o.style.top=(e.y-dragobj.xx[1])+"px"
						createtmpl(e)
					}
				}
				
				window.onerror=function(){return false};
				window.oDel=function(obj){if($(obj)!=null){$(obj).parentNode.removeChild($(obj))}};		
			}	
		},
		'.dragdropH1' : function(el) {
			el.onmousedown = function() {				 

					
			}
		}
		
	}
}

Behaviour.register(EditTagAction.rules);

// FileUpload required

/**
 *	File : Begin Upload
*/
// this variable is VERY important !
var finished = false;

//start functions 
/**
* you have to pass an uniq id in param
* @see lauchUpload function in the same page but this function is used with behaviour
*/
function beginUpload(sid) {
	//define vars
	var title = "";
	var description = "";
	if ($('fileTitle')) {
		title = $F('fileTitle')
	}
	if ($('fileDescription')) {
		description = $F('fileDescription')
	}
	
	var uform = $('formUpload');
	var udivform = $('divFormUpload');
	var upb = $('progressouter');
	if (uform.fileToUpload.value=="") {
		return; //no file, no upload
	}
	// set error message at blank
	$('errorMsg').innerHTML = '';
	//make appear the progress bar
	udivform.style.display = 'none';
	upb.style.display = 'block';
	//redefine where the form post goes
	uform.action = '/cgi-bin/upload.cgi?sid='+sid+'&maxsize=524288000';
	uform.submit();
	//ajax magic
	uploadUpdater = new Ajax.PeriodicalUpdater('','/upload/index', {'frequency' : 1,
																					'encoding':'UTF-8',
																				    'method': 'post',
																					'parameters': 'progress=' + sid + '&title=' + title + '&description=' + description,
																					'onSuccess' : updateProgress,
																					'onFailure' : updateProgress
																					});
}

/**
 *	FileUpload : update progress bar
 * this is the function call by ajax updater
*/
function updateProgress(req, el) {
	if (finished) return;
	var pb = $('progressinner');
	var pbText = $('pbtext');
	//we expect a number
	var percent = parseInt(req.responseText);
	//not a number... so that's FINISHED or else ...
	if (isNaN(percent)) {
		finished = true;
		uploadUpdater.stop();
		if (req.responseText.indexOf("FINISHED") > -1) {
			pb.style.width = "0%";
			pbText.innerHTML = "100%";
			setTimeout('endProgress(this)', 2000);
			$('errorMsg').innerHTML= 'Fichier reçu';
			return;
		}
		pb.style.width="0%";
		pbText.innerHTML = "100%";
		$('errorMsg').innerHTML= req.responseText;
		setTimeout('endProgress()', 2000);
	} else {
		// is a percentage in response so show it to the user
		if(!percent) percent = 0;
		if(percent > 100) percent = 100;
		showPercent = 100 - percent;
		pb.style.width = ""+showPercent+"%";
		pbText.innerHTML = ""+percent+"%";
	}
}

/**
* File : at the end of upload param id
*/
function endProgress(el) {
	// hide progress bar and show form
	var udivform = $('divFormUpload');
	var upb = $('progressouter');
	udivform.style.display = 'block';
	upb.style.display = 'none';
	// reset error message
	$('errorMsg').innerHTML = '';
	//reset form
	var uform = $('formUpload');
	uform.reset();
	// show the initial bar
	var pb = $('progressinner');
	pb.style.width = "100%";
	finished = false;
	
	var reloadType = $F('reloadType');
	var reloadAction = $F('reloadAction');
	var reloadDisplay = $F('reloadDisplay');
	
	param = "action=" + reloadAction + "&type=" + reloadType;
	if (reloadDisplay) {
		new Ajax.Updater(reloadDisplay, '/ajax/browser', {
			parameters	: param,
			method		: 'post',
			onComplete	: ActionCommon.reload
		});
	}
		
}

// end FileUpload Required

/**
 *	Tag : 
*/
function on_ini_div(){
	String.prototype.inc=function(s){return this.indexOf(s)>-1?true:false}
	var agent=navigator.userAgent
	window.isOpr=agent.inc("Opera")
	window.isIE=agent.inc("IE")&&!isOpr
	window.isMoz=agent.inc("Mozilla")&&!isOpr&&!isIE
	if(isMoz){
		Event.prototype.__defineGetter__("x",function(){return this.clientX})
		Event.prototype.__defineGetter__("y",function(){return this.clientY})
		Event.prototype.__defineGetter__("srcElement",function(){var node=this.target;while(node.nodeType!=1)
{node=node.parentNode}return node})
	}

}


/**
 *	Tag : 
*/
function addevent(e){
			on_ini_div();
			if(dragobj.o!=null)
				return false
			e=e||event
			var ee=e.srcElement
			if(ee.tagName=="FONT")
				return
			dragobj.o=this.parentNode
			dragobj.xy=getxy(dragobj.o)
			dragobj.xx=new Array((e.x-dragobj.xy[1]),(e.y-dragobj.xy[0]))
			dragobj.o.style.left=(e.x-dragobj.xx[0])+"px"
			dragobj.o.style.top=(e.y-dragobj.xx[1])+"px"			
			dragobj.o.style.position="absolute"
			var om=document.createElement("div")
			dragobj.otemp=om
			om.className="divmoving";
			om.Id="divmoving";
			dragobj.o.parentNode.insertBefore(om,dragobj.o)
			return false
}

/**
 *	Tag : 
*/
function getxy(e){
	var a=new Array()
	var t=e.offsetTop;
	var l=e.offsetLeft;
	var w=e.offsetWidth;
	var h=e.offsetHeight;
	while(e=e.offsetParent){
		
		 if ( e.style.position == 'absolute' || e.style.position == 'relative' || ( e.style.overflow != 'visible' && e.style.overflow != '' ) )
        {
            break;
        } 
        
		t+=e.offsetTop;
		l+=e.offsetLeft;
	}
	a[0]=t;a[1]=l;a[2]=w;a[3]=h
  return a;
}

/**
 *	Tag : 
*/
function inner(o,e){
	var a=getxy(o)
	if(e.x>a[1] && e.x<(a[1]+a[2]) && e.y>(a[0]) && e.y<(a[0]+a[3])){
		if(e.x<(a[1]+a[2]/2)){
			return 1;
		}
		else{
			return 2;
		}
	}else
		return 0;
}

function innerDiv(o,m){
	var a=getxy(o);
	var b=getxy(m);
	var mx=b[1]+b[2]/2;
	var my=b[0]+b[3]/2;
	if(mx>a[1] && mx<(a[1]+a[2]) && my>(a[0]) && my<(a[0]+a[3])){
		if(mx<(a[1]+a[2]/2)){
			return 1;
		}
		else{
			return 2;
		}
	}else
		return 0;
	
}

/**
 *	Tag : 
*/
function createtmpl(e){
	for(var i=0;i<tagdivId;i++){
		if(!$("tagdivId"+i))
			continue
		if($("tagdivId"+i)==dragobj.o)
			continue
		var b=innerDiv($("tagdivId"+i),dragobj.o);
		if(b==0)
			continue
		if(b==1){
			$("tagdivId"+i).parentNode.insertBefore(dragobj.otemp,$("tagdivId"+i))
		}
		else{
			if($("tagdivId"+i).nextSibling==null){
				$("tagdivId"+i).parentNode.appendChild(dragobj.otemp)
			}else{
				$("tagdivId"+i).parentNode.insertBefore(dragobj.otemp,$("tagdivId"+i).nextSibling)
			}
		}
		return
	}	
}

/* Action Add Tag
	@param Num actonAdd (0: no Alert; 1: Alert All Tags)
	@param Num db (0:delete div; 1:delete Div and db)	
*/
function addTags(actionAdd, id, db, tagnamepass) {
	db = (db ==1)? 1 : 0 ;
	var tagName = (tagnamepass) ? tagnamepass : chksafe($F('tagName'));
	if (tagName != '') {
		tagdivId = $('dragdropDiv').getElementsByClassName('tags').length;
		var o=document.createElement("div")
		o.className="tags";
		o.id="tagdivId" + tagdivId.toString();
				$(addToPlace).appendChild(o);
		o.innerHTML="<h1><span  class='tagelement'>"+tagName+"</span><font class='closediv' onclick='delDivAndDB(this, "+id+", "+db+")'>x</font><div class='nr' style='display:none'>"+id+"</div></h1>";
		o.getElementsByTagName("h1")[0].onmousedown=addevent;
		tagdivId++;
		if (db == 1){
			tagdivPos += id.toString() + ',';
		}
		if (!tagnamepass){
		$('tagName').value = '';
		}
		if(db == 0){
			mmAllTagsTitle += tagName + ',';
			$('mmAllTagsTitle').value = mmAllTagsTitle;
		}
	}
	if (actionAdd == 1){
		getAlltags(1,0);
	}
}
/* End Add Tag
*/

function deldiv(obj){
	var o=obj.parentNode.parentNode;
	$(addToPlace).removeChild(o);
}

function updateTagPos(allpos){
	var action = "update";
	if(allpos){
			var form = "allpos=" + allpos + "&action=" + action;
				new Ajax.Updater('tagDivAction', "/ajax/tagEdit", {
				parameters	: form,
				method		: 'post',
				onComplete	: EditTagAction.reload,
				asynchronous:false
				});
			}	
}

function delDivAndDB(obj,id,db){
	db=(db==1)?1:0;
	var type;
	var action = "delete";
	var title;
		if  (db == 1 ){
				var form = "id=" + id + "&type=" + type + "&action=" + action  + "&title=" + title;
				new Ajax.Updater('tagDivAction', "/ajax/tagEdit", {
						parameters	: form,
						method		: 'post',
						onComplete	: EditTagAction.reload,
						asynchronous:false
				});
				}

	var o=obj.parentNode.parentNode;
	$(addToPlace).removeChild(o);
	
		if (db == 0){
				getAlltags(0,0);
				mmAllTagsTitle = totalTagsTitleSort;
				$('mmAllTagsTitle').value = mmAllTagsTitle;							
		}
}
/*
	Tag : Functions for checking Tags order
	@ a: 1:alert;  0:no alert
	@ w: 0:get title; 1:get Id; 2:get title and id
*/

function getAlltags(a,w) {
		totalTagsTitleSort = '';
		totalTagsIdSort = '';
		if (w==1){
			var totalTagsId = document.getElementsByClassName('nr');
			totalTagsId.each(function(tagsid) {
			var tagText = tagsid.innerHTML;
			totalTagsIdSort += tagText + ',';
			});
		}
		else if(w==2){
			var totalTagsId = document.getElementsByClassName('nr');
			totalTagsId.each(function(tagsid) {
				var tagText = tagsid.innerHTML;
				totalTagsIdSort += tagText + ',';
			});
			var totalTagsTitle = document.getElementsByClassName('tagelement');
			totalTagsTitle.each(function(tagstitle) {
				var tagText = tagstitle.innerHTML;
				totalTagsTitleSort += tagText + ',';
			});
		}
		else {
			var totalTagsTitle = document.getElementsByClassName('tagelement');
			totalTagsTitle.each(function(tagstitle) {
				var tagText = tagstitle.innerHTML;
				totalTagsTitleSort += tagText + ',';
			});
		}
/*		if (a==1){
			if(totalTagsIdSort){
				alert(totalTagsIdSort);
			}
			if(totalTagsTitleSort){
				alert(totalTagsTitleSort);
			}
		}
*/	
}
function chksafe(temp){ 
	temp=temp.replace(/\#/g,"");
	temp=temp.replace(/\;/g,""); 
	temp=temp.replace(/\,/g,""); 
	temp=temp.replace(/\'/g,"");
	temp=temp.replace(/\_/g,"");    
	return temp;
}


function refreshTo(url){	
	document.location.href=url;
}

function alertDiv(title,contenu,pox,poy,ow,oh){
		var o=document.createElement("div")
		o.className="alertDiv";
		o.id="alertDiv";
		document.body.appendChild(o);
		o.style.position = "absolute";
		o.style.left = pox.toString()+"px";
		o.style.top = poy.toString()+"px";
		o.style.width = ow.toString+"px";
		o.style.height = oh.toString+"px";
		o.style.zindex = 100;
		o.innerHTML="<div style='border-style:solid;border-width:1px;border-color:#AAAAAA'><div style='float:left;back;background:#CCCCCC;width:193px'>"+title+"</div><font style='background:#CCCCCC;cursor:pointer' onclick='alertClose(this);'>x</font><div style='clear:both;height:80px'>"+contenu+"</div></div>";
		
}

function alertClose(obj){
	var o=obj.parentNode.parentNode;
	document.body.removeChild(o);
}

function IsValidEmail(email){
	if(email.length!=0){
		if (email.charAt(0)=="." ||
			email.charAt(0)=="@"||
			email.indexOf('@', 0) == -1 ||
			email.indexOf('.', 0) == -1 ||
			email.lastIndexOf("@") ==email.length-1 ||
			email.lastIndexOf(".")==email.length-1)
			{
			alert("L'Email est invalide");
			$('email').focus();
			return false;
			}
		else {
			arrA = email.split("@");
			arrP = email.split(".");
			if (arrA.length != 2 || arrA[1].length < (arrP[arrP.length-1].length+2)){
				alert("L'Email est invalide");
				$('email').focus();
				return false;
				}
			}
		}
	else
	{
		alert("L'Email est invalide");
		$('email').focus();
		return false;
	}
	return '1';
}


/*
END
*/