/*
	Ydyle object creation.
	to the loading of application it will redirect user to the good steps of suscribtion.
	the user will create a acount for free or log in the Ydyle api.
*/

/* object ydyle */

var ydyle={};

ydyle.decoUrl=function(){
	window.location="http://www.ydyle.com?deconnect=on&type_msg=wrong&msg=Votre+session+est+arriv%26eacute%3Be+%26agrave%3B+%26eacute%3Bch%26eacute%3Bance%2C+veuillez+vous+reconnecter";
}

ydyle.load_method = (window.ie ? 'load' : 'domready');

ydyle._Init=function(){
	

	ydyle.browserDetect._Init();
	ydyle._AddEventApi("html");
	
	//disableRightclick
	//this._DisableClick();
};
ydyle._DisableClick=function(){
	document.oncontextmenu=function(){return false};
}

ydyle._SwitchCss=function(id_nomVariable, urlCss){
	eval("var "+id_nomVariable+"=$('"+id_nomVariable+"')");
	eval(id_nomVariable+".remove()");
	eval("new Asset.css('"+urlCss+"', {id: '"+id_nomVariable+"'})");
};// method de switch css

ydyle._AddEventApi=function(cible){
	ydyle._SetFormEvent();
	
	$E(cible).addEvent("click", function(e){
		var currentEvent=new Event(e);
		
		var el = currentEvent.target;
		var currentClassName=$type(ydyle._GetParentByClass(el, "api_").className)==false ? "" : ydyle._GetParentByClass(el, "api_").className ;
		ydyle.currentEvent=currentEvent;
		// form soumission
		var elValidForm=ydyle._GetParentByClass(el, "submitForm");
		if(elValidForm!="undefined"){
			ydyle.currentInput=elValidForm;
			ydyle._FormSubmit(ydyle.currentInput);
			return(false);
		}
		
		// gestion du clique sur les liens avec redirection href
		if(ydyle.disableLinks(el)==true){
			return(true);
		}
		ydyle.displayApiLink(el);
		
		if($type($(el))!=false && currentClassName.indexOf("focusReset")==-1){
			// remove Event, blur
			if( el.nodeName=="INPUT" || el.nodeName=="LABEL" || el.nodeName=="SELECT" || el.nodeName=="TEXTAREA" || el.nodeName=="#document" || el.hasClass("droule") ){
				return(true);
			}else if(ydyle._GetParentByTagName(el, "LABEL")!="undefined"){
				return(true);
			}else{
				$(el).blur();
				if ($type(currentEvent) != false) {
					currentEvent.stop();
					currentEvent.stopPropagation();
				}
				return(false);
			}
		}
	});// clickEvent Api
}

ydyle.disableLinks=function(el){
	// gestion du clique sur les liens avec redirection href
	if(el.nodeName=="A"){
		if(ydyle.browserDetect.browser=="Opera"){
			if(el.nodeName=="A" && ((el.href != window.location) && ydyle._GetParentByClass(el, "api_")=="undefined")){
				return(true);
				//window.location=el.href;
			}
		}else{
			if(el.nodeName=="A" && ((el.href != "#") && ydyle._GetParentByClass(el, "api_")=="undefined")){
				return(true);
				//window.location=el.href;
			}
		}
	}else if(ydyle._GetParentByTagName(el, "A") != "undefined"){
		var aParentEl=ydyle._GetParentByTagName(el, "A");
		if(ydyle.browserDetect.browser=="Opera"){
			if(aParentEl.nodeName=="A" && ((aParentEl.href != window.location) && ydyle._GetParentByClass(el, "api_")=="undefined")){
				return(true);
				//window.location=aParentEl.href;
			}
		}else{
			if(aParentEl.nodeName=="A" && ((aParentEl.href != "#") && ydyle._GetParentByClass(el, "api_")=="undefined")){
				return(true);
				//window.location=aParentEl.href;
			}
		}
	}else{
		return(false);
	}
}

