function GetFormEl(){
	var Felem;
	$("input").each(function(){
		Felem=Felem+'&'+$(this).attr('name')+'='+$(this).val();
	});
	
	$("textarea").each(function(){
		Felem=Felem+'&'+$(this).attr('name')+'='+$(this).val();
	});
	return Felem;
}

$(function() {  
	var error;	
	$("#magazia a").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayShow': false }); 
	$('#subscr').click(function() {
		var parForm=$(this).parent();
		var fEm=$(parForm).find('input');	
		$.ajax({
				url: 'submit.php',
				type: 'POST',
				data: 'subscr=true&mail='+$(fEm).val(),
				success: function(result) {
					if(result=='Error')$(fEm).val('Email is incorrect');
					else $(parForm).html(result);
				}
		});
		return false;
	});
	
	$('form :reset').click(function() {
		error=false;
		$('#error').hide();
		$('#response').remove();
		$("input:[alt='must']").each(function(){	
			$(this).removeClass('ElemError');
		});
		
		$("textarea:[alt='must']").each(function(){	
			$(this).removeClass('ElemError');
		});
	});
	
	$('form :submit').click(function() {
		error=false;
		var parForm=$(this).parent();
		$('#error').hide();
		$("input:[alt='must']").each(function(){	
			if(!$(this).val()){ 
				error=true;
				$(this).addClass('ElemError');
			}
			else $(this).removeClass('ElemError');
		});
		$("textarea:[alt='must']").each(function(){	
			if(!$(this).val()){ 
				error=true;
				$(this).addClass('ElemError');
			}
			else $(this).removeClass('ElemError');
		});
		if(!error){
			$.ajax({
				url: 'submit.php',
				type: 'POST',
				data: GetFormEl(),
				success: function(result) {
					$('#response').remove();
					$(parForm).html('<p id="response">'+result+'</p>');
				}
			});
		}
		else $('#error').show();
		return false;
	});	
});

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=720,height=470,left = 200,top = 200');");
}

function popUp1(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=720,height=470,left = 200,top = 200');");
}