
// js\WxCore.js


// (c) 1993 - 2003 Legato Systems Inc.
//
// The WxCore.js file contains the core javascript library required by ApplicationXtender Web Access .NET web
// pages.  This libarary contains javascript that implements:
//    QueryString Object - For managing query string creation
//    Broswer Info Library - For discovering the version of the browser
//    Context Menu Libarary - Methods used for implementing a context menu
//    Misc Methods - For example, help, about, and settings popup creation.
//
// History:
//    Created 8/27/2003 - RZR

//global flag that tells us if the form was submitted.
g_bFormSubmitted = false;


function HookSubmit()
{
   thisForm = document.forms[0];

   //Create a new pointer to the intrinsic submit method
   thisForm.__submit = thisForm.submit;
   
   //replace the intrinsic submit method point with a pointer to
   //our own version of this method.
   thisForm.submit = __submitForm;
}

//Our replacement submit method
function __submitForm()
{
   //Fire the event that triggers onsubmit event.
   if (IsExplorer())
      thisForm.fireEvent("onsubmit");
   else
      thisForm.onsubmit();
      
   //call the original submit method.
   thisForm.__submit();
}

//This is the default hanlder for the onsubmit event.
function SetFormSubmitted()
{
   g_bFormSubmitted = true;
}



//This method is called from the unload event which checks to see if we should autologout.
function CheckAutoLogout()
{
   var oQuery = new QueryString(document)
   var enableAutoLogout = document.forms[0].elements["AutoLogout"].value;
   if (g_bFormSubmitted == false && enableAutoLogout == "True")
      window.open("AutoLogout.aspx", "AutoLogout", "height=1,width=1,toolbar=no,menubar=no,status=no");         
}



function NormalizePageLayout()
{
   var screenWidth;
   if (window.innerWidth == null) 
      screenWidth = document.body.clientWidth - 5;
   else 
      screenWidth = window.innerWidth - 5;
    
   var oThumbnailPane = document.getElementById("pageLayout_ThumbnailContainer");
   if (oThumbnailPane != null && oThumbnailPane.style.display != "none")
      screenWidth = screenWidth - oThumbnailPane.style.pixelWidth;
      
   var oIndexingPane = document.getElementById("pageLayout_IndexingContainer");
   if (oIndexingPane != null && oIndexingPane.style.display != "none")
      screenWidth = screenWidth - oIndexingPane.style.pixelWidth;
      
   var oGripPane = document.getElementById("pageLayout_IndexGripSeperator");
   if (oGripPane != null && oGripPane.style.display != "none")
      screenWidth = screenWidth - oGripPane.style.pixelWidth;
      
      
   var oConentPane = document.getElementById("pageLayout_ContentContainer");
   if (oConentPane != null)
   {

      if (oConentPane.parentNode.style.paddingTop != "")
         screenWidth = screenWidth - 10;
      if (screenWidth < 0)
         screenWidth = 0;
      oConentPane.style.pixelWidth = screenWidth;
    
      
      var oEmbeddedPageView = document.getElementById("PageLayout_PageView_PageLayout_ContentContainer");
      if (oEmbeddedPageView != null)
         oEmbeddedPageView.style.pixelWidth = screenWidth - 5;
   }
   
   var oSelectedControlID = document.forms[0].elements["SelectedControl"];
   if (oSelectedControlID != null)
   {
      var selectedControlId = oSelectedControlID.value;
      if (selectedControlId != null && selectedControlId.length > 0)
      {
         var oSelectedControl = document.getElementById(selectedControlId);
         if (oSelectedControl != null)
         {
            oSelectedControl.select();
            oSelectedControl.focus();
         }
      }
   }
}





/////////////////////////////////////////////////////////////////////////////////////
// Browser Info Library
/////////////////////////////////////////////////////////////////////////////////////
////////
//////
////
//

//	IsVersionMin(nVersion)
//
// This method returns true if the current browser	version is version 4.0 or greater.
function IsVersionMin(nVersion)
   {
   return (parseInt(navigator.appVersion.charAt(0)) >= nVersion)
   }
	 
	 
//
//	IsNav()
//
//	This method	returns true if the current browser	is	Netscape	naviagtor version	
//	4.0 or greater		
function IsNav()
   {
   return IsVersionMin(4) && (navigator.appName == "Netscape")
   }
		  
