var fieldsTab = Array();

	fieldsTab[0] = "s_Id";
	fieldsTab[1] = "a_Zip";
	fieldsTab[2] = "a_City";
	fieldsTab[3] = "p1_Number";
	fieldsTab[4] = "p2_Number";
	fieldsTab[5] = "p3_Number";
	fieldsTab[6] = "pe_Name";
	fieldsTab[7] = "pe_Surname";
	fieldsTab[8] = "pe_IdSex";
	fieldsTab[9] = "cu_SecondarySorcesOfIncome";
	fieldsTab[10] = "cu_Customer_Login";
	fieldsTab[11] = "tr_Id";
	fieldsTab[12] = "tr_IdOperator";

var employmentEdit = false;

var aOccupationTypes = Array();
	aOccupationTypes[0]  = Array(1,'Nieokreślony','selected');
	aOccupationTypes[1]  = Array(2,'Umowa o pracę',null);
	aOccupationTypes[2]  = Array(3,'Prowadzę działalność gosp.',null);
	aOccupationTypes[3]  = Array(4,'Jestem emerytem',null);
	aOccupationTypes[4]  = Array(5,'Jestem rencistą',null);
	aOccupationTypes[5]  = Array(6,'Jestem rolnikiem',null);
	aOccupationTypes[6]  = Array(7,'Jestem osobą bezrobotną',null);
	aOccupationTypes[7]  = Array(8,'Pracuję w wolnym zawodzie',null);
	aOccupationTypes[8]  = Array(9,'Pracuję na kontrakcie',null);
	aOccupationTypes[9]  = Array(10,'Pracuję na umowę-zlecenie',null);
	aOccupationTypes[10] = Array(11,'Pracuję na umowę o dzieło',null);
	
var aEvidenceTypes = Array();
	aEvidenceTypes[0] = Array(1,'Nieokreślony','selected');
	aEvidenceTypes[1] = Array(2,'Oświadczenie',null);
	aEvidenceTypes[2] = Array(3,'Zaświadczenie',null);
	
var aContractTypes = Array();
	aContractTypes[0] = Array(1,'Brak danych','selected');
	aContractTypes[1] = Array(2,'Umowa na czas nieokreślony',null);
	aContractTypes[2] = Array(3,'Umowa na czas określony',null);

var aTaxTypes = Array();
	aTaxTypes[0] = Array(1,'Nieokreślony','selected');
	aTaxTypes[1] = Array(2,'Zasady ogólne',null);
	aTaxTypes[2] = Array(3,'Ryczatł',null);
	aTaxTypes[3] = Array(4,'Karta podatkowa',null);
	aTaxTypes[4] = Array(5,'Księga przychodów i rozchodów',null);

