function HomePageTabs()
{
	$('#home_bottom a').click(function(e) {
		e.preventDefault();
		
			var id = $(this).attr('id').substr(3);
			
			$('#home_bottom_container > div').hide();
			$('#home_bottom'+id).show();

	});
	
}

function Register()
{
	/*
	$('#r_username').click(function(){
		$(this).tipTip({maxWidth: '250px', defaultPosition: 'right'});
	});*/
	CheckUser('username');
	CheckUser('email');
	CheckPassword();
}

function Login()
{
	$('#l_username').ClearField();
	$('#l_password').ClearField();
}


function NewPassword()
{
	$('input[name="username"]').ClearField();
	$('input[name="email"]').ClearField();
}


function EditProfile()
{
	var date_options = {
		changeMonth: true,
		changeYear: true,
		yearRange: 'c-100:c'
	};
	
	jQuery.extend(date_options, $.datepicker.regional['pl']);
	//$.datepicker.setDefaults($.datepicker.regional['']);
	$('#birth_date').datepicker(date_options);
	
	ChangeSex();
	$('#birth_date').mask('99.99.9999');
	$('input[name="zip_code"]').mask('99-999');
	
	
	$('select[name="looking_for"]').change(function () {
		if($(this).val() == '1')
		{
			$('#randki').show();
			$('#partnera').hide();
		}	
		else
		{
			$('#randki').hide();
			$('#partnera').show();
		}	
	});

}


function SelectAll()
{
	$('input[name="select_all"]').change(function(){
		$('input[name=\'to_del[]\']').prop('checked', $(this).is(':checked'));
	});
}

function ShowGalleryName()
{
	if($('select[name="gallery_id"]').val() == 0)
		$('#show_gallery_name').show();
	
	$('select[name="gallery_id"]').change(function() {
		if($(this).val() == '0')
			$('#show_gallery_name').show();
		else
			$('#show_gallery_name').hide();
	});
	
	$('input[name="add_photo"]').click(function() {
		if($('select[name="gallery_id"]').val() == 0 && $.trim($('input[name="gallery_name"]').val()) == '')
		{
			alert('Nie podano nazwy galerii !');
			return(false);
		}
	});
}


function ImgCrop()
{
	$('#original_img').Jcrop({
		onChange: ImgShowPreview,
		onSelect: ImgShowPreview,
		aspectRatio: 1,
		minSize: [75, 75]
	});
}


function ImgShowPreview(coords)
{
	$('input[name="offset_x"]').val(coords.x);
	$('input[name="offset_y"]').val(coords.y);
	$('input[name="width"]').val(coords.w);
	$('input[name="height"]').val(coords.h);
	
	var rx = 75 / coords.w;
	var ry = 75 / coords.h;

	$('#preview_img').css({
		width: Math.round(rx * $('#original_img').width()) + 'px',
		height: Math.round(ry * $('#original_img').height()) + 'px',
		marginLeft: '-' + Math.round(rx * coords.x) + 'px',
		marginTop: '-' + Math.round(ry * coords.y) + 'px'
	});
}


function DeleteImg()
{
	
	$('a.del_img').jconfirm('Czy na pewno chcesz usunąć to zdjęcie?');
}

function DeleteVideo()
{
	$('a.del_video').jconfirm('Czy na pewno chcesz usunąć to wideo?');
}

function AddPost()
{
	$('ul#profile_posts textarea').focus(function(){
		$(this).parent().find('img').show();
		$(this).parent().find('span.username').show();
		$(this).removeClass('input_530');
		$(this).addClass('input_470');
		$(this).prop('rows', 3);
		$(this).next().show();
		$(this).val('');
	});
	
	$('ul#profile_posts textarea').blur(function(){
		if($(this).val() == '')
		{
			$(this).parent().find('img').hide();
			$(this).parent().find('span.username').hide();
			$(this).removeClass('input_470');
			$(this).addClass('input_530');
			$(this).prop('rows', 1);
			$(this).next().hide();
			$(this).val('Dodaj wpis...');
		}
	});
	
	if($('ul#profile_posts textarea').val() != $('ul#profile_posts textarea').prop('defaultValue'))
		$('ul#profile_posts textarea').trigger('focus');
}


function CharsCount()
{
	$('textarea[name="description"]').textareaCount({
		'maxCharacterSize':800,
		'warningNumber':50,
		'displayFormat':''
	}, function(data) {
		$('#chars_count').text('Znaków: '+data.input+'/'+data.max);
	});
}

