//
// (C) Copyright 2006 Active Web Solutions Ltd
//   All rights reserved.
//
// This software is provided "as is" without warranty of any kind, express or implied, 
// including but not limited to warranties of merchantability and fitness for a particular 
// purpose. Active Web Solutions Ltd does not support the Software, nor does it warrant 
// that the Software will meet your requirements or that the operation of the Software will 
// be uninterrupted or error free or that any defects will be corrected.
//

//Effect.ToggleTools = function() 
function ToggleTools()
{
  var gadgetCatalogVisible = true;
  var windowWidth = document.documentElement.clientWidth;
  var showLeftPos = parseInt((windowWidth / 2) - (800 / 2));
  var hideLeftPos = showLeftPos + 303;
  var hideLeftPosStyle = "-" + hideLeftPos + "px"

  if ($('webPartCatalog').style.left == hideLeftPosStyle)
  {
    //hidden
    gadgetCatalogVisible = false;
  }

  if(gadgetCatalogVisible) 
  {
    //hide
    new Effect.MoveBy('webPartCatalog', 0, -303);
    gadgetCatalogVisible = false;
    $('gadgetCatalogStyle').value = "left: -" + hideLeftPos + "px;";
    $('gadgetCatalogToggle').style.background = "#E1E0D3 url(/App_Themes/1___default/images/open_tools.png) no-repeat center center";
    $('gadgetCatalogShown').value = "n";
  }
  else 
  {
    //show
    new Effect.MoveBy('webPartCatalog', 0, 303);
    gadgetCatalogVisible = true;
    $('gadgetCatalogStyle').value = "left: -" + showLeftPos + "px;";
    $('gadgetCatalogToggle').style.background = "#E1E0D3 url(/App_Themes/1___default/images/close_tools.png) no-repeat center center";
    $('gadgetCatalogShown').value = "y";
  }
}

function __CheckWebPartCatalog()
{
  //Attach the onresize event to the window
  window.attachEvent('onresize',setCatalogPosition)
  window.attachEvent('onscroll',setCatalogScrollPosition)
  
  var showLeftPos = parseInt((document.documentElement.clientWidth / 2) - (800 / 2));
  var hideLeftPos = showLeftPos + 303;

  //Check initial position
  if ($('webPartCatalog').style.left == "")
  {
    $('webPartCatalog').style.left = '-' + hideLeftPos + 'px';
    $('webPartCatalog').style.display = 'block';
    $('gadgetCatalogStyle').value = "left: -" + showLeftPos + "px;";
    new Effect.MoveBy('webPartCatalog', 0, 303);
  }
  else
  {
    //just show the Catalog
    $('webPartCatalog').style.display = 'block';
    //Check if hidden
    var hideLeftPosStyle = "-" + hideLeftPos + "px"
    if ($('webPartCatalog').style.left == hideLeftPosStyle)
    {
      $('gadgetCatalogToggle').style.background = "#E1E0D3 url(/App_Themes/1___default/images/open_tools.png) no-repeat center center";
    }
  }
}

function setCatalogPosition() 
{
  var showLeftPos = parseInt((document.documentElement.clientWidth / 2) - (800 / 2));
  var hideLeftPos = showLeftPos + 303;
  if ( $('gadgetCatalogShown').value == "y" || $('gadgetCatalogShown').value == "")
  {
    $('webPartCatalog').style.left = "-" + showLeftPos + "px"
    $('gadgetCatalogStyle').value = "left: -" + showLeftPos + "px;";
  }
  else
  {
    $('webPartCatalog').style.left = "-" + hideLeftPos + "px"
    $('gadgetCatalogStyle').value = "left: -" + hideLeftPos + "px;";
  }
}

function setCatalogScrollPosition() 
{
  var scroll = document.documentElement.scrollTop - 10;
  $('webPartCatalog').style.top = scroll + "px";
}


// Removes DropDown's from Rendered HTML when a Dialog Div is showing - to prevent them from displaying over the Dialog Div (IE Only)
function __RemoveDropDowns(exclusionId)
{
	if (exclusionId == '')
	{
		exclusionId = '&&&&&';
	}
	if (navigator.userAgent.indexOf('MSIE') !=-1)
	{
		var elementClass = '';

		var els = document.getElementsByTagName("SELECT");

		var done = 'false';
		var i = 0;

		while (done == 'false')
		{
			if (i > (document.getElementsByTagName("SELECT").length - 1))
			{
				done = 'true';
			}
			else
			{
				if (els[i].id.indexOf(exclusionId) != -1)
				{
					i++;
				}
				else
				{
					if (els[i].selectedIndex != -1)
					{
						els[i].outerHTML = '<span class=label>' + els[i].options[els[i].selectedIndex].text + '</span>';
					}
					else
					{
						if (els[i].options.length != 0)
						{
							var list = '';
							for(var j=0;j<els[i].options.length;j++)
							{
								list += els[i].options[j].text + "<br />";
							}
							
							els[i].outerHTML = '<span class=label>' + list + '</span>';
						}
						else
						{
							els[i].outerHTML = '<span class=label></span>';
						}
					}
				}
			}
		}
	}
}