ydyle.displayApiLink=function(el){
	// api link
	var monEl=ydyle._GetParentByClass(el, "api_");
	if(monEl=="undefined"){
		//no to toogle
		var elNoToogle=ydyle._GetParentByClass(el, "noToogleClickIn");
		(elNoToogle=="undefined") ? ydyle._ToogleUndefinedTarget(".bodyToogle") : ydyle._ToogleUndefinedTarget(".bodyToogle", "#"+elNoToogle.id);
		if(ydyle.alertMsg.isInit==true){
			if(ydyle.alertMsg.isOpen==true){
				ydyle.alertMsg._Close();
			}
		}
	}else{
		// si c une fonction dont l'element courant doit être permuté avec un autre élément
		if(el.className.indexOf("switchTag")!=-1){
			if($type($(el).getNext())!=false){
				var newElRef=$(el).getNext();
				var funcToGetEl="getPrevious";
			}else if($type($(el).getPrevious())!=false){
				var newElRef=$(el).getPrevious();
				var funcToGetEl="getNext";
			}else{
				var newElRef=$(el).getParent();
				var funcToGetEl="getFirst";
			}
			ydyle._SetApiLink(monEl.className, "api_", monEl);
			el=eval("$(newElRef)."+funcToGetEl+"()");
		}else if(monEl.className.indexOf("focusReset")!=-1){
			ydyle._SetApiLink(monEl.className, "api_", el);
			$(el).blur();
			if($type(ydyle.currentEvent)!=false){
				ydyle.currentEvent.stop();
				ydyle.currentEvent.stopPropagation();
			}
			return(false);
		}else{
			ydyle._SetApiLink(monEl.className, "api_", el);
		}
	}
}


ydyle._SetFormEvent=function(cible){
	if($type(cible)==false){
		cible="body";
	}
	
	$ES("form").each(function(formElement){
		$(formElement).addEvent("submit", function(e){
			ydyle.currentInput=formElement;
		});
	});

	$ES(cible+" input[type=text], "+cible+" input[type=password], "+cible+" textarea").each(
		function(elem){
			if($(elem).className.indexOf("noSelect") == -1){
				$(elem).addEvent("focus", function(e){
					this.select();
					ydyle.currentInput=e.target;
				});
			}	
		}
	);

	$ES(cible+" input[type=text], "+cible+" input[type=password], "+cible+" textarea").addEvent("blur", function(e){
		ydyle.currentInput=false;
	});
	
	$ES(cible+" input[type=text], "+cible+" input[type=password]").addEvent("keyup", function(e){
		e = new Event(e);
		if(e.key=="enter"){
			ydyle.currentInput=e.target;
			ydyle._FormSubmit(ydyle.currentInput);
			return(false);
		}else{
			return(true);
		}
	});// value select on focus // submit form on key press enter
	
}



ydyle._FormSubmit=function(targetEvent){
	//alert("dansFormSubmit = "+ydyle.currentInput.id);
	if(ydyle._GetParentByClass(ydyle.currentInput, "form_") != "undefined"){
		if($type(ydyle.currentEvent) != false){
			ydyle.currentEvent.stop();
		}
		var submitElement = ydyle._GetParentByClass(ydyle.currentInput, "form_");
		ydyle._SetApiLink($(submitElement).className, "form_", targetEvent);
		return(false);
	}
};

ydyle._GetParentByTagName=function(elBase, nodeName){
	var currentEl=$(elBase);
	if(currentEl.nodeName=="#document" || $type(currentEl)==false || $type(currentEl)=="string" || currentEl.className.indexOf("switchTag")!=-1)
		return("undefined");
	
	while(currentEl.nodeName!=nodeName){
		if(currentEl.nodeName=="BODY"){
			return("undefined");
		}
		currentEl=$(currentEl).getParent();
	}
	return(currentEl);
}

ydyle._GetParentByClass=function(elBase, cssCible){
	var currentEl=elBase;
	if(currentEl.nodeName=="#document") return("undefined");
	var currentClass=currentEl.className;
	while(currentClass.indexOf(cssCible)==-1){
		if(currentEl.nodeName=="BODY"){
			return("undefined");
		}
		currentEl=$(currentEl).getParent();
		currentClass=currentEl.className;
		
	}
	return(currentEl);
}

ydyle._GetParentByID=function(elBase, cssCible){
	var currentEl=elBase;
	if(currentEl.nodeName=="#document") return("undefined");
	var currentID=currentEl.id;
	while(currentID.indexOf(cssCible)==-1){
		if(currentEl.nodeName=="BODY"){
			return("undefined");
		}
		currentEl=$(currentEl).getParent();
		currentID=currentEl.id;
	}
	return(currentEl);
}