var aEmploymentForm = Array();		
	aEmploymentForm[0]  = new FormField('employment_new_data_','IdOccupationType','select','Wybierz rodzaj zatrudnienia','isDictionaryNotEmpty',null,null,null,aOccupationTypes);
	aEmploymentForm[1]  = new FormField('employment_new_data_','company_data_CompanyName','input/text','Nazwa firmy (zakładu pracy)','isNotEmpty',null,null,null,null);
	aEmploymentForm[2]  = new FormField('employment_new_data_','company_address_data_IdAddressType','input/hidden',null,'isDictionaryNotEmpty',null,null,null,null);
	aEmploymentForm[3]  = new FormField('employment_new_data_','company_address_data_Zip','input/text','Kod pocztowy','isZIP',null,null,null,6);
	aEmploymentForm[4]  = new FormField('employment_new_data_','company_address_data_City','input/text','Miejscowość','isCity',null,null,null,null);
	aEmploymentForm[5]  = new FormField('employment_new_data_','company_address_data_Street','input/text','Ulica, nr domu','isNotEmpty',null,null,null,null);
	aEmploymentForm[6]  = new FormField('employment_new_data_','company_address_data_PostOffice','input/text','Poczta','isCity',null,null,null,null);
	aEmploymentForm[7]  = new FormField('employment_new_data_','company_phone1_data_Number','input/text','Telefon zarejestrowany na firmę (lub do zakładu pracy)','isPhone',null,null,null,null);
	aEmploymentForm[8]  = new FormField('employment_new_data_','ContractBeginDate','date','Data podpisania umowy (rrrr-mm-dd)','checkDate',null,null,null,null);
	aEmploymentForm[9]  = new FormField('employment_new_data_','NettoIncome','input/text','Średni dochód NETTO','isNumber',0,null,null,null);
	aEmploymentForm[10] = new FormField('employment_new_data_','LastMonthIncome','input/text','Przychód (za ostatni miesiąc)','isNumber',0,null,null,null);
	aEmploymentForm[11] = new FormField('employment_new_data_','Profession','input/text','Wykonywany zawód','isNotEmpty',null,null,null,null);
	aEmploymentForm[12] = new FormField('employment_new_data_','IdContractType','select','Typ umowy','isDictionaryNotEmpty',null,null,null,aContractTypes);
	aEmploymentForm[13] = new FormField('employment_new_data_','ContractEndDate','date','Umowa ważna do dnia (rrrr-mm-dd)','checkDate',null,null,null,null);
	aEmploymentForm[14] = new FormField('employment_new_data_','IdEvidenceType','select','Dokument potwierdzający zatrudnienie','isDictionaryNotEmpty',null,null,null,aEvidenceTypes);
	aEmploymentForm[15] = new FormField('employment_new_data_','company_data_NIP','input/text','NIP','isNIP',null,null,13,null);
	aEmploymentForm[16] = new FormField('employment_new_data_','company_data_Regon','input/text','REGON','isRegon',null,null,20,null);
	aEmploymentForm[17] = new FormField('employment_new_data_','company_data_EKD','input/text','EKD lub rodzaj prowadzonej działalności','isNotEmpty',null,null,null,null);
	aEmploymentForm[18] = new FormField('employment_new_data_','company_data_EDGNumber','input/text','Numer wpisu do ewidencji działalności gops.','isNotEmpty',null,null,null,null);
	aEmploymentForm[19] = new FormField('employment_new_data_','company_data_EDGDate','date','Data rozpoczęcia działalności gosp. (rrrr-mm-dd)','checkDate',null,null,null,null);
	aEmploymentForm[20] = new FormField('employment_new_data_','company_data_IdTaxType','select','Sposób rozliczania podatkowego','isDictionaryNotEmpty',null,null,null,aTaxTypes);
	
var aFieldList = new Array();
	// wszystkie pola
	aFieldList[0]  = new Array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20);
	// wybierz opcję
	aFieldList[1]  = new Array(0);
	aFieldList[1][0] = 0;
	aFieldList[2]  = new Array(0,1,3,4,5,6,7,8,9,11,12,14);
	aFieldList[3]  = new Array(0,1,3,4,5,6,7,9,10,15,16,17,18,19,20);
	aFieldList[4]  = new Array(0,9);
	aFieldList[5]  = new Array(0,9);
	aFieldList[6]  = new Array(0,9);
	aFieldList[7]  = new Array();
	aFieldList[7][0] = 0;
	aFieldList[8]  = new Array(0,1,3,4,5,6,7,8,9,11,12,14);
	aFieldList[9]  = new Array(0,1,3,4,5,6,7,8,9,11,12,14);
	aFieldList[10] = new Array(0,1,3,4,5,6,7,8,9,11,12,14);
	aFieldList[11] = new Array(0,1,3,4,5,6,7,8,9,11,12,14);
	
var iContractEndDateFieldNo = 13;
	
function ClearFilter()
{
	var name ;
	for(var t=0; t < 13 ; t++)
	{
		name = 'filter_'+fieldsTab[t] ;
		if(document.getElementById(name))
			document.getElementById(name).value="";
	}

}
		
function UsersGroup(action,id)
{
	document.getElementById('page').value = action ;
	document.getElementById('editinguserid').value = id ;
	document.mForm.submit();
}

function FormForNeeUser(id)
{
	document.getElementById('newuserprofil_check').value = 'yes' ; 
	document.getElementById('page').value = 'formfornewuser' ;
	document.getElementById('editinguserid').value = id ;
	document.mForm.submit();
}

function SaveUserAccess()
{
	document.getElementById('change_user_access').value = 'yes' ; 
	document.mForm.submit();
}
		
