	GLOBALS = new Object;
	GLOBALS.list_refresh_interval = 30 * 1000;
	GLOBALS.calendar_opened = false;
	document.GLOBALS = GLOBALS;
	monthNames = [ 'Jan' , 'Feb' , 'Mar' , 'Apr' , 'May' , 'Jun' , 'Jul' , 'Aug' , 'Sep' , 'Oct' , 'Nov' , 'Dec' ];
	preSelectedCategoryID = 0;
	close_calendar_by_blur_flag = false;

	function numberFormat(number, decimal_count, decimal_separator, thousands_separator)
	{
		var dc, ds, ts, tmp, parts;
		var p1 = '';
		var p2 = '';
		var k = 0;

		if (typeof(decimal_count) == 'undefined') {
			dc = 2;
		} else {
			dc = decimal_count;
		}
		if (typeof(decimal_separator) == 'undefined') {
			ds = '.';
		} else {
			ds = decimal_separator;
		}
		if (typeof(thousands_separator) == 'undefined') {
			ts = ',';
		} else {
			ts = thousands_separator;
		}

		tmp = parseFloat(number).toString();
		parts = tmp.split('.');

		for (var i = (parts[0].length - 1); i >= 0; i--) {
			p1 = parts[0].charAt(i) + p1;
			k++;
			if (k == 3 && i > 0) {
				p1 = ts + p1;
				k = 0;
			}
		}

		if (parts[1]) {
			for (i = 0; i < dc; i++) {
				if (parts[1].charAt(i)) {
					p2 += parts[1].charAt(i);
				} else {
					p2 += '0';
				}
			}
		} else {
			p2 = '00';
		}

		return p1 + ds + p2;
	}

	function titleCh()
	{
		var len = 255 - $('Title').value.length;
		if (len == 0) {
			$('TitleLen').style.color = '#ff0000';
		} else if (len > 0) {
			$('TitleLen').style.color = '#2d659e';
		} else {
			alert('Title length is greater then 255 characters.\nTitle will be cut of.');
			$('Title').value = $('Title').value.substring(0, 255);
			titleCh();
		}
		$('TitleLen').innerHTML = len + ' characters remaining';
		window.setTimeout("titleCh()", 300);
	}

	function print_category_tree(styleIndex)
	{
		if (!styleIndex) styleIndex = auction_type;
		var style = new Array('guu','self');
			style['guu'] = {firstColor: '#E9F4FF', secondColor: '#F6FBFF', selectedColor: '#c0c0c0'};
			style['self'] = {firstColor: '#D7F5B4', secondColor: '#F3F2DE', selectedColor: '#c0c0c0'};

		var html = '';
		var inc = 0;
		for (var i in category_data) {



			var d = category_data[i];


			if (d.Visible) {

				inc++;

				if(d.ID == selected_category){

						var bgcolor = style[styleIndex].selectedColor;

				}else{
						if(inc%2===1){
							var bgcolor = style[styleIndex].firstColor;
						}else{
							var bgcolor = style[styleIndex].secondColor;
						}
				}

				html += '<div style="padding: 3px 3px 3px ' + (d.Level * 10) + 'px; background-color:' + bgcolor +';">';

				if (d.Child) {

					if (d.Opened) {
						html += '<img src="/pics/ab/ac_minus.gif" width="10" heiht="13" style="cursor: hand; cursor: pointer;" alt="" border="0" onclick="categoryClick(' + d.ID + ', false);"/>';
					} else {
						html += '<img src="/pics/ab/ac_plus.gif" width="10" heiht="13" style="cursor: hand; cursor: pointer;" alt="" border="0" onclick="categoryClick(' + d.ID + ', true);"/>';
					}

				} else {
					html += '<img src="/pics/arrow_next_level.gif" width="10" heiht="11" alt="" border="" />';
				}

				if (d.ID == selected_category) {
					html += '&nbsp;<strong>' + d.Title + '</strong></div>';
				} else {
					html += '&nbsp;<a href="/auction/index.php?category_id=' + d.ID + '"">' + d.Title + '</a></div>';
				}
			}
		}

		$('category_tree_box').innerHTML = html;
	}
	function categoryClick(id, close)
	{
		for (var i in category_data) {
			if (childOf(category_data[i].ID, id)) {
				if (category_data[i].PID != id) {
					if (category_data[category_data[i].PID].Opened) {
						category_data[i].Visible = close;
					}
				} else {
					category_data[i].Visible = close;
				}
			}
		}
		category_data[id].Opened = close;
		print_category_tree();
		doLoad(true, false, "remember_tree_state", {id: id, visible: (close ? 'false' : 'true')});
	}
	function childOf(cid, id)
	{
		if (cid == 0) {
			if (cid == id) {
				return true;
			} else {
				return false;
			}
		}
		if (category_data[cid].PID == id) {
			return true;
		} else {
			return childOf(category_data[cid].PID, id);
		}
	}

	function printFee()
	{
		var tmp;
		var fee = 0;
		var price = 0;
		var tmp_price = 0;
		var html = '';
		var total_html = '';
		var executeInterval = 300;
		var cat_count = 0;
		var details = '';
// Categories fee
/*
		tmp = 0;
		for (var i in selectedCategories) {
			tmp++;
		}
		tmp -= fee_values.FreeCategory;
		if (tmp > 0) {
			price += fee_values.Category * tmp;
		}

		for (var i in selectedCategories) {
			cat_count++;
		}
*/
		cat_count = $('selected_cat_field').value.split(',').length;
		if (!cat_count) {
			cat_count = 1;
		}
// Opening Bid fee
		tmp_price = 0;
		tmp = myParseFloat($('OpeningBid').value);
		if (parseFloat(tmp) != parseFloat($('OpeningBid').value) && tmp != 0) {
			$('OpeningBid').value = tmp;
		}
		if (tmp > 10000000) {
			showError('Invalid Opening Bid value. Max is 10,000,000.00');
			$('OpeningBid').value = '10000000.00';
			setTimeout('printFee();', executeInterval);
			return;
		}
		for (var i in fee_values.Bid) {
			if (tmp >= fee_values.Bid[i].StartAmount && tmp <= fee_values.Bid[i].EndAmount) {
				if (fee_values.Bid[i].Fee.value) {
					fee = tmp * fee_values.Bid[i].Fee.value / 100;
					if (fee_values.Bid[i].Fee.up_to && fee > fee_values.Bid[i].Fee.up_to) {
						fee = fee_values.Bid[i].Fee.up_to;
					}
				} else {
					fee = fee_values.Bid[i].Fee;
				}
				price += fee * cat_count;
				tmp_price += fee * cat_count;
			}
		}
		if (tmp_price > 0) {
			html += 'Listing Fee: $' + myParseFloat(tmp_price) + '<br />';
		}
		details += tmp_price + ';';
// Reserve fee
		tmp_price = 0;
		if ($('PriceType').value == 'auction') {
			tmp = myParseFloat($('Reserve').value);
			if (parseFloat(tmp) != parseFloat($('Reserve').value) && tmp != 0) {
				$('Reserve').value = tmp;
			}
			if (tmp > 10000000) {
				showError('Invalid Reserve value. Max is 10,000,000.00');
				$('Reserve').value = '10000000.00';
				setTimeout('printFee();', executeInterval);
				return;
			}
			for (var i in fee_values.Bid) {
				if (tmp >= fee_values.Bid[i].StartAmount && tmp <= fee_values.Bid[i].EndAmount) {
					if (fee_values.Bid[i].ReserveFee.value) {
						fee = tmp * fee_values.Bid[i].ReserveFee.value / 100;
						if (fee_values.Bid[i].ReserveFee.up_to && fee > fee_values.Bid[i].ReserveFee.up_to) {
							fee = fee_values.Bid[i].ReserveFee.up_to;
						}
					} else {
						fee = fee_values.Bid[i].ReserveFee;
					}
					price += fee * cat_count;
					tmp_price += fee * cat_count;
				}
			}
			if (tmp_price > 0) {
				html += 'Reserve Fee: $' + myParseFloat(tmp_price) + '<br />';
			}
		}
		details += tmp_price + ';';
// Featured fee
		tmp_price = 0;
		if ($('Featured').checked) {
			tmp_price = fee_values.Featured * cat_count;
			price += tmp_price;
			html += 'Featured: $' + myParseFloat(tmp_price) + '<br />';
		}
		details += tmp_price + ';';
// Highlighted fee
		tmp_price = 0;
		if ($('Highlighted').checked) {
			tmp_price = fee_values.Highlighted * cat_count;
			price += tmp_price;
			html += 'Highlighted: $' + myParseFloat(tmp_price) + '<br />';
		}
		details += tmp_price + ';';
// Bold fee
		tmp_price = 0;
		if ($('Bold').checked) {
			tmp_price = fee_values.Bold * cat_count;
			price += tmp_price;
			html += 'Bold: $' + myParseFloat(tmp_price) + '<br />';
		}
		details += tmp_price + ';';
// Italic fee
		tmp_price = 0;
		if ($('Italic').checked) {
			tmp_price = fee_values.Italic * cat_count;
			price += tmp_price;
			html += 'Italic: $' + myParseFloat(tmp_price) + '<br />';
		}
		details += tmp_price + ';';
// Border fee
		tmp_price = 0;
		if ($('Border').checked) {
			tmp_price = fee_values.Border * cat_count;
			price += tmp_price;
			html += 'Border: $' + myParseFloat(tmp_price) + '<br />';
		}
		details += tmp_price + ';';
/////////////
		price = myParseFloat(price);
		if (price > 0) {
			total_html = 'Total: $' + myParseFloat(price);
			if (current_fee > 0 && current_fee != price) {
				total_html += ' (Current fee $' + current_fee + ')';
			}
		}
		if (html != '' && price > 0) {
			$('fee_box').innerHTML = html;
			$('total_fee_box').innerHTML = total_html;
		} else {
			$('fee_box').innerHTML = '';
			$('total_fee_box').innerHTML = 'Total: $0.00';
		}
		$('FeeDetails').value = details;
		$('Fee').value = price;
		setTimeout('printFee();', executeInterval);
		return;
	}

	function preSelectCategory(id, direction)
	{
		if (preSelectedCategoryID != 0) {
			$('category_box_' + preSelectedCategoryID).style.backgroundColor = '#ffffff';
		}
		$('selected_cat_button').src = '/pics/arrow_1_' + direction + '.gif';
		preSelectedCategoryID = id;
	}

	function selectCategory2()
	{
		var obj = $('category_selector');
		var rebuild = false;

		for (var i = 0; i < obj.length; i++) {
			if (obj.options[i].selected) {
				if (categories[obj.options[i].value].Level == 1) {
					alert('First level categories are not selectable');
					continue;
				}
				if (disabledCategoriesFull) {
					alert('You can\'t remove this category');
				} else {
					selectedCategories[obj.options[i].value] = 1;
					rebuild = true;
				}
			}
		}
		if (rebuild) {
			printCategoryControl2();
		}
	}

	function unselectCategory2()
	{
		var obj = $('category_selected');
		var rebuild = false;

		for (var i = 0; i < obj.length; i++) {
			if (obj.options[i].selected) {
				if (disabledCategories[obj.options[i].value] || disabledCategoriesFull) {
					alert('You can\'t remove this category');
				} else {
					selectedCategories[obj.options[i].value] = 0;
					rebuild = true;
				}
			}
		}
		if (rebuild) {
			printCategoryControl2();
		}
	}

	function printCategoryControl2()
	{
		var opt;
		var text;
		var selected = '';
		var obj = $('category_selector');
		var obj2 = $('category_selected');

		delOption(obj, 'all');
		delOption(obj2, 'all');

		for (var i in categories) {
			opt = document.createElement('option');
			opt.setAttribute('value', i);

			text = '';
			if (selectedCategories[i]) {
				if (selected != '') {
					selected += ', ';
				}
				selected += i;
				obj2.appendChild(opt);
				text += full_named_categories[i].Title;
			} else {
				obj.appendChild(opt);
				for (var j = 1; j < categories[i].Level; j++) {
					text += '> ';
				}
				text += categories[i].Title;
			}

			text = document.createTextNode(text);
			opt.appendChild(text);
//			opt.style.marginLeft = (10 * (categories[i].Level - 1)) + 'px';
		}

		$('selected_cat_field').value = selected;
	}

	function printCategoryControl(disabled)
	{
		var html_1 = '';
		var html_2 = '';
		var d;
		var event;
		var tmp = [];
		var count = 0;
		var pos = '';

		if (typeof(disabled) == 'undefined') {
			disabled = false;
		}

//	alert(disabled + ' - ' + typeof(disabled));

		for (var i in categories) {
			d = (categories[i].Level - 1) * 10;
			event = '';
			pos = 'position: absolute; left: 0px; top: ' + (count * 20) + 'px; height: 20px;';
			if (selectedCategories[i]) {
				tmp.push(i);
				if (categories[i].Level > 1) {
					if (disabledCategories[i] || disabled) {
						event = ' onclick="alert(\'You can\\\'t remove this category\');"';
					} else {
						event = ' ondblclick="categorySelector();" onclick="preSelectCategory(' + i + ', \'left\');" onmouseover="hilightCategory(' + i + ', \'on\');" onmouseout="hilightCategory(' + i + ', \'off\');"';
					}
				}
				html_1 += '<div style="' + pos + ' width: 190px; z-index: 2;"><img src="/pics/1x1.gif" width="190" height="20" alt=""' + event + ' /></div>' +
							'<div id="category_box_' + i + '" style="' + pos + ' width: ' + (190 - d) + 'px; z-index: 1; overflow: hidden; padding: 0px 0px 0px ' + d + 'px;">' + categories[i].Title + '</div>';
				html_2 += '<div style="' + pos + ' width: ' + (190 - d) + 'px; z-index: 1; overflow: hidden; padding: 0px 0px 0px ' + d + 'px; color: 999999;">' + categories[i].Title + '</div>';
			} else {
				if (categories[i].Level > 1) {
					if (disabled) {
						event = ' onclick="alert(\'You can\\\'t remove this category\');"';
					} else {
					event = ' ondblclick="categorySelector();" onclick="preSelectCategory(' + i + ', \'right\');" onmouseover="hilightCategory(' + i + ', \'on\');" onmouseout="hilightCategory(' + i + ', \'off\');"';
					}
				}
				html_2 += '<div style="' + pos + ' width: 190px; z-index: 2;"><img src="/pics/1x1.gif" width="190" height="20" alt=""' + event + ' /></div>' +
							'<div id="category_box_' + i + '" style="' + pos + ' width: ' + (190 - d) + 'px; z-index: 1; overflow: hidden; padding: 0px 0px 0px ' + d + 'px;">' + categories[i].Title + '</div>';
				html_1 += '<div style="' + pos + ' width: ' + (190 - d) + 'px; z-index: 1; overflow: hidden; padding: 0px 0px 0px ' + d + 'px; color: 999999;">' + categories[i].Title + '</div>';
			}
			count++;
		}

		$('selected_cat').innerHTML = html_1;
		$('not_selected_cat').innerHTML = html_2;
		$('selected_cat_field').value = join(', ', tmp);
	}
	function categorySelector()
	{
		if (selectedCategories[preSelectedCategoryID]) {
			delete(selectedCategories[preSelectedCategoryID]);
		} else {
			selectedCategories[preSelectedCategoryID] = true;
		}
		preSelectedCategoryID = 0;
		printCategoryControl();
	}

	function calcPayments(percent, value, box)
	{
		percent = parseFloat(percent.replace(/,/g, ''));

		var tmp = value * percent / 100;

		$(box).value = myParseFloat(tmp);
		$('view_' + box).innerHTML = numberFormat(tmp);

		calcTotals();
	}
	function calcTotals()
	{
		var total = 0;
		var buyer_premium = 0;
		var insurance = 0;

		for (var i = 0; i < GLOBALS.lot.length; i++) {
			total += parseFloat(GLOBALS.price[i]);
			insurance += parseFloat($('insurance_box_' + GLOBALS.lot[i]).value);
			buyer_premium += parseFloat($('buyer_premium_box_' + GLOBALS.lot[i]).value);
		}
		$('total_insurance_box').innerHTML = numberFormat(insurance);
		$('total_buyer_premium_box').innerHTML = numberFormat(buyer_premium);
		total += (buyer_premium + insurance);

		var shipping = 0;
		var taxes = 0;

		for (var i = 0; i < GLOBALS.packs.length; i++) {
			shipping += parseFloat($('ShippingPrice_' + GLOBALS.packs[i]).value.replace(/,/g, ''));
			taxes += parseFloat($('taxes_box_' + GLOBALS.packs[i]).value);
		}

		$('total_shipping_box').innerHTML = numberFormat(shipping);
		$('total_taxes_box').innerHTML = numberFormat(taxes);
		total += (shipping + taxes);

		$('total_box').innerHTML = numberFormat(total);
	}

	function hilightCategory(id, switcher)
	{
		if (preSelectedCategoryID != id) {
			if (switcher == 'on') {
				$('category_box_' + id).style.backgroundColor = '#d9ecff';
			} else {
				$('category_box_' + id).style.backgroundColor = '#ffffff';
			}
		}
	}

	function show_payment_form(id)
	{
		for (var i = 0; i < GLOBALS.payment_forms.length; i++) {
			$('payment_form_' + GLOBALS.payment_forms[i]).style.display = 'none';
		}

		$('payment_form_' + id).style.display = 'inline';
	}

	function in_array(value, array)
	{
		if (isArray(array)) {
			for (var i in array) {
				if (array[i] == value) {
					return true;
				}
			}
			return false;
		} else {
			return false;
		}
	}

	function isArray(obj)
	{
		try {
			obj.push('test element');
			delete obj[(obj.length - 1)];
			return true;
		} catch (e) {
			return false;
		}
	}

	function join(sep, array)
	{
		var ret = '';

		if (isArray(array)) {
			for (var i in array) {
				if (ret != '') {
					ret += sep;
				}
				ret += array[i];
			}
			return ret;
		} else {
			return '';
		}
	}

	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 myParseFloat(num)
	{
		num = num * 100;
		num = Math.round(num);
		num = parseFloat(num / 100) + '';
		var tmp = num.split('.');

		if (tmp[1]) {
			var ceil = tmp[0];
			tmp = tmp[1] + '';
			if (tmp.length == 1) {
				num = num + '0';
			}
		} else {
			num = num + '.00';
		}

		return num;
	}

	function showCalendar(prefix, call, date, ignore_blur)
	{
		closeCalendar(prefix);
		var undef;
		var html = '';
		var show = true;

		var d = parseInt($(prefix + 'd').value);
		var m = parseInt($(prefix + 'm').value);
		var y = parseInt($(prefix + 'y').value);

		if (typeof(date) == typeof(undef)) {
			if ((isNaN(d) && isNaN(m) && isNaN(y)) || y == '0000') {
				var date = new Date();
			} else {
				date = new Date();
				if (!isNaN(d)) {
					date.setDate(d);
				}
				if (!isNaN(m)) {
					date.setMonth(m - 1);
				}
				if (!isNaN(y) && y != '0000') {
					date.setYear(y);
				}
			}
		} else {
			var 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);
		}

		var bg_mouse_over = 'ffffff';
		var bg_mouse_out = 'ffffff';
		var color_mouse_out = '0060ad';
		var color_mouse_over = 'ff0000';
		var color_wekend = 'ff0000';

		html += '<iframe src="/blank.html" width="140" height="153" frameborder="0" style="position: absolute; z-index: 900;"></iframe>';
		html += '<div style="position: absolute; width: 142px; 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" 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" 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: #' + color_wekend + ';">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: #' + color_wekend + ';">S</span></div>';

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

		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) {
				if (i == d && show) {
					html += '<div id="calendar_days_box_' + i + '_' + prefix + '" class="calendar_days_box" style="background-color: #' + bg_mouse_out + '; color: #' + color_mouse_over + ';" 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 = \'#' + bg_mouse_over + '\'; this.style.color = \'#' + color_mouse_over + '\';" onmouseout="this.style.backgroundColor = \'#' + bg_mouse_out + '\'; this.style.color = \'#' + color_mouse_out + '\';" 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 + '\');">close</div>';

		html += '</div>';

		$('calendar_box_' + prefix).innerHTML = html;
		GLOBALS.calendar_opened = true;
		$(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 = '';
		GLOBALS.calendar_opened = false;
		$(prefix + 'm').blur();
		return false;
	}

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

	function showError(str)
	{
		alert('Error:' + "\n\n" + str);
	}

	function showBidError(str)
	{
		$('loading_indicatior').style.display = 'none';
		$('bid_error_box').style.display = 'block';
		$('bid_error_box').innerHTML = '<strong style="color: #990000;">Error:</strong><br />' + str;
	}

	function updateLotTradingHTML(req)
	{
		var html = '';
		var date = new Date();
		var undef;
		var trading_time = 1;

		date.setTime(req.mktime * 1000);

		if (req.error == '') {
			var r = req.result;
			GLOBALS.last_lot_data = r;
		} else {
			$('trading_box').innerHTML = req.error;
			return;
		}
		if (req.refresh) {
			if (r.LotStatus == 1) {
				req.request.BidValue = r.BidValue;
				req.request.TotalBids = r.TotalBids;
				if (r.PriceType == 'auction') {

					var tmp = enlargeBid(r.BidValue, r.Increment, r.AuctionID);
					var bid_abs_options = '';
					var show_more_bids = true;
					for (var i = 1; i <= 10; i++) {
						bid_abs_options += '' +
											'<option value="' + tmp + '">$' + numberFormat(tmp) + '</option>';
						if (tmp == 10000000) {
							show_more_bids = false;
							break;
						}
						tmp = enlargeBid(tmp, r.Increment, r.AuctionID);
					}
					if (show_more_bids) {
						bid_abs_options += '' +
											'<option value="more">more...</option>';
					}

					tmp = enlargeBid(r.BidValue, r.Increment, r.AuctionID);
					var bid_cel_options = '';
					show_more_bids = true;
					for (var i = 1; i <= 10; i++) {
						tmp = enlargeBid(tmp, r.Increment, r.AuctionID);
						tmp = enlargeBid(tmp, r.Increment, r.AuctionID);
						bid_cel_options += '' +
											'<option value="' + tmp + '">$' + numberFormat(tmp) + '</option>';
						if (tmp == 10000000) {
							show_more_bids = false;
							break;
						}
					}
					if (show_more_bids) {
						bid_cel_options += '' +
											'<option value="more">more...</option>';
					}

					html += '' +
							'<table cellspacing="0" cellpadding="0" width="392" border="0">' +
								'<tr>' +
									'<td class="auction_trading_top_header">' +
										'' + r.BidTitle + '' +
									'</td>' +
								//	'<td class="auction_trading_top_header">' +
								//		'High Bidder' +
								//	'</td>' +
									'<td class="auction_trading_top_header">' +
										'Next Bid Increment' +
									'</td>' +
									'<td class="auction_trading_top_header">' +
										'Total Bids' +
									'</td>' +
								'</tr>' +
								'<tr>' +
									'<td class="auction_trading_top_value">' +
										'$' + numberFormat(r.BidValue) + '' +
'';
//									'</td>' +
//									'<td class="auction_trading_top_value">';
				if (false)
					if (r.HighBidderID == null) {
						GLOBALS.high_bidder_id = 0;
						html += '' +
										'&nbsp;';
					} else {
						GLOBALS.high_bidder_id = r.HighBidderID;
/*
						html += '' +
										'<a href="/auction/view_profile.php?id=' + r.HighBidderID + '">#' + r.HighBidderID + (r.HighBidderID == GLOBALS.logged_bidder_id ? '*' : '') + '</a>';
*/
						html += '' +
										'#' + r.HighBidderID + (r.HighBidderID == GLOBALS.logged_bidder_id ? ' *' : '');
					}
					if (r.TotalBids > 0) {
						var bid_value = enlargeBid(r.BidValue, r.Increment, r.AuctionID);
					} else {
						var bid_value = r.BidValue;
					}
					html += '' +
									'</td>' +
									'<td class="auction_trading_top_value">' +
										'$' + numberFormat(bid_value) + '' +
									'</td>' +
									'<td class="auction_trading_top_value">' +
										'' + (r.TotalBids == null ? '0' : r.TotalBids) + '' +
									'</td>' +
								'</tr>' +
								'<tr>' +
									'<td style="text-align: center; vertical-align: top;">';
					if (parseFloat(r.Reserve) > 0) {
						if (parseFloat(r.BidValue) < parseFloat(r.Reserve)) {
							html += '' +
									'Reserve Not Met';
						}
					}
					html += '' +
									'</td>' +
									'<td><img src="/pics/1x1.gif" width="1" height="1" alt="" /></td>' +
									'<td style="text-align: center; padding: 0px 0px 10px 0px;">' +
										useButton('bid_next_increment', {id: r.LotID, bid: bid_value}) +
									'</td>' +
									'<td><img src="/pics/1x1.gif" width="1" height="1" alt="" /></td>' +
								'</tr>' +
							'</table>';
							if(parseFloat(r.BidValue) < parseFloat(r.BuyNowValue)/2 && r.BuyNow == 'Y'){
								html += '<table cellspacing="0" cellpadding="0" width="392" border="0" style="margin-bottom:5px;">' +
								'<tr><td colspan="2" align="center">Until bidding has reached $' + numberFormat(r.BuyNowValue/2) + ', you can take advantage of the button \'Buy Now\' and <strong>buy this lot now</strong> for $' + numberFormat(r.BuyNowValue) + '</td></tr>' +
								'<tr>' +
									'<td align="left">';
									if (GLOBALS.logged_user_id) {
										html += '<a href="/auction/bid_history.php?id=' + r.LotID + '">view bids history</a>';
									}
									html += '</td>' +
									'<td align="right">';
										if (GLOBALS.logged_user_id) {
											html += '<img src="/pics/ab/buy-now.gif" width="73" height="23" alt="" class="hand" onclick="confirmBid(\'buy_now\', ' + r.LotID + ', \'\', \'100\');" />';
										} else {
											html += '<img src="/pics/ab/buy-now.gif" width="73" height="23" alt="" class="hand" onclick="document.location.href = \'/auction_reg.php\';" />';
										}
									html += '</td>' +
								'</tr>' +
								'</table>';
							} else if ((r.TotalBids == null || r.TotalBids == 0) && r.BuyNow == 'Y') {
								html += '<table cellspacing="0" cellpadding="0" width="392" border="0" style="margin-bottom:5px;">' +
								'<tr><td colspan="2" align="center">Before the first bid will be made, you can take advantage of the button \'Buy Now\' and <strong>buy this lot now</strong> for $' + numberFormat(r.BuyNowValue) + '</td></tr>' +
								'<tr>' +
									'<td align="left">';
									if (GLOBALS.logged_user_id){
										html += '<a href="/auction/bid_history.php?id=' + r.LotID + '">view bids history</a>';
									}
									html += '</td>' +
									'<td align="right">';
										if (GLOBALS.logged_user_id) {
											html += '<img src="/pics/ab/buy-now.gif" width="73" height="23" alt="" class="hand" onclick="confirmBid(\'buy_now\', ' + r.LotID + ', \'\', \'100\');" />';
										} else {
											html += '<img src="/pics/ab/buy-now.gif" width="73" height="23" alt="" class="hand" onclick="document.location.href = \'/auction_reg.php\';" />';
										}
									html += '</td>' +
								'</tr>' +
								'</table>';
							} else if (GLOBALS.logged_user_id && r.AuctionID == 0){
								html += '<div style="margin-bottom:5px;"><a href="/auction/bid_history.php?id=' + r.LotID + '">view bids history</a></div>';
							}
							html += '<table cellspacing="0" cellpadding="0" width="392" border="0" class="auction_trading_controls">' +
								'<tr>' +
									'<td>' +
										useButton('place_absolute_bid', {id: r.LotID, box: 'absolute_bid_value'}) +
									'</td>' +
									'<td>' +
										useButton('help_absolute_bid') +
									'</td>' +
									'<td>';
					if (r.AuctionID == 0) {
						html += '' +
										'<table cellspacing="0" cellpadding="0" width="110" border="0">' +
											'<tr>' +
												'<td style="text-align: left">' +
													'$' +
												'</td>' +
												'<td style="text-align: right">' +
													'<input type="text" ' +
													//value="' + enlargeBid(r.BidValue, r.Increment, r.AuctionID) + '"
													'name="absolute_bid_value" id="absolute_bid_value" style="width: 100px; font-size: 10px;" onchange="checkMaxBid(this)">' +
												'</td>' +
											'</tr>' +
										'</table>';
					} else {
						html += '' +
										'<select name="absolute_bid_value" id="absolute_bid_value" style="width: 110px; font-size: 10px;" onchange="get_more_values(this, ' + r.Increment + ', ' + r.AuctionID+ ')">' +
											bid_abs_options +
										'</select>';
					}
					html += '' +
									'</td>' +
									'<td rowspan="2"><img src="/pics/1x1.gif" width="100" height="1" alt="" /></td>' +
								'</tr>' +
								'<tr>' +
									'<td>' +
										useButton('place_cailing_bid', {id: r.LotID, box: 'cailing_bid_value'}) +
									'</td>' +
									'<td>' +
										useButton('help_cailing_bid') +
									'</td>' +
									'<td>' +
										'<select name="cailing_bid_value" id="cailing_bid_value" style="width: 110px; font-size: 10px;" onchange="get_more_values(this, ' + r.Increment + ', ' + r.AuctionID+ ')">' +
											bid_cel_options +
										'</select>' +
									'</td>' +
								'</tr>' +
							'</table>' +
							'<table cellspacing="0" cellpadding="0" width="392" border="0" style="background-color: #89bbed; margin-top: 5px;">' +
								'<tr>' +
									'<td style="padding: 2px 3px 2px 3px; text-align: right;">';
					if (GLOBALS.logged_user_id) {
						var wl_data = {id: r.LotID, selected: (r.WatchList ? true : false)};
					} else {
						var wl_data = {id: r.LotID};
					}
					html += '<table cellspacing="0" cellpadding="0" border="0"><tr><td>' +
										useButton('email_to_friend', {id: r.LotID}) +
										'</td><td>' +
										useButton('watch_list', wl_data) + '</td>';
					if(GLOBALS.logged_user_id) {
						html += '<td>' + useButton('personal_note', {}) + '</td>';
					}
					html += '</tr></table>' +
									'</td>' +
								'</tr>' +
							'</table>';
					if (r.HighBidderID == GLOBALS.logged_bidder_id) {
						html += '' +
							'<table cellspacing="0" cellpadding="0" width="392" border="0" style="margin-top: 5px;">' +
								'<tr>' +
									'<td>' +
										'<div style="color: #990000;">* you are the current high bidder</div>' +
									'</td>' +
								'</tr>' +
							'</table>';
					}
					html += '</td>' +
								'</tr>' +
							'</table>';
				} else {
					var best_offer = false;
					if (r.BestOffer == "Y") {
						best_offer = true;
					}

					html += '' +
							'<table cellspacing="0" cellpadding="0" width="392" border="0">' +
								'<tr>' +
									'<td width="50%" class="auction_trading_top_header">' +
										'Fixed Price' +
									'</td>';
					if (best_offer) {
						html += '' +
									'<td width="50%" class="auction_trading_top_header">' +
										'Place Best Offer' +
									'</td>';
					}
					html += '' +
								'</tr>' +
								'<tr>' +
									'<td class="auction_trading_top_value">' +
										'$' + r.BidValue + '' +
									'</td>';
					if (best_offer) {
						if(r.Quantity > 1){
							html += '' + '<td class="auction_trading_top_value"><div id="best_offer_box">' + (r.YourBestOffer ? 'Your best offer: $' + r.YourBestOffer : '') + ' (' + r.Quantity + 'pieces)</div></td>';
						} else{
							html += '' + '<td class="auction_trading_top_value"><div id="best_offer_box">' + (r.YourBestOffer ? 'Your best offer: $' + r.YourBestOffer : '') + '</div></td>';
						}
					}
					html += '' +
								'</tr>' +
								'<tr>' +
									'<td style="text-align: center">' +
										useButton('buy_now_fixed', {id: r.LotID}) +
									'</td>';
					if (best_offer && r.YourBestOffer == 0) {
						html += '' +
									'<td style="text-align: center">' +
										useButton('place_best_offer', {id: r.LotID, field: 'best_offer_value'}) +
									'</td>';
					}
					html += '' +
								'</tr>' +
								'<tr>' +
									'<td>' +
										'&nbsp;' +
									'</td>';
					if (best_offer && r.YourBestOffer == 0) {
						html += '' +
									'<td style="text-align: center">' +
										'<center><table cellspacing="0" cellpadding="0" border="0" style="margin-bottom: 20px;">' +
											'<tr>' +
												'<td style="text-align: left">' +
													'$&nbsp;' +
												'</td>' +
												'<td style="text-align: right">' +
													'<input type="text" value="' + /* (r.BidValue - 0.01) + */ '" name="best_offer_value" id="best_offer_value" style="width: 108px; font-size: 10px;">' +
												'</td>' +
											'</tr>' +
										'</table></center>' +
									'</td>';
					}
					html += '' +
								'</tr>' +
								'<tr>' +
									'<td' + (best_offer ? ' colspan="2"' : '') + ' style="padding: 2px 3px 2px 3px; background-color: #89bbed;">';
					if (GLOBALS.logged_user_id) {
						var wl_data = {id: r.LotID, selected: (r.WatchList ? true : false)};
					} else {
						var wl_data = {id: r.LotID};
					}
					html += '' +
										useButton('watch_list', wl_data) +
									'</td>' +
								'</tr>' +
								'<tr>' +
									'<td' + (best_offer ? ' colspan="2"' : '') + ' style="text-align: right;">' +
//										'Auction End: <div id="auction_end_box" style="display: inline;"></div>' +
									'</td>' +
								'</tr>' +
							'</table>';
				}
				$('trading_box').innerHTML = html;
				new inputPlaceholder($("absolute_bid_value"), "enter amount");
				new inputPlaceholder($("best_offer_value"), "Enter your offer here");
				if (GLOBALS.auction_end_timeout) {
					clearInterval(GLOBALS.auction_end_timeout);
				}
				setAuctionEndDate(parseInt(r.ToFinish), r.LotID, r.FinishDate, r.RealFinish);
			} else {
				trading_time = 0;
				if (r.LotStatus == 2 || r.LotStatus == 4 || r.LotStatus == 6 || r.LotStatus == 12) {
// Sold or Shipped or Closed
					html += 'Lot was sold' +
							'<br />' +
							'<br />' +
							'<strong>Winning Bidder: #' + r.SoldTo + '</strong>' +
							'<br />' +
							'<strong>Winning Bid: $' + r.SoldPrice + '</strong>' +
							'<br />' +
							'<br />';
					$('auction_end_box').innerHTML = 'Closed';
				} else if (r.LotStatus == 3 || r.LotStatus == 9) {
	// Returned or Not Sold
					if (r.FHighestBid > 0) {
						html += 'Lot was not sold, reserve not met' +
								'<br />' +
								'<br />' +
								'<strong>High Bid: $' + r.FHighestBid + '</strong>' +
								'<br />' +
								'<strong>High Bidder: #' + r.FHighBidder + '</strong>' +
								'<br />' +
								'<br />';
					} else {
						html += 'Lot was not sold' +
								'<br />' +
								'<br />' +
								'<strong>No bids placed</strong>' +
								'<br />' +
								'<br />';
					}
					$('auction_end_box').innerHTML = 'Closed';
				} else if (r.LotStatus == 10) {
	// Not Published
					html += 'Not published';
				} else if (r.LotStatus == 13) {
	// Cancelled
					html += 'Cancelled';
				} else if (r.LotStatus == 14) {
	// Dispute
					html += 'Disputed';
				} else if (r.LotStatus == 11) {
	// Preview
					html += 'Auction Will Be Open For Bidding on ' + r.StartDate;
					if (r.BuyNow == 'Y' && r.AuctionID == 0) {
						html += '<br>You can buy this goods now for $' + numberFormat(r.BidValue);
					}
				} else {
					html += 'Unknown lot status';
				}

				html += '' +
							'<table cellspacing="0" cellpadding="0" width="392" border="0" style="background-color: #89bbed; margin-top: 5px;">' +
								'<tr>' +
									'<td style="padding: 2px 3px 2px 3px; text-align: right;">';
					if (GLOBALS.logged_user_id) {
						var wl_data = {id: r.LotID, selected: (r.WatchList ? true : false)};
					} else {
						var wl_data;
					}
//					if (r.LotStatus == 11 && r.BuyNow == 'Y' && r.AuctionID == 0) {
//						html += useButton('buy_now_fixed', {id: r.LotID}) + '&nbsp;';
//					}
					html += useButton('email_to_friend', {id: r.LotID});

					if (GLOBALS.logged_user_id) {
						html += '&nbsp;' + useButton('personal_note', {});
					}
					html +=		'</td>' +
								'</tr>' +
							'</table>';

				$('trading_box').innerHTML = html;
			}
		}
		if (trading_time) {
			GLOBALS.req = req.request;
			GLOBALS.req.mktime = req.mktime;
			GLOBALS.lot_data_timeout = setTimeout('checkNewBid(GLOBALS.req.id);', 1000);
		}
	}

	function checkMaxBid(obj)
	{
		if (obj.value > 10000000) {
			obj.value = 10000000;
			alert('Max bid value is $10,000,000.00');
		}
	}

	function checkByNowPrice()
	{
		if ($('BuyNow').checked) {
			$('buy_now_price_1').style.display = 'inline';
			$('buy_now_price_2').style.display = 'inline';
			$('buy_now_price_3').style.display = 'inline';
		} else {
			$('buy_now_price_1').style.display = 'none';
			$('buy_now_price_2').style.display = 'none';
			$('buy_now_price_3').style.display = 'none';
		}
	}

	function setReserveOptions()
	{
		if (typeof(auction_data) == 'undefined') {
			delOption($('Reserve'), 'all');
			setOption($('Reserve'), 'Select Auction', '');
		} else {
			if ($('OpeningBid').value == '' || parseFloat($('OpeningBid').value) == 0) {
				delOption($('Reserve'), 'all');
				setOption($('Reserve'), 'Select Opening Bid', '');
			} else {
				delOption($('Reserve'), 'all');
				setOption($('Reserve'), 'Select...', '');
				var tmp = enlargeBid($('OpeningBid').value, auction_data.Increment, auction_data.AuctionID);
				if (parseFloat(reserve_from_post) > 0) {
					var default_setted = false;
				} else {
					var default_setted = true;
				}
				for (var i = 1; i <= 10; i++) {
					if (parseFloat(reserve_from_post) == parseFloat(tmp)) {
						setOption($('Reserve'), tmp, tmp, true);
						default_setted = true;
					} else {
						setOption($('Reserve'), tmp, tmp);
					}
					if (tmp == 10000000) {
						return;
					}
					tmp = enlargeBid(tmp, auction_data.Increment, auction_data.AuctionID);
				}
				while (!default_setted) {
					if (parseFloat(reserve_from_post) == parseFloat(tmp)) {
						setOption($('Reserve'), tmp, tmp, true);
						default_setted = true;
					} else {
						setOption($('Reserve'), tmp, tmp);
					}
					if (tmp == 10000000) {
						return;
					}
					tmp = enlargeBid(tmp, auction_data.Increment, auction_data.AuctionID);
				}
				setOption($('Reserve'), 'more...', 'more');
			}
		}
	}

	function setOption(obj, option, value, selected)
	{
		var opt = document.createElement('option');
		var text = document.createTextNode(option);
		opt.appendChild(text);
		opt.setAttribute('value', value);
		if (typeof(selected) != 'undefined') {
			opt.setAttribute('selected', true);
		}
		obj.appendChild(opt);
	}

	function delOption(obj, type)
	{
		switch (type) {
			case('all'):
				while(obj.hasChildNodes()) {
					obj.removeChild(obj.firstChild);
				}
				break;
			case('last'):
				obj.removeChild(obj.lastChild);
				break;
			default:
				alert('Unknown type');
				break;
		}
	}

	function get_more_values(obj, increment, auction)
	{
		if (obj.value == 'more') {
			var opt;
			var text;
			var twice = false;
			var tmp = obj.lastChild.previousSibling.value;
			if (obj.name == 'cailing_bid_value') {
				twice = true;
			}

			obj.removeChild(obj.lastChild);

			for (var i = 1; i <= 20; i++) {
				tmp = enlargeBid(tmp, increment, auction);
				if (twice) {
					tmp = enlargeBid(tmp, increment, auction);
				}

				opt = document.createElement('option');
				text = document.createTextNode('$' + numberFormat(tmp));
				opt.appendChild(text);
				opt.setAttribute('value', tmp);
				obj.appendChild(opt);

				if (tmp == 10000000) {
					return;
				}
			}

			opt = document.createElement('option');
			text = document.createTextNode('more...');
			opt.appendChild(text);
			opt.setAttribute('value', 'more');
			obj.appendChild(opt);
		}
	}

	function getTimeStr(time, type, f_date)
	{
		var ret = '';
		var qnt = 'single';
		var words =
		{
			'long':
			{
				'single': {'w': 'week', 'd': 'day', 'h': 'hour', 'm': 'minute', 's': 'second'},
				'multi': {'w': 'weeks', 'd': 'days', 'h': 'hours', 'm': 'minutes', 's': 'seconds'}
			},
			'short':
			{
				'single': {'w': 'week', 'd': 'd', 'h': 'h', 'm': 'm', 's': 's'},
				'multi': {'w': 'weeks', 'd': 'd', 'h': 'h', 'm': 'm', 's': 's'}
			}
		};
		var w = Math.floor(time / 60 / 60 / 24 / 7);
		if (w > 0) {
/*
			if (w > 1) {
				qnt = 'multi';
			}
			ret += w + ' ' + words[type][qnt].w;
*/
			ret += f_date;
		} else {
			var d = Math.floor(time / 60 / 60 / 24) % 7;
			var h = Math.floor(time / 60 / 60) % 24;
			if (d > 0) {
				if (d > 1) {
					qnt = 'multi';
				}
				ret += d + ' ' + words[type][qnt].d + ' ';
				if (h > 1) {
					qnt = 'multi';
				} else {
					qnt = 'single';
				}
				ret += h + ' ' + words[type][qnt].h;
			} else {
				var m = Math.floor(time / 60) % 60;
				if (h > 0) {
					if (h > 1) {
						qnt = 'multi';
					}
					ret += h + ' ' + words[type][qnt].h + ' ';
					if (m > 1) {
						qnt = 'multi';
					} else {
						qnt = 'single';
					}
					ret += m + ' ' + words[type][qnt].m;
				} else {
					var s = time % 60;
					if (m > 1) {
						if (m > 1) {
							qnt = 'multi';
						}
						ret += m + ' ' + words[type][qnt].m;
						if (m < 5) {
							if (s > 1) {
								qnt = 'multi';
							} else {
								qnt = 'single';
							}
							ret += ' ' + s + ' ' + words[type][qnt].s;
						}
					} else {
						if (m == 1) {
							s += 60;
						}
						if (s > 1) {
							qnt = 'multi';
						}
						ret += s + ' ' + words[type][qnt].s;
					}
				}
			}
		}
		return ret;
	}

	function setAuctionEndDate(time, lot_id, f_date, r_time)
	{
		if (r_time > 0) {
			$('auction_end_box').innerHTML = getTimeStr(r_time, 'long', f_date);
			GLOBALS.auction_end_timeout = setTimeout('setAuctionEndDate(' + (time - 1) + ', ' + lot_id + ', "' + f_date + '", ' + (r_time - 1) + ');', 1000);
		} else {
			if (time > 0) {
				$('auction_end_box').innerHTML = 'Extended Session';
			} else {
				closeAuctionOrLot(lot_id);
				if (GLOBALS.lot_data_timeout) {
					delete(GLOBALS.lot_data_timeout);
				}
				var r = GLOBALS.last_lot_data;

				$('auction_end_box').innerHTML = 'Closed';
				$('trading_box').innerHTML = 'Auction has been finished. Loading result for this lot...';
			}
		}
	}

	function switchAuctionOrFixed(first_launch)
	{
		if ($("PriceType").value == "auction") {

			$("buyNowField").style.display = "inline";
			$("label_Reserve").style.display = "inline";
			$("Reserve").style.display = "inline";

			$("best_offer_box_1").style.display = "none";
			$("best_offer_box_2").style.display = "none";
			$("best_offer_box_3").style.display = "none";
			$("best_offer_box_4").style.display = "none";
			$("BestOffer").checked = false;
			if (!first_launch) {
				$('AuctionLength').removeChild($('AuctionLength').lastChild);
			}
		} else {
			$('BuyNow').checked = false;
			$('BuyNowValue').value = '';
			$('Reserve').value = '';

			$("buyNowField").style.display = "none";
			$("label_Reserve").style.display = "none";
			$("Reserve").style.display = "none";

			$("best_offer_box_1").style.display = "inline";
			$("best_offer_box_2").style.display = "inline";
			$("best_offer_box_3").style.display = "inline";
			$("best_offer_box_4").style.display = "inline";

			var opt = document.createElement('option');
			var text = document.createTextNode('30 days');
			opt.appendChild(text);
			opt.setAttribute('value', '720');
			if (current_length == 720) {
				opt.setAttribute('selected', true);
			}
			$('AuctionLength').appendChild(opt);
		}
	}

	function enlargeBid(value, percent, auction)
	{
		var ret = 0;

		if (auction == 0) {
			if (value < 50) {
				ret = myParseFloat(parseFloat(value) + 0.5);
			} else if (value < 100) {
				ret = myParseFloat(parseFloat(value) + 1);
			} else if (value < 500) {
				ret = myParseFloat(parseFloat(value) + 5);
			} else {
				ret = myParseFloat(parseFloat(value) + 10);
			}
		} else {
			if (value > 10000) {
				percent = percent / 2;
			}
			ret = myParseFloat(Math.round(parseFloat(value) + parseFloat(value * percent / 100)));
		}

		if (ret > 10000000) {
			ret = '10000000.00';
		}

		return ret;
	}

	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 confirmBid(type, id, box, bid)
	{
		var undef;
		var top;
		var frame_height = 600;
		var d = new Date();
		var screen_height = getStageSize('y');

		if (screen_height > frame_height) {
			top = (screen_height - frame_height) / 2;
		} else {
			top = 0;
		}

		$('confirmation_window_box').style.display = 'block';
		$('confirmation_window_box').style.top = parseInt(document.body.scrollTop + top) + 'px';

		if (typeof(undef) == typeof(bid)) {
			bid = document.getElementById(box).value;
		}
		if(type == 'buy_now') {
			$('confirmation_window_src').src = '/auction/buy_now_confirmation.php?a=' + id + '&b=' + bid + '&c=' + type + '&nocache=' + d.getTime();
		} else if(type == 'fixed_price'){
			$('confirmation_window_src').src = '/auction/fixed_price_confirmation.php?a=' + id + '&b=' + bid + '&c=' + type + '&nocache=' + d.getTime();
		} else if(type == 'best_offer'){
			$('confirmation_window_src').src = '/auction/best_offer_confirmation.php?a=' + id + '&b=' + bid + '&c=' + type + '&nocache=' + d.getTime();
		}
		else {
			$('confirmation_window_src').src = '/auction/bid_confirmation.php?a=' + id + '&b=' + bid + '&c=' + type + '&nocache=' + d.getTime();
		}
	}

	function closeConfirmBid(reload_flag)
	{
		top.document.getElementById('confirmation_window_box').style.display = 'none';
		top.document.getElementById('confirmation_window_src').src = '/blank.html';
		if (reload_flag) {
			var undef;
			if (typeof(undef) != typeof(top.document.GLOBALS.lots_list_price)) {
				top.document.GLOBALS.lots_list_price = top.window.clearInterval(top.document.GLOBALS.lots_list_price);
				top.window.setTimeout('doLoad(true, false, "lots_list_price", GLOBALS.lots_req);', 10);
			}
		}
	}

	function useButton(type, data, action)
	{
		var undef;
		var html = '';

		switch (type) {
			case 'relist':
				if (typeof(undef) == typeof(action)) {
					if (data.status == 9 || (data.status == 2 && data.sc == 'D')) {
						if (data.ref == "N") {
							html += '<img src="/pics/ab/relist.gif" width="73" height="23" alt="" id="relist_button_' + data.id + '" class="hand" onclick="useButton(\'' + type + '\', {id: \'' + data.id + '\', ref: \'' + data.ref + '\'}, \'request\');" />';
						} else {
							html += '<img src="/pics/ab/relisted.gif" width="73" height="23" alt="" class="hand" onclick="useButton(\'' + type + '\', {id: \'' + data.id + '\', ref: \'' + data.ref + '\'}, \'request\');" />';
						}
					}
				} else if (action == 'request') {
					if (data.ref == "N") {
						if (confirm('Are you sure?')) {
							doLoad(true, false, 'click_' + type, data);
						}
					} else {
						showError('This lot already relisted');
					}
					return;
				} else if (action == 'response') {
					if (data.error == '') {
//						$('relist_button_' + data.request.id).src = '/pics/ab/relisted.gif';
						document.location.href = '/auction/edit_profile.php?dep=my_lots&relisting=1&id=' + data.result.new_id;
					} else {
						showError(data.error);
					}
					return;
				} else {
					showError('Bad action...');
					return;
				}
				break;
			case 'second_chance':
				if (typeof(undef) == typeof(action)) {
					if (data.status == 2 && data.sc == 'Y') {
						html += '<img src="/pics/ab/second-chance.gif" width="104" height="23" alt="" class="hand" onclick="useButton(\'' + type + '\', {id: ' + data.id + '}, \'request\');" id="second_change_' + data.id + '" />';
					}
				} else if (action == 'request') {
					if (confirm('Are you sure?')) {
						doLoad(true, false, 'click_' + type, data);
					}
					return;
				} else if (action == 'response') {
					if (data.error == '') {
						$('second_change_' + data.request.id).style.display = 'none';
						alert('Second chance offer has been sent to underbidder.');
					} else {
						showError(data.error);
					}
					return;
				} else {
					showError('Bad action...');
					return;
				}
				break;
			case 'discussion':

				var totalPost = '';

				var string = data.count_post;
				var digitIndex = string.split("");

				if (string>99) {
						var sizeSpace = '';
				} else if(data.count_post>9){
						var sizeSpace =	'<img src="/pics/digit/space.gif" width="3" alt="">';
				} else {
						var sizeSpace =	'<img src="/pics/digit/space.gif" width="6" alt="">';
				}


				var tmp_var = 0;
					for(var i=0, total = '';i<digitIndex.length;i++,tmp_var++){

						if(digitIndex[i] != undefined) {

							total += '<img src="/pics/digit/' + digitIndex[i] + '.gif" border="0" alt="" width="6" height="11">';

						}

					}

				if (tmp_var>2)
				{
					var valign = 'middle';
					var margin = 'margin-top: 1px;';

				} else {

					var valign = '70%';
					var margin = '';
				}


				html += ''
				+ '<table cellspacing="0" cellpadding="0" width="100%" border="0" class="hand" onclick="window.open(\'/vb_forum/showthread.php?t=' + data.thread_id + '\', \'view_discussion\', \'toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes\');"><tr>'
				+ '<td align="right"><img src="/pics/digit/button_01.gif" width="5" height="21" alt=""></td>'
				+ '<td align="right"><img src="/pics/digit/button_02.gif" width="86" height="21" alt=""></td>'
				+ '<td align="center" class="btnCDisc"  style="vertical-align:'+ valign +'" nowrap="nowrap"><div style="vertical-align:'+ valign +';'+ margin +'">' + sizeSpace
				+ '<img src="/pics/digit/left.gif" width="5" height="11" alt="">' + total + '<img src="/pics/digit/right.gif" width="5" height="11" alt="">'
				+ sizeSpace + '</div></td>'
				+ '<td align="right"><img src="/pics/digit/button_03.gif" width="3" height="21" alt=""></td>'
				+ '</tr></table>';
				//html += '<img src="/pics/ab/view-discussion.gif" width="107" height="23" alt="" class="hand" onclick="window.open(\'/vb_forum/showthread.php?t=' + data.thread_id + '\', \'view_discussion\', \'toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes\');" />';

				break;
			case 'bid_next_increment':
// Print button
				if (typeof(undef) == typeof(action)) {
					if (typeof(undef) == typeof(data.short_button)) {
//						html += '<img src="/pics/ab/bid-next-increment.gif" width="119" height="23" alt="" class="hand" onclick="if(confirm(\'Are you sure?\')){ useButton(\'' + type + '\', {id: ' + data.id + ', bid: ' + data.bid + '}, \'request\'); }" />';
						html += '<img src="/pics/ab/bid-next-increment.gif" width="119" height="23" alt="" class="hand" onclick="confirmBid(2, ' + data.id + ', \'\', ' + data.bid + ');" />';
					} else {
//						html += '<img src="/pics/ab/bid.gif" width="46" height="23" alt="" class="hand" onclick="if(confirm(\'Are you sure?\')){ useButton(\'' + type + '\', {id: ' + data.id + ', bid: $(\'' + data.box + '\').value}, \'request\'); }" />';
//						html += '<img src="/pics/ab/bid.gif" width="46" height="23" alt="" class="hand" onclick="window.open(\'/auction/bid_confirmation.php?a=' + data.id + '&b=\' + ' + data.box + '.value + \'&c=2 \',\'bid_confirmation' + data.id + '\', \'width=880px, height=770px; top=20px, left=20px, scrollbars=yes\');" />';
						html += '<img src="/pics/ab/bid.gif" width="46" height="23" alt="" class="hand" onclick="confirmBid(2, ' + data.id + ', \'' + data.box + '\');" />';
					}
// Request onclick
				} else if (action == 'request') {
					if (GLOBALS.loaded_lots) {
						var bidder = GLOBALS.loaded_lots[data.id].bidder;
					} else {
						var bidder = GLOBALS.high_bidder_id;
					}

					if (GLOBALS.logged_user_id != 0 && GLOBALS.logged_user_id == bidder) {
						showError('Current bid is yours, use Absolute or Cailing bids to enlarge your current bid.');
					} else {
						doLoad(true, false, 'click_' + type, data);
					}
					return;
// Response -
				} else if (action == 'response') {
					if (!data.result) {
						showBidError(data.error);
					} else {
						if (GLOBALS['is_confirm_window']) {
							document.location.href = document.location.href + '&d=1';
						}
					}
					if (typeof(undef) != typeof(GLOBALS.lots_list_price)) {
						clearInterval(GLOBALS.lots_list_price);

						doLoad(true, false, "lots_list_price", GLOBALS.lots_req);
					}
					return;
//
				} else {
					showError('Bad action...');
					return;
				}
				break;
			case 'place_absolute_bid':
// Print button
				if (typeof(undef) == typeof(action)) {
					//var src = '/pics/ab/place-absolute-bid.gif';
					var src = '/pics/ab/bid-other-amount.gif';
					//var w = '119';
					var w = '120';
//					html += '<img src="' + src + '" width="' + w + '" height="23" alt="" class="hand" onclick="if(confirm(\'Are you sure?\')){ useButton(\'' + type + '\', {id: ' + data.id + ', bid: $(\'' + data.box + '\').value}, \'request\');}" />';
//					html += '<img src="' + src + '" width="' + w + '" height="23" alt="" class="hand" onclick="window.open(\'/auction/bid_confirmation.php?a=' + data.id + '&b=\' + ' + data.box + '.value + \'&c=0\',\'bid_confirmation_a' + data.id + '\', \'width=880px, height=770px; top=20px, left=20px, scrollbars=yes\');" />';
					html += '<img src="' + src + '" width="' + w + '" height="23" alt="" class="hand" onclick="confirmBid(0, ' + data.id + ', \'' + data.box + '\');" />';
// Request onclick
				} else if (action == 'request') {
					if (GLOBALS['is_confirm_window']) {
						$('loading_indicatior').style.display = 'block';
					}
					doLoad(true, false, 'click_' + type, data);
					return;
// Response -
				} else if (action == 'response') {
					if (!data.result) {
						showBidError(data.error);
					} else {
						if (GLOBALS['is_confirm_window']) {

							if (typeof(undef) != typeof(top.document.GLOBALS.lots_list_price)) {
/*
								clearInterval(top.document.GLOBALS.lots_list_price);

								top.document.doLoad(true, false, "lots_list_price", top.document.GLOBALS.lots_req);
*/
							}
							document.location.href = document.location.href + '&d=1';
						}
					}
					return;
//
				} else {
					showError('Bad action...');
					return;
				}
				break;
			case 'add_to_my_collection':
				html += '<img src="/pics/ab/?.gif" width="46" height="23" alt="" class="hand" onclick="alert(\'Under construction\');" />';
				break;
			case 'track_ship_status':
				html += '<img src="/pics/ab/?.gif" width="46" height="23" alt="" class="hand" onclick="alert(\'Under construction\');" />';
				break;
			case 'next_bid_in_list':
				if (GLOBALS["loaded_lots"] && GLOBALS["loaded_lots"][data.id]) {
					var tmp = GLOBALS["loaded_lots"][data.id];
					if (tmp.lot_status == 1 && tmp.auction_status == 4) {
//						alert(data.price_type);
						if(data.price_type == 'auction'){
							html += useButton('bid_next_increment', {id: data.id, box: ('next_bid_value_' + data.id), short_button: true});
						}
						else if(data.price_type == 'fixed'){
							html += useButton('buy_now_fixed', {id: data.id});
						}
					} else {
						html += '&nbsp;';
					}
				} else {
					html += '&nbsp;';
				}
				break;
			case 'expert_opinion':
				if (data.opinion > 0) {
					html += '<img src="/pics/ab/see-guu-experts.gif" width="155" height="23" alt="" class="hand" onclick="document.location.href = \'/auction/opinion.php?id=' + data.id + '\';" />';
				} else {
					html += '&nbsp;';
				}
				break;
			case 'email_to_friend':
				html += '<img src="/pics/ab/e-mail-to-a-friend.gif" width="104" height="23" alt="" class="hand" onclick="window.open(\'/auction/email_to_friend.php?id=' + data.id + '\', \'email_to_friend\', \'width=500,height=300\');" />';
				break;
			case 'personal_note':
				html += '<img src="/pics/ab/add-personal-note.gif" width="120" height="23" alt="" class="hand" onclick="document.location.hash = document.location.hash.replace(/#personal_note/, \'\') + \'#personal_note\';" />';
				break;
			case 'help_absolute_bid':
				html += '<img src="/pics/ab/question.gif" width="23" height="23" alt="" class="hand" onclick="window.open(\'/auction/help.php?help=place_absolute_bid\', \'place_absolute_bid\', \'width=500,height=300\');" />';
				break;
			case 'view_auction_details':
				html += '<img src="/pics/ab/view-details.gif" width="104" height="23" alt="" class="hand" onclick="document.location.href = \'/auction/auction.php?id=' + data.id + '\';" />';
				break;
			case 'view_lots':
				if(data.hml != 0){
					html += '<img src="/pics/ab/view-lots.gif" width="73" height="23" alt="" class="hand" onclick="document.location.href = \'/auction/index.php?auction_id=' + data.id + '\';" />';
				}
				break;
			case 'place_cailing_bid':
// Print button
				if (typeof(undef) == typeof(action)) {
//					html += '<img src="/pics/ab/place-celling-bid.gif" width="119" height="23" alt="" class="hand" onclick="if(confirm(\'Are you sure?\')){ useButton(\'' + type + '\', {id: ' + data.id + ', bid: $(\'' + data.box + '\').value}, \'request\');}" />';
//					html += '<img src="/pics/ab/place-celling-bid.gif" width="119" height="23" alt="" class="hand" onclick="window.open(\'/auction/bid_confirmation.php?a=' + data.id + '&b=\' + ' + data.box + '.value + \'&c=1\',\'bid_confirmation_c' + data.id + '\', \'width=880px, height=770px; top=20px, left=20px, scrollbars=yes\');" />';
					html += '<img src="/pics/ab/place-celling-bid.gif" width="119" height="23" alt="" class="hand" onclick="confirmBid(1, ' + data.id + ', \'' + data.box + '\');" />';
// Request onclick
				} else if (action == 'request') {
					if (GLOBALS['is_confirm_window']) {
						$('loading_indicatior').style.display = 'block';
					}
					doLoad(true, false, 'click_' + type, data);
					return;
// Response -
				} else if (action == 'response') {
					if (!data.result) {
						showBidError(data.error);
					} else {
						if (GLOBALS['is_confirm_window']) {
							document.location.href = document.location.href + '&d=1';
						}
					}
					return;
//
				} else {
					showError('Bad action...');
					return;
				}
				break;
			case 'help_cailing_bid':
				html += '<img src="/pics/ab/question.gif" width="23" height="23" alt="" class="hand" onclick="window.open(\'/auction/help.php?help=place_ceiling_bid\', \'place_ceiling_bid\', \'width=500,height=300\');" />';
				break;
// Watch list
			case 'watch_list':
// Print button
				if (typeof(undef) == typeof(action)) {
					if (typeof(undef) == typeof(data['selected'])) {
						html += '<table><tr><td><img src="/pics/ab/add-to-watch-list.gif" width="149" height="23" alt="" class="hand" onclick="document.location.href = \'/login.php?add_lot_to_watch_list=' + data.id + '\';" /></td></tr></table>';
					} else {
						html += '<table><tr><td><img id="' + type + '_' + data.id + '" src="/pics/ab/' + (data.selected ? 'remove-from-watch-list' : 'add-to-watch-list') + '.gif" width="149" height="23" alt="" class="hand" onclick="useButton(\'' + type + '\', {id: \'' + data.id + '\', selected: (getBaseName(this.src) == \'add-to-watch-list.gif\' ? false : true)}, \'request\');" /></td></tr></table>';
					}
// Request onclick
				} else if (action == 'request') {
					doLoad(true, false, 'click_' + type, data);
					return;
// Response - change button value
				} else if (action == 'response') {
					if (data.selected) {
						$(type + '_' + data.id).src = '/pics/ab/remove-from-watch-list.gif';
						alert('This item has been added to your Watch List. Please click below to continue.');
					} else {
						$(type + '_' + data.id).src = '/pics/ab/add-to-watch-list.gif';
//						window.location.reload();
					}
//
				} else {
					showError('Bad action...');
					return;
				}
				break;
// Buy now fixed
			case 'buy_now_fixed':
// Print button
				if (typeof(undef) == typeof(action)) {
					if (GLOBALS.logged_user_id) {
						html += '<img src="/pics/ab/buy.gif" width="48" height="22" alt="" class="hand" onclick="confirmBid(\'fixed_price\', ' + data.id + ', \'\', \'100\');" />';
					} else {
						html += '<img src="/pics/ab/buy.gif" width="48" height="22" alt="" class="hand" onclick="document.location.href = \'/auction_reg.php\';" />';
					}
// Request onclick
				} else if (action == 'request') {
					doLoad(true, false, 'click_' + type, data);
					return;
// Response - change button value
				} else if (action == 'response') {
					if (!data.result) {
						showBidError(data.error);
					} else {
						if (GLOBALS['is_confirm_window']) {
//							document.location.href = document.location.href + '&d=1';
							document.location.href = document.location.href + '&d=1&f=' + data.request['confirmation_time'];
						}
					}
/*
					GLOBALS.req
					updateLotTradingHTML
*/
//
				} else {
					showError('Bad action...');
					return;
				}
				break;
// Best offer
			case 'place_best_offer':
// Print button
				if (typeof(undef) == typeof(action)) {
					if (GLOBALS.logged_user_id) {
						html += '<img src="/pics/ab/place-best-offer.gif" _width="" _height="" alt="" class="hand" onclick="confirmBid(\'best_offer\', ' + data.id + ', \'\', $(\'' + data.field + '\').value);" />';
					} else {
						html += '<img src="/pics/ab/place-best-offer.gif" _width="" _height="" alt="" class="hand" onclick="document.location.href = \'/auction_reg.php\';" />';
					}
// Request onclick
				} else if (action == 'request') {
					doLoad(true, false, 'click_' + type, {id: data.id, bid: $(data.field ).value, Quantity: data.Quantity});
					return;
// Response - change button value
				} else if (action == 'response') {
//					if (data.error == '') {
//						$('best_offer_box').innerHTML = 'Your best offer: $' + myParseFloat(data.result);
//					} else {
//						showError(data.error);
//					}

					if (!data.result) {
						showBidError(data.error);
					} else {
						if (GLOBALS['is_confirm_window']) {
							document.location.href = document.location.href + '&d=1';
						}
						window.parent.$('best_offer_box').innerHTML = 'Your best offer: $' + myParseFloat(data.result);
					}

//
				} else {
					showError('Bad action...');
					return;
				}
				break;
			default :
				html += '<button onclick="showError(\'Unknown button action\');">Unknown button type</button>';
				break;
		}
		if (typeof(undef) == typeof(action)) {
			return html;
		}
	}

	function getBaseName(path)
	{
		var tmp = path.split('/');
		return tmp[(tmp.length - 1)];
	}

	function swithTab(tab)
	{
		var tabs = ['select_user', 'register_user'];

		for (var i = 0; i < tabs.length; i++) {
			if (tabs[i] == tab) {
				$(tabs[i] + '_tab').className = "active_tab";
				$(tabs[i] + '_tab_content').className = "active_tab_content";
			} else {
				$(tabs[i] + '_tab').className = "inactive_tab";
				$(tabs[i] + '_tab_content').className = "inactive_tab_content";
			}
		}
	}

	function getImageForm(name, number)
	{
		if ($('ImagesNumber').value >= number && number > 0) {
			return;
		}

		if (number > 0) {
			postfix = number;
		} else {
			postfix = 1;
		}

		var div = document.createElement('DIV');
		div.setAttribute('id', 'image_div_' + postfix);

		$(name).appendChild(div);

		var html = '' +
					'<table cellspacing="0" cellpadding="0" width="" border="0">' +
						'<tr>' +
							'<td>' +
								'Title ' +
							'</td>' +
							'<td>' +
								'<input type="text" name="ImageTitle' + postfix + '" id="ImageTitle' + postfix + '" class="upload_image" />' +
							'</td>' +
						'</tr>' +
						'<tr>' +
							'<td style="padding-right: 4px;">' +
								'File URL' +
							'</td>' +
							'<td>' +
								'<input type="text" name="ImageURL' + postfix + '" id="ImageURL' + postfix + '" class="upload_image"' + (number > 0 ? ' onpropertychange="getImageForm(\'' + name + '\', ' + (number + 1) + ');" onchange="getImageForm(\'' + name + '\', ' + (number + 1) + ');"' : '' ) + ' />' +
							'</td>' +
						'</tr>' +
						'<tr>' +
							'<td>' +
								'File ' +
							'</td>' +
							'<td>' +
								'<input type="file" name="ImageFile' + postfix + '" id="ImageFile' + postfix + '" class="upload_image"' + (number > 0 ? ' onpropertychange="getImageForm(\'' + name + '\', ' + (number + 1) + ');" onchange="getImageForm(\'' + name + '\', ' + (number + 1) + ');"' : '' ) + ' />' +
							'</td>' +
						'</tr>' +
					'</table>';

		$('image_div_' + postfix).innerHTML = html;
		$('image_div_' + postfix).className = 'upload_image_box';
		$('ImagesNumber').value = (number > 0 ? number : 1);
	}

	function checkCC(id, data)
	{
		var undef;

		top.$('add_billing_info_box').src = '';
		top.$('add_billing_info_box').style.display = 'none';
		top.$('card_validation_value_box').innerHTML = '';
		GLOBALS.credit_card_user_id = 0;

		if (typeof(undef) == typeof(data)) {
			if (confirm('Click yes to validate card or click cancel if you don\'t want to validate now.')) {
				doLoad(true, false, 'cccheck', {id: id});
			}
		} else {
			if (data.error == '') {
				top.$('card_validation_value_box').innerHTML = 'Selected user has valid Credit Card';
			} else {
				if (data.error == 1) {
					if (confirm('There are no Credit Card info for this user, would you you like to add it?')) {
						top.$('add_billing_info_box').src = '/billing_info.php';
						top.$('add_billing_info_box').style.display = 'block';
						top.GLOBALS.credit_card_user_id = id;
					} else {
						top.$('card_validation_value_box').innerHTML = 'Selected user hasn\'t valid Credit Card';
					}
				} else if (data.error == 2) {
					if (confirm('Selected user hasn\'t valid Credit Card, would you you like to add new one?')) {
						top.$('add_billing_info_box').src = '/billing_info.php';
						top.$('add_billing_info_box').style.display = 'block';
						top.GLOBALS.credit_card_user_id = id;
					} else {
						top.$('card_validation_value_box').innerHTML = 'Selected user hasn\'t valid Credit Card';
					}
				} else {
					top.$('card_validation_value_box').innerHTML = 'Selected user hasn\'t valid Credit Card';
					showError(data.error);
				}
			}
		}
	}

	function saveNote(x, LotID)
	{
		unrollNote();
		var interval = 1000; // saving in [interval] seconds
		var tmp = new Date();
		var sec = tmp.getTime();

//		$('report').value += 'Last click - ' + GLOBALS['click_time'] + '; Execute - ' + (sec - interval) + "\n";
//									<textarea cols="100" rows="20" id="report"></textarea>

		if (GLOBALS['click_time'] && (GLOBALS['click_time'] <= (sec - interval))) {
			savingNote(LotID);
		} else if (x) {
			GLOBALS['click_time'] = sec;
			setTimeout('saveNote(0, ' + LotID + ');', interval);
		}
	}
	function savingNote(LotID)
	{
//		alert(LotID + ' - ' + $('personal_note').value);
//		delete(GLOBALS['click_time']);

		doLoad(true, false, 'saving_note', {lot: LotID, note: $('personal_note').value});
	}
	function unrollNote()
	{
		var rows = $('personal_note').value.split("\n").length;
		$('personal_note').rows = (rows < 3 ? 3 : rows);
	}

	function updateLotsList(req)
	{
		var flag = true;
		var price;
		if (GLOBALS["loaded_lots"]) {
			for (var i in GLOBALS["loaded_lots"]) {
				flag = false;
			}
		}
		if (flag) {
			return;
		}

//		alert(var_dump(GLOBALS.lots_req));
		if (req.refresh) {
			for (var i in req.result) {
//				if (req.result[i].finish > 0) {

					if (req.result[i].lot_status == 10 || req.result[i].lot_status == 11) {
						$('price_box_' + i).innerHTML = '';
						$('next_bid_box_' + i).innerHTML = '';
						$('counter_box_' + i).innerHTML = '';
						continue;
					}

					price = '$' + numberFormat(req.result[i].price);
					if (req.result[i].bidder == GLOBALS.logged_user_id) {
						price = '<span style="color: #990000;" title="You are High Bidder">' + price + '</span>';
					}
					$('price_box_' + i).innerHTML = price;

					var counterBoxContent = '';
					if(req.result[i].price_type == 'fixed'  && req.result[i].best_offer == 'Y'){
						counterBoxContent = '<i><a href="/auction/lot.php?id=' + req.result[i].id + '">Best <span style="color:#39AABE;">Offer</span></a><br /><br /></i>';
					} else if(req.result[i].price_type == 'fixed'){
						counterBoxContent = '';
					} else if((req.result[i].price < req.result[i].buy_now_value/2) && req.result[i].buy_now == 'Y' && req.result[i].price_type == 'auction'){
						counterBoxContent = '<i>Buy It <span style="color:#B6000D;">Now</span></i>';
					} else if((req.result[i].count == 0) && req.result[i].buy_now == 'Y' && req.result[i].price_type == 'auction' && req.result[i].sl_lot_status == 1){
						counterBoxContent = '<i>Buy It <span style="color:#B6000D;">Now</span></i>';
					} else {
						counterBoxContent = req.result[i].count;
					}

					if (auction_type == 'self') {
						var buyBidButtonHtml = '';
						// buy/bid button in list
						if (req.result[i].price_type == 'fixed') {
							buyBidButtonHtml += useButton('buy_now_fixed', {id: i});
						} else if (req.result[i].price_type == 'auction') {
							buyBidButtonHtml += '<br/>' + useButton('bid_next_increment', {id: i, box: 'next_bid_value_' + i, short_button: true});
						}
						$('buy_bid_button_' + i).innerHTML = buyBidButtonHtml;
					}

					$('counter_box_' + i).innerHTML = counterBoxContent;
					$('reserve_box_' + i).innerHTML = req.result[i].reserve;
//				}

				if (GLOBALS["loaded_lots"][i]) {
					GLOBALS["loaded_lots"][i].price = req.result[i].price;
					GLOBALS["loaded_lots"][i].count = req.result[i].count;
					GLOBALS["loaded_lots"][i].reserve = req.result[i].reserve;
					GLOBALS["loaded_lots"][i].bidder = req.result[i].bidder;
					GLOBALS["loaded_lots"][i].finish = req.result[i].finish;
					GLOBALS["loaded_lots"][i].r_time = req.result[i].r_time;
					GLOBALS["loaded_lots"][i].f_date = req.result[i].f_date;
					GLOBALS["loaded_lots"][i].auction_id = req.result[i].auction_id;
					GLOBALS["loaded_lots"][i].increment = req.result[i].increment;
					GLOBALS["loaded_lots"][i].price_type = req.result[i].price_type;
				}
			}
			setTimeAndNextBid();
			GLOBALS.lots_req = req.result;
		} else {
			GLOBALS.lots_req = req.request;
		}
//		alert(var_dump(GLOBALS.lots_req));
		GLOBALS.lots_list_price = setTimeout('doLoad(true, false, "lots_list_price", GLOBALS.lots_req);', GLOBALS.list_refresh_interval);
	}
	function setTimeAndNextBid()
	{
		for (var i in GLOBALS["loaded_lots"]) {
			var time = parseInt(GLOBALS["loaded_lots"][i].finish);
			var r_time = parseInt(GLOBALS["loaded_lots"][i].r_time);
			if (time > 0) {
				var tmp;

				if (GLOBALS["loaded_lots"][i].count > 0) {
					tmp = enlargeBid(GLOBALS["loaded_lots"][i].price, GLOBALS["loaded_lots"][i].increment, GLOBALS["loaded_lots"][i].auction_id);
				} else {
					tmp = myParseFloat(GLOBALS["loaded_lots"][i].price);
				}

				if (GLOBALS["loaded_lots"][i].lot_status == 1) {
					if(GLOBALS["loaded_lots"][i].price_type == 'auction'){
						$('next_bid_box_' + i).innerHTML = '$' + numberFormat(tmp);
					} else{
						$('next_bid_box_' + i).innerHTML = '<i>Fixed <span style="color:#0090D9;">Price</span></a></i><br />' + '$' + numberFormat(tmp);
					}
					$('next_bid_value_' + i).value = tmp;
				} else {
					$('next_bid_box_' + i).innerHTML = 'n/a';
				}
			} else {
				$('next_bid_box_' + i).innerHTML = 'n/a';
				$('next_bid_value_' + i).value = '';
				$('bid_button_box_' + i).style.display = 'none';
			}
			setListFinishTime($('time_box_' + i), time, i, GLOBALS["loaded_lots"][i].lot_status, GLOBALS["loaded_lots"][i].f_date, r_time);
		}
	}
	function setListFinishTime(box, time, lot_id, status, f_date, r_time)
	{
		if (status == 1) {
// Auction
			if (r_time > 0) {
				box.innerHTML = getTimeStr(r_time, 'short', f_date);
			} else {
				if (time > 0) {
					box.innerHTML = '<div style="text-align: center; font-size: 10px; line-height: 9px;">extended<br />session</div>';
				} else {
					closeAuctionOrLot(lot_id);
					box.innerHTML = 'Closed';
				}
			}
		} else {
			if (status == 2 || status == 4 || status == 6 || status == 3 || status == 9 || status == 12 || status == 14) {
// Sold or Shipped or Closed or Returned or Not Sold or Dispute
				box.innerHTML = 'Closed';
			} else if (status == 10) {
// Not Published
				box.innerHTML = 'not published';
			} else if (status == 11) {
// Preview
				box.innerHTML = 'not started';
			} else {
				box.innerHTML = 'error';
			}
			delete(GLOBALS["loaded_lots"][lot_id]);
		}
	}

	function closeAuctionOrLot(lot_id)
	{
		var obj = {'lot_id': lot_id};
		if (GLOBALS["auction_data_id"] > 0) {
			if (GLOBALS["auction_closed_id"] == GLOBALS["auction_data_id"]) {
				return
			}
			obj['auction_id'] = GLOBALS["auction_data_id"];
			GLOBALS["auction_closed_id"] = GLOBALS["auction_data_id"];
		}
//		alert(var_dump(obj));
		doLoad(true, false, 'close_auction', obj);
	}


	function showFeedbackCommentForm(id, feedback_id, comments_html)
	{
		if (typeof(comments_html) == 'undefined' || comments_html == '') {
			comments_html = 'You have no comments';
		}
		var html = '';
		var box = $('feedback_comment_form_' + id);

		html += '' +
					'<table cellspacing="5" cellpadding="0" width="420" border="0">' +
						'<tr>' +
							'<td width="50%" style="vertical-align: top;">' +
								'<fieldset>' +
									'<legend>Your comments</legend>' +
									comments_html +
								'</fieldset>' +
							'</td>' +
							'<td width="50%" style="vertical-align: top;">' +
								'<fieldset>' +
									'<legend>Add comment </legend>' +
									'<form action="" method="post" style="margin: 0px; padding: 0px;" />' +
										'<input type="hidden" name="feedback_id" value="' + feedback_id + '" />' +
									'<table cellspacing="3" cellpadding="0" width="" border="0" class="feedback_comment_form">' +
										'<tr>' +
											'<td colspan="2">' +
												'<textarea name="feedback_comment" cols="3" style="width: 200px;"></textarea>' +
											'</td>' +
										'</tr>' +
										'<tr>' +
											'<td colspan="2" style="text-align: right;">' +
												'<input type="submit" value="Save" />' +
												'<input type="button" value="Cancel" onclick="$(\'feedback_comment_form_\' + ' + id + ').style.display = \'none\';" />' +
											'</td>' +
										'</tr>' +
									'</table>' +
									'</form>' +
								'</fieldset>' +
							'</td>' +
						'</tr>' +
					'</table>';

		box.innerHTML = html;
		box.style.display = 'block';
	}

	function preloadImages()
	{
		addLoadEvent(function() {
			MM_preloadImages('/pics/login2_b.gif', '/pics/logout_b.gif', '/pics/my_account_b.gif','/pics/subscribe_b.gif','/pics/about_us_b.gif','/pics/contact_us_b.gif','/pics/player_charts_b_r.gif','/pics/price_guide_b_r.gif','/pics/news_b_r.gif','/pics/network_b_r.gif','/pics/expert_corner_b_r.gif','/pics/forums_b_r.gif','/pics/auctions_b_r.gif','/pics/directory_b_r.gif');
		});
	}

	function addLoadEvent(func)
	{
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
				if (oldonload) {
					oldonload();
				}
				func();
			}
		}
	}

	function checkNewBid(id, mktime)
	{
		if (typeof(mktime) != "undefined") {
			if (mktime > GLOBALS.req.mktime) {
				doLoad(true, false, "get_lot_trading_data", GLOBALS.req);
			} else {
				GLOBALS.lot_data_timeout = setTimeout('checkNewBid(GLOBALS.req.id);', 1000);
			}
		} else if (GLOBALS.canLoad) {
			var req = new Subsys_JsHttpRequest_Js();
			req.caching = false;
			req.open('POST', 'http://bidcheck.gameuseduniverse.com/dev/bid/' + id + '.txt', true);
			req.send();
		} else {
			setTimeout('checkNewBid(' + id + ');', 100);
		}
	}

	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 'get_lot_trading_data':
							updateLotTradingHTML(req.responseJS);
							break;
						case 'lots_list_price':
							updateLotsList(req.responseJS);
							break;
						case 'close_auction':
							if (!req.responseJS.result) {
//								doLoad(true, false, "get_lot_trading_data", {id: req.responseJS.id});
							}
							break;
						case 'saving_note':
