var profile;

Event.observe(window, 'load', function() 
	{
		if ($('userProfile') || $('userRegistration'))
		{
			profile = new Profile();
		}
		
	}
);

var Profile = Class.create (
{
	initialize:function()
	{
		if($('customerTypePrivatePersonLabel'))
		{
			if($('customerTypePrivatePersonLabel').hasClassName('selected'))
			{
				this.changeCustomerType('private-person');
			}
			else
			{
				this.changeCustomerType('company');
			}
		}
	},
	
	useUploadedImage:function(uploadData)
	{
		var currentTime = new Date();
		$('profileThumbImage').src = uploadData.thumbImageFile + "?nc=" + currentTime.getTime();
		$('profileNewImageDetail').value = uploadData.thumbImageFile;
		$('profileNewImage').value = uploadData.imageFile;
		
		$('profileImageGallery').select('.image').each(function(element) {element.removeClassName('selected')});
		$('profileImageUpload').select('.image').first().addClassName('selected');
	},
	
	setIcon:function(icon)
	{
		$('profileImageGallery').select('.image').each(function(element) {element.removeClassName('selected')});
		$('profileImageUpload').select('.image').first().removeClassName('selected');
		$('image-' + icon).addClassName('selected');
		$('profileNewImage').value = icon;
	},
	
	changeCustomerType: function(type)
	{
		switch(type)
		{
			case 'private-person':
				$('customerTypePrivatePerson').checked = true;
				$('customerTypePrivatePersonLabel').addClassName('selected');
				$('customerTypeCompanyLabel').removeClassName('selected');
				$$('.orderData .companyRow').each(function(row) {row.hide()})
				break;
			case 'company':
				$('customerTypeCompany').checked = true;
				$('customerTypeCompanyLabel').addClassName('selected');
				$('customerTypePrivatePersonLabel').removeClassName('selected');
				$$('.orderData .companyRow').each(function(row) {row.show()})
				break;	
		}
	},
	
	changeDeliveryAddress: function()
	{
		$('orderDeliveryName').value = $F('orderName');
		$('orderDeliverySurname').value = $F('orderSurname');
		$('orderDeliveryCompany').value = $F('orderCompany');
		$('orderDeliveryStreet').value = $F('orderStreet');
		$('orderDeliveryCity').value = $F('orderCity');
		$('orderDeliveryZip').value = $F('orderZip');
		
		$('differentDeliveryAddressInput').value = 1;
		
		$('deliveryAddressTable').show();
		$('changeDeliveryAddressLink').hide();
	}
	
});
