﻿DOM      = ( document.getElementById ) ? 1 : 0;
NS4      = ( document.layers ) ? 1 : 0;
IE4      = ( document.all ) ? 1 : 0;
Opera5  = (navigator.userAgent.indexOf("Opera 5") > -1 || navigator.userAgent.indexOf("Opera/5") > -1 || navigator.userAgent.indexOf("Opera 6") > -1 || navigator.userAgent.indexOf("Opera/6") > -1) ? 1 : 0;
isOldIE = (navigator.userAgent.indexOf("MSIE 4") > -1 || navigator.userAgent.indexOf("MSIE 3") > -1 || navigator.userAgent.indexOf("MSIE 2") > -1 || navigator.userAgent.indexOf("MSIE 1") > -1) ? 1 : 0;

function cloneLayerToIFrame( _div, _iframe )
{
  var layer = document.getElementById( _div );
  var iframe = document.getElementById( _iframe );
  iframe.style.display = layer.style.display;
  iframe.style.width = layer.offsetWidth-5;
  iframe.style.height = layer.offsetHeight-5;
  iframe.style.left = layer.offsetLeft;
  iframe.style.top = layer.offsetTop;
}

function changelayer( strLay, w, h )
{
  // alert(strLay + ' - ' + w + ' - ' + h);
  if (document.all)
  {
   if (document.all[strLay].style.visibility != 'hidden')
   {
    document.all[strLay].style.visibility = 'hidden';
   }
   else
   {
    document.all[strLay].style.visibility = 'visible';
    document.all[strLay].style.pixelLeft = w;
    document.all[strLay].style.pixelTop = h;
   }
  }
  else if (document.layers)
  {
   if (document.layers[strLay].visibility != 'hide')
   {
      document.layers[strLay].visibility = 'hide';
   }
   else
   {
    document.layers[strLay].visibility = 'show';
    document.layers[strLay].left = w;
    document.layers[strLay].top = h - 13;
   }
  }
  else if (document.getElementById)
  {
   if (document.getElementById(strLay).style.visibility != 'hidden')
   {
    document.getElementById(strLay).style.visibility = 'hidden';
   }
   else
   {
    document.getElementById(strLay).style.visibility = 'visible';
    document.getElementById(strLay).style.left = w;
    document.getElementById(strLay).style.top = h;
   }
  }
}

function showlayer(strLay)
{
  if (document.all)
  {
    document.all[strLay].style.visibility = 'visible';
  } else if (document.layers) {
    document.layers[strLay].visibility = 'show';
  } else if (document.getElementById) {
    document.getElementById(strLay).style.visibility = 'visible';
  }
}

function showlayerpos(strLay,w,h)
{
  if (document.all)
  {
    document.all[strLay].style.visibility = 'visible';
    document.all[strLay].style.pixelLeft = w;
    document.all[strLay].style.pixelTop = h;
  } else if (document.layers) {
    document.layers[strLay].visibility = 'show';
    document.layers[strLay].left = w;
    document.layers[strLay].top = h;
  } else if (document.getElementById) {
    document.getElementById(strLay).style.visibility = 'visible';
    document.getElementById(strLay).style.left = w;
    document.getElementById(strLay).style.top = h;
  }
}

function hidelayer(strLay) {
  if (document.all)
  {
    document.all[strLay].style.visibility = 'hidden';
  } else if (document.layers) {
    document.layers[strLay].visibility = 'hide';
  } else if (document.getElementById) {
    document.getElementById(strLay).style.visibility = 'hidden';
  }
}

