
String.prototype.trim = function() {
   return this.replace(/^\s+|\s+$/g, '');
};

String.prototype.endsWith = function(s) {
	return this.match( s + '$');
};

var count = 1;
var receivedCount = 0;
var DAY = 86400;
var HOUR = 3600;
var MINUTE = 60;
var CLEAR_TIMEOUT = 15000;
var CLASS_NAME_ATTR = "className";
var CLASS_ATTR = "class";
var SEP = ";";

var clearTimeoutId = setTimeout(clearAll, CLEAR_TIMEOUT);
var auctions = new Object();
var auctionsCount = 0;
var auctionsNR = new Object();
var bidsId = undefined;
var bidsWinner = undefined;
var imgId = undefined;
var imgSrc = new Object();

// buttons
function cleanClassName(name) {
   return name.replace('_hover', '').replace('_active', '');
}

function hover(b) {
   var cn = cleanClassName(b.className);
   b.className = cn + '_hover';
}
function out(b) {
   var cn = cleanClassName(b.className);
   b.className = cn;
}
function active(b) {
   var cn = cleanClassName(b.className);
   b.className = cn + '_active';
}

function cleanImageSrc(src) {
   return src.replace('_hover', '').replace('_active', '');
}
function hover_img(i) {
	i.src = cleanImageSrc(i.src).replace(/.(jpg|png)$/, "_hover.$1");
}
function out_img(i) {
	i.src = cleanImageSrc(i.src);
}
function active_img(i) {
	i.src = cleanImageSrc(i.src).replace(/.(jpg|png)$/, "_active.$1");
}

function getParams() {
	var params = "";
//	params = auctions.join(SEP) + SEP;
	/*
	 * tablica samych id, robić join, i wrzucać tylko te, które się nie skończyły jeszcze
	 */
	auctionsCount = 0;
	for (var id in auctions) {
		params = params + id + SEP;
		auctionsCount++;
	}
	if (params != "") {
		params = "ids=" + params + "&";
	}
	if (bidsId != undefined) {
		if (params == "") {
			params = "ids=" + bidsId + "&";
		}
		params = params + "bidsId=" + bidsId + "&";
	}
	params = params + "c=" + count + "&";
	count++;
	return params;
}
///////////////////////////////////////////////////////////////////////////////////
//aktualizacja htmla
function setInnerHtml(id, html) {
	setInnerHtmlAndStyle(id, html, null);
}

function setInnerHtmlAndStyle(id, html, style) {
	setRealInnerHtmlAndStyle(id, html, style);
	for (var i = 0; i < 3; i++) {
		setRealInnerHtmlAndStyle(id + "_" + i, html, style);
	}
}
var price_regexp = new RegExp("\\D(\\d+[,.]\\d{2})\\D");
function setRealInnerHtmlAndStyle(id, html, style) {
	var e = document.getElementById(id);
	if (e != undefined) {
		//log("update pola: " + id + " = " + html);
		
		if (style != null) {
			html = "<div class=\"" + style + "\">" + html + "</div>";
		}
		var oldHtml = e.innerHTML;
		e.innerHTML = html;
		if (id.indexOf("p") > -1) {//blink
			var oldPrice = price_regexp.exec(oldHtml);
			var newPrice = price_regexp.exec(html);
			if ((oldPrice != null) && (newPrice != null)) {
				//log("blink: " + oldPrice[1] + " ? " + newPrice[1]);
				if (oldPrice[1] != newPrice[1]) {
					blink(id);
				}
			}
		}
	}
}