ydyle._ChangeClass=function(cible, classToRemove, classToAdd){
	$E(cible).removeClass(classToRemove);
	$E(cible).addClass(classToAdd);
}

ydyle._ToogleElement=function(cible, linkEl){
	var el=$E(cible);
	if(el.hasClass("visibilityHidden")||el.hasClass("visibilityShow")){
		if(el.hasClass("visibilityHidden")){
			if(el.hasClass("drouleCible")){
				ydyle._InitSetKeyDrouleEvent($(el).id);
				$("textDrouleEvent").className=$(el).id;
			}
			ydyle._ChangeClass(cible, "visibilityHidden", "visibilityShow");
		}else{
			if(el.hasClass("drouleCible")){
				if($type($("textDrouleEvent"))!=false){
					if($type(ydyle.drouleInterval)!=false){
						$clear(ydyle.drouleInterval);
					}
					if($("textDrouleEvent").className == el.id){
						$("textDrouleEvent").remove();
					}else{
						$("textDrouleEvent").value="";
					}
				}
			}
			ydyle._ChangeClass(cible, "visibilityHidden", "visibilityHidden");
		}
	}else{
		if(el.hasClass("displayNone")){
			if(el.hasClass("drouleCible")){
				ydyle._InitSetKeyDrouleEvent($(el).id);
			}
			ydyle._ChangeClass(cible, "displayNone", "displayBlock");
		}else{
			if(el.hasClass("drouleCible")){
				if($type($("textDrouleEvent"))!=false){
					if($type(ydyle.drouleInterval)!=false){
						$clear(ydyle.drouleInterval);
					}
					if($("textDrouleEvent").className == el.id){
						$("textDrouleEvent").remove();
					}else{
						$("textDrouleEvent").value="";
					}
				}
			}
			ydyle._ChangeClass(cible, "displayBlock", "displayNone");
		}
	}
}


ydyle._ToogleUndefinedTarget=function(elements, elemNotToToogle){
	if(elemNotToToogle) var elemNotToToogle=$E(elemNotToToogle);
	$ES(elements).each(function(el){
		if(el.hasClass("visibilityShow") || el.hasClass("displayBlock")){
			if(elemNotToToogle){
				if(el.id!=elemNotToToogle.id){
					ydyle._ToogleElement("#"+el.id)
				}
			}else{
				ydyle._ToogleElement("#"+el.id);
			}
		}
	});
}


ydyle._InitSetKeyDrouleEvent=function(idElement){
	if($type(ydyle.drouleInterval)!=false){
		$clear(ydyle.drouleInterval);
	}
	if($type($("textDrouleEvent"))!=false){
		$("textDrouleEvent").className = idElement;
	}else{
		var mytextarea = new Element('textarea', {
			'id':'textDrouleEvent',
			'name':'textDrouleEvent',
			'cols': '1',
			'rows': '1',
			'class': idElement,
			'styles': {
				'display': 'block',
				'position': 'absolute',
				'z-index:': '0',
				'top': '-20px',
				'left': '-20px',
				'width': '10px',
				'height': '10px'
			},
			'events': {
				'blur': function(e){
					var e=new Event(e).stop();
					e.target.value="";
				},
				'focus': function(e){
					var e=new Event(e).stop();
					$("textDrouleEvent").value="";
				},
				'keyup': function(e){
					var e=new Event(e).stop();
					var typedText=$("textDrouleEvent").value.changeToSimpleString().escapeString(" ", "");
					var tabEls=$ES("#"+e.target.className+" label");
					
					for(var i=0; i<tabEls.length; i++){
						var elStamp=$(tabEls[i]).getText().changeToSimpleString().escapeString(" ", "");
						if(elStamp.indexOf(typedText) == 0){
							var myFx = new Fx.Scroll($E("#"+e.target.className)).toElement($(tabEls[i]));
							if($type(ydyle.drouleInterval)!=false){
								$clear(ydyle.drouleInterval);
							}
							ydyle.drouleInterval = function(){$("textDrouleEvent").value="";}.delay(1500);
							break;
						}
					}
				}
			}
		});
		$E("body").adopt(mytextarea);
	}
	$("textDrouleEvent").focus();
}