function setPointer(theRow, RowNr, theAction)
{
    var theCells = null;

    var theDefaultClass = 'listTableRowLow';
    var thePointerClass = 'listTableRowHigh';
    var theMarkClass    = 'listTableRowMark';    

	switch(theAction)
	{
	  case "over" :
		  if(theRow.className != theMarkClass)
		    theRow.className = thePointerClass ;
	  break;
	  case "out" :
		  if(theRow.className != theMarkClass)
		    theRow.className = theDefaultClass ;
	  break;
	  case "click" :
		
		  if(theRow.className != theMarkClass)
		    theRow.className = theMarkClass ;
	      else theRow.className = thePointerClass ;
	  break;
	}
}

function PeopleListReload(f_action)
{
	document.mForm.action = f_action ; 
	document.mForm.submit();
}

function CloseDictionaryWindow(name)
{
	name = 'DictionaryWindow_'+name ;
	document.getElementById(name).style.visibility = 'hidden' ;
}

function OpenDictionaryWindow(name)
{
	name = 'DictionaryWindow_'+name ;
	document.getElementById(name).style.visibility = 'visible' ;
}

function AddNewTranslation(name)
{
	document.getElementById('dictionaryname').value = name;
	document.getElementById('dictionaryaction').value = 'add';
	document.mForm.action.value = '?module=proposal&page=firstform';
	document.mForm.submit();	
}

function DeleteDictionary(name)
{
	document.getElementById('dictionaryname').value = name;
	document.getElementById('dictionaryaction').value = 'delete';
	document.mForm.action.value = '?module=proposal&page=firstform';
	document.mForm.submit();		
}

function ShowDictionaryWindow(name,_obj,off_left, off_top)
{
    if (! off_left)
      off_left = 50;
    if (! off_top)
      off_top = 30;
      
	name = 'DictionaryWindow_'+name ;
    if (_obj)
    {
      document.getElementById(name).style.position = 'absolute' ;
      document.getElementById(name).style.left = (findPosX(_obj) - off_left) +'px' ;
      document.getElementById(name).style.top = (findPosY(_obj) - off_top) +'px' ;
	}
	document.getElementById(name).style.visibility = 'visible' ;
}

function CheckForm(name)
{
	document.getElementById('check').value = name;
	document.getElementById('page').value = name;
	document.mForm.submit();
}

//!!!!!!!!!!!!!!
//  popup management
//!!!!!!!!!!!!!

var CurrentEditWindow = '';

var StatusEdit = new Array('Obligation','Employment','SpouseEmployment','Property');
StatusEdit['Obligation'] = false;
StatusEdit['Employment'] = false;
StatusEdit['SpouseEmployment'] = false;
StatusEdit['Property'] = false;

var StatusNumber = new Array('Obligation', 'Employment','SpouseEmployment', 'Property');
StatusNumber['Obligation'] = -1;
StatusNumber['Employment'] = -1;
StatusNumber['SpouseEmployment'] = -1;
StatusNumber['Property'] = -1;

// definition of the fields in a popup div
var popupfields = new Array('ObligationWindow','EmploymentWindow','SpouseEmploymentWindow','PropertyWindow');
    popupfields['ObligationWindow'] = new Array('obligation_new_data_','IdType','IdBankName','MonthlyInterest','Description'); 
    popupfields['EmploymentWindow'] = new Array('employment_new_data_','IdOccupationType','company_data_CompanyName','company_address_data_Zip','company_address_data_PostOffice','company_address_data_Street','company_address_data_City','company_phone1_data_Number','WorkPeriod','NettoIncome','IdEvidenceType','company_data_NIP','company_data_Regon','company_data_EKD','LastYearIncome','ThisYearIncome');
    popupfields['SpouseEmploymentWindow'] = new Array('employment_new_data_','IdOccupationType','company_data_CompanyName','company_address_data_Zip','company_address_data_PostOffice','company_address_data_Street','company_address_data_City','company_phone1_data_Number','WorkPeriod','NettoIncome','IdEvidenceType','company_data_NIP','company_data_Regon','company_data_EKD','LastYearIncome','ThisYearIncome');
    popupfields['PropertyWindow'] = new Array('properties_new_data_','IdType','ApproximateValue','Description'); 

