/** 
 * SVN FILE: $Id: ajax.js 15404 2011-10-24 05:53:15Z jlekse $
 * @version $Revision: 15404 $
 * @lastmodified $LastChangedDate: 2011-10-24 07:53:15 +0200 (pon, 24 okt 2011) $
 */
/**
 * objekt, ki se po ajaxu pogovarja s php košarico
 */
function AjaxBasket(timeoutDiv, containerDiv, type) {
	this.xmlHttp = null;
	if (type == 'articles') {
		this.article = new Article(timeoutDiv, containerDiv);
		this.type = 1;
	} else {
		this.basket = new Basket(timeoutDiv, containerDiv);
		this.type = 0;
	}
	this.fastLockTpack = false; /* true: script does not redirect user to the next venue */
	this.loadingElement = document.getElementById('basketDataLoading');
	this.sending(false);
};

AjaxBasket.prototype.sending = function (value) {
	this.connectionBusy = value;
	if (value) {
		$('#basketDataLoading').show();
		$("#submitButton").attr("disabled", "disabled");
	} else {
		$('#basketDataLoading').hide();
		$("#submitButton").removeAttr("disabled");
		$.unblockUI();
	}

	if (this.type == 0) {
		if (popupOpened(this.basket.venueWindow)) {
			movie = getFlashMovieObject(this.basket.venueId);
			if (movie != 'undefined' && movie != null) {
				if (movie.callLoading != undefined || movie.callLoading != null) {
					movie.callLoading(value)
				}
			}
		}
	}
};


AjaxBasket.prototype.sendRequest = function (method)
{
	var params = '';
	var aL = arguments.length;
	var i=1;
	while(i<aL){
		params += arguments[i] + ',';
		++i;
	}
	params = params.slice(0, params.length - 1);

	var payment = '';
	if (this.type == 0) {
		if (this.basket.payment) {
			payment = '&payment=' + this.basket.payment;
		}
	}
	
	errors = '&errors=';
	if (this.type == 0) {
		for (var i in this.basket.errors) {
			errors += this.basket.errors[i];
		}
	}
	errors = errors.slice(0, errors.length - 1);

	method = encodeURIComponent(method);
	params = encodeURIComponent(params);
	var qs = 'method=' + method + '&params=' + params + payment;

	var url = SITE_PATH+'ajax_basket.php5';

	this.sending(true);
	$.ajax({
		type: "GET",
		url: url,
		data: qs,
		dataType: "json",
		success: function(doc) {
			var xmlDoc = doc;
			if (ajaxBasket.type === 0) {
				ajaxBasket.basket.loadFromXml(xmlDoc);
			} else {
				ajaxBasket.article.loadFromXml(xmlDoc);
			}
			ajaxBasket.sending(false);
		},
		parsererror: function(doc) {
			ajaxBasket.sending(false);
			alert(STR_INTERNAL_ERROR);
		},
		error: function(doc) {
			ajaxBasket.sending(false);
			alert(STR_CONNECTION_ERROR);
		}
	});
};

