var ccLoaded = false;
var idElemCalc;

function LoadCredCalc(idelem, type){
	if (ccLoaded == false){
		jQueryUI('#lcc' + type).dialog(
			{autoOpen: true,height: 200,width: 400,modal: true
				,buttons: {'Закрыть': function() {
					jQueryUI( this ).dialog( 'close' );
					}
				}
			}
		);
		jQueryUI.post('/common/getcredcalc.php', function(data){jQueryUI('#lcc' + type).dialog('close');InitCredCalc(data, idelem, type);}).error(function (){jQueryUI('#lcc' + type).dialog('close');alert('При выполнении запроса произошла ошибка. Попробуйте позже.');});
		}
	else
		ShowCredCalc();
}

function LoadCredCalcWithParams(idelem, type, fParamsId){
	if (ccLoaded == false){
		jQueryUI('#lcc' + type).dialog(
			{autoOpen: true,height: 200,width: 400,modal: true
				,buttons: {'Закрыть': function() {
					jQueryUI( this ).dialog( 'close' );
					}
				}
			}
		);
		jQueryUI.post('/common/getcredcalc_ul.php', $("#"+fParamsId).serialize(), function(data){jQueryUI('#lcc' + type).dialog('close');InitCredCalcWithParams(data, idelem, type);}).error(function (){jQueryUI('#lcc' + type).dialog('close');alert('При выполнении запроса произошла ошибка. Попробуйте позже.');});
		}
	else
		ShowCredCalc();
}

function InitCredCalcWithParams(data, idelem, type){
	if (typeof idelem == "undefined")
		idelemt = '#cred_calc_n';
	else
		idelemt = '#' + idelem;
	jQueryUI(idelemt).html(data);
	ocKey = 12;
	for (var key in cprogramNA.commission){
		ocKey = key;
		break;
	}
	cprogramNA.onChange(ocKey);
	apvalueinfoNA.Show(20);
	jQueryUI(idelemt).dialog(
		{autoOpen: false,height: 700,width: 800,modal: true
			,buttons: {'Закрыть': function() {
				jQueryUI( this ).dialog( 'close' );
				}
			}
		}
	);
	idElemCalc = idelemt;
	ccLoaded = true;
	ShowCredCalc();
}

function InitCredCalc(data, idelem, type){
	if (typeof idelem == "undefined")
		idelemt = '#cred_calc_n';
	else
		idelemt = '#' + idelem;
	jQueryUI(idelemt).html(data);
	cprogramNA.onChange(12);
	apvalueinfoNA.Show(20);
	jQueryUI(idelemt).dialog(
		{autoOpen: false,height: 700,width: 800,modal: true
			,buttons: {'Закрыть': function() {
				jQueryUI( this ).dialog( 'close' );
				}
			}
		}
	);
	idElemCalc = idelemt;
	ccLoaded = true;
	ShowCredCalc();
}

function ShowCredCalc(idelem, type){
	if (typeof idelem == "undefined")
		idelem = idElemCalc;
	else
		idelem = '#' + idelem;
	jQueryUI(idelem).dialog('open');
	jQueryUI('#cred_calc_accord').accordion();
	jQueryUI('#cred_calc_accord').accordion('option', 'clearStyle', true);
	jQueryUI('#dp_daygive').datepicker( jQueryUI.datepicker.regional['ru'] );
	jQueryUI('#load_prog').css('display', 'none');
}