
function F_LoadImages()
/*-------------------------------------------------------------------------*/
/* Pre-Load Images for better client side performance                      */
/*-------------------------------------------------------------------------*/
{
  var doc  = document;
  var args = arguments;

  if(!doc.Loadimgs) doc.Loadimgs = new Array();

  for (var i = 0; i < args.length; i++)
  {
    doc.Loadimgs[i]     = new Image;
    doc.Loadimgs[i].src = args[i];  
  }
}

function F_Resize(obj, width, height)
/*-------------------------------------------------------------------------*/
/* Copy Value from one controll to another                                 */
/*-------------------------------------------------------------------------*/
{
	if (document.getElementById(obj) != null)
	{ 
       width  = screen.availWidth  - width;
       height = screen.availHeight - height;
       eval(obj + '.resizeTo(' + width + ',' + height + ')');
    }
}

function F_ResizeFixedX(obj, width, height)
/*-------------------------------------------------------------------------*/
/* Copy Value from one controll to another                                 */
/*-------------------------------------------------------------------------*/
{
	if (document.getElementById(obj) != null)
	{ 
       height = screen.availHeight - height;
       eval(obj + '.resizeTo(' + width + ',' + height + ')');
    }
}

function F_MaximizePage()
/*-------------------------------------------------------------------------*/
/* Maximize the browser page                                               */
/*-------------------------------------------------------------------------*/
{
	moveTo(-4,-4);
	window.resizeTo(screen.availWidth+8,screen.availHeight+8);
}

function F_SetFocus(obj)
/*-------------------------------------------------------------------------*/
/* Set FOCUS to control                                                    */
/*-------------------------------------------------------------------------*/
{
	if (document.getElementById(obj) != null) 
	{ 
	  if (document.getElementById(obj).disabled == false) 
	  { document.getElementById(obj).focus(); }
	}
}

function F_SubmitOnEnter(FormName)
/*-------------------------------------------------------------------------*/
/* Set the focus the field specified in 'nextfield'                        */
/*-------------------------------------------------------------------------*/
{
  syskey = window.event.keyCode;
  if (syskey == 13)
  {
  	eval("document." + FormName + ".submit()"); 
  }
}

function F_PostBackonEnter(ControlName)
/*-------------------------------------------------------------------------*/
/* Set the focus the field specified in 'nextfield'                        */
/*-------------------------------------------------------------------------*/
{
  syskey = window.event.keyCode;
  if (syskey == 13)
  {
  	__doPostBack(ControlName,''); 
  }
}

function F_Highlight(Ctrl, BackgroundColor, TextColor)
/*-------------------------------------------------------------------------*/
/* Highlight menu options                                                  */
/*-------------------------------------------------------------------------*/
{
  Ctrl.style.color           = TextColor;
  Ctrl.style.backgroundColor = BackgroundColor;
}

function Blue(ctrl)
/*-------------------------------------------------------------------------*/
/* Set control to blue background, blue text                               */
/*-------------------------------------------------------------------------*/
{
	ctrl.style.backgroundColor	= "#aaaafd";
	ctrl.style.color			= "#0a0a6c";
}

function White(ctrl)
/*-------------------------------------------------------------------------*/
/* Set control to white background, black text                             */
/*-------------------------------------------------------------------------*/
{
	ctrl.style.backgroundColor	= "#FFFFFF";
	ctrl.style.color			= "#000000";
}

function Normal(ctrl)
/*-------------------------------------------------------------------------*/
/* Set control to transparent background, black text                       */
/*-------------------------------------------------------------------------*/
{
	ctrl.style.backgroundColor	= "Transparent";
	ctrl.style.color			= "#0a0a6c";
}

function F_LoadFrame(PageToLoad, width, height)
/*-------------------------------------------------------------------------*/
/* Page to load in frame                                                   */
/*-------------------------------------------------------------------------*/
{
	eval("parent.frmBody.location='" + PageToLoad + "'");

    if ((width != 0) && (height != 0))
	{
       width  = screen.availWidth  - width;
       height = screen.availHeight - height;
	   eval('parent.frmBody.resizeTo(' + width + ',' + height + ')');
	}
	eval("parent.frmBody.focus()");
}

function F_OpenWin(sUrl)
/*-------------------------------------------------------------------------*/
/* Open new WINDOW with URL                                                */
/*-------------------------------------------------------------------------*/
{
   var newWin = window.open(sUrl);
   newWin.focus();
}

function F_LoadPageFromPage(PageToLoad)
/*-------------------------------------------------------------------------*/
/* Page to load in frame                                                   */
/*-------------------------------------------------------------------------*/
{
	eval("parent.frmBody.location='" + PageToLoad + "'");
	eval("parent.frmBody.focus()");
}