//
//	IsNavMinVer()
//
//	This method	returns true if the current browser	is	Netscape	and the version
// is greater than the supplied parameter
function IsNavMinVer(nVer)
   {
   return IsVersionMin(nVer) && (navigator.appName == "Netscape")
   }

//
//	IsExplorer()
//
//	This method	returns true if the current browser	is	Microsoft IE version	
//	4.0 or greater		
function IsExplorer()
   {
   return IsVersionMin(4) && (navigator.appVersion.indexOf("MSIE") != -1)
   }
   
//
//	IsExplorerMinVer()
//
//	This method	returns true if the current browser	is	Microsoft IE version	
//	nVer or higher
function IsExplorerMinVer(nVer)
   {
   return IsVersionMin(nVer) && (navigator.appVersion.indexOf("MSIE") != -1)
   }
   
	 
//	Trim(gValue)
//
//	This function trims the	leading and	trailing	white	space	from the	
//	input	string gValue
function Trim(gValue)
   {
   //Trim leading white space
   while (gValue.charAt(0) == " ")
      gValue =	gValue.substring(1,gValue.length);
   	 
   //Trim trailing whie space
   var cChar = gValue.charAt(gValue.length-1);
   while (cChar == " ")
      {
      gValue = gValue.substring(0,gValue.length - 1);
      cChar = gValue.charAt(gValue.length -1);
      }
   	 
   return gValue;
   }
	 
	 
function IsIEVersion(nVer)
   {
   szVersion = "MSIE " + nVer.toString();
   return navigator.appVersion.indexOf(szVersion) != -1;
   }

//
//	IsMacintosh()
//
//	This method	returns true if the current browser	is	on Macintosh
//
function IsMacintosh()
   {
   return (navigator.userAgent.indexOf("Macintosh") != -1)
   }
   
function _debugInspect(obj)
   {
   var dbgWnd = window.open("","inspect","HEIGHT=600,WIDTH=600,scrollbars=yes,resizable=yes")
   var wintxt = "<HTML><HEAD><TITLE>ApplicationXtender Web Access .NET</TITLE></HEAD><BODY>"
   wintxt += "<TABLE cellpadding='2' cellspacing='2' border='0' width='100%'>";
   wintxt += "<TR><TD width='30%'><B>Property</B></TD><TD width='70%'><B>Value</B></TD></TR>";
   for (prop in obj)
      {
      if (typeof obj[prop] != "function" && typeof obj[prop] != "unknown")
         wintxt += "<TR><TD nowrap>" + prop + "</TD><TD nowrap>" + obj[prop] + "</TD></TR>";
      }
   wintxt += "</TABLE>";
   
   
   wintxt += "<INPUT TYPE=button VALUE='Close' onClick='self.close()' id=button1 name=button1>"
   wintxt += "</FORM></BODY></HTML>"
   dbgWnd.document.write(wintxt)
   dbgWnd.document.close()
   return true
   }      
   
   
   
   
   
   
/////////////////////////////////////////////////////////////////////////////////////
// QueryString Object 
/////////////////////////////////////////////////////////////////////////////////////
// To use the QueryString object you'll need create an instance of this
// object using the following syntax
//
// var oQuery = new QueryString(document)
//
// The constructor takes only one arguement and that is the current pages document object.
// This method gets the query string from the document object and parses it.  It then creates
// a named collection of the query string items.  For example to to find out the value of 
// the name attribute in the following query string:
//    MyPage.htm?Name=Rudy&Title=Engineer
// you would used the following syntax:
//    oQuery["Name"]
//
// This object has two additional property count and value.  Count returns the number of items
// in the collection and value return the query string parameters unparsed (excluding the leading
// question mark).
//////////////////////////////////////////////////////////////////////////////////////
////////
//////
////
//	 
function QueryString(document)
   {
   var _instance = this;
	var szHref = document.location.search
   // First, get a list of all cookies that pertain to this document.
   // We do this by reading the magic Document.cookie property.
   if (szHref == null || szHref == "") 
      {
      _instance.length = 0
      return true;
      }

   //The first character is always a '?' so we need to trim that off   
   szHref =	szHref.substring(1,szHref.length);      
   
   return QueryStringEx(szHref,_instance);
   }
   

