﻿Tygrik.Style = function()
{
}

Tygrik.Style.Info = function(oElement)
{
   var sInfo = "";
   if (oElement != null)
   {
      sInfo = sInfo + oElement + ", ";
      sInfo = sInfo + "id:" + oElement.id + ", ";
      sInfo = sInfo + "class:" + oElement.className + ", ";
      sInfo = sInfo + "tag:" + oElement.tagName + ", ";
      sInfo = sInfo + "currentStyle.hasLayout:" + oElement.currentStyle.hasLayout + ", ";
      sInfo = sInfo + "nodeType:" + oElement.nodeType + ", ";
      sInfo = sInfo + "offsetLeft:" + oElement.offsetLeft + ", ";
      sInfo = sInfo + "scrollLeft:" + oElement.scrollLeft + ", ";
      sInfo = sInfo + "offsetTop:" + oElement.offsetTop + ", ";
      sInfo = sInfo + "scrollTop:" + oElement.scrollTop + ", ";
      sInfo = sInfo + "clientWidth:" + oElement.clientWidth + ", ";
      sInfo = sInfo + "clientHeight:" + oElement.clientHeight + ", ";
   }
   else
   {
      sInfo = sInfo + "[null]";
   }
   alert(sInfo);
}

Tygrik.Style.Class = function(oElement, sStyle)
{
   oElement.className = sStyle;
}

Tygrik.Style.Visibility = function(oElement, bVisible)
{
   if (bVisible)
   {
      oElement.style.visibility = 'visible';
   }
   else
   {
      oElement.style.visibility = 'hidden';
   }
}

Tygrik.Style.Display = function(oElement, sDisplay)
{
   oElement.style.display = sDisplay;
}

Tygrik.Style.ZIndex = function(oElement, iZIndex)
{
   oElement.style.zIndex = iZIndex;
}

Tygrik.Style.Cursor = function(oElement, sCursor)
{
   oElement.style.cursor = sCursor;
}

Tygrik.Style.Opacity = function(oElement, iFilter)
{
   if (typeof(oElement.style.opacity) != 'undefined')
   {
      if (iFilter == 10)
      {
         oElement.style.opacity = 1;
      }
      else
      {
         oElement.style.opacity = iFilter * 0.1;
      }
   }
   if (typeof(oElement.style.filter) != 'undefined')
   {
      if (iFilter == 10)
      {
         oElement.style.filter = '';
      }
      else
      {
         oElement.style.filter = 'alpha(opacity=' + iFilter * 10 + ')';
      }
   }
}

Tygrik.Style.ChangeSelectIcon = function(sID, sValue, sStyle)
{
   var oSelection = Tygrik.System.ByID(sID);
   if (oSelection != null)
   {
      var sNova = "";
      var sTrida = oSelection.className;
      var qTridy = sTrida.split(" ");
      for(var u = 0; u < qTridy.length; u++)
      {	
         var sCast = qTridy[u];

         if (sCast.indexOf(sStyle) == 0)
         {
            sCast = sStyle + Tygrik.Change.ToUrl(sValue);
         }
       
         if (sNova.length != 0)
         {
            sNova = sNova + " ";
         }
         sNova = sNova + sCast;
      }
      oSelection.className = sNova;
   }
}

Tygrik.Style.ChangeStretchInputCombo = function(sID)
{
   var oInput = Tygrik.System.ByID("Input_" + sID);
   var oCombo = Tygrik.System.ByID("Combo_" + sID);
   if (oInput != null && oCombo != null)
   {
      var iIndex = Tygrik.Change.String2Int(oCombo.value);
      oInput.value = oCombo.options[iIndex].text;
      oCombo.selectedIndex = 0;
   }
}

Tygrik.Style.Pos = function()
{
   this.x = 0;
   this.y = 0;
}

