var arrZalozky = new Array(); // obsahuje zoznam zaloziek (id elementu ako string) 
var arrTlacidla = new Array(); // obsahuje zoznam tlacidiel na prepnutie zaloziek (id elementu ako string) 

function StopUpozorneni () {
    document.getElementById("nacitam").style.visibility="hidden";
}

function priprav_text (str) {
    while (str.indexOf('\'') > 0 ) {
        str = str.replace('\'', "\"");
    }
  
    while (str.indexOf('\\') > 0 ) {
        str = str.replace('\\', "'");
    }
    
    return str;
}

function logout() {
    x = event.screenX;
    y = event.screenY;
    h = screen.height;
    w = screen.width;
    sirka = w - x;
    vyska = y;
    
    if ( sirka < 20 && vyska < 20 ) {
	window.open('../config/logout.php', 'Nový uživatel','left=2, top=2, height=200, width=200, location=no, menubar=no, tolbar=no, status=no ');
    }
}


function ChangeOver() {
	var tag = 0;
	tag = window.event.srcElement.sourceIndex;
	
	document.all(tag).style.color= '#b58439';
}

function ChangeOut() {
	var tag = 0;
	tag = window.event.srcElement.sourceIndex;
	document.all(tag).style.color= 'infotext';
}

function ChangeOverLink() {
	var tag = 0;
	tag = window.event.srcElement.sourceIndex;
	
	document.all(tag).style.color= '#b58439';
}

function ChangeOutLink() {
	var tag = 0;
	tag = window.event.srcElement.sourceIndex;
	document.all(tag).style.color= 'blue';
}


function NastavFrom ( i ) {
	document.all.f_from.value = i;
}			

function NastavSmer (el) {
	smer = document.all.f_smer.value;
	document.all.f_order.value = el;
	if (smer == "") {
		document.all.f_smer.value = "DESC";
	}
	else {
		 if (smer == "ASC") {
		 	document.all.f_smer.value = "DESC";
		 }
		 else {
		 	document.all.f_smer.value = "ASC";
		 }
	}
}
// ---------------------------------------------------------------------------- StartupInit
function StartupInit()
{
 
  window.parent.document.title = document.title;
  // inicializacia prvkov afsHeader a afsFooter
  // InitHeaderFooter();
  // inicializacia menu
  // oprava    
 
//  if( document.getElementById("menuBar")) {
//    InitMenu();
//  }
/*
  // doplnenie vseobecnej funkcionality prvkov typu SELECT
  var coll = document.all.tags("SELECT");
  if(coll!=null) {
    for(i=0; i < coll.length; i++) {
      //window.alert(i+'ssss');
      if(coll[i].size == 0)
      {
        coll[i].onfocus = new Function("this.className = 'menuItem'; EnsureVisible(this);");
        coll[i].onblur = new Function("this.className = 'menuItem';");
        InitCT(coll[i].id);
      }
    }
  }
*/
}

var sValidatorFocus = ""; // nazov prvku pre nastavenie focus po ValidationSummary ak validator nema zadany ControlToValidate

// ---------------------------------------------------------------------------- StrReplace
// Sluzi na nahradenie vsetkych vyskytov retazca inym retazcom vo vstupnom retazci
function StrReplace(str, co, cim) {
  while(str.indexOf(co) > 0)
    str = str.replace(co, cim);
  return str;
}

// ---------------------------------------------------------------------------- IsInt
// Sluzi na overenie platnosti celeho cisla
function IsInt(strInt) {
  //while(strInt.indexOf(" ") > 0)
  //  strInt = strInt.replace(" ", "");
  var reg = new RegExp(/^-?\d+$/);
  if(typeof(str) == "number")
    strInt = strInt.toString(10);
  return strInt.match(reg);
}

// ---------------------------------------------------------------------------- GetIntStr
// Vrati cele cislo bez formatu z formatovaneho cisla (napr. 12 000 -> 12000)
function GetIntStr(str) {
  if(typeof(str) == "number")
    str = str.toString(10);
  while(str.indexOf(" ") > 0)
    str = str.replace(" ", "");
  if(!IsInt(str))
    return "0";
  return str;
}