function QueryStringEx(szHref)
   {
   var _instance;
   if (QueryStringEx.arguments.length == 2)
      _instance = QueryStringEx.arguments[1];
   else
      _instance = this;
   
   if (szHref == null || szHref == "") 
      {
      _instance.length = 0
      return true;
      }

   var a = szHref.split("&");  // break it into array of name/value pairs
   
   for(var i=0; i < a.length; i++)  // break each pair into an array
      a[i] = a[i].split("=");
       
   // Now that we've parsed the query string value, set all the names and values
   // of the state variables in this QueryString object. Note that we unescape()
   // the property value.
   for(var i = 0; i < a.length; i++)
      {
      _instance[a[i][0]] = decodeURL(a[i][1]);
      }
   
   return QueryBuilder(_instance);
   }
   
function QueryBuilder()
   {
   var _instance;
   if (QueryStringEx.arguments != null)
      _instance = QueryStringEx.arguments[0];
   else
      _instance = this;
      
   _instance.$Target = "";
   _instance.toString = _getQueryString;
   _instance.setTarget = _setTarget;
   _instance = null;
   return true;

   }   
   
function _setTarget(szValue)
   {
   this.$Target = szValue;
   }   
   
   
function _getQueryString()
   {   
   var szQueryString = ""
   
   if (this.$Target.length > 0)
      szQueryString = this.$Target + "?";
      
   for(var prop in this)
      {
      // Ignore properties with names that begin with '$' and also methods.
      if (prop.charAt(0) == "$" || (typeof this[prop]) == "function") 
         continue;
         
      if (szQueryString.charAt(szQueryString.length -1) != "?") 
         szQueryString += "&";
         
      szQueryString += encodeURL(prop) + "=" + encodeURL(this[prop].toString());
      }

   return szQueryString
   }
   
function encodeURL(szValue)
   {
   if (typeof szValue == "undefined")
      return szValue;
      
   szValue = szValue.toString();
   var szRet = encodeURI(szValue);      
   return szRet;
   }
   

   
// This is a helper method used to extract the cookie values that are set by the
// server during an image request.  The cookie contains status information about
// the image.
function CookieExtract(strCookie, strCookieName, strKey)
   {
   // First, get a list of all cookies that pertain to this document.
   // We do this by reading the magic Document.cookie property.
   
   strValue = "";
   
   var allcookies = decodeURL(strCookie);
   if (allcookies == "") 
      return "";
      
   var start = allcookies.indexOf(strCookieName + "=");
   if (start == -1) 
      return "";   // cookie not defined for this page.
      
   // Now extract just the named cookie from that list
      
   start += strCookieName.length + 1;  // skip name and equals sign.
   
   var end = allcookies.indexOf(";", start);
   if (end == -1) 
      end = allcookies.length;
      
   var cookieval = allcookies.substring(start, end);
   
   // Now that we've extracted the value of the named cookie, we've
   // got to break that value down into individual state variable 
   // names and values. The name/value pairs are separated from each
   // other with ampersands, and the individual names and values are
   // separated from each other with colons. We use the split method
   // to parse everything.
   
   var a = cookieval.split("&");  // break it into array of name/value pairs
   
   for (var i=0; i < a.length; i++)  // break each pair into an array
      a[i] = a[i].split("=");
       
   // Now that we've parsed the cookie value, set all the names and values
   // of the state variables in this Cookie object. 
   for (var i = 0; i < a.length; i++)
      {
      if (decodeURL(a[i][0]) == strKey)
         {
         return decodeURL(a[i][1]);
         }
      }
      
   // We're done, so return the success code.
   return "";
   }
   
function decodeURL(szValue)
   {
   if (typeof szValue == "undefined")
      return szValue;
      
   if (szValue == null)
      return "";
      
   //Replace plus signs with ' '.  WHen you store a cookie value on the server side, the 
   //Response object automatically escapes values.  however, it places '+' for ' ' instead
   //of %20.  
   while(szValue.indexOf('+') != -1)
      szValue = szValue.replace('+',' ');  
      
   return decodeURI(szValue);
   } 
   

   



   
   

