// JavaScript Document

var ie5=document.all&&document.getElementById
var ns6=document.getElementById&&!document.all

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

self.name = "main";

var rand = Math.floor(Math.random()*18446744074000000000);
var portfolio = new Spry.Data.XMLDataSet("xml_get.php?xml=http://www.equitymonitor.net/rss/rss_securities_info.xml&random="+rand, "root/row", { useCache:  false, filterDataFunc: portfolioDataSetPreProcessor, sortOnLoad:"securities_symbol", sortOrderOnLoad:"ascending" });

var market_trade = new Spry.Data.XMLDataSet("xml_get.php?xml=http://www.equitymonitor.net/rss/rss_lasttrade_1.xml", "root/market", { filterDataFunc: myDataSetPreProcessor});

var index_value = new Spry.Data.XMLDataSet(null, "root/index", { filterDataFunc: myDataSetPreProcessor});
var securities = new Spry.Data.XMLDataSet(null, "root/row",{ sortOnLoad:"securities_trade_turnover", sortOrderOnLoad:"descending", filterDataFunc: myDataSetPreProcessor});
var securitiesUP = new Spry.Data.XMLDataSet(null, "root/row",{ sortOnLoad:"securities_trade_relchange", sortOrderOnLoad:"descending", filterDataFunc: myDataSetPreProcessor});
var securitiesDOWN = new Spry.Data.XMLDataSet(null, "root/row",{ sortOnLoad:"securities_trade_relchange", sortOrderOnLoad:"ascending", filterDataFunc: myDataSetPreProcessor});
var securitiesLIST = new Spry.Data.XMLDataSet(null, "root/row",{ sortOnLoad:"securities_symbol", sortOrderOnLoad:"ascending", filterDataFunc: myDataSetPreProcessor});

// novo za manje xmlove ka externim korisnicima

var smarket_sa = new Spry.Data.XMLDataSet("xml_get.php?xml=http://www.equitymonitor.net/rss/rss_market_1_small.xml", "root/market", { filterDataFunc: myDataSetPreProcessor});
var sindex_sa = new Spry.Data.XMLDataSet(null, "root/index", { filterDataFunc: myDataSetPreProcessor});
var sec_sa = new Spry.Data.XMLDataSet("xml_get.php?xml=http://www.equitymonitor.net/rss/rss_market_1_top5.xml", "root/toptrade",{ filterDataFunc: myDataSetPreProcessor});
var secUP_sa = new Spry.Data.XMLDataSet(null, "root/topup",{ filterDataFunc: myDataSetPreProcessor});
var secDOWN_sa = new Spry.Data.XMLDataSet(null, "root/topdown",{ filterDataFunc: myDataSetPreProcessor});

var smarket_bl = new Spry.Data.XMLDataSet("xml_get.php?xml=http://www.equitymonitor.net/rss/rss_market_2_small.xml", "root/market", { filterDataFunc: myDataSetPreProcessor});
var sindex_bl = new Spry.Data.XMLDataSet(null, "root/index", { filterDataFunc: myDataSetPreProcessor});
var sec_bl = new Spry.Data.XMLDataSet("xml_get.php?xml=http://www.equitymonitor.net/rss/rss_market_2_top5.xml", "root/toptrade",{ filterDataFunc: myDataSetPreProcessor});
var secUP_bl = new Spry.Data.XMLDataSet(null, "root/topup",{ filterDataFunc: myDataSetPreProcessor});
var secDOWN_bl = new Spry.Data.XMLDataSet(null, "root/topdown",{ filterDataFunc: myDataSetPreProcessor});

var clist = new Spry.Data.XMLDataSet("xml_get.php?xml=http://www.equitymonitor.net/rss/rss_currency_list.xml", "root/currency", { filterDataFunc: myDataSetPreProcessor});


