	function getElementCoo(obj) {
		var x=0;
		var y=0;

		var _obj=obj;

		while(obj) {
			x=x+obj.offsetLeft;
			y=y+obj.offsetTop;
			obj=obj.offsetParent;
		}
		return new Array(x,y);
	}

	/* format cen */
	function InputPrice( Value )
	{
		if( Value == '' || Value == 'undefined' || Value == null )
			return 0;
			
		Output = '';
		for ( var i = 0; i < Value.length; i++ )
			if ( Value.charAt(i) != ' ' )
				Output += Value.charAt(i);
				
		if ( isNaN ( parseInt ( Output ) ) )
			return 0;
		
		return parseInt ( Output );
	}
	
	function OutputPrice( Value, noCurrency )
	{	
		ThousandsSep	= ' ';
		
		if( noCurrency )
			CurrencySymbol	= '';
		else
			CurrencySymbol	= 'Kč';
		
		if ( Value == 0 )
			return '0 ' + CurrencySymbol;
			
		TempValue = Math.round ( Value );
		
		Output = '';
		while ( TempValue > 0 )
		{
			Remainder	= TempValue % 1000;
			TempValue	= ( TempValue - Remainder ) / 1000;
			
			if ( TempValue > 0 )
			{
				if ( Remainder < 10 )
					Output = '00' + Remainder + ThousandsSep + Output;
				else if ( Remainder < 100 )
					Output = '0' + Remainder + ThousandsSep + Output;
				else
					Output = Remainder + ThousandsSep + Output;
			}
			else
				Output = Remainder + ThousandsSep + Output;
		}
		
		return Output + CurrencySymbol;
	}

	function ShowHelp( elementName, icon )
	{
	
		var iconCoo=getElementCoo(icon);
		var help_box=document.getElementById( elementName );
		
		//help_box.style.left=(iconCoo[0]+10)+"px";
		//help_box.style.top=(iconCoo[1]+10)+"px";
		help_box.style.display='block';

	}
	function HideHelp( elementName )
	{
		document.getElementById( elementName ).style.display='none';
	}

	/* Request profi */
	function changeDataProfi()
	{	
		$("#btnCalcSubmit").attr("disabled", 1);
		//typ splacni 1 - anuitni, 2 - progres, 3 - degres
		LoanMaxProgress();
		LoanMaxLoanMaxPercentage();
		
		IsRightLoan( null, false );
		LoanVsPrice();
		
		RenderFixTimeProfi();
		RenderSelectOptionsProfi();
		
		WriteLoanRateProfi();
		
		SetRightFormatProfi();
		$("#btnCalcSubmit").attr("disabled", 0);
		return null;
	}
	
	function getTypSplaceni()
	{
		if( isSelected('typSplaceni1') )
			return 1;
			
		if( isSelected('typSplaceni2') )
			return 2;

		if( isSelected('typSplaceni3') )
			return 3;
		
		return 1;
	}
	
	/* Request small */
	function changeDataSmall()
	{
		LoanVsPriceSmall( false );
		IsRightLoan( false, true );

		percentage = CountPercentageSmall();
		WritePercentage( percentage );
	
		//SetRightFormatSmall();
		return null;
	}
	
	/* Request */
	function ChangeData( radioValue )
	{
		
		LoanMaxLoanMaxPercentage();
		
		IsRightLoan( null, false );
		
		LoanVsPrice();

		percentage = CountPercentage();
		WritePercentage( percentage );
		
		rp = roundedPercentage = GetRoundedPercentage();
		if( isChecked( 'us' ) )
			rp = 'us';
			
		ratesArray = GetArrayValuesByPercentage( rp );
		
		WriteCurrentLoanRate( ratesArray );
		
		WriteFixTime( ratesArray, radioValue );
		
		RenderSelectOptions();
		
		SetRightFormatSmall();
		return null;
	}
	
	/* Request Bonity */
	function changeDataBonity()
	{
		var typDomacnosti 	= document.getElementById( 'typDomacnosti' );
		var pocetClenu 		= document.getElementById( 'min4' );
		
		if( typDomacnosti.value < 3 && pocetClenu.value < 2 )
			pocetClenu.value = 2;
	
		WriteEarning( false );
		WriteRelease( false );
		WriteMin();
		
		SetRightInputFormatForTableElID( 'earningTbl' );
		SetRightInputFormatForTableElID( 'releaseTbl' );
		
		document.getElementById( 'releaseAll' ).innerHTML = OutputPrice( sumRelease() );
		
	}
	
	/* HYPO ONLINE */
	function changeHypoOnline()
	{
		var typDomacnosti 	= document.getElementById( 'typDomacnosti' );
		var pocetClenu 		= document.getElementById( 'min4' );
		
		if( typDomacnosti.value < 4 && pocetClenu.value < 2 )
			pocetClenu.value = 2;
			
		WriteEarning( true );
		WriteRelease( true );
		WriteMin();
		
		SetRightInputFormatForTableElID( 'earningTbl', true );
		SetRightInputFormatForTableElID( 'releaseTbl', true );
		
		document.getElementById( 'releaseAll' ).innerHTML = OutputPrice( sumRelease() );
	}
	
	function sumEarning()
	{
		var	calcRent1 = InputPrice( document . getElementById('calcRent1').value );
		var calcRent2 = InputPrice( document . getElementById('calcRent2').value );
		var calcRent3 = InputPrice( document . getElementById('calcRent3').value );
		var calcRent4 = InputPrice( document . getElementById('calcRent4').value );
		
		var calcRentAll = document . getElementById('calcRentAll');
		
		if( calcRent1 == '' )
			calcRent1 = 0;
		
		if( calcRent2 == '' )
			calcRent2 = 0;
		
		if( calcRent3 == '' )
			calcRent3 = 0;
			
		if( calcRent4 == '' )
			calcRent4 = 0;
			
		sumRent = parseInt( calcRent1 ) + parseInt( calcRent2 ) + parseInt( calcRent3 ) + parseInt( calcRent4 );
		
		return parseInt( sumRent );
	}
	
	function sumMinimum()
	{
		var min0 = InputPrice( document . getElementById('min0').value );
		var min1 = InputPrice( document . getElementById('min1').value );
		var min3 = InputPrice( document . getElementById('min3').value );
		var min4 = InputPrice( document . getElementById('min4').value );

		//celkem clenu
		var sumMemebers = parseInt( min0 ) + parseInt( min1 ) + parseInt( min3 ) + parseInt( min4 );
	
		//vydej domacnosti dle poctu clenu
		switch( sumMemebers )
		{
			case 0:
			case 1:
				min_domacnost = ziv_minima['domacnost_1cl'];
			break
			
			case 2:
				min_domacnost = ziv_minima['domacnost_2cl'];
			break;
			
			case 3:
				min_domacnost = ziv_minima['domacnost_3cl'];
			break;
			case 4:
				min_domacnost = ziv_minima['domacnost_4cl'];
			break;
			
			default:
			case 5:
				min_domacnost = ziv_minima['domacnost_5cl'];
			break;
		}
		
		
		//vypis vydaje domacnosti
		document . getElementById('minDomacnost').innerHTML = OutputPrice( min_domacnost );
				
		//jednotlivec 
		if( sumMemebers == 1 ) {
			sumMin =  min_domacnost + ziv_minima['jednotlivec'];
		} else {
			//vydej dospelych
			if( min4 > 1 )
				sumAdults = ( parseInt( min4 ) - 1 ) * ziv_minima['dospeli_dalsi'] + ziv_minima['dospeli_prvni'];
			else
				sumAdults = ziv_minima['dospeli_prvni'];
			
			//vydej 0 - 6
			sumZeroToSix = parseInt( min0 ) * ziv_minima['dite_0_6'];
			
			//vydej 6 - 15
			sumSixToFifteen = parseInt( min1 ) * ziv_minima['dite_6_15'];
			
			//vydej 15 - 26
			sumFifteenToTwentySix = parseInt( min3 ) * ziv_minima['dite_15_26'];
			
			
			//celkove vydaje
			sumMin = min_domacnost + sumAdults + sumZeroToSix + sumSixToFifteen + sumFifteenToTwentySix;
		}
		
		return sumMin;
	}
	
	function sumRelease()
	{
		celkemCelkem = new Array( 'calcRelease1_4', 'calcRelease2_4', 'calcRelease3_4', 'calcRelease4_4',
					'calcRelease1_3', 'calcRelease2_3', 'calcRelease3_3', 'calcRelease4_3',
					'calcRelease1_2', 'calcRelease2_2', 'calcRelease3_2', 'calcRelease4_2',
					'calcRelease1_1', 'calcRelease2_1', 'calcRelease3_1', 'calcRelease4_1' );
		
		sumReleaseQnt = getSumByArray( celkemCelkem ) + 150;

		return sumReleaseQnt + sumMinimum();
	}
	
	function WriteEarning( noCurrency )
	{
		/* ROWS */
		fstRow = new Array( 'calcRent1_1', 'calcRent1_2', 'calcRent1_3', 'calcRent1_4' );
		writeSumToEl( getSumByArray( fstRow ), 'calcRent1_celkem', noCurrency );
		
		secRow = new Array( 'calcRent2_1', 'calcRent2_2', 'calcRent2_3', 'calcRent2_4' );
		writeSumToEl( getSumByArray( secRow ), 'calcRent2_celkem', noCurrency );
		
		thdRow = new Array( 'calcRent3_1', 'calcRent3_2', 'calcRent3_3', 'calcRent3_4' );
		writeSumToEl( getSumByArray( thdRow ), 'calcRent3_celkem', noCurrency );
		
		forRow = new Array( 'calcRent4_1', 'calcRent4_2', 'calcRent4_3', 'calcRent4_4' );
		writeSumToEl( getSumByArray( forRow ), 'calcRent4_celkem', noCurrency );
		
		/* COLS */
		fstCol = new Array( 'calcRent1_1', 'calcRent2_1', 'calcRent3_1', 'calcRent4_1' );
		writeSumToEl( getSumByArray( fstCol ), 'calcRentCelkem_1', noCurrency );
		
		secCol = new Array( 'calcRent1_2', 'calcRent2_2', 'calcRent3_2', 'calcRent4_2' );
		writeSumToEl( getSumByArray( secCol ), 'calcRentCelkem_2', noCurrency );
		
		thdCol = new Array( 'calcRent1_3', 'calcRent2_3', 'calcRent3_3', 'calcRent4_3' );
		writeSumToEl( getSumByArray( thdCol ), 'calcRentCelkem_3', noCurrency );
		
		forCol = new Array( 'calcRent1_4', 'calcRent2_4', 'calcRent3_4', 'calcRent4_4' );
		writeSumToEl( getSumByArray( forCol ), 'calcRentCelkem_4', noCurrency );
		
		/* FULL SUM */
		celkemCelkem = new Array( 'calcRent1_4', 'calcRent2_4', 'calcRent3_4', 'calcRent4_4',
					'calcRent1_3', 'calcRent2_3', 'calcRent3_3', 'calcRent4_3',
					'calcRent1_2', 'calcRent2_2', 'calcRent3_2', 'calcRent4_2',
					'calcRent1_1', 'calcRent2_1', 'calcRent3_1', 'calcRent4_1' );
		
		writeSumToEl( getSumByArray( celkemCelkem ), 'calcRentCelkem_Celkem', noCurrency );
		
		return null;
	}
	
	function getSumByArray( elIDsArr )
	{
		sumQnt = 0;
		
		for( k in elIDsArr )
		{
		
			el = document.getElementById( elIDsArr[k] );
			
			if( el != null )
				sumQnt += InputPrice( el.value );
				
				
		}
		
		return sumQnt;
	}
	
	function writeSumToEl( sumQnt, elID, noCurrency )
	{
		el = document.getElementById( elID );
		
		if( el == null )
			return false;
		
		el.innerHTML = OutputPrice( sumQnt, noCurrency );
	}
	
	
	function WriteMin()
	{
		document . getElementById('minAll') . innerHTML = OutputPrice( sumMinimum() );
		return null;
	}
	
	function WriteRelease( noCurrency )
	{	
		/* ROWS */
		fstRow = new Array( 'calcRelease1_1', 'calcRelease1_2', 'calcRelease1_3', 'calcRelease1_4' );
		writeSumToEl( getSumByArray( fstRow ), 'calcRelease1_celkem', noCurrency );
		
		secRow = new Array( 'calcRelease2_1', 'calcRelease2_2', 'calcRelease2_3', 'calcRelease2_4' );
		writeSumToEl( getSumByArray( secRow ), 'calcRelease2_celkem', noCurrency );
		
		thdRow = new Array( 'calcRelease3_1', 'calcRelease3_2', 'calcRelease3_3', 'calcRelease3_4' );
		writeSumToEl( getSumByArray( thdRow ), 'calcRelease3_celkem', noCurrency );
		
		writeSumToEl( 150, 'calcRelease4_celkem', noCurrency );
		
		/* COLS */
		fstCol = new Array( 'calcRelease1_1', 'calcRelease2_1', 'calcRelease3_1', 'calcRelease4_1' );
		writeSumToEl( getSumByArray( fstCol ), 'calcReleaseCelkem_1', noCurrency );

		
		secCol = new Array( 'calcRelease1_2', 'calcRelease2_2', 'calcRelease3_2', 'calcRelease4_2' );
		writeSumToEl( getSumByArray( secCol ), 'calcReleaseCelkem_2', noCurrency );
		
		thdCol = new Array( 'calcRelease1_3', 'calcRelease2_3', 'calcRelease3_3', 'calcRelease4_3' );
		writeSumToEl( getSumByArray( thdCol ), 'calcReleaseCelkem_3', noCurrency );
		
		forCol = new Array( 'calcRelease1_4', 'calcRelease2_4', 'calcRelease3_4', 'calcRelease4_4' );
		writeSumToEl( getSumByArray( forCol ), 'calcReleaseCelkem_4', noCurrency );
		
		/* FULL SUM */
		celkemCelkem = new Array( 'calcRelease1_4', 'calcRelease2_4', 'calcRelease3_4', 'calcRelease4_4',
					'calcRelease1_3', 'calcRelease2_3', 'calcRelease3_3', 'calcRelease4_3',
					'calcRelease1_2', 'calcRelease2_2', 'calcRelease3_2', 'calcRelease4_2',
					'calcRelease1_1', 'calcRelease2_1', 'calcRelease3_1', 'calcRelease4_1' );
		
		writeSumToEl( getSumByArray( celkemCelkem ) + 150, 'calcReleaseCelkem_Celkem', noCurrency );
		
		return null;
	}
	
	function LoanMaxLoanMaxPercentage()
	{	
		if( ! isChecked('us') && ! isSelected('us')  )
			return null;

		var loan	= document.getElementById('calcLoan');		
		var price 	= document.getElementById('calcPrice');
		
		loanValue = parseInt( InputPrice( loan.value ) );
		priceValue = parseInt( InputPrice( price.value ) );	
		
		
		maxLoan = 5000000;
		if( loanValue > maxLoan )
		{
			alert( 'Maximální výše úvěru je ' + maxLoan + ' Kč' );
		
			loan.value = OutputPrice( maxLoan );
		}

		if( GetRoundedPercentage() > 70 )
		{
			alert( 'Maximální výše úvěru je 70%' );
			maxLoan = Math.round( priceValue / 100 * 70 );
			loan.value = OutputPrice( maxLoan );
		}
		
		return null;
	}
	
	function LoanMaxProgress()
	{
		var loan	= document.getElementById('calcLoan');		
		var price 	= document.getElementById('calcPrice');
		
		loanValue = parseInt( InputPrice( loan.value ) );
		priceValue = parseInt( InputPrice( price.value ) );	
		
		if( getTypSplaceni() != 2 )	
			return null;
		
		maxLoan = 3000000; 
		if( loanValue > maxLoan )
		{
			alert( 'Maximální výše úvěru je ' + maxLoan + ' Kč' );
		
			loan.value = OutputPrice( maxLoan );
		}
		
		return null;
	}

	/* Percentage */					
	function CountPercentage()
	{	
		var formName		= document.getElementById( 'calcForm' );
		var cenaNemovitosti = InputPrice( formName.calcPrice.value );
		var vyseUveru 		= InputPrice( formName.calcLoan.value );
		var percentage		= 0;
													
		if( vyseUveru > 0 && cenaNemovitosti > 0 )
			percentage = Math.round( vyseUveru * 100 / cenaNemovitosti );
		
		return Math.round( percentage );		
	}

	function CountPercentageSmall()
	{	
		var cenaNemovitosti = InputPrice( document.getElementById( "calcPrice") .value );
		var vyseUveru 		= InputPrice( document.getElementById( "calcLoan" ).value );
		var percentage		= 0;
													
		if( vyseUveru > 0 && cenaNemovitosti > 0 )
			percentage = Math.round( vyseUveru * 100 / cenaNemovitosti );
		
		return Math.round( percentage );		
	}
	
	function GetRoundedPercentage()
	{
		percentage = CountPercentage();
		roundedPercentage = 70;
		
		if( percentage > 70 && percentage <= 85 )
			roundedPercentage =  85;
												
		if( percentage > 85 )
			roundedPercentage =  100;
														
		return Math.round( roundedPercentage );
	}
	
	function WritePercentage( percentage )
	{
		var resultPlace 	= document.getElementById('calcpercentage');
	
		resultPlace.innerHTML = percentage + '%';
		
		return true;
	}

	function WriteCurrentLoanRate( arrayValue )
	{
		var i;
		var col = new Array( document.getElementById( 'fix1' ),
							document.getElementById( 'fix2' ),
							document.getElementById( 'fix3' ),
							document.getElementById( 'fix4' ),
							document.getElementById( 'fix5' ),
							document.getElementById( 'fix6' ),
							document.getElementById( 'fix7' ),
							document.getElementById( 'fix8' ) );
		
		var inputs = new Array( document.getElementById( 'L1' ),
							document.getElementById( 'L2' ),
							document.getElementById( 'L3' ),
							document.getElementById( 'L4' ),
							document.getElementById( 'L5' ),
							document.getElementById( 'L6' ),
							document.getElementById( 'L7' ),
							document.getElementById( 'L8' ) );
		
		for( i in col )
		{
			col[i].innerHTML 	= arrayValue[i] + '%';
			if( parseInt( arrayValue[i] ) == 0 )
				inputs[i].disabled = true;
			else
				inputs[i].disabled = false;
				
			/*inputs[i].value 	= arrayValue[i]; */
		}
		return true;
	}
		
	function WriteFixTime( ratesArray, radioValue )
	{
		switch( radioValue )
		{
			case '1':
				rate = ratesArray[0];
			break;
	
			case '3':
				rate = ratesArray[1];
			break;
			default:
			case '5':
				rate = ratesArray[2];
			break;
			
			case '10':
				rate = ratesArray[3];
			break;
			
			case '15':
				rate = ratesArray[4];
			break;
			
			case '20':
				rate = ratesArray[5];
			break;
			
			case '25':
				rate = ratesArray[6];
			break;
			
			case '30':
				rate = ratesArray[7];
			break;

		}
		
		document.getElementById('calcLoanRate').value = rate;
		
	}			
	
	function WriteLoanRateProfi()
	{
		var Typ 	= document . getElementById('calcTyp').value;
		var Fix 	= document . getElementById('calcFix').value;
		var Splatka	= document . getElementById('TypSplaceni').value;
	
		var hiddenInput = document . getElementById('inputCalcLoanRate'); 
	
		/* urok */
		if( Typ == 'classic' )
			Typ = GetRoundedPercentage();
		
		rateAnuitni = ReturnRateByTypFixSplatka( Typ, Fix, 1 );
		rateDeg = ReturnRateByTypFixSplatka( Typ, Fix, 2 );
		rateProg = ReturnRateByTypFixSplatka( Typ, Fix, 3 );

/*
		rateAnuitni = parseFloat( ReturnRateByTypFixSplatka( Typ, Fix, 1 ) );
		rateDeg = ReturnRateByTypFixSplatka( Typ, Fix, 2 );
		rateProg = parseFloat( ReturnRateByTypFixSplatka( Typ, Fix, 3 ) );

		rateDeg = parseFloat( rateDeg.substr(1) );
		
		if( isNaN( rateDeg ) )
			rateDeg = 0;
			
		if( isNaN( rateProg ) )
			rateProg = 0;
*/
		switch( Splatka )
		{
			case '3':
				rate = rateAnuitni - rateDeg;
			break;
			case '2':
				rate = rateProg + rateAnuitni; 
			break;
			case '1':
				rate = rateAnuitni;
			break;
		}
		
		/* protoze 4.59 + 0.1 = 4.6899999999995 nechapu */
		rate = Math.round( rate * 100 ) / 100;
		hiddenInput.value = rate;
		document . getElementById('calcLoanRate') . innerHTML = rate + '%';
	}
	

	function IsRightLoan( formatOutput, isSmall )
	{
		var loan	= document.getElementById('calcLoan');		
		var minLoan	= 300000;
		var price 	= document.getElementById('calcPrice');
		
		loanValue = parseInt( InputPrice( loan.value ) );
		priceValue = parseInt( InputPrice( price.value ) );
		
		if( loanValue == 0 )
			return null;
		
		if( isChecked( 'us' ) || isSelected('us') )
			minLoan = 200000;
		
		if( isChecked( 'classic' ) || isSelected('classic')  )
			minLoan = 300000;

		if(	loanValue < minLoan )
		{
			alert('Minimální výše úvěru je ' + OutputPrice( minLoan ) + '.');
			if( formatOutput == null )
				loan.value = OutputPrice( minLoan );
			else
				loan.value = minLoan;
			
			if( minLoan > priceValue )
				if( formatOutput == null )
					price.value = OutputPrice( minLoan );
				else
					price.value = minLoan;
		}
		
		if(isSmall) LoanVsPriceSmall(); else LoanVsPrice();
	}
	
	function GetCalcTypeValue()
	{
		return calcTyp = document . getElementById('calcTyp') . value;
	}
	
	function RenderSelectOptionsProfi()
	{
		var calcTyp  			= GetCalcTypeValue();
		var currentSelect 		= document.getElementById('calcLOL');
		var selectedOptionID 	= 'lol' + currentSelect.value;
		var minLength			= 5;
		var maxLength 			= 40;
		var i;
		
		if( ! ResetSelectOptions() )
			return null; 
		

		/* americka hypoteka max 20let */
		if( calcTyp == 'us' )
		{
			maxLength = 20;
			minLength = 3;
		}
		
		/* uver vetsi jak 70% max 30let*/
		if( calcTyp == 'classic' && GetRoundedPercentage() > 70 )
			maxLength = 30;
		
		if( getTypSplaceni() == 2 )
		{
			maxLength = 20;
			minLength = 20;
		}
		
		for( i = minLength ; i <= maxLength; i++ )
		{
			var addOption = document.createElement('option');
			addOption.text 	= i;
			addOption.id	= 'lol' + i;
			addOption.value	= i;

			try
			{
				currentSelect.add( addOption,null);
			}
			catch(ex)
			{
				currentSelect.add( addOption ); //IE
			}
			
		}
		
		/* nastavuje vybranou hodnotu  */
		selectedOption = document.getElementById( selectedOptionID );
		if( selectedOption != null )
			selectedOption.selected = true; 
	}
	
	function RenderFixTimeProfi()
	{
		var currentSelect 		= document.getElementById('calcFix');
		var selectedOptionID 	= 'fix' + currentSelect.value;
		var fixTimeArray		= new Array( '1 rok', '3 roky', '5 let', '10 let', '15 let', '20 let', '25 let', '30 let' );
		var fixTimeValueArray	= new Array( '1', '3', '5', '10', '15', '20', '25', '30' );
		var fixTimeIDArray		= new Array( 'fix1', 'fix3', 'fix5', 'fix10', 'fix15', 'fix20', 'fix25', 'fix30' );
		var i;
		var minLength			= 0;
		var Typ 				= document . getElementById('calcTyp').value;
		
		if( ! ResetSelectOptions( 'calcFix' ) )
			return null;

		/* degres */
		if( getTypSplaceni() == 3 )
			minLength = 2;
		
		opakovani = fixTimeArray.length;

		/* americka a druzstevni ma fix dobu jen 1, 3 a 5*/		
		if( document.getElementById('calcTyp').value == 'us' || document.getElementById('calcTyp').value == 'dr' )
			opakovani = 3;
		
		
		if( Typ == 'classic' )
			Typ = GetRoundedPercentage();
		
		for( i = minLength ; i < opakovani; i++ )
		{
			var addOption = document.createElement('option');
			addOption.text 	= fixTimeArray[i];
			addOption.id	= fixTimeIDArray[i];
			addOption.value	= fixTimeValueArray[i];

			if( ReturnRateByTypFixSplatka( Typ, fixTimeValueArray[i], 1 ) != 0 )
			{
				try
				{
					currentSelect.add( addOption,null);
				}
				catch(ex)
				{
					currentSelect.add( addOption ); //IE
				}
			}
			
		}
		
		/* nastavuje vybranou hodnotu  */
		selectedOption = document . getElementById( selectedOptionID );
		if( selectedOption != null )
			selectedOption.selected = true; 
	}
	
	function RenderSelectOptions()
	{
		var currentSelect = document.getElementById('calcLOL');
		var selectedOptionID 	= 'lol' + currentSelect.value;

		var i;
		var maxLength = 40;
		var minLength = 5;
		
		if( ! ResetSelectOptions() )
			return null;
		
			/* americka hypoteka max 20let */
		if( isChecked( 'us' ) )
		{
			maxLength = 20;
			minLength = 3;
		}
		
		/* uver vetsi jak 70% max 30let*/
		if( isChecked( 'classic' ) && GetRoundedPercentage() > 70 )
			maxLength = 30;

		for( i = minLength; i <= maxLength; i++ )
		{
			var addOption = document.createElement('option');
			addOption.text 	= i;
			addOption.id	= 'lol' + i;
			addOption.value	= i;

			try
			{
				currentSelect.add( addOption,null);
			}
			catch(ex)
			{
				currentSelect.add( addOption ); //IE
			}
		}
		
		/* nastavuje vybranou hodnotu  */
		selectedOption = document . getElementById( selectedOptionID );
		if( selectedOption != null )
			selectedOption.selected = true; 
	}	 
	
	function ResetSelectOptions( selectID )
	{
		if( selectID == null )
			selectID = 'calcLOL';
		
		var currentSelect = document.getElementById( selectID );
		var optionQnt = currentSelect.length;
		var i;
		
		for( i = 1; i <= optionQnt; i++ )
			currentSelect.remove( currentSelect.length - 1 );
			
		return true;
	}
	
	function LoanVsPrice( formatOutput )
	{
		var formName 	= document . getElementById( 'calcForm' );
		var price		= InputPrice( formName.calcPrice.value );
		var loan		= InputPrice( formName.calcLoan.value );
												
		loan 	= parseInt( loan );
		price 	= parseInt( price );
												
		if( loan > price )
		{
			alert('Úvěr nesmí být vyšší než cena nemovitosti.');
			if( formatOutput == null )
				formName.calcLoan.value = OutputPrice( price );
			else
				formName.calcLoan.value = price;
		}
													
		return true;
	}	

	function LoanVsPriceSmall( formatOutput )
	{
		var price		= InputPrice( document.getElementById('calcPrice').value );
		var loan		= InputPrice( document.getElementById('calcLoan').value );
												
		loan 	= parseInt( loan );
		price 	= parseInt( price );
												
		if( loan > price )
		{
			alert('Úvěr nesmí být vyšší než cena nemovitosti.');
			if( formatOutput == null )
				document.getElementById('calcLoan').value = OutputPrice( price );
			else
				document.getElementById('calcLoan').value = price;
		}
													
		return true;
	}	
	
	/* checking radiobuttons */  
	function isChecked( radioID )
	{
		var radioB	= document.getElementById( radioID );
		
		if( radioB == null )
			return false;
			
		if( radioB.checked )
			return true;
			
		return false;
	}
	
	function isSelected( optionID )
	{
		var optionFromSelect = document.getElementById( optionID );
		
		if( optionFromSelect == null)
			return false;
		
		return optionFromSelect.selected;
	}
	
	function SetRightInputFormatForTableElID( elID, noCurrency )
	{
		elTable = document.getElementById( elID );
		
		elArr = elTable.getElementsByTagName( 'input' );
		
		for( k in elArr )
			if( elArr[k] != null )
				elArr[k].value = OutputPrice( InputPrice( elArr[k].value ), noCurrency );	
	}
	
	function SetRightFormatSmall()
	{
		var formNamed = document . getElementById( 'calcForm' );
		formNamed . calcLoan . value = OutputPrice( InputPrice( formNamed . calcLoan . value ) );
		formNamed . calcPrice . value = OutputPrice( InputPrice( formNamed . calcPrice . value ) );
		
	}
	
	function SetRightFormatProfi()
	{
		SetRightFormatSmall();
		
		if( document . getElementById('releaseAll') != null )
			SetRightFormatSmall();
	}
	
	function controlMinimumValue()
	{
		SetHelpText( document . getElementById( 'min0' ) );
		SetHelpText( document . getElementById( 'min1' ) );
		SetHelpText( document . getElementById( 'min3' ) );
		SetHelpText( document . getElementById( 'min4' ) );
	}
	
	function SetHelpText( ID )
	{
		var HelpText = 'Počet osob';
			
		if( ID . value == 0 || ID . value == '' )	
			ID . value = HelpText;	
			
		return true;	
	}
	
	function ClearValue( ID )
	{
		ID . value = '';
	}
	
	function fldFocus(ctrl, defaultVal) {
		if (ctrl.value==defaultVal) ctrl.value='';
	}
	
	function fldBlur(ctrl, defaultVal) {
		if (ctrl.value=='') ctrl.value=defaultVal;
	}
	
	function copyPlace(elem)
	{
		if (true == elem.checked)
		{
			document.getElementById('koresp_ulice_1').value = document.getElementById('adr_ulice_1').value;
			document.getElementById('koresp_obec_1').value = document.getElementById('adr_obec_1').value;
			document.getElementById('koresp_psc_1').value = document.getElementById('adr_psc_1').value;
			
			document.getElementById('koresp_ulice_1').readOnly = true;
			document.getElementById('koresp_obec_1').readOnly = true;
			document.getElementById('koresp_psc_1').readOnly = true;
			
			document.getElementById('koresp_ulice_1').style.background="silver";
			document.getElementById('koresp_obec_1').style.background="silver";
			document.getElementById('koresp_psc_1').style.background="silver";
		}
		
		else
		{
			document.getElementById('koresp_ulice_1').readOnly = false;
			document.getElementById('koresp_obec_1').readOnly = false;
			document.getElementById('koresp_psc_1').readOnly = false;
			
			document.getElementById('koresp_ulice_1').style.background="";
			document.getElementById('koresp_obec_1').style.background="";
			document.getElementById('koresp_psc_1').style.background="";
		}
	}
	
	function clearField(elem)
	{ 
		if (elem.value == '0')
			elem.value = '';
	}

