// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// api_Common.js
//
// These are CLIENTSIDE JavaScript functions that help us on a "common" basis. For example
// opening new windows, setting focus to windows, cookie stuff...
//
// sections : 
//   SECTION I   = Window Functions
//   SECTION II  = Date / Time Functions
//   SECTION III = Cookie
//   SECTION IV  = Misc Functions
//
// created  : 02.14.00
// updated  : 02.14.00
//
// notes    : 2/14/00 JMB - Today i started the commenting standard...
//            2/14/00 JMB - Split the file up into III sections...
//            7/12/00 JMB - Added Misc Functions
//
//
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++






//
//
// SECTION I 
//
//
// //////////////////////////////////////////////////////////////////////////////////////////////
//
// Window Functions
//
// These functions operate, and manipulate popup windows or any browser window you specify..
//
//
//
// //////////////////////////////////////////////////////////////////////////////////////////////


// JS PROPERTY ***********************************************************************************
//
// window.focus()
//
// This IF-BLOCK takes care of focusing the Popup windows. if there is an opener (parent), then
// set the focus()....
//
// input  : none
//
// output : none
//
// **********************************************************************************************
if(window.opener)
{
 window.focus();
}


// JS PROPERTY ***********************************************************************************
//
// onunload=??
//
// This will set the onunload to call refresh list. common on popups that maintain lists below..
//
// input  : none
//
// output : none
//
// **********************************************************************************************
//if(opener){ if(opener.RefreshList){ window.onunload = window.opener.RefreshList; }}

//
// Written from MIBOR, used in new site
//
function InfopopUp(URL) 
{
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=300,height=300,left = 650,top = 450');");
}



// FUNCTION *************************************************************************************
//
// PopupWindow
//
// This function pops-up a window of size w and h...
//
// input  : url [string], width [number], height [number], windowName [string], 
//          allowScrolling [boolean]
//
// output : funcWindow [object]
//
// **********************************************************************************************
function PopupWindow(page, width, height, windowName, allowScrolling, useModal) 
{ 
 scrollFlag     = (allowScrolling) ? "yes" : "no";
 openParameters = "width="+width+",height="+height+",resizable=yes,scrollbars="+scrollFlag+",menubars=no,toolbar=yes,directories=no";

 funcWindow = window.open(page, windowName, openParameters);

 return funcWindow;
} 



// FUNCTION *************************************************************************************
//
// Redirect
//
// This function redirects to a url specified using the location.href object...
//
// input  : URL [string]
//
// output : none
//
// **********************************************************************************************
function Redirect(URL)
{ 
 if(URL != "")
 {
   window.location.href=URL;
 }
}



//
//
// SECTION III
//
//
// //////////////////////////////////////////////////////////////////////////////////////////////
//
// Cookie Functions
//
// These functions get and/or set cookies
//
//
//
// //////////////////////////////////////////////////////////////////////////////////////////////


// FUNCTION *************************************************************************************
//
// GetCookie
//
// This function gets the cookie value of cookieName
//
// input  : cookieName [string]
//
// output : cookieValue [string]
//
// **********************************************************************************************
function GetCookie(cookieName) 
{
   search = cookieName + "="
   if (document.cookie.length > 0)
   {
    offset = document.cookie.indexOf(search) 
    if (offset != -1)
    {
      offset += search.length;
      end = document.cookie.indexOf(";", offset);

      if (end == -1) { end = document.cookie.length; }

      cookieValue = unescape(document.cookie.substring(offset, end))

      return cookieValue
    } 
    else { return ""; }
   }
}



// FUNCTION *************************************************************************************
//
// SetCookie
//
// This function sets a cooke of cookieName with cookieValue for cookieLife
//
// input  : cookieName [string], cookieValue [string], cookieLife [date obj]
//
// output : none
//
// **********************************************************************************************
function setCookie(cookieName, cookieValue, cookieLife)
{
   expirationDate = new Date();

   if(cookieLife == null || cookieLife != -1)
   {
    cookieLife = 365*86400000;
    expirationDate.setTime(expirationDate.getTime() + cookieLife);
    document.cookie = escape(cookieName) + "=" + escape(cookieValue) + ";expires=" + expirationDate.toGMTString() + ";path=/";
   }
   else
   {
    document.cookie = escape(cookieName) + "=" + escape(cookieValue) + ";path=/";
   }
} 





//
//
// SECTION IV
// ----------
//
//
// //////////////////////////////////////////////////////////////////////////////////////////////
//
// Misc Functions
// 
// This section holds all general things...
// 
// //////////////////////////////////////////////////////////////////////////////////////////////

// FUNCTION ************************************************************************************
//
// FormatMoney
//
// This function take a FLOAT and format it into money with commas and optional "$"
//
// Input  : number [integer], showDollarSign [string, optional]
//
// Output : money [string]
//
// *********************************************************************************************
 function FormatMoney(num,wantDollarSign)
 {
   tensCount = 1;
   money     = "";
   num       = (num+"").replace(/\$|\,/g,"");
   numArr    = num.split(".");

   // dollars
   if(numArr[0].length > 3){
    for(x=numArr[0].length-1;x>=0;x--)
    {
      if(tensCount == 3 && x != 0){ comma = ","; tensCount = 0;} else { comma = ""; }
      money = comma + numArr[0].substr(x,1) + money;
  	  tensCount++;
    }
   }
   else { money=numArr[0]; }

   // cents
   if(numArr[1]){money += "." + numArr[1].substr(0,2); }
  
   // dollar sign?
   if(wantDollarSign) { money = "$"+money; }
  
   return money;
 }

// -- IE ONLY
// onkeypress, returns the item if it is a digit! :)
//
function IsDigit()
{ 
  return ( (event.keyCode >= 48) && (event.keyCode <= 57) || (event.keyCode ==46)); 
}