AjaxBasket.prototype.sendRequestOneWay = function (method)
{
	var params = '';
	var aL = arguments.length;
	var i=1;
	while(i<aL){
		params += arguments[i] + ',';
		++i;
	}
	params = params.slice(0, params.length - 1);

	var payment = '';
	if (this.type == 0) {
		if (this.basket.payment) {
			payment = '&payment=' + this.basket.payment;
		}
	}
	
	errors = '&errors=';
	if (this.type == 0) {
		for (var i in this.basket.errors) {
			errors += this.basket.errors[i];
		}
	}
	errors = errors.slice(0, errors.length - 1);

	method = encodeURIComponent(method);
	params = encodeURIComponent(params);
	var qs = 'method=' + method + '&params=' + params + payment;

	var url = SITE_PATH+'ajax_basket.php5';

	saync = true;
	if (method == 'changeStatus' || method == 'changeStatusSVC' || method == 'changeStatusPACK') { saync = false; }
	
	$.ajax({
		type: "GET",
		url: url,
		data: qs,
		async: saync,
		dataType: "json",
		success: function(rez) {
			var doc = rez.errors;
			var i = 0;
			if (doc.length > 0) {
				var s = STR_SERVER_NOTICE+'\r\n\r\n';
				var idx = 0;
				var showMessage = false;
				var reloadPage = false;
				var eL = doc.length;
				while (i < eL) {
					idx = doc[i].id;
					if (typeof(ajaxBasket.basket.errors[idx]) != 'undefined') {
						++i;
						continue;
					}
					eval('ajaxBasket.basket.errors[idx] = ' + doc[i].message + ';');
					s += '- ' + ajaxBasket.basket.errors[idx] + '\r\n';
					if (ajaxBasket.basket.errors[idx] == STR_BASKET_EXPIRED)
					{
						reloadPage = true;
					}
					showMessage = true;
					
					if (ajaxBasket.basket.errors[idx] == STR_SEAT_ALREADY_TAKEN)
					{
						ajaxBasket.basket.refreshFlash();
					}
					++i;
				}
				if (showMessage) {
					alert(s);
					if (reloadPage) {
						closeAllDivs();
					}
				}
			}
			ajaxBasket.sending(false);
		},
		parsererror: function(doc) {
			alert(STR_INTERNAL_ERROR);
		},
		error: function(xhr, status, err) {
			if (xhr.status == 0) {
				;
			} else {
				alert(STR_CONNECTION_ERROR);
			}
		}
	});
};


// vse funkcije uporabijo setTimeout zaradi buga v FireFox-u
// v določenih primerih xmlHttp.open ne dela, če ni klican iz glavnega okna (kar setTimeout zagotovi)

AjaxBasket.prototype.clear = function () {
	var item = this.basket.itemsById['i' + this.basket.venueId];
	var seat;

  for (var i in item.segqtysById) {
		item.uiTickets.deleteRow(item.uiTickets.rows[0].rowIndex);
		item.removeSegQty(item);
		item.uiTickets.deleteRow(0);
		//item.setQty();


		//this.rows.push(r);
		//item.uiTickets.rows[0].innerHTML = '';
		item.uiTickets.insertRow(0);
		item.uiTickets.rows[0].insertCell(0);
		item.uiTickets.rows[0].cells[0].width = '100%';
		item.uiTickets.rows[0].insertCell(1);
		item.uiTickets.rows[0].cells[1].align = 'right';
		item.uiTickets.rows[0].insertCell(2);
		item.uiTickets.rows[0].cells[2].align = 'right';
		item.uiTickets.rows[0].insertCell(3);
		item.uiTickets.rows[0].cells[3].align = 'right';
   }
   
	for (var i in item.seatsById) {
		seat = item.seatsById[i];
		//seat.updateFlash(0);
		delete item.seatsById[i];
		item.uiTickets.deleteRow(0);

		item.uiTickets.rows[0].innerHTML = '';
		
	}
};


AjaxBasket.prototype.FinishTpack = function (total) {
	var item = this.basket.itemsById['i' + this.basket.venueId];

	var j = 0;
	for (var i in item.seatsById) {
		++j;
	}

	item.uiTickets.insertRow(j+1);
	item.uiTickets.rows[j+1].insertCell(0);
	item.uiTickets.rows[j+1].cells[0].colSpan = '4';
	item.uiTickets.rows[j+1].cells[0].innerHTML = 'cena: <b>' + total + ' '+STR_CURRENCY_CODE+' </b>';

};

/**
 * Ponovno nalozi podatke iz XML-lja
 */
AjaxBasket.prototype.refresh = function ()
{
	setTimeout('ajaxBasket.sendRequest(\'getBasket\');', 0);
};

AjaxBasket.prototype.refreshArticles = function ()
{
	setTimeout('ajaxBasket.sendRequest(\'getArticle\');', 0);
};

/**
 * Na novo naložimo (reloadamo) celotno spletno stran, ta funkcija se kliče na koncu abonmajev (tpack_end), zaradi
 * statusov in cen, ker se ne dodajo, če strani ne osvežimo
 */
AjaxBasket.prototype.reloadPage = function () {
   window.location = "buy_step_1.php5";
};