function updateOthers(notificationType, notifier, data)
{
  if (notificationType != "onPostLoad")
    return;
   var doc2 = market_trade.getDocument();
	if (doc2) {
    index_value.setDataFromDoc(doc2);
	securities.setDataFromDoc(doc2);
	securitiesUP.setDataFromDoc(doc2);
	securitiesDOWN.setDataFromDoc(doc2);
	securitiesLIST.setDataFromDoc(doc2);
	}
	 var doc = portfolio.getDocument();
  if (doc) {
    cookie2array();
	}

// novo za externet klijente
	var xml_market_sa = smarket_sa.getDocument();
	if (xml_market_sa){
	sindex_sa.setDataFromDoc(xml_market_sa);
	}
	var xml_top5_sa = sec_sa.getDocument();
	if(xml_top5_sa){
	secUP_sa.setDataFromDoc(xml_top5_sa);
	secDOWN_sa.setDataFromDoc(xml_top5_sa);
	}

	var xml_market_bl = smarket_bl.getDocument();
	if (xml_market_bl){
	sindex_bl.setDataFromDoc(xml_market_bl);
	}
	var xml_top5_bl = sec_bl.getDocument();
	if(xml_top5_bl){
	secUP_bl.setDataFromDoc(xml_top5_bl);
	secDOWN_bl.setDataFromDoc(xml_top5_bl);
	}



};

market_trade.addObserver(updateOthers);
portfolio.addObserver(updateOthers);
smarket_sa.addObserver(updateOthers);
sec_sa.addObserver(updateOthers);
smarket_bl.addObserver(updateOthers);
sec_bl.addObserver(updateOthers);


