//<![CDATA[
	$(document).ready(function(){
		if ($('#gMap').length > 0){
			GInitialize('gMap', 'ul. &#379;wirki i Wigury 6b, 38-400 Krosno', '', 14);
		}
		
		$('.printCertificate').click(function(){
			window.open($(this).attr('href'), '', 'ocation=0,status=0,scrollbars=0,menubar=0,resizable=0,width=595,height=842');
			return false;
		});
		//$("#gallery a").prettyPhoto({theme:'dark_rounded'});
		$("#gallery a.callout, #productsGallery a").prettyPhoto({theme:'dark_square'});
		
		$('#button').click(function(){
			var error = false;
			var regexp = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
			
			if($('#email').val().replace(/\s+/g,"").length == 0){
				error = true;
			}
			if($('#comments').val().replace(/\s+/g,"").length == 0){
				error = true;
			}
			if(error){
				if($('#lang').val() == 'en'){
					$('#info').html('Please fill out all required fields!');
				}
				else{
					$('#info').html('Prosz&#281; wype&#322;ni&#263; wszystkie wymagane pola!');
				}
			}
			else if($('#email').val().search(regexp) == -1){
				error = true;
				if($('#lang').val() == 'en'){
					$('#info').html('Please enter valid email address!');
				}
				else{
					$('#info').html('Prosz&#281; poda&#263; poprawny adres email!');
				}
			}
			
			if(!error){
				if($('#lang').val() == 'en'){
					$('#info').html('Please wait. Processing...');
				}
				else{
					$('#info').html('Prosz&#281; czeka&#263;. Trwa wysy&#322;anie...');
				}
				$('#button').attr('disabled', 'true');
				
				var formData = 'lang=' + encodeURIComponent($('#lang').val()) + '&firstname=' + encodeURIComponent($('#firstname').val()) + '&lastname=' + encodeURIComponent($('#lastname').val()) + '&email=' + encodeURIComponent($('#email').val()) + '&phone=' + encodeURIComponent($('#phone').val()) + '&comments=' + encodeURIComponent($('#comments').val());
				
				$.ajax({
					type: 'POST',
					url: 'contact.php',
					cache: false,
					data: formData,
					dataType: "xml",
					timeout: 10000,
					error: function(ob, status){
						$('#button').attr('disabled', '');
						if($('#lang').val() == 'en'){
							$('#info').html('Error: ' + status + '. Please try again.');
						}
						else{
							$('#info').html('B&#322;&#261;d: ' + status + '. Prosz&#281; spr&#243;bowa&#263; ponownie.');
						}
					},
					success: function(xml){
						$('#button').attr('disabled', '');
						var root = xml.getElementsByTagName('root')[0];
						if(root.getElementsByTagName("error")[0].firstChild.nodeValue == 'false'){
							$('#contactForm')[0].reset();
							if($('#lang').val() == 'en'){
								$('#formContent').html('<br/><span class="info">Thank you! Your message has been successfully sent.</span>');
							}
							else{
								$('#formContent').html('<br/><span class="info">Dzi&#281;kujemy! Wiadomo&#347;&#263; zosta&#322;a wys&#322;ana.</span>');
							}
						}
						else{
							if($('#lang').val() == 'en'){
								$('#info').html('Error. Please try again.');
							}
							else{
								$('#info').html('B&#322;&#261;d. Prosz&#281; spr&#243;bowa&#263; ponownie.');
							}
						}
					}
				});
			}
		});
	});
//]]>
