function check_input(id,field)
{
	var $val = $('#'+id).val();
	if($val=='' || $val==field)
	{
		$('#'+id).focus();
		alert('Заполните поле '+field);
		return false;
	}
	return true;
}

function f_focus()
{
	var old_value = this.getAttribute('old_value');
	if(old_value!=null)
		return;
	var old_value = this.getAttribute('_old_value');
	if(old_value==null)
	{
		this.setAttribute('_old_value',this.value);
		old_value = this.value;
	}
	if(old_value==this.value)
		this.value = '';
}
function f_blur()
{
	if(this.value=='')
		this.value = this.getAttribute('_old_value')||'';
}

function check_mail(value) {
	value = value.toLowerCase();
	var reg = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/;
	var new_val = value.match(reg);
	if (new_val!=value) {
		alert("Пожалуйста, введите свой настоящий e-mail");
		return true;
	}
	return false;
}

$(function(){
	$('#sendnewsSubscribe').submit(function(){
		$.ajax({type: 'POST',url: '/emails/subscribe/',
			data: {email:$(this).find('#email').val()},
			success: function(data){
				if (data.success)
				{
					$('#email').val('');
					$('#sendnewsSubscribe').hide();
					$('#a_subscribe').show();
				}
				else
				{
					alert('Не верный email');
				}
			},
			dataType: 'json'
		});
		return false;
	});
	$('#a_subscribe').click(function()
	{
		$('#sendnewsSubscribe').show();
		$('#a_subscribe').hide();
		return false;
	});
	$('#close_rss').click(function()
	{
		$('#sendnewsSubscribe').hide();
		$('#a_subscribe').show();
		return false;
	});
	$('#email').focus(function(){
		var old_value = this.getAttribute('old_value');
		if(old_value==null)
		{
			this.setAttribute('old_value',this.value);
			old_value = this.value;
		}
		if(old_value==this.value)
			this.value = '';
	});
	$('#email').blur(function(){
		if(this.value=='')
			this.value = this.getAttribute('old_value');
	});
	$('p.audio a').click(function(){
		$(this).toggleClass('active');
		$(this).parent().next().toggle();
		return false;
	});
	$('div.rate a').click(function(){
		var email = '';
		do{
			email = prompt('Введите ваш Email',email);
			if(!email)
				return;
		}while(check_mail(email));
		$.ajax({type: 'POST',url: '/bands/rate/',
			data: {email:email,band_id:this.getAttribute('band_id')},
			success: function(data){
				alert(data.msg);
			},
			dataType: 'json'
		});
		return false;
	});
	$('.txt').focus(f_focus);
	$('.txt').blur(f_blur);
	$('#partners img').hover(function(){
		this.old_src = this.src;
		this.src = $(this).parent().parent().attr('src');
	},function(){
		this.src = this.old_src;
	});
	$('.headline').click(function(){
		location.href = '/bands/players';
	});
});