function F_LoadPageToMainBody(PageToLoad)
/*-------------------------------------------------------------------------*/
/* Page to load in frame                                                   */
/*-------------------------------------------------------------------------*/
{
	eval("parent.MainBody.location='" + PageToLoad + "'");
	eval("parent.MainBody.focus()");
}

function F_LoadForm(NewForm)
/*-------------------------------------------------------------------------*/
/* Page to load in frame                                                   */
/*-------------------------------------------------------------------------*/
{
	var win = eval("parent.document")
	win.location = NewForm;
}


function PostToForm(FormName, FormAction)
/*-------------------------------------------------------------------------*/
/* Do postback to specified form                                           */
/*-------------------------------------------------------------------------*/
{
	FormName.__ACTION.value	= FormAction
	FormName.submit();
}

function HiddenVar(FormName, FormVar, VarValue)
/*-------------------------------------------------------------------------*/
/* Do postback to specified form                                           */
/*-------------------------------------------------------------------------*/
{
	eval(FormName + '.' + FormVar + '.value = "' + VarValue + '"');
}

function initNumeric(oTextBox)
/*-------------------------------------------------------------------------*/
/*                                                                         */
/*-------------------------------------------------------------------------*/
{
	if (oTextBox.value * 1 == 0)
	{
		oTextBox.value = "";
	}
}

function F_Round(dValue, Dec)
/*-------------------------------------------------------------------------*/
/* Function that rounds a value to 2 decimal places                        */
/*-------------------------------------------------------------------------*/
{ 
	var factor	= 1;
	var i		= 0;
	
	for (i = 1; i < Dec; i++ ) {	factor = factor * 10; }

	dValue = Math.round(dValue * Math.pow(10,Dec)) / Math.pow(10,Dec);
	var iRemainder = dValue - Math.floor(dValue);

	/* FORMAT decimals */
	if (iRemainder == 0) { dValue = dValue + '.0'; }
	
	var ValueArr = (dValue + '').split('.');

	for(i = 0; i < (Dec - (ValueArr[1]).length); i++)
    {	dValue = dValue + '0'; }

	return dValue;
}

function F_FormatMoney(dValue)
/*-------------------------------------------------------------------------*/
/* Function to FORMAT to 2 decimals                                        */
/*-------------------------------------------------------------------------*/
{
  if (dValue > 0)
  {
     var iRemainder = dValue - Math.floor(dValue);

     /* FORMAT decimals */
     if (iRemainder == 0)
     {  dValue = dValue + '.00'; }
     else
     { iRemainder = (dValue  * 10) - Math.floor(dValue * 10);
       if (iRemainder == 0)
       { dValue = dValue + '0'; }
     }
     return dValue;
  }
  else
  {  return "0.00";  }
}

function isInteger(oTextBox, defaultValue)
/*-------------------------------------------------------------------------*/
/* Test if Value of object is an integer                                   */
/*-------------------------------------------------------------------------*/
{
  var sValue        = oTextBox.value;
  var sAllowedChars = '0123456789';
  var sReturnValue  = '';

  for (var i = 0; i < sValue.length; i++ )
    {
      if (sAllowedChars.indexOf(sValue.charAt(i)) >= 0)
       {
         sReturnValue = sReturnValue + sValue.charAt(i);
       }
    }
   if ((sReturnValue * 1) == 0)
	{ oTextBox.value = defaultValue; }
   else
    { oTextBox.value = sReturnValue * 1; }
}

function isDecimal(oTextBox, defaultValue, doRounding, DecimalPlaces)
/*-------------------------------------------------------------------------*/
/* Validate whether the Value of object is of type decimal                 */
/*-------------------------------------------------------------------------*/
{
	var sValue        = oTextBox.value;
	var sAllowedChars = '.0123456789';
	var sReturnValue  = '';
	var lFoundDot     = 0;

	for (var i = 0; i < sValue.length; i++ )
	{
		if (sAllowedChars.indexOf(sValue.charAt(i)) >= 0)
		{
			if (sValue.charAt(i) != '.')
			{	sReturnValue = sReturnValue + sValue.charAt(i); }
			else
			{
				if ((sValue.charAt(i) == '.') && (i > 0) && (lFoundDot < 1))
				{
					sReturnValue = sReturnValue + sValue.charAt(i);
					lFoundDot = lFoundDot + 1;
				}
			}
		}
	}

	if ((sReturnValue * 1) == 0)
	{ oTextBox.value = defaultValue; }
	else
	{ 
		if (doRounding == 1)
		{ oTextBox.value = F_Round(sReturnValue, DecimalPlaces); }
		else
		{ oTextBox.value = sReturnValue; }
	}
}