function enableButton(id) {
	var e = document.getElementById("s" + id);
	if (e != undefined) {
		e.disabled = false;
	}
	for (var i = 0; i < 3; i++) {
		var e = document.getElementById("s" + id + "_" + i);
		if (e != undefined) {
			e.disabled = false;
		}
	}
}
function disableButtonTemp(id) {
	var e = document.getElementById("s" + id);
	if (e != undefined) {
		e.disabled = true;
	}
	for (var i = 0; i < 3; i++) {
		var e = document.getElementById("s" + id + "_" + i);
		if (e != undefined) {
			e.disabled = true;
		}
	}
	setTimeout("enableButton('" + id + "')", 500);
}
function disableButton(id) {
	realDisableButton("s" + id);
	for (var i = 0; i < 3; i++) {
		realDisableButton("s" + id + "_" + i);
	}
}
function realDisableButton(id) {
	var e = document.getElementById(id);
	if (e != undefined) {
		e.disabled = true;
		e.value = msg_finished_button;
	}
}
///////////////////////////////////////////////////////////////////////////
// parsowanie odpowiedzi z serwera
function updateAuctions(request) {
	if (request.readyState == 4) {
		//log("got answer: " + request.status);
		if (request.status == 200) {
			var errors = new Array();
			var messages = new Array();
			//parse request
			//log(request.responseText);
			var lines = request.responseText.trim().split("\n");
			var updatedAuctions = new Object();
			for (var i = 0; i < lines.length; i++) {
				var properties = lines[i].trim().split(SEP);
				//log(lines[i] + ", splited: " + properties.length + ", " + properties[0]);
				if (properties.length > 0) {
					switch (properties[0]) {
					case "#CN":
						var c = parseInt(properties[1]);
						if (c <= receivedCount) {
							i = lines.length;
						} else {
							receivedCount = c;
						}
						break;
					case "#BI":
						switchImg(properties[1]);
						break;
					case "#ER":
						errors.push(properties[2]);
						//log("have error");
						break;
					case "#MS":
						messages.push(properties[2]);
						//log("have message");
						break;
					case "#BC":
						updateBidsCount(properties[1]);
						break;
					case "#RT":
						setInnerHtml("robot", properties[1]);
						break;
					case "#PR":
						showPrice(properties[1], properties[2], true, properties[3]);
						break;
					case "#PD":
						showPriceDone(properties[1], properties[2]);
						break;
					case "#RE":
						getPrice(properties[1]);
						break;
					case "#RD":
						window.location.href = properties[1];
						break;
					}
				}
			}
			if (messages.length > 0) {
				show("messages", messages);
			}
			if (errors.length > 0) {
				show("errors", errors);
			}
			//log("finished answer");
		} else if ((request.status != 404) && (request.status != 500) && (request.status != 503)) { //if ((request.status == 301) || (request.status == 302)) {
			//redirect do strony logowania
			var newLocation = request.getResponseHeader("Location");
			if ((newLocation != null) && (newLocation != "")) {
				window.location.href = newLocation
			} else {
				window.location.href = LOGIN_PAGE;
			}
		} else {
			//odswiez cala strone
			window.location.reload();
		}
		releaseRequestObject(request);
	}
}

function checkMinimumTime(currentTime) {
	var seconds = updateMinSeconds;
	if (isNaN(currentTime)) {
		return currentTime;
	} else {
		var currentSeconds = parseInt(currentTime);
		if (currentSeconds > seconds) {
			seconds = currentSeconds;
		}
	}
	return seconds;
}

function finishAuction(id) {
	log("finishAuction " + id);
	setInnerHtmlAndStyle("t" + id, msg_finished, "timer");
	auctions[id] = undefined;
	disableButton(id);
	if (id == bidsId) {
		// ten jest tylko jeden na stronie!
		e = document.getElementById("c" + id);
		if (e != undefined) {
			if (bidsWinner == loggedUser) {
				e.innerHTML = msg_congratulations;
			} else {
				e.innerHTML = msg_congratulationsTo + bidsWinner;
			}
		}
		e = document.getElementById("bidParams");
		//log("mam bidParams");
		if (e != undefined) {
			//log("parent: " + e.parentNode);
			e.parentNode.removeChild(e);
		}
	}
}

function formatRemainingTime(seconds) {
	var ss = 0;
	var mm = 0;
	var hh = 0;
	var dd = 0;
	var result = msg_robots;
	if (seconds > 0) {
		result = "";
		dd = Math.floor(seconds / DAY);
		if (dd >= 2) {
			result = dd + " " + msg_days;
		} else {
			hh = Math.floor(seconds / HOUR);
			mm = Math.floor((seconds - hh * HOUR) / MINUTE);
			ss = seconds - hh * HOUR - mm * MINUTE;
			if (hh < 10) {
				result = "0";
			}
			result = result + hh + ":";
			if (mm < 10) {
				result = result + "0";
			}
			result = result + mm + ":";
			if (ss < 10) {
				result = result + "0";
			}
			result = result + ss;
		}
	}
	return result;
}