function NumberFormat(num, inputDecimal)
{
this.VERSION = 'Number Format v1.5.4';
this.COMMA = ',';
this.PERIOD = '.';
this.DASH = '-';
this.LEFT_PAREN = '(';
this.RIGHT_PAREN = ')';
this.LEFT_OUTSIDE = 0;
this.LEFT_INSIDE = 1;
this.RIGHT_INSIDE = 2;
this.RIGHT_OUTSIDE = 3;
this.LEFT_DASH = 0;
this.RIGHT_DASH = 1;
this.PARENTHESIS = 2;
this.NO_ROUNDING = -1
this.num;
this.numOriginal;
this.hasSeparators = false;
this.separatorValue;
this.inputDecimalValue;
this.decimalValue;
this.negativeFormat;
this.negativeRed;
this.hasCurrency;
this.currencyPosition;
this.currencyValue;
this.places;
this.roundToPlaces;
this.truncate;
this.setNumber = setNumberNF;
this.toUnformatted = toUnformattedNF;
this.setInputDecimal = setInputDecimalNF;
this.setSeparators = setSeparatorsNF;
this.setCommas = setCommasNF;
this.setNegativeFormat = setNegativeFormatNF;
this.setNegativeRed = setNegativeRedNF;
this.setCurrency = setCurrencyNF;
this.setCurrencyPrefix = setCurrencyPrefixNF;
this.setCurrencyValue = setCurrencyValueNF;
this.setCurrencyPosition = setCurrencyPositionNF;
this.setPlaces = setPlacesNF;
this.toFormatted = toFormattedNF;
this.toPercentage = toPercentageNF;
this.getOriginal = getOriginalNF;
this.moveDecimalRight = moveDecimalRightNF;
this.moveDecimalLeft = moveDecimalLeftNF;
this.getRounded = getRoundedNF;
this.preserveZeros = preserveZerosNF;
this.justNumber = justNumberNF;
this.expandExponential = expandExponentialNF;
this.getZeros = getZerosNF;
this.moveDecimalAsString = moveDecimalAsStringNF;
this.moveDecimal = moveDecimalNF;
this.addSeparators = addSeparatorsNF;
if (inputDecimal == null) {
this.setNumber(num, this.PERIOD);
} else {
this.setNumber(num, inputDecimal);
}
this.setCommas(true);
this.setNegativeFormat(this.LEFT_DASH);
this.setNegativeRed(false);
this.setCurrency(false);
this.setCurrencyPrefix('KM');
this.setPlaces(2);
}
function setInputDecimalNF(val)
{
this.inputDecimalValue = val;
}
function setNumberNF(num, inputDecimal)
{
if (inputDecimal != null) {
this.setInputDecimal(inputDecimal);
}
this.numOriginal = num;
this.num = this.justNumber(num);
}
function toUnformattedNF()
{
return (this.num);
}
function getOriginalNF()
{
return (this.numOriginal);
}
function setNegativeFormatNF(format)
{
this.negativeFormat = format;
}
function setNegativeRedNF(isRed)
{
this.negativeRed = isRed;
}
function setSeparatorsNF(isC, separator, decimal)
{
this.hasSeparators = isC;
if (separator == null) separator = this.PERIOD;
if (decimal == null) decimal = this.COMMA;
if (separator == decimal) {
this.decimalValue = (decimal == this.COMMA) ? this.PERIOD : this.COMMA;
} else {
this.decimalValue = decimal;
}
this.separatorValue = separator;
}
function setCommasNF(isC)
{
this.setSeparators(isC, this.PERIOD, this.COMMA);
}
function setCurrencyNF(isC)
{
this.hasCurrency = isC;
}
function setCurrencyValueNF(val)
{
this.currencyValue = val;
}
function setCurrencyPrefixNF(cp)
{
this.setCurrencyValue(cp);
this.setCurrencyPosition(this.LEFT_OUTSIDE);
}
function setCurrencyPositionNF(cp)
{
this.currencyPosition = cp
}
function setPlacesNF(p, tr)
{
this.roundToPlaces = !(p == this.NO_ROUNDING);
this.truncate = (tr != null && tr);
this.places = (p < 0) ? 0 : p;
}
function addSeparatorsNF(nStr, inD, outD, sep)
{
nStr += '';
var dpos = nStr.indexOf(inD);
var nStrEnd = '';
if (dpos != -1) {
nStrEnd = outD + nStr.substring(dpos + 1, nStr.length);
nStr = nStr.substring(0, dpos);
}
var rgx = /(\d+)(\d{3})/;
while (rgx.test(nStr)) {
nStr = nStr.replace(rgx, '$1' + sep + '$2');
}
return nStr + nStrEnd;
}
function toFormattedNF()
{
var pos;
var nNum = this.num;
var nStr;
var splitString = new Array(2);
if (this.roundToPlaces) {
nNum = this.getRounded(nNum);
nStr = this.preserveZeros(Math.abs(nNum));
} else {
nStr = this.expandExponential(Math.abs(nNum));
}
if (this.hasSeparators) {
nStr = this.addSeparators(nStr, this.PERIOD, this.decimalValue, this.separatorValue);
} else {
nStr = nStr.replace(new RegExp('\\' + this.PERIOD), this.decimalValue);
}
var c0 = '';
var n0 = '';
var c1 = '';
var n1 = '';
var n2 = '';
var c2 = '';
var n3 = '';
var c3 = '';
var negSignL = (this.negativeFormat == this.PARENTHESIS) ? this.LEFT_PAREN : this.DASH;
var negSignR = (this.negativeFormat == this.PARENTHESIS) ? this.RIGHT_PAREN : this.DASH;
if (this.currencyPosition == this.LEFT_OUTSIDE) {
if (nNum < 0) {
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n1 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n2 = negSignR;
}
if (this.hasCurrency) c0 = this.currencyValue;
} else if (this.currencyPosition == this.LEFT_INSIDE) {
if (nNum < 0) {
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n0 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n3 = negSignR;
}
if (this.hasCurrency) c1 = this.currencyValue;
}
else if (this.currencyPosition == this.RIGHT_INSIDE) {
if (nNum < 0) {
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n0 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n3 = negSignR;
}
if (this.hasCurrency) c2 = this.currencyValue;
}
else if (this.currencyPosition == this.RIGHT_OUTSIDE) {
if (nNum < 0) {
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n1 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n2 = negSignR;
}
if (this.hasCurrency) c3 = this.currencyValue;
}
nStr = c0 + n0 + c1 + n1 + nStr + n2 + c2 + n3 + c3;
if (this.negativeRed && nNum < 0) {
nStr = '<font color="red">' + nStr + '</font>';
}
return (nStr);
}
function toPercentageNF()
{
nNum = this.num * 100;
nNum = this.getRounded(nNum);
return nNum + '%';
}
function getZerosNF(places)
{
var extraZ = '';
var i;
for (i=0; i<places; i++) {
extraZ += '0';
}
return extraZ;
}
function expandExponentialNF(origVal)
{
if (isNaN(origVal)) return origVal;
var newVal = parseFloat(origVal) + '';
var eLoc = newVal.toLowerCase().indexOf('e');
if (eLoc != -1) {
var plusLoc = newVal.toLowerCase().indexOf('+');
var negLoc = newVal.toLowerCase().indexOf('-', eLoc);
var justNumber = newVal.substring(0, eLoc);
if (negLoc != -1) {
var places = newVal.substring(negLoc + 1, newVal.length);
justNumber = this.moveDecimalAsString(justNumber, true, parseInt(places));
} else {
if (plusLoc == -1) plusLoc = eLoc;
var places = newVal.substring(plusLoc + 1, newVal.length);
justNumber = this.moveDecimalAsString(justNumber, false, parseInt(places));
}
newVal = justNumber;
}
return newVal;
}
function moveDecimalRightNF(val, places)
{
var newVal = '';
if (places == null) {
newVal = this.moveDecimal(val, false);
} else {
newVal = this.moveDecimal(val, false, places);
}
return newVal;
}
function moveDecimalLeftNF(val, places)
{
var newVal = '';
if (places == null) {
newVal = this.moveDecimal(val, true);
} else {
newVal = this.moveDecimal(val, true, places);
}
return newVal;
}
function moveDecimalAsStringNF(val, left, places)
{
var spaces = (arguments.length < 3) ? this.places : places;
if (spaces <= 0) return val;
var newVal = val + '';
var extraZ = this.getZeros(spaces);
var re1 = new RegExp('([0-9.]+)');
if (left) {
newVal = newVal.replace(re1, extraZ + '$1');
var re2 = new RegExp('(-?)([0-9]*)([0-9]{' + spaces + '})(\\.?)');
newVal = newVal.replace(re2, '$1$2.$3');
} else {
var reArray = re1.exec(newVal);
if (reArray != null) {
newVal = newVal.substring(0,reArray.index) + reArray[1] + extraZ + newVal.substring(reArray.index + reArray[0].length);
}
var re2 = new RegExp('(-?)([0-9]*)(\\.?)([0-9]{' + spaces + '})');
newVal = newVal.replace(re2, '$1$2$4.');
}
newVal = newVal.replace(/\.$/, '');
return newVal;
}
function moveDecimalNF(val, left, places)
{
var newVal = '';
if (places == null) {
newVal = this.moveDecimalAsString(val, left);
} else {
newVal = this.moveDecimalAsString(val, left, places);
}
return parseFloat(newVal);
}
function getRoundedNF(val)
{
val = this.moveDecimalRight(val);
if (this.truncate) {
val = val >= 0 ? Math.floor(val) : Math.ceil(val);
} else {
val = Math.round(val);
}
val = this.moveDecimalLeft(val);
return val;
}
function preserveZerosNF(val)
{
var i;
val = this.expandExponential(val);
if (this.places <= 0) return val;
var decimalPos = val.indexOf('.');
if (decimalPos == -1) {
val += '.';
for (i=0; i<this.places; i++) {
val += '0';
}
} else {
var actualDecimals = (val.length - 1) - decimalPos;
var difference = this.places - actualDecimals;
for (i=0; i<difference; i++) {
val += '0';
}
}
return val;
}
function justNumberNF(val)
{
newVal = val + '';
var isPercentage = false;
if (newVal.indexOf('%') != -1) {
newVal = newVal.replace(/\%/g, '');
isPercentage = true;
}
var re = new RegExp('[^\\' + this.inputDecimalValue + '\\d\\-\\+\\(\\)eE]', 'g');
newVal = newVal.replace(re, '');
var tempRe = new RegExp('[' + this.inputDecimalValue + ']', 'g');
var treArray = tempRe.exec(newVal);
if (treArray != null) {
var tempRight = newVal.substring(treArray.index + treArray[0].length);
newVal = newVal.substring(0,treArray.index) + this.PERIOD + tempRight.replace(tempRe, '');
}
if (newVal.charAt(newVal.length - 1) == this.DASH ) {
newVal = newVal.substring(0, newVal.length - 1);
newVal = '-' + newVal;
}
else if (newVal.charAt(0) == this.LEFT_PAREN
&& newVal.charAt(newVal.length - 1) == this.RIGHT_PAREN) {
newVal = newVal.substring(1, newVal.length - 1);
newVal = '-' + newVal;
}
newVal = parseFloat(newVal);
if (!isFinite(newVal)) {
newVal = 0;
}
if (isPercentage) {
newVal = this.moveDecimalLeft(newVal, 2);
}
return newVal;
}