//definiotion of fields in form data section
var dataformfields = new Array('Obligations','Employment','SpouseEmployment','Property');
    dataformfields['Obligation'] = new Array('obligation_data_All','IdType','IdBankName','MonthlyInterest','Description'); 
    dataformfields['Employment'] = new Array('employment_data_All','IdOccupationType','company_data_CompanyName','company_address_data_Zip','company_address_data_PostOffice','company_address_data_Street','company_address_data_City','company_phone1_data_Number','WorkPeriod','NettoIncome','IdEvidenceType','company_data_NIP','company_data_Regon','company_data_EKD','LastYearIncome','ThisYearIncome');
    dataformfields['SpouseEmployment'] = new Array('spouse_employment_data_All','IdOccupationType','company_data_CompanyName','company_address_data_Zip','company_address_data_PostOffice','company_address_data_Street','company_address_data_City','company_phone1_data_Number','WorkPeriod','NettoIncome','IdEvidenceType','company_data_NIP','company_data_Regon','company_data_EKD','LastYearIncome','ThisYearIncome');
    dataformfields['Property'] = new Array('properties_data_All','IdType','ApproximateValue','Description'); 
// must be the sam number of fields in popup and in formdata

function ShowEditWindow(windowname,_obj,off_left,off_top) {
	//Obligation 
	if (! off_left) off_left = 50;
	if (! off_top) off_top = 30;
	
	if (windowname == 'SpouseEmployment') winname = 'Employment';
	else winname = windowname;
	
	if (_obj) {
		document.getElementById(winname+'Window').style.position = 'absolute';
		document.getElementById(winname+'Window').style.left = (findPosX(_obj) - off_left) +'px';
		document.getElementById(winname+'Window').style.top = (findPosY(_obj) - off_top) +'px';
	}
	if(document.getElementById(winname+'Window').style.visibility == 'hidden')
		document.getElementById(winname+'Window').style.visibility = 'visible';
	else 
		document.getElementById(winname+'Window').style.visibility = 'hidden';
}

function ClearEditWindow(windowname) {
  for (i=1; i< popupfields[windowname+'Window'].length; i++)
  {
    if (document.getElementById(popupfields[windowname+'Window'][0]+popupfields[windowname+'Window'][i])!= null)
//      alert(popupfields[windowname+'Window'][0]+popupfields[windowname+'Window'][i]);
//    alert(document.getElementById(popupfields[windowname+'Window'][0]+popupfields[windowname+'Window'][i]));
    document.getElementById(popupfields[windowname+'Window'][0]+popupfields[windowname+'Window'][i]).value = '';
  }
}

function FillEditWindow(oblNr,windowname) {
  for (var i=1; i< popupfields[windowname+'Window'].length; i++)
  {
//    alert(popupfields[windowname+'Window'][0]+popupfields[windowname+'Window'][i]);
//    alert(dataformfields[windowname][0]+'['+oblNr+']'+'['+dataformfields[windowname][i]+']');
    document.getElementById(popupfields[windowname+'Window'][0]+popupfields[windowname+'Window'][i]).value =  
    document.getElementById(dataformfields[windowname][0]+'['+oblNr+']'+'['+dataformfields[windowname][i]+']').value;
  }
}
function UpdateDataFields(oblNr,windowname) {
  for (var i=1; i< popupfields[windowname+'Window'].length; i++) {
    document.getElementById(dataformfields[windowname][0]+'['+oblNr+']['+dataformfields[windowname][i]+']').value =
    document.getElementById(popupfields[windowname+'Window'][0]+popupfields[windowname+'Window'][i]).value ; 
//    document.getElementById('td_obligation_data_All['+oblNr+']['+dataformfields['Obligations'][i]+']').innerHTML = 
    document.getElementById(popupfields[windowname+'Window'][0]+popupfields[windowname+'Window'][i]).value;
    document.getElementById('td_'+dataformfields[windowname][0]+'['+oblNr+']['+dataformfields[windowname][i]+']').innerHTML = 
    document.getElementById(popupfields[windowname+'Window'][0]+popupfields[windowname+'Window'][i]).value;
  }
  ClearEditWindow(windowname);
  ShowEditWindow(windowname);  

  StatusEdit[windowname]= false;
  StatusNumber[windowname] = -1;
}