function setNewTime(id, newSeconds, finish) {
	var oldSeconds = auctions[id];
	auctions[id] = newSeconds;
	if (auctions[id] != undefined) {
		if (finish) {
			finishAuction(id);
		} else {
			enableButton(id);
			if (auctions[id] == 'soon') {
				setInnerHtmlAndStyle("t" + id, msg_soon, "timer");
			} else {
				var seconds = parseInt(auctions[id]);
				if (!isNaN(oldSeconds) && ((parseInt(oldSeconds) - seconds) != -1)) {
					//log(id + " " + time);
					seconds = seconds - 1;
					var time = formatRemainingTime(seconds);
					if (seconds < timerInverse) {
						if ((seconds <= 0) && (auctionsNR[id] != undefined)) {
							time = "00:00:00";
						}
						setInnerHtmlAndStyle("t" + id, time, "timer_inverse");
					} else if (seconds < timerAlert) {
						setInnerHtmlAndStyle("t" + id, time, "timer_alert");
					} else {
						setInnerHtmlAndStyle("t" + id, time, "timer");
					}
				}
			}
		}
	}
}

function setNewDelta(id, delta) {
	var e = document.getElementById("d" + id);
	if (e != null) {
		var newDelta = null;
		if (delta > DAY) {
			newDelta = Math.floor(delta/DAY) + " " + msg_short_days;
		} else if (delta > HOUR) {
			newDelta = Math.floor(delta/HOUR) + " " + msg_short_hours;
		} else if (delta > MINUTE) {
			newDelta = Math.floor(delta/MINUTE) + " " + msg_short_minutes;
		} else {
			newDelta = delta + " " + msg_short_seconds;
		}
		//e.className = "as_blue" + delta;
		e.innerHTML = newDelta;
	}
}

function switchImg(id) {
	var e;
	if (imgId != id) {
		if (imgSrc[imgId] != undefined) {
			e = document.getElementById("i" + imgId);
			if (e != undefined) {
				e.src = imgSrc[imgId];
				imgSrc[id] = undefined;
			}
		}
		imgId = id;
		e = document.getElementById("i" + imgId);
		if ((e != undefined) && (e.src != BONUS_IMAGE)) {
			imgSrc[id] = e.src;
			e.src = BONUS_IMAGE;
		}
	}
}
/////////////////////////////////////////////////////////////////
// flash
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;

/* IE update fix */
function showMovieMax(id, name, src, vars, width, height, color, secure) {
	var e = document.getElementById(id);
	if (e != undefined) {
		document.write(prepShowMovie(name, src, vars, width, height, color, secure));
		e.style.display = 'block';
		var maxW = "1000";
		if (isIE) {
			maxW = document.body.offsetWidth - 20;
		} else  {
			maxW = window.innerWidth - 20;
		}
		e.style.width = maxW + "px";
	}
}
function showMovie(name, src, vars, width, height, color, secure) {
	document.write(prepShowMovie(name, src, vars, width, height, color, secure));
}
function prepShowMovie(name, src, vars, width, height, color, secure) {
	var m = '';
	m = m + '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="';
	if (secure) {
		m = m + 'https';
	} else {
		m = m + 'http';
	}
	m = m + '://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + width + '" height="' + height + '" id="' + name + '" align="top">\n';
	m = m + '<param name="FlashVars" value="' + vars + '" />\n';
	m = m + '<param name="allowScriptAccess" value="sameDomain" />\n';
	m = m + '<param name="movie" value="' + src + '" />\n';
	m = m + '<param name="quality" value="high" />\n';
	if (color == 'null') {
		m = m + '<param name="wmode" value="transparent" />\n';
	} else {
		m = m + '<param name="bgcolor" value="' + color + '" />\n';
	}
	if (!isIE) {
		m = m + '<embed src="' + src + '" FlashVars="' + vars + '" quality="high" ';
		if (color == 'null') {
			m = m + 'wmode="transparent" ';
		} else {
			m = m + 'bgcolor="' + color + '" ';
		}
		m = m + 'width="' + width + '" height="' + height + '" name="' + name + '" align="top" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="';
		if (secure) {
			m = m + 'https';
		} else {
			m = m + 'http';
		}
		m = m + '://www.macromedia.com/go/getflashplayer" />\n';
	}
	m = m + '</object>\n';
	return m;
}

