	GLOBALS = new Object;
	GLOBALS.ccp = 0;
	GLOBALS.click_cb = null;
	client_fields =
	{
		'insert_client' :
		{
			ID : 'ClientID',
			FirstName : 'FirstName',
			LastName : 'LastName',
			Email : 'Email',
			Phone : 'Phone',
			CountryID : 'Country',
			State : 'State',
			City : 'City',
			ZIP : 'ZIP',
			Address : 'Address'
		},
		'insertCheckInClient' :
		{
			ID : 'ClientID',
			FirstName : 'FirstName',
			LastName : 'LastName',
			MiddleName : 'MiddleName',
			Reservation : 'Reservation',
			Number : 'Number'
		}
	};
	billing_info_fields = '67,67,78,117,109,98,101,114,124,67,67,84,121,112,101,124,69,120,112,68,97,116,101,124,67,86,86,50,124,67,67,78,97,109,101,124,67,67,65,100,100,114,101,115,115,124,67,67,67,105,116,121,124,67,67,83,116,97,116,101,124,67,67,90,73,80,124,67,67,67,111,117,110,116,114,121';
	_z = 1;
	route_temp = {};
	dbAddPaymentSelectedRes = 0;
	dbAddPaymentSelectedGroup = '';
	dbAddPaymentSelected = 0;
	tmpAddPaymentFilter = '';
	intervalAddPaymentFilter = '';
	palette = [];
	using_custom_rate = false;
	custom_rate_price_enter = 0;
	using_custom_additions = false;
	custom_additions_price_enter = 0;
	can_use_custom = false;
	regDefaultAddress = new Array();
	total_group_price = 0;
	monthNames = [ 'Jan' , 'Feb' , 'Mar' , 'Apr' , 'May' , 'Jun' , 'Jul' , 'Aug' , 'Sep' , 'Oct' , 'Nov' , 'Dec' ];
	week_days_keys = [ 'mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun' ];
	active_tab = new Object;
	all_tabs = {guest: ['info', 'billing'], add: ['charge', 'transf']};
	silent_begin_time = new Date;
	close_calendar_by_blur_flag = false;

	try {
		document.execCommand("BackgroundImageCache", false, true); 
	} catch (err) {}