function EditData(oblNr,windowname) {
  CurrentEditWindow = windowname;
//  alert(CurrentEditWindow);
  
  ClearEditWindow(windowname);
  FillEditWindow(oblNr,windowname);
  ShowEditWindow(windowname);  

  StatusEdit[windowname]= true;
  StatusNumber[windowname] = oblNr;
}

function AddData(windowname) {
//	alert('add'+windowname);
	document.getElementById('add'+windowname).value = 'yes';
	document.mForm.submit();
}

function DeleteData(position,windowname) {	
	document.getElementById('delete'+windowname).value = position ;
	document.getElementById('doDelete'+windowname).value ='yes';
	document.mForm.submit();	
}

function ShowEmploymentWindow(prefix,_obj,off_left,off_top)
{
    if (! off_left)
      off_left = 50;
    if (! off_top)
      off_top = 30;
      
    CurrentEditWindow = prefix;

    if (_obj)
    {
      document.getElementById('EmploymentWindow').style.position = 'absolute' ;
      document.getElementById('EmploymentWindow').style.left = (findPosX(_obj) - off_left) +'px' ;
      document.getElementById('EmploymentWindow').style.top = (findPosY(_obj) - off_top) +'px' ;
	}

	if(document.getElementById('EmploymentWindow').style.visibility == 'hidden')
		document.getElementById('EmploymentWindow').style.visibility = 'visible' ;
	else 
		document.getElementById('EmploymentWindow').style.visibility = 'hidden' ;
}

function AddEmployment()
{
	document.getElementById('addemployment').value = 'yes';
	document.mForm.submit();
}

function DeleteEmployment(position)
{	
	document.getElementById('deleteemployment').value = position ;
	document.getElementById('dodeleteemployment').value ='yes';
	ClearEditWindow('Employment')
	document.mForm.submit();	
}

function set_hour(obj, hour, min)
{
 obj.value = ''+hour+':'+min;
}

function show_hour(hour_obj, min_obj, hour)
{

//   alert(hour.value);
   if (hour.value != "")
   {
     hour_obj.value = hour.value.substr(0,2);
     min_obj.value = hour.value.substr(3,2);
   }
//   alert(hour.value.substr(0,2)+" "+hour.value.substr(3,2));
}

function PeopleListSelectAllCheckBox()
{
	for (i=0;i< document.mForm.elements.length;i++) 
	{
		if(document.mForm.elements[i].type=='checkbox' && document.mForm.elements[i].name == 'people_list_checkbox[]')
		{
			document.mForm.elements[i].checked = true;
		}
		
	}  
}


function PeopleListUnselectAllCheckBox()
{
	for (i=0;i< document.mForm.elements.length;i++) 
	{
		if(document.mForm.elements[i].type=='checkbox' && document.mForm.elements[i].name == 'people_list_checkbox[]')
		{
			document.mForm.elements[i].checked = false;
		}
		
	}  
}