/////////////////////////////////////////////////////////////////////////////////////
// Miscellaneous Functions
/////////////////////////////////////////////////////////////////////////////////////
////////
//////
////
//



function OnMonitor(oItem)
{
   var oQuery = new QueryBuilder();
   oQuery.setTarget("WmiMonitor.aspx");
   oQuery["DataSource"] = document.forms[0].elements["DataSource"].value;
   oQuery["OType"] = oItem;
   window.open(oQuery.toString(), "Monitor", "width=550,height=475,resizable=yes,scrollbars=yes,status=no,titlebar=no,menubar=no,toolbar=no", true);
}

function OnAdmin()
{
   var oQuery = new QueryBuilder();
   oQuery.setTarget("Admin.aspx");
   oQuery["DataSource"] = document.forms[0].elements["DataSource"].value;
   window.open(oQuery.toString(), "Admin","resizable=yes,scrollbars=yes,status=yes,titlebar=no,menubar=no,toolbar=no", true);
}

//This is an event handler used to open the settings.asp page as a popup.
function OnConfig()
{
   var oQuery = new QueryBuilder();
   oQuery.setTarget("Settings.aspx");
   oQuery["DataSource"] = document.forms[0].elements["DataSource"].value;
   window.open(oQuery.toString(), "Settings", "left=100,top=100,width=785,height=565,resizable=yes,scrollbars=yes,status=no,titlebar=no,menubar=no,toolbar=no", true);
}

function OnBatchListMenu()
{
   var oQuery = new QueryBuilder();
   oQuery.setTarget("BatchList.aspx");
   oQuery["DataSource"] = document.forms[0].elements["DataSource"].value;
   window.open(oQuery.toString(), null,"resizable=yes,toolbar=no,menubar=no,status=yes,scrollbars=yes", true);
}


function OnComponentCheck()
{
   var urlBld = new QueryBuilder();
   urlBld.setTarget("ComponentCheck.aspx");
   window.open(urlBld.toString(), "Check_Installed_Components", "width=550,height=400,resizable=yes,scrollbars=yes,status=no,titlebar=no,menubar=no,toolbar=no", true);
}

function OnHelp()
{
   helpURL = document.forms[0].elements["HelpTopic"].value;
   window.open(helpURL, "WxHelp", "width=750,height=550,resizable=yes,scrollbars=yes,status=no,titlebar=no,menubar=no,toolbar=no", true);
}

function OnAbout()
{
   var urlBld = new QueryBuilder();
   urlBld.setTarget("About.aspx");
   window.open(urlBld.toString(), "About_WebXtender", "width=610, height=540,resizable=yes,scrollbars=yes,status=no,titlebar=no,menubar=no,toolbar=no", true);
}

/////////////////////////////////////////////////////////////////////////////////////
// Context Menu Functions
/////////////////////////////////////////////////////////////////////////////////////
////////
//////
////
//
function CancelContextMenu(event)
{
	var oContextMenu = document.getElementById("oContextMenu");
	if(typeof oContextMenu != "undefined" && oContextMenu != null)
	{
	   if(oContextMenu.getAttribute("status") == "true")
		{
		   // Reset the context menu, release mouse capture, and hide it.	
		   oContextMenu.style.display="none";
		   oContextMenu.setAttribute("status","false");
		   ClearTableRows(oContextMenu);
		   if(event != null)
   		   event.returnValue = false;
		}
   }
   
   CancelWfxContextSubMenu();
   
   if (bSkipCloseFieldIndexPopup == true)
   {
      bSkipCloseFieldIndexPopup = false;
   }
   else
   {
      CloseFieldIndexPopup();
   }
}

function CancelWfxContextSubMenu(event)
{
   var oWfxContextMenu = document.getElementById("oWfxContextMenu");
   if(typeof oWfxContextMenu != "undefined" && oWfxContextMenu != null)
   {
      if(oWfxContextMenu.getAttribute("status") == "true")
      {
         // Reset the context menu, release mouse capture, and hide it.	
         oWfxContextMenu.style.display="none";
         oWfxContextMenu.setAttribute("status","false");
         ClearTableRows(oWfxContextMenu);
         if(event != null)
            event.returnValue = false;
      }
   }
}

