/**
 * @author 58062
 */
function viewProfile(id) {
	
	if (fStatus['isLogged'] == false)
		return;
	if (fExternalVars.viewProfileOverflow == true){
		hideViewProfile();
		setTimeout("viewProfile("+id+")", fConfigs[fConfigs['sideBar']['boxes'][i]['type']][fConfigs['sideBar']['boxes'][i]['id']]['durationClose']);
		return;
	}
	if (fStatus['overflowAction'] == true) {
		for (i = 0; i < fConfigs['sideBar']['boxes'].length; i++) 
			if (fStatus[fConfigs['sideBar']['boxes'][i]['type']][fConfigs['sideBar']['boxes'][i]['id']]['self'] == "open") {
				showBox(fConfigs['sideBar']['boxes'][i]['id']);
				setTimeout("viewProfile("+id+")", fConfigs[fConfigs['sideBar']['boxes'][i]['type']][fConfigs['sideBar']['boxes'][i]['id']]['durationClose']);
				return;
			}
	}
	else {
		setOverflowAction(true);
		var parent = $('viewProfileOverflow');
		var div = new Element('div', {
			'styles'	:	{
				'display'	:	'block',
				'width'		:	'100%',
				'float'		:	'left',
				'backgroundColor' : '#1f1f1f'
			}
		});
		parent.setStyle('display', 'block').grab(div);
		div.innerDHTML(standAlone['profil']);
		initViewProfile(id);
	}
}
function initViewProfile(id){
	var profile = null;
	var request = new Request.JSON({
		url: fUrls.DISPLAYPROFILE,
		method: 'post',
		onComplete:function(xhr){
			if (xhr['status'] == true){
				fExternalVars.profileOverflow = xhr['user'];
				loadGlobalProfile();
			}
			else
				clearBoxesSideBar();
		}
	}).send("user_id="+id);
	
}
function loadGlobalProfile(){
	fExternalVars.viewProfileOverflow = true;
	fForms.viewProfilForm = new Form('commentProfile');
	fForms.viewProfilForm.setResultClasses('error', 'success');
	fForms.viewProfilForm.setResultBox('resultComment');
	var parentEl = $('picturesRand');
	var asset = new Asset.image('http://'+slsBuild.site.domainName+'/'+slsBuild.paths.imgJs+'pepetsSmall.png', {
		onload:function(){
			var moneyString = fExternalVars.profileOverflow['user_money'].toString().strrev();
			var arrayCpt = new Array();
			for (var i=0;i<moneyString.length;i++){
				var div = new Element('div', {
					'styles' : {
						'display'	:	'block',
						'float'		:	'right',
						'width'		:	'20px',
						'height'	:	'30px',
						'color'		:	'#FFF',
						'backgroundImage': 'url('+this.src+')',
						'backgroundRepeat': 'no-repeat',
						'backgroundPosition': 'center center',
						'textAlign'	:	'center',
						'lineHeight':	'30px',
						'fontSize'	:	'1.5em',
						'fontWeight':	'900',
						'marginRight':	'2px'
					},
					'html'	:	moneyString.substr(i, 1)
				});
				if (Browser.Engine.trident && Browser.Engine.version == 4)
					div.setStyles({
						'backgroundImage':'none',
						'filter': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + this.src + '\', sizingMethod=\'scale\')'
					});
				arrayCpt.push(div);
				}
				for (var i=arrayCpt.length; i<8;i++){
					var div = new Element('div', {
						'styles': {
							'display': 'block',
							'float': 'right',
							'width': '20px',
							'height': '30px',
							'backgroundImage': 'url(' + this.src + ')',
							'backgroundRepeat': 'no-repeat',
							'backgroundPosition': 'center center',
							'marginRight':	'2px'
						}
					});
					if (Browser.Engine.trident && Browser.Engine.version == 4)
						div.setStyles({
							'backgroundImage':'none',
							'filter': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + this.src + '\', sizingMethod=\'scale\')',
							'marginRight' : '1px'
						});
					arrayCpt.push(div);
				}
				var container = new Element('div', {
					'styles'	: {
						'display'	:	'block',
						'float'		:	'left',
						'width'		:	'190px',
						'marginLeft': '20px'
					}
				});
				if (Browser.Engine.trident && Browser.Engine.version == 4)
					container.setStyle('margin-left', '0px');
				/*var pepet = new Element('div', {
					'styles' : {
						'display'	:	'block',
						'float'		:	'right',
						'fontSize'	:	'1em',
						'color'		:	'#FFF'
					},
					'html'	:	slsBuild.langs.SIDEBAR_MYACCOUNT_DOLLARS_PEPETS
				}).inject(container);*/
				for (var i=0;i<arrayCpt.length;i++){
					container.grab(arrayCpt[i]);
				}
				parentEl.getNext().getFirst().empty();
				parentEl.getNext().getFirst().grab(container);
				var element = new Element('div', {
					'styles'	: {
						'display'	:	'block',
						'float'		:	'left',
						'width'		:	'190px',
						'marginLeft':	'10px',
						'color'		: '#FFF',
						'fontWeight': 900,
						'textAlign'	: 'left',
						'fontSize'	: '0.9em'
					},
					'html'	:	fExternalVars.profileOverflow['user_login']+"<br />"+fExternalVars.profileOverflow['user_age']+" ans - "+fExternalVars.profileOverflow['user_work']+"<br /><br />"+fExternalVars.profileOverflow['user_orientation']['name']+" - "+fExternalVars.profileOverflow['user_situation']['name']+"<br />"+fExternalVars.profileOverflow['city']['city_name']+" ("+fExternalVars.profileOverflow['city']['city_zip_code']+")<br /><br /><span style=\"color:"+fConfigs['profiles']['color'+fExternalVars.profileOverflow['sex'].toUpperCase()]+"\">"+fExternalVars.profileOverflow['nb_received_invitations']+"</span> "+slsBuild.langs.INVITS_RECEIVED+"<br />"+slsBuild.langs.PROFIL_NUM_VIEW+" <span style=\"color:"+fConfigs['profiles']['color'+fExternalVars.profileOverflow['sex'].toUpperCase()]+"\">"+fExternalVars.profileOverflow['views']+"</span> "+slsBuild.langs.PROFIL_NUM_VIEW_0
				});
				parentEl.getNext().getFirst().grab(element);
				
				parentEl.getNext().getFirst().getNext().setStyles({
					backgroundColor: fConfigs['profiles']['color'+fExternalVars.profileOverflow['sex'].toUpperCase()]
				});
				
				loadViewProfilePictures(0);
				loadViewProfileComments(0);
		}
	});
}
function loadViewProfilePictures(indexFrom, num){
	var arrayPic = new Array();
	var arrayBigPic = new Array();
	$('paginationAccountPictures').empty();
	var parentEl = $('picturesRand');
	parentEl.set('html', "<div style=\"display:block;height:370px;width:100%;\"><img src=\"Style/Img/Javascript/waitProfilePictures.gif\" alt=\"Pease wait\" title=\"Please Wait\" style=\"margin-top:150px;margin-left:285px;\" /></div>");
	if (num == null)
		num = 6;
	var pictures = new Array();
	for (var i= 0;i<fExternalVars.profileOverflow['user_photo'].length;i++){
		pictures.push(fExternalVars.profileOverflow['user_photo'][i]['user_photo_name']);
	}
	if (!pictures.keyExists(indexFrom))
		indexFrom = 0;
	
	var indexTo = indexFrom+num;
	
	for(var i=indexFrom;i<indexTo;i++){
		if (pictures.keyExists(i)) {
			arrayBigPic.push('http://'+slsBuild.site.domainName+'/'+fConfigs['paths']['userMedias']+fExternalVars.profileOverflow['user_id']+"/"+pictures[i]+"_2.jpg");
			arrayPic.push('http://' + slsBuild.site.domainName + '/' + fConfigs['paths']['userMedias'] + fExternalVars.profileOverflow['user_id'] + "/" + pictures[i] + "_1.jpg");
		}
	}
	var defaultPic = "defaultPicture"+fExternalVars.profileOverflow['sex'].toUpperCase();
	var picturesFinal = arrayPic.pad(num, 'http://'+slsBuild.site.domainName+'/'+fConfigs['paths']['userMedias']+fConfigs['profiles'][defaultPic]+"_1.jpg");
	
	var els = new Array();
	for(var i=0;i<picturesFinal.length;i++){
		var el = new Element('div').set('class', 'blockFloat').setStyles({
			backgroundImage : 'url('+picturesFinal[i]+')',
			backgroundPosition:'center center',
			cursor: 'pointer'
		});
		if (arrayBigPic.keyExists(i)) {
			el.removeEvent('click');
			eval("el.addEvent('click', function (e){viewPicture('" + arrayBigPic[i] + "', '" + fExternalVars.profileOverflow['sex'] + "'); e.stop();});");
		}
		els.push(el);
	}
	var asset = new Asset.images(picturesFinal, {
		onComplete: function(){
			parentEl.empty();
			
			for(var i=0;i<els.length;i++){
				parentEl.grab(els[i]);
			}
			var footerBlocPagination = new Element('div', {
					'styles' :{
						'display'	:	'block',
						'float'		:	'left',
						'width'		:	'630px',
						'textAlign'	: 'right',
						'backgroundColor' : '#242424',
						'padding'	: '5px 0'
					}									
				});
			var footerBlocActions = new Element('div', {
					'styles' :{
						'display'	:	'block',
						'float'		:	'left',
						'width'		:	'210px',
						'padding'	: '5px 0',
						'backgroundColor' : fConfigs['profiles']['color'+fExternalVars.profileOverflow['sex'].toUpperCase()]
					}									
				});
			var footerActions = new Element('ul', {
				'id'	:	'profil-menu-actions2',
				'styles' : {
					'display'	:	'block',
					'width'		:	'80%',
					'marginLeft': 	'10%',
					'color'		: '#FFF'
				}
			});
			var actions = new Element('ul', {
				'id'	:	'profil-menu-actions',
				'styles' : {
					'display'	:	'block',
					'width'		:	'80%',
					'marginLeft': 	'10%',
					'color'		: '#FFF',
					'fontSize'	: '0.9em'
				}
			});
			var li1 = new Element('li', {
				'class': 'linkOnProfile'
			});
			var a1 = new Element('a', {
				'title': slsBuild.langs.PROFIL_ACTION_ADDFRIEND,
				'html': slsBuild.langs.PROFIL_ACTION_ADDFRIEND
			});
			if (fExternalVars.profileOverflow['isFriend'] == false) {
				eval("a1.addEvent('click', function(e){addFriend();e.stop();});");
			}
			else {
				li1.set('class', 'linkOnProfileBlack');
			}
			li1.grab(a1);
			
			
			var li2 = new Element('li', {
				'class' : 'linkOnProfile'
			});
			var a2 = new Element('a', {
				'title' : slsBuild.langs.PROFIL_ACTION_SEND_MSG,
				'html'	: slsBuild.langs.PROFIL_ACTION_SEND_MSG
			});
			eval("a2.addEvent('click', function(e){profileSendMessageTo("+fExternalVars.profileOverflow['user_id']+", '"+fExternalVars.profileOverflow['user_login']+"');e.stop();});");
			li2.grab(a2);
			
			var li3 = new Element('li', {
				'class' : 'linkOnProfile'
			});
			var a3 = new Element('a', {
				'title' : slsBuild.langs.PROFIL_ACTION_SEND_INVITATION,
				'html'	: slsBuild.langs.PROFIL_ACTION_SEND_INVITATION
			});
			eval("a3.addEvent('click', function(e){profileSendInvitationTo("+fExternalVars.profileOverflow['user_id']+", '"+fExternalVars.profileOverflow['user_login']+"');e.stop();});");
			li3.grab(a3);
			
			var li4 = new Element('li', {
				'class' : 'linkOnProfile'
			});
			var a4 = new Element('a', {
				'title' : slsBuild.langs.PROFIL_ACTION_RECOMMANDATION,
				'html'	: slsBuild.langs.PROFIL_ACTION_RECOMMANDATION
			});
			eval("a4.addEvent('click', function(e){recommandPeople();e.stop();});");
			li4.grab(a4);
			
			var li5 = new Element('li', {
				'class' : 'linkOnProfile'
			});
			var a5 = new Element('a', {
				'title' : slsBuild.langs.PROFIL_ACTION_CV,
				'html'	: slsBuild.langs.PROFIL_ACTION_CV
			});
			eval("a5.addEvent('click', function(e){viewCv();e.stop();});");
			li5.grab(a5);
			
			var li6 = new Element('li', {
				'class' : 'linkOnProfileBlack'
			});
			if (fExternalVars.profileOverflow['user_id'] == fMember['id'])
			{
				li6.set('html', 'A');
				li6.setStyles({
					'color': fConfigs['profiles']['color'+fExternalVars.profileOverflow['sex'].toUpperCase()],
					'listStyle' : 'none'
					});
				actions.grab(li5);
				$('paginationAccountPictures').grab(actions);
			}
			else if (fExternalVars.profileOverflow['isBlocked'] == true && fExternalVars.profileOverflow['unBlocked'] == true) {
				var a6 = new Element('a', {
					'title': slsBuild.langs.PROFIL_ACTION_UNBANPEOPLE,
					'html': slsBuild.langs.PROFIL_ACTION_UNBANPEOPLE
				});
				eval("a6.addEvent('click', function(e){banPeople(" + fExternalVars.profileOverflow['user_id'] + ");e.stop();});");
				li6.grab(a6);
				
			}
			else if (fExternalVars.profileOverflow['isBlocked'] == true && fExternalVars.profileOverflow['unBlocked'] == false) {
				li6.set('html', 'A');
				li6.setStyles({
					'color': fConfigs['profiles']['color'+fExternalVars.profileOverflow['sex'].toUpperCase()],
					'listStyle' : 'none'
					});
			}
			else {
				var a6 = new Element('a', {
					'title': slsBuild.langs.PROFIL_ACTION_BANPEOPLE,
					'html': slsBuild.langs.PROFIL_ACTION_BANPEOPLE
				});
				eval("a6.addEvent('click', function(e){banPeople(" + fExternalVars.profileOverflow['user_id'] + ");e.stop();});");
				li6.grab(a6);
				actions.grab(li1);
				actions.grab(li2);
				actions.grab(li3);
				actions.grab(li4);
				actions.grab(li5);
				$('paginationAccountPictures').grab(actions);
			}
			
			footerActions.grab(li6);
			footerBlocActions.grab(footerActions);
			
			var strPag = "";
			var start = 0;
			var spanTmpParent = new Element('span', {
					'html'	:	'A',
					'styles':	{
						'color'	:'#242424'
					}
				});
			if (indexFrom != 0){
				start = ((indexFrom-num) >= 0) ? (indexFrom-num) : 0;
				var spanTmp = new Element('span', {
					'class'	:	'valid',
					'id'	:	'profil-view-previous',
					'html'	:	'< '+slsBuild.langs.SIDEBAR_MYMESSAGES_PAGIN_PREVIOUS,
					'styles':	{
						'color'	:'#FFFFFF',
						'marginRight' : '10px'
					}
				});
				eval("spanTmp.addEvent('click', function(){loadViewProfilePictures("+start+","+num+");})");
				spanTmpParent.grab(spanTmp);
			}
			
			if (fExternalVars.profileOverflow['user_photo'].length > indexTo) {
				var spanTmp = new Element('span', {
					'class': 'valid',
					'id'	:	'profil-view-next',
					'html': slsBuild.langs.SIDEBAR_MYMESSAGES_PAGIN_NEXT+" >",
					'styles': {
						'color'	:'#FFFFFF',
						'marginRight' : '10px'
					}
				});
				eval("spanTmp.addEvent('click', function(){loadViewProfilePictures('" + indexTo + "'," + num + ");})");
				spanTmpParent.grab(spanTmp);
			}
			footerBlocPagination.grab(spanTmpParent);
			$('footerPictures').empty();
			$('footerPictures').grab(footerBlocPagination, 'top');
			$('footerPictures').grab(footerBlocActions);
		}
	});
}
function loadViewProfileComments(indexFrom, num){
	var parentEl = $('comments');
	parentEl.empty();
	if (num == null)
		num = 4;
	if (!fExternalVars.profileOverflow['comments'].keyExists(indexFrom) && indexFrom != 0)
		indexFrom = 0;
	if (!fExternalVars.profileOverflow['comments'].keyExists(indexFrom) && indexFrom == 0){
		parentEl.innerHTML = slsBuild.langs.PROFIL_NO_ONE+" "+slsBuild.langs.PROFIL_COMMENT+" "+fExternalVars.profileOverflow['user_login'];
		return;
	}
	$('comentOnUserProfile').set('html', slsBuild.langs.PROFIL_COMMENT+' '+fExternalVars.profileOverflow['user_login']+':');
	
	var indexTo = indexFrom+num;
	
	var gifWait = new Asset.image(fConfigs['paths']['loading']+"waitComments.gif", {title:'Chargement de l\'image...'});
	var picsToLoad = new Array();
	for(var i=indexFrom;i<indexTo;i++){
		if (fExternalVars.profileOverflow['comments'].keyExists(i)) {
			var copyGif = gifWait.clone();
			copyGif.set('style', 'margin-top:10px');
			var divEl = new Element('div', {
				id: "comment-" + fExternalVars.profileOverflow['comments'][i]['user_wall_id']
			}).setStyles({
				display: 'block',
				width: '100%',
				marginBottom: '20px',
				'float': 'left'
			});
			var picEl = new Element('div').setStyles({
				display: 'block',
				'float': 'left',
				width: '50px',
				height: '50px',
				marginRight: '20px',
				'cursor'	:	'pointer'
			});
			eval("picEl.addEvent('click', function(){viewProfile("+fExternalVars.profileOverflow['comments'][i]['user']['user_id']+");});");
			picEl.grab(copyGif);
			var infosEl = new Element('div').setStyles({
				display: 'block',
				'float': 'left',
				width: '160px',
				marginRight: '20px'
			}).set('html', '<span>' + fExternalVars.profileOverflow['comments'][i]['user']['user_login'] + '</span><br /><span>' + fExternalVars.profileOverflow['comments'][i]['user_wall_date'] + '</span><br /><span>'+fExternalVars.profileOverflow['comments'][i]['user_wall_time']+'</span>');
			var msgEl = new Element('div').setStyles({
				display: 'block',
				'float': 'left',
				width: '510px'
			}).set('html', ''+fExternalVars.profileOverflow['comments'][i]['user_wall_body']+'');
			if (fExternalVars.profileOverflow['user_id'] == fMember['id']) {
				msgEl.setStyle('width', '450px');
				var deleteComment = new Element('div', {
					'class'	:	'deleteButton'
				});
				eval("deleteComment.addEvent('click', function(e){deleteWallComment("+fExternalVars.profileOverflow['comments'][i]['user_wall_id']+");e.stop();});");
			}
			divEl.grab(picEl);
			divEl.grab(infosEl);
			divEl.grab(msgEl);
			if (fExternalVars.profileOverflow['user_id'] == fMember['id'])
				divEl.grab(deleteComment);
			parentEl.grab(divEl);
			if (fExternalVars.profileOverflow['comments'][i]['user']['user_photo'] != 0 && fExternalVars.profileOverflow['comments'][i]['user']['user_photo'] != null) 
				picsToLoad.push('http://'+slsBuild.site.domainName+'/'+fConfigs['paths']['userMedias'] + fExternalVars.profileOverflow['comments'][i]['user']['user_id'] + "/" + fExternalVars.profileOverflow['comments'][i]['user']['user_photo'] + "_0.jpg");
			else {
				var defaultPic = "defaultPicture" + fExternalVars.profileOverflow['comments'][i]['user']['sex'].toUpperCase();
				picsToLoad.push('http://'+slsBuild.site.domainName+'/'+fConfigs['paths']['userMedias'] + fConfigs['profiles'][defaultPic] + "_0.jpg");
			}
		}
	}
	var pagEl = new Element('div').setStyles({
		display:'block',
		'float' : 'left',
		width:'100%',
		textAlign:'left',
		borderTop: '1px solid #FFF',
		paddingTop: '10px',
		color	: '#1f1f1f'
	});
	
	
	var start = 0;
	var strPag = "";
	if (fExternalVars.profileOverflow['comments'].length > indexTo)
		strPag += "<span class=\"valid\" style=\"margin-left:10px;float:right;\" onclick=\"loadViewProfileComments("+(indexTo)+","+num+")\">"+slsBuild.langs.SIDEBAR_MYMESSAGES_PAGIN_NEXT+"</span>";
	if (indexFrom != 0){
		((indexFrom-num) >= 0) ? start = indexFrom-num : start = 0;
		strPag += "<span class=\"valid\" style=\"float:right;\" onclick=\"loadViewProfileComments("+start+","+num+")\">"+slsBuild.langs.SIDEBAR_MYMESSAGES_PAGIN_PREVIOUS+"</span>";
	}
	
	
	
	if (strPag != "")
		pagEl.set('html', strPag);
		
	parentEl.grab(pagEl);
	var assets = new Asset.images(picsToLoad, {
		onComplete: function(){
			var g=0;
			for (var i=indexFrom;i<indexTo;i++){
				if (fExternalVars.profileOverflow['comments'].keyExists(i)) {
					var div = $('comment-' + fExternalVars.profileOverflow['comments'][i]['user_wall_id']);
					var pic = div.getFirst();
					pic.setStyle('background-image', 'url(' + picsToLoad[g] + ')');
					pic.empty();
					g++;
				}
			}
		}
	});	
}
function hideViewProfile(){
	var parent = $('viewProfileOverflow');
	parent.empty();
	parent.setStyle('display', 'none');
	setOverflowAction(false);
	fExternalVars.viewProfileOverflow = false;
}
function sendComment() {
	if (!$chk(fForms.viewProfilForm))
		return;
	if (fExternalVars.profileOverflow == null)
		return;
	if (fForms.viewProfilForm.getValue('comment').trim() == ""){
		fForms.viewProfilForm.displayGlobalMsg(slsBuild.langs.PROFIL_ERROR_NO_COMMENT, 'error');
		return;
	}
	var request = new Request.JSON({
		url: fUrls.WRITEONWALL,
		method:'post',
		onComplete:function(xhr){
			if (xhr['status'] == true){
				fForms.viewProfilForm.resetGlobalMsg();
				fForms.viewProfilForm.get("comment").set('value', '');
				fExternalVars.profileOverflow['comments'] = xhr['user']['comments'];
				loadViewProfileComments(0);
			}
			else{
				var str = "";
				for (var i=0;i<xhr['errors'].length;i++)
					str += xhr['errors'][i]+"<br />";
				
				fForms.viewProfilForm.displayGlobalMsg(str, 'error');
			}
		}
	}).send('user_id='+fExternalVars.profileOverflow['user_id']+'&user_wall_body='+fForms.viewProfilForm.getValue('comment').trim());
}
function profileSendMessageTo(id, login){
	fExternalVars.writeTo['id'] = id;
	fExternalVars.writeTo['login'] = login;
	smoothSideBar('myWebmail', 'newMessage');
}
function profileSendInvitationTo(id, login){
	fExternalVars.writeTo['id'] = id;
	fExternalVars.writeTo['login'] = login;
	smoothSideBar('myInvits', 'newInvit');
}
function addFriend(){
	if (fExternalVars.profileOverflow == null)
		return;
	var request = new Request.JSON({
		url: fUrls.ADDFRIENDS,
		method:'post',
		onComplete:function(xhr){
			if (xhr['status'] == true){
				fExternalVars.profileOverflow['isFriend'] = xhr['user']['isFriend'];
				loadViewProfilePictures(0);
			}
			else{
				var str = "";
				for (var i=0;i<xhr['errors'].length;i++)
					str += xhr['errors'][i]+"<br />";
				
				fForms.viewProfilForm.displayGlobalMsg(str, 'error');
			}
		}
	}).send('user_id='+fExternalVars.profileOverflow['user_id']);
}
function recommandPeople(){
	if ($chk($('profil-view-next')))
		$('profil-view-next').setStyle('display', 'none');
	if ($chk($('profil-view-previous')))
		$('profil-view-previous').setStyle('display', 'none');
	if ($chk($('profil-menu-actions')))
		$('profil-menu-actions').setStyle('display', 'none');
	 var span = new Element('span', {
	 	'html'	:	slsBuild.langs.PROFIL_ACTION_RECOMMANDATION,
		'styles': {
			'display'	:	'block',
			'float'		:	'left',
			'width'	:	'190px',
			'margin':	'10px 0 10px 10px',
			'color' : '#FFF'
		}
	 }).inject($('paginationAccountPictures'));
	 var div = new Element('div', {
	 	'html'	:	'<span style=\'display:block;float:left;width:100%;\'>'+slsBuild.langs.PROFIL_ACTION_RECOMMANDATION_MAILS+'</span><form id=\'profile-recommandation-form\'><input type=\'text\' autocomplete=\"off\" onkeyup=\'checkProfileFriendsList()\' name=\'msgTo\' id=\'profile-user-input\' style=\'display:block;font-size:0.8em;float:left;width:100%;color:#FFF;border-color:#FFF;\' /><ul id=\"profile-sendToList\" style=\'margin-top:50px;\'></ul><input type=\"hidden\" value=\"0\" name=\"send-to-id\" id=\"send-to-id\" /><input type=\"hidden\" name=\"old-sender\" /></form><span style=\'display:block;float:left;text-align:right;width:100%;color:#FFF;\' onclick=\'confirmRecommandation()\' class=\'valid\'>'+slsBuild.langs.FORMS_DEFAULT_SEND+'</span>',
	 	'styles': {
			'display'	:	'block', 
			'float'		:	'left',
			'width'		:	'170px',
			'margin'	:	'10px 0 0 10px',
			'color'		: '#FFF'
		}
	 }).inject($('paginationAccountPictures'));
	 fForms.recommandationForm = new Form('profile-recommandation-form');
}
function confirmRecommandation(){
	if (fForms.recommandationForm.getValue("send-to-id") == 0)
		return;
	var request = new Request.JSON({
		url: fUrls.RECOMMANDPEOPLE,
		method: 'post',
		onComplete:function(xhr){
			loadViewProfilePictures(0);
		}
	}).send("user_recipient_id="+fForms.recommandationForm.getValue("send-to-id")+"&user_object="+fExternalVars.profileOverflow['user_id']);
}
function banPeople(id){
	var request = new Request.JSON({
		'url'	 : fUrls.BANPEOPLE,
		'method' : 'post',
		 onComplete:function(xhr) {
		 	if (xhr['status'] == true){
				fExternalVars.profileOverflow['isBlocked'] = xhr['user']['isBlocked'];
				fExternalVars.profileOverflow['unBlocked'] = xhr['user']['unBlocked'];
				loadViewProfilePictures(0);
			}
			else{
				var str = "";
				for (var i=0;i<xhr['errors'].length;i++)
					str += xhr['errors'][i]+"<br />";
				
				fForms.viewProfilForm.displayGlobalMsg(str, 'error');
			}
		 }
	}).send("user_id="+id);
}
function viewCv(){
	var container = $('curriculumVitae');
	if ($chk(container.getFirst())){
		container.empty();
		return;
	}
	var request = new Request.JSON({
		url : fUrls.VIEWPROFILECV,
		method : 'post',
		onComplete:function(xhr){
			if (xhr['status'] == false && ExtObj.keyExists(xhr, 'errors') == false) {
				return;
			}
			else if (xhr['status'] == false && ExtObj.keyExists(xhr, 'errors') == true) {
					var str = "<table>";
					for (var i = 0; i < xhr['errors'].length; i++) {
						str += "<tr><td colspan=\"2\" style=\"font-size:1.1em;color:#FFF;text-align:left;\">" + xhr['errors'][i] + "</td><tr>";
					}
					str += "</table>";
					container.set('html', str);
					return;
				}
			if (xhr['user']['cv'].length == 0) {
				return;
			}
			var str = "<table><tr><td colspan=\"2\" style=\"font-size:1.1em;color:#FFF;text-align:left;\">"+slsBuild.langs.PROFIL_TEXT_CV+"</td><tr>";
			for (var i=0;i<xhr['user']['cv'].length;i++)
			{
				str += "<tr><td style=\"font-size:0.8em;width:220px;vertical-align:top;color:"+fConfigs['profiles']['color'+fExternalVars.profileOverflow['sex'].toUpperCase()]+"\">"+xhr['user']['cv'][i]['label']+" :</td><td style=\"color:#FFF;font-size:0.8em;vertical-align:top;\"><table>";
				for (var o=0;o<xhr['user']['cv'][i]['answers'].length; o++){
					str += "<tr><td style=\"color:#FFF;\">"+xhr['user']['cv'][i]['answers'][o]+"</td></tr>";
				}
				str += "</table></td></tr><tr height=\"5\"></tr>";
			}
			str += "</table>";
			container.set('html', str);
		}
	}).send("user_id="+fExternalVars.profileOverflow['user_id']);
}
function checkProfileFriendsList(){
	if (fForms.recommandationForm.getValue('msgTo').trim() == ""){
		$('profile-sendToList').setStyle('display', 'none');
		if (fForms.recommandationForm.getValue('msgTo').trim() == "") {
			fForms.recommandationForm.get('send-to-id').value = '0';
			fForms.recommandationForm.get('old-sender').value = "";
		}
	}
	else {
		fForms.recommandationForm.get('old-sender').value = fForms.recommandationForm.getValue('msgTo');
		var json = new Request.JSON({
			url: fUrls.CHECKSENDER,
			method: 'post',
			onComplete:function(xhr){
				var users = xhr['users'];
				if (users.length > 0)
					fillProfileFriendsList(users);
			}
		}).send('user='+fForms.recommandationForm.getValue('msgTo').trim());
	}
		
}
function fillProfileFriendsList(array){
	$('profile-sendToList').empty();
	for (var i=0;i<array.length;i++){
		if (i < fConfigs['complexBoxes']['myWebmail']['menu']['items']['newMessage']['nbFriends']) {
			var a = new Element('a').setStyle('float', 'left').addEvent('click', function(e){
				e.stop();
				selectProfileFriend(this);
			}).set('rel', array[i]['user_login']).set('href', array[i]['user_id']);
			a.set('html', "<div style=\"display:block;width:50px;float:left;height:50px;margin:0 10px 0 0;background-image:url(http://" + slsBuild.site.domainName + "/" + fConfigs['paths']['userMedias'] + array[i]['user_id'] + "/" + array[i]['user_photo'] + "_0.jpg);background-repeat:no-repeat;background-position:top left;\"></div>" + array[i]['user_login']);
			var li = new Element('li').grab(a);
			$('profile-sendToList').grab(li);
		}
	}
	if (Browser.Engine.trident)
		$('profiles-sendToList').setStyles({
			marginLeft: '-170px',
			marginTop: '20px'
		});
	$('profile-sendToList').setStyle('display', 'block');
	fStatus.menus.friendsProfileMenuOpen = true;
}
function selectProfileFriend(a){
	hideProfileFriendsMenu();
	fForms.recommandationForm.get('msgTo').value = a.get('rel');
	fForms.recommandationForm.get('send-to-id').value = a.get('href');
}
function hideProfileFriendsMenu(){
	$('profile-sendToList').empty();
	$('profile-sendToList').setStyle('display', 'none');
	fStatus.menus.friendsProfileMenuOpen = false;
}