AjaxBasket.prototype.clearLockCache = function () {
	setTimeout('ajaxBasket.sendRequest(\'clearLockCache\');', 0);
};

/** NAVADNE KARTE **/
AjaxBasket.prototype.lockSeat = function (item, id) {
	setTimeout('ajaxBasket.sendRequest(\'lockSeat\', ' + item + ', ' + id + ');', 0);
	//this.mode = 1;
};

/*
 * Odstranimo sedež iz košarice
 *
 * @param int item - id_item_tree -> id predstave
 * @param int idbasketitem - id_basket_item
 */
AjaxBasket.prototype.unlockSeat = function (item, idbasketitem) {
	setTimeout('ajaxBasket.sendRequest(\'unlockSeat\', ' + item + ', ' + idbasketitem + ');', 0);
};

/** NEPOZICIJSKI SEGMET - NAVADNE KARTE **/
AjaxBasket.prototype.changeQty = function (item, id, qty, idbasketitem)
{
	var numericExpression = /^[0-9]+$/;  // regular expression, dovoljene so samo številke 0-9
	if(!numericExpression.exec(qty)) // preverjanje ali je podano besedilo različno od expressiona, ne vsebuje samo številk
	{
		alert(STR_NOT_A_NUMBER); // napišemo napako
	}
	else
	{
		if (parseInt(qty, 10) <= parseInt(MAXQTY, 10)) // MAXQTY = 25
		{
			setTimeout('ajaxBasket.sendRequest(\'changeQty\', ' + item + ', ' + id + ', ' + qty + ', '+idbasketitem+');', 0);
		}
		else
		{	// v primeru da smo izbrali več kot 25 vstopnic nas opozori, da smo jih izbrali preveč
			alert(STR_TO_MANY_SEATS);
		}
	}
};

// brisanje iz košarice
AjaxBasket.prototype.removeQty = function (item, id, qty, idbasketitem)
{
	setTimeout('ajaxBasket.sendRequest(\'changeQty\', ' + item + ', ' + id + ', ' + qty + ', '+idbasketitem+');', 0);
};

/**
 * Ta funkcija se kliče, ko imamo samo en segment, pa še ta je nepozicijski. Zato samo vpišemo željeno število vstopnic
 * @param int item - id_item_tree (id_predstave)
 * @param int qty - željeno število vstopnic
 */
AjaxBasket.prototype.fastLock = function (item, qty)
{
	var numericExpression = /^[0-9]+$/;  // regular expression, dovoljene so samo številke 0-9
	if(!numericExpression.exec(qty)) // preverjanje ali je podano besedilo različno od expressiona, ne vsebuje samo številk
	{
		alert(STR_NOT_A_NUMBER); // napišemo napako
	}
	else
	{
		$.blockUI();
		if (parseInt(qty, 10) <= parseInt(MAXQTY, 10)) // MAXQTY = 25
		{
			setTimeout('ajaxBasket.sendRequest(\'fastLock\', ' + item + ', ' + qty + ');', 0);
		}
		else
		{	// v primeru da smo izbrali več kot 25 vstopnic nas opozori, da smo jih izbrali preveč
			$.unblockUI();
			alert(STR_TO_MANY_SEATS);
		}
	}
};

/** ABONMAJI **/
AjaxBasket.prototype.lockTpackSeat = function (item, id, index, idtpack) {
	setTimeout('ajaxBasket.sendRequest(\'lockTpackSeat\', ' + item + ', ' + id + ', ' + idtpack + ');', 0);
	this.index = index;
	this.mode = 0;
	this.idtpack = idtpack;
	this.item = item;
};

AjaxBasket.prototype.lockTpackSeatOM = function (item, id, index, idtpack) {
	setTimeout('ajaxBasket.sendRequest(\'lockTpackSeatOM\', ' + item + ', ' + id + ', ' + idtpack + ');', 0);
	this.index = index;
	this.mode = 0;
	this.idtpack = idtpack;
	this.item = item;
	this.fastLockTpack = true;
};
AjaxBasket.prototype.lockTpackSeatCQ = function (item, id, index, idtpack) {
	setTimeout('ajaxBasket.sendRequest(\'lockTpackSeatCQ\', ' + item + ', ' + id + ', ' + idtpack + ');', 0);
	this.index = index;
	this.mode = 0;
	this.idtpack = idtpack;
	this.item = item;
	this.fastLockTpack = true;
};

