﻿var iSelMnu     = -1;
var iSelTopMnu  = -1;
var iSelTab     = -1;
var _imgNormal  = "n";
var _imgSel     = "s";
var _imgPath    = "img/mnu/";
var _imgExt     = ".jpg";
var _imgArr     = [_imgPath + "toto", _imgPath + "tippmix", _imgPath + "keno", _imgPath + "lotto5", _imgPath + "lotto6", _imgPath + "lotto7"];
var topImages   = new Array(_imgArr.length);
for(var i=0; i<_imgArr.length; i++) {
   topImages[i] = new Array(2);
   topImages[i][0] = new Image(); topImages[i][0].src = _imgArr[i] + _imgNormal + _imgExt;
   topImages[i][1] = new Image(); topImages[i][1].src = _imgArr[i] + _imgSel + _imgExt;
}

/* */
function setMenu(id, bOn) {
   var oMenu = document.getElementById("mnu" + i.toString());
   if(oMenu != null) {
      oMenu.className = bOn ? "mnu1" : "mnu1";
   }
}

/* */
function setTopMenu(id, bOn) {
   for(var i=0; i<_imgArr.length; i++) {
      if(i != iSelMnu) {
         var bSel = ((i == iSelTopMnu) || ((i == id) && bOn));
         var oImg  = document.getElementById("topImg" + i.toString());
         if(oImg != null) {
            oImg.src = bSel ? topImages[i][1].src : topImages[i][0].src;
            oImg.style.cursor = bSel ? "hand" : "auto";
         }
      }
   }
}

/* */
function selectMenu(id) {
   iSelMnu = id;
   var oImg = document.getElementById("topMenu" + id.toString());
   if(oImg != null)
      oImg.src = topImages[id][1].src;
}

function trim(value) {
   var temp = value;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
   var obj = / +/g; 
   temp = temp.replace(obj, " ");
   if (temp == " ") { temp = ""; }
   return temp;
}

/*
var aInfo = [ ["Szabadon beállítható reklámszöveg...", "#FFFF40"], 
              ["Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh", "#FFFF40"],
              ["euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.", "#FFFF40"] ];
*/
function showInfo(iPage) {
   if(aInfo.length > 0) {
      //alert(infoBox.className);
      //alert(infoBox.className.filter);

      if(aInfo[iPage][1] != "") {
         for(i=0; i<document.styleSheets[0].rules.length; i++) {
            if(document.styleSheets[0].rules[i].selectorText == "." + infoBox.className) {
               document.styleSheets[0].rules[i].style.filter = "progid:DXImageTransform.Microsoft." + aInfo[iPage][1] + ";"; //"progid:DXImageTransform.Microsoft.Slide(slidestyle=PUSH,Bands=1);";
            }
            //s += document.styleSheets[0].rules[i].selectorText + "\r\n";
         }
      }

      //alert(document.styleSheets[0].rules[10].selectorText);
      infoBox.filters[0].apply();
      infoBox.innerHTML = aInfo[iPage][0];
      //if(aInfo[iPage][1] != '')
      //   infoBox.style.backgroundColor = aInfo[iPage][1];
      iPage = (iPage == (aInfo.length - 1)) ? 0 : iPage + 1;
      setTimeout('showInfo(' + iPage.toString() + ')', 5000);
      infoBox.filters[0].play();
   }
}

// Vásárlás megerosíto terület megjelenítése
function showBuy() {
   var o = document.getElementById("lnkSzelveny");
   if(!o.disabled) {
      var oDiv = document.getElementById("pnlConfirm");
      if(oDiv)
         oDiv.style.display = "";
   }
}

//
function getContent(sSource) {
   var oFrame = document.getElementById("fTemp");
   if(!oFrame) {
      alert("Browser error!");
      return false;
   }
   window.status = "Egy kis türelmet...";
   oFrame.src = sSource;
   return false;
}

//
function setContent(sResp) {
   window.status = "";
   if(sResp == "OK") {
      var oFav = document.getElementById("fav" + iLastId.toString());
      if(iAct == 0) {
         oFav.onclick = new Function("delFav(" + iLastId.toString() + ");");
         oFav.innerHTML = "Eltávolít (-)";
      } else if(iAct == 1) {
         oFav.onclick = new Function("addFav(" + iLastId.toString() + ");");
         oFav.innerHTML = "Hozzáad (+)";
      }
   } else {
      alert(sResp);
   }
}


/* */
function setTab(id) {
   if(id < 4) {
      var oTab = document.getElementById("tab" + id.toString());
      if(oTab != null) {
         oTab.className = (iSelTab == id ? "tabSel" : (oTab.className == "tabSel" ? "tabNormal" : "tabSel"));
         oTab.style.cursor = (oTab.className == "tabNormal" ? "auto" : "hand");
      }
   }
}

/* */
function selRow(id) {
   var oRow = document.getElementById("row" + id.toString());
   if(oRow != null) {
      oRow.className = (oRow.className == "" ? "rowSel" : "");
      //oRow.style.cursor = (oRow.className == "" ? "auto" : "hand");
   }
   //oRow = document.getElementById("rowB" + id.toString());
   //oRow.className = (oRow.className == "row_sel" ? "rowB" : "row_sel");
}

function selRowH(id) {
   var oRow = document.getElementById("row" + id.toString());
   if(oRow != null) {
      oRow.className = (oRow.className == "" ? "rowSel" : "");
      oRow.style.cursor = (oRow.className == "" ? "auto" : "hand");
   }
}