function PeopleListReverseCheckBox()
{
	for (i=0;i< document.mForm.elements.length;i++) 
	{
		if(document.mForm.elements[i].type=='checkbox' && document.mForm.elements[i].name == 'people_list_checkbox[]')
		{
			if(document.mForm.elements[i].checked)
				document.mForm.elements[i].checked = false;
			else 
				document.mForm.elements[i].checked = true ; 
		}
		
	}  
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function validateForm(page)
{
	var errors_list = '';

//	if (! isName(document.mForm.people_data_PeopleName,''))
//		errors_list += ' Proszę podać imię. \n';
//	if (! isName(document.mForm.people_data_Surname,''))
//		errors_list += ' Proszę podać nazwisko. \n';
//	if (! isEmail(document.mForm.otherContact1_data_Value,''))
//		errors_list += ' Proszę podać e-mail. \n';
//	if (! isCity(document.mForm.address_data_City,''))
//		errors_list += ' Proszę podać miejscowość. \n';
//	if (! isPhone(document.mForm.phone1_data_Number,''))
//		errors_list += ' Proszę podać telefon kontaktowy. \n';
//	if (! isName(document.mForm.vehicle_data_Name,''))
//		errors_list += ' Proszę podać markę pojazdu. \n';
//	if (! isNumber(document.mForm.vehicle_data_PriceBrutto,''))
//		errors_list += ' Proszę podać szacunkową cenę pojazdu. \n';
//	if (! isNumber(document.mForm.vehicle_data_ProductionYear,''))
//		errors_list += ' Proszę podać rocznik. \n';
//	if (! isNumber(document.mForm.product_data_Value,''))
//		errors_list += ' Proszę podać szacunkową kwotę kredytu. \n';

	if (errors_list != '')
	{
		alert(' Proszę uzupełnić następujące dane: \n'+ errors_list)
	}
	else
	{
		if (CheckAcceptation()) CheckForm(page);
	}
	return errors_list =='';
}

function CheckAcceptation()
{
	if ((! document.mForm.accept.checked) && (document.mForm.accept.value != 't'))
	{
		alert(' Przed wyslaniem musisz zaakceptowac regulamin. \n');
		return  false;
	}
	else return true;
}

function ShowSpouseDivs(_elem)
{
  if (_elem.value == '2')
  {
    document.getElementById('SpouseEmploymentDiv').style.display = 'block';
    document.getElementById('SpouseDiv').style.display = 'block';
  }
  else
  {
    document.getElementById('SpouseEmploymentDiv').style.display = 'none';
    document.getElementById('SpouseDiv').style.display = 'none';
  }
}

function showSpouseData()
{
	if(document.getElementById('spouse').value == '2')
	{
		document.getElementById('SpouseDiv').style.display = 'block' ;
		document.getElementById('SpouseEmploymentDiv').style.display = 'block';
	}
	else
	{
		document.getElementById('SpouseDiv').style.display = 'none' ;
		document.getElementById('SpouseEmploymentDiv').style.display = 'none';
	}
	ClearEditWindow('Employment');
}

function validateEmploymentForm(aFieldDefinitions,aFieldList,fieldId) {
	var errors_list = '';
	var num = document.getElementById(fieldId).value;
	var formularz = document.forms.mForm;
	
	SetEmploymentDates();
	var list = aFieldList[num];
	if(list instanceof Array) {
		for(var i=0; i<list.length; i++) {
			if(!aFieldDefinitions[list[i]].validateField()) errors_list += aFieldDefinitions[list[i]].label+'\n';
		}
	}
	else {
		if(!aFieldDefinitions[list].validateField()) errors_list += aFieldDefinitions[list].label+'\n';
	}
	
	if (errors_list != '') {
		alert(' Proszę uzupełnić następujące dane: \n'+ errors_list)
	}
	else {
//		if (CheckAcceptation()) CheckForm(page);
//		alert(' Dziękuję za uzupełnienie wszystkich wymaganych pól');
//		ClearEditWindow('Employment');
		 (StatusEdit[CurrentEditWindow])? UpdateEmploymentDataFields(StatusNumber[CurrentEditWindow],CurrentEditWindow):AddData(CurrentEditWindow);
	}
	
	return errors_list =='';
}

function ResetForm(name) {
	var formularz = document.getElementById(name);
	
	employmentEdit = false;
	for(var i=0; i<aEmploymentForm.length; i++) {
		var tmp = document.getElementById(aEmploymentForm[i].prefix+aEmploymentForm[i].name);
		if(aEmploymentForm[i].type == 'select') {
			tmp.selectedIndex = 0;
		}
		else if(aEmploymentForm[i].type != 'input/hidden') {
			tmp.value = '';
		}
	}
}

function FillEmploymentForm(optionNumber,name,prefix) {
	for(var i=0; i<aEmploymentForm.length; i++) {
		var tmp = document.getElementById(aEmploymentForm[i].prefix+aEmploymentForm[i].name);
		var employmentFieldList = document.getElementById(prefix+'employment_data_All['+optionNumber+']['+aEmploymentForm[i].name+']');
		if(aEmploymentForm[i].type == 'select') {
			if(employmentFieldList.value) tmp.value = employmentFieldList.value;
		}
		else if(aEmploymentForm[i].type == 'date') {
			if(employmentFieldList.value) tmp.value = employmentFieldList.value;
			setDate(aEmploymentForm[i].prefix+aEmploymentForm[i].name,aEmploymentForm[i].prefix+aEmploymentForm[i].name+'_year',aEmploymentForm[i].prefix+aEmploymentForm[i].name+'_month',aEmploymentForm[i].prefix+aEmploymentForm[i].name+'_day');
		}
		else if(aEmploymentForm[i].type != 'input/hidden') {
			if(employmentFieldList.value) tmp.value = employmentFieldList.value;
		}
	}
}

function SetEmploymentDates() {
	for(var i=0; i<aEmploymentForm.length; i++) {
		if(aEmploymentForm[i].type == 'date') {
			getDate(aEmploymentForm[i].prefix+aEmploymentForm[i].name+'_year',aEmploymentForm[i].prefix+aEmploymentForm[i].name+'_month',aEmploymentForm[i].prefix+aEmploymentForm[i].name+'_day',aEmploymentForm[i].prefix+aEmploymentForm[i].name);
		}
	}
}

function UpdateEmploymentDataFields(oblNr,windowname) {
	var tmp ='';
	var tdEmploymentField = '';
	var employmentField = '';
	var prefix = '';
	
	if(windowname == 'SpouseEmployment') prefix = 'spouse_';
	
	// czyszczenie poprzednich wartości
	for(var i=0; i<aEmploymentForm.length; i++) {
		tmp = document.getElementById(aEmploymentForm[i].prefix+aEmploymentForm[i].name);
		tdEmploymentField = document.getElementById('td_'+prefix+'employment_data_All['+oblNr+']['+aEmploymentForm[i].name+']');
		employmentField   = document.getElementById(      prefix+'employment_data_All['+oblNr+']['+aEmploymentForm[i].name+']');

		if(aEmploymentForm[i].type == 'select') {
			employmentField.value = 0;
			tdEmploymentField.innerHTML = '';
		}
		else if(aEmploymentForm[i].type != 'input/hidden') {
//			alert('td_employment_data_All['+oblNr+']['+aEmploymentForm[i].name+']');
			employmentField.value = null;
			tdEmploymentField.innerHTML = '';
		}
	}
	
	// ustawianie poprawnych wartości, wyświetlanie tekstu
	for(var i=0; i<aEmploymentForm.length; i++) {
		tmp = document.getElementById(aEmploymentForm[i].prefix+aEmploymentForm[i].name);
		tdEmploymentField = document.getElementById('td_'+prefix+'employment_data_All['+oblNr+']['+aEmploymentForm[i].name+']');
		employmentField   = document.getElementById(      prefix+'employment_data_All['+oblNr+']['+aEmploymentForm[i].name+']');

		if(aEmploymentForm[i].type == 'select') {
			employmentField.value = tmp.selectedIndex+1;
			if(tmp.selectedIndex > 1) tdEmploymentField.innerHTML = aEmploymentForm[i].options[tmp.selectedIndex][1]+'<br />';
			else {
				if(employmentField.value > 1) tdEmploymentField.innerHTML = aEmploymentForm[i].options[tmp.selectedIndex][1];
				else tdEmploymentField.innerHTML = null;
			}
		}
		else if(aEmploymentForm[i].type == 'date') {
			employmentField.value = tmp.value;
			if((tmp.value) && (i > 6)) {
//				alert(aEmploymentForm[i].name+" "+i);
				tdEmploymentField.innerHTML = tmp.value+'<br />';
			}
			else if(tmp.disabled == false) tdEmploymentField.innerHTML = tmp.value;
		}
		else if(aEmploymentForm[i].type != 'input/hidden') {
			employmentField.value = tmp.value;
			if((tmp.value) && (i > 6)) {
//				alert(aEmploymentForm[i].name+" "+i);
				tdEmploymentField.innerHTML = tmp.value+'<br />';
			}
			else tdEmploymentField.innerHTML = tmp.value;
		}
	}

  ClearEditWindow(windowname);
  ShowEditWindow(windowname);  

  StatusEdit[windowname]= false;
  StatusNumber[windowname] = -1;
}

function EnableFields(aFieldDefinitions,aFieldList,num) {
	var fieldName = "";
	
	for (var i=0; i<aFieldList[0].length;i++) {
		aFieldDefinitions[aFieldList[0][i]].disableField();
	}
	
	fieldName = "";
	for (var i=0; i<aFieldList[num].length;i++) {
		aFieldDefinitions[aFieldList[num][i]].enableField();
	}
}

function EditEmploymentData(oblNr,windowname) {
	CurrentEditWindow = windowname;
//	alert(CurrentEditWindow);
	var prefix = '';
	if(windowname == 'SpouseEmployment') prefix = 'spouse_';
	
	ClearEditWindow(windowname);
	FillEmploymentForm(oblNr,windowname,prefix);
	ShowEditWindow(windowname);  
	
	StatusEdit[windowname]= true;
	StatusNumber[windowname] = oblNr;
}

function EnableField(aFieldDefinitions,number) {
	aFieldDefinitions[number].enableField();
}

function DisableField(aFieldDefinitions,number) {
	aFieldDefinitions[number].disableField();
}

function SetContractEndDateField(aFieldDefinitions,fieldNumber,optionNumber) {
	if(optionNumber == 3) EnableField(aFieldDefinitions,fieldNumber);
	else DisableField(aFieldDefinitions,fieldNumber);
	return true;
}

function getDate(year,month,day,field) {
	var doc = document;
	doc.getElementById(field).value = doc.getElementById(year).value+'-'+doc.getElementById(month).value+'-'+doc.getElementById(day).value;
	return true;
}

function setDate(field,year,month,day) {
	var aStr = document.getElementById(field).value;
	var re = new RegExp("^[0-9]{1,4}[\.-]{1}[0-9]{1,2}[\.-]{1}[0-9]{1,2}$");
	var ret = re.test(aStr);
	if (!ret) return false;
	
	var DateArr = aStr.split(/-/);
	var tmp = document.getElementById(year);
	for(var i = 0; i < tmp.options.length; i++)
		if(DateArr[0].match(tmp.options[i].value)) {
			tmp.options[i].selected = true;
			tmp.selectedIndex = i;
			tmp.value = tmp.options[i].value;
		}
		else {
			tmp.options[i].selected = false;
		}
	tmp = document.getElementById(month);
	for(var i = 0; i < tmp.options.length; i++)
		if(DateArr[1].match(tmp.options[i].value)) {
			tmp.options[i].selected = true;
			tmp.selectedIndex = i;
			tmp.value = tmp.options[i].value;
		}
		else {
			tmp.options[i].selected = false;
		}
	tmp = document.getElementById(day);
	for(var i = 0; i < tmp.options.length; i++)
		if(DateArr[2].match(tmp.options[i].value)) {
			tmp.options[i].selected = true;
			tmp.selectedIndex = i;
			tmp.value = tmp.options[i].value;
		}
		else {
			tmp.options[i].selected = false;
		}
	return true;
}

function checkYear(year) {
	if((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))) return true;
	else return false;
}