AjaxBasket.prototype.unlockTpackSeats = function (id) {
	setTimeout('ajaxBasket.sendRequest(\'unlockTpackSeats\', ' + id + ');', 0);
};

AjaxBasket.prototype.lockTpackNonSeat = function (id, index, idtpack, seg, qty) {
	var numericExpression = /^[0-9]+$/;  // regular expression, dovoljene so samo številke 0-9
	if(!numericExpression.exec(qty)) { // preverjanje ali je podano besedilo različno od expressiona, ne vsebuje samo številk
		alert(STR_NOT_A_NUMBER); // napišemo napako
	} else {
		setTimeout('ajaxBasket.sendRequest(\'lockTpackNonSeat\', '+id+', '+idtpack+', '+seg+', '+qty+');', 0);
	}
	this.index = index;
	this.mode = 0;
	this.idtpack = idtpack;
	this.item = id;
	this.fastLockTpack = true;
}


AjaxBasket.prototype.lockTpackNonSeatMP = function (index, idtpack, qty) {
	var numericExpression = /^[0-9]+$/;  // regular expression, dovoljene so samo številke 0-9
	if(!numericExpression.exec(qty)) { // preverjanje ali je podano besedilo različno od expressiona, ne vsebuje samo številk
		alert(STR_NOT_A_NUMBER); // napišemo napako
	} else {
		setTimeout('ajaxBasket.sendRequest(\'lockTpackNonSeatMP\', '+idtpack+', '+qty+');', 0);
	}
	this.index = index;
	this.mode = 0;
	this.idtpack = idtpack;
	this.item = -1;
	this.fastLockTpack = true;
}


/**
 * Odstranjevanje več sedežev iz košarice (npr.: da ima abonma 5 predstav, ne glede na to katero bomo kliknili, se bodo vse predstave
 * tega abonmaja izbrisale
 *
 * @param int item - id_basket_item (id_predstave)
 * @param int idbasketitem - 
 */
AjaxBasket.prototype.unlockTpackSeat = function (item, idbasketitem)
{
	setTimeout('ajaxBasket.sendRequest(\'unlockTpackSeat\', ' + item + ', ' + idbasketitem + ');', 0);
};

/** NEPOZICIJSKI SEGMET - ABONMAJI **/
AjaxBasket.prototype.changeTpackQty = function (item, id, qty, idtpack, index, idbasketitem) {
	if (idbasketitem==undefined) {
		idbasketitem = 'null';
	}
	setTimeout('ajaxBasket.sendRequest(\'changeTpackQty\', ' + item + ', ' + id + ', ' + qty + ', ' + idtpack + ', '+idbasketitem+');', 0);
	this.index = index;
	this.mode = 0;
	this.idtpack = idtpack;
	this.item = item;
};

AjaxBasket.prototype.changeTpackQtyOM = function (item, id, qty, idtpack, index, idbasketitem) {
	if (idbasketitem==undefined) {
		idbasketitem = 'null';
	}
	setTimeout('ajaxBasket.sendRequest(\'changeTpackQtyOM\', ' + item + ', ' + id + ', ' + qty + ', ' + idtpack + ', '+idbasketitem+');', 0);
	this.index = index;
	this.mode = 0;
	this.idtpack = idtpack;
	this.item = item;
	this.fastLockTpack = true;
};
/** ticket packages, custom qty */
AjaxBasket.prototype.changeTpackQtyCQ = function (item, id, qty, idtpack, index, lockAll) {
	setTimeout('ajaxBasket.sendRequest(\'changeTpackQtyCQ\', ' + item + ', ' + id + ', ' + qty + ', ' + idtpack + ');', 0);
	this.index = index;
	this.mode = 0;
	this.idtpack = idtpack;
	this.item = item;
	this.fastLockTpack = lockAll;
};