function IsNumeric(strString)
   //  check for valid numeric strings
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }



function portfolioDataSetPreProcessor(ds, row, rowIndex)
{
var num=new NumberFormat();
num.setPlaces('0', false);

if(row.securities_trade_daily == '') {
row.securities_trade_daily_display = new NumberFormat(row.securities_nominal).toFormatted();
} else {
row.securities_trade_daily_display = new NumberFormat(row.securities_trade_daily).toFormatted();
}
row.securities_trade_relchange_display = new NumberFormat(row.securities_trade_relchange).toFormatted();

row.company_name=row.company_name.substring(0,20);

// Make sure we return the row so that it is added to the data set.
return row;
}
portfolio.setColumnType("securities_symbol", "string");

function myDataSetPreProcessor(ds, row, rowIndex)
{
var num=new NumberFormat();
num.setPlaces('0', false);

num.setNumber(row.securities_trade_volume);
row.securities_trade_volume_display = num.toFormatted();
row.securities_trade_turnover_display = new NumberFormat(row.securities_trade_turnover).toFormatted();
row.securities_trade_daily_display = new NumberFormat(row.securities_trade_daily).toFormatted();
row.securities_trade_relchange_display = new NumberFormat(row.securities_trade_relchange).toFormatted();

num.setNumber(row.market_trade_volume);
row.market_trade_volume_display = num.toFormatted();
row.market_trade_turnover_display = new NumberFormat(row.market_trade_turnover).toFormatted();

num.setNumber(row.market_trade_transactions);
row.market_trade_transactions_display = num.toFormatted();

row.index_values_daily_display = new NumberFormat(row.index_values_daily).toFormatted();
row.index_values_apschange_display = new NumberFormat(row.index_values_apschange).toFormatted();
row.index_values_relchange_display = new NumberFormat(row.index_values_relchange).toFormatted();

num.setNumber(row.currency_units);
row.currency_units_display = num.toFormatted();

num.setPlaces('4', false);
num.setNumber(row.currency_data_mvalue);
row.currency_data_mvalue_display = num.toFormatted();
row.currency_data_bvalue_display = new NumberFormat(row.currency_data_bvalue).toFormatted();
row.currency_data_svalue_display = new NumberFormat(row.currency_data_svalue).toFormatted();

// Added by dubravko

row.mttd = new NumberFormat(row.market_trade_turnover).toFormatted();
row.ca = row.currency_acode
row.cud = row.currency_units_display
row.cdmd = row.currency_data_mvalue_display
row.ivrd = new NumberFormat(row.index_values_relchange).toFormatted();
row.is = row.index_symbol
row.mtd = row.market_trade_date
row.ss = row.securities_symbol
row.stdd = row.securities_trade_daily_display
row.strd = row.securities_trade_relchange_display
row.sttd = row.securities_trade_turnover_display
row.stvd = row.securities_trade_volume_display
row.ivdd = new NumberFormat(row.index_values_daily).toFormatted();


// Make sure we return the row so that it is added to the data set.

return row;
}
securities.setColumnType("securities_trade_turnover", "number");
securitiesUP.setColumnType("securities_trade_relchange", "number");
securitiesDOWN.setColumnType("securities_trade_relchange", "number");
sec_sa.setColumnType("securities_trade_turnover", "number");
secUP_sa.setColumnType("securities_trade_relchange", "number");
secDOWN_sa.setColumnType("securities_trade_relchange", "number");
sec_bl.setColumnType("securities_trade_turnover", "number");
secUP_bl.setColumnType("securities_trade_relchange", "number");
secDOWN_bl.setColumnType("securities_trade_relchange", "number");
clist.setColumnType("currency_units", "number");