ydyle._JsonToUpdtHtml=function(json){
	for(var i=0; i<json.body.elements.length; i++){
		var el=$E(json.body.elements[i].cible);
		if(json.body.elements[i].newContent){
			el.setHTML(json.body.elements[i].newContent);
		}// gestion du contenu
		if(json.body.elements[i].attributes){
			for(var j=0; j<json.body.elements[i].attributes.length; j++){
				el[json.body.elements[i].attributes[j].attribute]=json.body.elements[i].attributes[j].value;
			}// gestion des attributs
		}
	}
}

ydyle._SetApiLink=function(apiLink, stamp, linkEl){
	var monApi=Json.evaluate(apiLink.getJsonFromClass(stamp));
	var myAction=monApi.name+"."+monApi.action+"(";
	if($defined(monApi.values)){
		var i=0;
		for(val in monApi.values){
			(i==0) ? myAction+= "\""+($type(monApi.values[val])=="string" ? monApi.values[val].escapeRegExp() : monApi.values[val])+"\"" : myAction+=", \""+($type(monApi.values[val])=="string" ? monApi.values[val].escapeRegExp() : monApi.values[val])+"\"";
			i++;
		}
		myAction+=", ";
	}
	myAction+="linkEl)";
	eval(myAction);
	if(monApi.values && monApi.values.cible){
		ydyle._ToogleUndefinedTarget(".bodyToogle", monApi.values.cible);
	};
}// dispatch of all links api by json class element call in vd._AddEventApi for exemple



ydyle._UpdClass=function(elements){
	$ES(elements).each(function(el){
		var elClass=$(el).className;
		$(el).className="empty";
		$(el).className=elClass;
	});
}

/* alert messages */
ydyle.alertMsg={};
ydyle.alertMsg.funcTimer;
ydyle.alertMsg.isOpen=false;
ydyle.alertMsg._Init=function(){
	ydyle.alertMsg.isInit=true;
	if(ydyle.situ=="home" || ydyle.situ.indexOf("etp")!=-1){
		ydyle.alertMsg.styleAttr="left";
		ydyle.alertMsg.posTop=0;
	}else if(ydyle.situ=="vd"){
		ydyle.alertMsg.styleAttr="top";
		ydyle.alertMsg.posTop=40;
	}else if(ydyle.situ=="chat"){
		ydyle.alertMsg.styleAttr="top";
		ydyle.alertMsg.posTop=0;
	}else if(ydyle.situ=="perso" || ydyle.situ=="mail"){
		ydyle.alertMsg.styleAttr="right";
		ydyle.alertMsg.posTop=0;
	}
	ydyle.alertMsg.posTop
	ydyle.alertMsg.initTop=$E("#alertMessage").style.top.toInt();
	ydyle.alertMsg.styleVal=$E("#alertMessage").style[ydyle.alertMsg.styleAttr].toInt();
	ydyle.alertMsg.initWidth=$E("#alertMessage").getSize().size.x;
}