// ---------------------------------------------------------------------------- FormatInt
// Vrati naformatovane cele cislo (napr. 12000 -> 12 000)
function FormatInt(str) {
  if(typeof(str) == "number")
    str = str.toString(10);
  if(!IsInt(str))
    return "0";
  var sRet = "";
  while(str.length > 3) {
    if(sRet.length > 0)
      sRet = " " + sRet;
    sRet = str.substr(str.length - 3) + sRet;
    str = str.substring(0, str.length - 3);
  }
  if(str.length > 0) {
    if(sRet.length > 0)
      sRet = str + " " + sRet;
    else
      sRet = str;
  }
  return sRet;
}

// ---------------------------------------------------------------------------- IsDecimal
// Sluzi na overenie platnosti desatinneho cisla
function IsDecimal(strDecimal) {
  //while(strDecimal.indexOf(" ") > 0)
  //  strDecimal = strDecimal.replace(" ", "");
  var reg = new RegExp(/^-?\d+([.,]{1}\d+)?$/);
  if(typeof(strDecimal) == "number")
    strDecimal = strDecimal.toString(10);
  return strDecimal.match(reg);
}


// ---------------------------------------------------------------------------- GetDecimalStr
// Vrati desatinne cislo bez formatu z formatovaneho cisla (napr. 12 000,20 -> 12000,20)
function GetDecimalStr(str) {
  if(typeof(str) == "number")
    str = str.toString(10);
  while(str.indexOf(" ") > -1)
    str = str.replace(" ", "");
  if(!IsDecimal(str))
    return "0,00";
  return str;
}

// ---------------------------------------------------------------------------- FormatDecimal
// Vrati naformatovane desatinne cislo (napr. 12000,20 -> 12 000,20)
function FormatDecimal(str, precision) {
  var sDec = ",00000000000000000000";
  if(typeof(str) == "number")
    str = str.toString(10);
  if(!IsDecimal(str))
    return "0" + sDec.substr(0, precision + 1);
  str = str.replace(",", ".");
  var nX = parseFloat(str);
  var sEval = "nX = Math.round(" + str + " * 1" + sDec.substr(1, precision) + ") / 1" + sDec.substr(1, precision) + ";";
  eval(sEval);
  str = nX.toString(10);
  str = str.replace(".", ",");
  var nX = str.indexOf(",");
  var sDec1 = sDec.substr(1, precision);
  if(nX > -1) {
    sDec1 = str.substr(nX + 1);
    str = str.substring(0, nX);
    sDec1 += sDec.substr(1, precision);
    sDec1 = sDec1.substr(0, precision);
  }
  sDec = FormatInt(str) + "," + sDec1;
  return sDec;
}

// ---------------------------------------------------------------------------- IsDate
function IsDate(strDate) {
  var den, mesiac, rok, nX;
  while(strDate.indexOf("/") > 0)
    strDate = strDate.replace("/", "");
  while(strDate.indexOf(",") > 0)
    strDate = strDate.replace(",", "");
  while(strDate.indexOf(".") > 0)
    strDate = strDate.replace(".", "");
  while(strDate.indexOf(" ") > 0)
    strDate = strDate.replace(" ", "");
  nX = parseInt(strDate, 10);
  if(isNaN(nX))
    return false;
  if(strDate.length == 6 || strDate.length == 8) {
    den = parseInt(strDate.substr(0, 2), 10);
    mesiac = parseInt(strDate.substr(2, 2), 10);
    rok = parseInt(strDate.substr(4), 10);
    if(isNaN(den) || isNaN(mesiac) || isNaN(rok))
      return false;
    if(rok < 100)
      rok += 2000;
    mesiac--;
    var dt = new Date(rok, mesiac, den);
    if(dt.getDate() != den || dt.getMonth() != mesiac || dt.getFullYear() != rok)
      return false;
  }
  else
    return false;
  return true;
}