//							alert(var_dump(req.responseJS));
							delete(GLOBALS['click_time']);
							break;
						case 'remember_tree_state':
//							alert(var_dump(req.responseJS));
							break;
						case 'get_auction_bid_date':
							auction_data = req.responseJS;
//							alert(var_dump(auction_data));
							setReserveOptions();
							break;
						case 'cccheck':
							checkCC(req.responseJS.request.id, req.responseJS);
							break;
						case 'click_relist':
						case 'click_watch_list':
						case 'click_bid_next_increment':
						case 'click_place_absolute_bid':
						case 'click_place_cailing_bid':
						case 'click_buy_now_fixed':
						case 'click_place_best_offer':
						case 'click_second_chance':
							useButton(type.replace(/click_/, ''), req.responseJS, 'response');
							break;
						default:
							showError('unknown type');
							break;
					}
				}
//				$('debug').innerHTML = req.responseText;
			}
		}

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

	function inputPlaceholder(obj, placeholder) {
		if (!obj) return;
		var originalColor = obj.style.color;
		obj.onblur = function() {
			if (this.value == '') {
				this.value = placeholder;
				this.style.color = '#aaaaaa';
			} else {
				this.style.color = originalColor;
			}
		}
		obj.onfocus = function() {
			this.style.color = originalColor;
			if (this.value == placeholder) {
				this.value = '';
			}
		}
		obj.onblur();
	}

	document.doLoad = doLoad;
	document.checkNewBid = checkNewBid;