  $(function() {
		$("#datepicker").datepicker();
		$("#datepicker2").datepicker();
		$("#datepicker3").datepicker();
		$(".datepickerrr").datepicker();
	});
			$(function() {
                $('#tabs > ul').tabs({ fx: { opacity: 'toggle' } })
				$('#tabs2 > ul').tabs({ fx: { opacity: 'toggle' } })
				$('#tabs3 > ul').tabs({ fx: { opacity: 'toggle' } })
				$('#tabs4 > ul').tabs({ fx: { opacity: 'toggle' } })
				}
			);
			$(document).ready(function() {
				var div = document.getElementById('asidx_connected_select');
				$(div).change(function() {
					var wpidx = document.getElementById('wpidx_connected').value;
					$.ajax({
						type: "POST",
						url: "index.php?pg=komorkiaspektumojalista",
						data: "asidx="+this.value+"&wpidx="+wpidx+"&t=1",
						success: function(msg){
							//$('#komorkiUzytkownikaAll').html(msg);
							alert ('jest');
							//$('#komorkiUzytkownikaAll_current_multi').html(msg);
							//updateDOM(document.getElementById('optionsdpidx'));
						}
					});
				});
			});
			function checkEnter(event)
			{
				var code = 0;
				code = event.keyCode;
				if (code==13)
					return true;
				else
					return false;
			}
			
			
			
			//pobiera komórki aspektu wybranego w multi 
			function getKomorkiAspektuMl(wpidx, asidx) {
				if (wpidx != '' && asidx != '') {
					var wpidx = document.getElementById('wpidx_connected').value;
					$.ajax({
						type: "POST",
						url: "index.php?pg=show_komorki_aspektu_ml",
						data: "asidx="+asidx+"&wpidx="+wpidx+"&t=2",
						success: function(msg){
						  msg=$('#komorkiUzytkownikaAll').html()+msg; 
							$('#komorkiUzytkownikaAll').html(msg);
						}
					});
				}
			}
			
  		// pobiera wszystkie komórki dla zapisanych aspektów wpidx  	
  		function getALLKomorkiAspektuMl(wpidx) {
  				if (wpidx != '') {
  					var wpidx = document.getElementById('wpidx_connected').value;
  					$.ajax({
  						type: "POST",
  						url: "index.php?pg=show_all_komorki_aspektu_ml",
  						data: "wpidx="+wpidx+"&t=2",
  						success: function(msg){
  							$('#komorkiUzytkownikaAll').html(msg);
  						}
  					});
  			}			
  		}
			function editMojaLista(wpidx) { //, asidx) {
				if (wpidx != '') {
					$('#formNameField').html('Edytuj na mojej liście');
          // zapełnia selectboxa
          $.ajax({
						type: "POST",
						url: "index.php?pg=aspektywymagania",
						data: "wpidx="+wpidx+"&t=2",
						success: function(msg){
							$('#asidx_connected_select').html(msg);
							//updateDOM(document.getElementById('aspekty_select_div'));
							var select = document.getElementById('asidx_connected_select');
						        	if(select.options.length){
                      //getKomorkiAspektuMl(wpidx, select.options[0].value,true);
                      //generuje dla wszytkich aspektów oddzielne multi komórek organizacyjnych 
                          getALLKomorkiAspektuMl(wpidx);
                      }
						}
					});
					// generuje multi aspektów 
					$.ajax({
						type: "POST",
						url: "index.php?pg=aspektymlall",
						data: "wpidx="+wpidx+"&t=2",
						success: function(msg){
							$('#aspektyUzytkownikaAll').html(msg);
						}
					});
					document.getElementById('wpidx_hidden').value = wpidx;
					document.getElementById('df_ml_wpidx_hidden').value = wpidx;					
					document.getElementById('wpidx_connected').value = wpidx;
					Alert('EditDiv');
				}
			}
			
			
			
			function addMojaLista(wpidx) {
				var div;
				$('#formNameField').html('Dodaj do mojej listy');
				document.getElementById('del_button_ml').style.display='none';
				if (div = document.getElementById('wpidx_connected'))
					document.getElementById('wpidx_connected').value = wpidx;
				else
					alert('Brak hiddena z id wymagania!!!');
				if (wpidx != '') {
					var asidx = document.getElementById('first_asidx').value;
					$.ajax({
						type: "POST",
						url: "index.php?pg=aspektymlall",
						data: "wpidx="+wpidx+"&t=2",
						success: function(msg){
							$('#aspektyUzytkownikaAll').html(msg);
							//updateDOM(document.getElementById('optionsdpidx2'));
						}
					});
					document.getElementById('wpidx_hidden').value = wpidx;
					document.getElementById('komorkiUzytkownikaAll').innerHTML=document.getElementById('komorkiUzytkownikaAll_info').innerHTML;
					Alert('EditDiv');
				}
			}
			
			
			
			$(document).ready(function() {
				$('#loginField, #passwordField').keydown(function(event) {
					if (checkEnter(event))
						document.userlogintopform.submit();
				});
				$('.login_field').keydown(function(event) {
					if (checkEnter(event))
						document.userloginform.submit();
				});
				$('.definitionLink').mouseover(function(event) {
					var y = event.clientY + (document.body.scrollTop + document.documentElement.scrollTop)+10;
					var x = event.clientX + (document.body.scrollLeft + document.documentElement.scrollLeft);
					$.ajax({
						type: "POST",
						url: "index.php?pg=definicjachmurka",
						data: "didx="+this.id,
						success: function(msg){
							if (msg != '') {
								jQuery("<div/>", {
									id: 'definicja',
									html: msg
								}).appendTo('body');
								$('#definicja').css('top', y+'px');
								$('#definicja').css('left', x+'px');
								$('#definicja').show();
							}
						}
					});
				});
				$('.definitionLink').mouseout(function() {
					$('#definicja').hide();
					$('#definicja').remove();
				});
				$('#asidx_select').change(function() {
					var asidx = this.value;
					$.ajax({
						type: "POST",
						url: "index.php?pg=komorkiaspektumojalista",
						data: "asidx="+asidx+"&t=2",
						success: function(msg){
							$('#komorkiUzytkownikaAll').html(msg);
							//updateDOM(document.getElementById('optionsdpidx'));
						}
					});
				});
			});
			$(function() {
				$("#treeFolder1").treeview({
				   persist: "cookie",
				   cookieId: "navigationtree",
					animated: "medium",
					control:"#sidetreecontrol",
					persist: "location"
				});
				$("#treeFolder2").treeview({
				   persist: "cookie",
				   cookieId: "navigationtree",
					animated: "medium",
					control:"#sidetreecontrol",
					persist: "location"
				});
				$("#treeFolder3").treeview({
					   persist: "cookie",
				   cookieId: "navigationtree",
					animated: "medium",
					control:"#sidetreecontrol",
					persist: "location"
				});
				$("#treeFolder4").treeview({
				   persist: "cookie",
				   cookieId: "navigationtree",
					animated: "medium",
					control:"#sidetreecontrol",
					persist: "location"
				});
				$("#treeFolder5").treeview({
				   persist: "cookie",
				   cookieId: "navigationtree",
					animated: "medium",
					control:"#sidetreecontrol",
					persist: "location"
				});
				$("#treeFolder6").treeview({
					   persist: "cookie",
				   cookieId: "navigationtree",
					animated: "medium",
					control:"#sidetreecontrol",
					persist: "location"
				});
				$("#treeFolder7").treeview({
					   persist: "cookie",
				   cookieId: "navigationtree",
					animated: "medium",
					control:"#sidetreecontrol",
					persist: "location"
				});
				$("#treeFolder8").treeview({
						   persist: "cookie",
				   cookieId: "navigationtree",
					animated: "medium",
					control:"#sidetreecontrol",
					persist: "location"
				});
				
				$("#treeAdresaci").treeview({
					persist: "cookie",
					collapsed: true,

				   cookieId: "navigationtree",
					animated: "medium",
					persist: "location"
				});
				
			});
		$(window).load(
			function()
			{
				// get collapsible list
				/*
				$("ul.collapsible").each(
					function()
					{
						iterateList(this);
						//$("#codeblock").html($("#thisscript").get(0).text);
					}
				);
				*/
				$('#najczesciej').click(function() {
					$('#tabs4').hide();
					$('#tabs3').show();
				});
				$('#ostatnio').click(function() {
					$('#tabs3').hide();
					$('#tabs4').show();
				});
			}
		);
			// kamil => do pseudo selectboxow, po wyborze przypisuje do "id" wartosc "value" i chowa diva "hide"
			function setValueToId(id, value, hide) {
				$('#'+id).attr('value', value);
				$('#'+hide).hide();
			}
			function setValue(id, value) {
				$('#'+id).attr('value', value);
			}
			function setValueAndSend(id,value,formName) {
			  $('#'+id).attr('value', value);
			  document.getElementsByName(formName)[0].submit();
      }
			function changeStatus(id,knidx, value) {
				$('#'+id).attr('value', value);
				if(value==2 || value==3){
					document.getElementById('show_button_'+id).style.display='block';			
             if(knidx!=0){
              document.getElementById('show_delbutton_'+id).style.display='block';
             }        		
				}else if(value==1){
				  document.getElementById('show_button_'+id).style.display='none';
            if(knidx!=0){
					     document.getElementById('show_delbutton_'+id).style.display='none';	
            }			  
				}
			}
			function checkedUnchecked(id, noid) {
				var i, n=noid.length;
				if ($('#'+id).attr('value') == '') {
					$('#'+id).attr('value', 1);
					for (i=0; i<n; i++)
						$('#'+noid[i]).attr('value', '');
				}
				else if ($('#'+id).attr('value') == 1)
					$('#'+id).attr('value', '');
				//alert('id: '+id+'   value: '+$('#'+id).attr('value'));
			}
			function transport(values, where) {
				var i, n = where.length;
				for (var i=0; i<n; i++) {
				
				        values[i] = str_replace ("#", "\n", values[i]);
                values[i] = str_replace ("$","\r", values[i]);

				
				
					$('#'+where[i]).attr('value', values[i]);
				}
			}
			function clearValues(where) {
				var i, n = where.length;
				for (var i=0; i<n; i++) {
					$('#'+where[i]).attr('value', '');
				}
			}