/*
	function ccc()
	{
		var tmp = document.getElementsByTagName('input');
		for (var i = 0; i < tmp.length; i++) {
			alert(tmp[i].checked);
		}
	}
*/
	function debug()
	{
		if (top.window.document.location.href.match(/\?debug/)) {
			return true;
		} else {
			return false;
		}
	}

	function myRound(x) {
		var int, frc;
		int = Math.floor(parseInt(x));
		frc = (x - int + 1) * Math.pow(10, 2);
		frc = '' + Math.ceil(frc);
		return int + + (frc.charAt(0) == "2") + "." + frc.substring(1);
	}

	function fieldAction(field, target)
	{
		var active;

		if (!GLOBALS.client_import_target_field) {
			GLOBALS.client_import_target_field = '';
		}
		active = GLOBALS.client_import_target_field;

		if (target) {
			if (active != '') {
				$('Internal_Field_' + active).style.color = '#000000';
			}
			$('Internal_Field_' + field).style.color = '#ff0000';

			GLOBALS.client_import_target_field = field;
		} else {
			if (active == '') {
				alert(global_dictionary.get('select_target_field_first'));
			} else {
				if ($('Map_' + active).value != '') {
					$('Map_' + active).value += ';';
				}
				$('Map_' + active).value += field;

				$('External_Field_' + field).style.display = 'none';
			}
		}
	}
	function clearTarget(field)
	{
		var fields, i;

		if ($('Map_' + field).value != '') {
			fields = $('Map_' + field).value.split(/;/);

			for (i = 0; i < fields.length; i++) {
				if (fields[i] != '' && $('External_Field_' + fields[i])) {
					$('External_Field_' + fields[i]).style.display = 'block';
				}
			}
			$('Map_' + field).value = '';
		}
	}

	function commentRemarkForm()
	{
		var html, d;

		html = '';

		html += '' +
				'<textarea id="comment_remark_control" cols="100" onkeyup="saveCommentRemark(this.value);" onclick="saveCommentRemark(this.value);" style="width: 450px; height: 200px;">' + $('CommentRemark').value + '</textarea>';

		d = myAlert(global_dictionary.get('comment_remark'), html);

		d.getElementById('comment_remark_control').focus();
	}
	function saveCommentRemark(txt)
	{
		var d;

		d = $w('reservation_window').document;

		if (txt == '') {
			d.getElementById('comment_remark_value').innerHTML = global_dictionary.get('no');
			d.getElementById('comment_remark_control_label').innerHTML = global_dictionary.get('add');
		} else {
			d.getElementById('comment_remark_value').innerHTML = global_dictionary.get('yes');
			d.getElementById('comment_remark_control_label').innerHTML = global_dictionary.get('edit');
		}
		d.getElementById('CommentRemark').value = txt;
	}

	function woFillPropertyControl(data, request)
	{
		var undef;
		if (typeof(undef) == typeof(request)) {
			cat = data.value;
			if (cat == 0) {
				woFillPropertyControl({error: '', cat_id: cat, prop: {0: global_dictionary.get('select_category_first')}}, false)
			} else {
				fillSelect('PropertyID', {0: global_dictionary.get('loading')})
				doLoad(true, false, 'get_wo_property_by_category', { id : cat });
			}
		} else {
			fillSelect('PropertyID', data.prop)
		}
	}

	function switchPackageActivity(el, num)
	{
		if (el.checked) {
			if (num == 1) {
				$('package_activity_box_' + 1).style.display = 'block';
				$('package_activity_box_' + 2).style.display = 'none';
			} else {
				$('package_activity_box_' + 1).style.display = 'none';
				$('package_activity_box_' + 2).style.display = 'block';
			}
		} else {
			if (num == 1) {
				$('package_activity_box_' + 1).style.display = 'none';
				$('package_activity_box_' + 2).style.display = 'block';
			} else {
				$('package_activity_box_' + 1).style.display = 'block';
				$('package_activity_box_' + 2).style.display = 'none';
			}
		}
	}

	function clCB(obj, evt)
	{
		evt = (evt) ? evt : (window.event) ? window.event : "";
		if (GLOBALS.click_cb != null && evt.shiftKey) {
			var inputs = document.getElementsByTagName('input');
			var num_cb = num_last_cb = -1;
			for(i = 0, n = inputs.length; i<n; i++) {
				if (inputs[i].getAttribute('group')) {
					if (inputs[i] == obj) num_cb = i;
					if (inputs[i] == GLOBALS.click_cb) num_last_cb = i;
					if (num_cb != -1 && num_last_cb != -1) break;
				}
			}
			var start = Math.min(num_cb, num_last_cb);
			var stop = Math.max(num_cb, num_last_cb);
			var checked = obj.checked;
			for (i = start; i <= stop; i++) {
				if (inputs[i].getAttribute('group')) {
					inputs[i].checked = checked;
				}
			}
		}
		GLOBALS.click_cb = obj;
	}

	function woFillUnitControl(data, request)
	{
		var undef;
		if (typeof(undef) == typeof(request)) {
			prop = data.value;
			if (prop == 0) {
				woFillUnitControl({ids: {0: global_dictionary.get('select_property_first')}}, false)
			} else {
				fillSelect('UnitID', {0: global_dictionary.get('loading')})
				doLoad(true, false, 'get_wo_unit_by_property', { id : prop });
			}
		} else {
			fillSelect('UnitID', data.ids)
		}
	}

	function checkFromTo(value)
	{
		if (value == '') {
			$('from_m').disabled = 1;
			$('from_d').disabled = 1;
			$('from_y').disabled = 1;
			$('calendar_control_icon_from_').style.visibility = 'hidden';
			$('to_m').disabled = 1;
			$('to_d').disabled = 1;
			$('to_y').disabled = 1;
			$('calendar_control_icon_to_').style.visibility = 'hidden';
		} else {
			$('from_m').disabled = 0;
			$('from_d').disabled = 0;
			$('from_y').disabled = 0;
			$('calendar_control_icon_from_').style.visibility = 'visible';
			$('to_m').disabled = 0;
			$('to_d').disabled = 0;
			$('to_y').disabled = 0;
			$('calendar_control_icon_to_').style.visibility = 'visible';
		}
	}

	function woUnitSelected()
	{
		if ($("UnitID").value == 0) {
			switchCheck(1);
		} else {
			switchCheck(0);
		}
	}

	function updateDeadline()
	{
		if ($("Deadlined").value == "") {
			$("Deadlined").value = $("CheckOutd").value;
		}
		if ($("Deadlinem").value == "") {
			$("Deadlinem").value = $("CheckOutm").value;
		}
		if ($("Deadliney").value == "") {
			$("Deadliney").value = $("CheckOuty").value;
		}
	}

	function switchCheck(v)
	{
		$("CheckInd").disabled = v;
		$("CheckInm").disabled = v;
		$("CheckIny").disabled = v;
		$("CheckOutd").disabled = v;
		$("CheckOutm").disabled = v;
		$("CheckOuty").disabled = v;
	}

	function fillSelect(el, data)
	{
		var sel = $(el);
		while(sel.hasChildNodes()) {
			sel.removeChild(sel.firstChild);
		}
		for (var id in data) {
			var opt = document.createElement("option");
			var text = document.createTextNode(data[id]);
			opt.appendChild(text);
			opt.setAttribute("value", id);
			sel.appendChild(opt);
		}
	}

	function paymentSelected(value, price)
	{
		try {
			if (value != '') {
				$('description_txt').disabled = 1
			} else {
				$('description_txt').disabled = 0
			}
		} catch (e) {}
		if (GLOBALS.payment_default_prices[value]) {
			$('price').value = GLOBALS.payment_default_prices[value];
		}

		var tmp = $('all_taxes').value.split(',');
		var taxes = {};
		for (var i = 0; i < tmp.length; i++) {
			taxes[tmp[i]] = false;
		}
		if (GLOBALS.payment_taxes[value]) {
			for (i = 0; i < GLOBALS.payment_taxes[value].length; i++) {
				taxes[GLOBALS.payment_taxes[value][i]] = true;
			}
		}
		for (i in taxes) {
			if ($('tax_' + i)) {
				$('tax_' + i).checked = taxes[i];
			}
		}
		if (value == GLOBALS.ccp) {
			var undef;
			if (typeof(undef) == typeof(price)) {
				showCC();
				return true;
			} else {
				showCC(price);
				return true;
			}
		} else {
			hideCC();
			return false;
		}
	}

	function myAlert(title, body)
	{
		var d;

		if ($('error_box')) {
			d = document;
		} else if (top.document.getElementById('error_box')) {
			d = top.document;
		} else {
			alert('Can\'t get error box');
			return;
		}
		d.getElementById('error_box_title').innerHTML = title;
		d.getElementById('error_box_content').innerHTML = body;
		d.getElementById('error_box').style.left = parseInt((parseInt(top.document.body.clientWidth) - 480) / 2) + 'px';
		d.getElementById('error_box').style.display = 'block';

		return d;
	}

	function showCC(price)
	{
		$('error_box').style.display = 'block';
		$('error_box').style.left = parseInt((parseInt(top.document.body.clientWidth) - 480) / 2) + 'px';
		var undef;
		if (typeof(undef) != typeof(price)) {
			$('cc_price').value = price;
		}
	}

	function hideCC()
	{
		$('error_box').style.display = 'none';
		try {
			$('cc_price').value = '';
		} catch (e) {}   
	}

	function loading(hide)
	{
		var undef;
		var html = '';
		if (typeof(undef) == typeof(hide)) {
			var tmp = getStageSize('');
			var w = 214;
			var h = 39;
			html = '' +
						'<div style="position: absolute; left: ' + parseInt((tmp[0] - w) / 2) + 'px; top: ' + parseInt((tmp[1] - h) / 3) + 'px; width: ' + w + 'px; height: ' + h + 'px; background-color: black; color: white;">' +
							'<table cellspacing="0" cellpadding="0" border="0" width="100%" height="' + h + '">' +
								'<tr>' +
									'<td style="text-align: center; vertical-align: middle;">' +
										'<img src="/pics/processing.gif" width="' + w + '" height="' + h + '" alt="" /></td>' +
								'</tr>' +
							'</table>' +
						'</div>';
		}
		$('labourer').innerHTML = html;
	}

	function calcTax(tax, price, exemption)
	{
		var ret, tmp, i, undef;

		ret = {'old_price': price, 'new_price': price, 'tax': 0};

		if (typeof(exemption) != typeof(undef)) {
			tmp = exemption.split(',');
			exemption = {};
			for (i in tmp) {
				exemption[tmp[i]] = true;
			}
		} else {
			exemption = {};
		}

//var debug = '';

		for (i in tax) {
			if (typeof(exemption[i]) == typeof(undef)) {
				tmp = price * tax[i].Percent / 100;
//debug += '- ' + tmp;
				tmp = '' + tmp;
//debug += '- ' + tmp;
				if (tmp.charAt(tmp.length - 1) == '5' && tmp.split(/\./)[1] && tmp.split(/\./)[1].length > 2) {
					tmp += '1';
//debug += '- ' + tmp;
				}
				tmp = parseFloat(tmp);
//debug += '- ' + tmp;
				tmp = tmp.toFixed(2);
//debug += '- ' + tmp;
				tmp = parseFloat(tmp);
//debug += ' - ' + tmp;
				ret['tax'] += tmp;
//debug += ' - ' + ret['tax'];
				ret['tax'] = parseFloat(ret['tax'].toFixed(2));
//debug += ' - ' + ret['tax'] + "\n\n";
			}
		}
//alert(debug);
//
		ret['new_price'] = parseFloat(price + ret['tax']).toFixed(2);

		return ret;
	}

	function switchPriceBox(type)
	{   
		switch(type){
			case "monthly" :
			type_of_period=type+'_section';
			break;
			case "weekly":
			type_of_period=type+'_section';
			break;
			default:
			type_of_period='section';
			break;
			
			
		}  
		for (var id in period_for_switcher) {
			pid = period_for_switcher[id];
			var i = 1;
			while ($('dayly_' + pid + '_box_1_' + i)) {
				$('dayly_' + pid + '_box_1_' + i).style.left = '-1000px';
				$('dayly_' + pid + '_box_2_' + i).style.left = '-1000px';
				$('weekly_' + pid + '_box_1_' + i).style.left = '-1000px';
				$('weekly_' + pid + '_box_2_' + i).style.left = '-1000px';
				$('monthly_' + pid + '_box_1_' + i).style.left = '-1000px';
				$('monthly_' + pid + '_box_2_' + i).style.left = '-1000px';
				if (type == 'dayly' || i == 1) {
					$(type + '_' + pid + '_box_1_' + i).style.left = '0px';
					$(type + '_' + pid + '_box_2_' + i).style.left = '0px';
				}
				if (i > 1 && $('strut_' + pid + '_' + i)) {
					if (type == 'dayly') {
						$('strut_' + pid + '_' + i).style.display = 'block';
					} else {
						$('strut_' + pid + '_' + i).style.display = 'none';
					}
				}
				i++;
			}
		}
		var tmp = {'dayly': 4095,'weekly': 4130,'monthly': 4165};

		$('btn_dayly_price').style.backgroundPosition = '0 -4200px';
		$('btn_weekly_price').style.backgroundPosition = '0 -4235px';
		$('btn_monthly_price').style.backgroundPosition = '0 -4270px';

		$('btn_' + type + '_price').style.backgroundPosition = '0 -' + tmp[type] + 'px';
	}

	function switchBedType(adt)
	{
		if (adt.value == 2) {
			$('bed_type_1').style.visibility = 'visible';
			$('bed_type_2').style.visibility = 'visible';
		} else {
			$('bed_type_1').style.visibility = 'hidden';
			$('bed_type_2').style.visibility = 'hidden';
		}
	}

	function CCVAddition(checked, id)
	{
		var v;
		if (checked) {
			v = 0;
		} else {
			v = 1;
		}
		try {
			$('CCVValue_' + id).disabled = v;
			$('CCVType2_' + id).disabled = v;
		} catch (e) {}
	}

	function openCustomPrice(str)
	{
		$('custom_' + str).style.display = 'block';
		$('money_' + str).style.display = 'none';
		$('custom_' + str).focus();
	}

	function closeCustomPrice(str)
	{
		$('custom_' + str).style.display = 'none';
		$('money_' + str).style.display = 'inline';
		print_money();
	}

	function paymentAction(obj)
	{
		$w('right').document.getElementById('action').value = obj.value;
		if (obj.value != '') {
			$w('right').document.forms.selected_payments.submit();
		}
		obj.value = '';
	}

	function rebuildSelect(obj)
	{
		var sel = top.$('action_select');
		var opt;
		var text;
		while(sel.hasChildNodes()) {
			sel.removeChild(sel.firstChild);
		}
		for (var id in obj) {
			opt = top.document.createElement('option');
			opt.setAttribute('value', id);
			text = top.document.createTextNode(obj[id]);
			sel.appendChild(opt);
			opt.appendChild(text);
		}
	}

	function getStageSize(str)
	{
		var x,y;

		if (self.innerHeight) {
			x = self.innerWidth;
			y = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) {
			x = document.documentElement.clientWidth;
			y = document.documentElement.clientHeight;
		} else if (document.body) {
			x = document.body.clientWidth;
			y = document.body.clientHeight;
		}

		if (str == 'x') {
			return parseInt(x);
		} else if (str == 'y') {
			return parseInt(y);
		} else {
			return [parseInt(x), parseInt(y)];
		}
	}

	function setAddressSameAsAbouve(obj)
	{
		var fields = {'Address': 'text', 'City': 'text', 'State': 'select', 'ZIP': 'text', 'Country': 'select'};
		if (!GLOBALS['tmp_cc_address']) {
			GLOBALS['tmp_cc_address'] = {};
		}

		if (obj.checked) {
			for (var i in fields) {
				GLOBALS['tmp_cc_address'][i] = $('CC' + i).value;
				if (fields[i] == 'select') {
					if ($(i).value == '') {
						$('CC' + i).value = '';
					} else {
						$('CC' + i).value = $(i).options[$(i).selectedIndex].text;
					}
				} else {
					$('CC' + i).value = $(i).value;
				}
			}
			GLOBALS['tmp_cc_address']['CCName'] = $('CCName').value;
			$('CCName').value = $('FirstName').value + ' ' + $('LastName').value;
		} else {
			for (var i in fields) {
				$('CC' + i).value = GLOBALS['tmp_cc_address'][i];
			}
			$('CCName').value = GLOBALS['tmp_cc_address']['CCName'];
		}
	}

	function wysiwyg_tmp_func(rte)
	{
		var d = GLOBALS['wysiwyg_tmp_data' + rte];
		document.getElementById('hdn'+rte).value = d.html;
		enableDesignMode(rte, d.html, d.rte_css, d.readOnly);
	}

	function getImageHTML(obj, id, width, height, alt, addition)
	{
		var ret = '';
		var undef;

		if (typeof(undef) == typeof(alt)) {
			alt = '';
		}
		if (typeof(undef) == typeof(addition)) {
			addition = 'border="0"';
		}

		if (obj.pics[id]) {
			if (obj.pics[id].width > 0) {
				width = obj.pics[id].width;
			}
			ret += '<img src="/pics/1x1.gif" width="' + width + '" height="' + height + '" alt="' + alt + '" ' + addition + ' style="background: url(\'' + obj.skin_url + obj.pics[id].skin + '\') 0px -' + ((obj.pics[id].pos - 1) * obj.pics[id].grid) + 'px;" />';
		} else {
			ret += '<img src="no_such_image" width="' + width + '" height="' + height + '" alt="' + id + '" ' + addition + ' />';
		}

		return ret;
	}

	function flipTab(group, tab)
	{
		if (active_tab[group] != tab) {
			for (var i = 0; i < all_tabs[group].length; i++) {
				$('res_tab_' + group + '_' + all_tabs[group][i]).className = 'res_inactive_tab';
				$('res_form_' + group + '_' + all_tabs[group][i]).className = 'res_inactive_form';
			}
			$('res_tab_' + group + '_' + tab).className = 'res_active_tab';
			$('res_form_' + group + '_' + tab).className = 'res_active_form';
			active_tab[group] = tab;
		}
	}

	function showCalendar(prefix, call, date, ignore_blur)
	{
		closeCalendar(prefix);
		var undef, tmp, d, m, y, html, show;

		html = '';
		show = true;

		tmp = new Date();
		d = parseInt($(prefix + 'd').value);
		if (isNaN(d)) {
			d = tmp.getDate();
		}
		m = parseInt($(prefix + 'm').value);
		if (isNaN(m)) {
			m = tmp.getMonth() + 1;
		}
		y = parseInt($(prefix + 'y').value);
		if (isNaN(y)) {
			y = tmp.getFullYear();
		}

		if (typeof(date) == typeof(undef)) {
			if ((isNaN(d) && isNaN(m) && isNaN(y)) || y == '0000') {
				date = new Date();
			} else {
				date = new Date();
				date.setDate(d);
				date.setMonth(m - 1);
				date.setYear(y);
			}
		} else {
			date = date.split('-');
			if (date[2]) {
				d = date[0];
				m = date[1];
				y = date[2];
			} else {
				if (date[0] != m || isNaN(d)) {
					show = false;
					d = 1;
				}
				m = date[0];
				y = date[1];
			}
			date = new Date();
			date.setDate(d);
			date.setMonth(m - 1);
			date.setYear(y);
		}

		html += '<iframe src="/blank.html" width="140" height="163" frameborder="0" style="position: absolute; z-index: 900;"></iframe>';
		html += '<div style="position: absolute; width: 140px; border: solid 1px black; z-index: 901; text-align: center;">';

		var pref_date;
		if (date.getMonth() == 0) {
			pref_date = '12-' + (date.getFullYear() - 1);
		} else {
			pref_date = date.getMonth() + '-' + date.getFullYear();
		}
		html += '<div id="calendar_move_right_box_' + prefix + '" class="calendar_move_right_box" onmouseover="this.style.backgroundColor = \'#666666\'; this.style.color = \'#ffffff\';" onmouseout="this.style.backgroundColor = \'#cccccc\'; this.style.color = \'#000000\';" onclick="showCalendar(\'' + prefix + '\', \'' + call + '\', \'' + pref_date + '\', true); return false;"><</div>';

		html += '<div id="calendar_month_box_' + prefix + '" class="calendar_month_box">' + monthNames[date.getMonth()] + ' ' + date.getFullYear() + '</div>';

		var next_date;
		if (date.getMonth() == 11) {
			next_date = '1-' + (date.getFullYear() + 1);
		} else {
			next_date = (date.getMonth() + 2) + '-' + date.getFullYear();
		}
		html += '<div id="calendar_move_right_box_' + prefix + '" class="calendar_move_right_box" onmouseover="this.style.backgroundColor = \'#666666\'; this.style.color = \'#ffffff\';" onmouseout="this.style.backgroundColor = \'#cccccc\'; this.style.color = \'#000000\';" onclick="showCalendar(\'' + prefix + '\', \'' + call + '\', \'' + next_date + '\', true); return false;">></div>';

		html += '<div id="calendar_week_0_box_' + prefix + '" class="calendar_week_box"><span style="color: #990000;">S</span></div>';
		html += '<div id="calendar_week_1_box_' + prefix + '" class="calendar_week_box">M</div>';
		html += '<div id="calendar_week_2_box_' + prefix + '" class="calendar_week_box">T</div>';
		html += '<div id="calendar_week_3_box_' + prefix + '" class="calendar_week_box">W</div>';
		html += '<div id="calendar_week_4_box_' + prefix + '" class="calendar_week_box">T</div>';
		html += '<div id="calendar_week_5_box_' + prefix + '" class="calendar_week_box">F</div>';
		html += '<div id="calendar_week_6_box_' + prefix + '" class="calendar_week_box"><span style="color: #990000;">S</span></div>';

		var tmp = date.getDate();
		date.setDate(1);
		var cd = date.getDay();
		var cur_month = date.getMonth();

		for (var i = 0; i < cd; i++) {
			html += '<div class="calendar_week_box">&nbsp;</div>';
		}

		for (var i = 1; i < (43 - cd); i++) {
			date.setDate(i);
			if (date.getDate() == i && cur_month == date.getMonth()) {
				if (i == d && show) {
					html += '<div id="calendar_days_box_' + i + '_' + prefix + '" class="calendar_days_box" style="background-color: #ffffff;" onmouseover="this.style.backgroundColor = \'#666666\'; this.style.color = \'#ffffff\';" onmouseout="this.style.backgroundColor = \'#ffffff\'; this.style.color = \'#000000\';" onclick="setCalendar(\'' + prefix + '\', \'' + i + '\', \'' + (date.getMonth() + 1) + '\', \'' + date.getFullYear() + '\', \'' + call + '\'); closeCalendar(\'' + prefix + '\');">' + i + '</div>';
				} else {
					html += '<div id="calendar_days_box_' + i + '_' + prefix + '" class="calendar_days_box" onmouseover="this.style.backgroundColor = \'#666666\'; this.style.color = \'#ffffff\';" onmouseout="this.style.backgroundColor = \'#dddddd\'; this.style.color = \'#000000\';" onclick="setCalendar(\'' + prefix + '\', \'' + i + '\', \'' + (date.getMonth() + 1) + '\', \'' + date.getFullYear() + '\', \'' + call + '\'); closeCalendar(\'' + prefix + '\');">' + i + '</div>';
				}
			} else {
				html += '<div class="calendar_week_box">&nbsp;</div>';
			}
		}

		html += '<div id="calendar_close_box_' + prefix + '" class="calendar_close_box" onclick="closeCalendar(\'' + prefix + '\');">' + global_dictionary.get('close') + '</div>';

		html += '</div>';

		$('calendar_box_' + prefix).innerHTML = html;
		$(prefix + 'm').focus();

		if (ignore_blur) {
			close_calendar_by_blur_flag = true;
		}
	}

	function setCalendar(prefix, d, m, y, call)
	{
		$(prefix + 'd').value = d;
		$(prefix + 'm').value = m;
		$(prefix + 'y').value = y;

		if (call != '') {
			eval(call);
		}
	}

	function closeCalendar(prefix)
	{
		if (close_calendar_by_blur_flag) {
			close_calendar_by_blur_flag = false;
			return false;
		}
		$('calendar_box_' + prefix).innerHTML = '';
		$(prefix + 'm').blur();
		return false;
	}

	function checkPackageBit()
	{
		if ($('AnyNights').checked) {
			$('Nights').disabled = true;
			$('package_stayover_bit').style.display = 'table';
		} else {
			$('Nights').disabled = false;
			if ($('Nights').value < 1) {
				$('Nights').value = 1;
			}

			if ($('Nights').value == 1) {
				$('package_stayover_bit').style.display = 'none';
			} else {
				$('package_stayover_bit').style.display = 'table';
			}
		}
	}

	function clientForm(type, img)
	{
		if (typeof(img) != 'undefined' && fileName(img.src) == '1x1.gif') {
			return;
		}
		var lock;
		var fields = ['LastName', 'FirstName', 'Address', 'ZIP', 'Country', 'State', 'City', 'Phone', 'Email'];

		switch (type) {
			case 'lock':
				lock = true;
				break;
			case 'insert':
				$('ClientID').value = '';
				lock = false;
				break;
			case 'update':
				lock = false;
				break;
			default:
				if (confirm(global_dictionary.get('update_or_create_client'))) {
					clientForm('update');
				} else {
					clientForm('insert');
				}
				return;
				break;
		}
		if (lock) {
			for (var i = 0; i < fields.length; i++) {
				$(fields[i]).readOnly = true;
				$('lock_img_' + fields[i]).src = '/pics/lock.gif';
			}
		} else {
			for (var i = 0; i < fields.length; i++) {
				$(fields[i]).readOnly = false;
				$('lock_img_' + fields[i]).src = '/pics/1x1.gif';
				if (type == 'insert' && fields[i] != 'LastName' && fields[i] != 'FirstName') {
					$(fields[i]).value = '';
				}
			}
		}
	}

	function setBillingAddress(flag)
	{
		if (flag) {

			regDefaultAddress['BAddress'] = $('BAddress').value;
			regDefaultAddress['BCity'] = $('BCity').value;
			regDefaultAddress['BState'] = $('BState').value;
			regDefaultAddress['BProvince'] = $('BProvince').value;
			regDefaultAddress['BZIP'] = $('BZIP').value;
			regDefaultAddress['BCountry'] = $('BCountry').value;

			$('BAddress').value = $('Address').value;
			$('BCity').value = $('City').value;
			$('BState').value = $('State').value;
			$('BProvince').value = $('Province').value;
			$('BZIP').value = $('ZIP').value;
			$('BCountry').value = $('Country').value;
		} else {
			$('BAddress').value = regDefaultAddress['BAddress'];
			$('BCity').value = regDefaultAddress['BCity'];
			$('BState').value = regDefaultAddress['BState'];
			$('BProvince').value = regDefaultAddress['BProvince'];
			$('BZIP').value = regDefaultAddress['BZIP'];
			$('BCountry').value = regDefaultAddress['BCountry'];
		}
	}

	function pageLoaded()
	{
		if ($('pincode')) {
			$('pincode').focus();
		} else {
			showPIN();
		}
	}

	function showPIN(action)
	{
		var tmp, undef;

		if (typeof(action) == typeof(undef)) {
			tmp = new Date();
			doLoad(true, false, 'session_expire', {silent_time: (tmp.getTime() - silent_begin_time.getTime())});
			setTimeout('showPIN();', (10 * 60 * 1000));
		} else {
			if (action == 'reload') {
				document.location.reload();
			}
		}
	}

	function in_array(value, array)
	{
		var ret = false;
		for (var i = 0; i < array.length; i++) {
			if (array[i] == value) {
				ret = true;
			}
		}
		return ret;
	}

	function copyToClipboard(string)
	{
		alert(global_dictionary.get('under_construction') + '\n\n' + global_dictionary.get('copy_text_to_clipboard') + '\n\n\n' + string);
	}

	function showPalette(name, foo)
	{
		if ($('box_' + name).innerHTML != '') {
			$('box_' + name).style.display = 'none';
			$('box_' + name).innerHTML = '';
			return;
		}

		var width = 10;
		var height = 10;
		var left = -1;
		var top = -1;
		var undef;

		var h = new Array('00', '33', '66', '99', 'cc', 'ff');
		var hConst = new Array('ff0000', '00ff00', '0000ff', 'ffff00', '00ffff', 'ff00ff');
		var color_pelete_html = '<iframe src="/blank.html" width="210" height="122" frameborder="0" style="position: absolute; left: -1px; top: -1px; z-index: 1;"></iframe>';

		for (var r = 0; r <= 1; r ++) {
			for (var i = 0; i < 6; i++) {
				var color = h[i] + h[i] + h[i];
				color_pelete_html += '<div style="position: absolute; z-index: 2; border: solid 1px #000000; background-color: #' + color + '; left: ' + left + 'px; top: ' + top + 'px;"><img src="/pics/1x1.gif" width="' + width + '" height="' + width + '" onclick="' + (typeof(undef) == typeof(foo) ? 'setColor(\'' + name + '\', \'' + color + '\');' : foo.replace(/\[COLOR\]/, color)) + '"></div>';
				left += width + 1;

				for (var j = (3 * r); j < (3 + (3 * r)); j++) {
					for (var k = 0; k < 6; k++) {

						color = h[j] + h[k] + h[i];
						color_pelete_html += '<div style="position: absolute; z-index: 2; border: solid 1px #000000; background-color: #' + color + '; left: ' + left + 'px; top: ' + top + 'px;"><img src="/pics/1x1.gif" width="' + width + '" height="' + width + '" onclick="' + (typeof(undef) == typeof(foo) ? 'setColor(\'' + name + '\', \'' + color + '\');' : foo.replace(/\[COLOR\]/, color)) + '"></div>';
						left += width + 1;

					}
				}
				left = -1;
				top += height;
			}
		}

		for (i = 0; i < palette.length; i++) {
			$('box_' + palette[i]).style.display = 'none';
			$('box_' + palette[i]).innerHTML = '';
		}
		$('box_' + name).style.display = 'block';
		$('box_' + name).innerHTML = color_pelete_html;
	}

	function setColor(name, color)
	{
		$('div_' + name).style.backgroundColor = "#" + color;
		$(name).value = '#' + color;
		$('box_' + name).style.display = 'none';
		$('box_' + name).innerHTML = '';
	}

	function reset_wo_filter()
	{
		document.location.href = '/workorders/?priority=&object=&unit=&status=&hide_7=fox&hide_7=on&hide_8=fox&hide_8=on';
	}

	function reset_al_filter()
	{
		document.location.href = '/report/log.php?user=&prop=&res=&client=&cat=&data_range=0&sm=&sd=&sy=&fm=&fd=&fy=';
	}
	
	function filterMinMax(pic, type)
	{
		var value = ''

		if (fileName(pic.src) == 'm.gif') {
			pic.src = '/pics/p.gif';
			pic.alt = global_dictionary.get('maximize');
			value = 'none';
		}else{
			pic.src = '/pics/m.gif';
			pic.alt = global_dictionary.get('minimize');
			value = 'block';
		}

		$('filter_hide').style.display = value;
	}

	function filpShare(role)
	{
		var value = '';

		if (role == 'Owner') {
			value = 'block';
		} else {
			value = 'none';
		}

		$('share_box_1').style.display = value;
		$('share_box_2').style.display = value;
		$('share_box_3').style.display = value;
	}

	function dbAddPaymentResClick(ResID, GroupID, Type, Groupleader)
	{
		var i;
		var path = '/dashboard/ifarme_add_payment.php?window=right&type=' + Type + '&';
		if (Groupleader > 0) {
			path += 'groupleader=' + Groupleader + '&';
		}
		if (dbAddPaymentSelectedRes > 0) {
			for (i = 1; i < 5; i++) {
				$('div_' + i + '_' + dbAddPaymentSelectedRes).style.backgroundColor = GLOBALS['default_selected_res_bgcolor'];
			}
		}
		if (dbAddPaymentSelectedGroup != '') {
			$('div_group_' + dbAddPaymentSelectedGroup).style.backgroundColor = GLOBALS['default_selected_res_bgcolor'];
		}
		if (GroupID == 0) {
			GLOBALS['default_selected_res_bgcolor'] = $('div_1_' + ResID).style.backgroundColor;
			for (i = 1; i < 5; i++) {
				$('div_' + i + '_' + ResID).style.backgroundColor = '#e7fbff';
			}
			top.right.location.href = path + 'id=' + ResID;

			dbAddPaymentSelectedRes = ResID;
			dbAddPaymentSelectedGroup = '';

			top.document.getElementById('group_id').value = '';
		} else {
			$('div_group_' + GroupID).style.backgroundColor = '#e7fbff';

			top.right.location.href = path + 'group_id=' + GroupID;

			dbAddPaymentSelectedRes = 0;
			dbAddPaymentSelectedGroup = GroupID;

			top.document.getElementById('group_id').value = GroupID;
		}
		top.document.getElementById('reservation_id').value = ResID;

		clearPaymentForm();
	}

	function clearPaymentForm()
	{
		top.document.getElementById('payment_id').value = '';
		top.document.getElementById('description_txt').value = '';
		top.document.getElementById('description_sel').value = '';
		top.document.getElementById('qty').value = '1';
		top.document.getElementById('price').value = '';

		var tmp = new Date((top.document.GLOBALS['mk_time_tz'] * 1000));
		top.document.getElementById('y').value = tmp.getYear();
		top.document.getElementById('m').value = tmp.getMonth() + 1;
		top.document.getElementById('d').value = tmp.getDate();

		var tax = top.document.getElementById('all_taxes').value.split(',');
		for (var i = 0; i < tax.length; i++) {
			if (top.document.getElementById('tax_' + tax[i])) {
				top.document.getElementById('tax_' + tax[i]).checked = false;
			}
		}
		top.document.getElementById('error_box').style.display = 'none';
	}

	function emptyPaymentForm()
	{
		$('payment_id').value = '';
		$('description_sel').value = '';
		$('description_txt').value = '';
		$('description_txt').disabled = 0;
		$('qty').value = '1';
		$('price').value = '';

		var tmp = new Date();

		$('y').value = tmp.getYear();
		$('m').value = (tmp.getMonth() + 1);
		$('d').value = tmp.getDate();

		var tax = $('all_taxes').value.split(',');
		for (var i = 0; i < tax.length; i++) {
			if ($('tax_' + tax[i])) {
				$('tax_' + tax[i]).checked = false;
			}
		}
		$('error_box').style.display = 'none';
	}

	function dbAddPaymentClick(ID, data)
	{
		clearPaymentForm();
		if (dbAddPaymentSelected == ID) {
			for (var i = 1; i < 8; i++) {
				$('div_' + i + '_' + ID).style.backgroundColor = '#e7fbff';
			}
			dbAddPaymentSelected = 0;
		} else {
			if (dbAddPaymentSelected > 0) {
				for (i = 1; i < 8; i++) {
					$('div_' + i + '_' + dbAddPaymentSelected).style.backgroundColor = '#e7fbff';
				}
			}
			for (i = 1; i < 8; i++) {
				$('div_' + i + '_' + ID).style.backgroundColor = '#bbf3ff';
			}
			top.document.getElementById('payment_id').value = data.ID;

			if (data.Selected == 'H') {
				top.document.getElementById('description_txt').value = data.Description;
				top.document.getElementById('description_sel').value = '';
			} else {
				top.document.getElementById('description_txt').value = '';
				top.document.getElementById('description_sel').value = data.DescriptionID;
			}
			top.document.getElementById('qty').value = data.Qty;
			top.document.getElementById('price').value = data.Price;

			for (i = 0; i < data.Taxes.length; i++) {
				top.document.getElementById('tax_' + data.Taxes[i]).checked = true;
			}

			var tmp = data.Created.split('-');
			top.document.getElementById('y').value = parseInt(tmp[0]);
			top.document.getElementById('m').value = (tmp[1].charAt(0) == 0 ? tmp[1].charAt(1) : tmp[1]);
			top.document.getElementById('d').value = (tmp[2].charAt(0) == 0 ? tmp[2].charAt(1) : tmp[2]);

			dbAddPaymentSelected = ID;
		}
	}

	function runAddPaymentFilter(n)
	{
		var el = $('filter');
		if (tmpAddPaymentFilter == el.value) {
			if (n) {
				clearInterval(intervalAddPaymentFilter);
				$('filter_form').submit();
				document.frames.right.location.href = '/dashboard/ifarme_add_payment.php';
			}
		} else {
			tmpAddPaymentFilter = el.value;
			clearInterval(intervalAddPaymentFilter);
			intervalAddPaymentFilter = setInterval('runAddPaymentFilter(1);', 700);
		}
	}

	function $(name)
	{
		return document.getElementById(name);
	}

	function $f(name)
	{
		return document.forms[name];
	}

	function $w(name)
	{
		return window.top[name];
	}

	function myParseFloat(num)
	{
		num = parseFloat(num) + '';
		var tmp = num.split('.');

		if (tmp[1]) {
			var ceil = tmp[0];
			tmp = tmp[1] + '';
			if (tmp.length == 1) {
				num = num + '0';
			} else if (tmp.length > 2) {
				var first = tmp.charAt(0);
				var second = tmp.charAt(1);
				var third = tmp.charAt(2);
				if (third >= 5) {
					if (second == '9') {
						if (first == '9') {
							ceil++;
							first = '0';
						} else {
							first++;
						}
						second = '0';
					} else {
						second++;
					}
				}
				num = ceil + '.' + first + second;
			}
		} else {
			num = num + '.00';
		}

		return num;
	}

	function fileName(str)
	{
		var tmp = str.split("/");
		return tmp[(tmp.length - 1)];
	}

	function show_hide(obj, el, value)
	{
		if (obj.checked) {
			el.style.display = value;
		} else {
			el.style.display = 'none';
		}
	}

	function insert_client(data)
	{
		for (var el in data) {
			$(el).value = data[el];
			if (el == 'Country') {
				GLOBALS['lock_tmp_country'] = data[el];
			}
			if (el == 'State') {
				GLOBALS['lock_tmp_state'] = data[el];
			}
		}
		clientForm('lock');
	}

	function rebuildPropertySelect(value)
	{
		var full_list = false;
		var total_units_count = 0;

		if (value == '') {
			full_list = true;
		}

		var sel = $('PropertySelect');
		while(sel.hasChildNodes()) {
			sel.removeChild(sel.firstChild);
		}

		for (var i in property_list) {
			if (property_list[i].id == '' || full_list || owner_property[value][property_list[i].id]) {
				if (property_list[i].id != '') {
					total_units_count++;
				}
				var opt = document.createElement("option");
				var text = document.createTextNode(property_list[i].prefix + property_list[i].name);
				opt.appendChild(text);
				opt.setAttribute("value", property_list[i].id);
				if (property_list[i].id == property_selected) {
					opt.setAttribute("selected", true);
				}
				sel.appendChild(opt);
			}
		}
		$('prop_id').value = $('PropertySelect').value;
		$('total_units_count').innerHTML = total_units_count;
		print_money();
	}

	function getClientHTML(data, selected_function, confirm)
	{
		var html = '';
		var color = 'f5f5f5';
		var info = '';
		var obj = '';
		var show = false;
		var undef;
		var show_button;

		for (var id in data) {
			if (color == 'ffffff') {
				color = 'f5f5f5';
			} else {
				color = 'ffffff';
			}
			show = true;

			obj = '{';
			for (var cf in client_fields[selected_function]) {
				if (client_fields[selected_function][cf].length > 0) {
					if (obj.length > '1') {
						obj += ', ';
					}
					obj += client_fields[selected_function][cf] + ' : ' + "'" + data[id][cf] + "'";
				}
			}
			obj += '}';

			info = '';
			var event = selected_function + '(' + obj + '); document.getElementById(\'client_selector\').innerHTML = \'\';';
			if (typeof(undef) != typeof(confirm)) {
				event = 'if (confirm(\'' + global_dictionary.get('ci_check_in') + ' ' + data[id]['FirstName'] + ' ' + data[id]['LastName'] + '?\')) {' + event + '}';
			}
			event += ' return false;';
			info += '<a href="#" onclick="' + event + '" class="client_select">';
			info += data[id]['LastName'] + ' ' + data[id]['FirstName'];
			if (typeof(data[id]['Country']) == 'string') {
				info += ' - ' + data[id]['Country'];
			}
			if (data[id]['DoNotRent'] == 'Y') {
				info += ' - <span style="color: #990000; font-weight: bold;">Marked as Do Not Rent</span>';
			}
			info += '<br />';
			if (data[id]['ZIP'].length > 0) {
				info += data[id]['ZIP'] + ', ';
			}
			if (data[id]['City'].length > 0) {
				info += data[id]['City'] + ', ';
			}
			if (data[id]['Address'].length > 0) {
				info += data[id]['Address'];
			}
			info += '</a>';

			html += '<div style="background-color: #' + color + '; padding: 5px; border-bottom: solid 1px #e5e5e5;" class="client_select">' + info + '</div>';

			show_button = ' CheckinButton(\'' + data[id]['Reservation'] + '\', \'' + data[id]['Number'] + '\', \'inline\');';
		}
		html = '<iframe src="/blank.html" frameborder="0" width="302" height="249" style="position: absolute; z-index: 100;"></iframe>' +
				'<div style="position: absolute; z-index: 102; border: solid 1px #c6c6c6; background-color: #ffffff;">' +
				'<div style="background-color: #dedede; background-image: url(\'/pics/gray_suggest.gif\');"><table width="290"><tr><td style="padding: 0px 0px 0px 6px; color: #4c4c4c; background-color: transparent; font-family: Verdana; font-size: 11px; font-weight: bold;">Suggested Clients</td><td style="text-align: right; vertical-align: middle; background-color: transparent;"><a href="#" style="color: #4c4c4c; font-family: Verdana; font-size: 9px;" onclick="document.getElementById(\'client_selector\').innerHTML = \'\';' + show_button + ' return false;">close</a></td></tr></table></div>' +
				'<div style="width: 300px; height: 230px; overflow: auto;">' +
				html + 
				'</div>' +
				'</div>';

		if (show) {
			return html;
		} else {
			return '';
		}
	}

	function showClientSelect(data)
	{
		$('client_selector').innerHTML = getClientHTML(data, 'insert_client');
	}

	function findClients()
	{
		var fn = $('FirstName');
		var ln = $('LastName');

		if (fn.value.length > 0 && ln.value.length > 0) {
			doLoad(true, false, 'get_clients', { first_name : fn.value , last_name : ln.value });
		}
	}

	function checkInClient(res, number, set_leader, check_in_if_not_fount)
	{
		fn = $('fn_' + res + '_' + number);
		ln = $('ln_' + res + '_' + number);
		mn = $('mn_' + res + '_' + number);

		if (set_leader == 0) {
			if (fn.value != '' && ln.value != '') {
				CheckinButton(res, number, 'none');
				doLoad(true, false, 'check_in_client', { res : res , number : number , fn : fn.value , ln : ln.value , mn : mn.value , check_in_if_not_fount : check_in_if_not_fount });
			}
		} else {
			CheckinButton(res, number, 'none');
			insertCheckInClientRequest({ res : res , number : number , set_leader : set_leader , fn : fn.value , ln : ln.value , mn : mn.value });
		}
	}

	function showCheckInClientSelect(data)
	{
		if (data.not_found) {
			CheckinButton(data.res, data.number, 'inline');
			if (data.check_in_if_not_fount == 'true') {
				insertCheckInClientRequest({ res : data.res , number : data.number , fn : data.fn , ln : data.ln , mn : data.mn });
			}
		} else {
			$('client_selector').innerHTML = getClientHTML(data, 'insertCheckInClient', true);
		}
	}

	function insertCheckInClient(data)
	{
		if (data.fn == '' || data.ln == '') {
			alert(global_dictionary.get('error_bad_client_name'));
			return;
		}
		if (data.Reservation && data.Number) {
			CheckinButton(data.Reservation, data.Number, 'inline');
		} else if (data.res && data.number) {
			CheckinButton(data.res, data.number, 'inline');
		}
		if (data.number == 1 && $('id_' + data.res + '_1')) {
			data.ClientID = $('id_' + data.res + '_1').value;
			data.Reservation = data.res;
			data.Number = data.number;
		}
		insertCheckInClientRequest(data);
	}

	function insertCheckInClientRequest(data)
	{
		if (GLOBALS.pre_check_in) {
			data.pre_check_in = GLOBALS.pre_check_in;
		}
		doLoad(true, false, 'insert_check_in_client', data);
	}

	function CheckinButton(res, num, val)
	{
		$('ci_button_' + res + '_' + num).style.display = val;

		if ($('cigl_button_' + res) && num == 1 && val == 'none') {
			$('cigl_button_' + res).style.display = val;
		}

		if ($('id_' + res + '_' + num) && num == 1 && val == 'none') {
			$('id_' + res + '_' + num).value = '';
		}
	}

	function setDateChange(data)
	{
		var board_instance = $('instance').value;
		var obj, i, key, tmp;

		try {
			obj = parent.document.frames['board'][board_instance];
		} catch (e) {
			obj = parent.document.getElementById('board').contentDocument[board_instance];
		}

		if (data['Error']) {
			$('sm').value = data.OldData.sm;
			$('sd').value = data.OldData.sd;
			$('sy').value = data.OldData.sy;
			$('fm').value = data.OldData.fm;
			$('fd').value = data.OldData.fd;
			$('fy').value = data.OldData.fy;
			$('PropertySelect').value = data.OldData.PropertyID;

			try {
				obj.showErrors(data.Message);
			} catch (e) {
				showError(data.Message);
			}
		} else {
			var from = obj.gridX(data.FromMktime);

			try {
				$('Deadliney').value = $('fy').value;
				$('Deadlinem').value = $('fm').value;
				$('Deadlined').value = $('fd').value;
			} catch (e) {}

			$('prop_id').value = $('PropertySelect').value;
			property_selected = $('PropertySelect').value;
			$('num').value = parseInt(data.Nights);

			if (!data.OldData || (data.OldData.Type != 6 && data.OldData.Type != 7)) {
// price
				property_price = data.NewPrice;
// transfer
				full_transfer = data.NewTransfer;

				key = 'in';
				while (key) {
					tmp = false;
					if (full_transfer[key]) {
						for (i in full_transfer[key]) {
							if (!tmp) {
								tmp = {0: global_dictionary.get('option_select')};
							}
							tmp[i] = full_transfer[key][i].name;
						}
					}
					if ($(key + '_t_id') && tmp) {
						fillSelect(key + '_t_id', tmp);
					}

					if (key == 'in') {
						key = 'out';
					} else {
						key = false;
					}
				}
// additions
				for(var i in full_addition) {
					for(var j in full_addition[i]) {
						$('addition_' + j + '_table_row').style.display = "none";
					}
				}
				full_addition = data.NewAdditions;
				for(var i in full_addition) {
					for(var j in full_addition[i]) {
						$('addition_' + j + '_table_row').style.display = "table-row";
					}
				}
// package
				package_data = data.NewPackage;
				rebuildPackageSelect();
//
				$('nights_el').innerHTML = parseInt(data.Nights);

				if (data.Rule) {
					by_rule_discount = data.Rule.DiscountID;
					full_rule = data.Rule;
					$('rule_id').value = data.Rule.ID;
				} else {
					by_rule_discount = 0;
					$('rule_id').value = 0;
				}
			}

			if (data.Reload === false) {
				$('from').value = from;
			} else {
				obj.loaded[$('PropertySelect').value] = false;
				obj.loaded[data.OldData.PropertyID] = false;
				obj.loadedFast[data.Reload] = false;
				obj.loading('');
			}
			print_money();
		}
	}

	function rebuildPackageSelect()
	{
		var i, tmp, value;

		value = $('PackageID').value;
		tmp = {0: global_dictionary.get('option_select')};
		if (package_data[$('Rate').value]) {
			for (i in package_data[$('Rate').value]) {
				tmp[i] = package_data[$('Rate').value][i].Title;
			}
		}
		fillSelect('PackageID', tmp);
		$('PackageID').value = value;
	}

	function showError(str)
	{
		alert(global_dictionary.get('error') + ':' + "\n\n" + str);
	}

	function setToday()
	{
		var date = new Date();

		var d = date.getDate();
		var m = date.getMonth() + 1;
		var y = date.getFullYear();

		$('day').value = d;
		$('month').value = m;
		$('year').value = y;
	}

	function moveToNextField(el, max, next)
	{
		if (el.value.length >= max) {
			$(next).focus();
		}
	}

	function humanRules()
	{
		var ret = '';
		var tmp;
		var criteria = $('NewCriteria').value;

		if (!GLOBALS['selected_criteria']) {
			GLOBALS['selected_criteria'] = '';
		}
		if (GLOBALS['selected_criteria'] != criteria) {
			if (criteria != '') {
				if (GLOBALS['selected_criteria']) {
					$('criteria_' + GLOBALS['selected_criteria'] + '_box').style.display = 'none';
				}
				GLOBALS['selected_criteria'] = criteria;
				$('criteria_' + criteria + '_box').style.display = 'block';
			} else {
				$('criteria_' + GLOBALS['selected_criteria'] + '_box').style.display = 'none';
			}
			$('NewValue').value = $('criteria_' + criteria + '_value').value;
		}
		var v = $('NewValue').value;
		if (v == '') {
			v = '[X]';
		}
		var d = discount_data[$('NewDiscount').value];
		if (d == undefined) {
			d = '[Y]';
		}

		if (criteria == 'wr') {
			for (var i = 1; i <= 7; i++) {
				$('WeekDays_' + i).checked = false;
			}
			if (v == 1) {
				$('WeekDays_5').checked = true;
			} else {
				$('WeekDays_6').checked = true;
			}
			wds = [1, 2, 3, 4, 5, 6, 7];
			$('week_days_title_box').style.color = '#999999';
		} else {
			var wds = [];
			for (var i = 1; i <= 7; i++) {
				if ($('WeekDays_' + i).checked) {
					wds.push(i);
				}
			}
			$('week_days_title_box').style.color = '#000000';
		}
		if (criteria == '') {
			$('human_view').innerHTML = '&nbsp;';
		} else {
			$('human_view').innerHTML = parseRuleTpl(criteria_data[criteria], v, d, $('m_from').value, $('d_from').value, $('m_to').value, $('d_to').value, $('OnResTime').value, wds);
		}
	}

	function parseRuleTpl(ret, v, d, m_from, d_from, m_to, d_to, on_res_time, wds)
	{
		ret = ret.replace(/\[:VALUE:\]/, v);
		ret = ret.replace(/\[:DISCOUNT:\]/, d);

		tmp = ret.match(/\[:IF \((\d+)\) ([^:]+):\]/);
		first_replaced = false;
		while (tmp) {
			if (tmp[1] == v) {
				ret = ret.replace(/\[:IF \((\d+)\) ([^:]+):\]/, tmp[2]);
			} else if (v == '[X]' && !first_replaced) {
				ret = ret.replace(/\[:IF \((\d+)\) ([^:]+):\]/, '[X]');
				first_replaced = true;
			} else {
				ret = ret.replace(/\[:IF \((\d+)\) ([^:]+):\]/, '');
			}
			tmp = ret.match(/\[:IF \((\d+)\) ([^:]+):\]/);
		}
		if (m_from != 0 && d_from != 0 && m_to != 0 && d_to != 0) {
			var df = (d_from.length == 1 ? '0' : '') + d_from + '.' + (m_from.length == 1 ? '0' : '') + m_from;
			var dt = (d_to.length == 1 ? '0' : '') + d_to + '.' + (m_to.length == 1 ? '0' : '') + m_to;

			ret += ' ' + global_dictionary.get('rule_period').replace(/\[:FROM:\]/, df).replace(/\[:TO:\]/, dt);

			if (on_res_time == 'Y') {
				ret += ' ' + global_dictionary.get('option_time_frame') + ' - ' + global_dictionary.get('period_to_rent') + '.';
			} else {
				ret += ' ' + global_dictionary.get('option_time_frame') + ' - ' + global_dictionary.get('period_to_book') + '.';
			}
		}
		if (typeof(wds) == 'string') {
			wds = wds.split(/,/);
		}
		if (wds.length < 7) {
			wds_text = '';
			for (var i = 0; i < wds.length; i++) {
				if (wds_text != '') {
					wds_text += ', ';
				}
				wds_text += global_dictionary.get('week_' + week_days_keys[(wds[i] - 1)]);
			}
			ret += ' ' + global_dictionary.get('checkin_weekdays') + ' ' + wds_text + '.';
		}
		return ret;
	}

	function dateChanged(x, id)
	{
		if (_z == 1) {
			_z = setTimeout('dateChanged(1, "' + id + '");', 3000);
		}
		if (x == 1) {
			_z = 1;

			var sm, sd, sy, fm, fd, fy, p, min_stay, max_stay, undef;

			sm = $('sm').value;
			sd = $('sd').value;
			sy = $('sy').value;
			fm = $('fm').value;
			fd = $('fd').value;
			fy = $('fy').value;
			p = $('PropertySelect').value;

			if (typeof(property_list) == typeof(indef)) {
				min_stay = 0;
				max_stay = 0;
			} else {
				min_stay = property_list['p' + p].min_stay;
				max_stay = property_list['p' + p].max_stay;
			}

			if ($('Rate')) {
				var r = $('Rate').value;
			} else {
				var r = 0;
			}
			var stop = false;
			if (min_stay > 0 || max_stay > 0) {
				var s = new Date();
				s.setYear(sy);
				s.setMonth(sm);
				s.setDate(sd);
				s.setHours(0);
				s.setMinutes(0);
				s.setSeconds(1);
				var f = new Date();
				f.setYear(fy);
				f.setMonth(fm);
				f.setDate(fd);
				f.setHours(0);
				f.setMinutes(0);
				f.setSeconds(1);
				var tmp = Math.round((f.getTime() - s.getTime()) / 86400000);
				if (min_stay > 0 && tmp < min_stay) {
					if (!confirm(global_dictionary.get('error_board_min_stay', [min_stay]) + '. ' + global_dictionary.get('are_you_sure'))) {
						stop = true;
					}
				}
				if (max_stay > 0 && tmp > max_stay) {
					if (!confirm(global_dictionary.get('error_board_max_stay', [max_stay]) + '. ' + global_dictionary.get('are_you_sure'))) {
						stop = true;
					}
				}
				if (stop) {
					s = from_str.split('-');
					$('sd').value = parseInt(s[2]);
					$('sm').value = parseInt(s[1]);
					$('sy').value = parseInt(s[0]);
					f = to_str.split('-');
					$('fd').value = parseInt(f[2]);
					$('fm').value = parseInt(f[1]);
					$('fy').value = parseInt(f[0]);
					$('PropertySelect').value = $('prop_id').value;
					return;
				}
			}

			if (id == '' || id == '0') {
				tmp = {from: sy + '-' + sm + '-' + sd, to: fy + '-' + fm + '-' + fd, prop: p, rate: r, min_stay: min_stay, max_stay: max_stay};
				doLoad(true, false, 'date_change', tmp);
			} else {
				var pers;
				try {
					pers = $('ComingAdults').value > $('NormalAdult').value ? $('NormalAdult').value : $('ComingAdults').value;
				} catch (e) {
					pers = 0;
				}
				doLoad(true, false, 'res_date_change', {from: sy + '-' + sm + '-' + sd, to: fy + '-' + fm + '-' + fd, prop: p, res_id: id, rate: r, min_stay: min_stay, max_stay: max_stay});
			}
		}
	}

	function fillTimeField(el_h, el_m, el_ap, el_res)
	{
		var h, m;

		h = $(el_h).value;
		m = $(el_m).value;
		if (h.charAt(0) == '0' && h.charAt(1)) {
			h = h.charAt(1);
		}
		if (m.charAt(0) == '0' && m.charAt(1)) {
			m = m.charAt(1);
		}
		h = parseInt(h);
		m = parseInt(m);
		try {
			var ap = $(el_ap).value;
			if (ap == "am") {
				if (h == 12) {
					h = 0;
				}
			} else {
				if (h != 12) {
					h = h + 12;
				}
			}
		} catch(e) {}

		h = h.toString();
		m = m.toString();
		if (h.charAt(1) == '') {
			h = '0' + h;
		}
		if (m.charAt(1) == '') {
			m = '0' + m;
		}
		var el = $(el_res);
		el.value = h + ":" + m;
	}

	function openProperty(pic, name, id)
	{
		obj = $(name);

		if (fileName(pic.src) == 'p2.gif') {
			pic.src = '/pics/m2.gif';
			obj.style.display = 'block';
			doLoad(true, false, 'set_opened_property', id);
		} else {
			pic.src = '/pics/p2.gif';
			obj.style.display = 'none';
			doLoad(true, false, 'set_opened_property', -id);
		}
	}

	function flipClientPaymentDetails(pic, id)
	{
		if (fileName(pic.src) == 'p2.gif') {
			pic.src = '/pics/m2.gif';
			$('details_' + id + '_box_1').style.display = 'block';
			$('details_' + id + '_box_2').style.display = 'block';
		} else {
			pic.src = '/pics/p2.gif';
			$('details_' + id + '_box_1').style.display = 'none';
			$('details_' + id + '_box_2').style.display = 'none';
		}
	}

	function var_dump(obj, level)
	{
		var out = '';
		var space = '';
		var under;
		if (typeof(level) == typeof(under)) {
			level = 1;
		}
		for (var i = 0; i < level; i++) {
			space += ' ';
		}

		for (var id in obj) {
			if (typeof obj[id] == 'object') {
				out += space + 'OBJECT "' + id + '"' + " \n " + var_dump(obj[id], ++level) + "";
			} else {
				out += space + id + ' = ' + obj[id] + "\n";
			}
		}

		return out + "\n";
	}

	function checkRouteProperty(type, id)
	{
		var sel = $('route_select_' + id);
		var txt = $('route_input_' + id);
		var hid = $('route_hide_' + id);

		switch (type) {
			case 'sel':
				if (sel.value == 'pers') {
					if (parseInt(hid.value) > 1) {
						route_temp[id] = parseInt(txt.value);
					}
					txt.value = '1';
					hid.value = '1';
					txt.disabled = 1;
				} else {
					txt.value = hid.value = (route_temp[id] ? route_temp[id] : 2);
					txt.disabled = 0;
				}
				break;
			case 'txt':
				if (parseInt(txt.value) < 2) {
					sel.value = 'pers';
					txt.value = '1';
					hid.value = '1';
					txt.disabled = 1;
				} else {
					sel.value = 'route';
					hid.value = parseInt(txt.value);
				}
				break;
			default:
				showError('Unknown Route type');
				break;
		}
	}

	function setPackageDays(value, id)
	{
		for (var i = 1; i <= 7; i++) {
			$('Activity[' + id + '][' + i + ']').checked = value;
		}
	}

	function notVerified()
	{
		$('CCValid').value = 'N';
		$('valid_form_check_lable').innerHTML = '';
		$('valid_form_button').style.display = 'block';
		$('res_tab_guest_billing').innerHTML = global_dictionary.get('billing_info') + ' (<span style="color: #990000;">' + global_dictionary.get('not_checked') + '</span>)<div>';
	}

	function checkBillingInfo(step)
	{
		if (step == 'query') {
			var tmp = billing_info_fields.split(',');
			var str = '';
			for (var i = 0; i < tmp.length; i++) {
				str += String.fromCharCode(tmp[i]);
			}
			str = str.split('|');
			var obj = {};
			for (var i = 0; i < str.length; i++) {
				if (($(str[i]).value == '' && i != 7) || ($(str[7]).value == '' && $(str[9]).value == 1)) {
					try {
						parent.document.frames['board']['board'].showErrors(global_dictionary.get('fill_all_fields'));
					} catch (e) {
						parent.document.getElementById('board').contentDocument['board'].showErrors(global_dictionary.get('fill_all_fields'));
					}
					return;
				}
				obj[str[i]] = $(str[i]).value;
			}
// By luhn appendix /////////////////////////////////////////////////
			if (GLOBALS.required_billing_info == 'luhn' || GLOBALS.required_billing_info == 'none_luhn') {
				if (checkByLuhn($(str[0]).value)) {
					$('res_tab_guest_billing').innerHTML = global_dictionary.get('billing_info') + ' (<span style="color: #009900;">' + global_dictionary.get('valid') + '</span>)<div>';
					$('CCValid').value = 'Y';
				} else {
					$('res_tab_guest_billing').innerHTML = global_dictionary.get('billing_info') + ' (<span style="color: #990000;">' + global_dictionary.get('invalid') + '</span>)<div>';
					$('CCValid').value = 'N';
				}
				return;
			}
/////////////////////////////////////////////////////////////////////
			$('valid_form_check_lable').innerHTML = 'Validating...';
			$('valid_form_button').style.display = 'none';

			doLoad(true, false, 'check_card', obj);
		} else {
			$('valid_form_check_lable').innerHTML = '';
			$('valid_form_button').style.display = 'block';

			if (step.result) {
				$('res_tab_guest_billing').innerHTML = global_dictionary.get('billing_info') + ' (<span style="color: #009900;">' + global_dictionary.get('valid') + '</span>)<div>';
				$('CCValid').value = 'Y';
			} else {
				$('res_tab_guest_billing').innerHTML = global_dictionary.get('billing_info') + ' (<span style="color: #990000;">' + global_dictionary.get('invalid') + '</span>)<div>';
				$('CCValid').value = 'N';
			}
		}
	}

	function checkByLuhn(num)
	{
		var sum, mul, l, i, digit, tproduct;

		sum = 0;
		mul = 1;
		l = num.length;

		for (i = 0; i < l; i++) {
			digit = num.substring(l - i - 1, l - i);
			tproduct = parseInt(digit, 10) * mul;
			if (tproduct > 9) {
				sum += tproduct - 9;
			} else {
				sum += tproduct;
			}
			if (mul == 1) {
				mul = 2;
			} else {
				mul = 1;
			}
		}
		if ((sum % 10) == 0) {
			return true;
		} else {
			return false;
		}
	 }

	function doLoad(force, cach, type, element)
	{
		var req = new Subsys_JsHttpRequest_Js();

		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				if (req.responseJS) {
					switch (type) {
						case 'check_card':
							checkBillingInfo(req.responseJS);
							break;
						case 'set_opened_property':
							if (req.responseJS != true) {
								alert('Unknown error, state wasn\'t saved');
							}
							break;
						case 'get_clients':
							showClientSelect(req.responseJS);
							break;
						case 'date_change':
							setDateChange(req.responseJS);
							break;
						case 'res_date_change':
							setDateChange(req.responseJS);
							break;
						case 'check_in_client':
							showCheckInClientSelect(req.responseJS);
							break;
						case 'check_in_children':
							if (req.responseJS) {
								document.body.focus();
							}
							break;
						case 'insert_check_in_client':
							if (req.responseJS) {
								document.location.href = document.location.href;
							}
							break;
						case 'gsp':
							if (req.responseJS) {
								$('price_1').innerHTML = req.responseJS.data.price_1;
								$('price_2').innerHTML = req.responseJS.data.price_2;
								$('num').innerHTML = $('units').value;
							}
							break;
						case 'refresh_dashboard':
							if (req.responseJS == 'reload') {
								document.location.href = document.location.href;
							}
							can_check_refresh = true;
							break;
						case 'get_wo_property_by_category':
							woFillPropertyControl(req.responseJS.data, false)
							break;
						case 'get_wo_unit_by_property':
							woFillUnitControl(req.responseJS, false)
							break;
						case 'session_expire':
							showPIN(req.responseJS.data)
							break;
						default:
							alert('unknown type');
							break;
					}
				}
//				$('debug').innerHTML = req.responseText;
			}
		}

		req.caching = cach;
		req.open('POST', '/load.php', true);
		req.send({ data: element, act: type });
	}