/////////////////////////////////////////////////////////////////
// ukrywanie elementów bo kliknięciu checkboxa
function hide(id, checkbox, count) {
	var e;
	var v = 'visible';
	var p = 'static';
	if (! checkbox.checked) {
		v = 'hidden';
		p = 'absolute';
	}
	for (var i = 0; i < count; i++) {
		e = document.getElementById(id + i);
		if (e != null) {
			e.style.visibility = v;
			e.style.position = p;
		}
	}
}
function toggle(id, count) {
	for (var i = 0; i < count; i++) {
		toggleOne(id + i);
	}
}
function toggleOne(id) {
	var e = document.getElementById(id);
	if (e != null) {
		if ((e.style.visibility == null) || (e.style.visibility == '') || (e.style.visibility == 'visible')) {
			e.style.visibility = 'hidden';
			e.style.position = 'absolute';
		} else {
			e.style.visibility = 'visible';
			e.style.position = 'static';
		}
	}
}
function setDisabled(id, count, d) {
	var i;
	var e;
	for (i = 0; i < count; i++) {
		e = document.getElementById(id + i);
		if (e != undefined) {
			e.disabled = d;
		}
	}
}
function enableFields(id, count) {
	setDisabled(id, count, false);
}
function disableFields(id, count) {
	setDisabled(id, count, true);
}
/////////////////////////////////////////////////////////////////
//
function updateBidsCount(count) {
	var e = document.getElementById("bidsCount");
	//log("bidsCount: " + e.nodeName);
	if (e != undefined) {
		if (count == "-") {
			//reload, wylogowany
			window.location.reload();
		} else {
			e.innerHTML = count.trim();
		}
	}
}
/////////////////////////////////////////////////////////////////
// errors i messages
function clearAll() {
//	log("clearing all");
	if (clearTimeoutId != null) {
		clearTimeout(clearTimeoutId);
		clearTimeoutId = null;
	}
	clear("errors");
	clear("messages");
	//log("clean");
}
function clear(id) {
	var e = document.getElementById(id);
	if (e != undefined) {
		while (e.childNodes.length > 0) {
   			e.removeChild(e.firstChild);
		}
	}
}
function show(id, texts) {
	var e = document.getElementById(id);
//	log("show: " + id + ", " + e);
	if (e != undefined) {
		while (e.childNodes.length > 0) {
   			e.removeChild(e.firstChild);
		}
		var ul = document.createElement("ul");
		e.appendChild(ul);
		ul.setAttribute(CLASS_NAME_ATTR, id);
		ul.setAttribute(CLASS_ATTR, id);
		var li;
		for (var i = 0; i < texts.length; i++) {
			li= document.createElement("li");
			ul.appendChild(li);
			li.appendChild(document.createTextNode(texts[i]));
		}
		if (clearTimeoutId != null) {
			clearTimeout(clearTimeoutId);
		}
		clearTimeoutId = setTimeout(clearAll, CLEAR_TIMEOUT);
	}	
}
/////////////////////////////////////////////////////////////////
// przełączanie obrazków
function showBig(name, path) {
	var e = document.images[name];
	log(e.src + ", " + path);
	if (e != null) {
		e.src = path;
	}
}

/////////////////////////////////////////////////////////////////
// ograniczenie długości pól tekstowych
function checkLength(e, t, l) {
	var keycode;
	if (e != null) {
		if (e.keyCode) {
			keycode = e.keyCode;
		} else {
			keycode = e.which;
		}
	}
	if ((keycode > 34) && (keycode < 41) || (keycode == 8) || (keycode == 9) || (keycode == 116)) {
		return true;
	} else if (t.value.replace(/[\r\n]*/g, "").length >= l) {
		return false;
	}
	return true;
}
function updateRemainingCharacters(t, l) {
	var c = document.getElementById("counter");
	if (c != undefined) {
		c.innerHTML = msg_remaining_characters + (l - t.value.replace(/[\r\n]*/g, "").length);
	}
}
/////////////////////////////////////////////////////////////////
//
function checkSubmit(e) {
	var keycode;
	if (e != null) {
		if (e.keyCode) {
			keycode = e.keyCode;
		} else {
			keycode = e.which;
		}
	}
	return (keycode != 13);
}
/////////////////////////////////////////////////////////////////
// ustawia focus
function focus(id) {
	var e = document.getElementById(id);
	if (e != undefined) {
		e.focus();
	}
}
/////////////////////////////////////////////////////////////////
// miganie
var colors = new Array('#22bb22', '#2cb122', '#3aa220', '#49911f', '#58831e', '#67721e', '#77621d', '#85531b', '#95431b', '#a5321a', '#b22418', '#be1818');
var bgColors = new Array('#22bb22', '#2ebe2d', '#42c543', '#5acc5a', '#6fd36f', '#85da85', '#9ae09b', '#b1e7b0', '#c6edc7', '#dbf4dc', '#f1fbf1', 'transparent');
function blink(id) {
	var e = document.getElementById(id);
	//log("blinking " + id + ", " + e);	
	if (e != undefined) {
		e.style.backgroundColor = bgColors[0];
		setTimeout("fade('" + id + "', 1, true)", 20);
		//e.style.color = colors[0];
		//setTimeout("fade('" + id + "', 1, false)", 40);
	}
}
function fade(id, colorId, bg) {
	var e = document.getElementById(id);
	if (e != undefined) {
		if (bg) {
			e.style.backgroundColor = bgColors[colorId];
		} else {
			e.style.color = colors[colorId];
		}
		colorId++;
		//log("fade: " + colorId);
		if (colorId < bgColors.length) {
			setTimeout("fade('" + id + "', " + colorId + ", " + bg + ")", 20);
		}
	}
}

