var ROOT = '/';
// kepelotoltes
if (navigator.appVersion.substring(0,1) >= 3) {
	// active items
	var active_img = new Image();
	active_img.src = ROOT+'images/active_item.gif';
	var inactive_img = new Image();
	inactive_img.src = ROOT+'images/inactive_item.gif';
	// op.
	var create_link_14_img = new Image();
	create_link_14_img.src = ROOT+'images/create_link_14.gif';
	var edit_link_14_img = new Image();
	edit_link_14_img.src = ROOT+'images/edit_link_14.gif';
	var up_img = new Image();
	up_img.src = ROOT+'images/up.gif';
	var down_img = new Image();
	down_img.src = ROOT+'images/down.gif';
	var delete_img = new Image();
	delete_img.src = ROOT+'images/delete.gif';
	// icons
	var building_type_block_of_flat_img = new Image();
	building_type_block_of_flat_img.src = ROOT+'images/building_type_block_of_flat.gif';
	var building_type_brick_img = new Image();
	building_type_brick_img.src = ROOT+'images/building_type_brick.gif';
	var building_type_other_img = new Image();
	building_type_other_img.src = ROOT+'images/building_type_other.gif';
	var edit_link_img = new Image();
	edit_link_img.src = ROOT+'images/edit_link.gif';
	var edit_office_img = new Image();
	edit_office_img.src = ROOT+'images/edit_office.gif';
	var edit_office_exclamation_img = new Image();
	edit_office_exclamation_img.src = ROOT+'images/edit_office_exclamation.gif';
	var edit_office_uploader_img = new Image();
	edit_office_uploader_img.src = ROOT+'images/edit_office_uploader.gif';
	var edit_office_uploader_exclamation_img = new Image();
	edit_office_uploader_exclamation_img.src = ROOT+'images/edit_office_uploader_exclamation.gif';
	var edit_uploader_img = new Image();
	edit_uploader_img.src = ROOT+'images/edit_uploader.gif';
	var edit_uploader_exclamation_img = new Image();
	edit_uploader_exclamation_img.src = ROOT+'images/edit_uploader_exclamation.gif';
	var elektromos_img = new Image();
	elektromos_img.src = ROOT+'images/elektromos.gif';
	var fancoil_img = new Image();
	fancoil_img.src = ROOT+'images/fancoil.gif';
	var francia_img = new Image();
	francia_img.src = ROOT+'images/francia.gif';
	var hazkozponti_img = new Image();
	hazkozponti_img.src = ROOT+'images/hazkozponti.gif';
	var hazkozponti_em_img = new Image();
	hazkozponti_em_img.src = ROOT+'images/hazkozponti-em.gif';
	var hera_img = new Image();
	hera_img.src = ROOT+'images/hera.gif';
	var incoming_img = new Image();
	incoming_img.src = ROOT+'images/incoming.gif';
	var kazan_img = new Image();
	kazan_img.src = ROOT+'images/kazan.gif';
	var kedvenc_img = new Image();
	kedvenc_img.src = ROOT+'images/kedvenc.gif';
	var kert_img = new Image();
	kert_img.src = ROOT+'images/kert.gif';
	var konvektor_img = new Image();
	konvektor_img.src = ROOT+'images/konvektor.gif';
	var nemkedvenc_img = new Image();
	nemkedvenc_img.src = ROOT+'images/nemkedvenc.gif';
	var next2_img = new Image();
	next2_img.src = ROOT+'images/next2.gif';
	var no_parking_img = new Image();
	no_parking_img.src = ROOT+'images/no_parking.gif';
	var outgoing_img = new Image();
	outgoing_img.src = ROOT+'images/outgoing.gif';
	var parking_img = new Image();
	parking_img.src = ROOT+'images/parking.gif';
	var people_copy_img = new Image();
	people_copy_img.src = ROOT+'images/people_copy.gif';
	var people_edit_button_img = new Image();
	people_edit_button_img.src = ROOT+'images/people_edit_button.gif';
	var people_info_button_img = new Image();
	people_info_button_img.src = ROOT+'images/people_info_button.gif';
	var people_move_img = new Image();
	people_move_img.src = ROOT+'images/people_move.gif';
	var people_new_img = new Image();
	people_new_img.src = ROOT+'images/people_new.gif';
	var people_open_img = new Image();
	people_open_img.src = ROOT+'images/people_open.gif';
	var purchase_lock_img = new Image();
	purchase_lock_img.src = ROOT+'images/purchase_lock.gif';
	var purchase_locked_img = new Image();
	purchase_locked_img.src = ROOT+'images/purchase_locked.gif';
	var reduced_price2_img = new Image();
	reduced_price2_img.src = ROOT+'images/reduced_price2.gif';
	var show_link_img = new Image();
	show_link_img.src = ROOT+'images/show_link.gif';
	var show_link_public_img = new Image();
	show_link_public_img.src = ROOT+'images/show_link_public.gif';
	var tav_em_img = new Image();
	tav_em_img.src = ROOT+'images/tav-em.gif';
	var udvar_img = new Image();
	udvar_img.src = ROOT+'images/udvar.gif';
	var utca_img = new Image();
	utca_img.src = ROOT+'images/utca.gif';
	var x_delete_img = new Image();
	x_delete_img.src = ROOT+'images/x_delete.gif';
	var increased_price2_img = new Image();
	increased_price2_img.src = ROOT+'images/increased_price2.gif';
	var important_img = new Image();
	important_img.src = ROOT+'images/important.gif';
}
function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}
function showHint(str,input_name) {
	document.getElementById("txtHint_"+input_name).innerHTML=str;
}
function peopleEditor(stype, input_name, c_name, c_name_v, c_name_m, c_company_name ,c_telephone1, c_telephone1_v, c_telephone1_m, c_telephone2, c_telephone2_v, c_telephone2_m, c_telephone3, c_telephone3_v, c_telephone3_m, c_fax, c_fax_v, c_fax_m) {
	if (stype.length==0) {   
  	return;
	}
	if (input_name.length==0) {
	  return;
	}
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
	  alert ("Your browser does not support AJAX!");
	  return;
	}
	if (stype == 'new') {
		client_new_opened(c_name,input_name);
	} else {
		client_new_opened('',input_name);
	}
	id_name = input_name;
	var url=ROOT+"scripts/client.script.php";
	url=url+"?type="+stype+"&input_name="+input_name;
	if (c_name != '') {
		url=url+"&name="+c_name;
	}
	if (c_name_v != '') {
		url=url+"&name_v="+c_name_v;
	}
	if (c_name_m != '') {
		url=url+"&name_m="+c_name_m;
	}		
	if (c_company_name != '') {
		url=url+"&company_name="+c_company_name;
	}
	if (c_telephone1 != '') {
		url=url+"&telephone1="+c_telephone1;
	}
	if (c_telephone1_v != '') {
		url=url+"&telephone1_v="+c_telephone1_v;
	}
	if (c_telephone1_m != '') {
		url=url+"&telephone1_m="+c_telephone1_m;
	}
	if (c_telephone2 != '') {
		url=url+"&telephone2="+c_telephone2;
	}
	if (c_telephone2_v != '') {
		url=url+"&telephone2_v="+c_telephone2_m;
	}
	if (c_telephone2_m != '') {
		url=url+"&telephone2_m="+c_telephone2_m;
	}
	if (c_telephone3 != '') {
		url=url+"&telephone3="+c_telephone3;
	}
	if (c_telephone3_v != '') {
		url=url+"&telephone3_v="+c_telephone3_v;
	}
	if (c_telephone3_m != '') {
		url=url+"&telephone3_m="+c_telephone3_m;
	}
	if (c_fax != '') {
		url=url+"&fax="+c_fax;
	}
	if (c_fax_v != '') {
		url=url+"&fax_v="+c_fax_v;
	}
	if (c_fax_m != '') {
		url=url+"&fax_m="+c_fax_m;
	}
	xmlHttp.onreadystatechange=showEditor;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function showEditor() {
	if (xmlHttp.readyState==4) {
		var z = "people_input_"+id_name;
		document.getElementById(z).innerHTML=xmlHttp.responseText;
	}	
}
function client_selected(str,input_name) {
	var y = "txtHint_"+input_name;
	document.getElementById(y).innerHTML=str.options[str.selectedIndex].childNodes[0].nodeValue;
	document.getElementById(input_name).value=str.options[str.selectedIndex].value;
	var x = input_name+"_show";
	document.getElementById(x).value=str.options[str.selectedIndex].childNodes[0].nodeValue;
}
function client_new_opened(c_name,input_name){
	var y = "txtHint_"+input_name;
	document.getElementById(y).innerHTML=c_name;
	document.getElementById(input_name).value=0;
	var x = input_name+"_show";
	document.getElementById(x).value=c_name;
}
function closeBox(input_name) {
	var xx = "people_input_"+input_name;
	document.getElementById(xx).innerHTML="";
	var xx = "people_input_"+input_name;
	document.getElementById(xx).innerHTML="";	
	return;
}
function saveClient(input_name) {
	var y = "txtHint_"+input_name;
	document.getElementById(y).innerHTML=str.options[str.selectedIndex].childNodes[0].nodeValue;
	document.getElementById(input_name).value=str.options[str.selectedIndex].value;
	var x = input_name+"_show";
	document.getElementById(x).value=str.options[str.selectedIndex].childNodes[0].nodeValue;
}
function agentEditor(str,input_name, office_id, office_members) {
	if (str.length==0) {   
  	return;
	}
	if (input_name.length==0) {
	  return;
	}
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
	  alert ("Your browser does not support AJAX!");
	  return;
	}
	id_name = input_name;
	var url=ROOT+"scripts/agent.script.php";
	url=url+"?type="+str+"&input_name="+input_name+"&office_id="+office_id+"&office_members="+office_members;
	xmlHttp.onreadystatechange=showEditor;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function country_selected(str, country_id, city_id, disabled, radio, area_mode, area_show, area_selected, area_new, directly_loaded) {
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
	  alert ("Your browser does not support AJAX!");
	  return;
	}
	var url=ROOT+"scripts/city.script.php";
	if (country_id == -1) {
		url=url+"?country_id="+str.options[str.selectedIndex].value+'&radio='+radio+'&area_mode='+area_mode+'&area_show='+area_show+'&area_selected='+area_selected+'&area_new='+area_new;
	} else {
		if (area_mode == 'searchable' && country_id == 20) {
			if (!directly_loaded) {
				city_id = refresh_area(city_id);
				area_selected = refresh_area_selected();
			}
		}
		if (city_id == 'city_post_code') {
			city_id = refresh_city_id();
		}
		url=url+"?country_id="+country_id+"&city_id="+city_id+"&disabled="+disabled+'&radio='+radio+'&area_mode='+area_mode+'&area_show='+area_show+'&area_selected='+area_selected+'&area_new='+area_new;
	}
	xmlHttp.onreadystatechange=citySelector;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function citySelector() {
	if (xmlHttp.readyState==4) {
		document.getElementById('city').innerHTML=xmlHttp.responseText;
	}
}
function show_area() {
	document.getElementById('area').className = 'show';
}
function refresh_area(city_id) {
	// type 1 bp, 2 vidék
	var dist = '';
	var buda_1 = document.getElementById('buda_1');
	var buda_2 = document.getElementById('buda_2');
	var buda_3 = document.getElementById('buda_3');
	var buda_11 = document.getElementById('buda_11');
	var buda_12 = document.getElementById('buda_12');
	var buda_22 = document.getElementById('buda_22');
	var pest_4 = document.getElementById('pest_4');
	var pest_5 = document.getElementById('pest_5');
	var pest_6 = document.getElementById('pest_6');
	var pest_7 = document.getElementById('pest_7');
	var pest_8 = document.getElementById('pest_8');
	var pest_9 = document.getElementById('pest_9');
	var pest_10 = document.getElementById('pest_10');
	var pest_13 = document.getElementById('pest_13');
	var pest_14 = document.getElementById('pest_14');
	var pest_15 = document.getElementById('pest_15');
	var pest_16 = document.getElementById('pest_16');
	var pest_17 = document.getElementById('pest_17');
	var pest_18 = document.getElementById('pest_18');
	var pest_19 = document.getElementById('pest_19');
	var pest_20 = document.getElementById('pest_20');
	var pest_21 = document.getElementById('pest_21');
	var pest_23 = document.getElementById('pest_23');
	if (city_id == 'pest') {
		dist = '4_5_6_7_8_9_10_13_14_15_16_17_18_19_20_21_23';
		if (buda_1.checked) {dist += '_1';}
		if (buda_2.checked) {dist += '_2';}
		if (buda_3.checked) {dist += '_3';}
		if (buda_11.checked) {dist += '_11';}
		if (buda_12.checked) {dist += '_12';}
		if (buda_22.checked) {dist += '_22';}
	} else if (city_id == 'buda') {
		dist = '1_2_3_11_12_22';
		if (pest_4.checked) {dist += '_4';}
		if (pest_5.checked) {dist += '_5';}
		if (pest_6.checked) {dist += '_6';}
		if (pest_7.checked) {dist += '_7';}
		if (pest_8.checked) {dist += '_8';}
		if (pest_9.checked) {dist += '_9';}
		if (pest_10.checked) {dist += '_10';}
		if (pest_13.checked) {dist += '_13';}
		if (pest_14.checked) {dist += '_14';}
		if (pest_15.checked) {dist += '_15';}
		if (pest_16.checked) {dist += '_16';}
		if (pest_17.checked) {dist += '_17';}
		if (pest_18.checked) {dist += '_18';}
		if (pest_19.checked) {dist += '_19';}
		if (pest_20.checked) {dist += '_20';}
		if (pest_21.checked) {dist += '_21';}
		if (pest_23.checked) {dist += '_23';}
	} else {
		if (buda_1.checked) {dist += '_1';}
		if (buda_2.checked) {dist += '_2';}
		if (buda_3.checked) {dist += '_3';}
		if (buda_11.checked) {dist += '_11';}
		if (buda_12.checked) {dist += '_12';}
		if (buda_22.checked) {dist += '_22';}
		if (pest_4.checked) {dist += '_4';}
		if (pest_5.checked) {dist += '_5';}
		if (pest_6.checked) {dist += '_6';}
		if (pest_7.checked) {dist += '_7';}
		if (pest_8.checked) {dist += '_8';}
		if (pest_9.checked) {dist += '_9';}
		if (pest_10.checked) {dist += '_10';}
		if (pest_13.checked) {dist += '_13';}
		if (pest_14.checked) {dist += '_14';}
		if (pest_15.checked) {dist += '_15';}
		if (pest_16.checked) {dist += '_16';}
		if (pest_17.checked) {dist += '_17';}
		if (pest_18.checked) {dist += '_18';}
		if (pest_19.checked) {dist += '_19';}
		if (pest_20.checked) {dist += '_20';}
		if (pest_21.checked) {dist += '_21';}
		if (pest_23.checked) {dist += '_23';}
	}
	return dist;
}
function refresh_area_selected() {
	var opt = '';
	var select = document.getElementById('area_selected');
	var len = 0;
	var i = 0;
	if (select) {
		len = select.length;
		for (i = 0; i < len; i++) {
			if (select[i].selected) {
				opt += '_'+select[i].value;
			}
		}
	}
	return opt;
}
function refresh_city_id() {
	var i;
	var city_id = -1;
	var select = document.getElementById('place_city');
	if (select) {
		i = select.selectedIndex;
		if (i != -1) {
			city_id = select[i].value;
		}
	}
	return city_id;
}
function setValue(value, id) {

	if (value == Infinity) {
		document.getElementById(id).innerHTML='-';
	} else {
		document.getElementById(id).innerHTML= Math.round(value);
	}

}
function setFormValue(value, id) {

	if (value == Infinity) {
		document.getElementById(id).innerHTML='-';
	} else {
		document.getElementById(id).innerHTML= Math.round(value);
	}

}
function new_client_data(data_type, input_value, input_name) {
	if (data_type == 'name') {
		document.getElementById(input_name+'_new_client[name]').value=input_value;
		document.getElementById(input_name+'_show').value=input_value;
		showHint(input_value,input_name);
	}
	if (data_type == 'company_name') {
		document.getElementById(input_name+'_new_client[company_name]').value=input_value;
	}
	if (data_type == 'telephone1') {
		document.getElementById(input_name+'_new_client[telephone1]').value=input_value;
	}
	if (data_type == 'telephone2') {
		document.getElementById(input_name+'_new_client[telephone2]').value=input_value;
	}
	if (data_type == 'telephone3') {
		document.getElementById(input_name+'_new_client[telephone3]').value=input_value;
	}
	if (data_type == 'fax') {
		document.getElementById(input_name+'_new_client[fax]').value=input_value;
	}
}
function submit_next() {
	var max_row = document.getElementById('max_row').value;
	var limit_jump = document.getElementById('limit_jump').value;
	if ((document.getElementById('limit_offset').value - 0) + (document.getElementById('limit_jump').value - 0) < max_row) {
		document.getElementById('limit_offset').value = (document.getElementById('limit_offset').value - 0) + (document.getElementById('limit_jump').value - 0);
		document.getElementById('search_form').submit();
	}
}
function submit_last() {
	var min_row = 0;
	var limit_jump = document.getElementById('limit_jump').value;
	if ((document.getElementById('limit_offset').value - limit_jump) >= 0) {
		document.getElementById('limit_offset').value = document.getElementById('limit_offset').value - limit_jump;
		document.getElementById('search_form').submit();
	}
}
function submit_page(page_num) {
	var limit_jump = document.getElementById('limit_jump').value;
	document.getElementById('limit_offset').value = limit_jump * page_num;
	document.getElementById('search_form').submit();
}
function reset_offset() {
	document.getElementById('limit_offset').value = 0;
}
function reset_compare() {
	document.getElementById('compare').value = '';
}
function telephone(value, caller, sid, sess) {
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
	  alert ("Your browser does not support AJAX!");
	  return;
	}		
	var url=ROOT+"scripts/telephone.script.php";
	url=url+"?telephone="+value+"&caller="+caller+"&rand="+Math.random()+"&"+sid+"="+sess;
	if (caller == 'cdc_list') {
		xmlHttp.onreadystatechange=cdcListOperations;
	} else {
		xmlHttp.onreadystatechange=telephoneSelected;
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function telephoneSelected() {
	if (xmlHttp.readyState==4) {
		document.getElementById('telephone_message').innerHTML=xmlHttp.responseText;
	}
}
function cdcListOperations() {
	if (xmlHttp.readyState==4) {
		if (xmlHttp.responseText == 'no_match') {
			display_cdc_list_operations('show');
			document.getElementById('telephone_message').innerHTML= '';
		} else if (xmlHttp.responseText == '') {
			display_cdc_list_operations('hide');
			document.getElementById('telephone_message').innerHTML= '';
		} else {
			end_tag = xmlHttp.responseText.slice(-8,xmlHttp.responseText.length);
			if (end_tag == 'no_match') {
				document.getElementById('telephone_message').innerHTML=xmlHttp.responseText.slice(0,-8);
				display_cdc_list_operations('show');
			} else {
				display_cdc_list_operations('hide');
				document.getElementById('telephone_message').innerHTML=xmlHttp.responseText;
			}
		}
	}	
}
function check_full_telephone(value) {
	if (value.length == 8 || value.length == 9) {
		var prefix = value.slice(0,2);
			if ((value.length == 8 && prefix != 20 && prefix != 30 && prefix != 70) || (value.length == 9 && (prefix == 20 || prefix == 30 || prefix == 70))) {
				xmlHttp=GetXmlHttpObject()
			if (xmlHttp==null) {
			  alert ("Your browser does not support AJAX!");
			  return;
			}
			var url=ROOT+"scripts/telephone.script.php";
			url=url+"?telephone="+value+"&caller=0&rand="+Math.random();
			xmlHttp.onreadystatechange=telephoneSelected;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
		}
	}
}
function display_cdc_list_operations(to_do) {
	var obj1 = document.getElementById('cdc_list_op_1');
	var obj2 = document.getElementById('cdc_list_op_2');
	if (obj1 && obj2) {
		if (to_do == 'hide') {
			//document.getElementById('cdc_list_op_title').className = "cdc_list_op_hide";
			obj1.className = "cdc_list_op_hide";
			obj2.className = "cdc_list_op_hide";
		} else if (to_do == 'show') {
			//document.getElementById('cdc_list_op_title').className = "cdc_list_op_title_show";
			obj1.className = "cdc_list_op_even";
			obj2.className = "cdc_list_op_odd";
		}
	}
}
function note_client_type(id, type) {
	var note_free = document.getElementById('note_status_free_' + id);
	var note_conciliation = document.getElementById('note_status_conciliation_' + id);
	var note_processed = document.getElementById('note_status_processed_' + id);
	var note_comment = document.getElementById('note_comment_' + id);
	if (type == 'estate_agent') {
		note_processed.checked=true;
		note_free.disabled=true;
		note_conciliation.disabled=true;
	} else if (type == 'private' || type == 'unknown') {
		note_free.checked=true;
		note_free.disabled=false;
		note_conciliation.disabled=false;
		//note_comment.disabled=false;
		var hidden_node_comment = document.getElementById('hidden_note_comment_' + id);
		if (hidden_node_comment) {
			note_comment.removeChild(hidden_node_comment);
		}
	}
}
function selectRoom(str,i) {	
	if (str.options[str.selectedIndex].value == 1) {
		var x = 'room_'+i+'_type1';
		document.getElementById(x).className = 'object_vis';
		var xx = 'room_'+i+'_type2';
		document.getElementById(xx).className = 'object_none';
	}
	if (str.options[str.selectedIndex].value == 0) {
		var x = 'room_'+i+'_type1';
		document.getElementById(x).className = 'object_none';
		var xx = 'room_'+i+'_type2';
		document.getElementById(xx).className = 'object_none';
	}
	if (str.options[str.selectedIndex].value > 1) {
		var x = 'room_'+i+'_type1';
		document.getElementById(x).className = 'object_none';
		var xx = 'room_'+i+'_type2';
		document.getElementById(xx).className = 'object_vis';
	}
}
function char_counter(value) {
	var x = value;	
	var y = x.length;
	document.getElementById('char_counter').innerHTML = y;
}
function set_order(order_by, direction) {
	document.getElementById('order_by').value = order_by;
	document.getElementById('direction').value = direction;
	document.getElementById('search_form').submit();
}
function get_office_id() {
	var order_office = document.getElementById("office_id");
	if (order_office) {
		return order_office.value;
	} else {
		return 0;
	}
}
function table_view() {
	document.getElementById('result_view').value = 'table_view';
	document.getElementById('search_form').submit();
}
function adv_view() {
	document.getElementById('result_view').value = 'adv_view';
	document.getElementById('search_form').submit();
}
function datasheet(type, href, title) {
	if (type == 'data') {
		open(href, title, 'width=670,height=700,status=no,menubar=no,scrollbars=yes,resizable=yes');
	} else if (type == 'img') {
		open(href, title, 'width=830,height=790,status=no,menubar=no,scrollbars=yes,resizable=yes');
		//open(href, title, 'width=660,height=650,status=no,menubar=no,scrollbars=yes,resizable=yes');
	}
}
function get_pic(order) {
	var imgs = document.getElementsByTagName('img');
	var pic_nums = 0;
	var j = 0;
	for(i in imgs) {
		if (imgs[i].className == 'pic_visible') {
			active_id = imgs[i].id;
			pic_nums++;
		} else if (imgs[i].className == 'pic_hide') {
			pic_nums++;
		}
	}
	id_parts = active_id.split('_');
	if (order == 'next') {
		next_id = (id_parts[1] - 0) + 1;
		if (next_id >= pic_nums) {
			new_id = 'pic_0';
		} else {
			new_id = 'pic_' + next_id;
		}
	} else if (order == 'prew') {
		prew_id = (id_parts[1] - 0) - 1;
		if (prew_id < 0) {
			new_id = 'pic_' + --pic_nums;
		} else {
			new_id = 'pic_' + prew_id;
		}
	}
	document.getElementById(active_id).className = "pic_hide";
	document.getElementById(new_id).className = "pic_visible";
}
function set_pic(index_id) {
	var imgs = document.getElementsByTagName('img');
	for(i in imgs) {
		if (imgs[i].className == 'pic_visible') {
			active_id = imgs[i].id;
		}
	}
	id_parts = index_id.split('_');
	new_id = 'pic_' + id_parts[2];
	document.getElementById(active_id).className = "pic_hide";
	document.getElementById(new_id).className = "pic_visible";
}
function set_pic_size() {
	var imgs = document.getElementsByTagName('img');
	for(i in imgs) {
		if (imgs[i].id) {
			if (imgs[i].id.substr(0, 4) == 'pic_') {
				if (imgs[i].width > 500) {
					imgs[i].width = 500;
				}
				if (imgs[i].height > 500) {
					imgs[i].height = 500;
				}
			}
		}
	}
}
function set_note_date_array(obj) {
	// 1:re, 2:st
	var _event_on = obj;
	var note_type = document.getElementById("note_type").value;
	var all_note = document.getElementById("all_note");
	var own_note = document.getElementById("own_note");
	if (_event_on) {
		if (_event_on.id == 'all_note') {
			if (_event_on.checked) {
				all_note_checked = true;
				own_note_checked = false;
				own_note.checked = false; 
			} else {
				all_note_checked = false;
				own_note_checked = false;
			}
		} else if (_event_on.id == 'own_note') {
			if (_event_on.checked) {
				all_note_checked = false;
				all_note.checked = false; 
				own_note_checked = true;
			} else {
				all_note_checked = false;
				own_note_checked = false;
			}
		} else if (_event_on.id == 'note_type') {
			if (all_note.checked ) {
				all_note_checked = true;
			} else {
				all_note_checked = false;
			}
			if (own_note.checked ) {
				own_note_checked = true;
			} else {
				own_note_checked = false;
			}
		}
	}
	else {
		all_note_checked = false;
		own_note_checked = false;
	}
	if (note_type == '1') {
		if (all_note_checked) {
			document.getElementById("re_note_date").className = 'hide';
			document.getElementById("re_note_date_all").className = 'show';
			document.getElementById("re_note_date_own").className = 'hide';
			document.getElementById("st_note_date").className = 'hide';
			document.getElementById("st_note_date_all").className = 'hide';
			document.getElementById("st_note_date_own").className = 'hide';
		} else if (own_note_checked) {
			document.getElementById("re_note_date").className = 'hide';
			document.getElementById("re_note_date_all").className = 'hide';
			document.getElementById("re_note_date_own").className = 'show';
			document.getElementById("st_note_date").className = 'hide';
			document.getElementById("st_note_date_all").className = 'hide';
			document.getElementById("st_note_date_own").className = 'hide';
		} else {
			document.getElementById("re_note_date").className = 'show';
			document.getElementById("st_note_date").className = 'hide';
			document.getElementById("re_note_date_own").className = 'hide';
			document.getElementById("re_note_date_all").className = 'hide';
			document.getElementById("st_note_date_all").className = 'hide';
			document.getElementById("st_note_date_own").className = 'hide';
		}
	} else if (note_type == '2') {
		if (all_note_checked) {
			document.getElementById("re_note_date").className = 'hide';
			document.getElementById("re_note_date_all").className = 'hide';
			document.getElementById("re_note_date_own").className = 'hide';
			document.getElementById("st_note_date").className = 'hide';
			document.getElementById("st_note_date_all").className = 'show';
			document.getElementById("st_note_date_own").className = 'hide';
		} else if (own_note_checked) {
			document.getElementById("re_note_date").className = 'hide';
			document.getElementById("re_note_date_all").className = 'hide';
			document.getElementById("re_note_date_own").className = 'hide';
			document.getElementById("st_note_date").className = 'hide';
			document.getElementById("st_note_date_all").className = 'hide';
			document.getElementById("st_note_date_own").className = 'show';
		} else {
			document.getElementById("re_note_date").className = 'hide';
			document.getElementById("re_note_date_all").className = 'hide';
			document.getElementById("re_note_date_own").className = 'hide';
			document.getElementById("st_note_date").className = 'show';
			document.getElementById("st_note_date_all").className = 'hide';
			document.getElementById("st_note_date_own").className = 'hide';
		}
	}
}
var cl_item_id = 0;
function display_cdc_list_item(note_type, id) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
	  alert ("Your browser does not support AJAX!");
	  return;
	}
	cl_item_id = id;
	var obj = document.getElementById('cl_item_' + cl_item_id);
	if (obj.className == "show_2") {
		var url=ROOT+"index.php?page=cdc_list&state=item_undo_selector&note_type="+note_type+"&id="+id;
		xmlHttp.onreadystatechange=cdcListItemUndoSelector;
	} else {
		var url=ROOT+"index.php?page=cdc_list&state=item_selector&note_type="+note_type+"&id="+id;
		xmlHttp.onreadystatechange=cdcListItemSelector;
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function cdcListItemSelector() {
	if (xmlHttp.readyState==4) {
		var obj = document.getElementById('cl_item_' + cl_item_id);
		var obj2 = document.getElementById('cl_item_link' + cl_item_id);
		if (obj.className == "show_2") {
			obj.className = "hide_2";
			obj2.innerHTML = '<img src="'+ROOT+'images/inactive_item.gif" />'
		} else {
			if (xmlHttp.responseText) {
				obj.className = "show_2";
				obj2.innerHTML = '<img src="'+ROOT+'images/active_item.gif" />'
			}
		}
		document.getElementById('cl_item_selector_'+cl_item_id).innerHTML=xmlHttp.responseText;
	}
}
function cdcListItemUndoSelector() {
	if (xmlHttp.readyState==4) {
		var obj = document.getElementById('cl_item_' + cl_item_id);
		var obj2 = document.getElementById('cl_item_link' + cl_item_id);
		if (obj.className == "show_2") {
			obj.className = "hide_2";
			obj2.innerHTML = '<img src="'+ROOT+'images/inactive_item.gif" />'
		} else {
			obj.className = "show_2";
			obj2.innerHTML = '<img src="'+ROOT+'images/active_item.gif" />'
		}
		document.getElementById('cl_item_selector_'+cl_item_id).innerHTML='';
	}
}
function display_cdc_list_import_item(id) {
	var obj = document.getElementById('cl_item_' + id);
	var obj2 = document.getElementById('cl_item_link' + id);
	if (obj.className == "show_2") {
		obj.className = "hide_2";
		obj2.innerHTML = '<img src="'+ROOT+'images/inactive_item.gif" />'
	} else {
		obj.className = "show_2";
		obj2.innerHTML = '<img src="'+ROOT+'images/active_item.gif" />'
	}
}
function print_window(href, title) {
	if (href != '') {
		open(href, title, 'width=660,height=600,status=no,menubar=no,scrollbars=yes,resizable=yes');
	}
}
function print_button_display(to_do) {	
	if (to_do == 'hide') {
		document.getElementById("print_button").style.display = 'none';
		if (document.getElementById("print_button2")) {
			document.getElementById("print_button2").style.display = 'none';
		}
	} else if (to_do == 'show') {
		document.getElementById("print_button").style.display = 'inline';
		if (document.getElementById("print_button2")) {
			document.getElementById("print_button2").style.display = 'inline';
		}
	}
}
function print_log(page, state, agent_id, object_id) {
	print_button_display('hide');
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
	  alert ("Your browser does not support AJAX!");
	  return;
	}		
	var url=ROOT+"scripts/print.script.php";
	url=url+"?page="+page+"&state="+state+"&agent_id="+agent_id+"&object_id="+object_id;
	xmlHttp.onreadystatechange=print_logged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function print_logged() {
	if (xmlHttp.readyState==4) {
		var obj = document.getElementById('show_contact_data');
		window.setTimeout("print_button_display('show')", 30000);
		if (obj) {
			obj.innerHTML=xmlHttp.responseText;
		}
		window.print();
	}
}
function print_public(to_do) {
	if (to_do == 'hide') {
		document.getElementById("print_button").style.display = 'none';
		document.getElementById("print_button2").style.display = 'none';
		window.setTimeout("print_public('show')", 30000);
		window.print();
	} else if (to_do == 'show') {
		document.getElementById("print_button").style.display = 'inline';
		document.getElementById("print_button2").style.display = 'inline';
	}
}
function print_compare(to_do) {
	if (to_do == 'hide') {
		document.getElementById("print_button3").style.display = 'none';
		window.setTimeout("print_compare('show')", 30000);
		window.print();
	} else if (to_do == 'show') {
		document.getElementById("print_button3").style.display = 'inline';
	}
}
function display_sys_log_param(id) {
	var obj = document.getElementById('sys_log_param_' + id);
	var obj2 = document.getElementById('sys_log_param_link' + id);
	if (obj.className == "show_2") {
		obj.className = "hide_2";
		obj2.innerHTML = '<img src="'+ROOT+'images/inactive_item.gif" />'
	} else {
		obj.className = "show_2";
		obj2.innerHTML = '<img src="'+ROOT+'images/active_item.gif" />'
	}
}
function select_districts(city_part) {
	var inputs = document.getElementsByTagName('input');
	for (var i = 0; i < inputs.length; i++) {
		if (inputs[i].type == "checkbox" && inputs[i].id) {
			var id_parts = inputs[i].id.split('_');
			if (id_parts[0] == city_part) {
				if (inputs[i].checked == true) {
					inputs[i].checked = false;
				} else {
					inputs[i].checked = true;
				}
			}
		}
	}
}
function set_cl_place() {
	var district = document.getElementById('district').value;
	if (district == 1 || district == 2 || district == 3 || district == 11 || district == 12 || district == 22) {
			document.getElementById('place').value = 'Buda';
	} else if (district == 4 || district == 5 || district == 6 || district == 7 || district == 8 || district == 9 ||
			district == 10 || district == 13 || district == 14 || district == 15 || district == 16 || district == 17 ||
			district == 18 || district == 19 || district == 20 || district == 21 || district == 23) {
		document.getElementById('place').value = 'Pest';
	} else {
		document.getElementById('place').value = '';
	}
}
function set_cl_first_phone_number() {
	var phone1 = document.getElementById('call_name').value;
	document.getElementById('new_note_type_1').href = ROOT+'cdc_list/create/1/' + phone1;
	document.getElementById('new_note_type_2').href = ROOT+'cdc_list/create/2/' + phone1;
}
function displayNewProperties(output) {
	if (document.getElementById(output).value != '') {
		document.getElementById(output).value = '';
		document.getElementById(output + "_client_id").value = '';
		document.getElementById(output + "_company_name").value = '';
		document.getElementById(output + "_telephone1").value = '';
		document.getElementById(output + "_telephone2").value = '';
		document.getElementById(output + "_telephone3").value = '';
		document.getElementById(output + "_fax").value = '';
		document.getElementById(output + "_secret_telephone").checked = false;
	} else {
		var client_output = document.getElementById("client_output_"+output);
		if (client_output.className == 'show') {
			client_output.className = 'hide';
		}
		else {
			client_output.className = 'show';
		}
	}
}
function displayOnlyProperties(output) {
	var client_output = document.getElementById("client_output_"+output);
	if (client_output.className == 'show') {
		client_output.className = 'hide';
	}
	else {
		client_output.className = 'show';
	}
}
function bookmarksite(title,url) {
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print) { // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	}
	else if(document.all)// ie
		window.external.AddFavorite(url, title);
}
function open_it_message_box(nation) {
	var title;
	if (nation == 'de') {
		title = 'de';
	} else if (nation == 'es') {
		title = 'es';
	} else if (nation == 'gb') {
		title = 'gb';
	} else if (nation == 'it') {
		title = 'it';
	} else if (nation == 'il') {
		title = 'il';
	}
	open(ROOT+'international_message/send/'+nation, title, 'width=530,height=580,status=no,menubar=no,scrollbars=yes,resizable=yes');
}
function close_it_message_box() {
	window.setTimeout("window.close()", 2000);
}
function display_customer_crits_res(id) {
	var obj = document.getElementById('customer_crits_res_' + id);
	var obj2 = document.getElementById('customer_crits_res_link_' + id);
	if (obj.className == "show_2") {
		obj.className = "hide_2";
		obj2.innerHTML = '<img src="'+ROOT+'images/inactive_item.gif" />';
	} else {
		obj.className = "show_2";
		obj2.innerHTML = '<img src="'+ROOT+'images/active_item.gif" />';
	}
}
function hide_mail(crits_id, re_id) {
	document.getElementById('sendmail_'+crits_id+'_'+re_id).checked = false;
	document.getElementById('sendmail_'+crits_id+'_'+re_id).disabled = true;
	document.getElementById('email_auto_'+crits_id+'_'+re_id).checked = false;
	document.getElementById('email_auto_'+crits_id+'_'+re_id).disabled = true;
}
function show_mail(crits_id, re_id) {
	document.getElementById('sendmail_'+crits_id+'_'+re_id).disabled = false;
	document.getElementById('email_auto_'+crits_id+'_'+re_id).disabled = false;
}
function favorite(re_id, mode) {
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
	  alert ("Your browser does not support AJAX!");
	  return;
	}
	if (mode == 'set') {
		var url=ROOT+"real_estate/set_favorite/"+re_id;
		document.getElementById('favorite_icon_'+re_id).innerHTML='<img class="tooltip_icon" src="'+ROOT+'images/kedvenc.gif" title="Eltávolítás a kedvencek ingatlanok közül" onclick="favorite('+"'"+re_id+"'"+', '+"'unset'"+')" />';
	} else if (mode == 'unset') {
		var url=ROOT+"real_estate/unset_favorite/"+re_id;
		document.getElementById('favorite_icon_'+re_id).innerHTML='<img class="tooltip_icon" src="'+ROOT+'images/nemkedvenc.gif" title="Hozzáadás a kedvencek ingatlanokhoz" onclick="favorite('+"'"+re_id+"'"+', '+"'set'"+')" />';
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function reset_search() {
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
	  alert ("Your browser does not support AJAX!");
	  return;
	}
	url=ROOT+"real_estate/reset_search";
	xmlHttp.onreadystatechange=reset_crits;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function reset_crits() {
	// ref
	document.getElementById('ref').value = '';
	// status
	document.getElementById('status').selectedIndex = 1;
	// real_estate_type
	document.getElementById('real_estate_type').selectedIndex = 0;
	// order_type
	document.getElementById('order_type').selectedIndex = 0;
	// country, city
	document.getElementById('country').selectedIndex = 0;
	document.getElementById('city').innerHTML = '';
	// project
	document.getElementById('project').selectedIndex = 0;
	// m2_from
	document.getElementById('m2_from').value = '';
	// m2_to
	document.getElementById('m2_to').value = '';
	// number_of_rooms_min
	document.getElementById('number_of_rooms_min').value = '';
	// view
	document.getElementById('view').selectedIndex = 0;
	// price_min
	document.getElementById('price_min').selectedIndex = 0;
	// price_max
	document.getElementById('price_max').selectedIndex = 0;
	// price_max_m2
	document.getElementById('price_max_m2').value = '';
	// state_real_estate
	document.getElementById('state_real_estate').selectedIndex = 0;
	// state_outside
	document.getElementById('state_outside').selectedIndex = 0;
	// state_inside
	document.getElementById('state_inside').selectedIndex = 0;
	// street
	document.getElementById('street').value = '';
	// which_re
	document.getElementById('all_re').checked = true;
	document.getElementById('own_office_re').checked = false;
	document.getElementById('own_re').checked = false;
	document.getElementById('favorite_re').checked = false;
	// storey_min
	document.getElementById('storey_min').value = '';
	// storey_max
	document.getElementById('storey_max').value = '';
	// building_type
	document.getElementById('building_type').selectedIndex = 0;
	// parking_place
	document.getElementById('parking_place').selectedIndex = 0;
	// other_heating
	document.getElementById('other_heating').selectedIndex = 0;
	// panorama
	document.getElementById('panorama').selectedIndex = 0;
	// lift
	document.getElementById('lift').selectedIndex = 0;
	// balcony
	document.getElementById('balcony').selectedIndex = 0;
	// terrace
	document.getElementById('terrace').selectedIndex = 0;
	// office_id, uploader_id
	document.getElementById('office_id').selectedIndex = 0;
	// uploader_id
	document.getElementById('txtHint_uploader_id').innerHTML = '';
	document.getElementById('people_input_uploader_id').innerHTML = '';
	if (document.getElementById("uploader_id")) {
		document.getElementById("uploader_id").value = "";
	}
	if (document.getElementById("uploader_id_show")) {
		document.getElementById("uploader_id_show").value = "";
	}
	// order_assortment
	document.getElementById('order_assortment').selectedIndex = 0;
	// offer_date
	document.getElementById('offer_date').value = '';
	// storey_min
	document.getElementById('storey_min').selectedIndex = 0;
	// storey_max
	document.getElementById('storey_max').selectedIndex = 0;
	// comment
	document.getElementById('comment').value = '';
	// price_change_day
	document.getElementById('price_change_day').selectedIndex = 0;
	//price_change
	document.getElementById('price_change').selectedIndex = 0;
	//compare_change
	document.getElementById('compare').value = '';
	//reset checkboxes
	reset_checkboxes();
}
function save_search_params() {
	var obj = document.getElementById('param_save');
	if (obj.className == 'show') {
		obj.className = 'hide';
	} else {
		obj.className = 'show';
	}
}
function delete_search_param(id) {
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
	  alert ("Your browser does not support AJAX!");
	  return;
	}
	var url=ROOT+"search/delete_param/"+id;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function display_addressees(id) {
	var obj = document.getElementById('addressees_' + id);
	var obj2 = document.getElementById('addressees_link_' + id);
	if (obj.className == "show_2") {
		obj.className = "hide_2";
		obj2.innerHTML = '<img class="tooltip_icon" src="'+ROOT+'images/inactive_item.gif" onclick="display_addressees('+"'"+id+"'"+')" />';
	} else {
		obj.className = "show_2";
		obj2.innerHTML = '<img class="tooltip_icon" src="'+ROOT+'images/active_item.gif" onclick="display_addressees('+"'"+id+"'"+')" />';
	}
}
function display_cl_visitors(id) {
	var obj = document.getElementById('visitors_' + id);
	var obj2 = document.getElementById('visitors_link_' + id);
	if (obj.className == "show_2") {
		obj.className = "hide_2";
		obj2.innerHTML = '<img class="tooltip_icon" src="'+ROOT+'images/inactive_item.gif" onclick="display_cl_visitors('+"'"+id+"'"+')" />'
	} else {
		obj.className = "show_2";
		obj2.innerHTML = '<img class="tooltip_icon" src="'+ROOT+'images/active_item.gif" onclick="display_cl_visitors('+"'"+id+"'"+')" />'
	}
}
var area_content_id;
function set_area(obj, content_id) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
	  alert ("Your browser does not support AJAX!");
	  return;
	}
	area_content_id = content_id;
	var url=ROOT+"index.php?page=area&state=set_area&area_id="+obj.value;
	xmlHttp.onreadystatechange=areaSelected;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function areaSelected() {
	if (xmlHttp.readyState==4) {
		document.getElementById(area_content_id).innerHTML=xmlHttp.responseText;
	}	
}
function clear_field(obj) {
	if (obj) {
		obj.value = '';
	}
}
function set_field(obj, text) {
	if (obj) {
		if (obj.value == '') {
			obj.value = text;
		}
	}
}
function show_project(obj, href) {
	if (obj.value != 0) {
		open(href+obj.value, obj.value, 'width=670,height=700,status=no,menubar=no,scrollbars=yes,resizable=yes');
	}
}
function open_message_note(note_type) {
	open(ROOT+'message/note/'+note_type, note_type, 'width=530,height=580,status=no,menubar=no,scrollbars=yes,resizable=yes');
}
function open_credit_calculator() {
	open('http://hitelpont.hu/hitelkalkulator/index.html', 'hitel','width=370,height=500,status=no,menubar=no,scrollbars=yes,resizable=yes');
}
function submit_form(obj, form_id) {
	if (obj.checked) {
		document.getElementById(form_id).submit();
	}
}
function help(topic) {
	open(ROOT+'help/'+topic, topic, 'width=670,height=700,status=no,menubar=no,scrollbars=yes,resizable=yes');
}
function submit_customer_res(page_num, customer_id) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
	  alert ("Your browser does not support AJAX!");
	  return;
	}
	var url=ROOT+"index.php?page=customer&state=respond_customer_res&page_num="+page_num+"&customer_id="+customer_id;
	xmlHttp.onreadystatechange=respond_customer_res;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function respond_customer_res() {
	if (xmlHttp.readyState==4) {
		document.getElementById('respond_customer_res').innerHTML=xmlHttp.responseText;
	}
}
var actual_crits_id;
function submit_crits_res(page_num, crits_id) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
	  alert ("Your browser does not support AJAX!");
	  return;
	}
	actual_crits_id = crits_id;
	var url=ROOT+"index.php?page=customer&state=respond_crits_res&page_num="+page_num+"&crits_id="+crits_id;
	xmlHttp.onreadystatechange=respond_crits_res;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function respond_crits_res() {
	if (xmlHttp.readyState==4) {
		document.getElementById('respond_crits_res_'+actual_crits_id).innerHTML=xmlHttp.responseText;
	}
}
function submit_form2(form_id) {
	document.getElementById(form_id).submit();
}
function topic_display(parent_topic_id, mode) {
	var trs = document.getElementsByTagName("tr");
	for(i = 0; i < trs.length; i++) {
		if (trs[i].id) {
			id_parts = trs[i].id.split('_');
			if (id_parts[0] == parent_topic_id) {
				if (mode == 'open') {
					if ((id_parts[2]-0) == 1) {
						trs[i].className = 'selected_help';
					} else {
						if ((id_parts[1]-0) % 2 == 0) {
							trs[i].className = 'form_even_type';
						} else {
							trs[i].className = 'form_odd_type';
						}
					}
				} else if (mode == 'close') {
					trs[i].className = 'hide_2';
				}
			}
		}
	}
	if (mode == 'open') {
		var obj = document.getElementById("display_topic_icon" + parent_topic_id);
		if (obj) {
			obj.innerHTML = '<img class="tooltip_icon" src="'+ROOT+'images/active_item.gif" onclick="topic_display('+"'"+parent_topic_id+"', 'close'"+')"/>';
		}
	} else if (mode == 'close') {
		var obj = document.getElementById("display_topic_icon" + parent_topic_id);
		if (obj) {
			obj.innerHTML = '<img class="tooltip_icon" src="'+ROOT+'images/inactive_item.gif" onclick="topic_display('+"'"+parent_topic_id+"', 'open'"+')"/>';
		}
	}
}
function select_messages(obj) {
	var inputs = document.getElementsByTagName("input");
	for(i = 0; i < inputs.length; i++) {
		if (inputs[i].type == 'checkbox') {
			if (inputs[i].disabled == false) {
				if (inputs[i].id) {
					id_parts = inputs[i].id.split('_');
					if (id_parts[0] == 'msgcheck') {
						if (obj.checked) {
							inputs[i].checked = true;
						} else {
							inputs[i].checked = false;
						}
					}
				}
			}
		}
	}
}
function switch_off(id) {
	var obj = document.getElementById(id);
	if (obj && obj.checked) {
		obj.checked = false;
	}
}
function add_new_file() {
	var obj = document.getElementById("upload_file_list");
	if (obj) {
		var new_file = '<br /><i>Fájl:</i><br /><input type="file" name="upload_file_list[]" /><br /><i>Megjegyzés:</i><br/><input type="text" name="form_data[upload_file_list_text][]" value="" /><span id="upload_file_list"></span>';
		obj.innerHTML = obj.innerHTML+new_file;
		obj.id = "";
		form_display();
	}
}
function office_type_selector(obj) {
	window.location = obj.options[obj.selectedIndex].value;
}
function new_calendar(direction) {
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
	  alert ("Your browser does not support AJAX!");
	  return;
	}
	var url=ROOT+"index.php?page=calendar&state=new_calendar&direction="+direction;
	xmlHttp.onreadystatechange=showCalendar;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function showCalendar() {
	if (xmlHttp.readyState==4) {
		document.getElementById('calendar_frame').innerHTML=xmlHttp.responseText;
	}	
}
var re_to_show_id = 0;
function real_estate_to_show_edit(id) {
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
	  alert ("Your browser does not support AJAX!");
	  return;
	}
	re_to_show_id = id;
	var url=ROOT+"index.php?page=calendar&state=real_estate_to_show_edit&id="+id;
	xmlHttp.onreadystatechange=showRealEstateToShowEdit;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function showRealEstateToShowEdit() {
	if (xmlHttp.readyState==4) {
		document.getElementById(re_to_show_id).innerHTML=xmlHttp.responseText;
		Calendar.setup({inputField  : "date_to_show", ifFormat    : "%Y-%m-%d %H:%M", showsTime      :    true, button      : "date_to_show_button" });
	}	
}
function submit_real_estate_to_show_edit() {
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		alert ("Your browser does not support AJAX!");
		return;
	}
	var url=ROOT+"index.php?page=calendar&state=submit_real_estate_to_show_edit";
	var post_data = '';
	var customer_id_to_show = document.getElementById('customer_id_to_show');
	var customer_name_to_show = document.getElementById('customer_name_to_show');
	var date_to_show = document.getElementById('date_to_show');
	var re_id = document.getElementById('re_id');
	if (customer_id_to_show) {
		post_data += "form_data[customer_id_to_show]="+customer_id_to_show.options[customer_id_to_show.selectedIndex].value+"&";
	}
	if (customer_name_to_show) {
		post_data += "form_data[customer_name_to_show]="+customer_name_to_show.value+"&";
	}
	if (date_to_show) {
		post_data += "form_data[date_to_show]="+date_to_show.value+"&";
	}
	if (re_id) {
		post_data += "form_data[re_id]="+re_id.value+"&";
	}
	post_data += "form_data[re_to_show_id]="+re_to_show_id;
	xmlHttp.onreadystatechange=submitRealEstateToShowEdit;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(post_data);
}
function submitRealEstateToShowEdit() {
	if (xmlHttp.readyState==4) {
		if (xmlHttp.responseText == 'success') {
			window.location.href = ROOT+"calendar/search";
		} else {
			document.getElementById(re_to_show_id).innerHTML=xmlHttp.responseText;
		}
	}
}
function real_estate_to_show_delete(id) {
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
	  alert ("Your browser does not support AJAX!");
	  return;
	}
	re_to_show_id = id;
	var url=ROOT+"index.php?page=calendar&state=real_estate_to_show_delete&id="+id;
	xmlHttp.onreadystatechange=showRealEstateToShowDelete;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function showRealEstateToShowDelete() {
	if (xmlHttp.readyState==4) {
		document.getElementById(re_to_show_id).innerHTML=xmlHttp.responseText;
	}	
}
function submit_real_estate_to_show_delete() {
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		alert ("Your browser does not support AJAX!");
		return;
	}
	var url=ROOT+"index.php?page=calendar&state=submit_real_estate_to_show_delete";
	var post_data = '';
	post_data += "form_data[re_to_show_id]="+re_to_show_id;
	xmlHttp.onreadystatechange=submitRealEstateToShowEdit;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(post_data);
}
function submitRealEstateToShowEdit() {
	if (xmlHttp.readyState==4) {
		if (xmlHttp.responseText == 'success') {
			window.location.href = ROOT+"calendar/search";
		} else {
			document.getElementById(re_to_show_id).innerHTML=xmlHttp.responseText;
		}
	}
}
var calendar_note_id = 0;
function delete_calendar_note(id) {
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
	  alert ("Your browser does not support AJAX!");
	  return;
	}
	calendar_note_id = id;
	var url=ROOT+"index.php?page=calendar&state=delete_calendar_note&id="+id;
	xmlHttp.onreadystatechange=showCalendarNoteDelete;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function showCalendarNoteDelete() {
	if (xmlHttp.readyState==4) {
		document.getElementById('calendar_note_' + calendar_note_id).innerHTML=xmlHttp.responseText;
	}	
}
var cio_page;
var cio_id;
var cio_what;
var cio_to;
function change_image_order(page, id, what, to) {
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
	  alert ("Your browser does not support AJAX!");
	  return;
	}
	cio_page = page;
	cio_id = id;
	cio_what = what;
	cio_to = to;	
	var url=ROOT+"index.php?page="+page+"&state=change_image_order&id="+id+"&what="+what+"&to="+to;
	xmlHttp.onreadystatechange=changeImageSrc;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function changeImageSrc() {
	if (xmlHttp.readyState==4) {
		var image_src_what = document.getElementById('picture_img_' + cio_what).src;
		var image_src_to = document.getElementById('picture_img_' + cio_to).src;
		image_src_to = image_src_to.substr(prefix_length);
		image_src_what = image_src_what.substr(prefix_length);
		document.getElementById('picture_img_' + cio_what).src = image_src_to;
		document.getElementById('picture_img_' + cio_to).src = image_src_what;
		// Ha szerkesztési form
		if (document.getElementById('picture_'+cio_what+'_original_src')) {
			document.getElementById('picture_'+cio_what+'_original_src').value = image_src_to.replace("_200", "");
		}
		if (document.getElementById('picture_'+cio_what+'_src')) {
			document.getElementById('picture_'+cio_what+'_src').value = image_src_to;
		}
		if (document.getElementById('picture_'+cio_to+'_original_src')) {
			document.getElementById('picture_'+cio_to+'_original_src').value = image_src_what.replace("_200", "");
		}
		if (document.getElementById('picture_'+cio_to+'_src')) {
			document.getElementById('picture_'+cio_to+'_src').value = image_src_what;
		}
	}
}
function real_estate_to_show_entries(re_id) {
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
	  alert ("Your browser does not support AJAX!");
	  return;
	}
	var url=ROOT+"index.php?page=real_estate&state=real_estate_to_show_entries&re_id="+re_id;
	xmlHttp.onreadystatechange=displayRealEstateToShowEntries;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function displayRealEstateToShowEntries() {
	if (xmlHttp.readyState==4) {
		document.getElementById('real_estate_to_show_entries').innerHTML=xmlHttp.responseText;
	}
}