// Дима, что это за порно, посмтори на остальной код, пиши пожалуйста по стандарту, очень неудобно...

	function copyfields(id,next,name_id){
	var checked_id='';	
	if(typeof name_id=='undefined' || name_id==null)
	{
		 name_id='section';
	}	 
	else if(name_id!='checked_section')
		{
		 name_id=type_of_period;
		 if(name_id=='section')
		 checked_id='checked_section';
	     }
	else
	 {
		name_id='checked_section';
	 }     

	var table= document.getElementById('sections'); 
	var tr=table.getElementsByTagName('table'); 
	var Otable=document.getElementById(name_id+''+id);
	var Oinputs = Otable.getElementsByTagName('input'); 
	var Oselects =Otable.getElementsByTagName('select');
	var inputs;
	var selects;
	var inputTable;
	if(next==1)
	cols=id+2;
	else
	cols=tr.length;
    for(var i=id; i<cols; i++){
    if(typeof document.getElementById(name_id+i) !='undefined' && document.getElementById(name_id+i)!=null) 
    {
    	inputTable=document.getElementById(name_id+i);
	    inputs = inputTable.getElementsByTagName('input'); 	    
	    selects = inputTable.getElementsByTagName('select');
	    for(var j=0; j<Oinputs.length; j++){
		    if(Oinputs[j].getAttribute('type')=='checkbox'){
				if(Oinputs[j].checked==true)
				{ 
					inputs[j].checked=true;
				}
		    
			    else
			    {
		    		inputs[j].checked=false;
				}
			}
			else
			inputs[j].value=Oinputs[j].value;	
			if(Oinputs[j].hasAttribute('disabled')!=true) 
			{
				inputs[j].removeAttribute('disabled');  	
		    }
		    else
		  	  inputs[j].setAttribute('disabled','disabled');
		}
	    for( j=0; j<Oselects.length; j++){
			selects[j].value=Oselects[j].value;	
			
	    }
	     
    } 
    if(checked_id=='checked_section'){		
	copyfields(id,next,checked_id);	
    }
		
	}	
	}

	document.GLOBALS = GLOBALS;
	document.loading = loading;