/////////////////////////////////////////////////////////////////
//sprawdzanie cookie
function cookiesEnabled(path) {
	document.cookie = "test_cookie=cookie_enabled";
	var idx = document.cookie.indexOf("test_cookie=");
	var date = new Date();
	date.setTime(date.getTime() + ((-1)*24*60*60*1000));
	document.cookie = "test_cookie=; expires=" + date.toGMTString();
	if (idx == -1) {
		window.location.replace(path);
	}
}

/////////////////////////////////////////////////////////////////
// logowanie
var logs = new Array();
function log(msg) {
	var log = document.getElementById("log");
	if (log != null) {
		var now = new Date();
		logs.push(msg);
		if (logs.length > 50) {
			logs.shift();
		}
		log.innerHTML = logs.join("<br>");
	}
}
/////////////////////////////////////////////////////////////////
//
function getRequestParam(param) {
	var query = document.location.search.substring(1);
	var params = query.split('&');
	for (var i = 0; i < params.length; i++) {
		if (params[i].indexOf(param) > -1) {
			var pos = params[i].indexOf('=');
			if (pos > 0) {
				return params[i].substring(pos + 1);
			}
		}
	}
	return "";
}
/////////////////////////////////////////////////////////////////
//menu highlighting

function leftMenuHover(id) {
	if (id != null) {
		if (!id.className.trim().endsWith('_selected')) {
			if (id.className.trim().endsWith('_arrow')) {
				id.style.backgroundImage = 'url(\'' + IMAGES_PATH + 'box_arrow_highlighted.png\')';
			}
			else if (id.className.trim().endsWith('_noarrow')) {
				id.style.backgroundImage = 'url(\'' + IMAGES_PATH + 'box_noarrow_highlighted.png\')';
			}
		}
	}
}

function leftMenuOut(id) {
	if (id != null) {
		if (!id.className.trim().endsWith('_selected')) {
			if (id.className.trim().endsWith('_arrow')) {
				id.style.backgroundImage = 'url(\'' + IMAGES_PATH + 'box_arrow.png\')';
			}
			else if (id.className.trim().endsWith('_noarrow')) {
				id.style.backgroundImage = 'url(\'' + IMAGES_PATH + 'box_noarrow.png\')';
			}
		}
	}
}

function topMenuHover(id) {
	if (id != null) {
		id.style.backgroundColor = '#dddddd';
	}
}

function topMenuOut(id) {
	if (id != null) {
		id.style.backgroundColor = 'transparent';
	}
}

/////////////////////////////////////////////////////////////////
//help karta kredytowa CVV

var cvvHelp = null;

function _getOffsetTop(e) {
	var offsetTop = e.offsetTop;
	var parent = e.offsetParent;
	while (parent != null) {
		offsetTop = offsetTop + parent.offsetTop;
		parent = parent.offsetParent;
	}
	return offsetTop;
}

function _getOffsetLeft(e) {
	var offsetLeft = e.offsetLeft;
	var parent = e.offsetParent;
	while (parent != null) {
		offsetLeft = offsetLeft + parent.offsetLeft;
		parent = parent.offsetParent;
	}
	return offsetLeft;
}

function hideCvvHelp() {
	if (cvvHelp != null) {
		var body = document.getElementsByTagName("body")[0];
		body.removeChild(cvvHelp);
		cvvHelp = null;
	}	
}

