		var oMap;
		function viewMode(bMode){
			bViewMode=bMode;
			
			filterContent();
			var oRad = G$('rad_view_'+bMode);
			if(oRad!=null){
				oRad.checked=true;;
			}
			//save state
			var sUrl = sUserUpdateUrl+'?method=PUT&user_id='+getUserId()+'&parameters=[userPreferences.contentViewPref='+bViewMode+']';
			var oReq = new HttpReq(sUrl,'GET',function(){
				if(oReq!=null && oReq.IsReady() ){				
				}
			});
			
			bab_track('profile/view_mode/'+bMode,1);
		}
		
		function displayContent(sBodyHTML,arr){
			var oCont=G$('content_list');
			if(bViewMode){
				if(arr.length<2){
					for(ii=0;ii<2;ii++){
						sBodyHTML+='<tr><td colspan="6" class="first">&nbsp;</td></tr>'+
							'<tr class="alt"><td colspan="6" class="first">&nbsp;</td></tr>';
					}
				}
				oCont.innerHTML=getAudioTableHTML(sBodyHTML);
			}else{
				oCont.innerHTML=sBodyHTML;
			}
		}
		//NOTE: this output should always match the jsp output
		function getAudioTableHTML(sBodyHTML){
			return '<table class="tblAudio" style="border-top:1px solid #CCC;">'+
						'<thead>'+
							'<tr>'+
								'<td class="firstHead">Name</td>'+
								'<td>Artist</td>'+
								'<td>Album</td>'+
								'<td>Genre</td>'+
								//'<td>Category</td>'+
								'<td>Play Count</td>'+
							'</tr>'+
						'</thead>'+
						'<tbody>'+
						sBodyHTML+
						'</tbody>'+
					'</table>';
		}
		function getAudioRow(oContent,bAlt){
			var sHTML='';
			var sOwnerLnk='';
			if(oContent.isOwner){
				sOwnerLnk=OWNER_STR;
			}
			var sType;
			var sListStr='';
			if(selContType==1){
				sType='contentFav';
			}else if(selContType==2){
				sType='contentList';
				sListStr='::'+iSelPlId;
			}else{
				sType='content';
			}
			
			var sCat='';
			if(oContent.category){
				sCat=oCatMap[oContent.category];			
			}
			
			var sIdStr='id="'+sType+'::'+oContent.resourceId+sOwnerLnk+sListStr+'"';
			
			if(bViewMode){
				sHTML+='<tr '+sIdStr+' ondblclick="viewContent('+oContent.resourceId+');" '+
					'onclick="selectContent(this);"';
					if(bAlt){sHTML+='class="alt" '}
					sHTML+='>'+
					'<td class="first">'+
						'<img src="'+sIMG_PATH+'/btnSmallPlay.gif" class="hand" '+
						'alt="Play" onclick="playAudio(\''+oContent.encId+'\');return false;"/> '+
						'<span class="default" onclick="showContexMenu(event);">'+oContent.title+'</span>'+
					'</td>'+
					'<td onclick="showContexMenu(event);">'+oContent.artist+'</td>'+
					'<td onclick="showContexMenu(event);">'+oContent.album+'</td>'+
					'<td onclick="showContexMenu(event);">'+oContent.genre+'</td>'+
					//'<td onclick="showContexMenu(event);">'+sCat+'</td>'+
					'<td onclick="showContexMenu(event);">'+oContent.playcount+'</td>'+
				'</tr>';
			}else{
				sHTML+='<div class="contentIcon" '+sIdStr+' ondblclick="viewContent('+oContent.resourceId+');" '+
					' onclick="selectContent(this);"> '+
					'<div class="avatarCont contentCont" onclick="showContexMenu(event);"> ';
						if(oContent.imageURI){
					    	sHTML+='<img src="'+oContent.imageURI+'" class="imgAvatar" alt=""/> ';
					   	}else{
					    	sHTML+='<img src="'+sIMG_PATH+'default.gif" alt="" class="imgAvatar"/> ';
					    }
						sHTML+='<img src="'+sIMG_PATH+'roundedWhite75.gif" alt="" class="rounded75"/> '+
				    '</div>'+
				    '<div class="friendAlias">'+
				    	'<img src="'+sIMG_PATH+'btnSmallPlay.gif" class="hand" '+
						'alt="Play" onclick="playAudio(\''+oContent.encId+'\');return false;"/> '+
						'<a href="/'+oContent.resourceId+'/'+stripNonAlphaNumeric(oContent.title)+'/'+sContentPage+'" '+
							'>'+limitString(oContent.title,11)+'</a> <br/>'+
				    	'<span class="fontNormal" onclick="showContexMenu(event);">'+limitString(oContent.artist,17)+'</span> '+
				    '</div> '+
				'</div>';
			}
			return sHTML;
		}
		function limitString(ss,max){
			if(!max){max=14;}
			if(ss.length > max){
				ss=ss.substring(0,max)+'&#133;';
			}
			return ss;
		}
		var oSelAud=null;
		function selectContent(oEle){
			if(oSelAud!=null){
				oSelAud.ele.className=oSelAud.prevClass;
			}
			oSelAud = new SelectedContent(oEle);
			return false;
		}
		function SelectedContent(oEle){
			this.ele=oEle;
			this.prevClass=oEle.className;
			
			oEle.className=(oEle.className=="alt")?"selectedCont":oEle.className+" selectedCont";
		}
		//------------------------Comment----------------
		function replyComment(userId,sUsrAlias,oLnk,iStatus){
			var oDiv = G$('dvNewComment');
			var oFrm = G$('frmNewComment');
			var oResponse = G$('dvCommResponse');
			
			var sOrig;
			if(document.all){
				sOrig=oLnk.parentNode.parentNode.parentNode.nextSibling.firstChild.innerHTML;
			}else{
				sOrig=oLnk.parentNode.parentNode.parentNode.nextSibling.nextSibling.firstChild.nextSibling.innerHTML;
			}
			
			oResponse.innerHTML='<strong>'+unescape(sUsrAlias)+'</strong> wrote: '+sOrig
				+'<br/></br>';
			
			oFrm.user_id.value=userId;
			toggleDisplay(oDiv);
			
			if(iStatus!=1){
				G$('radPub').checked=true;
			}else{
				G$('radPri').checked=true;
			}
			
			window.location='#commentBlock';
		}
		function submitUserComment(frm){
			var oDiv=G$('dvComments');
			var sCmt = parseComments(frm.comment.value,oDiv);
			
			var sParams='user_id='+frm.user_id.value+'&comment='+escape(sCmt)+'&status='+((G$('radPri').checked)?1:2)
			var sUrl=CONTENT_PATH+'/xui/user-comment.xui?';
			var oReq = new HttpReq(sUrl,'POST',function(){
				if(oReq!=null && oReq.IsReady() ){
					var bPrivate = (frm.radPri!=null && frm.radPri.checked)?true:false;
					if(frm.orig_user_id.value!=frm.user_id.value){
						popMessage('Your comment has been sent');
						frm.user_id.value=frm.orig_user_id.value;
						G$('dvCommResponse').innerHTML='';
					}else{
						addCommentToEle(oDiv,sCmt,0,1,bPrivate);
					}
					frm.comment.value='';
					hideEle(frm.parentNode);
					
					bab_track('profile/comment/add',1);
				}
			},sParams);
			return false;
		}
		
		function deleteComment(commentId,oComment){
			var sUrl=CONTENT_PATH+'/xui/user-comment.xui?method=delete&comment_id='+commentId;
			var oReq = new HttpReq(sUrl,'GET',function(){
				if(oReq!=null && oReq.IsReady() ){
					hideEle(G$('dvComment_'+commentId));
					
					bab_track('profile/comment/delete',1);
				}
			});
		}
		function editComment(frm){
			var sUrl=CONTENT_PATH+'/xui/user-comment.xui?';
			var sParams = 'method=PUT&user_id='+frm.resource_id.value+'&'+getResterizeParams(frm);
			var oReq = new HttpReq(sUrl,'POST',function(){
					if(oReq!=null && oReq.IsReady() ){
						if(oReq.GetText()==''){
							
						}else{
							
						}
					}
				},sParams);
			return false;
		}
		
		
		//******************************* Playlist *******************************//		
		var iSelPlId;
		function selectPlaylist(oPl,iType){
			var iResourceId=iSelPlId=parseIntAll(oPl.id);
			//sent to player
			//playAudio(iResourceId,'playlist');
			//highlight
			selectTreeNode(oPl);
			//lookup object
			var oPlaylist;
			if(!iType){
				oPlaylist=getObjById(arrUserPlaylists,iResourceId);
			}else if(iType==1){
				oPlaylist=getObjById(arrUserPlaylistsFavorites,iResourceId);
			}else if(iType==2){
				oPlaylist=getObjById(arrBabPlaylists,iResourceId);
			}else{
				oPlaylist=getObjById(arrCommPlaylists,iResourceId);
			}
			
			
			arrSelContent=oPlaylist.content;
			
			
			selContType=2;
			var sBodyHTML='';
			if(oPlaylist.content.length>0){
				for(var cc=0;cc<oPlaylist.content.length;cc++){
					var bAlt=(cc%2==1);
					sBodyHTML+=getAudioRow(oPlaylist.content[cc],bAlt);
				}
				displayContent(sBodyHTML,oPlaylist.content);
			}else{
				var oCont=G$('content_list');
				var sHTML='';
				if(bIsOwner){
					sHTML='Your playlist is empty';
				}else{
					sHTML='This playlist is empty';
				}
				oCont.innerHTML=sHTML;
			}
			showPlaylistBtn();
			
		}
		function playRecentPlaylist(id){
			playAudio('http://www.babulous.com'+sActivtyService+'xmlFormat=playlist&action=recent&userId='+id);
		}
		function playSelPlaylist(){
			playAudio(iSelPlId,'playlist');
		}
		function playFav(userId){
			playAudio('http://www.babulous.com'+sFavoriteUrl+'?user_id='+userId+'&filter=au','playlist');
		}
		function hidePlayBtn(){
			hideEle(G$('spPlaylistPlay'));
			hideEle(G$('spPlayContents'));
			hideEle(G$('spPlayFav'));
		}
		function showPlayContBtn(){
			hidePlayBtn();
			showEleInline($('spPlayContents'));
		}
		function showPlaylistBtn(){
			hidePlayBtn();
			showEleInline($('spPlaylistPlay'));
		}
		function showPlayFavBtn(){
			hidePlayBtn();
			showEleInline($('spPlayFav'));
		}
		
		function deletePlaylist(iResourceId){
			var bConf=confirm('Are you sure you want to delete the selected playlist?');
			if(bConf){
				var sUrl = sSetUrl+'?method=delete&resource_id='+iResourceId;	
				var oReq = httpRequest('GET',sUrl);				
				if(oReq.responseText==''){
					var sId='playlist::'+iResourceId+OWNER_STR;
					removeElement($(sId));
				}else{
					popMessage(oReq.responseText+'<br/><br/>'+sGenericError);
				}
			}
		}
		function oPlaylist(iResourceId,sName){
			this.resourceId=iResourceId;
			this.name=sName;
			
			this.ShowRenamePop=function(){
				var sHTML='<form onsubmit="oPlayCtrl.SubmitRename(this);return false;">'+
					'<table>'+
					'<tr>'+
					'<td><label for="txtRenameName">Name:</label></td>'+
					'<td><input type="text" id="txtRenameName" name="name" maxlength="<%=iInputMaxLength %>" size="35"/></td>'+
					'</tr>'+
					'<tr>'+
					'<td></td>'+
					'<td><input type="submit" value="Rename Playlist" class="btnStyle"/> '+
					'<input type="button" value="Cancel" onclick="oPlayCtrl.ClosePop();" class="btnStyle"/></td>'+
					'</tr>'+
					'</table>'+
					'</form>';
				
				var oDiv = G$('dvSharedPop');
				oDiv.innerHTML=sHTML;
				toggleDisplay(oDiv);
				centerOnScreen(oDiv);
				//disablePage();
			};
			this.SubmitRename=function(oFrm){
				var sUrl = sSetUrl+'?method=PUT&resource_id='+iResourceId+
					'&'+getResterizeParams(oFrm);
				var oReq = httpRequest('GET',sUrl);
				this.ClosePop();
				
				var id="playlist::"+this.resourceId+"::owner::label";
				G$(id).innerHTML=oFrm.name.value+' ';
				return false;
			};
			this.ClosePop=function(){
				var oDiv = G$('dvSharedPop');
				toggleDisplay(oDiv);
				//enablePage();
			}
		}
		var oPlayCtrl;
		function renamePlaylist(iResourceId){
			oPlayCtrl = new oPlaylist(iResourceId);
			oPlayCtrl.ShowRenamePop();
		}
		function removeFromPlaylist(iContentId){
			var oSet=getObjById(arrUserPlaylists,iSelPlId);
			var oContent=getObjById(oSet.content,iContentId);
			var sParams='method=delete&content_set_id='+oContent.id+'&set_id='+iSelPlId;
			var sUrl=sAddContentToSet+'?'+sParams;
			
			
			var oReq = new HttpReq(sUrl,'GET',function(){
				if(oReq!=null && oReq.IsReady()){					
					if(oReq.GetText()==''){						
						var sId='contentList::'+iContentId+OWNER_STR+'::'+iSelPlId;
						try{
							removeElement($(sId));
						}catch(e){
							track_error('could not find playlist','profile',0);
						}
						var iArrIdx=getObjIdxById(oSet.content,iContentId);
						arrUserContent=arrUserContent.remove(iArrIdx);
						
						bab_track('profile/remove_content',1);
					}else{
						popMessage(sGenericError);
					}
				}
			});
		}
		
		var oContentCtrl = {
			curID : null,
			DIV_ID : 'dvSharedPop',
			ShowDeleteMenu : function(iResourceId){
				this.curID = iResourceId;
				var sHTML='<div style="padding:20px;">Are you sure you\'d like to remove this file?<br/><br/>'+
					'<input type="button" value="Yes - Remove From Profile" onclick="oContentCtrl.Delete()" /> '+
					'<input type="button" value="Yes - Delete From Babulous" onclick="oContentCtrl.Delete(true)" /> '+
					'<input type="button" value="Cancel" onclick="oContentCtrl.CloseDialog()" />'+
					'</div>';
				var oDiv = G$(this.DIV_ID);
				oDiv.innerHTML=sHTML;
				showEle(oDiv);
				centerOnScreen(oDiv);
				disablePage();
			},
			Delete : function(bPurge){
				var sUrl = sUpdateContent+'?method=delete&resource_id='+this.curID;
				
				if(bPurge){
					sUrl+="&type=purge";
				}
				var oReq = new HttpReq(sUrl,'GET',function(){
					if(oReq!=null && oReq.IsReady() ){
						if(oReq.GetText()==''){
							var sId='content::'+iResourceId+OWNER_STR;
							removeElement($(sId));
							var iArrIdx=getObjIdxById(arrUserContent,iResourceId);
							arrUserContent=arrUserContent.remove(iArrIdx);
							
							bab_track('content/delete/'+bPurge,1);
						}else{
							popMessage(sGenericError);
						}
					}
				});
				
				this.CloseDialog();
			},
			CloseDialog : function(){
				var oDiv = G$(this.DIV_ID);
				oDiv.innerHTML='';
				hideEle(oDiv);
				enablePage();
			}
		}
		function deleteContent(iResourceId){
			oContentCtrl.ShowDeleteMenu(iResourceId);
		}
		
		//******************************* user info *******************************
		function EditProfile(){// showUploadImage(${model.user.id});
			var sBASE='dvEdit';
			var sDEF_TAB_ID='Gen';
			var oCurTab = null;
			var oCurLnk = null;
			var sID='dvEditProfile';
			this.bDoRefresh=false;
			this.Display=function(sTab,oOpt){
				var bOpt=false;
				showEle($(sID));
				if(!sTab){
					sTab=sDEF_TAB_ID;
				}
				
				this.DisplayTab(sTab,oOpt);
				window.location="#";
			}
			this.DisplayTab=function(sTab,oOpt){
				this.UpdateStatus("");
				if(oCurTab!=null){
					hideEle(oCurTab);
				}
				var oNewTb = $('dvEdit'+sTab);
				showEle(oNewTb);
				oCurTab=oNewTb;
				this.DeselectCur();
				this.SelectLnk(sTab);
				
				//special case
				if(oOpt){
					this.DoImgFrm(oOpt);
				}
				if((sTab=='Artist' || sTab=='Questions') && navigator.userAgent.indexOf('Gecko')>0){
					var oArtFrm=$('frmQuestions');
					oArtFrm.style.height=(window.innerHeight-300)+'px';
				}
			}
			this.SelectLnk=function(sTab){
				var oLnk=$('lnk'+sTab);
				oLnk.parentNode.className='ontab';
				oCurLnk=oLnk;
			}
			this.DeselectCur=function(){
				if(oCurLnk!=null){	
					oCurLnk.parentNode.className='offtab';
				}
			}
			this.DoImgFrm=function(iResourceId){
				var sUrl=sUserImageUpload+'?resourceType=user'+'&resourceId='+iResourceId;
				var oFrame = $('frmImageUpload');
				oFrame.src=sUrl;
			}
			this.UpdateStatus=function(mm){
				$('dvEditStatus').innerHTML=mm;
				if(mm.length==0){
					hideEle($('dvEditStatus'));
				}else{					
					showEle($('dvEditStatus'));
					window.location="#userAlias";
				}
			}
			this.HideEdit=function(){
				if(this.bDoRefresh){
					window.location.reload();
				}else{
					hideEle($(sID));
				}
			}
		}
		var oProfEditCntrl = new EditProfile();
		function showEditProfile(sTab){
			var sID='dvEditProfile';
			showEle($(sID),true);
			//toggle display hides select boxes
			
			
			//$('selUserLang').style.visibility='visible';
			
		}
		function countryChange(cc){
			$('trZipCode').style.display=(cc!='USA')?'none':'';
		}
		function submitProfileInfo(frm){
			if(!frm.email.value.validateEmail()){
				$('dvEditProfileError').innerHTML='Invalid email address';
				showEle($('dvEditProfileError'));
				return false;
			}else if(frm.password.value!=frm.passwordConfirm.value){
				$('dvEditProfileError').innerHTML='Passwords dont match';
				showEle($('dvEditProfileError'));
				return false;
			}else if(frm.gender.value=="" && iUserStatus!=10){
				$('dvEditProfileError').innerHTML='Please select your gender';
				showEle($('dvEditProfileError'));
				return false;
			}else{//hide errors by default
				hideEle($('dvEditProfileError'));
			}
			//strip char
			frm.alias.value=frm.alias.value.replace("'","");
			
			if(frm.personalLink.value.indexOf('http://')!=0 && frm.personalLink.value.length>1){
				frm.personalLink.value='http://'+frm.personalLink.value;
			}
			if(frm.txaAboutMe.value.trim()==''){frm.txaAboutMe.value=' ';}
			
			var sParams = 'method=PUT&user_id='+frm.resource_id.value+'&'+getResterizeParams(frm)+getCacheKill();;
			
			var sUrl = sUserUpdateUrl;
			var oReq = new HttpReq(sUrl,'POST',function(){
				if(oReq!=null && oReq.IsReady() ){
					if(oReq.GetText()==''){
						//update the new values
						$('userAlias').innerHTML=frm.alias.value;
						try{
							if(!document.all){
								var sLang = frm.userLanguage.options[frm.userLanguage.selectedIndex].text.toString();
								$('userLanguage').innerHTML=sLang;
								if(frm.userLanguage.value.length > 0){showEle($('languageLabel'));}
							}
							if(frm.gender.value!=""){
								$('userGender').innerHTML=frm.gender.options[frm.gender.selectedIndex].text;
								showEle($('genderLabel'));
							}
						}catch(e){}
						$('userLink').innerHTML='<a href="'+frm.personalLink.value+'" target="_blank">'+
							frm.personalLink.value.replace('http://','').replace('www.','');+'</a>';
						
						setDspLocation(frm);
						
						$('userAbout').innerHTML=frm.aboutMe.value.chop(270);
						//if(frm.aboutMe.value.length>280){
						/*			'<br/><a href="" onclick="toggleDisplay($(\'dvFullAbout\'));return false;">more</a>';
							$('dvFullAbout').innerHTML=frm.aboutMe.value;
						}else{
							$('userAbout').innerHTML=frm.aboutMe.value;
						}*/
						//display the label span if hidden
						if(frm.personalLink.value.length > 0){showEle($('linkLabel'));}
						if(frm.location && frm.location.value.length > 0){showEle($('locationLabel'));}
						
						//hide form
						//toggleDisplay(frm.parentNode.parentNode,true);
						oProfEditCntrl.UpdateStatus('Your changes have been saved');
						
						
						bab_track('profile/info/submit',1);
					}else{
						$('dvEditProfileError').innerHTML='There was a problem! Try again.';
					}
				}
			},sParams);
			
			return false;
		}
		function setDspLocation(frm){
			var locDsp=null;
			var locSrch=null;
			//set default to loc rulls may override it
			if(frm.location && frm.location.value.length > 0){
				locSrch=locDsp=frm.location.value;
			}
			
			if(locSrch==null && frm.countryCode && frm.countryCode.value!='USA'){
				locSrch=locDsp= frm.countryCode.options[frm.countryCode.selectedIndex].text;
			}else if(frm.countryCode && frm.countryCode.value=='USA'){
				if(locDsp==null){
					locDsp=frm.countryCode.text;
				}
				
				if(frm.zipCode.value.length==5){
					locSrch=frm.zipCode.value;
				}else if(locSrch==null){
					locSrch=frm.countryCode.options[frm.countryCode.selectedIndex].text;
				}
			}
			if(locDsp!=null){
				$('userLocation').innerHTML='<a href="http://maps.google.com/maps?q='
					+locSrch+'" target="_blank">'
					+locDsp+'</a>';
			}
		}
		
		function submitProfileCSS(frm){
			var sParams = 'method=PUT&user_id='+frm.resource_id.value+'&'+getResterizeParams(frm);

            var sUrl = sUserUpdateUrl;
			var oReq = new HttpReq(sUrl,'POST',function(){
				if(oReq!=null && oReq.IsReady() ){
					if(oReq.GetText()==''){
						oProfEditCntrl.UpdateStatus('Loading your style changes...');
						window.location.reload();	
						//hide form
						//toggleDisplay(frm.parentNode,true);
					}else{
						//$('dvEditProfileError').innerHTML='There was a problem! Try again.';
					}
				}
			},sParams);
			
			return false;
		}
		function StyleManager(){
			var sIMG_ID='imgThemePrev';
			var sFORM_ID='frmUserCSS';
			var oThemes = {
					def:" ",
					red:
						".accentBlock{background-color:red;}",
					green:
						".accentBlock{background-color:green;}",
					contrast:
						".accentBlock{background-color:#333;}.accentBlockGrey{background-color:#999;}"
				}
			this.PreviewTheme=function(tt){
				$(sIMG_ID).src=sIMG_PATH+'themes/'+tt+'.gif';
				
				this.SetTheme(tt);
			}
			this.SetTheme=function(tt){
				var oForm = $(sFORM_ID);
				alert(oThemes[tt]);
				oForm.css.value=oThemes[tt];
			}
			this.SaveTheme=function(){
				submitProfileCSS(oForm);
			}
			this.ClearStyles=function(){
				var oForm = $(sFORM_ID);
				oForm.css.value=' ';
				submitProfileCSS(oForm);
			}
		}
		var oStyleManager = new StyleManager();
		
		function submitPref(frm){
			var sParams = 'method=PUT&user_id='+frm.resource_id.value+'&'+getResterizeParams(frm);
			var sUrl = sUserUpdateUrl;
			
			var oReq = new HttpReq(sUrl,'POST',function(){
					if(oReq!=null && oReq.IsReady() ){
						if(oReq.GetText()==''){
							//hide form
							//toggleDisplay(frm.parentNode.parentNode,true);
							oProfEditCntrl.UpdateStatus('Your preferences have been updated');
							
							bab_track('profile/pref/submit',1);
						}
					}
				},sParams);
			return false;
		}
		function submitQuestion(frm){
			var sParams = 'method=PUT&user_id='+frm.resource_id.value+'&'+getResterizeParams(frm);
			var sUrl = sUserUpdateUrl;
			var oReq = new HttpReq(sUrl,'POST',function(){
					if(oReq!=null && oReq.IsReady() ){
						if(oReq.GetText()==''){
							oProfEditCntrl.UpdateStatus('Your information have been updated');
							//var dvNull=$('nullArtistInfo');
							//if(dvNull!=null){hideEle(dvNull);}
							for(var ee=0;ee<frm.elements.length;ee++){
								if(frm.elements[ee].type=='textarea' && frm.elements[ee].value.length>1){
									showEle($(frm.elements[ee].name+"Cont"));
									$(frm.elements[ee].name+"Inner").innerHTML=frm.elements[ee].value;
								}else{
									hideEle($(frm.elements[ee].name+"Cont"));
								}
							}
							
							bab_track('profile/questions/submit',1);
						}
					}
				},sParams);
			return false;
		}
		function submitArtistInfo(frm){
			var sParams = 'method=PUT&'+getFormParams(frm);
			var sUrl = sArtistInfoUrl;
			var oReq = new HttpReq(sUrl,'POST',function(){
					if(oReq!=null && oReq.IsReady() ){
						if(oReq.GetText()==''){
							oProfEditCntrl.UpdateStatus('Your information have been updated');
							var dvNull=$('nullArtistInfo');
							if(dvNull!=null){hideEle(dvNull);}
							for(var ee=0;ee<frm.elements.length;ee++){
								if(frm.elements[ee].type=='textarea' && frm.elements[ee].value.length>1){
									showEle($(frm.elements[ee].name+"Cont"));
									$(frm.elements[ee].name+"Inner").innerHTML=frm.elements[ee].value;
								}else{
									hideEle($(frm.elements[ee].name+"Cont"));
								}
							}
							
							bab_track('profile/artist_questions/submit',1);
						}
					}
				},sParams);
			return false;
		}
		/*
		function showUploadImage(iResourceId){
			var sUrl=sUploadImageUrl+'?resourceType=user'+'&resourceId='+iResourceId;
			var oFrame = $('frmImageUpload');
			oFrame.src=sUrl;
			toggleDisplay($('dvEditImage'),true);
		}
		*/
		function uploadFinished(){	
			hideEle($('dvEditImage'));
			window.location.reload();
		}
		function toggleMoreAbout(evt){
			var oDivAbt=$('dvFullAbout');
			toggleDisplay(oDivAbt);
			positionOnEvent(evt, oDivAbt);
			oDivAbt.style.top=(parseInt(oDivAbt.style.top)-150)+'px';
			oDivAbt.style.left=(parseInt(oDivAbt.style.left)-50)+'px';
		}
		function showApproveFriends(){
			var oDiv = $('dvPendingFriends');
			toggleDisplay(oDiv);
			window.location="#dvFriendsCont";
		}
		function submitProfileVideo(frm){
			var sCode=frm.profileVideo.value;
			var oErr = $('dvVideoError');
			//validate
			var r = /(((?:<embed){1}(?:\s|\S)*<\/embed{1}>)|((?:<object){1}(?:\s|\S)*<\/object{1}>)){1}/i;
			var rTwo = /<object(?:\s|\S)*<\/object(?:\s|\S)*<object/i;
			if(sCode.trim()==''){
				//its cool i guess
			}else if(!r.test(sCode)){
				oErr.innerHTML='The code was incomplete, please recopy the code.';
				showEle(oErr);
				return false;
			}else if(rTwo.test(sCode)){
				oErr.innerHTML='Please skin one video at a time.';
				showEle(oErr);
				return false;
			}
			
			hideEle(oErr);
			//remove all extra HTML (messes with alignment)
			var arrExec=r.exec(sCode);
			if(arrExec)
				sCode=arrExec[0];
			//convert param tags to singletons
			frm.profileVideo.value=sCode.replace(/><\/param>/g,"/>");
			
			
			var sParams = 'method=PUT&user_id='+frm.resource_id.value+'&'+getResterizeParams(frm);
			var sUrl = sUserUpdateUrl;
			var oReq = new HttpReq(sUrl,'POST',function(){
				if(oReq!=null && oReq.IsReady() ){
					if(sCode.length>1){
						displayProfileVideo(frm.profileVideo.value);
					}else{
						$('dvVideoCont').innerHTML='';
					}
					oProfEditCntrl.UpdateStatus('Your video has been saved');
					
					bab_track('profile/video/submit',1);
				}
			},sParams);
			
			return false;
		}
		function submitUniqueUrl(frm){
			var oTxt = $('txtUnique');
			var sName = oTxt.value;
			$('uniqueError').innerHTML='';
			if(sName.length>2 && /[A-Za-z0-9-]+/.test(sName) && sName.length<100 ){
				var oNull=$('uniqueNull');
				if(oNull!=null){
					hideEle(oNull);
				}
				var oReq = new HttpReq(sUniqueUrl,'POST',function(){
					if(oReq!=null && oReq.IsReady()){
						if(oReq.GetText()==''){
							oProfEditCntrl.UpdateStatus('Your URL has been saved');
							showEle($(oTxt.name+"Cont"));
							$(oTxt.name+"Inner").innerHTML=sName;
							
							bab_track('profile/unique/submit',1);
						}else{
							oProfEditCntrl.UpdateStatus('');
							$('uniqueError').innerHTML='Sorry, this name is already taken.  Please try a different name.';
						}
					}
				},"&uniqueName="+sName);
				
			}else{
				oProfEditCntrl.UpdateStatus('');
				var sError='Your name contains invalid characters.';
				if(sName.length<4){
					sError='Your must be at least 4 characters long, sorry.';
				}
				$('uniqueError').innerHTML=sError;
			}
			
			return false;
		}
		function displayProfileVideo(sVid){
			var oDiv=$('dvVideoCont');
			oDiv.innerHTML='<div>'+sVid.replace(rWIDTH,'width="99%"').replace(rHEIGHT,'height="325"')+'</div>'; 
		}
		function deleteAccount(uid){
			if(uid==getUserId()){
				var bConf = confirm('Are you sure you want to delete your account?\n Babulous will not be able to revert this action!');
				if(bConf){
					bConf = confirm('Clicking OK will disable your account and you will no longer be able to access babulous.');
					if(bConf){
						var sUrl = sUserUpdateUrl;
						var sParams = 'method=PUT&user_id='+uid+'&parameters=[status=3]';
						var oReq = new HttpReq(sUrl,'POST',function(){
							if(oReq!=null && oReq.IsReady() ){
								var sHTML = '<div class="aCenter">Your account has been deleted, thank you for using babulous '+
									'<br/><br/><input type="button" value="OK" onclick="window.location=\''+sLogoutUrl+'\';"/><br/></div>';
								popMessage(sHTML,true);
							}
						},sParams);
					}
				}
			}else{
				popMessage('Shame on you for trying that.');	
			}
		}
		//******************************* /user info *******************************//
		
		
		//******************************** FRIENDS *********************************//
		function addFriend(userId){
			if(bIsLoggedIn){
				var sUrl=CONTENT_PATH+'/xui/friends.xui?friend_id='+userId;
				var oReq = new HttpReq(sUrl,'POST',function(){
					if(oReq!=null && oReq.IsReady() ){
						popMessage('Your friend request has been sent');
						$('frndLnk').innerHTML='pending friendship';//TODO: opacity fade
						bab_track('profile/friend/add',1);
					}
				});
			}else{
				oLoginCntrl.ShowRegistration('Login to add this friend.');
			}
		}
		function removeFriend(userId,oLink){
			var bConf = confirm('Are you sure you want to remove this friend?');
			if(bConf){
				var sUrl=CONTENT_PATH+'/xui/friends.xui?method=delete&friend_id='+userId;
				var oReq = new HttpReq(sUrl,'GET',function(){
					if(oReq!=null && oReq.IsReady() ){
						if(oReq.GetText()==''){
							hideEle(oLink.parentNode);
							//hideEle($('user_'+));
							bab_track('profile/friend/remove',1);
						}
					}
				});	
			}
		}
		function acceptFriend(userId,oLink){
			var sUrl=CONTENT_PATH+'/xui/friends.xui?method=put&accept=true&friend_id='+userId;
			var oReq = new HttpReq(sUrl,'GET',function(){
				if(oReq!=null && oReq.IsReady() ){
					if(oReq.GetText()==''){
						popMessage('Your friend has been approved.');
						iNumFrndReq--;
						testForAutoHidePenFrnd();
						hideEle($('fanLnk'));
						bab_track('profile/friend/accept',1);
					}
				}
			});	
			hideEle(oLink.parentNode);
		}
		function denyFriend(userId,oLink){
			var sUrl=CONTENT_PATH+'/xui/friends.xui?method=put&accept=false&friend_id='+userId;
			var oReq = new HttpReq(sUrl,'GET',function(){
				if(oReq!=null && oReq.IsReady() ){
					if(oReq.GetText()==''){
						hideEle(oLink.parentNode.parentNode);
						popMessage('<br/> &nbsp; Request deniend! &nbsp; <br/><br/>');
						iNumFrndReq--;
						testForAutoHidePenFrnd();
						bab_track('profile/friend/deny',1);
					}
				}
			});
		}
		function testForAutoHidePenFrnd(){
			if(iNumFrndReq<1){
				toggleDisplay($('dvPendingFriends'));
			}
		}
		
		function hideLnkDot(){
			var oDot = $('spLnkDot');
			if(oDot!=null){
				hideEle(oDot);
			}
		}
		
		function addFan(artistId,oLnk){
			if(bIsLoggedIn){
				var sUrl=CONTENT_PATH+'/xui/artistFan.xui?artistId='+artistId;
				var oReq = new HttpReq(sUrl,'POST',function(){
					if(oReq!=null && oReq.IsReady() ){
						popMessage('You are now a fan!');
						hideEle(oLnk);
						//hideLnkDot();
						bab_track('profile/fan/add',1);
					}
				});
			}else{
				oLoginCntrl.ShowRegistration('Login to become a fan.');
			}
		}
		//******************************** /FRIENDS ************************************
		//******************************** FAVORITES ************************************
		function removeFav(iResourceId,sType){
			if(IsNumeric(iResourceId)){			
				if(!sType){sType='AU';}
				var sUrl = CONTENT_PATH+sFavoriteUrl+'?method=delete&resource_type='+sType+'&resource_id='+iResourceId+getCacheKill();
				var oReq = new HttpReq(sUrl,'GET',function(){
					if(oReq!=null && oReq.IsReady()){
						if(oReq.GetText()==''){
							//TODO: pop from array
							if(sType=='AU' && typeof(arrUserContentFavorites)=='object'){
								try{
									hideEle($('contentFav::'+iResourceId+OWNER_STR));
									var iArrIdx=getObjIdxById(arrUserContentFavorites,iResourceId);
									arrUserContentFavorites=arrUserContentFavorites.remove(iArrIdx);
								}catch(e){ }
							}
							popMessage('<br/>The selected favorite has been removed<br/><br/>');
						}//else{//already added or error
					}
				});
			}
		}
		/** ********************** CONTENT FILTERS ********************** **/
		var sFILT_PREFIX='selFilt_';
		var arrFilters = ['category','artist','genre','album'];
		function initContentFilters(){
			var arrCategories = new Array();
			var arrGenres = new Array();
			var arrArtists = new Array();
			var arrAlbums = new Array();
			var oFilter = null;
			
			//get the values
			for(xx=0;xx<arrSelContent.length;xx++){
				if(!arrCategories.hasValue(arrSelContent[xx].category) && arrSelContent[xx].category!='' ){
					arrCategories.push(arrSelContent[xx].category);
				}
				if(!arrGenres.hasValue(arrSelContent[xx].genre) && arrSelContent[xx].genre!='' ){
					arrGenres.push(arrSelContent[xx].genre);
				}
				if(!arrArtists.hasValue(arrSelContent[xx].artist) && arrSelContent[xx].artist!='' ){
					arrArtists.push(arrSelContent[xx].artist);
				}
				if(!arrAlbums.hasValue(arrSelContent[xx].album) && arrSelContent[xx].album!='' ){
					arrAlbums.push(arrSelContent[xx].album);
				}
			}
			//display them in the select lists
			oFilter = $(sFILT_PREFIX+arrFilters[0]);
			for(var cc=0;cc<arrCategories.length;cc++){
				oFilter.options[cc+1] = new Option(unescape(oCatMap[arrCategories[cc]]), arrCategories[cc], false, false);
			}
			oFilter = $(sFILT_PREFIX+arrFilters[1]);
			for(var cc=0;cc<arrArtists.length;cc++){
				oFilter.options[cc+1] = new Option(unescape(arrArtists[cc]), arrArtists[cc], false, false);
			}
			oFilter = $(sFILT_PREFIX+arrFilters[2]);
			for(var cc=0;cc<arrGenres.length;cc++){
				oFilter.options[cc+1] = new Option(unescape(arrGenres[cc]), arrGenres[cc], false, false);
			}
			oFilter = $(sFILT_PREFIX+arrFilters[3]);
			for(var cc=0;cc<arrAlbums.length;cc++){
				oFilter.options[cc+1] = new Option(unescape(arrAlbums[cc]), arrAlbums[cc], false, false);
			}
		}		
		function filterContent(){
			var iDspCnt=0;
			var sBodyHTML='';
			
			for(var yy=0;yy<arrSelContent.length;yy++){
				var bDisplay=true;
				//loop through the filters
				for(ff=0;ff<arrFilters.length;ff++){					
					//get the value
					var tmpVal=$(sFILT_PREFIX+arrFilters[ff]).value;
					//compare against content attribute
					if(tmpVal!='all' && tmpVal!=arrSelContent[yy][arrFilters[ff]]){
						bDisplay=false;
						break;//no need to keep searching - dont display
					}
				}
				if(bDisplay){
					var bAlt=(yy%2==1);
					sBodyHTML+=getAudioRow(arrSelContent[yy],bAlt);
					iDspCnt++;
				}
			}
			displayContent(sBodyHTML,arrSelContent);
		}
		/** ********************** /CONTENT FILTERS ********************** **/
		
		function BabbleFeed(){
			var sServiceUrl = sMsgBoardService;
			var sID_BASE='dvMessageBaord_';
			
			this.GetBabbleFeed=function(id){
				var sUrl = sServiceUrl+'userId='+id
					var oReq = new HttpReq(sUrl,'GET',function(){
						if(oReq!=null && oReq.IsReady()){
							if(oReq.GetText()==''){
								alert(oReq.GetText());
							}
						}
					});
			}
			this.DeleteFeed=function(resourceId){
				var sUrl = sServiceUrl+'method=DELETE&resourceId='+resourceId
				var oReq = new HttpReq(sUrl,'GET',function(){
					if(oReq!=null && oReq.IsReady()){
						if(oReq.GetText()==''){
							hideEle($(sID_BASE+resourceId));
						}
					}
				});
			}
		}
		var oFeed = new BabbleFeed();
		
		function RecentActivity(){
			var sServiceUrl = sActivtyService;
			var sCLASS_NAME='recentPlay';
			this.Delete=function(resourceId,oLnk){
				var sUrl = sServiceUrl+'method=DELETE&resourceId='+resourceId;
				var oReq = new HttpReq(sUrl,'GET',function(){
					if(oReq!=null && oReq.IsReady()){
						var oDiv = oLnk.parentNode.parentNode;
						if(oReq.GetText()=='' && oDiv.className.indexOf(sCLASS_NAME)!=-1){
							hideEle(oDiv);
						}
					}
				});
			}
		}
		var oRecentCont = new RecentActivity();
		/** ********************** TREE FUNCTS ********************** **/
		function displayDefault(bOwner){
			var sUrl = sOLAPService+"?dataType=content&dimension=week"+getCacheKill();
			var oReq = new HttpReq(sUrl,'GET',function(){
					if(oReq!=null && oReq.IsReady()){
						var arrDefault = new Array();
						var arrResult = parseXML(oReq.GetXML(), 'content');
						//silly but we'll reformat
						for(var rr=0;rr<arrResult.length;rr++){
							if(arrResult[rr].resourceId){
								var sTitle = (arrResult[rr].title.value=="null")?"":arrResult[rr].title.value;
								var sArtist = (arrResult[rr].artist.value=="null")?"":arrResult[rr].artist.value;
							 arrDefault.push({resourceId:arrResult[rr].resourceId.value,
									encId:arrResult[rr].eid.value,
									title:sTitle,
									language:'',
									artist:sArtist,
									category:'',
									genre:arrResult[rr].genre.value,			
									album:arrResult[rr].album.value,		
									playcount:'',				
									imageURI:arrResult[rr].image.value,
									isOwner:false
								});
							}
						}
						arrSelContent=arrDefault;
						selContType=0;
						filterContent();
						
						$('dvCurSelection').innerHTML='Top Plays';
						
						var sMsg;
						if(bOwner){
							sMsg = (isArtist)?'You haven\'t uploaded anything':'You haven\'t saved any favorites';
							sMsg+='. Until then, here are the most popular songs currently ' +
							'on babulous. <div class="fontLtBlue fontBold" style="padding-top:5px;">';
							sMsg += (isArtist)?'<a href="'+sUploadUrl+'">Click here upload your music</a>'
							 :'<a href="'+sSearchUrl+'?dateCreated=90&action=user&sort=dateCreated&userType=10">Click here to start discovering new music</a>';
							sMsg += '.</div>';
						}else{
							sMsg="This user doesn\'t have any favorites. Until then, here are the top songs of the week.";
						}						
						
						var oCont = $('content_list');
						
						var sHTML ="<div class='floatLeft fontDark' style='padding:0px 6px;'> "+sMsg+"&nbsp; "+
							" <br/></div> <br class='floatClear'/>" +oCont.innerHTML;
						oCont.innerHTML = sHTML;
					}
				});
				hidePlayBtn();
		}
		function showTreeBlock(sDivId,sImgId){			
			var bDisplayed=showHideEle($(sDivId));
			var oImgArrow=$(sImgId);
			if(bDisplayed){
				oImgArrow.src=oImgArrow.src.replace('right','down');
			}else{
				oImgArrow.src=oImgArrow.src.replace('down','right');
			}			
		}
		var oPrevSelNode=null;
		function selectTreeNode(oDiv,bParent){
			if(oPrevSelNode!=null){
				oPrevSelNode.className=oPrevSelNode.className.replace('selectedNode','treeNode');
				if(oPrevSelNode.parentNode.className && oPrevSelNode.parentNode.className.indexOf('selected')>-1){
					oPrevSelNode.parentNode.className='';
				}
			}
			oPrevSelNode=oDiv;
			oDiv.className=oDiv.className.replace('treeNode','selectedNode');
			
			setSelectedHeader(oDiv);
			hideEle($('dvProfTree'));
			
			if(bParent){
				selectParent(oDiv);
			}
		}
		function selectParent(oDiv){
			oDiv.parentNode.className='selectedParent';
		}
		//display in header
		function setSelectedHeader(oDiv){
			var sHTML=oDiv.innerHTML;
			$('dvCurSelection').innerHTML=sHTML.replace(/<img(.)*>/gi,'');
		}
		function toggleArrowImg(oImg,bDown){
			var sArrowPath=(bDown)?'/arrow_down.gif':'/arrow_right.gif';
			oImg.src=sIMG_PATH+sArrowPath;
		}
		function selectLibrary(oDiv){
			selectTreeNode(oDiv,1);
			arrSelContent=arrUserContent;
			selContType=0;
			filterContent();
			showPlayContBtn();
			if(arrUserContent.length==0){
				var oCont=$('content_list');
				var sMsg;
				if(isArtist){
					sMsg = 'You haven\'t uploaded anything yet! '+
						'<span class="fontLtBlue"><a href="'+sUploadUrl+'">Upload</a></span> ' +
						'your audio now so the entire online community can hear you.';
				}else{
					sMsg = 'Your  haven\'t uploaded anything yet!';
				}
				oCont.innerHTML='<div class="profPadding fontDark">'+sMsg+'</div>';
			}	
		}
		function selectFavContent(oDiv){
			selectTreeNode(oDiv);
			arrSelContent=arrUserContentFavorites;
			selContType=1;
			filterContent();
			showPlayFavBtn();
			/*
			if(arrUserContentFavorites.length==0){
				var oCont=$('content_list');
				oCont.innerHTML='<div class="profPadding fontDark">You haven\'t saved any favorites. '+
					'To save an item in your favorites, '+
					'right click on the image and select ' +
					'the "Add to favorites" option in the menu<br/><br/> Or view the details and '+
					'click add to favorites on the details page.</div>';
			}
			*/ 
		}
		//function selectAll(oDiv){
		//	selectTreeNode(oDiv);
		//}
		var bSwapNext;
		function matchLeftHeight(id2,id1){
			var oDiv1 = $('mod'+id1);
			var oDiv2 = $('mod'+id2);
			if(oDiv1==null || oDiv2==null){
				return;
			}
			
			var h1=oDiv1.offsetHeight;
			var h2=oDiv2.offsetHeight;
			
			//if it's scrolling add a lil more to prevent the vert scroll
			//if(oList.offsetWidth < oList.firstChild.offsetWidth){
			//	max+=20;
			//}
			if(h1 < h2){ 
				bSwapNext=true;
				var max=Math.max(h1,h2);
				//oDiv1.style.height=max+'px';
			}
		}
		
		/** ********************** /TREE FUNCTS ********************** **/
		function selectTab(usrNum){
			if(getUserId()==usrNum){
				$('tabProfile').className='topTabInner selected';
			}
		}
		function togglePlaylistBar(){
			toggleDisplay($('dvProfTree'));	
		}
		
		function sizeProfileImg(oImg){
			var fDoResize=function(){
				oImg.style.visibility='visible';
				
				var iRawW = oRawImg.width;
				var iRawH = oRawImg.height;
				
				if(iRawW < iW){
					oImg.style.width=iRawW+'px';
					oImg.style.height=iRawH+'px';
				}
			}
			
			var iW = oImg.offsetWidth;
			var iH = oImg.offsetHeight;
			
			var oRawImg = new Image();
			oRawImg.src=oImg.src;
			if(/MSIE/i.test(navigator.userAgent)){
				fDoResize();
			}else{
				oRawImg.onload=fDoResize;
			}
		}
		
		function UserAlbum(iNum,bOwn){
			var iNumPics = iNum;
			var bOwner=bOwn;
			var oTheImage;
			var oThumbnails;
			var oAlbumCont;
			
			var IMG_ID_BASE='userImage_';
			
			var oBigImg;
			
			var DoUserResize=function(){
				var iAvail = oAlbumCont.offsetHeight-oThumbnails.offsetHeight-50;
				//alert('oAlbumCont.offsetHeight'+oAlbumCont.offsetHeight);
				//alert('oThumbnails.offsetHeight'+oThumbnails.offsetHeight);
				//alert('avail'+iAvail);
				
				if(!oBigImg.complete){//fix this later
					setTimeout(function(){DoUserResize();},600);
				}
				var iRawW = oBigImg.width;
				var iRawH = oBigImg.height;
				
				if(iRawW < iAvail && iRawH < iAvail){
					oTheImage.style.height=iRawH+'px';
					oTheImage.style.width=iRawW+'px';
				}else{
					//alert('calc down');
					var arrDims = getImgDimensions(oBigImg, iAvail);
					//alert(oBigImg.height);
					//alert(arrDims[0]);
					oTheImage.style.height=arrDims[0]+'px';
					oTheImage.style.width=arrDims[1]+'px';
					
				}
				if(parseInt(oTheImage.style.height)<iAvail){
					oTheImage.style.marginBottom=(iAvail-parseInt(oTheImage.style.height) )+'px';
				}else{
					oTheImage.style.marginBottom='0px';
				}
				
				oTheImage.src=oBigImg.src;
				showEle(oTheImage);
			}
			
			
			this.ViewAlbum=function(){
				if(iNumPics==0 && !bOwner){
					return false;
				}
				
				$('whiteOut').style.backgroundColor="#000";
				disablePage();
				oAlbumCont = $('dvPhotoAlbum');
				oTheImage = $('imgBigImage');
				oThumbnails = $('photoThumbnails');
				
				showEle(oAlbumCont);
				this.SetPictureSizes();
				centerOnScreen(oAlbumCont);
				if(iNumPics>0){
					this.DisplayLarge($(IMG_ID_BASE+1).src);
				}else if(bOwner){
					this.DisplayNoImages();
				}
			}
			this.DisplayNoImages=function(){
				var oDiv = $('photoThumbnails')
				oDiv.innerHTML='<br/><br/>You havent uploaded any pictures.<br/>'+
					'Select the pictures tab under the Edit profile section to being loading.'+
					'<br/><br/> or <a href="" style="color:#fff;"'+
					'onclick="oAlbum.HideAlbum();oProfEditCntrl.Display(\'Gen\');return false;">'+
					'click here to begin</a>.';
				hideEle($('imgBigImage'));
			}
			this.DisplayLarge=function(sUrl){
				
				oBigImg = new Image();
				oBigImg.src=sUrl;
				
				if(/MSIE/i.test(navigator.userAgent)){
					DoUserResize();
				}else{
					oBigImg.onload=DoUserResize();
				}
			}
			
			this.SetPictureSizes=function(){
				var iScreenHeight = getAvailScreenHeight();
				var iScreenWidth = viewport.width;
				
				//make viewable area the right size
				var iSize = Math.round(Math.min(iScreenHeight,iScreenWidth)*.9);
				oAlbumCont.style.height = oAlbumCont.style.width = iSize+'px';
				
				//var iImageSize = Math.floor(Math.sqrt((iSize*iSize)/iNumPics));	
				//for(var xx=1;xx<iNumPics;xx++){
				//	var oImg = $(IMG_ID_BASE+xx);
					//oImg.style.height = oImg.style.width = iImageSize + 'px';
				//}
			}
			this.HideAlbum=function(){
				$('whiteOut').style.backgroundColor="#FFF";
				enablePage();
				hideEle(oAlbumCont);
			}
			this.AddImage=function(sUrl,id){
				iNumPics++;
				var oNewDiv = document.createElement('DIV');
				var sHTML='<div class="floatLeft aCenter" id="userImageCont_'+id+'">'+
					'<div class="pRel" style="left:70px;">'+
						'<div class="popDiv noDisplay" style="width:100px;" id="photo_menu_'+id+'">'+
							'<div class="hand contextItem" onclick="oAlbumControl.SetDefault(\''+unescape(sUrl)+'\');">set default</div>'+
							'<div class="hand contextItem" onclick="oAlbumControl.Delete('+id+');">delete</div>'+
						'</div>'+
					'</div>'+
					'<div class="editUserImage">'+
						'<img src="'+unescape(sUrl)+'" alt="" id="userImage_edit_'+id+'" class="" onclick=""/>'+
					'</div>'+
					'<a href="" onclick="toggleDisplay($(\'photo_menu_'+id+'\'));return false;">options</a>'+
					'<br/>'+
				'</div>';
				
				oNewDiv.innerHTML=sHTML;
				$('dvEditImages').appendChild(oNewDiv);
				
				oProfEditCntrl.bDoRefresh=true;
			}
		}
		function UserAlbumsController(){
			var sDIV_BASE_ID="userImageCont_";
			this.Delete=function(id,oDD){
				var bConf = confirm('Are you sure you want to delete this image?');
				if(bConf){
					var sUrl = sUserImageControl+"?method=DELETE&resourceId="+id;
					var oReq = new HttpReq(sUrl,'GET',function(){
						if(oReq!=null && oReq.IsReady() ){
							var oDiv = $(sDIV_BASE_ID+id);
							if(oDiv!=null){
								hideEle(oDiv);
							}else if(oDD){
								hideEle(oDD);
							}
						}
					});
				}
			}
			this.SetDefault=function(url){
				var sUrl = sUserImageControl;
				var sParams = "method=POST&imageUrl="+escape(url);
				var oReq = new HttpReq(sUrl,'POST',function(){
					if(oReq!=null && oReq.IsReady() ){
						$('imgAvatar').src=url+sNORMAL_IMG;
						popMessage('<br/>This image has been set as your default.<br/><br/>');
					}
				},sParams);
			}
		}
		var oAlbumControl = new UserAlbumsController();
		
		var oPrevMsgPic=null;
		function previewMsgBoardPic(id,sUrl){
			if(oPrevMsgPic!=null){
				hideEle(oPrevMsgPic);
			}
			var oDiv = G$(id);
			oPrevMsgPic=oDiv;
			toggleDisplay(oDiv);
			if(oDiv.firstChild.src!=sUrl+sNORMAL_IMG){
				oDiv.firstChild.src=sUrl+sNORMAL_IMG;
			}
		}
		
		var oEvent = {
			/*
			//loadedExt : false,
			LoadExts : function(){
				if(!this.loadedExt){
					
					var SID="js_date";
					LoadScript('/common/js/ui.datepicker.min.js',SID);
					
					this.loadedExt=true;
					var oScript = jQuery('#'+SID).get(0);
					alert(jQueryUI_Datepicker_loaded);
					
					oScript.onreadystatechange = function(){
			        		alert(this.readyState );
			        	if (this.readyState == "complete"){
			        		alert('complete');
							jQuery(function($){
								alert('jQuery');
								$("#evtDate").datepicker();
							});
			            }
			        };
				}
			},
			*/
			arrEvents : new Array(),
			New : function(){
				//this.LoadExts();
				this.DisplayForm();
			},
			Hide : function(){
				var oDiv = G$('dvSharedPop');
				toggleDisplay(oDiv);
			},
			DisplayForm : function(){
				var oDiv = G$('dvSharedPop');
				var sHTML='<h3>New Event</h3>'+
					'<form onsubmit="return oEvent.Submit(this);" style="padding:5px;">'+
					'<input type="hidden" name="owner" value="'+getUserId()+'"/>'+
					
					'<table>'+
					'<tr>'+
					'<td>Description&nbsp;</td> '+
					'<td class="evtFrmPadd"><textarea name="textDescription" maxlength="1024"></textarea></td> '+
					'</tr>'+
					
					'<tr>'+
					'<td class="aRight">Address&nbsp;</td> '+
					'<td class="evtFrmPadd"><input type="text" name="address" size="25" maxlength="1024"/></td> '+
					'</tr>'+
					
					'<tr>'+
					'<td class="aRight">City&nbsp;</td> '+
					'<td class="evtFrmPadd"><input type="text" name="city" size="25" maxlength="256"/></td> '+
					'</tr>'+
					
					'<tr>'+
					'<td class="aRight">State&nbsp;</td> '+
					'<td class="evtFrmPadd">'+
					'<input type="text" name="state" size="2" maxlength="2"/> &nbsp; '+
					'Zip&nbsp;'+
					'<input type="text" name="zipcode" size="5" maxlength="15"/>'+
					'</td>'+
					'</tr>'+
					'<tr>'+
					'<td class="aRight">Date&nbsp;</td> '+
					'<td class="evtFrmPadd">'+
					'<input type="text" id="evtDate" name="month" size="1" maxlength="2"/> / '+
					'<input type="text" name="day" size="1" maxlength="2"/> / '+
					'<input type="text" name="year" size="3" maxlength="4"/>'+
					'</td> '+
					'</tr>'+
					
					
					'<tr>'+
					'<td></td> '+
					'<td style="padding-top:8px;">'+
						'<input type="submit" value="Submit" /> '+
						'<input type="button" value="Cancel" onclick="oEvent.Hide();"/> '+
					'</td> '+
					'</tr>'+
					'</table>'+
					'</form>';
				
				oDiv.innerHTML=sHTML;
				
				toggleDisplay(oDiv);
				centerOnScreen(oDiv);
			},
			ValidateForm : function(oFrm){
				if(oFrm.textDescription.value.length<1){alert('desc');
					return false;
				}
				if(!IsNumeric(oFrm.month.value) || oFrm.month.value.length<2){alert('month'+oFrm.month.value.length);
					return false;
				}
				if(!IsNumeric(oFrm.day.value) || oFrm.day.value.length<2){alert('day');
					return false;
				}
				if(!IsNumeric(oFrm.year.value) || oFrm.year.value.length!=4){alert('year'+oFrm.year.value.length);
					return false;
				}
				return true;
			},
			Submit : function(oFrm){
				if(this.ValidateForm(oFrm)){
					var sUrl = sEventsUrl+'?method=POST&'+getFormParams(oFrm);
					var oReq = new HttpReq('GET',sUrl,function(){
						if(oReq!=null && oReq.IsReady()){					
							if(oReq.GetText()==''){
								popMessage('Your event has been created');
								bab_track('profile/event/new',1);
								oEvent.CloseEvent();

							}else{
								popMessage(sGenericError);
							}
						}
					});
				}
				return false;
			},
			AddEvent:function(_id,_owner,_desc,_address,_city,_state,_zip,_createDate,_eventTime){
				this.arrEvents[_id]= new UserEvent(_id,_owner,_desc,_address,_city,_state,_zip,_createDate,_eventTime);
			},
			DisplayEvent:function(_id){
				var oEvt = this.arrEvents[_id];
				
				var oDiv = G$('dvSharedPop');
				var sHTML='<div style="width:420px;margin:10px 0px;" class="aCenter">'+
					'<h3 class="floatLeft" >'+oEvt.desc+'</h3>'+
					'<div class="floatRight hand" onclick="oEvent.CloseEvent();" style="width:20px;margin-bottom:6px;">[X]</div>'+
					'<br class="floatClear"/>'+
					'<div id="eventMap" style="width:400px;height:250px;border:1px solid #000;"></div>'+
					'</div>';
				
				oDiv.innerHTML=sHTML;
				toggleDisplay(oDiv);
				centerOnScreen(oDiv);
				
		        oMap = new GoogleMap("eventMap");
		        oMap.AddAddress(oEvt.GetAddress());
			},
			CloseEvent:function(){
				var oDiv = G$('dvSharedPop');
				oDiv.innerHTML="";
				toggleDisplay(oDiv);
			}
		}
		function UserEvent(_id,_owner,_desc,_address,_city,_state,_zip,_createDate,_eventTime){
			this.id=_id;
			this.blobDescription=null;
			this.owner=_owner;
			this.desc=_desc;
			this.address=_address;
			this.city=_city;
			this.state=_state;
			this.zip=_zip;
			this.createDate=_createDate;
			this.eventTime=_eventTime;
			this.GetAddress=function(){
				return this.address + "," + this.city + "," + this.state + this.zip;
			}
		}
		function GoogleMap(sDivID){
	    	this.map=null;
	    	this.geocoder=null;
	    	if (GBrowserIsCompatible()) {
				this.map = new GMap2(document.getElementById(sDivID));
				this.geocoder =  new GClientGeocoder();	
				var topRight = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,10));
				this.map.addControl(new GSmallMapControl(),topRight);
			}
			this.Center=function(lat,long,zoom){
				if(!zoom) zoom = 11;
				this.map.setCenter(new GLatLng(lat, long), zoom);
			}
			this.AddAddress=function(address,display){
				if(!display) display=address;
			  var mapScope=this;
			  this.geocoder.getLatLng(
			    address,
			    function(point) {
			      if (!point) {
			        alert(address + " not found");
			      } else {
			        mapScope.map.setCenter(point, 13);
		
			        var marker = new GMarker(point);
			        GEvent.addListener(marker, "click", function() {
			        	marker.openInfoWindowHtml(display);
			        });
			       	mapScope.map.addOverlay(marker);
			       	marker.openInfoWindowHtml(display);
			      }
			    }
			  );			
			}
	    }