function ProfileActions()
{
	// send a smile
	/*$('a#send_a_smile').click(function(){
		return(confirm('Czy na pewno chcesz wysłać uśmiech?'));
	});
	//*/
	
	$('a#send_a_smile').jconfirm('Czy na pewno chcesz wysłać uśmiech?');
	
	// send gift
	$('#dialog_sendgift').dialog({
		autoOpen: false,
		height: 540,
		width: 454,
		modal: true,
		draggable: false,
		resizable: false,
		title: 'Wybierz prezent',
		buttons: {
			'Zamknij': function(){
				$(this).dialog('close');
			}
		}
	});
	
	$('#send_gift').click(function(e) {
		e.preventDefault();
		$('#dialog_sendgift').dialog('open');
	});

	$('#dialog_recommend').dialog({
		autoOpen: false,
		height: 365,
		width: 454,
		modal: true,
		draggable: false,
		resizable: false,
		title: 'Poleć tę osobę',
		buttons: {
			'Wyślij':function(e){

				var error_txt = '';
				
				if($('#recommend_email').val() == '')
					error_txt = 'Nie podano adresu e-mail !';
				else if(!/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test($('#recommend_email').val()))
					error_txt = 'Nieprawidłowy format e-mail !';
				else if($('#recommend_desc').val() == '')
					error_txt = 'Nie podano opisu !';
				
				if(error_txt == '')
					$('#dialog_recommend form').submit();
				else
				{
					$('#dialog_recommend form p.ui-state-error').remove();
					$('#dialog_recommend form').prepend('<p class="ui-state-error center">'+error_txt+'</p>');
					setTimeout(function(){$('#dialog_recommend form p.ui-state-error').slideUp()}, 5000);	
				}
				
			},
			'Zamknij': function(){
				$(this).dialog('close');
			}
		}
	});
	
	$('#recommend_person').click(function(e){
		e.preventDefault();
		$('#dialog_recommend').dialog('open');
	});
	
	
	
	$('#dialog_abuse').dialog({
		autoOpen: false,
		height: 365,
		width: 454,
		modal: true,
		draggable: false,
		resizable: false,
		title: 'Zgłoś nadużycie',
		buttons: {
			'Wyślij':function(e){

				var error_txt = '';
				
				/*if($('#recommend_desc').val() == '')
					error_txt = 'Nie podano opisu!';*/
				
				if(error_txt == '')
					$('#dialog_abuse form').submit();
				else
				{
					$('#dialog_abuse form p.ui-state-error').remove();
					$('#dialog_abuse form').prepend('<p class="ui-state-error center">'+error_txt+'</p>');
					setTimeout(function(){$('#dialog_abuse form p.ui-state-error').slideUp()}, 5000);	
				}
				
			},
			'Zamknij': function(){
				$(this).dialog('close');
			}
		}
	});
	
	$('#send_abuse').click(function(e){
		e.preventDefault();
		$('#dialog_abuse').dialog('open');
	});
}


function RecommendPerson()
{
	$('#dialog_recommend').dialog({
		autoOpen: false,
		height: 365,
		width: 454,
		modal: true,
		draggable: false,
		resizable: false,
		title: 'Poleć tę osobę',
		buttons: {
			'Wyślij':function(e){

				var error_txt = '';
				
				if($('#recommend_email').val() == '')
					error_txt = 'Nie podano adresu e-mail !';
				else if(!/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test($('#recommend_email').val()))
					error_txt = 'Nieprawidłowy format e-mail !';
				else if($('#recommend_desc').val() == '')
					error_txt = 'Nie podano opisu !';
				
				if(error_txt == '')
					$('#dialog_recommend form').submit();
				else
				{
					$('#dialog_recommend form p.ui-state-error').remove();
					$('#dialog_recommend form').prepend('<p class="ui-state-error center">'+error_txt+'</p>');
					setTimeout(function(){$('#dialog_recommend form p.ui-state-error').slideUp()}, 5000);	
				}
				
			},
			'Zamknij': function(){
				$('#recommend_user').val('');
				$(this).dialog('close');
			}
		}
	});
	
	$('a.user_recommend').click(function(e){
		e.preventDefault();
		$('#recommend_user').val($(this).parent().find('img').prop('alt')+'');
		$('#dialog_recommend').dialog('open');
	});
}


function ConfirmPMDelete()
{
	/*$('input[name="del"]').click(function(){
		return(confirm('Czy napewno chcesz usunąć tą wiadomość?'));
	});*/
	
	$('input[name="del"]').jconfirm('Czy napewno chcesz usunąć tą wiadomość?');
}


function Payments()
{
	$('#dialog_payment').dialog({
		autoOpen: false,
		height: 490,
		width: ($.browser.msie && $.browser.version == '7.0') ? 730 : 715,
		modal: true,
		draggable: false,
		resizable: false,
		title: 'Opłać konto PREMIUM'
	});
	
	$('#payment_button').click(function(e){
		e.preventDefault();
		$('#dialog_payment').dialog('open');
	});
}


function PaymentDetails()
{
	$('a.payment_option').click(function(){
		$('a.payment_option').removeClass('payment_option_selected');
		$(this).addClass('payment_option_selected');
		$(this).filter('input').attr('checked', 'checked');
		$(this).filter('input').prop('checked', 'checked');
	});
	
	$('input[name="p24_kod"]').mask('99-999');
	
	$('#payment_type').change(function(){
		if($(this).val() == 2)
			$('#payment_card').show();
		else
			$('#payment_card').hide();
	});
}


function Help()
{
	$('ul#help li a.help_link').click(function(e) {
		e.preventDefault();

		$(this).next('span').toggle();

	});
}

function Tooltip()
{
	$('ul.photo_row a').tipTip();
	$('ul.photo_row2 a').tipTip();
}