ydyle.alertMsg._Open=function(bodyMsg, goodBadConf, el){
	if(!ydyle.alertMsg.isInit) ydyle.alertMsg._Init();
	
	// fermeture de la fenêtre
	$E("#alertMessage a#closeAlert").title=lang.front.alert.closeText;
	//titre
	$E("#alertMessage").className=goodBadConf;
	$E("#closeAlert span.displayNone").empty();
	$E("#closeAlert span.displayNone").appendText(lang.front.alert.closeText);
	$E("#alertMessage h2").empty();
	$E("#alertMessage h2").appendText(lang.front.alert[goodBadConf]["title"]);
	
	// body
	htmlConstruct._GoodAppendChild($E("#alertMessage #bodyMsg"), bodyMsg, true);
	
	ydyle.alertMsg.EffectOpen = new Fx.Styles('alertMessage', {
		duration: 300
		,transition: Fx.Transitions.Quad.easeIn
		,onComplete:function(e){
			$E("#alertMessage h2").focus();
			ydyle.alertMsg.isOpen=true;
			//ydyle.alertMsg.funcTimer = ydyle.alertMsg._Close.delay(5000);
		}
	});
	
	ydyle.alertMsg.EffectReOpen = new Fx.Styles('alertMessage', {
		duration: 300
		,transition: Fx.Transitions.Elastic.easeOut
		,onComplete:function(e){
			$E("#alertMessage h2").focus();
			ydyle.alertMsg.isOpen=true;
			//ydyle.alertMsg.funcTimer = ydyle.alertMsg._Close.delay(5000);
		}
	});
	
	ydyle.alertMsg.EffectClose = new Fx.Styles('alertMessage', {
		duration: 300
		,transition: Fx.Transitions.Elastic.easeOut
		,onComplete:function(e){
			ydyle.alertMsg.isOpen=false;
			//ydyle.alertMsg.funcTimer = ydyle.alertMsg._Close.delay(5000);
		}
	});
	
	//if(ydyle.alertMsg.isOpen!=true){
		if(ydyle.situ!="perso"){
			ydyle.alertMsg.EffectOpen.start({
			    'top': [ydyle.alertMsg.initTop, ydyle.alertMsg.posTop]
			});
		}else{
			$('alertMessage').style.top=window.getScrollTop()+"px";
			ydyle.alertMsg.EffectOpen.start({
			    'right': [-250, -1]
			});
		}
	/*
	}else{
		if(ydyle.situ != "perso"){
			eval("ydyle.alertMsg.EffectReOpen.start({" + ydyle.alertMsg.styleAttr + ": [ydyle.alertMsg.styleVal-(ydyle.alertMsg.initWidth/2), ydyle.alertMsg.styleVal]});");
		}else{
			var startPoint = window.getScrollTop();
			ydyle.alertMsg.EffectReOpen.start({"top": [(window.getScrollTop()-($("alertMessage").getPosition().y) / 4), startPoint]});
		}
	}
	*/
};

ydyle.alertMsg.createButton=function(Atext, aClass){
	return(htmlConstruct._SetNode("a", {"href":"#","class":aClass}, Atext));
}

ydyle.alertMsg._OpenConfirm=function(phraseExplainConfirm, varCibleConfirm, classActionValidConfirm){
	ydyle.alertMsg._Open(htmlConstruct._SetNode("div", {}, [phraseExplainConfirm, varCibleConfirm, htmlConstruct._SetNode("p", {"class":"alignCenter"}, [ydyle.alertMsg.createButton(lang.front.alert.refuseBt, 'btRefuseAccept api_{"name":"ydyle.alertMsg","action":"_Close","values":{"cible":"#alertMessage"}}'), ydyle.alertMsg.createButton(lang.front.alert.acceptBt, classActionValidConfirm+' btRefuseAccept')])]) , "ask");
}

ydyle.alertMsg._Close=function(){
	if(ydyle.alertMsg.isOpen!=false){
		if(ydyle.situ!="perso"){
			ydyle.alertMsg.EffectClose.start({
				'top': [ydyle.alertMsg.posTop, ydyle.alertMsg.initTop]
			});
		}else{
			$('alertMessage').style.top=window.getScrollTop()+"px";
			ydyle.alertMsg.EffectClose.start({
			    'right': [-1, -250]
			});
		}
		//ydyle.alertMsg.funcTimer = $clear(ydyle.alertMsg.funcTimer);
	}
	ydyle.alertMsg.isOpen=false;
}

ydyle.browserDetect={
	_Init: function () {
		this.browser = this._SearchString(this.dataBrowser) || "An unknown browser";
		this.version = this._SearchVersion(navigator.userAgent)
			|| this._SearchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this._SearchString(this.dataOS) || "an unknown OS";
	}
	,_SearchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	}
	,_SearchVersion: function (dataString) {
		var index = dataString.lastIndexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	}
	,dataBrowser: [
		{
			string: navigator.userAgent
			,subString: "OmniWeb"
			,versionSearch: "OmniWeb/"
			,identity: "OmniWeb"
		}
		,{
			string: navigator.vendor
			,subString: "Apple"
			,identity: "Safari"
		}
		,{
			prop: window.opera
			,identity: "Opera"
		}
		,{
			string: navigator.vendor
			,subString: "iCab"
			,identity: "iCab"
		}
		,{
			string: navigator.vendor
			,subString: "KDE"
			,identity: "Konqueror"
		}
		,{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor
			,subString: "Camino"
			,identity: "Camino"
		}
		,{		// for newer Netscapes (6+)
			string: navigator.userAgent
			,subString: "Netscape"
			,identity: "Netscape"
		}
		,{
			string: navigator.userAgent
			,subString: "MSIE"
			,identity: "Explorer"
			,versionSearch: "MSIE"
		}
		,{
			string: navigator.userAgent
			,subString: "Gecko"
			,identity: "Mozilla"
			,versionSearch: "rv"
		}
		,{ // for older Netscapes (4-)
			string: navigator.userAgent
			,subString: "Mozilla"
			,identity: "Netscape"
			,versionSearch: "Mozilla"
		}
	]
	,dataOS : [
		{
			string: navigator.platform
			,subString: "Win"
			,identity: "Windows"
		}
		,{
			string: navigator.platform
			,subString: "Mac"
			,identity: "Mac"
		}
		,{
			string: navigator.platform
			,subString: "Linux"
			,identity: "Linux"
		}
	]

};