var days = Array(0,31,28,31,30,31,30,31,31,30,31,30,31);

function checkDaysInMonth(year,month) {
	if(checkYear(year) && (month == 2)) return days[month+1];
	else return days[month];
}
					
/**
 * checks if given value matches expression:
 * "^([0-9]{2})$" and checkcs if number is between <1 and 31>
 * @param _input = input text field
 */
function isDay(_input) {
	var str = _input.value;
	
	if (str == "") return false;
	
	var re = new RegExp("^([0-9]{2})$");
	var ret = re.test(str);
	
	if(!ret || str < 1 || str > 31) return false;
	else return true;
}

/**
 * checks if given value matches expression:
 * "^([0-9]{2})$" and checkcs if number is between <1 and 12>
 * @param _input = input text field
 */
function isMonth(_input) {
	var str = _input.value;
	
	if (str == "") return false;
	
	var re = new RegExp("^([0-9]{2})$");
	var ret = re.test(str);
	
	if(!ret || str < 1 || str > 12) return false;
	else return true
}

function isDate(name) {
	var aStr = document.getElementById(name).value;

	var re = new RegExp("^[0-9]{1,4}[\.-]{1}[0-9]{1,2}[\.-]{1}[0-9]{1,2}$");
	var ret = re.test(aStr);
	if (!ret) return false;
	
	var DateArr = aStr.split(/\./);
	if(DateArr[1] == null) DateArr = aStr.split(/-/);
	if(DateArr[0] < 1900 || DateArr[0] > 2030) return false;
	if (DateArr[1] < 1 || DateArr[1]>12) return false;
	
	if (checkYear(DateArr[0]) && DateArr[1] == 2) days[2] = 29;
	if (DateArr[2] < 1 || DateArr[2]>days[DateArr[1]]) return false;
	
	return true;
}
