/** ** ** ** ** ** ** ** ** ** ** ** **
 * Graphics object
 */

var Graphics = {
		
	showLogin : function(animate)
	{
		$('#username').val('Käyttäjätunnus');
		$('#password').val('Salasana');
		
		$('#username').bind('click',function() {
			if ($('#username').val() == 'Käyttäjätunnus') {
				$('#username').val('');
			}
		});
		$('#password').bind('click',function() {
			if ($(this).val() == 'Salasana') {
				$(this).val('');
			}
		});		
		
		if (animate)
		{
			$('#userTools').fadeOut('slow',function() {
				$('#login').fadeIn('slow');
			});
		}
		else
		{
			$('#userTools').hide();
			$('#login').show();
		}
		
		//index page create account link
		$('.moreinfo_links .createAccount').show();
		
		$('#login').removeClass('invisible');
		
	},
	
	showUserTools : function(animate)
	{
		$('#nickname').html(User.nickname);
		
		if (animate)
		{
			$('#userTools').fadeIn('slow',function() {
				$('#login').fadeOut('slow');
			});
		}
		else {
			$('#userTools').show();
			$('#login').hide();
		}

		//index page remove create account link
		$('.moreinfo_links .createAccount').hide();
	},
	
	showFeedbackForm : function()
	{
        var point = MMap.map.fromContainerPixelToLatLng(ContextMenuDialogue.clickedPixel);
        
        var dataObject = {
            lat    : point.lat(),
            lng    : point.lng()
        }
        
        var results = document.getElementById('modalContent');
        results.innerHTML = tmpl("feedbackTemplate", dataObject);
        $('#placeInfoNotifyErrorSubmit').attr({'href' : 'javascript:Dialogues.sendFeedback()'});
        $('#modalContent').show();
        $('#commentContent').hide();
        this.showModal();	
    },
	
	formatContextMenu : function()
	{
		//default settings
		$('#contextMenuService').hide();
		$('#contextMenuAuthority').hide();
		$('#contextMenuSetBaseLocation').hide();
		
		if (User.loggedIn === true)
		{
			if (User.usergroup == 2) //service provider
			{
				//$('#contextMenuService').show();
			}
			
			if (User.usergroup == 3) //authority
			{
				$('#contextMenuAuthority').show();
				$('#contextMenuService').show();				
			}
			
			//home harbour
			$('#contextMenuSetBaseLocation').show();
			
		}
	},
	
	showContextMenu : function()
	{
		$('#contextMenu').show();
	},
	
	hideContextMenu : function()
	{
		$('#contextMenu').hide();
	},
	
	formatNewTarget : function()
	{
		//console.log('Graphics.formatNewTarget()');
		var classes = PanelDialogue.markerNames.target;
		for (var i = 0; i < classes.length; i++)
		{
			var element = $('#newTargetType').createAppend('optgroup',{'label':classes[i].name});
			
			var typeLength = classes[i].types.length;
			
			for (var j = 0; j < typeLength; j++)
			{
				element.createAppend
				(
					'option',
					{
						'value':'cat' + classes[i].types[j].id_category + '_id' + classes[i].types[j].id
					},
					classes[i].types[j].name
				);
			} 
		}
	},
	
	formatNewService : function()
	{
		//console.log('Graphics.formatNewService()');
		if (PanelDialogue.markerNames.service[0].types[0].properties)
		{
			var props = PanelDialogue.markerNames.service[0].types[0].properties;
					
			var row = 0;
		
			while (row < props.length)
			{
				
				var propBlock = $('#newServiceProperties').createAppend
				(
					'ul',
					{},
					''
				); 
			
				var loopEnd = row + 8;
				for (var i = row ; i < loopEnd && i < props.length ; i++)
				{
					var propName = props[i].name;
					var propId = props[i].id;
					
					$(propBlock).createAppend
					(
						'li',
						{
							'className' : 'selectionName'
						},
						[
							'input',
							{
								'type'     : 'checkbox',
								'value'    : '',
								'name'     : 'property_' + propId,
								'className': 'propertySelection' 
							},
							'',
							
							'label',
							{
								'for' : 'property_' + propId
							},
							propName
						]
					);
					row++;
				}
			}
		}
	},
	
	formatNewAuthority : function()
	{
		
		//console.log('Graphics.formatNewAuthority()');
		var classes = PanelDialogue.markerNames.authority;
		for (var i = 0; i < classes.length; i++)
		{
			var element = $('#newAuthorityType').createAppend('optgroup',{'label':classes[i].name});
			
			var typeLength = classes[i].types.length;
			
			for (var j = 0; j < typeLength; j++)
			{
				element.createAppend
				(
					'option',
					{
						'value':'cat' + classes[i].types[j].id_category + '_id' + classes[i].types[j].id
					},
					classes[i].types[j].name
				);
			} 
		} 
	},
	
	formatNewImage : function()
	{
		
	},
	
	showNewMarker : function(type)
	{
		switch(type)
		{
			case "Target":
                var dataObject = {'action'          : '/marker/addtarget', 
                                  'onSubmit'        : 'return NewTargetDialogue.addNewTarget(this)',
                                  'submitLabel'     : 'Lis&auml;&auml;',
                                  'heading'         : 'Lis&auml;&auml; uusi kohde',
                                  'targetId'        : '',
                                  'name'            : '',
                                  'description'     : '',
                                  'www'             : '',
                                  'file'            : '',
                                  'seamap'          : '',
                                  'lat'             : NewTargetDialogue.lat.toFixed(4),
                                  'lng'             : NewTargetDialogue.lng.toFixed(4),
                                  'classes'         : PanelDialogue.markerNames.target,
                                  'selectedType'    : ''
                                 };
                              			
				var results = document.getElementById('modalContent');
                results.innerHTML = tmpl("targetTemplate", dataObject);
                $('#commentContent').hide();                
				this.showModal();
				break;
			case "Service":
                var dataObject = {'action'      : '/marker/addservice', 
                                  'onSubmit'    : 'return NewServiceDialogue.addNewService(this)',
                                  'submitLabel' : 'Lis&auml;&auml;',
                                  'heading'     : 'Lis&auml;&auml; uusi palvelu',
                                  'serviceId'   : '',
                                  'name'        : '',
                                  'description' : '',
                                  'seaMap'      : '',                                  
                                  'www'         : '',
                                  'file'        : '',
                                  'lat'         : NewServiceDialogue.lat.toFixed(4),
                                  'lng'         : NewServiceDialogue.lng.toFixed(4),
                                  'props'       : PanelDialogue.markerNames.service[0].types[0].properties,
                                  'checkedProps': new Array()
                                 };
                                        
                var results = document.getElementById('modalContent');
                results.innerHTML = tmpl("serviceTemplate", dataObject);
                $('#commentContent').hide();
                this.showModal();
                break;
			case "Authority":
                var dataObject = {'action'      : '/marker/addauthority', 
                                  'onSubmit'    : 'return NewAuthorityDialogue.addNewAuthority(this)',
                                  'submitLabel' : 'Lis&auml;&auml;',
                                  'heading'     : 'Lis&auml;&auml; uusi viranomaistieto',
                                  'authorityId' : '',
                                  'name'        : '',
                                  'description' : '',
                                  'icon'        : '',      
                                  'seaMap'      : '',                                  
                                  'www'         : '',
                                  'file'        : '',
                                  'lat'         : NewAuthorityDialogue.lat.toFixed(4),
                                  'lng'         : NewAuthorityDialogue.lng.toFixed(4),
                                  'classes'     : PanelDialogue.markerNames.authority,
                                  'selectedType': ''
                                 };
                                        
                var results = document.getElementById('modalContent');
                results.innerHTML = tmpl("authorityTemplate", dataObject);
                $('#commentContent').hide();                
                this.showModal();
                break;
			case "Image":
                var dataObject = {'action'      : '/marker/addimage', 
                                  'onSubmit'    : 'return NewImageDialogue.addNewImage(this)',
                                  'submitLabel' : 'Lis&auml;&auml;',
                                  'heading'     : 'Lis&auml;&auml; uusi kuva',
                                  'imageId'     : '',
                                  'name'        : '',
                                  'description' : '',
                                  'seamap'      : '',                                  
                                  'www'         : '',
                                  'file'        : '',
                                  'lat'         : NewImageDialogue.lat.toFixed(4),
                                  'lng'         : NewImageDialogue.lng.toFixed(4),
                                  'props'       : PanelDialogue.markerNames.image[0].types[0].properties,
                                  'checkedProps': new Array()                               
                                 };
                                        
                var results = document.getElementById('modalContent');
                results.innerHTML = tmpl("imageTemplate", dataObject);
                $('#commentContent').hide();
                this.showModal();
                break;
        }
		
	},
	
	hideNewMarker : function(type)
	{
		switch(type)
		{
			case "Target":
                this.hideModal();
				break;
			case "Service":
                this.hideModal();
				break;
			case "Authority":
                this.hideModal();
				break;
			case "Image":
                this.hideModal();
				break;
		}
	},

    hideUpdateMarker : function(type)
    {
        switch(type)
        {
            case "Target":
                this.hideModal();
                this.hidePlaceInfo();
                break;
            case "Service":
                this.hideModal();
                this.hidePlaceInfo();
                break;
            case "Authority":
                this.hideModal();
                this.hidePlaceInfo();
                break;
            case "Image":
                this.hideModal();
                this.hidePlaceInfo();
                break;
        }
    },
	
	
    showUpdateMarker : function(type)
    {
        switch(type)
        {
            case "Target":
                var dataObject = {'action'          : '/marker/updatetarget', 
                                  'onSubmit'        : 'return UpdateTargetDialogue.updateTarget(this)',
                                  'submitLabel'     : 'Tallenna',
                                  'targetId'        : TargetInfoDialogue.id,
                                  'heading'         : 'Muokkaa kohdetta',
                                  'name'            : TargetInfoDialogue.title,
                                  'description'     : TargetInfoDialogue.description,
                                  'www'             : TargetInfoDialogue.www,
                                  'file'            : '',
                                  'lat'             : TargetInfoDialogue.lat,
                                  'lng'             : TargetInfoDialogue.lng,
                                  'classes'         : PanelDialogue.markerNames.target,
                                  'selectedType'    : 'cat' + TargetInfoDialogue.id_category + '_id' + TargetInfoDialogue.id_type                         
                                 };
                                        
                var results = document.getElementById('modalContent');
                results.innerHTML = tmpl("targetTemplate", dataObject);
                $('#modalContent').show();
                $('#commentContent').hide();
                this.showModal();
                break;
            case "Service":
                
                checkedProps = new Array();
                
                for (i = 0; i<ServiceInfoDialogue.properties.length; i++) {
                	checkedProps[i]= ServiceInfoDialogue.properties[i].id;
                }
            
                var dataObject = {'action'          : '/marker/updateservice', 
                                  'onSubmit'        : 'return UpdateServiceDialogue.updateService(this)',
                                  'submitLabel'     : 'Tallenna',
                                  'heading'         : 'Muokkaa palvelua',
                                  'serviceId'       : ServiceInfoDialogue.id,                                 
                                  'name'            : ServiceInfoDialogue.title,
                                  'description'     : ServiceInfoDialogue.description,
                                  'www'             : ServiceInfoDialogue.www,
                                  'file'            : '',
                                  'seaMap'          : ServiceInfoDialogue.seaMap,
                                  'lat'             : ServiceInfoDialogue.lat,
                                  'lng'             : ServiceInfoDialogue.lng,
                                  'props'           : PanelDialogue.markerNames.service[0].types[0].properties,
                                  'checkedProps'    : checkedProps
                                 };
                                        
                var results = document.getElementById('modalContent');
                results.innerHTML = tmpl("serviceTemplate", dataObject);
                $('#modalContent').show();
                $('#commentContent').hide();                
                this.showModal();
                break;
            case "Authority":
                var dataObject = {'action'      : '/marker/updateauthority', 
                                  'onSubmit'    : 'return UpdateAuthorityDialogue.updateAuthority(this)',
                                  'submitLabel' : 'Tallenna',
                                  'heading'     : 'Muokkaa viranomaistietoa',
                                  'name'        : AuthorityInfoDialogue.title,
                                  'authorityId' : AuthorityInfoDialogue.id,
                                  'description' : AuthorityInfoDialogue.description,
                                  'icon'        : AuthorityInfoDialogue.icon,       
                                  'seaMap'      : AuthorityInfoDialogue.seaMap,                                  
                                  'www'         : AuthorityInfoDialogue.www,
                                  'file'        : '',
                                  'lat'         : AuthorityInfoDialogue.lat,
                                  'lng'         : AuthorityInfoDialogue.lng,
                                  'classes'     : PanelDialogue.markerNames.authority,
                                  'selectedType'    : 'cat' + AuthorityInfoDialogue.id_category + '_id' + AuthorityInfoDialogue.id_type                         
                                 };
                                        
                var results = document.getElementById('modalContent');
                results.innerHTML = tmpl("authorityTemplate", dataObject);
                $('#modalContent').show();
                $('#commentContent').hide();
                this.showModal();
                break;
            case "Image":
                checkedProps = new Array();
                
                for (i = 0; i<ImageInfoDialogue.properties.length; i++) {
                    checkedProps[i]= ImageInfoDialogue.properties[i].id;
                }
                        
                var dataObject = {'action'      : '/marker/updateimage', 
                                  'onSubmit'    : 'return UpdateImageDialogue.updateImage(this)',
                                  'submitLabel' : 'Tallenna',
                                  'heading'     : 'Muokkaa kuvaa',
                                  'imageId'     : ImageInfoDialogue.id,                                  
                                  'name'        : ImageInfoDialogue.title,
                                  'description' : ImageInfoDialogue.description,
                                  'seamap'      : ImageInfoDialogue.seamap,                                  
                                  'www'         : ImageInfoDialogue.www,
                                  'file'        : '',
                                  'lat'         : ImageInfoDialogue.lat,
                                  'lng'         : ImageInfoDialogue.lng,
                                  'props'       : PanelDialogue.markerNames.image[0].types[0].properties,
                                  'checkedProps': checkedProps
                                 };
                                        
                var results = document.getElementById('modalContent');
                results.innerHTML = tmpl("imageTemplate", dataObject);
                $('#modalContent').show();
                $('#commentContent').hide();
                this.showModal();
                break;
        }
        
    },
	
	showTargetInfo : function()
	{	
		
		//show small image content
		$('#placeInfoBigPictureContent').hide();
		$('#placeInfoSmallPictureContent').show();
		if (TargetInfoDialogue.imageUrl != null) {
			$('#placeInfoImage').show();
		} else {
			$('#placeInfoImage').hide();
		}
		
		//category and type
		$('#placeInfoCategory').html(TargetInfoDialogue.category);
		$('#placeInfoType').html(" / " + TargetInfoDialogue.type);
		$('#placeInfoCategory').show();
		$('#placeInfoType').show();
		
		//name and description
		$('#placeInfoName').empty().html(TargetInfoDialogue.title);
		$('#placeInfoDescription').empty().html(TargetInfoDialogue.description);
		
		//image
		if (TargetInfoDialogue.imageUrl != null && TargetInfoDialogue.imageUrl != '')
		{
			
            var timestamp = Number(new Date());			
			$('#placeInfoImage').attr('src','/client-data/' + TargetInfoDialogue.imageUrl + '?' + timestamp);
		}
		else 
		{
			$('#placeInfoImage').attr('src','/static/images/merenkulkulaitos/targetinfo/kuva.jpg');
		}
		
		//show web-link
		if (TargetInfoDialogue.www != '') {
			$('#placeInfoWWW').attr({'href' : TargetInfoDialogue.www, 'target' : '_blank'});
			$('#wwwLink').show();
		}
		else $('#wwwLink').hide();
		
		//show rating
		Graphics.updateRating('placeInfo',TargetInfoDialogue);
		
		//show comments count
		$('#placeInfoCommentsCount').html(TargetInfoDialogue.commentsCount + ' kpl');
		
		//show comments link
		$('#placeInfoCommentsLink').attr('href','javascript:Dialogues.readComments('+ Dialogues.openMarkerId + ',\'TargetInfoDialogue\',\'placeInfo\')');
		
		//show comments link
		$('#placeInfoCommentsContainer').show();
				
		//no properties yet hide it
		$('#placeInfoProperties').hide();
		
		//notify error
		$('#placeInfoNotifyErrorText').html('Ilmoita virheellisest&auml; tiedosta');
		$('#placeInfoNotifyErrorText').attr({'href' : 'javascript:Graphics.showNotifyError(\'TargetInfoDialogue\',\'placeInfo\')'});
		$('#placeInfoNotifyError').show();
		
        //send to friend
        $('#placeInfoSendLinkText').html('L&auml;het&auml; s&auml;hk&ouml;postilla kaverille');
        $('#placeInfoSendLinkText').attr({'href' : 'javascript:Graphics.showSendLinkToFriend(\'TargetInfoDialogue\',\'placeInfo\')'});
        $('#placeInfoSendLinkLink').show();		
        
            
		
		// show remove-link if target adder or moderator or 
		if (TargetInfoDialogue.id_adder === User.id || User.usergroup === 3 || User.is_moderator)
		{
			$('#removeMarker a').html('Poista');
			$('#removeMarker a').attr({'href' : 'javascript:Dialogues.removeMarker()'});
			$('#removeMarker').show();		

            $('#modifyMarker a').html('Muokkaa');
            $('#modifyMarker a').attr({'href' : "javascript:Graphics.showUpdateMarker('Target')"});
            $('#modifyMarker').show();      
		} else {
            $('#removeMarker').hide();      
            $('#modifyMarker').hide();      
        }		
		
		//show place info tools
		$('#placeInfoTools').show();
		
		//dont show seamap information
		$('#placeInfo').hide();
		
		//show general view
		Graphics.showGeneralView('placeInfo');
		
		//show dialogue
		$('#placeInfo').show();
	},
	
	showServiceInfo : function()
	{
		//show small image content
		$('#placeInfoBigPictureContent').hide();
		$('#placeInfoSmallPictureContent').show();
		if (ServiceInfoDialogue.imageUrl != null) {
			$('#placeInfoImage').show();
		} else {
			$('#placeInfoImage').hide();
		}
		
		//category and type
		$('#placeInfoCategory').html(ServiceInfoDialogue.category);
		$('#placeInfoType').html(" / " + ServiceInfoDialogue.type);
		$('#placeInfoCategory').show();
		$('#placeInfoType').hide();
		
		//name and description
		$('#placeInfoName').empty().html(ServiceInfoDialogue.title);
		$('#placeInfoDescription').empty().html(ServiceInfoDialogue.description);
		
		//image
		if (ServiceInfoDialogue.imageUrl != null && ServiceInfoDialogue.imageUrl != '')
		{
            var timestamp = Number(new Date());     			
			$('#placeInfoImage').attr('src','/client-data/' + ServiceInfoDialogue.imageUrl + '?' + timestamp);
		}
		else 
		{
			$('#placeInfoImage').attr('src','/static/images/merenkulkulaitos/targetinfo/kuva.jpg');
		}
		
		//show web-link
		if (ServiceInfoDialogue.www != '') {
			$('#placeInfoWWW').attr({'href' : ServiceInfoDialogue.www, 'target' : '_blank'});
			$('#wwwLink').show();
		}
		else $('#wwwLink').hide();
		
		//show rating
		Graphics.updateRating('placeInfo',ServiceInfoDialogue);
		
		//show comments count
		$('#placeInfoCommentsCount').html(ServiceInfoDialogue.commentsCount + ' kpl');
		
		//show comments link
		$('#placeInfoCommentsLink').attr('href','javascript:Dialogues.readComments('+ ServiceInfoDialogue.id + ',\'ServiceInfoDialogue\')');
		
		//show comments link
		$('#placeInfoCommentsContainer').show();
				
		//properties
		$('#placeInfoProperties').empty();
		
		//properties title
		$('#placeInfoProperties').createAppend
		(
			'span',
			{
				'className' : 'properties_title'
			},
			'Palvelut'
		);
		
		var propertiesContainer = $('#placeInfoProperties').createAppend
		(
			'ul',
			{
				'className' : 'properties'
			},
			''
		);
		
		if (ServiceInfoDialogue.properties.length > 0)
		{
			for (var i = 0 ; i < ServiceInfoDialogue.properties.length ; i++)
			{
				$(propertiesContainer).createAppend
				(
					'li',
					{},
					ServiceInfoDialogue.properties[i].name
				);
			}	
		}
		
		$('#placeInfoProperties').show();
		
		//notify error
		$('#placeInfoNotifyErrorText').html('Ilmoita virheellisest&auml; tiedosta');
		$('#placeInfoNotifyErrorText').attr({'href' : 'javascript:Graphics.showNotifyError(\'ServiceInfoDialogue\',\'placeInfo\')'});
		$('#placeInfoNotifyError').show();
		
        //send to friend
        $('#placeInfoSendLinkText').html('L&auml;het&auml; s&auml;hk&ouml;postilla kaverille');
        $('#placeInfoSendLinkText').attr({'href' : 'javascript:Graphics.showSendLinkToFriend(\'ServiceInfoDialogue\',\'placeInfo\')'});
        $('#placeInfoSendLinkLink').show();     		
		
        // show remove-link if admin
        if (User.usergroup == 3 || User.is_moderator)
        {
            $('#removeMarker a').html('Poista');
            $('#removeMarker a').attr({'href' : 'javascript:Dialogues.removeMarker()'});
            $('#removeMarker').show();      

            
            $('#modifyMarker a').html('Muokkaa');
            $('#modifyMarker a').attr({'href' : "javascript:Graphics.showUpdateMarker('Service')"});
            $('#modifyMarker').show();                  
        } else {
            $('#removeMarker').hide();      
            $('#modifyMarker').hide();      
        }        
		
		//show place info tools
		$('#placeInfoTools').show();
		
		//show seamap information if found
		if (ServiceInfoDialogue.seaMap != '' && ServiceInfoDialogue.seaMap != null) {
			$('#placeInfoSeamap').html('Merikartta: ' + ServiceInfoDialogue.seaMap);
			$('#placeInfoSeamap').show();
		} else {
			$('#placeInfoSeamap').hide();
		}
		
		//show general view
		Graphics.showGeneralView('placeInfo');
		
		//show dialogue
		$('#placeInfo').show();
	},
	
	showAuthorityInfo : function()
	{
		//show small image content
		$('#placeInfoBigPictureContent').hide();
		$('#placeInfoSmallPictureContent').show();
		if (AuthorityInfoDialogue.imageUrl != null) {
			$('#placeInfoImage').show();
		} else {
			$('#placeInfoImage').hide();
		}
		
		//category and type
		$('#placeInfoCategory').html(AuthorityInfoDialogue.category);
		$('#placeInfoType').html(" / " + AuthorityInfoDialogue.type);
		$('#placeInfoCategory').show();
		$('#placeInfoType').show();
				
		//name and description
		$('#placeInfoName').empty().html(AuthorityInfoDialogue.title);
		$('#placeInfoDescription').empty().html(AuthorityInfoDialogue.description);
				
		//image
		if (AuthorityInfoDialogue.imageUrl != null && AuthorityInfoDialogue.imageUrl != '')
		{
            var timestamp = Number(new Date());     			
			$('#placeInfoImage').attr('src','/client-data/' + AuthorityInfoDialogue.imageUrl + '?' + timestamp);
		}
		else 
		{
			$('#placeInfoImage').attr('src','/static/images/merenkulkulaitos/targetinfo/kuva.jpg');
		}
		
		//hide rating
		$('#placeInfoRating').hide();
		
		//show web-link
		if (AuthorityInfoDialogue.www != '') {
			$('#placeInfoWWW').attr({'href' : AuthorityInfoDialogue.www, 'target' : '_blank'});
			$('#wwwLink').show();
			//dont show place info tools
			$('#placeInfoTools').show();
		} else {
			$('#wwwLink').hide();
			$('#placeInfoTools').hide();
		}
		
		//hide comments link
		$('#placeInfoCommentsContainer').hide();
		 
		//no properties yet hide it
		$('#placeInfoProperties').hide();
		
		//show seamap information if found
		if (AuthorityInfoDialogue.seaMap != '' && AuthorityInfoDialogue.seaMap != null) {
			$('#placeInfoSeamap').html('Merikartta: ' + AuthorityInfoDialogue.seaMap);
			$('#placeInfoSeamap').show();
		} else {
			$('#placeInfoSeamap').hide();
		}
		
		//notify error
		$('#placeInfoNotifyErrorText').html('Ilmoita virheellisest&auml; tiedosta');
		$('#placeInfoNotifyErrorText').attr({'href' : 'javascript:Graphics.showNotifyError(\'AuthorityInfoDialogue\',\'placeInfo\')'});
		$('#placeInfoNotifyError').show();

        //send to friend
        $('#placeInfoSendLinkText').html('L&auml;het&auml; s&auml;hk&ouml;postilla kaverille');
        $('#placeInfoSendLinkText').attr({'href' : 'javascript:Graphics.showSendLinkToFriend(\'AuthorityInfoDialogue\',\'placeInfo\')'});
        $('#placeInfoSendLinkLink').show();     

        // show remove-link if admin 
        if (User.usergroup == 3)
        {
            $('#removeMarker a').html('Poista');
            $('#removeMarker a').attr({'href' : 'javascript:Dialogues.removeMarker()'});
            $('#removeMarker').show();      
            
            $('#modifyMarker a').html('Muokkaa');
            $('#modifyMarker a').attr({'href' : "javascript:Graphics.showUpdateMarker('Authority')"});
            $('#modifyMarker').show();                  
        } else {
            $('#removeMarker').hide();      
            $('#modifyMarker').hide();      
        }       
		
		//show general view
		Graphics.showGeneralView('placeInfo');
		
		$('#placeInfo').show();
	},
	
	showImageInfo : function()
	{	
		
		//show small image content
		$('#placeInfoBigPictureContent').show();
		$('#placeInfoSmallPictureContent').hide();
		if (ImageInfoDialogue.imageUrl != null) {
			$('#placeInfoBigImage').show();
		} else {
			$('#placeInfoBigImage').hide();
		}
		
		//category and type
		$('#placeInfoCategory').html(ImageInfoDialogue.category);
		$('#placeInfoType').html(" / " + ImageInfoDialogue.type);
		$('#placeInfoCategory').hide();
		$('#placeInfoType').hide();
				
		//name and description
		$('#placeInfoName').empty().html(ImageInfoDialogue.title);
		if (ImageInfoDialogue.description == '') {
			$('#placeInfoBigPictureDescription').empty().html('&nbsp;');
		} else {
			$('#placeInfoBigPictureDescription').empty().html(ImageInfoDialogue.description);
		}
		
		//image
		if (ImageInfoDialogue.imageUrl != null && ImageInfoDialogue.imageUrl != '')
		{
			var timestamp = Number(new Date());      
			$('#placeInfoBigImage').attr('src','/client-data/' + ImageInfoDialogue.imageUrl + '?' + timestamp);
		}
		else 
		{
			$('#placeInfoBigImage').attr('src','/static/images/merenkulkulaitos/targetinfo/kuva.jpg');
		}
		
		//hide www-link
		$('#wwwLink').hide();
		
		//show rating
		Graphics.updateRating('placeInfo',ImageInfoDialogue);
		
		//show comments count
		$('#placeInfoCommentsCount').html(ImageInfoDialogue.commentsCount + ' kpl');
		
		//show comments link
		$('#placeInfoCommentsLink').attr('href','javascript:Dialogues.readComments('+ ImageInfoDialogue.id + ',\'ImageInfoDialogue\',\'placeInfo\')');
		
		//show comments link
		$('#placeInfoCommentsContainer').show();		
		
		//no properties yet hide it
		$('#placeInfoProperties').hide();
		
		//notify error
		$('#placeInfoNotifyErrorText').html('Ilmoita ep&auml;asiallisesta kuvasta');
		$('#placeInfoNotifyErrorText').attr({'href' : 'javascript:Graphics.showNotifyError(\'ImageInfoDialogue\',\'placeInfo\')'});
		$('#placeInfoNotifyError').show();
		
        //send to friend
        $('#placeInfoSendLinkText').html('L&auml;het&auml; s&auml;hk&ouml;postilla kaverille');
        $('#placeInfoSendLinkText').attr({'href' : 'javascript:Graphics.showSendLinkToFriend(\'ImageInfoDialogue\',\'placeInfo\')'});
        $('#placeInfoSendLinkLink').show();     		
		
        // show remove-link if target adder or moderator or 
        if (ImageInfoDialogue.id_adder === User.id || User.usergroup == 3 || User.is_moderator)
        {
            $('#removeMarker a').html('Poista');
            $('#removeMarker a').attr({'href' : 'javascript:Dialogues.removeMarker()'});
            $('#removeMarker').show();      
            
            $('#modifyMarker a').html('Muokkaa');
            $('#modifyMarker a').attr({'href' : "javascript:Graphics.showUpdateMarker('Image')"});
            $('#modifyMarker').show();                  
        } else {
            $('#removeMarker').hide();      
            $('#modifyMarker').hide();      
        }           		
		
		//dont show place info tools
		$('#placeInfoTools').show();
		
		//dont show seamap information
		$('#placeInfoSeamap').hide();
				
		//show general view
		Graphics.showGeneralView('placeInfo');
		
		//show dialogue
		$('#placeInfo').show();
	},
	
	showGeneralView : function(dialogue)
	{
		$('#' + dialogue + 'Comments').hide();
		$('#' + dialogue + 'AddComment').hide();
		$('#' + dialogue + 'SingleComment').hide();
		$('#' + dialogue + 'NotifyError').hide();
		$('#' + dialogue + 'General').show();
		this.hideModal();
	},
	
	showNotifyError : function(diag,win)
	{	
		//empty fields
		$('#' + win + 'NotifyErrorName').val('');
		$('#' + win + 'NotifyErrorEmail').val('');
		$('#' + win + 'NotifyErrorMessage').val('');
		
		//link to go back to conversation
		$('#' + win + 'NotifyErrorBack').attr({'href':'javascript:Graphics.showGeneralView(\'' + win + '\')'});
	
		//fill the fields if possible
		if (User.loggedIn === true)
		{
			$('#' + win + 'NotifyErrorEmail').val(User.email);
		}
		
		$('#' + win + 'Comments').hide();
		$('#' + win + 'AddComment').hide();
		$('#' + win + 'SingleComment').hide();
		//$('#' + win + 'General').hide();
        $('#' + win + 'SendLink').hide();		
		$('#' + win + 'NotifyError').show();

        $('#modalContent').hide();
        $('#commentContent').show();        
        this.showModal();       
		
		$('#' + win + 'NotifyErrorSubmit').attr({'href' : 'javascript:Dialogues.notifyError(\''+ diag +'\', \'' + win +'\')'});
		
	},
	
    showSendLinkToFriend : function(diag,win)
    {   
        //empty fields
        $('#' + win + 'SendLinkName').val('');
        $('#' + win + 'SendLinkEmail').val('');
        $('#' + win + 'SendLinkReceiver').val('');
        $('#' + win + 'SendLinkMessage').val('');
        
        //link to go back to conversation
        $('#' + win + 'SendLinkBack').attr({'href':'javascript:Graphics.showGeneralView(\'' + win + '\')'});
    
        //fill the fields if possible
        if (User.loggedIn === true)
        {
            $('#' + win + 'NotifyErrorEmail').val(User.email);
        }

        $('#modalContent').hide();
        $('#commentContent').show();
        $('#' + win + 'Comments').hide();
        $('#' + win + 'AddComment').hide();
        $('#' + win + 'SingleComment').hide();
        $('#' + win + 'NotifyError').hide();
        //$('#' + win + 'General').hide();
        $('#' + win + 'SendLink').show();
        this.showModal();       
        
        $('#' + win + 'SendLinkSubmit').attr({'href' : 'javascript:Dialogues.sendLinkToFriend(\''+ diag +'\', \'' + win +'\')'});
        
    },	
	
	updateRating : function(id,dialogue)
	{
		var dName = '';
		switch(dialogue)
		{
			case TargetInfoDialogue:
				dName = "TargetInfoDialogue";
				break;
			case ServiceInfoDialogue:
				dName = "ServiceInfoDialogue";
				break;
			case ImageInfoDialogue:
				dName = "ImageInfoDialogue";
				break;
		}
		
		//show rating
		$('#'+id+'Rating').show();
		
		//show rating
		var activeStars = dialogue.rating;
		
		$('#'+id+'Stars').empty();
		
		//active stars
		for(var i = 0;i < 5;i++)
		{
			var starType = (i < activeStars)?'/static/images/merenkulkulaitos/targetinfo/star_active.gif':'/static/images/merenkulkulaitos/targetinfo/star_inactive.gif'
			
			$('#'+id+'Stars').createAppend
			(
				'img',
				{
					'className' : 'star', 
					'src'   	: starType,
					'alt'   	: '',
					'onclick'	: 'javascript:Dialogues.addRating(' + (i+1) + ','+ dName +')'
				}
			);
			
		}
				
		$('#'+id+'Rating').show();
		
		//rating count
		var ratingCount = dialogue.ratingCount;
		if (ratingCount == null) ratingCount = 0; 
		$('#'+id+'RatingCount').empty().html(ratingCount + ' kpl');
	},
	
	showComments : function(diag,win)
	{
		
		//$('#' + win + 'General').hide();
		$('#' + win + 'SingleComment').hide();
        $('#' + win + 'SendLink').hide();
		$('#' + win + 'AddComment').hide();
        $('#' + win + 'NotifyError').hide();
        $('#modalContent').hide();
        $('#commentContent').show();
		$('#' + win + 'CommentsMessages').empty();
	
		//get comments from right dialogue
		
		switch(diag)
		{
			case "TargetInfoDialogue":
				var comments = TargetInfoDialogue.comments;
				var dialogueId = TargetInfoDialogue.id;
				break;
			case "ServiceInfoDialogue":
				var comments = ServiceInfoDialogue.comments;
				var dialogueId = ServiceInfoDialogue.id;
				break;
			case "ImageInfoDialogue":
				var comments = ImageInfoDialogue.comments;
				var dialogueId = ImageInfoDialogue.id;
				break;
			case "AuthorityInfoDialogue":
				var comments = AuthorityInfoDialogue.comments;
				var dialogueId = AuthorityInfoDialogue.id;
				break;
		}
		
		//link to add new comment
		$('#placeInfoAddCommentLink').attr({'href':'javascript:Graphics.addComment(\''+ diag +'\',\''+ win +'\',' + dialogueId + ')'});
		
		//comments
		if (comments.length == 0) $('#' + win + 'CommentsMessages').html('<li>Ei kommentteja</li>');
		
		for (var i = 0; i < comments.length; i++)
		{
			if (comments[i].active === true)
			{
				$('#' + win + 'CommentsMessages').createAppend
				(
					'li',
					{
						'className' : 'commentRow clear'
					},
					
					[
					
						'a',
						{
							'href' : 'javascript:Graphics.showSingleCommentView(\''+ diag +'\',\''+ win +'\','+i+');'
						},
						
						[
							'span',
							{
								'className' : 'commentText'
							},
							comments[i].comment_title,
						],
						
						'span',
						{
							'className' : 'commentDate'
						},
						comments[i].modified,
					
					
						'span',
						{
							'className' : 'commentUser'
						},
						comments[i].nickname_user,
						
					]
				);	
			} else {
                $('#' + win + 'CommentsMessages').createAppend
                (
                    'li',
                    {
                        'className' : 'commentRow clear'
                    },
                    
                    [
                        'span',
                        {
                            'className' : 'commentText'
                        },
                        'Kommentti poistettu.',
                                                
                        'span',
                        {
                            'className' : 'commentDate'
                        },
                        comments[i].modified,
                    
                        'span',
                        {
                            'className' : 'commentUser'
                        },
                        comments[i].nickname_modifier,
                    ]
                );  
            }			
			
		}
        $('#placeInfoSingleComment').hide();
		$('#' + win + 'Comments').show();
	},
	
	showSingleCommentView : function(diag,win,commentId)
	{
		//get comments from right dialogue
		switch(diag)
		{
			case "TargetInfoDialogue":
				var comments = TargetInfoDialogue.comments;
				break;
			case "ServiceInfoDialogue":
				var comments = ServiceInfoDialogue.comments;
				break;
			case "ImageInfoDialogue":
				var comments = ImageInfoDialogue.comments;
				break;
			case "AuthorityInfoDialogue":
				var comments = AuthorityInfoDialogue.comments;
				break;
		}
		
		//link to go back to conversation
		$('#placeInfoBackToConversation').attr({'href':'javascript:Graphics.showComments(\'' + diag + '\',\'' + win + '\')'});
		
		//title of comment
		$('#placeInfoSingleCommentTitle').html(comments[commentId].comment_title);
		
		//comment body
		$('#placeInfoSingleCommentBody').html(comments[commentId].comment);
		
		
		$('#'+ win +'Comments').hide();
        $('#' + win + 'SendLink').hide();		
		//$('#'+ win +'General').hide();
		$('#'+ win +'NotifyError').hide();
		$('#'+ win +'SingleComment').show();
		
		//notify comment
		$('#'+ win + 'NotifyComment').attr({'onclick' : 'javascript:Dialogues.notifyComment(' + comments[commentId].id + ')'});

        var currentDiag = null;

        switch(this.currentDialogue)
        {
            case "TargetInfoDialogue":
                currentDiag = TargetInfoDialogue;
                break;
            case "ServiceInfoDialogue":
                currentDiag = ServiceInfoDialogue;
                break;
            case "ImageInfoDialogue":
                currentDiag = ImageInfoDialogue;
                break;
            case "AuthorityInfoDialogue":
                currentDiag = AuthorityInfoDialogue;
                break;
        }   

        //console.log(comments);

        //remove comment
        if (comments[commentId].id_user == User.id || User.usergroup === 3 || User.is_moderator)
        {
            $('#'+ win + 'RemoveComment').show();        	
            $('#'+ win + 'RemoveComment').attr({'onclick' : 'javascript:Dialogues.removeComment(' + comments[commentId].id + ')'});
        } else {
            $('#'+ win + 'RemoveComment').hide();           
        }
	},
	
	addComment : function(diag,win,id)
	{
		//check if user has logged in
		if (!User.loggedIn === true)
		{
			alert('Kommentin kirjoittaminen vaatii sisäänkirjautumisen.');
			return;
		}
		
		$('#'+ win +'Comments').hide();
		//$('#'+ win +'General').hide();
		$('#'+ win +'SingleComment').hide();
		$('#'+ win +'NotifyError').hide();
		$('#'+ win +'AddComment').show();
		
		//link to go back to conversation
		$('#placeInfoAcBackToConversation').attr({'href':'javascript:Graphics.showComments(\'' + diag + '\',\'' + win + '\')'});
		
		//empty fields
		$('#'+ win +'AddCommentTitle').val('');
		$('#'+ win +'AddCommentBody').val('');
		
		//add onclick event to submit button
		$('#'+ win +'AddCommentSubmit').attr({'href' : 'javascript:Dialogues.addComment(\'' + diag + '\',\'' + win + '\',\'' + id + '\')'});
	},
	
	showThankYouForRegistering : function()
	{
		$('#registerForm').hide();
		$('#registerThanks').show();
	},
	
	hidePlaceInfo : function()
	{
		$('#placeInfo').hide();
        $('#removeTarget').hide();
	},
	
	
	formatPanel : function()
	{
		//add target categories
		for (var i = 0 ; i < PanelDialogue.markerNames.target.length ; i++)
		{
			
			var catName = PanelDialogue.markerNames.target[i].name;
			var catId = PanelDialogue.markerNames.target[i].id;
			
			//container
			var categoryContainer = $('#sc_targets').createAppend
			(
				'ul',
				{
					'className' : 'targetsCategory'
				},
				''
			);
			
			//heading
			var heading = $(categoryContainer).createAppend
			(
				'li',
				{},
				[
					'span',
					{},
					catName
				]
			);
			
			//category container
			var catContainer = $(heading).createAppend
			(
				'ul',
				{},
				''
			);
			
			//categories
			for (var j = 0 ; j < PanelDialogue.markerNames.target[i].types.length ; j++)
			{
				var typeId = PanelDialogue.markerNames.target[i].types[j].id;
				var typeName = PanelDialogue.markerNames.target[i].types[j].name;
				
				
				$(catContainer).createAppend
				(
					'li',
					{},
					[
						'input',
						{
							'type'     : 'checkbox',
							'value'    : '',
							'name'     : 'selecttarget_' + catId + '_' + typeId,
							'id'       : 'selecttarget_' + catId + '_' + typeId,
							'checked'  : 'checked',
							'onclick'  : 'javascript:PanelDialogue.showSelections()',
							'className': 'targetSelection' 
						},
						'',
						
						'label',
						{
							'htmlFor' : 'selecttarget_' + catId + '_' + typeId
						},
						typeName
					]
				);
			}
		}
		
		//add service properties
		var props = PanelDialogue.markerNames.service[0].types[0].properties; 
		
		var row = 0;
		
		while (row < props.length)
		{
			
			var propBlock = $('#sc_services_properties').createAppend
			(
				'ul',
				{},
				''
			); 
		
			var loopEnd = row + 5;
			for (var i = row ; i < loopEnd && i < props.length ; i++)
			{
				var propName = props[i].name;
				var propId = props[i].id;
				
				$(propBlock).createAppend
				(
					'li',
					{
						'className' : 'selectionName'
					},
					[
						'input',
						{
							'type'     : 'checkbox',
							'value'    : '',
							'name'     : 'selectserviceproperty_' + propId,
							'id'       : 'selectserviceproperty_' + propId,
							'onclick'  : 'javascript:PanelDialogue.showSelections()',
							'className': 'serviceSelection' 
						},
						'',
						
						'label',
						{
							'htmlFor' : 'selectserviceproperty_' + propId
						},
						propName
					]
				);
				row++;
			}
		}
		
		//add authorities types
		var types = PanelDialogue.markerNames.authority[0].types; 
		var row = 0;
		
		while (row < types.length)
		{
			
			var typeBlock = $('#sc_authorities_types').createAppend
			(
				'ul',
				{},
				''
			); 
		
			var loopEnd = row + 5;
			for (var i = row ; i < loopEnd && i < types.length ; i++)
			{
				var typeName = types[i].name;
				var typeId = types[i].id;
				
				$(typeBlock).createAppend
				(
					'li',
					{
						'className' : 'selectionName'
					},
					[
						'input',
						{
							'type'     : 'checkbox',
							'value'    : '',
							'name'     : 'selectauthoritytype_' + typeId,
							'id'       : 'selectauthoritytype_' + typeId,
							'checked'  : 'checked',
							'onclick'  : 'javascript:PanelDialogue.showSelections()',
							'className': 'authoritySelection' 
						},
						'',
						
						'label',
						{
							'htmlFor' : 'selectauthoritytype_' + typeId
						},
						typeName
					]
				);
				row++;
			}
		}
		
        //add image properties
        var props = PanelDialogue.markerNames.image[0].types[0].properties; 
        
        var row = 0;
        
        while (row < props.length)
        {
            
            var propBlock = $('#sc_images_properties').createAppend
            (
                'ul',
                {},
                ''
            ); 
        
            var loopEnd = row + 5;
            for (var i = row ; i < loopEnd && i < props.length ; i++)
            {
                var propName = props[i].name;
                var propId = props[i].id;
                
                $(propBlock).createAppend
                (
                    'li',
                    {
                        'className' : 'selectionName'
                    },
                    [
                        'input',
                        {
                            'type'     : 'checkbox',
                            'value'    : '',
                            'name'     : 'selectimageproperty_' + propId,
                            'id'       : 'selectimageproperty_' + propId,
                            'checked'  : 'checked',                            
                            'onclick'  : 'javascript:PanelDialogue.showSelections()',
                            'className': 'imageSelection' 
                        },
                        '',
                        
                        'label',
                        {
                            'htmlFor' : 'selectimageproperty_' + propId
                        },
                        propName
                    ]
                );
                row++;
            }
        }		
		
		
		//load markers
		MMap.updateMarkers();
		
	},

    formatSidebar : function()
    {
        var results = document.getElementById('myTargetsSlider');
        if (User.loggedIn===true && results != null)
        {
            
            var dataObject;
            
            if (SidebarDialogue.sidebarData !== false)
            {
            	dataObject = SidebarDialogue.sidebarData;
            } else {
            	dataObject = new Array();
            	dataObject['targets'] = new Array();
                dataObject['images'] = new Array();
                dataObject['comments'] = new Array();                
            }
            
            results.innerHTML = tmpl("sidebarTemplate", dataObject);
            $('#myTargetsSlider').height('100%');
            $('#myTargetsSlider').show(); 


			$("#myTargetsHandle").bind("click", function(){ 
			  Graphics.toggleSidebar(); 
			});

            $("a.kotisatama").bind("click", function(){ 
              User.goToBaseLocation(); 
            });
            
            $("#myTargetsHandle").bind("mouseover", function(){ 
                $('.myTargetsText').css('height','150px');
            });            	

            $("#myTargetsHandle").bind("mouseout", function(){ 
                $('.myTargetsText').css('height','26px');
            });     
            
                    
            
        } else {
        	$('#myTargetsSlider').hide();
        }    	
                        
    },
	
    refreshSidebar : function()
    {
        var results = document.getElementById('myTargetsSlider');
        if (User.loggedIn===true && results != null)
        {
            
            var dataObject;
            
            if (SidebarDialogue.sidebarData !== false)
            {
                dataObject = SidebarDialogue.sidebarData;
            } else {
                dataObject = new Array();
                dataObject['targets'] = new Array();
                dataObject['images'] = new Array();
                dataObject['comments'] = new Array();                
            }
            
            results.innerHTML = tmpl("sidebarTemplate", dataObject);


            $("#myTargetsHandle").bind("click", function(){ 
              Graphics.toggleSidebar(); 
            });

            $("a.kotisatama").bind("click", function(){ 
              User.goToBaseLocation(); 
            });
            
            $("#myTargetsHandle").bind("mouseover", function(){ 
                $('.myTargetsText').css('height','150px');
            });             

            $("#myTargetsHandle").bind("mouseout", function(){ 
                $('.myTargetsText').css('height','26px');
            });     
            
                    
            
        } else {
            $('#myTargetsSlider').hide();
        }       
                        
    },	
	
	showSlider : function()
	{
		$('#slider').show();
		$('#slider').animate({top:'95px'},500);
	},
	
	hideSlider : function()
	{
		$('#slider').animate({top:'-300px'},500);
		$('#tabNavi').attr('class','off');
		MMap.enableControls();
	},
	
	toggleSidebar : function()
	{
		if (SidebarDialogue.isOpen)
		{
            $('#myTargetsSlider').animate({left:'-255px'}, { queue:true, duration:500 });
            $('#panelWrapper').animate({marginLeft: '40px'}, { queue:true, duration:500 });
            $('#myTargetsSlider').animate({height: '100%'}, { queue:true, duration:50 });
            $('#lmc3d').animate({left:'-=255px'}, { queue:true, duration:500 });

            MMap.enableControls();
            $('.myTargetsText').css({'background-image' : 'url(/static/images/merenkulkulaitos/panel/mytargets_handle_text_closed.gif)'});
			SidebarDialogue.isOpen = false;
		} else {
            $('#myTargetsSlider').height('100%');
            $('#myTargetsSlider').animate({left:'0px'}, { queue:false, duration:500 });
            $('#lmc3d').animate({left:'+=255px'}, { queue:true, duration:500 });            
            $('#panelWrapper').animate({marginLeft: '295px'}, { queue:false, duration:500 });
            $('.myTargetsText').css({'background-image' : 'url(/static/images/merenkulkulaitos/panel/mytargets_handle_text_open.gif)'});
            SidebarDialogue.isOpen = true;
		}
	}, 
	
	showSearchLocations : function()
	{
		
		$('#searchResults').empty();
		
		for (var i = 0 ; i < PanelDialogue.searchLocations.length ; i++ )
		{
			$('#searchResults').createAppend
			(
				'div',
				{
					'className' : 'searchResultRow'
				},
				[
					'a',
					{
						'href' : 'javascript:PanelDialogue.selectLocation('+ i +');'
					},
					PanelDialogue.searchLocations[i].address,
				]
			);
		}
		
		//close link
		$('#searchResults').createAppend
		(
			'div',
			{
				'id' : 'searchResultsClose'
			},
			[
				'a',
				{
					'href' : 'javascript:Graphics.hideSearchLocations()'
				},
				'Sulje'
			]
		);
		
		$('#searchResults').show();	
	},
	
	hideSearchLocations : function()
	{
		$('#searchResults').hide();
	},
	
	showResultsCount : function()
	{
		$('#resultsCount').empty().createAppend
		(
			'span',
			{},
			'Haun tulos kartalla: ' + PanelDialogue.resultsCount + ' kpl'
		);	
	},
	
	formatMyUserInfo : function()
	{
		switch(User.usergroup)
		{
			case 1:
				$('#muiFirstnameLastname').html(User.groupSpecificData.firstname + ' ' + User.groupSpecificData.lastname);
				break;
			case 2:
				$('#muiFirstnameLastname').html(User.groupSpecificData.service_name + ', ' + User.groupSpecificData.company_name + ' (' + User.groupSpecificData.contact_person_first_name + ' ' + User.groupSpecificData.contact_person_last_name +')');
				break;
			case 3:
				$('#muiFirstnameLastname').html(User.groupSpecificData.institute + ' (' + User.groupSpecificData.contact_person_first_name + ' ' + User.groupSpecificData.contact_person_last_name +')');
				break;
		}
		
		$('#muiNickname').html(User.nickname);
		$('#muiEmail').html(User.email);
		
		//empty some fields
		$('#muiNewEmail').val('');
		$('#muiNewEmailAgain').val('');
		
		//email edit
		$('#muiNewEmail').val('');
		$('#muiNewEmailAgain').val('');
		$('#muiNewEmailConfirm').val('');
		
		//password edit
		$('#muiNewPassword').val('');
		$('#muiNewPasswordAgain').val('');
		$('#muiNewPasswordConfirm').val('');
		
		//close edit views
		$('#myUserInfo_edit_email').css({'display':'none'});
		$('#myUserInfo_field_email').css({'display':'block'});
		$('#myUserInfo_edit_password').css({'display':'none'});
		$('#myUserInfo_field_password').css({'display':'block'});
		
		//toggle close links
		$('#toggle_email').html('Muokkaa');
		$('#toggle_password').html('Muokkaa');
		
	},
	
	showForgetAccount : function()
	{
		$('#forgetAccount').show();		
	},
	
	hideForgetAccount : function()
	{
		$('#forgetAccount').hide();
	},
	
	showFinnishIcons : function()
	{
		$('#iconInfoIcons_se').hide();
		$('#iconInfoIcons_fi').show();
		$('#iconInfoTab_se').removeClass('selected');
		$('#iconInfoTab_fi').addClass('selected');
	},
	
	showSwedishIcons : function()
	{
		$('#iconInfoIcons_fi').hide();
		$('#iconInfoIcons_se').show();
		$('#iconInfoTab_fi').removeClass('selected');
		$('#iconInfoTab_se').addClass('selected');
	},
	
	showServiceProviderRegisterThanks : function()
	{
		$('#registerForm').hide();
		$('#registerThanks').show();
	},
    /**
     * show modal layer
     */
    showModal : function() {
        $('#mlModal').jqmShow();
    },
    /**
     * hide modal layer
     */
    hideModal : function() {
        $('#mlModal').jqmHide();
    },
    
    animateSidebarHandle : function() {
        $('.myTargetsText').css('height','150px');    	
        $('.myTargetsText').animate( { height : '150px' } , 2000);        
    	$('.myTargetsText').animate( { height : '26px' } , 1000);
    }    
}