AjaxBasket.prototype.lockTpackGoToNext = function (item, index, idtpack) {
	setTimeout('ajaxBasket.sendRequest(\'lockTpackGoToNext\', ' + item + ', ' + idtpack + ');', 0);
	this.index = index;
	this.mode = 0;
	this.idtpack = idtpack;
	this.item = item;
	this.fastLockTpack = true;
};

/** BEST SEAT **/
/**
 * @param int id_item_tree -> id predstave
 * @param int id_seg -> id segmenta
 * @param int qty -> količina kart
 * @param string price -> string v katerem je zapisana cena in ime statusa (npr: "Otroci (15,25 EUR)")
 */
AjaxBasket.prototype.bestSeat = function(id_item_tree, id_seg, qty, price)
{
	var numericExpression = /^[0-9]+$/;  // regular expression, dovoljene so samo številke 0-9
	if(!numericExpression.exec(qty)) // preverjanje ali je podano besedilo različno od expressiona, ne vsebuje samo številk
	{
		alert(STR_NOT_A_NUMBER); // napišemo napako
	}
	else
	{
		$.blockUI();
		if (parseInt(qty, 10) <= parseInt(MAXQTY, 10)) // MAXQTY = 25
		{
			setTimeout('ajaxBasket.sendRequest(\'bestSeat\', \'' + id_item_tree + '\', \'' + id_seg + '\', ' + qty + ', \'' + price + '\');', 0);
		}
		else
		{	// v primeru da smo izbrali več kot 25 vstopnic nas opozori, da smo jih izbrali preveč
			$.unblockUI();
			alert(STR_TO_MANY_SEATS);
		}
	}
};

/** STORITVE **/
AjaxBasket.prototype.addSVC = function (id_item_tree, qty, price) // dodajanje
{
	var numericExpression = /^[0-9]+$/; // regular expression, dovoljene so samo številke 0-9
	if(!numericExpression.exec(qty)) // preverjanje ali je podano besedilo različno od expressiona, ne vsebuje samo številk
	{
		alert(STR_NOT_A_NUMBER); // napišemo napako
	}
	else
	{
		//$.blockUI();
		if (parseInt(qty, 10) <= parseInt(MAXQTY, 10)) // MAXQTY = 25
		{
			setTimeout('ajaxBasket.sendRequest(\'addSVC\', ' + id_item_tree + ', ' + qty + ', '+price+');', 0);
		}
		else
		{	// v primeru da smo izbrali več kot 25 vstopnic nas opozori, da smo jih izbrali preveč
			//$.unblockUI();
			alert(STR_TO_MANY_SVC);
		}
	}
};

AjaxBasket.prototype.removeSVC = function (item, idbasketitem) // odstranjevanje
{
	setTimeout('ajaxBasket.sendRequest(\'removeSVC\', ' + item + ', ' + idbasketitem + ');', 0);
};

AjaxBasket.prototype.checkSvcDate = function (item) {
	var date = $('#in'+item).val();
	if (date == "") {
		date = new Date();
		date = date.addDays(1).asString();
		$('#in'+item).val(date);
	}
	$('#dDate'+item).html(date);
	setTimeout('ajaxBasket.sendRequest(\'checkSvcDate\', ' + item + ', "' + date + '");', 0);
};

AjaxBasket.prototype.addSVCEvent = function (item) {
	var qty = $('#inq'+item).val();
	var date = $('input:radio[name=r'+item+']:checked').val();
	var numericExpression = /^[0-9]+$/; // regular expression, dovoljene so samo številke 0-9
	if(!numericExpression.exec(qty)) // preverjanje ali je podano besedilo različno od expressiona, ne vsebuje samo številk
	{
		alert(STR_NOT_A_NUMBER); // napišemo napako
	}
	else
	{
		if (parseInt(qty, 10) <= parseInt(MAXQTY, 10)) // MAXQTY = 20
		{
			setTimeout('ajaxBasket.sendRequest(\'addSVCEvent\', ' + item + ', ' + qty + ', '+date+');', 0);
		}
		else
		{	// v primeru da smo izbrali več kot 20 vstopnic nas opozori, da smo jih izbrali preveč
			alert(STR_TO_MANY_SVC);
		}
	}
};

