function deleteSelectedProduct(product_id){
	$.ajax({
		type: 'POST',
		url: base_href,
		data: {
			ajax: 1,
			deleteSelectedProduct: product_id
		},
		success: function(data){
			$('#content').html(data);
			if ($('.products .block').length==0)
				$('ul.langs .check a').replaceWith('<span title="'+$('ul.langs .check span').attr('href')+'">'+$('ul.langs .check a').html()+'</span>');
		}
	});
}

function addSelectedProduct(product_id){
	$.ajax({
		type: 'POST',
		url: base_href,
		data: {
			ajax: 1,
			addSelectedProduct: product_id
		},
		success: function(data){
			$('#content .bottom_block.last').html(data);
			$('ul.langs .check').show();
			$('ul.langs .check span').replaceWith('<a href="'+$('ul.langs .check span').attr('title')+'">'+$('ul.langs .check span').html()+'</a>');
		}
	});
}

function toggleSendForm(form_id){
	if (!form_id){
		var currentTime = new Date();
		var splash_id = 'splash-'+currentTime.getTime();
		$('body').append('<div id="content_hover"></div><div class="splash" id="'+splash_id+'">'+$('#hidden_splash').html()+'</div>');
		var margin = $('#'+splash_id).height()/-2 - 10;
		$('#'+splash_id).css({'margin-top': margin});
		//$('#'+splash_id).find('.delete').attr('onclick','toggleSendForm("'+splash_id+'");');
		//$('#'+splash_id).find('form').attr('onsubmit','sendFriendForm("'+splash_id+'"); return false;');
	} else {
		$('#content_hover').remove();
		$(form_id).parent().remove();
	}
}

function sendFriendForm(form){
	var submit_form = true;
	$(form).find('input:not([type=submit]), textarea').each(function(){
		$(this).removeClass('error');
		if($(this).hasClass('email') && !isValidEmailAddress($(this).val()) || $(this).val().length < 3){
			$(this).addClass('error');
			submit_form = false;
		}
	});	   
	
	if (submit_form){
		document.forms[form].submit();
	} 	
}

function getTypeColors(select){
	var type_id = $(select).val();
	var first_option = $('#search select[name="color"] option:first-child').text();
	if (type_id){
		$.ajax({
			type: 'POST',
			url: base_href,
			data: {
				ajax: 1,
				getTypeColors: type_id
			},
			success: function(data){
				$('#search select[name="color"]').html('<option value="">'+first_option+'</option>'+data);
				$('#search select[name="color"]').attr('disabled', '');
				$('#search').submit();
			}
		});
	} else {
		$('#search select[name="color"]').attr('disabled', 'disabled');
		$('#search select[name="color"]').html('<option value="">'+first_option+'</option>');
		$('#search').submit();
	}
}

function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}