// OVO SE MORA IZVRSAVATI PRI UCITAVANJU STRANICE

//var timeToKeep = 31536000000; // one year
//var expires = new Date();
//expires.setTime(expires.getTime() + timeToKeep);

// 1.PROVJERA POSTOJANJA COOCKIA
function cookie2array(){
var cookieName='portfolio';
var myPortfolio=init_array();

// 1.2 AKO IMA COOKIA PROCITAJ SADRZAJ I KREIRAJ PORTFOLIO
get_array(cookieName, myPortfolio);

for (var i=1; i<next_entry(myPortfolio); i++) {
var pSplit = myPortfolio[i].split('/');
var secid = pSplit[0];
var secquant = pSplit[1];

var rows = portfolio.getData();

for (var k = 0; k < rows.length; k++)
{
	if (rows[k]["securities_id"] == secid){
		//return rows[i]["ds_RowID"];

//prepravljeno zarad IE prezentacije
addRow(secid+'|'+rows[k]["securities_symbol"]+'|'+rows[k]["securities_trade_daily_display"]+'|'+rows[k]["securities_trade_relchange_display"]+'|'+secquant);

		}

}

}
}


// KRAJ 1.


// 2. MODIFIKACIJA COOCKIA -- FUNKCIJA ZA DODAVANJE PARA DIONICA+KOLICINA U COOCKIE
// ILI KREIRANJE ISTOG AKO NE POSTOJI
function send2cookie(x,y){

var timeToKeep = 31536000000; // one year
var expires = new Date();
expires.setTime(expires.getTime() + timeToKeep);
var cookieName='portfolio';
var myPortfolio=init_array();
del_cookie(cookieName);

for (var j=0; j < x.length; j++) {
myPortfolio[j+1]=x[j]+"/"+y[j];
  }

set_array(cookieName,myPortfolio,expires);
}

