var postData = {
	OTH01 : 'BRAK',
	OTH02 : 'BRAK',
	OTH03 : 'BRAK',
	OTH04 : 'BRAK',
	OTH10 : 'BRAK',
	form_code : 'FORM',
	Campaign_ID : 'CMP0002716',
	Wave_ID : 'WAVE1013723',
	GRB_NO : '',
	Lead_ID : '',
	Content_ID : 'FORM_CL_KROTKI',
	name : 'BRAK',
	surname : 'BRAK',
	pesel : 'BRAK',
	birthdate_day : '01',
	birthdate_month : '01',
	birthdate_year : '1900',
	street : 'BRAK',
	city : 'BRAK',
	email : 'BRAK',
	home_phone : 'BRAK',
	cellphone : 'BRAK',
	sex : 'BRAK',
	polish_nationality : 'BRAK',
	nationality : 'BRAK',
	personal_card : 'BRAK',
	passport_number : 'BRAK',
	mother_maiden_name : 'BRAK',
	check_in_street : 'BRAK',
	check_in_house_nr : 'BRAK',
	check_in_flat_nr : 'BRAK',
	check_in_city : 'BRAK',
	check_in_zipcode : 'BRAK',
	check_in_post_office : 'BRAK',
	house_nr : 'BRAK',
	flat_nr : 'BRAK',
	zipcode : 'BRAK',
	post_office : 'BRAK',
	corr_addr : 'BRAK',
	condition : 'BRAK',
	education : 'BRAK',
	education_another : 'BRAK',
	i_live_in : 'BRAK',
	it_is_local : 'BRAK',
	it_is_local_another : 'BRAK',
	official_firmname : 'BRAK',
	company_street : 'BRAK',
	company_building : 'BRAK',
	company_local : 'BRAK',
	company_city : 'BRAK',
	company_zipcode : 'BRAK',
	company_postoffice : 'BRAK',
	company_phone : 'BRAK',
	company_phone_ext : 'BRAK',
	kind_of_employment : 'BRAK',
	profession : 'BRAK',
	monthly_brutto_pay : 'BRAK',
	activity_area_other : 'BRAK',
	practice_year : 'BRAK',
	practice_month : 'BRAK',
	hired_years : 'BRAK',
	hired_months : 'BRAK',
	other_sex : 'BRAK',
	other_name : 'BRAK',
	other_surname : 'BRAK',
	other_polish_nationality : 'BRAK',
	other_nationality : 'wybierz',
	other_pesel : 'BRAK',
	other_personal_card : 'BRAK',
	other_passport_number : 'BRAK',
	other_birthdate_day : 'BRAK',
	other_birthdate_month : 'BRAK',
	other_birthdate_year : 'BRAK',
	other_mother_maiden_name : 'BRAK',
	other_check_in_street : 'BRAK',
	other_check_in_house_nr : 'BRAK',
	other_check_in_flat_nr : 'BRAK',
	other_check_in_city : 'BRAK',
	other_check_in_zipcode : 'BRAK',
	other_check_in_post_office : 'BRAK',
	other_street : 'BRAK',
	other_house_nr : 'BRAK',
	other_flat_nr : 'BRAK',
	other_city : 'BRAK',
	other_zipcode : 'BRAK',
	other_post_office : 'BRAK',
	other_corr_addr : 'BRAK',
	other_home_phone : 'BRAK',
	other_cellphone : 'BRAK',
	other_email : 'BRAK',
	other_condition : 'BRAK',
	other_education : 'BRAK',
	other_education_another : 'BRAK',
	other_i_live_in : 'BRAK',
	other_it_is_local : 'BRAK',
	other_it_is_local_another : 'BRAK',
	other_official_firmname : 'BRAK',
	other_company_street : 'BRAK',
	other_company_building : 'BRAK',
	other_company_local : 'BRAK',
	other_company_city : 'BRAK',
	other_company_zipcode : 'BRAK',
	other_company_postoffice : 'BRAK',
	other_company_phone : 'BRAK',
	other_company_phone_ext : 'BRAK',
	other_kind_of_employment : 'BRAK',
	other_profession : 'BRAK',
	other_monthly_brutto_pay : 'BRAK',
	other_activity_area_other : 'BRAK',
	other_practice_year : 'BRAK',
	other_practice_month : 'BRAK',
	other_hired_years : 'BRAK',
	other_hired_months : 'BRAK',
	non_living_sex : 'BRAK',
	non_living_name : 'BRAK',
	non_living_surname : 'BRAK',
	non_living_home_phone : 'BRAK',
	promotion_code : 'BRAK',
	common_disclaimer1 : 'BRAK',
	common_disclaimer2 : 'BRAK',
	common_disclaimer3 : 'BRAK',
	common_disclaimer4 : 'BRAK',
	common_disclaimer5 : 'BRAK',
	common_disclaimer6 : 'BRAK',
	new_account_type : 'BRAK',
	nr_stay_card : 'BRAK',
	nr_ssn : 'BRAK',
	language : 'BRAK',
	name_on_card : 'BRAK',
	want_cbol : 'BRAK',
	other_nr_stay_card : 'BRAK',
	other_nr_ssn : 'BRAK',
	other_language : 'BRAK',
	other_name_on_card : 'BRAK',
	other_want_cbol : 'BRAK',
	acc_disclaimer1 : 'BRAK',
	acc_disclaimer2 : 'BRAK',
	card_select : 'BRAK',
	name_on_card : 'BRAK',
	creditshield : 'BRAK',
	safety_package : 'BRAK',
	secondary_sex : 'BRAK',
	secondary_name : 'BRAK',
	secondary_surname : 'BRAK',
	secondary_name_on_card : 'BRAK',
	secondary_msecondary_maiden_name : 'BRAK',
	secondary_relationship_level : 'BRAK',
	secondary_birthdate_day : 'BRAK',
	secondary_birthdate_month : 'BRAK',
	secondary_birthdate_year : 'BRAK',
	secondary_pesel : 'BRAK',
	secondary_personal_card : 'BRAK',
	secondary_nationality : 'BRAK',
	secondary_passport_number : 'BRAK',
	secondary_home_phone : 'BRAK',
	secondary_work_phone : 'BRAK',
	secondary_cellphone : 'BRAK',
	cards_in_another_bank : 'BRAK',
	credit_card_in_another_bank : 'BRAK',
	debet_card_in_another_bank : 'BRAK',
	have_account_in_another_bank_name : 'BRAK',
	cc_disclaimer1 : 'BRAK',
	cc_disclaimer2 : 'BRAK',
	cc_disclaimer3 : 'BRAK',
	get_uod : 'BRAK',
	change_amount_uod : 'BRAK',
	maximum_avaliable : 'BRAK',
	no_less_than : 'BRAK',
	no_more_than : 'BRAK',
	declared_account_incomings : 'BRAK',
	other_declared_account_incomings : 'BRAK',
	uod_disclaimer1 : 'BRAK',
	uod_disclaimer2 : 'BRAK',
	uod_disclaimer3 : 'BRAK',
	uod_disclaimer4 : 'BRAK',
	uod_disclaimer5 : 'BRAK',
	uod_disclaimer6 : 'BRAK',
	destiny_of_credit : 'BRAK',
	first_application : 'BRAK',
	amount_of_credit_netto : 'BRAK',
	nominal_rate : 'BRAK',
	preparatory_fee : 'BRAK',
	time_payoff : 'BRAK',
	min_acceptable_amount_of_credit : 'BRAK',
	nominal_rate2 : 'BRAK',
	preparatory_fee2 : 'BRAK',
	have_credit_card_citibank : 'BRAK',
	other_have_credit_card_citibank : 'BRAK',
	relation_type : 'BRAK',
	pil_disclaimer1 : 'BRAK',
	pil_disclaimer2 : 'BRAK',
	pil_disclaimer3 : 'BRAK',
	pil_disclaimer4 : 'BRAK',
	pil_disclaimer5 : 'BRAK',
	pil_disclaimer6 : 'BRAK',
	pil_disclaimer7 : 'BRAK'
};