/* */
function showPic(obj) {
   var mLeft = (document.all ? event.clientX + document.body.scrollLeft : e.pageX + window.pageXOffset);
   var mTop = (document.all ? event.clientY + document.body.scrollTop : e.pageY + window.pageYOffset);

   var _y = (document.all ? event.clientY : e.pageY);
window.status = obj.width.toString();
   /* pozíció javítása */            
   if(_y > 140)
      mTop -= 140;
   if(mLeft < 690)
      if(obj.width < 24)
         mLeft -= 85;
      else
         mLeft -= 105;
      
   var oDiv            = document.createElement("div");
	oDiv.id             = "dPic";
	oDiv.className      = "pic";
	oDiv.style.position = "absolute";
	oDiv.style.left     = mLeft;
	oDiv.style.top      = mTop;
	oDiv.style.display  = "";
	oDiv.innerHTML      = "<img src='" + obj.src + "' />";
	document.body.insertBefore(oDiv);
}

function hidePic() {
   var oDiv = document.getElementById("dPic");
   if(oDiv != null)
      document.body.removeChild(oDiv);
}

function chkNums(e) {
   var key;
   var keychar;
   if (window.event)
      key = window.event.keyCode;
   else if (e)
      key = e.which;
   else
      return true;
   keychar = String.fromCharCode(key);
   keychar = keychar.toLowerCase();
   if ((key == null) || (key == 0) || (key == 8) || (key == 9) || (key == 13) || (key == 27) )
      return true;
   else if ((("0123456789").indexOf(keychar) > -1))
      return true;
   else
   return false;
}

function clearOnSubmit() {
   if(document.forms.length > 0)
      document.forms[0].onsubmit = null;
}

function loadPage(sUrl) {
   document.location.href = sUrl;
   //alert(document.location.href);
}

function findPosX(obj) {
   var curleft = 0;
   if (obj.offsetParent) {
      while (obj.offsetParent) {
         curleft += obj.offsetLeft
         obj = obj.offsetParent;
      }
   } else if (obj.x)
      curleft += obj.x;
   return curleft;
}

function findPosY(obj) {
   var curtop = 0;
   if (obj.offsetParent) {
      while (obj.offsetParent) {
         curtop += obj.offsetTop; obj = obj.offsetParent;
      }
   } else if(obj.y)
      curtop += obj.y;
   return curtop;
}

function preview(width) {
   var iLeft = (screen.availWidth-width) / 2;
   var sPos=',left=' + iLeft.toString() + ',top=' + (screen.availHeight/2-250).toString();
   var pWin=window.open('preview.aspx', "Print", "toolbar=no,scrollbars=yes,resizable=no,width=" + width.toString() + ",height=500" + sPos);
   //var sPos=',left=' + (screen.availWidth/2-370).toString() + ',top=' + (screen.availHeight/2-250) .toString();
   //var pWin=window.open('preview.aspx', "Print", "toolbar=no,scrollbars=yes,resizable=no,width=740,height=500" + sPos);
}

/* hint */
var horizontal_offset = "9px";
var vertical_offset   = "0";
var ie=document.all;
var ns6=document.getElementById&&!document.all;

function iecompattest(){return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;}
function hidetip(e){dropmenuobj.style.visibility="hidden";dropmenuobj.style.left="-500px";}
function createhintbox(){var divblock=document.createElement("div");divblock.setAttribute("id", "hintbox");document.body.appendChild(divblock);}

function getposOffset(what, offsettype){
   var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
   var parentEl=what.offsetParent;
   while (parentEl!=null){
      totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
      parentEl=parentEl.offsetParent;
   }
   return totaloffset;
}

function clearbrowseredge(obj, whichedge){
   var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1;
   if(whichedge=="rightedge"){
      var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40;
      dropmenuobj.contentmeasure=dropmenuobj.offsetWidth;
      if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure) {
         edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset);
      }
   }else{
      var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18;
      dropmenuobj.contentmeasure=dropmenuobj.offsetHeight;
      if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
         edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight;
   }
   return edgeoffset;
}

/*
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
*/
function _showHint(menucontents, obj, e, tipwidth){
   if ((ie||ns6) && document.getElementById("hintbox")){
      dropmenuobj=document.getElementById("hintbox");
      dropmenuobj.innerHTML=menucontents;
      dropmenuobj.style.left=dropmenuobj.style.top=-500;
      if (tipwidth!=""){
         dropmenuobj.widthobj=dropmenuobj.style;
         dropmenuobj.widthobj.width=tipwidth;
      }
      dropmenuobj.x=getposOffset(obj, "left");
      dropmenuobj.y=getposOffset(obj, "top");
      dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px";
    //dropmenuobj.style.left=event.clientX + document.body.scrollLeft + 10;
    
      dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px";
      dropmenuobj.style.visibility="visible";
      obj.onmouseout=hidetip;
   }
}

if (window.addEventListener)
   window.addEventListener("load", createhintbox, false);
else if (window.attachEvent)
   window.attachEvent("onload", createhintbox);
else if (document.getElementById)
   window.onload=createhintbox;

/******************/
function showTl(id) {
   for(var i=1; i<=6; i++) {
      var oLnk=document.getElementById("atl" + i.toString());
      if(oLnk != null)
         if(i == id)
            oLnk.innerText = (oLnk.innerText == "tovább") ? "vissza" : "tovább";
         else
            oLnk.innerText = "tovább";
      
      var o=document.getElementById("tl" + i.toString());
      if(o != null) {
         if(i == id)
            o.style.display = (o.style.display == "none" ? "" : "none");
         else
            o.style.display = "none";
      }
   }
}

/******************/
function showMinta(sUrl) {
   var sPos=',width=680,height=600,left=' + (screen.availWidth/2-320).toString() + ',top=' + (screen.availHeight/2-300).toString();
   var actWin=window.open(sUrl, 'Minta', 'location=no,menubar=no,toolbar=no,scrollbars=yes,resizable=no,status=no'+sPos);
}