// KRAJ 2.

function remRow(r){ //ORIGINAL
var root = r.parentNode;//the root
var nextroot = r.nextSibling;
var tbody = root.parentNode.parentNode.parentNode.getElementsByTagName('tbody');//the rows' collection

root.removeChild(r);//deletes current row
nextroot.parentNode.removeChild(nextroot);

}

function addRow(input){
var output=input.split("|");
a=output[0];
b=output[1];
c=output[2];
d=output[3];
e=output[4];
//var root = r.parentNode; //the root
var root = document.getElementById('port_tabela');
var allRows = root.getElementsByTagName('tr');//the rows' collection
var tbody = root.getElementsByTagName('tbody');//the rows' collection

var cRow = document.createElement('tr');

var cTdA = document.createElement('td');
cTdA.height="26";
cTdA.style.borderBottom="1px solid #FFFFFF";
cTdA.innerHTML="&nbsp;";

var cTdB = document.createElement('td');
cTdB.height="26";
//cTdB.className="tablecontent";
cTdB.style.padding="3px";
cTdB.style.borderRight="1px solid #FFFFFF";
cTdB.style.borderBottom="1px solid #FFFFFF";
cTdB.innerHTML='<strong>'+b+'</strong>';

var cTdC = document.createElement('td');
cTdC.height="26";
cTdC.align="right";
//cTdC.className="tablecontent";
cTdC.style.padding="3px";
cTdC.style.borderRight="1px solid #FFFFFF";
cTdC.style.borderBottom="1px solid #FFFFFF";

var cTdCs = document.createElement('span');
//cTdCs.className="tecajna";
cTdCs.id='unos['+a+']';
cTdCs.style.padding="3px";
cTdCs.style.textAlign="right";
cTdCs.style.borderBottom="1px solid #FFFFFF";
cTdCs.innerHTML=c+' KM';

var cTdD = document.createElement('td');
cTdD.height="26";
cTdD.className="tablecontent";
cTdD.style.borderRight="1px solid #FFFFFF";
cTdD.style.borderBottom="1px solid #FFFFFF";

var cTdDT = document.createElement('table');
cTdDT.width="100%";
cTdDT.border="0";
cTdDT.cellspacing="0";
cTdDT.cellpading="0";
cTdDT.id='slicka['+a+']';

var cTdDTrTBdy= document.createElement('tbody'); //DODAO RADI IE KOJI NE TRPI TABLE BEZ TBODY
var cTdDTr = document.createElement('tr');

var cTdDTrTdA = document.createElement('td');
//cTdDTrTdA.className="tablecontent";
cTdDTrTdA.style.padding="3px";

var cTdDTrTdAS = document.createElement('span');
cTdDTrTdAS.style.padding="3px";
cTdDTrTdAS.style.textAlign="right";
cTdDTrTdAS.innerHTML=d;

var cTdDTrTdB = document.createElement('td');
cTdDTrTdB.align="center";
cTdDTrTdB.style.padding="3px";

var cTdDTrTdBS = document.createElement('span');
cTdDTrTdBS.style.padding="3px";
cTdDTrTdBS.style.textAlign="center";

var num=new NumberFormat();
num.setInputDecimal(',');
num.setPlaces('2', false);
num.setSeparators(true, ',', ',');
num.setNumber(d);
var d = num.toFormatted();
d = parseFloat(d);

if(d>=0){
cTdDTrTdBS.innerHTML='<img src="images/up.gif" alt="arrow" width="9" height="5" / >';
} else {
	cTdDTrTdBS.innerHTML='<img src="images/down.gif" alt="arrow" width="9" height="5" / >';
}


var cTdE = document.createElement('td');
cTdE.align="center";
cTdE.height="26";
cTdE.style.padding="3px";
cTdE.style.borderBottom="1px solid #ECECEC";
cTdE.innerHTML='<img src="images/minus.gif" alt="Obriši simbol" border="0" onclick="remRow(this.parentNode.parentNode); show_total();" />';

var cTdF = document.createElement('td');
cTdF.height="26";
cTdF.style.borderBottom="1px solid #ECECEC";
cTdF.innerHTML="";

var eRow = document.createElement('tr');

var eTdA = document.createElement('td');
eTdA.height="26";
eTdA.style.backgroundColor="#FFFFFF";
eTdA.style.borderBottom="1px solid #ECECEC";
eTdA.innerHTML="";

var eTdB = document.createElement('td');
eTdB.height="26";
eTdB.colSpan="5";
//eTdB.className="tablecontent";
eTdB.style.backgroundColor="#FFFFFF";
eTdB.style.borderBottom="";
eTdB.style.paddingLeft="2px";

var eTdBT = document.createElement('table');
eTdBT.width="100%";
eTdBT.border="0";
eTdBT.cellspacing="0";
eTdBT.cellpading="0";

var eTdBTrTBdy= document.createElement('tbody'); //DODAO RADI IE KOJI NE TRPI TABLE BEZ TBODY
var eTdBTr = document.createElement('tr');

var eTdBTrTdA = document.createElement('td');
//eTdBTrTdA.className="tablecontent";

if(e){
eTdBTrTdA.innerHTML='Broj dionica:<input type="text" name="security_amount['+a+']" id="security_amount['+a+']" style="text-align:right; border:1px solid #CCCCCC; height:16px; width:80px;" value="'+e+'" onkeyup="StartFilterTimer(this.value, '+a+');" class="tablecontent" maxlength="10"/>';
} else {
eTdBTrTdA.innerHTML='Broj dionica:<input type="text" name="security_amount['+a+']" id="security_amount['+a+']" style="text-align:right; border:1px solid #CCCCCC; height:16px; width:80px;" value="0" onkeyup="StartFilterTimer(this.value, '+a+');" class="tablecontent" maxlength="10"/>';
}


var eTdBTrTdB = document.createElement('td');
//eTdBTrTdB.className="tablecontent";
eTdBTrTdB.width="5";
eTdBTrTdB.align="right";


var eTdBTrTdC = document.createElement('td');
//eTdBTrTdC.className="tablecontent";
eTdBTrTdC.id='iznos['+a+']';
eTdBTrTdC.align="right";
eTdBTrTdC.innerHTML="0";


var eTdC = document.createElement('td');
eTdC.height="20";
eTdC.style.backgroundColor="#FDFDFD";
eTdC.style.borderBottom="1px solid #ECECEC";

cRow.appendChild(cTdA);
cRow.appendChild(cTdB);

cTdC.appendChild(cTdCs);
cRow.appendChild(cTdC);

cTdDTrTdA.appendChild(cTdDTrTdAS);
cTdDTrTdB.appendChild(cTdDTrTdBS);
cTdDTr.appendChild(cTdDTrTdA);
cTdDTr.appendChild(cTdDTrTdB);
cTdDTrTBdy.appendChild(cTdDTr);
cTdDT.appendChild(cTdDTrTBdy);
cTdD.appendChild(cTdDT);
cRow.appendChild(cTdD);
cRow.appendChild(cTdE);
cRow.appendChild(cTdF);

tbody[0].appendChild(cRow);//appends the cloned row as a new row

//eRow.appendChild(eTdA);
eRow.appendChild(eTdB);
eRow.appendChild(eTdC);

eTdBTr.appendChild(eTdBTrTdA);
//eTdBTr.appendChild(eTdBTrTdB);
eTdBTr.appendChild(eTdBTrTdC);
eTdBTrTBdy.appendChild(eTdBTr);
eTdBT.appendChild(eTdBTrTBdy);
eTdB.appendChild(eTdBT);


tbody[0].appendChild(eRow);//appends the cloned row as a new row

if(e){
calc(e,a);
show_total();
}

}


