﻿
// Aligns a flyout popup to align with the top (x,y) coordinate as the control that is passed in
function AlignFlyout(strControlID, strFlyoutID)//, yOffset) 
{
  //alert(strControlID);
  var ctl = $get(strControlID);
  //alert(ctl);
  if( ctl )
  {    
    //alert('found control');      
    var ctlLocation = Sys.UI.DomElement.getLocation(ctl);
    var flyout = $get(strFlyoutID);
    
    if( flyout )
    {      
      //alert( 'flyout.id=' + flyout.id + ' | ctlLocation.y=' + ctlLocation.y + ' | ctlLocation.x=' + ctlLocation.x );
      flyout.style.position = 'absolute';
      //var y = ctlLocation.y;
      //y = y + yOffset;      
      //alert('y=' + y + ' | yOffset=' + yOffset + 'typeof y = ' + typeof(y) + ' | typeof yOffset = ' + typeof(yOffset) );
      //var totalYOffet =  y + yOffset;   
      //alert(totalYOffset);   
      //alert( 'totalYOffset=' + totalYOffset );
      //flyout.style.top = y + 'px';
      flyout.style.top = ctlLocation.y + 'px';
      flyout.style.left = ctlLocation.x + 'px';
      
    }
  }    
}

// Aligns a flyout popup to align with the top coordinate as the control that is passed in
// and aligns the right hand side of the controls. Use this function for flyouts that
// are from the right hand side of the screen.
function AlignFlyoutRight(strControlID, strFlyoutID)//, yOffset) 
{
  //alert(strControlID);
  var ctl = $get(strControlID);
  if( ctl )
  {    
    //alert('found control');      
    var ctlLocation = Sys.UI.DomElement.getLocation(ctl);
    var flyout = $get(strFlyoutID);
    
    if( flyout )
    {      
      //alert( 'flyout.id=' + flyout.id + ' | ctlLocation.y=' + ctlLocation.y + ' | ctlLocation.x=' + ctlLocation.x );
      flyout.style.position = 'absolute';
      //var y = ctlLocation.y;
      //y = y + yOffset;      
      //alert('y=' + y + ' | yOffset=' + yOffset + 'typeof y = ' + typeof(y) + ' | typeof yOffset = ' + typeof(yOffset) );
      //var totalYOffet =  y + yOffset;   
      //alert(totalYOffset);   
      //alert( 'totalYOffset=' + totalYOffset );
      //flyout.style.top = y + 'px';
      var x = ctlLocation.x - flyout.clientWidth;
      //alert( 'x=' + x + ' | ctlLocation.x = ' + ctlLocation.x + ' | flyout.clientWidth=' + flyout.offsetWidth );
      flyout.style.top = ctlLocation.y + 'px';
      //flyout.style.left = ctlLocation.x + 'px';
      flyout.style.left = x + 'px';
    }
  }    
}

function RadCombo(combo)
{	
	this.LoadCombo = function(item) 
	{
		if(combo) 
		{
			combo.ClearSelection();
			combo.SetText("Loading...");
			if (item.Index > 0)
			{        
					combo.RequestItems(item.Value, false);                                
			}
		}
	}
	
	this.ItemsLoaded = function(comboLoaded)
	{
		if(comboLoaded)
		{
			if (comboLoaded.Items.length > 0)
			{
					comboLoaded.SetText(comboLoaded.Items[0].Text);
			}
			comboLoaded.ShowDropDown();
		}
	}
}

function OpenContactSearchWindow(windowID)
{
	alert ('calling OpenContactSearchWindow');
	//var oWnd = radopen (null, "<%= SearchContactDialog.ClientID %>");
	var oWnd = $find(windowID);   
	if(oWnd)
	{
		oWnd.show();
	}
	else
	{
		alert('oWnd is null for ID: ' + windowID);
	}
}

function EscrowSearchContactCallback(radWindow, returnValue)
{
	//var ajaxManager = $find('RadAjaxManager1');
	alert(ajaxManager.toString());
	var ajaxRequestActionType = '101';
	
	var returnValueWithClientID = ajaxRequestActionType + '|' + returnValue;
	
	// this initiates an asynchronous call to the server to populate the contact data
	ajaxManager.ajaxRequest(returnValueWithClientID);
}

function OpenSearchWindow(id)
{
	//alert ('calling OpenSearchWindow for ' + id);
	var oWnd = $find(id);   
	oWnd.show();
}

// this function is called by the contact search dialog window
// returnValue contains the personID for the person that was selected
function SearchContactCallback(ajaxManagerClientID, ajaxRequestActionType, controlClientID, radWindow, returnValue)
{
	alert('SearchContactCallback called');
	var ajaxManager = $find(ajaxManagerClientID);
	
	var returnValueWithClientID = ajaxRequestActionType + '|' + controlClientID + '|' + returnValue;
	
	// this initiates an asynchronous call to the server to populate the contact data
	ajaxManager.ajaxRequest(returnValueWithClientID);
}