// ---------------------------------------------------------------------------- EnsureVisible
// Zabezpecuje odrolovanie obrazovky, aby bol aktivny prvok (onfocus) viditelny
function EnsureVisible(oX)
{
  var nTop = oX.offsetTop;
  var nBodyHeight = document.body.scrollTop + document.body.clientHeight;
  var nBodyTop = document.body.scrollTop;

  var el = oX;
  while(1) {
    try {
      el = el.offsetParent;
      nTop += el.offsetTop;
    }
    catch(e) { break; }
  }

  /*
  if (nTop > nBodyHeight - nFooterHeight) {
    document.body.scrollTop += (nTop - (nBodyHeight - nFooterHeight));
    setTimeout("SetStartupFocus('" + oX.id + "')",100);
  }
  if(nTop < nBodyTop + nHeaderHeight) {
    document.body.scrollTop -= ((nBodyTop + nHeaderHeight) - nTop);
    setTimeout("SetStartupFocus('" + oX.id + "')",100);
  }
  if (nTop > nBodyHeight - 80) {
    document.body.scrollTop += (nTop - (nBodyHeight - 80));
    setTimeout("SetStartupFocus('" + oX.id + "')",100);
  }
  if(nTop < nBodyTop + 110) {
    document.body.scrollTop -= ((nBodyTop + 110) - nTop);
    setTimeout("SetStartupFocus('" + oX.id + "')",100);
  }
  */
}


var arrWindow = new Array();

// ---------------------------------------------------------------------------- OpenPopup
function OpenPopup(url, nH, nW, bResize)
{
  if (bResize == "") {
    bResize='no';
  }
  var nT = Math.round((700 - nH) / 2), nL = Math.round((1000 - nW) / 2);
  var sX = "top=" + nT +",left=" + nL + ",height=" + nH + ",width=" + nW + ",scrollbars=yes,status=no,toolbar=no,menubar=no,location=no,resizable=" + bResize;
  document.body.onunload = new Function("CloseAllPopup();");
  var oX = window.open(url, "_blank", sX, true);
  arrWindow = arrWindow.concat(oX);
}

// ---------------------------------------------------------------------------- CloseAllPopup
function CloseAllPopup()
{
  for(i=0; i < arrWindow.length; i++) {
    try {
      var oX = arrWindow[i];
      oX.close();
    }
    catch(e) {;}
  }
}

// ---------------------------------------------------------------------------- OpenModal
function OpenModal(url, arg, nH, nW)
{
  var sX = "dialogHeight:" + nH + "px;dialogWidth:" + nW + "px;status:no;resizable:yes;center:yes;help:no;scroll:yes;";
  return window.showModalDialog(url, arg, sX);
}

// ---------------------------------------------------------------------------- OpenCalendar
function OpenCalendar(elText)
{
  var sX = "dialogHeight:245px;dialogWidth:175px;status:no;help:no;scroll:no;", el;

  if(typeof(elText) == "string")
    el = document.all(elText, 0);
  else
    el = elText;

  if(el)
    el.value = window.showModalDialog ("../config/calendar.html", el.value, sX);
}

// ---------------------------------------------------------------------------- OpenCpv
function OpenCpv(elText, sValue)
{
  var sX = "dialogHeight:450px;dialogWidth:650px;status:yes;help:yes;scroll:yes;", el;
  var el;
  
  if(typeof(elText) == "string")
    el = document.all(elText, 0);
  else
    el = elText;

  if(el) {
    sRet = window.showModalDialog('../config/cpv_zvol.php?cpv='+sValue+'&b_but=1', el.value, sX);    
  }
  
  if (sRet) {
    el.value = sRet  +';\n' + el.value;
  }
}

// ---------------------------------------------------------------------------- DeleteQuestion
function DeleteQuestion()
{
  if(dgSelectedID == "0")
  {
    alert("Zaznam ktory si prajete odstranit musite najskor oznacit.");
    return;
  }
  if(window.confirm("Skutocne si prajete odstranit oznaceny zaznam ?"))
    __doPostBack('btnDelete', dgSelectedID);
}

// ---------------------------------------------------------------------------- CopyRecord
function CopyRecord()
{
  if(dgSelectedID == "0")
  {
    alert("Zaznam ktory si prajete kopirovat musite najskor oznacit.");
    return;
  }
  if(window.confirm("Skutocne si prajete vytvorit kopiu oznaceneho zaznamu ?"))
    __doPostBack('btnCopy', dgSelectedID);
}


