﻿/// <summary>
/// This is a support function that provides client and server side validation for the DateControl.ascx
/// </summary>
function createDate(monthId, dayId, yearId, txtId, dateOrder)
{
  if( document.getElementById )
  {
    var txt = document.getElementById(txtId);
    if( !txt )
    {
      return;
    }
    
    try
    {
      var month = document.getElementById(monthId);
      var day   = document.getElementById(dayId);
      var year  = document.getElementById(yearId);
      var dateOrder = new String(dateOrder).toLowerCase();
      if( dateOrder.indexOf('m') < dateOrder.indexOf('d') )
      {
        txt.value = month.value + '/' + day.value + '/' + year.value;
      }
      else
      {
        txt.value = day.value + '/' + month.value + '/' + year.value;
      }
    } 
    catch(e) 
    { 
      if( txt )
      {
        txt.value = '';
      }
    }
  }
}

/// <summary>
/// Attempts to resize the current window using the values provided
/// </summary>
function resizeWindow(iWidth, iHeight) 
{
	if (isNaN(iWidth) || (20 >= iWidth) || isNaN(iHeight) || (20 >= iHeight)) return;

	window.resizeTo(iWidth, iHeight);	// IE outerWidth & outerHeight set... NS innerWidth & innerHeight set
	window.outerWidth  = iWidth;		  // IE ignores this... NS outerWidth set
	window.outerHeight = iHeight;		  // IE ignores this... NS outerHeight set
}

/// <summary>
/// Attempts to close the current window
/// </summary>
function closeWindow()
{
  window.opener = window.self;
  window.close();
}

/// <summary>
/// Shows the print dialog for the current window
/// </summary>
function printWindow()
{
  window.print();
}

/// <summary>
/// Selects the single qualifier for all the qualifiers on the multi-add page
/// </summary>
function selectQualifiers( name, count )
{
  var ddlApplyToAll = document.getElementById(name)
  for(i = 0; i < count; i++) 
  {
    var ddl = document.getElementById(name + i)
    if ( ddl )
    {
      ddl.value = ddlApplyToAll.value
    }
  }
}	

function resizeWindowToElement(sElementId, bSecondResize)
{
  var dx, dy, el;
  var wWidth, wHeight;
  
  el = document.getElementById(sElementId);
  
  if( el )
  {
    if( typeof( window.innerWidth ) == 'number' ) 
    {
      //Non-IE
      wWidth = window.innerWidth;
      wHeight = window.innerHeight;
    } 
    else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
    {
      //IE 6+ in 'standards compliant mode'
      wWidth = document.documentElement.clientWidth;
      wHeight = document.documentElement.clientHeight;
    } 
    else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
    {
      //IE 4 compatible
      wWidth = document.body.clientWidth;
      wHeight = document.body.clientHeight;
    }
    
    dx = el.offsetWidth - wWidth;
    dy = el.offsetHeight - wHeight;
    
    window.resizeBy(dx, dy);
    
    // Resizing the window can cause menu bars to re-arrange themselves and block content.
    // Resize again to accomodate this
    if( !bSecondResize )
    {
      resizeWindowToElement(sElementId, true);
    }
  }
}