//	pobieramy datę.
function showPoraKontaktu(){
	if ( poraKontaktuRun ) return false;
	poraKontaktuRun = true;
	clearTimeout(showPoraKontaktuTimer);
	
	jQuery(function(){
		var datka = new Date();
		if ( typeof window._today != 'undefined' ) {
			datka = window._today;
		}
		if ( ( parseInt(datka.getHours()) == 20 && parseInt(datka.getMinutes()) >= 45 ) ||
			( parseInt(datka.getHours()) >= 21 ||  parseInt(datka.getHours()) < 8 ) ) {
			jQuery('#poraKontaktuContainer').show();
			if ( typeof niceLayoutForPoraKontaktu == 'function' ) {
				niceLayoutForPoraKontaktu.call();
			}
		}
	});
};

var showPoraKontaktuTimer = setTimeout(showPoraKontaktu, 2000);
var poraKontaktuRun = false;

jQuery.ajax({
	type: "GET",
	url: '/PLGCB/copy.do?content=getDate',
	dataType: "html",
	async: true,
	success: function(data) {
		var div = jQuery('<div>').hide().html(data);
		jQuery('body').append(div);
		showPoraKontaktu();
	},
	error: function (XMLHttpRequest, textStatus, errorThrown) { showPoraKontaktu(); }
});

function send2IEWA(form) {
	if ( typeof form == 'function' ) {
		form.call();
	}
	else {
		//alert('send2 form');
		form.submit();
	}
};

function send2Crm(form, callback){
/*
	form - form html Object or function to call after crm sent
*/
	if ( typeof form2crm != 'undefined' ) {
		//alert('preparing crm.... '+form2crm.fields.toString());
		var fields = form2crm.fields || false;
		if ( !fields ) {
			//jesli nie ma pól do crm, wyslij normalnie.
			return true;
		}
		for (var i in fields) {
			if (i == 'pesel' && fields[i]=='msp') {
				postData[i] = '';
				break;
			}
			if ( typeof postData[i] != 'undefined' && fields[i] != '' ){
				if ( jQuery('#'+fields[i]).length ) {
					var _value = jQuery('#'+fields[i]).val();
					if ( _value == '' ) { 
						_value = 'BRAK';
					}
					postData[i] = _value;
				} else {
					postData[i] = fields[i];
				}
			}
		}
		//	data w polu other_name 
		if ( typeof window._nowCrmFormat != 'undefined' ) {
			postData.other_name = window._nowCrmFormat;
		} else {
			postData.other_name = new Date();
		}
		
		var infoLayer = jQuery('#infolayer');
		if ( typeof form2crm.infoLayer != 'undefined' ) {
			infoLayer = jQuery('#'+form2crm.infoLayer);
		} 
		infoLayer.fadeIn();
		//alert('ajax -> typeof '+typeof postData+'\n'+postData.name); 
		window._formik_ = form;
		
		jQuery.ajax({
			type: "POST",
			url: '/PLGCB/CRM/XMLForm.do',
			dataType: "html",
			async: true,
			data : postData,
			success: function(data) { 
				send2IEWA(window._formik_);
			},
			error: function (XMLHttpRequest, textStatus, errorThrown) { 
				send2IEWA(window._formik_);
			}
		});
		return false;
	}
};