var htmlConstruct={};

htmlConstruct._SetNode=function(nodeType, attrObject, content){
	var myNode=new Element(nodeType, attrObject);
	if($type(content)=="array" && (nodeType!="IMG" || nodeType!="INPUT")){
		for(var i=0; i<content.length; i++){
			htmlConstruct._GoodAppendChild(myNode, content[i]);
		}
	}else if($type(content)!="array" && (nodeType!="IMG" || nodeType!="INPUT")){
		htmlConstruct._GoodAppendChild(myNode, content);
	}
	return(myNode);
}

htmlConstruct._GoodAppendChild=function(nodeConteneur, TextOrElemNode, keepOldContent){
	keepOldContent ? nodeConteneur.empty() : false;// empty node Conteneur or not
	if($type(TextOrElemNode)=="string" && TextOrElemNode.indexOf("<")==-1){// if string insert as textnode
		nodeConteneur.appendText(TextOrElemNode.escapeHtmlEntities());
	}else if($type(TextOrElemNode)=="string" && TextOrElemNode.indexOf("<")!=-1){
		nodeConteneur.innerHTML=TextOrElemNode;
	}else if($type(TextOrElemNode)=="element"){// else insert as htmlelement
		nodeConteneur.appendChild(TextOrElemNode);
	}
}

htmlConstruct._SwitchTag=function(element, newNodeType, newAttrObject){
	var nodeContent=element.innerHTML;
	$(element).replaceWith(htmlConstruct._SetNode(newNodeType, newAttrObject, nodeContent));
}

var deroulLink={};

deroulLink._SetLink=function(foncToEval, cibleEvent, MyElement){
	
	var el=($type(cibleEvent)=="string") ? $(MyElement) : $(cibleEvent);
	var parentCible=ydyle._GetParentByClass(el, "drouleCibleLink");
	var cible= $E("#"+((parentCible.id).replace("Cible", "")));
	
	$(cible).innerHTML=$(el).getText();
	ydyle._ToogleUndefinedTarget(".bodyToogle");
	
	eval(foncToEval+"('"+el.className+"')");
}

ydyle._setDrouleDynHeight=function(cible, nbHeightElement){
	var liLength=$ES(cible+" li").length;
	if(liLength!=0){
		if(liLength<=nbHeightElement){
			$E(cible).style.height ="auto";
		}else{
			var heightElement= ($E(cible+" li").getSize().size.y==0) ? 23 : $E(cible+" li a").getSize().size.y;
			$E(cible).style.height = ((heightElement * nbHeightElement))+"px";
		}
	}
}

ydyle.switchPng=function(cible){
	var version = parseFloat(navigator.appVersion.split("MSIE")[1]);
	if ((version >= 5.5) && (version < 7) && (document.body.filters)){
		var tabImg=$ES(cible);
		var htmlElement;
		if(tabImg.length>0){
			$$(tabImg).each(function(el){
				var strNewHTML = "<span "+( ($(el).id!="") ? ("id=\""+$(el).id+"\" ") : "" )+" "+( ($(el).className!="") ? ("class=\""+$(el).className+"\" ") : "" )+" "+( ($(el).title!="") ? ("title=\""+$(el).title+"\" ") : "" )
					+ " style=\""+( ($(el).width!="") ? ("width:"+(($(el).src.indexOf("83x")!=-1) ? "107" : $(el).getSize().size.x)+"px; ") : "" )
			        + ( ($(el).height!="") ? ("height:"+(($(el).src.indexOf("83x")!=-1) ? "101" : $(el).getSize().size.y)+"px; ") : "" )
			        + "" +( ($(el).style.cssText!="") ? ($(el).style.cssText) : "" )
			        + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			        + "(src=\'" + $(el).src + "\', sizingMethod='scale');\"></span>";
				if ($type($(el).parentNode) != false) {
					$(el).parentNode.innerHTML = strNewHTML;
					htmlElement=strNewHTML;
				}
			});
		}
	}
}