function showCvvHelp(id, imagePath) {
	if (cvvHelp == null) {
		var body = document.getElementsByTagName("body")[0];
		cvvHelp = document.createElement("div");
		var image = new Image();
		image.src = imagePath;
		cvvHelp.innerHTML = "<img src=\"" + imagePath + "\" onmouseout=\"hideCvvHelp();\"/>";
		body.appendChild(cvvHelp);
		with (cvvHelp.style) {			
			width = image.width + 'px';
			height = image.height + 'px';
			position = 'absolute';
			top = _getOffsetTop(id) + 'px';
			left = _getOffsetLeft(id) + 'px';
			borderWidth = '1px';
			borderStyle = 'solid';
			borderColor = 'black';
		}
	}
}

/////////////////////////////////////////////////////////////////////////////////////////
// check price

var auctionsRE = new Object();

function getPrice(auctionId) {
	setTimeout("getPrice2(" + auctionId + ")", 500);
}
function getPrice2(auctionId) {
	if (auctionId != '') {
		if (auctionsRE[auctionId] != undefined) {
			return true;
		}
		sendRequest(updateAuctions, CHECK_PRICE_PAGE + "?js=true&aid=" + auctionId + "&", null);
	}
	return false;
}
function checkPrice(auctionId) {
	if (auctionId != '') {
		if (auctionsRE[auctionId] != undefined) {
			return true;
		}
		if (loggedUser != '') {
			disableButtonTemp(auctionId);
			sendRequest(updateAuctions, CHECK_PRICE_ACTION_PAGE + "?js=true&aid=" + auctionId + "&", null);
		} else {
			return true;
		}
	}
	return false;
}

function checkPriceByCode(auctionId) {
	var e = document.getElementById("cbc");
	if (e != undefined) {
		if (auctionId != '') {
			if (auctionsRE[auctionId] != undefined) {
				return true;
			}
			if (e.value != '') {
				disableButtonTemp(auctionId);
				sendRequest(updateAuctions, CHECK_PRICE_ACTION_PAGE + "?js=true&aid=" + auctionId + "&code=" + e.value + "&", null);
				e.value = '';
			}
		}
	}
	return false;
}

function showPrice(auctionId, price, show, savings) {
	if (show) {
		showBuy(auctionId, price, "", savings);
		for (var i = 1; i < 4; i++) {
			showBuy(auctionId, price, "_" + i, savings);
		}
	}
	auctionsRE[auctionId] = price;
	setTimeout("hidePrice(" + auctionId + ")", 15000);
}
var buyButton = '';

function showBuy(auctionId, price, suffix, savings) {
	var e = document.getElementById("f" + auctionId + suffix);
	if (e != undefined) {
		e.action = BEFORE_BUY_PAGE;
		e.method = "POST";
		e["price"].value = price;
		var b = document.getElementById("s" + auctionId + suffix);
		if (b != undefined) {
			b.value = msg_wantToBuy_button;
		}
		var stamp = " class=\"stamp\"";
		e = document.getElementById("bth");
		if (e != undefined) {
			stamp = "";
			buyButton = e.innerHTML;
			e.innerHTML = '';
			b.value = msg_buy_button;
			b.className = "button_check_green";
		}
		e = document.getElementById("p" + auctionId + suffix);
		if (e != undefined) {
			e.innerHTML = '<div class="price">' + price + "</div>";
			blink("p" + auctionId + suffix);
		}
		e = document.getElementById("stamp" + auctionId + suffix);
		if (e != undefined) {
			e.innerHTML = "<img src=\"/images/stamps/" + savings + ".png\"" + stamp + ">";
		}
	}
}

function showPriceDone(auctionId, price) {
	showSold(auctionId, price, "");
	for (var i = 1; i < 4; i++) {
		showSold(auctionId, price, "_" + i);
	}
}

function showSold(auctionId, price, suffix) {
	var e = document.getElementById("f" + auctionId + suffix);
	if (e != undefined) {
		e.action = '';
		e.method = "POST";
		e["price"].value = '';
		auctionsRE[auctionId] = price;
		realDisableButton("s" + auctionId + suffix);
		e = document.getElementById("p" + auctionId + suffix);
		if (e != undefined) {
			e.innerHTML = '<div class="price">' + price + "</div>";
			blink("p" + auctionId + suffix);
		}
	}
}
function hidePrice(auctionId) {
	hideBuy(auctionId, "");
	for (var i = 1; i < 4; i++) {
		hideBuy(auctionId, "_" + i);
	}
}