var delimiter = ":";
function MoveOption (MoveFrom, MoveTo, ToDo,output_name,output_div,outputmultiple,field_name) {
  var SelectFrom = document.getElementById(MoveFrom);
  var SelectTo = document.getElementById(MoveTo);
  var SelectedIndex = SelectFrom.options.selectedIndex;
  var OUTPUTMULTIPLE = document.getElementById(outputmultiple);
	var OUTPUT_DIV = document.getElementById(output_div);
  var container;
  if (ToDo=='Add') {
    container= document.getElementById('Add'.MoveTo);
  }
  if (ToDo=='Remove') {
    container= document.getElementById('Remove'.MoveTo);
  }
  if (SelectedIndex == -1) {
             var error = document.getElementById('error_show'+field_name);
             var error_content = document.getElementById('error_content'+field_name);
             error.style.display='';
             error_content.innerHTML='Tip: Zaznacz pozycję po prawej lub lewej stronie klikająć w nią, lub kilka pozycji zaznaczając je myszką <br />przy jednocześnie wcisniętym klawiszu Ctrl<br />';
  } else {
    for (i=0; i<SelectFrom.options.length; i++) {
      if(SelectFrom.options[i].selected) {
        var name = SelectFrom.options[i].text;
        var ID = SelectFrom.options[i].value;
        SelectFrom.options[i] = null;
        SelectTo.options[SelectTo.options.length]=new Option (name,ID);
        i=i-1;
        if(ToDo=='Add'||ToDo=='Remove') {
          //container.value=container.value+name+delimiter;
          //container.value=container.value+ID+delimiter;
        }
      }
    }
          var length_output = OUTPUTMULTIPLE.length;
          var groupvalue='';
		  var groupvalue2='';
        	for(ii=0;ii<length_output;ii++)
					{
					 groupvalue=groupvalue+'<input type="hidden" name="'+output_name+'" value="'+OUTPUTMULTIPLE.options[ii].value+'" />';
						groupvalue2+='<option value="'+OUTPUTMULTIPLE.options[ii].value+'">'+OUTPUTMULTIPLE.options[ii].text+'</option>';
						//console.log(groupvalue2);
					}
        	OUTPUT_DIV.innerHTML=groupvalue;
			var div;
			//alert(MoveFrom+' '+MoveTo);
			//if (div = document.getElementById('asidx_connected_select'))
				if ((MoveFrom == 'optionsdpidx2' && MoveTo == 'selected_optionsdpidx2') || (MoveFrom == 'selected_optionsdpidx2' && MoveTo == 'optionsdpidx2')) {
					//div.innerHTML = '';
					//div.innerHTML=groupvalue2;
					//var select = document.getElementById('asidx_connected_select');
					//$(select).html(groupvalue2);
					//if ($('#asidx_connected_select').length) {
					//	if(select.options.length){getKomorkiAspektuMl(document.getElementById('wpidx_connected'), select.options[0].value);}
						//if(select.options.length){
						
					        document.getElementById('komorkiUzytkownikaAll').innerHTML='';//document.getElementById('komorkiUzytkownikaAll_info').innerHTML;
                  for(ii=0;ii<length_output;ii++)
        					{
        					 getKomorkiAspektuMl(document.getElementById('wpidx_connected'), OUTPUTMULTIPLE.options[ii].value);
        					}
            //}
				//	}
				}
			if (div = document.getElementById('kidx_auditors_select')) {
				if ((MoveFrom == 'optionsdpidx_zes_a' && MoveTo == 'selected_optionsdpidx_zes_a') || (MoveFrom == 'selected_optionsdpidx_zes_a' && MoveTo == 'optionsdpidx_zes_a')) {
					//div.innerHTML=groupvalue2;
					var select = document.getElementById('kidx_auditors_select');
					var odpowiedzialny = document.getElementById('hidden_odpowiedzialny_kidx');
					$(select).html(groupvalue2);
					//if ($('#kidx_auditors_select').length)
						//getKomorkiAspektuMl(document.getElementById('wpidx_connected'), select.options[0].value);
				}
			}
	}
}
function updateDOM(inputField) {
    // if the inputField ID string has been passed in, get the inputField object
    if (typeof inputField == "string") {
        inputField = document.getElementById(inputField);
    }
    if (inputField.type == "select") { // bylo select-one
        for (var i=0; i<inputField.options.length; i++) {
            if (i == inputField.selectedIndex) {
                inputField.options[inputField.selectedIndex].setAttribute("selected","selected");
            }
        }
    } else if (inputField.type == "text") {
        inputField.setAttribute("value",inputField.value);
    } else if (inputField.type == "textarea") {
        inputField.setAttribute("value",inputField.value);
    } else if ((inputField.type == "checkbox") || (inputField.type == "radio")) {
        if (inputField.checked) {
            inputField.setAttribute("checked","checked");
        } else {
            inputField.removeAttribute("checked");
        }
    }
}