function reset_checkboxes()
{
	var checkboxes = document.getElementsByName('form[re_id][]');
	for(var i=0; i<checkboxes.length; i++)
	{
		checkboxes[i].checked = false;
	}
}

function comparethis(id, value)
{
	var compare_re_id = document.getElementById('compare').value;
	var ids = compare_re_id.split(',');
	//Már ki volt-e jelölve?
	if (inArray(value, ids))
	{
		compare_re_id = '';
		for(var i=0; i<ids.length-1; i++)
		{
			if (ids[i] != value)
			{
				compare_re_id = compare_re_id+ids[i]+',';
			}
		}
	}
	//Még nem volt kijelölve
	else
	{
		//Vizsgálat, hogy eddig hány volt kijelölve (51 mert a végén még van egy üres
		if (ids.length != 51)
		{
			compare_re_id = compare_re_id+value+',';
		}
	}
	//Új értékek mentése
	document.getElementById('compare').value = compare_re_id;
	//Ha ez volt az 50-ik kijelölés, akkor a többi legyen disabled
	if (ids.length == 50)
	{
		var checkboxes = document.getElementsByName('form[re_id][]');
		for(var i=0; i<50; i++)
		{
			if (checkboxes[i].checked != true)
			checkboxes[i].disabled = true;
		}
	
	}
	//Ha nem ez volt az 50. akkor checkboxok aktiválása visszavonása
	else
	{
		var checkboxes = document.getElementsByName('form[re_id][]');
		for(var i=0; i<50; i++)
		{
			checkboxes[i].disabled = false;
		}
	}
}

function arrayCompare(a1, a2) {
    if (a1.length != a2.length) return false;
    var length = a2.length;
    for (var i = 0; i < length; i++) {
        if (a1[i] !== a2[i]) return false;
    }
    return true;
}

function inArray(needle, haystack) {
    var length = haystack.length;
    for(var i = 0; i < length; i++) {
        if(typeof haystack[i] == 'object') {
            if(arrayCompare(haystack[i], needle)) return true;
        } else {
            if(haystack[i] == needle) return true;
        }
    }
    return false;
}