// fonction de redirection
ydyle._CallLocation=function(url){
	window.location=url;
}

ydyle._MixJson=function(mainJson, jsonToMix){
	for(el in jsonToMix){
		mainJson[el]=jsonToMix[el];
	}
	return(mainJson);
}

/* assignation de contacts comme contacts particuliers */

var fav={};
fav._AddFav=function(id, linkConfig){
	profilAction._SetOneUser("fav", id, linkConfig);
	if(ydyle.situ=="Desktop"){
		if(config.isVisible==true && config.idRub=="favoris"){
			config._SetLink("favoris");
		}
	}
}
var friend={};
friend._AddFriend=function(id, linkConfig){
	profilAction._SetOneUser("friend_send", id, linkConfig);
	if(ydyle.situ=="Desktop"){
		if(config.isVisible==true && config.idRub=="amis_attenteenvoi"){
			config._SetLink("amis_attenteenvoi");
		}
	}
}
var bizz={};
bizz._AddBizz=function(id, linkConfig){
	profilAction._SetOneUser("kiss", id, linkConfig);
	if(ydyle.situ=="Desktop"){
		if(config.isVisible==true && config.idRub=="bises_envoi"){
			config._SetLink("bises_envoi");
		}
	}
}
var black={};
black._AddBlack=function(id, linkConfig){
	profilAction._SetOneUser("black", id, linkConfig);
	if(ydyle.situ=="Desktop"){
		if(config.isVisible==true && config.idRub=="blacklist"){
			config._SetLink("blacklist");
		}
	}
}

var profilAction={}
profilAction._SetOneUser=function(context, value, linkConfig){
	profilAction.request=new Ajax("http://www.ydyle.com/modules/bv/set_user/contact_status.php", {
		method:'post'
		,data:{'lang': lang.currentLang, 'type': context, 'id_contact':value}
		/*
		,onRequest:function(){
			$("inputSearchPseudo").addClass("setLoader");
		}
		,onFailed:function(){
			$("inputSearchPseudo").removeClass("setLoader");
		}
		*/
		,onSuccess:function(response){
			var repObject=Json.evaluate(response);
			if(repObject.response=="ok"){
				if (ydyle.situ == "Desktop") {
					if ($type(linkConfig) == "string") {
						config._SetLink(linkConfig);
					}
				}
				// gestion du feedback red5
				if(context=="black"){
					profilAction._Red5AddBlack(value);
				}
				// afficher le message
				ydyle.alertMsg._Open(htmlConstruct._SetNode("p", {}, repObject.msg), "good");
			}else{
				ydyle.alertMsg._Open(htmlConstruct._SetNode("p", {}, repObject.msg), "wrong");
			}
		}
	}).request();
}

profilAction._Red5AddBlack=function(idUser){
	if(ydyle.situ=="vd"){
		//alert("profilAction._Red5AddBlack idUser = "+idUser+" && situ=vd");
		document.getElementById("swfRed5Bv")._SetBlack(idUser);
	}else{
		window.opener.profilAction._Red5AddBlack(idUser);
	}
}

profilAction._Red5RemoveBlack=function(tabIdUsers){
	if(ydyle.situ=="vd"){
		for(var i=0; i<tabIdUsers.length; i++)
			document.getElementById("swfRed5Bv")._SetWhite(tabIdUsers[i]);
	}
}


var win={};

