/**
 * @author BitArtis.pl
 */


// Lighbox

$(document).ready(function() {
	$('a.LB').lightBox();
	$('div.Galeria a').lightBox();

$('.wysrodzica_32').each(function() {
		var wys=$(this).parent().parent().parent().height();
		$(this).css('height',wys+'px');
	});
	$('.wysrodzica_22').each(function() {
		var wys=$(this).parent().parent().height();
		$(this).css('height',wys+'px');
	});
	

	supported=false; test1=false;
	if (navigator.platform=="Win32") test1=true;
	if (test1 && /MSIE 6/.test(navigator.userAgent)) supported=true;
	
	if (supported) {
		$('img:regex(src,^.*\.png$)').each (function() {
			h_ = $(this).css('height');
			w_ = $(this).css('width');
			sciezka="/css/images/";
			stara=$(this).attr("src");
			stara=stara.split('/');
			link=stara[(stara.length)-1];
			$(this).attr("src","/css/images/transp.gif");
			$(this).css("filter","progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+sciezka+link+"', sizingMethod='scale')");
			$(this).css("height",h_);
			$(this).css("width",w_);
		});
	}
});




function validacja(id) {
	var blad='';
	var nowy=''; var stary='';
	var count=-1;
	var passTab=Array();
	$('#'+id+' .req_text').each(function() {
		if ($(this).attr('value')=='' || $(this).attr('value')==undefined) {
			blad += "- " + $(this).attr('title') + "\n";
		}
	});
	$('#'+id+' .req_login').each(function() {
		if (!/[a-z0-9_]{6,30}/.test($(this).attr('value'))) {
			blad += "- " + $(this).attr('title') + "\n";
		}
	});
	$('#'+id+' .req_mail').each(function() {
		if (!/^([a-zA-Z0-9._-]{1,})@([a-zA-Z0-9._-]{1,})\.([a-zA-Z]{2,4})$/.test($(this).attr('value'))) {
			blad += "- " + $(this).attr('title') + "\n";
		}
	});
	
	$('#'+id+' .req_youtube').each(function() {
		if (!/^http:\/\/([a-zA-Z]{2,3})\.youtube\.com\/(.*)$/.test($(this).attr('value'))) {
			blad += "- " + $(this).attr('title') + "\n";
		}
		else {
			if (!/(\?|&)v=([0-9a-zA-Z_-]+)(&|$)/.test($(this).attr('value'))) {
				alert('de');
				blad += "- " + $(this).attr('title') + "\n";
			}
		}
	});	
	$('#'+id+' .req_pass').each(function() {
		count++;
		passTab[count]=$(this).attr('value');
		if (!/.{6,30}/.test($(this).attr('value'))) {
			blad += "- " + $(this).attr('title') + "\n";
		}
	});
	for(i in passTab) {
		if (nowy) { stary=nowy; }
		nowy=passTab[i];
		if (stary!='' && stary!=nowy) {
			blad += "- Podane hasła nie pasują do siebie"
		}
	}
	if (blad != '') {
		alert("Przepraszamy, ale wystąpiły nastpępujące błędy:\n\n"+blad+"\nProszę popraw błędy i spróbuj ponownie.");
		return false;
	}
	else {
		return true;
	}
	
}


function validacja2(id) {
	var blad='';
	var nowy=''; var stary='';
	var count=-1;
	var passTab=Array();
	$('#'+id+' .req_mail').each(function() {
		if (!/^([a-zA-Z0-9._-]{1,})@([a-zA-Z0-9._-]{1,})\.([a-zA-Z]{2,4})$/.test($(this).attr('value'))) {
			blad += "- " + $(this).attr('title') + "\n";
		}
	});
	
	if (blad != '') {
		alert("Przepraszamy, ale wystąpiły nastpępujące błędy:\n\n"+blad+"\nProszę popraw błędy i spróbuj ponownie.");
		return false;
	}
	else {
		var mail=$('#'+id+' .req_mail').attr('value');
		dodaj_do_newslettera(mail);
		return false;
	}
	
}


function dodaj_do_newslettera(mail) {
	$.ajax({
		type: "GET",
		url: "/index.php?ajax=1&module=newsletter&mail="+mail,
		cache: false,
		success: function(info) {
			if (info) {
				alert(info);
			}
			else {
				alert('Błąd połączenia. Spróbuj ponownie.');
			}
         }
	});// ajax
}



// Google MAPS
/*
function load() {
	var zoom=11;
	var xx=50.0;
	var yy=22.0;
	var point = new GLatLng(xx,yy);  
	var marker = new GMarker(point);

	if (GBrowserIsCompatible()) { 
		var mapa = new GMap2(document.getElementById("mapka")); 
		mapa.addControl(new GSmallZoomControl());
		mapa.setCenter(new GLatLng(xx,yy), zoom); 
		mapa.addOverlay(marker);
	}
}
*/