/**
 * Bonus cards
 */
AjaxBasket.prototype.addBC = function (id_item_tree, price) // dodajanje
{
	setTimeout('ajaxBasket.sendRequest(\'addBC\', ' + id_item_tree + ', '+price+');', 0);
};

AjaxBasket.prototype.removeBC = function (item) // dodajanje
{
	window.location = SITE_PATH+'tickets/basket.php5?action=removeBC&id='+item;
};

AjaxBasket.prototype.removeBCR = function (item) // dodajanje
{
	window.location = SITE_PATH+'tickets/basket.php5?action=removeRBC&id='+item;
};

/**
 * Debit cards
 */
AjaxBasket.prototype.addDC = function (item, qty) {
	var numericExpression = /^[0-9]+$/;
	if(!numericExpression.exec(qty)) {
		alert(STR_NOT_A_NUMBER);
	} else {
		setTimeout('ajaxBasket.sendRequest(\'addDC\', ' + item + ', ' + qty + ');', 0);
	}
};
AjaxBasket.prototype.removeDC = function (item, idbasketitem) {// dodajanje
	setTimeout('ajaxBasket.sendRequest(\'removeDC\', ' + item + ', ' + idbasketitem + ');', 0);
};

AjaxBasket.prototype.addDCR = function (item, qty) // dodajanje
{
	var numericExpression = /^[0-9]+$/; // regular expression, dovoljene so samo številke 0-9
	if(!numericExpression.exec(qty)) // preverjanje ali je podano besedilo različno od expressiona, ne vsebuje samo številk
	{
		alert(STR_NOT_A_NUMBER); // napišemo napako
	}
	else
	{
		setTimeout('ajaxBasket.sendRequest(\'addDCR\', ' + item + ', ' + qty + ');', 0);
	}
};

AjaxBasket.prototype.removeDCR = function (item, idbasketitem) {
	setTimeout('ajaxBasket.sendRequest(\'removeDCR\', ' + item + ', ' + idbasketitem + ');', 0);
};

 
/*
* sprememba statusa za ...
@param price - nova cena
@param status - nov status
@param id_basket_item - id_basket_item
@param number_of_shows - število predstav, ki pripadajo temu itemu (npr: navadna predstava = 1, tpack  >= 1)
*/
AjaxBasket.prototype.changeStatus = function (id_price, index_off, id_item_tree, id_basket_item)
{
	setTimeout('ajaxBasket.sendRequestOneWay(\'changeStatus\', "' + id_price + '", "' + index_off + '", "' + id_item_tree + '", "' + id_basket_item + '");', 0);
};

AjaxBasket.prototype.changeBCStatus = function (id_price, id_item_tree, id_basket_item)
{
	setTimeout('ajaxBasket.sendRequest(\'changeBCStatus\', "' + id_price + '", "' + id_item_tree + '", "' + id_basket_item + '");', 0);
};

AjaxBasket.prototype.changeStatusSVC = function (id_price, id_item_tree, id_basket_item)
{
	setTimeout('ajaxBasket.sendRequestOneWay(\'changeStatusSVC\', "' + id_price + '", "' + id_item_tree + '", "' + id_basket_item + '");', 0);
};


///////////////////// ARTIKLI \\\\\\\\\\\\\\\\\\\\\
AjaxBasket.prototype.getArtAttrList = function (id_item_art_tree, selectIndex, sellable) 
{
	if (parseInt(id_item_art_tree, 10) != 0) {
		if (sellable == 0) {
			ajaxBasket.article.sellable = 0;
			setTimeout('ajaxBasket.sendRequest(\'getArtAttrList\', "' + id_item_art_tree  + '", "' + selectIndex + '", "' + sellable + '");', 0);
		} else {
			ajaxBasket.article.sellable = 1;
		}
		ajaxBasket.article.showBuy();
		
		id_el = document.getElementById('id_article');
		id_el.value = id_item_art_tree;
		
		hid_pri = document.getElementById(id_item_art_tree);
		id_pr = document.getElementById('invalue2');
		id_pr.cells[1].innerHTML = formatCurrency(hid_pri.value)+' '+STR_CURRENCY_CODE;
	}
};