win._Open=function(name, url){
	var name=name;
	var url=url;
	var winOptions= "dependent=yes, directories=yes, location=yes, menubar=no, resizable=yes, scrollbars=yes, status=yes, toolbar=yes";
	var width = "";
	var height = "";
	var top="";
	if($type(url)=="element"){
		var urlLink=ydyle._GetParentByTagName(url, "A")
		url= $type($(urlLink)!=false) ? $(urlLink).href : false;
	}
	
	if(url!=false){
		//gestion des dimenssions de la fenêtre
		if(name == "contact"){
			width = 499;
			height = 480;
			//gestion de la position top de la fenêtre
			top=(Math.round(screen.height/2))-(Math.round(height/2));
		}else if(name == "signal"||name=="formMdp"){
			width = 348;
			height = 402;
			//gestion de la position top de la fenêtre
			top=(Math.round(screen.height/2))-(Math.round(height/2));
		}else if(name == "chat"){
			width = 650;
			height = 470;
			winOptions="directories=no, location=no, menubar=no, resizable=yes, scrollbars=yes, status=no, toolbar=no";
			//winOptions="directories=yes, location=yes, menubar=yes, resizable=yes, scrollbars=yes, status=yes, toolbar=yes";
			//url=url+"";
			//gestion de la position top de la fenêtre
			top=(0);
		}else{
			width = 1014;
			height = screen.height-300;
			//gestion de la position top de la fenêtre
			top=50;
		}
		
		winOptions+=", height="+height+",top="+top;
		//gestion de la position left de la fenêtre
		var left=(Math.round(screen.width/2))-(Math.round(width/2));
		winOptions+=", width="+width+", left="+left;		
		
		// test de l'ouverture de la fenêtre
		win["win"+name]=window.open(url,"win"+name, winOptions);
		// test de l'existance de la fenêtre sinon on message la detection d'un popup blocker
		/*if($type(win["win"+name])==false){
			ydyle.alertMsg._Open(htmlConstruct._SetNode("p", {}, lang.front.popubBlocker), "wrong");
		}else{
			win["win"+name]=window.open(url,"win"+name, winOptions);
		}
		*/
		
		if (!win["win"+name].opener) {win["win"+name].opener = self;}
		if (window.focus) {win["win"+name].focus();}
	}
};

var smiley={
	tabSmileyText : ["heart","flower","kiss","evil","angel","seek","mute","cool","shocked","dubitative","hypnose","sarcasm","think","party","sleep","anger","sorry","shy","cry","sad","fool","mokery","wink","laugh","smile"]
	,tabSmileyAscii : ["<3","(f)",":*",":6","o)","+(",":x","8)",":o",":/",":|","^)","*)","<)","|)","x(",":s",":[",":'(",":(","xD",":p",";)",":D",":)"]
	,_Permute : function(el){
		if($(el).nodeName=="IMG"){
			var base = $(el).alt.replace("-","");
			var monEl=new Element("SPAN",{
				'class':"api_{'name':'smiley','action':'_Permute'} switchTag"
			}).appendText(base);
		}else if($(el).nodeName=="SPAN"){
			var base = $(el).getText().replace("-","");
			var monEl=new Element("IMG",{
				'class':"api_{'name':'smiley','action':'_Permute'} switchTag"
				,'src':'http://www.ydyle.com/medias/img/common/icon_chat/'+ smiley._PermuteAscii(base)+".gif"
				,'alt':base
			});
		}
		$(el).replaceWith(monEl);
	}
	//smile and party.
	,_PermuteSmiley:function(smileyText){
		for(var i=0; i<this.tabSmileyText.length; i++){
			if(this.tabSmileyText[i].indexOf(smileyText)!=-1)
				return(this.tabSmileyAscii[i]);
		}
	}
	,_PermuteAscii:function(smileyAscii){
		for(var i=0; i<this.tabSmileyAscii.length; i++){
			if(this.tabSmileyAscii[i] == smileyAscii)
				return(this.tabSmileyText[i]);
		}
	}
}

/*
,tabSmileyText : ["heart","flower","kiss","evil","angel","seek","mute","cool","shocked","dubitative","hypnose","sarcasm","think","party","sleep","anger","sorry","shy","cry","sad","fool","mokery","wink","laugh","smile"]
,tabSmileyAscii : ["<3","(f)",":*",":6","o:)","+(",":x","8)",":o",":/",":|","^)","*)","<:)","|)","x(",":s",":[",":'(",":(","xD",":p",";)",":D",":)"]
*/