function ClearTableRows(oTable)
   {
   if (oTable == null)
      return;
   var rowCount = oTable.rows.length;
   for(i = 0; i < rowCount ; i++)
      oTable.deleteRow(0);
   }   

function DoPopup(event)
   {
   //set to false to indicate that we don't wish to bubble this event to the parent.
	event.returnValue = false;
	if(event.stopPropagation)
	   event.stopPropagation();

   //Kill the browser's default action for this event (displaying its own context menu)
   if (event.preventDefault)
      event.preventDefault();
   
   var oContextMenu = document.getElementById("oContextMenu");
   
   var nBodyHeight = 0;
   var nScrollTop = 0;
   var nScrollLeft = 0;
   var offsetTop = 0;
 
   // Relocate the menu to an offset from the mouse position
   if(typeof oContextMenu.style.pixelTop == "undefined")
      {
      // Netscape 7.0
      nScrollTop = document.body.scrollTop;
      nScrollLeft = document.body.scrollLeft;
      nBodyHeight = document.body.offsetHeight;
      oContextMenu.style.top =  nScrollTop + event.clientY - 5;
      oContextMenu.style.left = nScrollLeft + event.clientX;
      }
   else
      {
      // IE
      var container = document.getElementById("pageLayout_ContentContainer");
      nScrollTop = container.scrollTop;
      nScrollLeft = container.scrollLeft;
      nBodyHeight = container.offsetHeight;
      offsetTop = container.offsetParent.offsetTop;
      
      var elem = event.srcElement;
      oContextMenu.style.pixelTop = getClientTop(elem) + elem.clientHeight - event.offsetY;
      oContextMenu.style.pixelLeft = getClientLeft(elem) + event.offsetX;
      }

   // Make the menu visible.
   oContextMenu.style.display = "block";
	
   // Set its STATUS to true
   oContextMenu.setAttribute("status", "true");
	
	// 
   var nScrollY = (oContextMenu.offsetTop + oContextMenu.offsetHeight) - (nBodyHeight + nScrollTop);
	if(nScrollY > 0)
      window.scrollBy(0, nScrollY);
   }

   
//This is a generic method used by grid controls that are derived from NavBaseGrid.  This method
//is called when the mouse moves over or out of a single row's area within the grid   
function OnMouseHover(oElement,bOverRow,bEnter)
   {
   //_debugInspect(oElement.attributes);
   if (top.IsNav())
      {
      var oAttr = oElement.attributes.getNamedItem("isSelected");
      if (oAttr != null)
         oElement.isSelected = oAttr.nodeValue;
      }
      
   if (bOverRow)
      {
      if (bEnter)
         {
         if (oElement.style.backgroundColor == "#e0e0e0")
            oElement.isSelected = "0";
            
         oElement.style.backgroundColor  = "#ffff99"
         oElement.style.cursor='hand'         
         }
      else
         {
         if (oElement.isSelected == "1")
            oElement.style.backgroundColor = "#6699cc"
         else
            oElement.style.backgroundColor = "#e0e0e0"
         }
      }
   else
      {
      if (bEnter)
         {
         oElement.style.backgroundColor = "#6699cc"
         oElement.style.cursor='hand'         
         }
      else
         {
         if (oElement.innerText != "")
            oElement.style.backgroundColor = "#2e4a79"
         }
      }            
   }            


function OnCheckRow(Evt,oElement)
   {
   if (typeof oElement.style == "undefined" || typeof oElement.style == null)
      return;

   var isChecked = oElement.checked;
        
   if (isChecked == false)
      {
      window.document.forms[0].elements['CheckAll'].checked = false;
      }
   
   Evt.cancelBubble = true;
   }      
   
function GetLocalizedText(stringId)
{
   return window.document.forms[0].elements[stringId].value;
}  


// Helper returns element regardless of browser type.
function getElement(id) 
{
   return document.getElementById ? document.getElementById(id) :document.all ? document.all(id) : null;
}


