//--------------------------------------------------------------------------------------------------
//  Funkcja sprawdza siłe hasła
//--------------------------------------------------------------------------------------------------
function passwordStrength(input,div) 
{
	$(input).bind("keyup",function(){
	var password = $(this).val();

	var score = 0;

	//if password bigger than 6 give 1 point
	if (password.length >= 8) score++;

	//if password has both lowercase characters give 1 point
	if ( password.match(/[a-z]/) ) score++;

	//if password has both uppercase characters give 1 point
	if ( password.match(/[A-Z]/) ) score++;

	//if password has at least one number give 1 point
	if (password.match(/[0-9]/)) score++;

	//if password has at least one special caracther give 1 point
	if ( password.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) ) score++;

	//if password bigger than 12 give another 1 point
	if (password.length > 12) score++;

	$(div).empty();
	for(var i = 0;i<score;i++)
	$(div).append('<div style="width: 20px;height: 40px; background-color: green;float:left"></div>')
	});
}
//--------------------------------------------------------------------------------------------------
//  Przełącza zakładki (modul: dlamediow)
//--------------------------------------------------------------------------------------------------
function switchTabs(button,tabName) 
{
	$('.tabs').children().each(function(){
		if($(this).attr('id')!=undefined)
		$(this).attr('id',$(this).attr('id').replace(/on/,'off'));
	});
	
	$(button).attr('id',$(button).attr('id').replace(/off/,'on'));
	
	$('#tabContent').children().each(function(){
		$(this).hide();
	});

	$('#'+tabName).show();
}
//--------------------------------------------------------------------------------------------------
//  Funkcja obsługuje zapytania teryt
//--------------------------------------------------------------------------------------------------
function teryt(type,objID)
{
	var prefix = objID.split('_');	

	$('#'+objID).parent().nextAll().children('select').html('<option value="0">-- Wybierz -- </option>').css('background-color','#eee');
	$.ajax({
		url: "/ajax/teryt.html",
		
		type: "POST",
		data: {
			typ: type,
			id_woj: $("#wojewodztwo"+'_'+prefix[1]).val(),
			id_pow: $("#powiat"+'_'+prefix[1]).val(),
			id_gmi: $("#gmina"+'_'+prefix[1]).val(),
			id_mie: $("#miejscowosc"+'_'+prefix[1]).val(),
			id_ulica: $("#ulica"+'_'+prefix[1]).val()
		},
		
		success: function(html)
		{
			var obj='';
			if(obj = $.parseJSON(html)) 
			{
				var options = '';
				options += '<option value="0">-- Wybierz --</option>';
				for (var i = 0; i < obj.length; i++) {
				options += '<option value="' + obj[i].id + '">' + obj[i].nazwa + '</option>';
				}

        //ukrycie diva z ulicą jeśli taka w danej miejscowości nie występuje
        if(obj.length=='0' && type=='ulica'){
          $('#ulicadiv'+'_'+prefix[1]).hide('slow');
        } else {
          $('#ulicadiv'+'_'+prefix[1]).show('slow');
        }
        
        $('#'+type+'_'+prefix[1]).html(options);
        $('#'+type+'_'+prefix[1]).css('background-color','white');

			}
		}
	});
}
//--------------------------------------------------------------------------------------------------
//  Funkcja sprawdza formularz wniosku pod kątem wysyłanych plików
//--------------------------------------------------------------------------------------------------
function verifyWnioski(form)
{	
  if ($('.completed').length == $('.uploadifyQueueItem').length) {
	return true;
  }else{
    $(".uploadifyField").uploadifyUpload();
	return false;
  }
}