function show_total(){
var num=new NumberFormat();
num.setInputDecimal(',');
num.setPlaces('2', false);
num.setSeparators(false, ',', ',');
  var j;

   tds = new Array();
   tdi = new Array();
   tdq = new Array();
   var tmp = document.getElementsByTagName("td");
   var itmp = document.getElementsByTagName("input");
   for (j = 0; j < tmp.length; j++) {
     if (tmp[j].id.search(/iznos/) > -1) {
num.setNumber(tmp[j].innerHTML);
var iznos_display = num.toFormatted();
iznos_display = parseFloat(iznos_display);
      tds.push(iznos_display);
	  tdi.push(tmp[j].id.substring(6,tmp[j].id.length-1)) ; // za slanje id dionice u cookie
	   }
}

   for (j = 0; j < itmp.length; j++) {
     if (itmp[j].id.search(/security_amount/) > -1) {
	  tdq.push(itmp[j].value); //za slanje kolicine u cookie
        	   }
		}



  var iznosi;
  iznosi = 0;
  for (j = 0; j < tds.length; j++) {
   iznosi = (iznosi+tds[j]);
     }

var tTd = document.getElementById('total');
tTd.width="20%";
tTd.align="right";
tTd.style.paddingRight="5px";
tTd.innerHTML = new NumberFormat(iznosi).toFormatted()+' KM';
send2cookie(tdi,tdq);
}


function calc(a,b) {

var cTd = document.getElementById('iznos['+b+']');
var unosHTML = document.getElementById('unos['+b+']').innerHTML;
unosHTML = unosHTML.split(" ");

var num=new NumberFormat();
num.setInputDecimal(',');
num.setPlaces('2', false);
num.setSeparators(true, ',', ',');
num.setNumber(unosHTML[0]);
var iznos_display = num.toFormatted();
iznos_display = parseFloat(iznos_display);
cTd.innerHTML = new NumberFormat((iznos_display*a)).toFormatted()+' KM';

}

function StartFilterTimer(a,b)
{
	if (StartFilterTimer.timerID)
		clearTimeout(StartFilterTimer.timerID);
	StartFilterTimer.timerID = setTimeout(function() { StartFilterTimer.timerID = null; calc(a,b); show_total(); }, 100);
}