//
// Calender Support
// ==========================================================================
var bSkipCloseFieldIndexPopup = false;
var currentFieldIndexField = null;
function OnCalender(event, dateControlId, FieldName)
{
   if (CloseFieldIndexPopup())
   {
      bSkipCloseFieldIndexPopup = false;
      return;
   }
   
   currentFieldIndexField = getElement(dateControlId);
   var oQuery = new top.QueryBuilder();
   oQuery.setTarget("CalenderPopup.aspx");
   if (document.forms[0].elements["DataSource"] !=  null)
      oQuery["DataSource"] = document.forms[0].elements["DataSource"].value;
   else
   {
      var queryString = new QueryString(document);
      oQuery["DataSource"] = queryString["DataSource"];
   }
   if (document.forms[0].elements["AppName"] != null)
      oQuery["AppName"] = document.forms[0].elements["AppName"].value;
   else
   {
      if (document.forms[0].elements["AppId"] != null)
         oQuery["AppId"] = document.forms[0].elements["AppId"].value;
   }
   oQuery["FieldName"] = FieldName;
   oQuery["BoundControl"] = dateControlId;
   oQuery["CurrentDate"] = currentFieldIndexField.value;
   //window.open(oQuery.toString(),"Calender","width=212,height=188,resizeable=no,scrollbars=no,titlebar=no,top=300,left=300",true)
   
   var sContents = "<IFRAME SRC='" + oQuery.toString() + "' width=212 height=184  name=calframe id=calframe>";
   var newIframe = document.createElement(sContents);
   
   //set to false to indicate that we don't wish to bubble this event to the parent.
	event.returnValue = false;
	if(event.stopPropagation)
	   event.stopPropagation();

   //Kill the browser's default action for this event (displaying its own context menu)
   if (event.preventDefault)
      event.preventDefault();
      
   var spanElem = getElement("fieldIdxGridPopup");
   
   var elem = event.srcElement;
   currentFieldIndexField.offsetParent.appendChild(spanElem);
   spanElem.style.display = "";
   elem.offsetParent.vAlign = "top";
   currentFieldIndexField.style.pixelWidth = currentFieldIndexField.style.pixelWidth - 205 <= 0 ? 0 : currentFieldIndexField.style.pixelWidth - 205;
   currentFieldIndexField.style.backgroundColor = "LightSteelBlue";
   currentFieldIndexField.style.borderColor = "#dbd7d0";
   spanElem.style.pixelHeight = 184;
   spanElem.appendChild(newIframe);
   
   bSkipCloseFieldIndexPopup = true;
}


function getClientLeft(elem)
{
   var left = elem.offsetLeft;
   while (elem.offsetParent != null)
   {
      elem = elem.offsetParent;
      left = left + elem.offsetLeft + elem.scrollLeft;
   }
   return left;
}

function getClientTop(elem)
{
   var top = elem.offsetTop;
   while (elem.offsetParent != null)
   {
      elem = elem.offsetParent;
      top = top + elem.offsetTop - elem.scrollTop;
   }
   return top;
}

function setFieldDate()
{
   while (document.readyState != "complete")
   {
      setTimeout("setFieldDate()",50);
      return;
   }
   
   var elemId = document.forms[0].elements["BoundControl"].value;
   var fieldValue = document.forms[0].elements["DateString"].value
   while (elemId.indexOf(' ') != -1)
      elemId = elemId.replace(' ','+');
   var elem = window.top.getElement(elemId);
   elem.value = fieldValue;
   
   window.top.CloseFieldIndexPopup();
   bSkipCloseFieldIndexPopup = false;
   return;
}   
   


function CloseFieldIndexPopup()
{
   if (IsExplorer())
   {
      var spanElem = getElement("fieldIdxGridPopup");
      if (spanElem != null)
      {
         if (spanElem.children.length > 0)
         {
            var oCalender = spanElem.children(0);
            spanElem.removeChild(oCalender);
            spanElem.style.display = "none";
            if (currentFieldIndexField != null)
            {
               currentFieldIndexField.style.width = "100%";
               currentFieldIndexField.style.backgroundColor = "";
               currentFieldIndexField.style.borderColor = "";
            }
            return true;
         }
      }
    }
      
    return false;
}



//
// Index Pane Resize Support
// ==========================================================================
var g_beginResizeIndexPane = false;
var g_originalScreenX = 0;
var g_orginalWidth;
var g_oIndexPane = null;



function bodyMouseUp()
{
   if (g_beginResizeIndexPane)
   {
      g_beginResizeIndexPane = false
      window.document.releaseCapture();
      
      
   }
}