Tygrik.Style.GetPosition = function(oElement, oPos)
{

   var obj = oElement;
   var curleft = 0;
   var curtop = 0;

   while (obj != null)
   {
      curleft += obj.offsetLeft;
      curtop += obj.offsetTop;

      obj = obj.offsetParent;
   }

   obj = oElement;
   while (obj != null)
   {
      if (obj.scrollLeft != undefined && obj.scrollTop != undefined)
      {
         curleft -= obj.scrollLeft;
         curtop -= obj.scrollTop;
      }
      obj = obj.parentNode;
   }
  
   oPos.x = curleft;
   oPos.y = curtop;
}

Tygrik.Style.GetPositionAbsolute = function(oElement, oPos)
{

   var obj = oElement;
   var curleft = 0;
   var curtop = 0;

   while (obj != null)
   {
      curleft += obj.offsetLeft;
      curtop += obj.offsetTop;

      obj = obj.offsetParent;
   }
 
   oPos.x = curleft;
   oPos.y = curtop;
}

Tygrik.Style.SetPosition = function(oElement, oPos)
{
   oElement.style.left = oPos.x + "px";
   oElement.style.top = oPos.y + "px";
}

Tygrik.Style.SetSize = function(oElement, oSize)
{
   oElement.style.width = oSize.w + "px";
   oElement.style.height = oSize.h + "px";
}

Tygrik.Style.SizeHeight = function(oElement)
{
   return oElement.offsetHeight;
}

Tygrik.Style.SizeWidth = function(oElement)
{
   return oElement.offsetWidth;
}

Tygrik.Style.Size = function()
{
   this.w = 0;
   this.h = 0;
}

Tygrik.Style.GetStyleValue = function(oElement, sValueName)
{
   if (oElement != null)
   {
     if (oElement.currentStyle)
     {
        return oElement.currentStyle[sValueName];
     }
     if (window.getComputedStyle)
     {
        return document.defaultView.getComputedStyle(oElement, null).getPropertyValue(sValueName);
     }
   }
   return "";
}

Tygrik.Style.GetPaddingLeft = function(oElement)
{
  var sPaddinLeft = Tygrik.Style.GetStyleValue(oElement, "padding-left");
  if (typeof sPaddinLeft == "undefined")
  {
     sPaddinLeft =  Tygrik.Style.GetStyleValue(oElement, "padding");
  }
  if (typeof sPaddinLeft == "undefined" || sPaddinLeft == "" || sPaddinLeft == "auto")
  {
     return 0;
  }
  var iRet = Tygrik.Change.String2Int(sPaddinLeft);
  return iRet;
}

Tygrik.Style.GetMarginLeft = function(oElement)
{
  var sMarginLeft = Tygrik.Style.GetStyleValue(oElement, "margin-left");
  if (typeof sMarginLeft == "undefined")
  {
     sMarginLeft =  Tygrik.Style.GetStyleValue(oElement, "margin");
  }
  if (typeof sMarginLeft == "undefined" || sMarginLeft == "" || sMarginLeft == "auto")
  {
     return 0;
  }
  var iRet = Tygrik.Change.String2Int(sMarginLeft);
  return iRet;
}

Tygrik.Style.GetIsInline = function(oElementNow)
{
  return  Tygrik.Style.GetStyleValue(oElementNow, "display") == "inline";
}

Tygrik.Style.qDocumentWidthHeight = function(oRozmery)
{
  var winWidth = 0;
  var winHeight = 0;
  var oObj = Tygrik.System.ByID("Div_qDocumentWidthHeight");
  if (oObj == null)
  {
    var oNewElement = document.createElement("div");
    oNewElement.id = "Div_qDocumentWidthHeight";
    oNewElement.style.position = "absolute";
    oNewElement.style.left = "0px";
    oNewElement.style.top = "0px";
    oNewElement.style.width = "100%";
    oNewElement.style.height = "100%";
    oNewElement.style.zIndex = -3500;
    document.body.appendChild(oNewElement);
    oObj = Tygrik.System.ByID("Div_qDocumentWidthHeight");
  }
  oObj.style.display = "block";
  oRozmery.w = Tygrik.Style.SizeWidth(oObj);
  oRozmery.h = Tygrik.Style.SizeHeight(oObj);
  oObj.style.display = "none";
} 