// ---------------------------------------------------------------------------- SetStartupFocus
function SetStartupFocus(el)
{
  var oX = document.all(el,0);
  if(oX) {
    try {
      oX.focus();
      oX.select(); 
    } 
    catch(e) { ; }
  }
}

// ---------------------------------------------------------------------------- HeaderFooter
var nSetHeaderTop = 1, nSetFooterTop = 1, nIgnoreHeaderFooter = 0;
function SetHeaderFooter()
{
  if(document.all("divizia_detail_div_0",0))
    posunDIV();
     
  if(nIgnoreHeaderFooter == 1)
    return;
  document.body.focus();
  if(document.all('AFSHeader'))
    SetHeaderPos();
  if(document.all('AFSFooter'))
    SetFooterPos();
}

function SetHeaderPos()
{
  if(nSetHeaderTop == 0)
    return;
  var OffY = document.body.scrollTop;
  var PosY =  document.all('AFSHeader',0).style.pixelTop;
  var IncY = (OffY - PosY) / 3;
  if(IncY == 0 && OffY - PosY != 0)
    IncY = OffY - PosY;
  if(IncY != 0)
  { 
    PosY = PosY + IncY;
    document.all('AFSHeader',0).style.pixelTop=PosY;
    setTimeout('SetHeaderPos()',1);
  }
}

function SetFooterPos()
{
  if(nSetFooterTop == 0)
    return;
  var OffY = document.body.scrollTop + document.body.clientHeight - 52;
  var PosY =  document.all('AFSFooter',0).style.pixelTop;
  var IncY = (OffY - PosY) / 3;
  if(IncY == 0 && OffY - PosY != 0)
    IncY = OffY - PosY;
  if(IncY != 0)
  { 
    PosY = PosY + IncY;
    document.all('AFSFooter',0).style.pixelTop=PosY;
    setTimeout('SetFooterPos()',1);
  }
}

// ---------------------------------------------------------------------------- CascadeMenu
var bMenuVisible = 0;

function InitMenu()
{
  var bar = document.getElementById("menuBar").childNodes;

  for(var i=0;i < bar.length;i++)
  {
    if(bar[i].className != "Bar")
      continue;
    var menu = eval(bar[i].menu);
    if(!menu)
      continue;
    menu.style.visibility = "hidden";
    bar[i].onmouseover = new Function("if(bMenuVisible == 1) ShowMenu("+bar[i].id+");");
    bar[i].onclick = new Function("SwapMenu("+bar[i].id+")");
    bar[i].onmouseenter = new Function("if(bMenuVisible == 0) this.className = 'barOverNoMenu';");
    bar[i].onmouseleave = new Function("if(bMenuVisible == 0) this.className = 'Bar';");
    var Items = menu.children;
    
    for(var j=0; j<Items.length; j++)
    {
      var menuItem = eval(Items[j].id);
      if(menuItem.menu != null)
      { 
        menuItem.innerHTML += "<DIV Id="+menuItem.id+"_Arrow class='Arrow'>4</DIV>";
        FindSubMenu(menuItem.menu);
      }
      if(menuItem.cmd != null) 
        menuItem.onclick = new Function("Do("+menuItem.id+")");
      menuItem.onmouseover = new Function("highlight("+Items[j].id+")");
    }    
  }  
}

function SwapMenu(obj)
{
  if(bMenuVisible == 1) {
    bMenuVisible = 0;
    HideMenu(menuBar);
    document.body.onclick = null; 
  }
  else {
    HideAllMenus();
    bMenuVisible = 1;
    ShowMenu(obj);
    document.body.onclick = new Function("if(bMenuVisible == 1 && event.srcElement.tagName != 'DIV') SwapMenu(menuBar);"); 
  }
}

function FindSubMenu(subMenu)
{
  var menu=eval(subMenu);
  var Items = menu.children;
  for(var j=0; j<Items.length; j++)
  {
    menu.style.visibility = "hidden";
    var menuItem = eval(Items[j].id);
    if(menuItem.menu!= null)
    {
      menuItem.innerHTML += "<DIV Id="+menuItem.id+"_Arrow class='Arrow'>4</DIV>";
      FindSubMenu(menuItem.menu);
    }
    if(menuItem.cmd != null) 
      menuItem.onclick = new Function("Do("+menuItem.id+")"); 
    menuItem.onmouseover = new Function("highlight("+Items[j].id+")");
  }  
} 