function SetMenuItemOverStyle()
{
   this.className = 'ContextMenuItemOver';
}

function SetMenuItemOutStyle()
{
   this.className = 'ContextMenuItem';
}	


function NavigateTo(url)
{
   window.location.replace(url);
}

function ___doPostBack(eventTarget,eventArgument)
{
   document.forms[0].onsubmit();
   __doPostBack(eventTarget, eventArgument) 
}

function DownloadFile(filePath)
{
   window.open(filePath,null,"width=1,height=1,resizable=yes,toolbar=no,menubar=no,status=no,top=0,left=0",true);
}


///////////////////////////////////////////////////////////////////////////////////
// INDEX PANE RESIZE LOGIC
///////////////////////////////////////////////////////////////////////////////////


var theobject = null; //This gets a value as soon as a resize start

function resizeObject() {
	this.el        = null; //pointer to the object
	this.dir    = "";      //type of current resize (n, s, e, w, ne, nw, se, sw)
	this.grabx = null;     //Some useful values
	this.graby = null;
	this.width = null;
	this.height = null;
	this.left = null;
	this.top = null;
}

function gripMouseDown()
{
   doDown();
}

//Find out what kind of resize! Return a string inlcluding the directions
function getDirection(el) 
{
	var xPos, yPos, offset, dir;
	dir = "";

	xPos = window.event.offsetX;
	yPos = window.event.offsetY;

	
	offset = 8; //The distance from the edge in pixels

	if (yPos<offset) dir += "n";
	else if (yPos > el.offsetHeight-offset) dir += "s";
	if (xPos<offset) dir += "e";
	else if (xPos > el.offsetWidth-offset) dir += "w";

	return dir;
}

function doDown() 
{
	var el = document.getElementById("PageLayout_IndexPanel");

	if (el == null) 
	{
		theobject = null;
		return;
	}		

	dir = getDirection(el);
	if (dir == "") return;

	theobject = new resizeObject();
		
	theobject.el = el;
	theobject.dir = dir;

	theobject.grabx = window.event.clientX;
	theobject.graby = window.event.clientY;
	theobject.width = el.offsetWidth;
	theobject.height = el.offsetHeight;
	theobject.left = el.offsetLeft;
	theobject.top = el.offsetTop;

	window.event.returnValue = false;
	window.event.cancelBubble = true;
}

function doUp() 
{
	if (theobject != null) 
	{
		//Post back to the server so that we can save the new width within the
      //user profile.
      hiddenField = document.getElementById("IndexPaneWidth"); 
      hiddenField.value = theobject.el.style.pixelWidth;
      document.body.style.cursor = "";
      document.forms[0].submit();
      
      theobject = null;
	}
}

function doMove() {
	var xMin, yMin;
	xMin = 8; //The smallest width possible
	yMin = 8; //             height

	
	
//Dragging starts here
	if(theobject != null) 
	{
		if (dir.indexOf("e") != -1)
			theobject.el.style.width = Math.max(xMin, theobject.width + window.event.clientX - theobject.grabx);
	
		if (dir.indexOf("s") != -1)
			theobject.el.style.height = Math.max(yMin, theobject.height + window.event.clientY - theobject.graby);		

		if (dir.indexOf("w") != -1) 
		{
			theobject.el.style.left = Math.min(theobject.left + window.event.clientX - theobject.grabx, theobject.left + theobject.width - xMin);
			theobject.el.style.width = Math.max(xMin, theobject.width - window.event.clientX + theobject.grabx);
		}
		if (dir.indexOf("n") != -1) 
		{
			theobject.el.style.top = Math.min(theobject.top + window.event.clientY - theobject.graby, theobject.top + theobject.height - yMin);
			theobject.el.style.height = Math.max(yMin, theobject.height - window.event.clientY + theobject.graby);
		}
		
		window.event.returnValue = false;
		window.event.cancelBubble = true;
	} 
}


function getReal(el, type, value) 
{
	temp = el;
	while ((temp != null) && (temp.tagName != "BODY")) {
		if (eval("temp." + type) == value) {
			el = temp;
			return el;
		}
		temp = temp.parentElement;
	}
	return el;
}

document.onmouseup   = doUp;
document.onmousemove = doMove;

// Bring the window to foreground
window.focus();

   
   
