$(document).ready( function()
{
	popup=function(sPopupUrl)
	{
		showPopup("nwlPopup");
		$("#nwlPopup").load(sPopupUrl);
	};
	
	submitPopup=function(oForm, sUrl)
	{
		$("#err").hide();
		validate(oForm.id)? 
			$.post(sUrl, $("#"+oForm.id).serialize(), function(a) { $("#nwlPopup").html(a);}):
			$("#err").show();
		return false;
	};
	
	showPopup=function(a)
	{
		$("#"+a).length||$("body").prepend('<div id="overlay"></div><div id="'+a+'" class="popup"></div><a href="#"><img src="'+tlxLang._WEBROOT_+'/images/ico-close.png" id="ico-close" width="23" height="23" alt=""></a>');
		$("select").addClass("ieHide");
		$("#overlay").css("opacity","0.7").fadeIn(
			function()
			{
				window.scrollTo(0,0);
				$("#"+a).css("top",75).css("left",$(window).width()/2-$("#nwlPopup").outerWidth()/2).fadeIn(
					function()
					{
						$("#ico-close").css("top",parseInt($("#"+a).css("top"))-10).css("left",parseInt($("#"+a).css("left"))+$("#"+a).width()+20).show();
					});
			});
	};
	
	$("#overlay, #ico-close").live("click",	function()
	{
		$("#ico-close").hide();
		$(".popup").fadeOut(
			function()
			{
				$("#overlay").fadeOut(
					function()
					{
						$("#overlay, #ico-close, .popup").remove();
						$(".ieHide").removeClass("ieHide");
					}
				);
			}
		);
		return false;
	})
	
	validate=function(a)
	{
		var b=false;
		$("#"+a+" :input").each(
			function()
			{
				$(this).removeClass("ferr");
				if($(this).attr("type")!="hidden"&&$(this).attr("rel")=="req")
					if($(this).attr("name").toLowerCase().indexOf("email")>=0)
					{
						if(!/^[0-9a-zA-Z-_.]+@[0-9a-zA-Z-]+[.]{1}[0-9a-zA-Z-]+[.]?[0-9a-zA-Z]+$/.test($(this).val()))
						{
							$(this).addClass("ferr");
							b=true
						}
					}
					else
						if($(this).val().length==0)
						{
							$(this).addClass("ferr");
							b=true
						}
			});
		$("#"+a+" :input.ferr:first").focus();
		return!b
	};
})
