Profile = {

	modulePath: "/profil/index.php5",
	statusTextPanel: "",
	colorPanel: "",
	contentPanel: "",
	filePanel: "",
	linkPanel: "",
	
	chooseColor: function(previousThemeId) {
		
		if (this.contentPanel) {
			this.contentPanel.hide();
			this.contentPanel = false;
		}
		
		if (this.colorPanel) {
			this.colorPanel.hide();
			this.colorPanel = false;
		}
		else {
				
			//statusText = document.getElementById(statusTextElementId).innerHTML;
			
			this.colorPanel = new YAHOO.widget.Panel("colorPanel", 
				{ 
				    close:false,  
					visible:false,  
					draggable:false,
					width: "110px",
					constraintoviewport:true, 
					iframe: true,
					zIndex: 99999,
					context: ["choose_theme_color", "tl", "bl"]
				} 
			); 
			//this.colorPanel.setHeader('Endre status (100 tegn)');
			this.colorPanel.setBody('<ul style="padding-left:10px;">' +
										'<li><a href="/profil/?op=SetProfileTheme&themeName=lightblue&themeId=100&previousThemeId=' + previousThemeId + '"><img src="http://gfx.dagbladet.no/blink/themes/profile/lightblue/colors.gif" style="border:1px solid #aaaaaa;background-color:#ffffff;padding:1px;vertical-align:center;margin-bottom:1px;" /></a></li>' +
										'<li><a href="/profil/?op=SetProfileTheme&themeName=lightgreen&themeId=140&previousThemeId=' + previousThemeId + '"><img src="http://gfx.dagbladet.no/blink/themes/profile/lightgreen/colors.gif"  style="border:1px solid #aaaaaa;background-color:#ffffff;padding:1px;vertical-align:center;margin-bottom:1px;"/></a></li>' +
										'<li><a href="/profil/?op=SetProfileTheme&themeName=lightred&themeId=140&previousThemeId=' + previousThemeId + '"><img src="http://gfx.dagbladet.no/blink/themes/profile/lightred/colors.gif"  style="border:1px solid #aaaaaa;background-color:#ffffff;padding:1px;vertical-align:center;margin-bottom:1px;"/></a></li>' +
										'<li><a href="/profil/?op=SetProfileTheme&themeName=pinkandbeige&themeId=115&previousThemeId=' + previousThemeId + '"><img src="http://gfx.dagbladet.no/blink/themes/profile/pinkandbeige/colors.gif"  style="border:1px solid #aaaaaa;background-color:#ffffff;padding:1px;vertical-align:center;margin-bottom:1px;"/></a></li>' +
										'<li><a href="/profil/?op=SelectProfileTheme">Flere...</a></li></ul>');
			this.colorPanel.render("bd");
			this.colorPanel.show();
		}
				
		return false;
		
	},
	
	chooseContent: function() {
		
		if (this.colorPanel) {
			this.colorPanel.hide();
			this.colorPanel = false;
		}
		
		if (this.contentPanel) {
			this.contentPanel.hide();
			this.contentPanel = false;
		}
		else {
				
			//statusText = document.getElementById(statusTextElementId).innerHTML;
			
			this.contentPanel = new YAHOO.widget.Panel("contentPanel", 
				{ 
				    close:false,  
					visible:false,  
					draggable:false,
					width: "150px",
					constraintoviewport:true, 
					iframe: true,
					zIndex: 99999,
					context: ["choose_profile_content", "tl", "bl"]
				} 
			); 
			//this.colorPanel.setHeader('Endre status (100 tegn)');
			this.contentPanel.setBody('<ul style="padding-left:10px;padding-right:10px;">' +
										'<li style="margin-bottom:2px;"><img src="http://gfx.dagbladet.no/blink/elements/icons/page_white_text.png" style="vertical-align:bottom;" /> <a href="/profil/?op=PopulateProfileContent&fromOverview=1&bundleId=1&name=html">Tekstboks</a></li>' +
										'<li style="margin-bottom:2px;"><img src="http://gfx.dagbladet.no/blink/elements/icons/feed.png" style="vertical-align:bottom;" /> <a href="/profil/?op=PopulateProfileContent&fromOverview=1&bundleId=1&name=rss">RSS-feed</a></li>' +
										'<li style="margin-bottom:2px;"><img src="http://gfx.dagbladet.no/blink/elements/icons/youtube.gif" style="vertical-align:bottom;" /> <a href="/profil/?op=PopulateProfileContent&fromOverview=1&bundleId=4&name=youtubePlayer">YouTube-film</a></li>' +
										'<li style="margin-bottom:6px;"><img src="http://gfx.dagbladet.no/blink/elements/icons/film.png" style="vertical-align:bottom;" /> <a href="/profil/?op=PopulateProfileContent&fromOverview=1&bundleId=4&name=videoPlayer">Blink-video</a></li>' +
										'<li><a href="/profil/?op=SelectProfileContentBundle">Flere...</a></li></ul>');
			this.contentPanel.render("bd");
			this.contentPanel.show();
		}
				
		return false;
		
	},
	
	editStatusText: function(userId, statusTextElementId) {
		
		element = document.getElementById(statusTextElementId);
		if (element != undefined) {
			statusText = element.innerHTML;
		}
		else {
			element = YAHOO.util.Dom.get(statusTextElementId);
			if (element != undefined) {
				statusText = element.innerHTML;
			}
			else {
				statusText = '';
			}
		}
		
		
		
		this.statusTextPanel = new YAHOO.widget.Panel("statusTextPanel", 
			{ 
			    close:true,  
				visible:false,  
				draggable:false,
				width: "320px",
				context: ["status_text", "tl", "bl"]
			} 
		); 
		this.statusTextPanel.setHeader('Endre status (100 tegn)');
		this.statusTextPanel.setBody('<form action="' + this.modulePath + '" method="get" >' + 
										'<textarea name="statusText" id="statusTextInput" onkeyup="Profile.validateStatusText(this);" style="width:290px;height:60px;margin-bottom:5px;">' + statusText + '</textarea>' +  
										'<input type="hidden" name="op" value="UpdateProfileStatusText" />' + '<br/>' +
										'<input type="hidden" name="referer" value="' + document.location.href + '" />' + '<br/>' +
										'Antall tegn: ' + '<input disabled size="3" value="' + statusText.length + '" name="char_count" id="char_count"> ' +
										' tegn igjen: ' + '<input disabled size="3" value="' + (100 - statusText.length) + '" name="left_count" id="left_count">' +
										'<div style="margin-top:5px;">' +
										'<input type="submit" value="Oppdater" /> eller <input type="button" onclick="Profile.statusTextPanel.hide();" value="Avbryt" />' + 
										'</div>' +
									'</form>');
		this.statusTextPanel.render("bd");
		this.statusTextPanel.show();
			
		return false;
		
	},
	
	addFile: function(userId, anchorElement) {
		

		this.filePanel = new YAHOO.widget.Panel("filePanel", 
			{ 
			    close:true,  
				visible:false,  
				draggable:false,
				width: "320px",
				fixedcenter: true,
				constraintoviewport: true,
				modal: true
			} 
		); 
		this.filePanel.setHeader('Last opp fil');
		this.filePanel.setBody('<form action="/user/sb_file_from_profile.php" method="post" enctype="multipart/form-data" >' + 
										'<label for="file" >Finn frem filen på maskinen din :</label>' +  
										'<input type="file" name="file" />' +  
										'<label for="file" >Beskrivelse:</label>' +  
										'<textarea name="description" id="statusTextInput" style="width:290px;height:60px;margin-bottom:5px;"></textarea>' +  
										'<input type="hidden" name="op" value="UpdateProfileStatusText" />' + '<br/>' +
										'<input type="hidden" name="referer" value="' + document.location.href + '" />' + '<br/>' +
										'Vi gjør oppmerksom på at filer med innhold som strider mot blinkreglene vil bli slettet uten varsel.' +
										'<div style="margin-top:5px;">' +
										'<input type="submit" value="Last opp" /> eller <input type="button" onclick="Profile.filePanel.hide();" value="Avbryt" />' + 
										'</div>' +
									'</form>');
		this.filePanel.render("bd");
		this.filePanel.show();
			
		return false;
		
	},
	
	addLink: function(userId, anchorElement) {
		

		this.linkPanel = new YAHOO.widget.Panel("linkPanel", 
			{ 
			    close:true,  
				visible:false,  
				draggable:false,
				width: "320px",
				fixedcenter: true,
				constraintoviewport: true,
				modal: true
			} 
		); 
		this.linkPanel.setHeader('Legg til lenke');
		this.linkPanel.setBody('<form action="/user/sb_link_from_profile.php" method="post" enctype="multipart/form-data" >' + 
										'<label for="url" >Adresse (URL):</label>' +  
										'<input type="text" name="url" value="http://" style="width:290px;margin-bottom:5px;" />' +   
										'<label for="name" >Tittel:</label>' +  
										'<input type="text" name="name" value="" style="width:290px;margin-bottom:5px;" />' +  
										'<label for="file" >Beskrivelse:</label>' +  
										'<textarea name="description" id="statusTextInput" style="width:290px;height:60px;margin-bottom:5px;"></textarea>' +  
										'<input type="hidden" name="op" value="UpdateProfileStatusText" />' + '<br/>' +
										'<input type="hidden" name="referer" value="' + document.location.href + '" />' + '<br/>' +
										'Vi gjør oppmerksom på at filer med innhold som strider mot blinkreglene vil bli slettet uten varsel.' +
										'<div style="margin-top:5px;">' +
										'<input type="submit" value="Last opp" /> eller <input type="button" onclick="Profile.linkPanel.hide();" value="Avbryt" />' + 
										'</div>' +
									'</form>');
		this.linkPanel.render("bd");
		this.linkPanel.show();
			
		return false;
		
	},
	
	validateStatusText: function(element) {

		var statusText = element.value;

		var charCount = document.getElementById("char_count");
		var leftCount = document.getElementById("left_count");
		
		leftCount.value = 100 - statusText.length;
		charCount.value = statusText.length;
		
	    if ((100 -  statusText.length) < 0) {
	        alert('Statusteksten kan ikke være lengre enn 100 tegn');
	        element.value = statusText.substr(0, 100);
	        Profile.validateStatusText(element);
	    }
		
	}
	
}