$(function() {

  if(document.getElementById('textarea')){
  $("#textarea").autogrow();
  }
  
      
});

function getAdresaci(hidx_p){
  $.get("SendRequest/get_adresaci.php", { hidx: hidx_p},
   function(data){
     //alert("Data Loaded: " + data);
     document.getElementById('adresacidiv').innerHTML=data;
				$("#treeAdresaci").treeview({
					persist: "cookie",
					collapsed: true,

				   cookieId: "navigationtree",
					animated: "medium",
					persist: "location"
				});     
   }); 
}
function open_window(address)
{
  window.open(address);
}

function check_powiazanie_komorka_uzytkownik(id_to_check,id_kom){
if(document.getElementById(id_to_check).options.length==0){
document.getElementById(id_kom).style.display='block';
return false;
}else return true;
}


function ClosePopup(){ 
 document.getElementById('Popup').style.display = 'none';
 createCookie('wymagania_popup2',1,3);
} 


function createCookie(name,value,hours) {
	if (hours) {
		var date = new Date();
		date.setTime(date.getTime()+(hours*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return 0;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

// komentarze header

function limituj_znaki(limit_znakow, pole ,wynik_contener)
{					
	var tekst_w_polu = $('#'+pole).val();
	//alert(tekst_w_polu);
	/*for (i=0; i < tekst_w_polu; i++) 
	{ 
          if (tekst.charAt(i) == "\n") 
		{ 				
              prawdziwa++; 
              entery++;                  
          }             	 
    	} 
      */
	 $('textarea[maxlength]').keyup(function(){  
		         //get the limit from maxlength attribute  
		         var limit = parseInt($(this).attr('maxlength'));  
		         //get the current text inside the textarea  
		         var text = $(this).val();  
		         //count the number of characters in the text  
		         var chars = text.length;  
		   
		         //check if there are more characters then allowed  
		         if(chars > limit){  
		             //and if there are use substr to get the text before the limit  
		             var new_text = text.substr(0, limit);  
		   
		             //and change the current text with the new text  
		             $(this).val(new_text);  
		         }  
		     });  
	var znakow_w_polu = tekst_w_polu.length;			
	var pozostalo_znakow = limit_znakow - znakow_w_polu;
	var ogr = Number(limit_znakow);			 
	if(znakow_w_polu == ogr)
	{							
		$('#'+wynik_contener).text(0); 
	}
	else
	{				
		$('#'+wynik_contener).text(pozostalo_znakow);
	}
}
function ajax_check()
{
	
	$(document).ajaxStart(function() 
	{       
	 $("div#loadingajax").css("display", 'block');
	 $('.lista_komentarzy').css("opacity", '0.2');
	 $('.lista_komentarzy').addClass('loadingajax_active');
	});		
	$(document).ajaxComplete(function() 
	{      		     	
	 $("div#loadingajax").css("display", 'none');	 
	 $('.lista_komentarzy').css("opacity", '1');
	 $('.lista_komentarzy').removeClass('loadingajax_active');
	});	
	$(document).ajaxError(function() 
	{      		     	
	 //$("div#loading").css("display", 'none');
	 alert('Blad podczas operacji, skontaktuj się z cok@wymagania-prawne.pl');
	});	
}

// komentarze footer