function ShowMenu(obj)
{
  HideMenu(menuBar);
  document.body.focus();
  var menu = eval(obj.menu);
  var bar = eval(obj.id);
  
  bar.className="barOver";
  menu.style.visibility = "visible";
  menu.style.pixelTop =  obj.getBoundingClientRect().top + obj.offsetHeight;
  menu.style.pixelLeft = obj.getBoundingClientRect().left;
}

function highlight(obj)
{
  var PElement = eval(obj.parentElement.id);
  if(PElement.hasChildNodes() == true)
  {
    var Elements = PElement.children;
    for(var i=0;i<Elements.length;i++)
    {
      TE = eval(Elements[i].id);
      TE.className = "menuItem";
    }
  } 
  obj.className="ItemMouseOver";
  window.defaultStatus = obj.popis == null?"":obj.popis;
  ShowSubMenu(obj);
}
   
function Do(obj)
{
  bMenuVisible = 0;
  HideMenu(menuBar);
  document.body.onclick = null; 
  var cmd = eval(obj).cmd;	

  comand = obj.cmd ;

  if ( obj.cmd.indexOf('user_pozice_uz') > 0  )  {       
    hlaska = 'Report \"uzavřené pozice\" je podkladem k přiznání daně z příjmů a zahrnuje\npouze transakce v portfoliích služby BHS Asset Management (zákazníci se \n\"smlouvou o správě individuálních portfolií\"). Jedinými zavazujícími podklady\nk vykazování kapitálových výnosů (pro všechny zákazníky, t.j. i s \"Komisionářskou\nsmlouvou \" a \"Smlouvou o poradenství\") jsou formální vyúčtování obchodů na \nhlavičkovém papíru BH Securities a.s.\n\nU obchodů před 1.1.2003 je jako pořizovací cena použita cena průměrná a jako \ndatum obchodu je použito datum posledního obchodu, proto BH Securities a.s.\ndoporučuje zmíněné obchody porovnat s vyúčtováním obchodů z roku 2002.\n\nV případě zdanění dluhopisů jsou výpočty provedeny na základě odborného\nvýkladu společnosti TPA-NOTIA (daňový poradce) ze dne 25.11.2003, který\nsi BH Securities a.s. nechala vypracovat.\n\nVšechny aspekty kapitálových výnosů a jejich vliv na vaši daňovou strategii\ndoporučujeme konzultovat s vašim daňovým poradcem. BH Secutities a.s. nenese \nodpovednost za správnost reportu \"uzavřené pozice\", ani za případné důsledky\nneúplného nebo nesprávně podaného přiznání daňě z příjmu našich zákazníků';    
    what = window.confirm(hlaska );
    if (what != true) {
	return;
    }
  }

  
  if ( obj.cmd.indexOf('spad.php') > 0  )  {       
    hlaska = 'Společnost BH Securities a.s. nenese odpovednost za správnost dat!';    
    what = window.confirm(hlaska );
    if (what != true) {
	return;
    }
  }

  window.navigate(cmd);
}

function HideMenu(obj)
{
  if(obj.hasChildNodes()==true)
  {  
    var child = obj.children;
    for(var j =0;j<child.length;j++)
    {
      if (child[j].className=="barOver")
      {
        var bar = eval(child[j].id);
        bar.className="Bar";
      }
      if(child[j].menu != null)
      {
        var childMenu = eval(child[j].menu);
        if(childMenu.hasChildNodes()==true) 
          HideMenu(childMenu);
        childMenu.style.visibility = "hidden";
      }
    }
  }
}

function ShowSubMenu(obj)
{
  PMenu = eval(obj.parentElement.id);
  HideMenu(PMenu);
  if(obj.menu != null)
  {
    var menu = eval(obj.menu);
    menu.style.visibility = "visible";
    menu.style.pixelTop =  obj.getBoundingClientRect().top;
    menu.style.pixelLeft = obj.getBoundingClientRect().right - obj.offsetWidth ;
    if(menu.getBoundingClientRect().right > window.screen.availWidth )
      menu.style.pixelLeft = obj.getBoundingClientRect().left - obj.offsetWidth;
  }
} 