function hideBuy(auctionId, suffix) {
	var e = document.getElementById("f" + auctionId + suffix);
	if (e != undefined) {
		e.action = CHECK_PRICE_ACTION_PAGE;
		e.method = "GET";
		var oldPrice = e["price"].value;
		e["price"].value = '';
		auctionsRE[auctionId] = undefined;
		e = document.getElementById("s" + auctionId + suffix);
		if (e != undefined) {
			e.value = msg_check_button;
			e.className = "button_check_big";
		}
		e = document.getElementById("bth");
		if (e != undefined) {
			e.innerHTML = buyButton;
		}
		e = document.getElementById("p" + auctionId + suffix);
		if (e != undefined) {
			if (suffix == "") {
				e.innerHTML = '<div class="price">' + msg_pricex + "</div>";
			} else {
				e.innerHTML = '<div class="price">' + msg_price + "</div>";
			}
			blink("p" + auctionId + suffix);
		}
		if (suffix == "") {
			e = document.getElementById("stamp" + auctionId);
			if (e != undefined) {
				e.innerHTML = "";
			}
			e = document.getElementById("pp" + auctionId);
			if (e != undefined) {
				e.innerHTML = '<strong>' + oldPrice + "</strong>";
			}
		}
	}
}

function nextBlink(auctionId, first) {
	if (auctionsRE[auctionId] == undefined) {
		if (! first) {
			blink("p" + auctionId);
			for (var i = 1; i < 4; i++) {
				blink("p" + auctionId + "_" + i);
			}
		}
		var next = 10 + Math.floor(Math.random() * 100) % 50;
		setTimeout("nextBlink(" + auctionId + ", false)", next * 1000);
	}
}
/////////////////////////////////////////////////////////////////////////////////////////
// popup onclick

function showLayer(width, height, content, id) {
	// checking available window size
	var top = 150;
	var left = 200;
	var maxW = "100%";
	var maxH = "1000px";
	if (window.screen) {
		left = (window.screen.availWidth / 2) + 456 - width;
		//top = (window.screen.availHeight - height - 200) / 2;
		maxW = window.screen.availWidth + "px";
	}
	var parent = document.getElementById(id);
	if (parent != null) {
		parent.innerHTML = '<div onclick="hideLayer(\'' + id + '\');" class="layer" style="cursor:pointer;top:' + top + 'px;left:' + left + 'px;width:' + width + 'px;height:' + height + 'px;">' +
			content + '</div>';
	}
}

function hideLayer(id) {
	var parent = document.getElementById(id);
	if (parent != null) {
		parent.innerHTML = '';
	}
}

/////////////////////////////////////////////////////////////////////////////
//zakładki opisie aukcji

var currentTab = 'desc';
function showTab(id) {
	var e = undefined;
	if (currentTab != '') {
		e = document.getElementById(currentTab);
		if (e != undefined) {
			if (e.className.indexOf("hidden") == -1) {
				e.className = e.className + "hidden";
			}
			e = document.getElementById(currentTab + 'Tab');
			if (e != undefined) {
				e.className = "tab";
			}
		}
	}
	if (id != '') {
		currentTab = '';
		e = document.getElementById(id);
		if (e != undefined) {
			currentTab = id;
			if (e.className.indexOf("hidden") > -1) {
				e.className = e.className.substring(0, e.className.indexOf("hidden"));
			}
			e = document.getElementById(currentTab + 'Tab');
			if (e != undefined) {
				e.className = "selectedTab";
			}
		}
	}
}

////////////////////////////////////////////////////////////////////////
// galeria

var currentImage = 0;
var gallery = new Array();

function showPrevImg(id) {
	showImg(id, parseInt(currentImage - 1));
	
}
function showNextImg(id) {
	showImg(id, parseInt(currentImage + 1));
}
function showImg(id, idx) {
	var e = document.getElementById(id);
	if (e != undefined) {
		if (idx < 0) {
			idx = (gallery.length - 1);
		} else if (idx >= gallery.length) {
			idx = 0;
		}
		currentImage = idx;
		e.src = gallery[currentImage];
	}
}

function switchClassess(idSrc, idDest) {
	var dest = document.getElementById(idDest);
	var src = document.getElementById(idSrc);
	var classDest = dest.className;
	dest.className = src.className;
	src.className = classDest;
}