AjaxBasket.prototype.removeArt = function (item, idbasketitem) {
	setTimeout('ajaxBasket.sendRequest(\'removeArt\', ' + item + ', ' + idbasketitem + ');', 0);
};


AjaxBasket.prototype.checkPromotionCode = function (id, promotionCode) {
	setTimeout('ajaxBasket.sendRequest(\'checkPromotionCode\', "' + id  + '", "' + promotionCode + '");', 0);
};

AjaxBasket.prototype.setDelivery = function (id, delivery) {
	setTimeout('ajaxBasket.sendRequestOneWay(\'setDelivery\', "' + id  + '", "' + delivery + '");', 0);
};

AjaxBasket.prototype.packStart = function (id, qty) {
	//var qty = $('#idq'+id).val();
	var numericExpression = /^[0-9]+$/; // regular expression, dovoljene so samo številke 0-9
	if(!numericExpression.exec(qty)) { // preverjanje ali je podano besedilo različno od expressiona, ne vsebuje samo številk
		alert(STR_NOT_A_NUMBER); // napišemo napako
	} else {
		if (parseInt(qty, 10) <= parseInt(MAXQTY, 10)) // MAXQTY = 20
		{
			setTimeout('ajaxBasket.sendRequest(\'packStart\', ' + id + ', ' + qty + ');', 0);
		} else {
			// v primeru da smo izbrali več kot 20 vstopnic nas opozori, da smo jih izbrali preveč
			alert(STR_TO_MANY_SVC);
		}
	}
};

AjaxBasket.prototype.packNext = function (item, idx) {
	var date = $('input:radio[name=r'+item+']:checked').val();
	setTimeout('ajaxBasket.sendRequest(\'packNext\', ' + item + ', ' + idx + ', '+date+');', 0);
};

AjaxBasket.prototype.checkPackDate = function (item, idSvc) {
	var date = $('#in'+item).val();
	if (date == "") {
		date = new Date();
		date = date.addDays(1).asString();
		$('#in'+item).val(date);
	}
	$('#dDate'+item).html(date);
	if ('' != idSvc) {
		setTimeout('ajaxBasket.sendRequest(\'checkPackDate\', ' + item + ', ' + idSvc + ', "' + date + '");', 0);
	}
};


AjaxBasket.prototype.removePack = function (item, idbasketitem) {
	setTimeout('ajaxBasket.sendRequest(\'removePack\', ' + item + ', "' + idbasketitem + '");', 0);
};

AjaxBasket.prototype.changeStatusPACK = function (id_price, id_item_tree, id_basket_item)
{
	setTimeout('ajaxBasket.sendRequestOneWay(\'changeStatusPACK\', "' + id_price + '", "' + id_item_tree + '", "' + id_basket_item + '");', 0);
};

/**
 * @item - item tree id
 * @seat - seat id
 * @type - perf / tpack
 * @pack - tpack id
 */
AjaxBasket.prototype.viewFromSeat = function(item, seat, type, pack, isSeat) {
	var href="";
	if (isSeat == 0) {
		if (true == WEB_KIOSK_MOD_REWRITE)  {
			href = SITE_PATH+'view-from-seat/'+item+'-'+type+'-'+seat+'.jpg';
		} else {
			href = SITE_PATH+'pictureViewFromSeat.php5?&isSeat=T&id='+item+'&type='+type+'&seat='+seat;
		}
	} else {
		if (true == WEB_KIOSK_MOD_REWRITE)  {
			href = SITE_PATH+'view-from-seg/'+item+'-'+type+'-'+seat+'.jpg';
		} else {
			href = SITE_PATH+'pictureViewFromSeat.php5?&isSeg=T&id='+item+'&type='+type+'&seat='+seat;
		}
	}
	if ($("a#viewFromSeat").length == 0) {
		$('<a id="viewFromSeat" href="'+href+'"></a>').appendTo("body");
		
		$("a#viewFromSeat").slimbox({overlayOpacity: 1}, null, function(el) {
			return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
		});
	} else {
		$("a#viewFromSeat").attr('href', href);
	}
	$("a#viewFromSeat").click();
};