// ---------------------------------------------------------------------------- ContextMenu
function SwapContextMenu(el, menu) {
  HideAllMenus();
  var elMenu = document.all(menu, 0);
  if(!elMenu || !el)
    return;
  if(elMenu.style.visibility == "visible")
    HideCM(elMenu);
  else {
    ShowCM(el, elMenu);
    document.body.onclick = new Function("if(event.srcElement.tagName != 'DIV' && event.srcElement.id != '" + el.id + "') HideCM(document.all('" + menu + "', 0));"); 
  }
}

function HideAllMenus() {
  var coll = document.all.tags("INPUT");
  if(coll!=null) {
    for(i=0; i < coll.length; i++) { 
      if(coll[i].type == "button") {
        var elText = coll[i].id + "Menu";
        if(document.all(elText, 0))
          HideCM(document.all(elText, 0));
      }
    }
  }
  try { 
    bMenuVisible = 0;
    HideMenu(menuBar);
    document.body.onclick = null; 
  }
  catch(e) { ; }
}

function ShowCM(el, elMenu) {
  var nTop = el.offsetTop;
  var nLeft = el.offsetLeft;
  var oX = el;
  while(1) {
    try {
      oX = oX.offsetParent;
      nTop += oX.offsetTop;
      nLeft += oX.offsetLeft;
    }
    catch(e) { break; }
  }
  elMenu.style.pixelLeft = nLeft - ((elMenu.clientWidth - el.clientWidth) / 2);
  elMenu.style.pixelTop = nTop - elMenu.clientHeight - 7;
  elMenu.style.visibility = "visible";
  return false;
}

function HideCM(elMenu) {
  elMenu.style.visibility = "hidden";
}

function HLCM() {
  if(event.srcElement.className == "menuItem" && !event.srcElement.disabled) {
    event.srcElement.className = "ItemMouseOver";
    window.status = event.srcElement.popis;
  }
}

function LLCM() {
  if(event.srcElement.className == "ItemMouseOver" && !event.srcElement.disabled) {
    event.srcElement.className = "menuItem";
    window.status = "";
  }
}

function JumpCM(elMenu) {
  if (event.srcElement.className == "ItemMouseOver" && !event.srcElement.disabled) {
    HideCM(elMenu);
    if(event.srcElement.url)
      window.location = event.srcElement.url;
  }
}


function showTable(which, whichNone)
{
	var whichItem, whichNoneItem;
	
	whichArray = which.split(',');
	whichNoneArray = whichNone.split(',');

	for (ii in whichArray)
	{
		whichItem = whichArray[ii];
		if (document.all(whichItem))
			document.all(whichItem).style.display = 'block';
		if (document.all('btn_'+whichItem))
		{
			document.all('btn_'+whichItem).style.color = 'white';
			document.all('btn_'+whichItem).style.background = 'darkblue';
		}
	}
	
	for (ii in whichNoneArray)
	{
		whichNoneItem = whichNoneArray[ii];
		if (document.all(whichNoneItem))
			document.all(whichNoneItem).style.display = 'none';
		if (document.all('btn_'+whichNoneItem))
		{
			document.all('btn_'+whichNoneItem).style.color = 'black';
			document.all('btn_'+whichNoneItem).style.background = '#ddddff';
		}
	}
}

var nMyZoom = 10;
// zobrazenie zalozky
function ShowTab(nX) {
  nActiveTab = nX;
  nX--;
  for(i = 0; i < arrZalozky.length; i++) {
    try {
      document.all(arrZalozky[i], 0).style.display = (nX == i?"block":"none");
      document.all(arrTlacidla[i], 0).className = (nX == i?"ActiveTab":"Tab");
    }
    catch(e) {;}
  }
  InitHeaderFooter();
  //nMyZoom = 10;
  //ZoomIn();
}

function ZoomIn() {
  var sX = nMyZoom.toString(10) + "%";
  var el = document.all(arrZalozky[nActiveTab - 1], 0);
  el.style.zoom = sX;
  nMyZoom += 10;
  
  if(nMyZoom <= 100)
    setTimeout('ZoomIn()',10);
}