function MM_swapImgRestore()
{ //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages()
{ //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d)
{ //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage()
{ //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function openloginhelpwindow(path)
{
  window.open(path,"window1","width=450,height=550,scrollbar=yes");
}

function openhelpwindow(path)
{
  window.open(path,"window3","width=470,height=350,resizable=yes,scrollbars=yes");
}

function opentoplistwindow(path)
{
  window.open(path,"window2","width=800,height=350,resizable=yes,scrollbars=yes,toolbar=no,menubar=yes");
}

function opennewentitywindow(path)
{
  window.open(path,"window2","width=300,height=100,resizable=yes,scrollbars=yes,toolbar=no,menubar=yes");
}

function opennewcustomwindow(path,width,height)
{
  window.open(path,"window2","width=" + width + ",height=" + height + ",resizable=yes,scrollbars=yes,toolbar=no,menubar=yes");
}

function doPost()
{
  document.forms[0].submit();
}

function changePicture( strId, strLayerId, strPicturePath, strPicturePathSub )
{
  if( document.images )
  {
    if ( IE4 )
    {
      if ( document.all[ strLayerId ].style.visibility == "visible" )
        document[ strId ].src=strPicturePath;
      else
        document[ strId ].src=strPicturePathSub;
    }
    else
    {
      //alert( document.getElementById( strLayerId ).style.visibility );
      if ( document.getElementById( strLayerId ).style.visibility == "visible" )
        document[ strId ].src=strPicturePath;
      else
        document[ strId ].src=strPicturePathSub;
    }
  }
}

function isProfilePage()
{
  myString = document.URL;
  intResult = myString.search(/profiles.aspx/gi);

  strResult = myString.slice(intResult);

  if( strResult == "profiles.aspx" )
  {
    return true;
  }
  else
  {
    return false;
  }
}


function postIfProfilePage( strPage )
{
  if( isProfilePage() )
  {
    document.forms[0].location.value=strPage;
    document.forms[0].submit();
  }
  else
  {
    window.location=strPage;
  }
}

/*function togglecheckbox( oCheckbox, intIndex )
{
  if ( true == oCheckbox[ intIndex ].checked )
  {
    oCheckbox[ intIndex ].checked = false;
  }
  else
  {
    oCheckbox[ intIndex ].checked = true;
  }
}*/

function togglecheckbox( _checkbox )
{
  if ( true == _checkbox.checked )
  {
    _checkbox.checked = false;
  }
  else
  {
    _checkbox.checked = true;
  }
}

function toggleCheckBoxByID( _label )
{
  // alert( _label );
  for (i=0;i<document.forms[0].elements.length;i++)
  {
    if (document.forms[0].elements[i].type=="checkbox")
    {
      if( document.forms[0].elements[i].id.indexOf( _label ) > -1 )
      {
        togglecheckbox( document.forms[0].elements[i] );
      }
    }
  }
}


function ToggleCheckBoxes( _label )
{
  for (i=0;i<document.forms[0].elements.length;i++)
  {
    if (document.forms[0].elements[i].type=="checkbox")
    {
      if( document.forms[0].elements[i].name.indexOf( _label ) > -1 )
      {
        togglecheckbox( document.forms[0].elements[i] );
      }
    }
  }
}

function ToggleCheckBoxes2( _label, bcheck )
{
  for (i=0;i<document.forms[0].elements.length;i++)
  {
    if (document.forms[0].elements[i].type=="checkbox")
    {
      if( document.forms[0].elements[i].name.indexOf( _label ) > -1 )
      {
        document.forms[0].elements[i].checked = bcheck;
      }
    }
  }
}

function CheckBoxAction( _label, _type )
{
  for (i=0;i<document.forms[0].elements.length;i++)
  {
    if (document.forms[0].elements[i].type=="checkbox")
    {
      if( document.forms[0].elements[i].name.indexOf( _label ) > -1 )
      {
        if( _type == 0 )
        {
          // Unselect:
          document.forms[0].elements[i].checked = false;
        }
        else if( _type == 1 )
        {
          // Select:
          document.forms[0].elements[i].checked = true;
        }
        else if( _type == 2 )
        {
          // Invert
          togglecheckbox( document.forms[0].elements[i] );
        }
      }
    }
  }
}

function togglelayer( strLay )
{
  if (document.getElementById)
  {
//    alert( document.getElementById(strLay).style.visibility );
    if (document.getElementById(strLay).style.visibility != 'hidden')
    {
      document.getElementById(strLay).style.visibility = 'hidden';
      document.getElementById(strLay).style.position   = 'absolute';
    }
    else
    {
      document.getElementById(strLay).style.visibility = 'visible';
      document.getElementById(strLay).style.position   = 'relative';
    }
  }
  else if (document.all)
  {
    if (document.all[strLay].style.visibility != 'hidden')
    {
      document.all[strLay].style.visibility = 'hidden';
      document.all[strLay].style.position   = 'absolute';
    }
    else
    {
      document.all[strLay].style.visibility = 'visible';
      document.all[strLay].style.position   = 'relative';
    }
  }
  else if (document.layers)
  {
    if (document.layers[strLay].visibility != 'hide')
    {
      document.layers[strLay].visibility = 'hide';
      document.layers[strLay].position   = 'absolute';
    }
    else
    {
      document.layers[strLay].visibility = 'show';
      document.layers[strLay].position   = 'relative';
    }
  }
}

function setInnerHTML( id, text )
{
  if( document.all )
  {
    document.all[ id ].innerHTML=text;
  }
  else
  {
    document.getElementById( id ).innerHTML=text;
  }
}


function toggledescription( strLay, strHidden )
{
  var intCheck = 1;

  if (document.getElementById)
  {
    if (document.getElementById(strLay).style.visibility != 'hidden')
    {
      intCheck = 0;
      document.getElementById(strLay).style.visibility = 'hidden';
      document.getElementById(strLay).style.position   = 'absolute';
    }
    else
    {
      intCheck = 1;
      document.getElementById(strLay).style.visibility = 'visible';
      document.getElementById(strLay).style.position   = 'relative';
    }
  }
  else if (document.all)
  {
    if (document.all[strLay].style.visibility != 'hidden')
    {
      intCheck = 0;
      document.all[strLay].style.visibility = 'hidden';
      document.all[strLay].style.position   = 'absolute';
    }
    else
    {
      intCheck = 1;
      document.all[strLay].style.visibility = 'visible';
      document.all[strLay].style.position   = 'relative';
    }
  }
  else if (document.layers)
  {
    if (document.layers[strLay].visibility != 'hide')
    {
      intCheck = 0;
      document.layers[strLay].visibility = 'hide';
      document.layers[strLay].position   = 'absolute';
    }
    else
    {
      intCheck = 1;
      document.layers[strLay].visibility = 'show';
      document.layers[strLay].position   = 'relative';
    }
  }

  document.forms[0].elements[ strHidden ].value = intCheck;
}


function toggleProfileGroup( pgid, groupid )
{
  intValue = document.forms[0].elements["ProfileGroup_PGID" + pgid + "_GroupID" + groupid].value;
//  alert( "toggleProfileGroup " + intValue );
  if ( 0 == intValue )
  {
    document.forms[0].elements["ProfileGroup_PGID" + pgid + "_GroupID" + groupid].value=1;
  }
  else
  {
    document.forms[0].elements["ProfileGroup_PGID" + pgid + "_GroupID" + groupid].value=0;
  }
  
  toggleLayer2( "ProfileGroupContainer_PGID" + pgid + "_GroupID" + groupid );
  changeProfileGroupPicture( pgid, groupid );
}


function toggleProfileGroup2( pgid, groupid )
{ 
//  alert( "toggleProfileGroup2" );
  toggleLayer2( "ProfileGroupContainer_PGID" + pgid + "_GroupID" + groupid );
  changeProfileGroupPicture( pgid, groupid );
}


function toggleElement( strid )
{
//  alert( "toggleElement" );
  toggleLayer2( strid + 'div' );
  changeElementPicture( strid );
}


function changeElementPicture( strid )
{
//  alert( "changeElementPicture" );
  if( document.images )
  {
    imgObject = document.getElementById( strid + 'pic' );
    intValue = document.forms[0].elements[strid + 'value'].value;
    if( 0 == intValue )
    {
      imgObject.src="../images/collapse_blue.jpg";
      document.forms[0].elements[strid + 'value'].value=1;
    }
    else
    {
      imgObject.src="../images/expand_blue.jpg";
      document.forms[0].elements[strid + 'value'].value=0;
    }
  }
}

function doSomething(e)
{
	if (!e) var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
}

function toggleSectionGroupContainer( sid )
{
  intValue = document.forms[0].elements["SectionPageQuestionToggleValue_" + sid].value;
//  alert( "toggleSectionGroupContainer " + intValue );
  if ( 0 == intValue )
  {
    document.forms[0].elements["SectionPageQuestionToggleValue_" + sid].value=1;
  }
  else
  {
    document.forms[0].elements["SectionPageQuestionToggleValue_" + sid].value=0;
  }

  toggleLayer2( "SectionPageQuestionContainer_" + sid );
  changeSectionGroupPicture( sid );
}


function changeSectionGroupPicture( sid )
{
  if( document.images )
  {
    imgObject = document.getElementById( "SectionPageQuestionPicture_" + sid );
    intValue = document.forms[0].elements[ "SectionPageQuestionToggleValue_" + sid ].value;
//    alert( "changeSectionGroupPicture " + intValue );
    
    if ( 1 == intValue )
      imgObject.src="../images/collapse_blue.jpg";
    else
      imgObject.src="../images/expand_blue.jpg";
  }
}

function togglePicture( id, img1, img2 )
{
  img = document.getElementById( id );
  if( img.src == img1 )
    img.src = img2;
  else
    img.src = img1;
}


function toggleLayer2( strLay )
{
  if (document.getElementById)
  {
    layerObject = document.getElementById(strLay);
    if (layerObject.style.display != 'none')
    {
      layerObject.style.display = 'none';
    }
    else
    {
      layerObject.style.display = 'block';
    }
  }
  else if (document.all)
  {
    if ( document.all[ strLay ].style.display != 'none' )
    {
      document.all[ strLay ].style.display  = 'none';
      document.all[ strLay ].style.position = 'absolute';
    }
    else
    {
      document.all[ strLay ].style.display  = 'block';
      document.all[ strLay ].style.position = 'relative';
    }
  }
  else if ( document.layers )
  {
    if ( document.layers[ strLay ].display != 'none' )
    {
      document.layers[ strLay ].display  = 'none';
      document.layers[ strLay ].position = 'absolute';
    }
    else
    {
      document.layers[ strLay ].display  = 'block';
      document.layers[ strLay ].position = 'relative';
    }
  }
}

function changeProfileGroupPicture( pgid, groupid )
{
  if ( document.images )
  {
    imgObject = document.getElementById( "ProfileGroupPicture_PGID" + pgid + "_GroupID" + groupid );
    intValue  = document.forms[ 0 ].elements[ "ProfileGroup_PGID" + pgid + "_GroupID" + groupid ].value;
    
    // alert( "changeProfileGroupPicture " + intValue );
    
    if ( 1 == intValue )
      imgObject.src="../images/collapse_blue.jpg";
    else
      imgObject.src="../images/expand_blue.jpg";
  }
}

function getInfo()
{
  intValue = document.forms[0].elements[ "SectionPageQuestionToggleValue_1" ].value;
  
  alert( "Current: " + intValue );
}

function toggleDisplay( sID )
{
  if (document.getElementById)
  {
    var _o = document.getElementById( sID ).style;
    
    if ( _o.display == 'none' )
      _o.display = 'block';
    else
      _o.display = 'none';
  }
}

function switchRecommendationView()
{
  var _oB = document.getElementById( 'btnSwitchRecommendationView' );
  var _oC = document.getElementById( 'ffChart' ).style;
  var _oT = document.getElementById( 'ffTable' ).style;
  
  if ( _oC.display == 'block' || _oC.display == '' )
  {
    _oB.value = 'Byt vy';
    _oC.display = 'none';
    _oT.display = 'block';
  }
  else
  {
    _oB.value = 'Byt vy';
    _oT.display = 'none';
    _oC.display = 'block';
  }
}

function openPrintWindow( sURL )
{
  window.open( sURL, "", "width=800,height=600,resizable=yes,scrollbars=yes,toolbar=yes,menubar=yes,status=yes" );
}