/** METODE ZA NASTAVITVE VALUTE **/
function formatCurr(amount)
{
	amount1 = '';
	if (amount != 'Nan' &&  amount != null && amount != '')
	{
		amount1 = amount.toFixed(2);
	}
	return amount1;
};

function formatCurrency(strValue)
{
	strValue = strValue.toString().replace(/\$|\,/g,'');
	dblValue = parseFloat(strValue);

	blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
	dblValue = Math.floor(dblValue*100+0.50000000001);
	intCents = dblValue%100;
	strCents = intCents.toString();
	dblValue = Math.floor(dblValue/100).toString();
	if (intCents<10) {
		strCents = "0" + strCents;
	}
	for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++) {
		dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+'.'+
		dblValue.substring(dblValue.length-(4*i+3));
	}
	return (((blnSign)?'':'-') + '' + dblValue + ',' + strCents);
};

// metoda za prikazovaje in skrivanje DIV-a s flash animacijo
function switchFlash(obj, mode)
{	
	var el = document.getElementById('divDvorana_'+obj); // "poiščemo" div
	$.each(ajaxBasket.basket.dvorane, function(index, value) { 
		var el3 = document.getElementById('divDvorana_'+value); // "poiščemo" div
		if (el3) {
			el3.style.display = 'none'; // spremenimo mode, ga skrijemo
			el3.firstChild.contentWindow.document.location = "about:blank"; // source iframa
	
			var el2 = document.getElementById('select_box_'+value); // "poiščemo" div
			if (el != el3) // preverjamom ta div in div, ki smo ga kliknili, če smo ga, potem ga ne spreminjamo
			{
				if (el2 != null) // preverjamo zaradi predstav, ki nimajo drop down menija
				{
					el2.selectedIndex = 0; // ostalim spremenimo selectbox status na 0
				}
			}
		}
	});

	$('#divDvorana_'+obj).css('display', mode);
	$('#flashDvorana_'+obj).focus();

	return false;
};

function closeAllDivs()
{
	
	$.each(ajaxBasket.basket.dvorane, function(index, value) { 
		$("#divDvorana_"+value).hide();
		$("#flashDvorana_"+value).attr('src', 'about:blank');
		$("#select_box_"+value).get(0).selectedIndex = 0;
	});
	ajaxBasket.basket.venueWindow = '';
};

function hideVenue() {
	$.each(ajaxBasket.basket.dvorane, function(index, value) { 
		$("#divDvorana_"+value).hide('slow');
		$("#select_box_"+value).get(0).selectedIndex = 0;
	});
	ajaxBasket.basket.venueWindow = '';
};

// metodi podamo ID_FRAME
// dobimo nazaj DOM object HTMLEmbedElement
function getFlashMovieObject(id) {
	// ostali brskalniki
	var x = document.getElementById('flashDvorana_'+id); // html div
	// first child -> iframe
	// contentwindow -> vsebina iframe
	// document.embeds -> poiščemo embed-e
	// [0] -> ker vemo da je samo en, to pomeni prvi v arrayu
	
	if ($.browser.msie /* && ($.browser.version.substr(0,1)=="7" || $.browser.version.substr(0,1)=="6")*/){
		// Internet Explorer, Netscape
		frame = 'venue_'+id; // ker IE potrebuje NAME od embed elementa
		return x.contentWindow.window[frame]; // išče po objektu window
	} else {
		return x.contentWindow.document.embeds[0];
	}
};


/**
 * extend string
 */
String.prototype.padLeft = function(length, c) {
	var s = this;
	var i=s.length;
	while(i<length) {
		s = c + s;
		++i;
	}
	return s;
};

String.prototype.xmlEscapeText = function() {
	var s = this;
	s = s.replace('&', "&amp;");
  s = s.replace(">", "&gt;");
  s = s.replace("<", "&lt;");
  s = s.replace('"', "&quot;");
	return s;
};

/**
 * popup functions
 */
function popupOpened(popup, id)
{
	return popup &&  !popup.closed; // preverjamo, če "popup" obstaja in če je odprt
};
