// VARIABLES USED TO FORMAT THE DATE FOR DISPLAY ON THE TABS
today = new Date();
dotw = today.getDay();
month = today.getMonth();
date = today.getDate();
year = today.getYear();
    

/*
Variables to hold the domain prefix for each of the action domains. Allows the web-tier to 
idenfity the handler for an action even if it is references across multiple roles.
*/
var ADMIN_DOMAIN_PREFIX         = "ba_";
var OPERATOR_DOMAIN_PREFIX      = "bo_";
var VENDOR_DOMAIN_PREFIX        = "bv_";
var LIST_MGT_DOMAIN_PREFIX  	= "bl_";
var INVENTORY_DOMAIN_PREFIX 	= "bi_";
var REPORTS_DOMAIN_PREFIX      	= "br_";
var TIBERADMIN_DOMAIN_PREFIX	= "ta_";
var IQ_DOMAIN_PREFIX		= "iq_";

var BUYERORG      = "tibersoft";

corner_line = new Array;
DistributorButtonWidth = 220;

//------------------------------ VENDOR TABS -----------------------------------
function VendorOrdersConfirm() {
  setLocationHref(VENDOR_DOMAIN_PREFIX, "confirmorder");
}

//------------------------------ OPERATOR TABS ---------------------------------
function OptionsPage()
{
 return setLocationHref(OPERATOR_DOMAIN_PREFIX, "sellerlist");
}
function FeedbackPage()
{
 return setLocationHref(OPERATOR_DOMAIN_PREFIX, "feedback");
}
function Help()
{
  try{
    {
        var pagename=document.pagenameform.PAGENAME.value
         //alert(pagename);
        var nw = window.open("",null,"width=800,height=600,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no, resizable=yes");
        nwd = nw.document
        nwd.writeln("<HTML><BODY>")
        nwd.writeln('<FORM action="BuyerHelp" name="submitForm" METHOD="POST">')
        nwd.writeln('<INPUT TYPE=hidden name=PAGENAME Value="'+ pagename +'">')
        nwd.writeln('</FORM>')
        nwd.writeln("</BODY></HTML>")
        nwd.close();
        nw.submitForm.submit();
    }
  } catch (Exception) {
    alert("No help available for this page");
  }
}   
function Logout()
{
  setLocationHref(OPERATOR_DOMAIN_PREFIX, "logout");
}   
function BuyerOrdersReceive()
{
  setLocationHref(OPERATOR_DOMAIN_PREFIX, "receiveheader");
}
function BuyerOrdersTrack()
{
  setLocationHref(OPERATOR_DOMAIN_PREFIX, "orderheader");
}
function BuyerOrdersCreate()
{
  setLocationHref(OPERATOR_DOMAIN_PREFIX, "mvd");
}   
function BuyerOrderGuidesDownload()
{
  setLocationHref(OPERATOR_DOMAIN_PREFIX, "listorderguidestodownload");
}   
function InvoicesPage() 
{
  setLocationHref(OPERATOR_DOMAIN_PREFIX, "invoicesreceiptsheader");
}
function BuyerInvoicesReconcile()
{
  setLocationHref(OPERATOR_DOMAIN_PREFIX, "invoicesreceiptsheader");    
}
function BuyerInvoicesList()
{

}
function InvoicePay()
{
  setLocationHref(OPERATOR_DOMAIN_PREFIX, "buyerinvoicespay");   
}

function OrderUpload() {
  setLocationHref(OPERATOR_DOMAIN_PREFIX, "orderuploadmain"); 
}

//---------------------- List Management -----------------------------------
// Main tab
function BuyerListMgtPage()
{
DisableMenuLinks();
    // Each home event requires a type to determine which multi-vendor lists  to load
    if (AttemptToCallHandlePageExit() == true) 
    {
          top.location.href = "dir?action=" + LIST_MGT_DOMAIN_PREFIX + "inventoryhome" + "&list_type=3" +"&BUYERORG=" + BUYERORG;
    }
}

// Sub tabs
function BuyerListMgtAccountingListPage()
{
    // Each home event requires a type to determine which multi-vendor lists  to load
    if (AttemptToCallHandlePageExit() == true) 
    {
        location.href = "dir?action=" + LIST_MGT_DOMAIN_PREFIX + "inventoryhome" + "&list_type=4" +"&BUYERORG=" + BUYERORG;
    }
}
function BuyerListMgtOrderListPage()
{
  setLocationHref(LIST_MGT_DOMAIN_PREFIX, "home");
}

function InventorySetupPage()
{
  setLocationHref(LIST_MGT_DOMAIN_PREFIX, "inventorysetup");
}



//----------------------- Inventory Management ----------------------------
function BuyerInventoryMgtPage()
{
	DisableMenuLinks();
  setLocationHref(LIST_MGT_DOMAIN_PREFIX, "inventorymgthome");
}
// Sub tabs
function BuyerInventoryCountPage()
{
  setLocationHref(LIST_MGT_DOMAIN_PREFIX, "inventorycount");
}
function BuyerInventoryValuationPage()
{
  setLocationHref(LIST_MGT_DOMAIN_PREFIX, "invntvaluation");
}
function BuyerInventorySuggestOrderPage()
{
  setLocationHref(LIST_MGT_DOMAIN_PREFIX, "inventorysuggestorderhome");
}



//------------------------------ REPORTING TABS ---------------------------------
function ReportsPage()
{
  setLocationHref(REPORTS_DOMAIN_PREFIX, "purchasingreportshome");
}
// Sub tabs
function PurchasingReportsPage()
{
  setLocationHref(REPORTS_DOMAIN_PREFIX, "purchasingreportshome");
}

function BuyerAdminSystemStatistics()
{
   setLocationHref(REPORTS_DOMAIN_PREFIX, "adminsystemstatistics");
}

//------------------------------ ADMIN TABS ---------------------------------
function BuyerAdminCorporateMessages() 
{ 
 //alert("Feature disabled");
  setLocationHref(ADMIN_DOMAIN_PREFIX, "corporatemessages"); 
} 
function BuyerAdminCorporateMessagesSave() 
{ 
 alert("calling the save methods.");
//  setLocationHref(ADMIN_DOMAIN_PREFIX, "corporatemessages"); 
} 
function BuyerAdminProductCatalog() 
{ 
  setLocationHref(ADMIN_DOMAIN_PREFIX, "catalogpageload"); 
} 
function BuyerAdminProductPriceMaintenance() 
{ 
  setLocationHref(ADMIN_DOMAIN_PREFIX, "catalogpricingpageload"); 
}
function BuyerAdminCatalogUpload() 
{ 
  setLocationHref(ADMIN_DOMAIN_PREFIX, "cataloguploadmain"); 
} 
function BuyerAdminCatalogUploadExc() 
{ 
  setLocationHref(ADMIN_DOMAIN_PREFIX, "cataloguploadexceptionmain"); 
} 
function BuyerAdminDepartments() 
{
  setLocationHref(ADMIN_DOMAIN_PREFIX, "buyerdeptcreate");
}
function AdminSellers()
{
  setLocationHref(ADMIN_DOMAIN_PREFIX, "buyeradminsellers");
}
function BuyerGroupsCreate()
{
  setLocationHref(ADMIN_DOMAIN_PREFIX, "buyergroupscreate");
}
function BuyerAdminSettings()
{
  setLocationHref(ADMIN_DOMAIN_PREFIX, "buyerterritorycreate");
}
function BuyerAdminTerritories()
{
  setLocationHref(ADMIN_DOMAIN_PREFIX, "buyerterritorycreate");
}
function BuyerAdminReasonCodes()
{
  setLocationHref(ADMIN_DOMAIN_PREFIX, "reasoncodescreate");
}
function BuyerAdminRegions()
{
  setLocationHref(ADMIN_DOMAIN_PREFIX, "buyerregionscreate");
}
function BuyerAdminAccountManagers()
{
  setLocationHref(ADMIN_DOMAIN_PREFIX, "buyeraccountmanagerscreate");
}
function BuyerAdminTCEVendors()
{
  setLocationHref(ADMIN_DOMAIN_PREFIX, "tcevendorauthorization");
}
function BuyerAdminCatalogAudit()
{
  setLocationHref(ADMIN_DOMAIN_PREFIX, "catalogauditmain");
}
function BuyerAdminContractApproval()
{
   setLocationHref(ADMIN_DOMAIN_PREFIX, "contractapproval_main");
}
function BuyerAdminContractReview()
{
   setLocationHref(ADMIN_DOMAIN_PREFIX, "contractreview_main");
}
function BuyerAdminInvoiceDownload()
{
   setLocationHref(ADMIN_DOMAIN_PREFIX, "admininvoicedownload_main");
}
function BuyerAdminEmail()
{
   setLocationHref(ADMIN_DOMAIN_PREFIX, "buyeradminemailcreate");
}

//  BuyerAdminDoneAssignVendors function is added for Bug17288

function BuyerAdminDoneAssignVendors()
{
  setLocationHref(ADMIN_DOMAIN_PREFIX, "admindoneassignvendors");
}

//------------------------------ TIBERADMIN TABS ---------------------------------
function BuyerTiberAdminEnterpriseManage() 
{ 
  setLocationHref(TIBERADMIN_DOMAIN_PREFIX, "buyertiberadmin_get_enterprises"); 
}
function BuyerTiberAdminVendors() 
{ 
  setLocationHref(TIBERADMIN_DOMAIN_PREFIX, "buyertiberadmin_get_vendors"); 
}
function BuyerTiberAdminEnableVendors() 
{ 
  setLocationHref(TIBERADMIN_DOMAIN_PREFIX, "buyertiberadmin_enable_vendors"); 
}



//------------------------------ IQ TABS ---------------------------------
function BuyerIQAdminEnterpriseManage() 
{ 
  setLocationHref(IQ_DOMAIN_PREFIX, "iq_load_enterprises"); 
}
function BuyerIQAdminDistributorManage() 
{ 
  setLocationHref(IQ_DOMAIN_PREFIX, "iq_distributor_home"); 
}
function BuyerIQAdminDistCenterManage() 
{ 
  setLocationHref(IQ_DOMAIN_PREFIX, "iq_distcenter_home"); 
}
function BuyerIQAdminReportsManage() 
{ 
  setLocationHref(IQ_DOMAIN_PREFIX, "iq_reports_home");  
}
function BuyerIQAdminErrorReportsHome() 
{ 
  setLocationHref(IQ_DOMAIN_PREFIX, "iq_reports_error_home"); 
}







/*
To ensure that consistent handling is performed, all location.href setting should be performed
via this function. It makes sure that modifications are checked etc.
*/
function setLocationHref(domain_prefix, value) {

    if (AttemptToCallHandlePageExit() == true) {
        top.location.href = "dir?action=" + domain_prefix + value +"&BUYERORG=" + BUYERORG;
    }
}

/*
the handlePageExit is provided by modification_management.js which may not have been included
on the current page. This method attempts to call it and ignores exceptions that occur if
the method does not exist.
*/

function AttemptToCallHandlePageExit() {
    try {    
        return handlePageExit();
    } catch (Exception) {
        return true;
     }
}


function display_date(date_format,daystoadd) {
  if (daystoadd == "TBD") return "TBD"
  var dotw_long = dotw_short = "DOTW";
  var month_long = month_short = "January";
  var tempdate = date + daystoadd;
  var tempdotw = dotw + daystoadd;
  var tempmonth = month;
  var year_whole = year;
  if (tempdotw > 6) tempdotw = tempdotw - 7;
  switch(tempdotw){
    case 0: dotw_long = "Sunday"; dotw_short = "Sun"; break;
    case 1: dotw_long = "Monday"; dotw_short = "Mon"; break;
    case 2: dotw_long = "Tuesday"; dotw_short = "Tue"; break;
    case 3: dotw_long = "Wednesday"; dotw_short = "Wed"; break;
    case 4: dotw_long = "Thursday"; dotw_short = "Thu"; break;
    case 5: dotw_long = "Friday"; dotw_short = "Fri"; break;
    case 6: dotw_long = "Saturday"; dotw_short = "Sat"; break;
  }
  switch(month){
    case 0:
      month_long = "January"; month_short = "Jan";
      if (tempdate > 31) {tempmonth = 1; tempdate = tempdate - 31; month_long = "February"; month_short = "Feb"}; break;
    case 1:
      month_long = "February"; month_short = "Feb";
      if (tempdate > 28) {tempmonth = 2; tempdate = tempdate - 28; month_long = "March"; month_short = "Mar"}; break;
    case 2:
      month_long = "March"; month_short = "Mar";
      if (tempdate > 31) {tempmonth = 3; tempdate = tempdate - 31; month_long = "April"; month_short = "Apr"}; break;
    case 3:
      month_long = "April"; month_short = "Apr";
      if (tempdate > 30) {tempmonth = 4; tempdate = tempdate - 30; month_long = "May"; month_short = "May"}; break;
    case 4:
      month_long = "May"; month_short = "May";
      if (tempdate > 31) {tempmonth = 5; tempdate = tempdate - 31; month_long = "June"; month_short = "Jun"}; break;
    case 5:
      month_long = "June"; month_short = "Jun";
      if (tempdate > 30) {tempmonth = 6; tempdate = tempdate - 30; month_long = "July"; month_short = "Jul"}; break;
    case 6:
      month_long = "July"; month_short = "Jul";
      if (tempdate > 31) {tempmonth = 7; tempdate = tempdate - 31; month_long = "August"; month_short = "Aug"}; break;
    case 7:
      month_long = "August"; month_short = "Aug";
      if (tempdate > 31) {tempmonth = 8; tempdate = tempdate - 31; month_long = "September"; month_short = "Sep"}; break;
    case 8:
      month_long = "September"; month_short = "Sep";
      if (tempdate > 30) {tempmonth = 9; tempdate = tempdate - 30; month_long = "October"; month_short = "Oct"}; break;
    case 9:
      month_long = "October"; month_short = "Oct";
      if (tempdate > 31) {tempmonth = 10; tempdate = tempdate - 31; month_long = "November"; month_short = "Nov"}; break;
    case 10:
      month_long = "November"; month_short = "Nov";
      if (tempdate > 30) {tempmonth = 11; tempdate = tempdate - 30; month_long = "December"; month_short = "Dec"}; break;
    case 11:
      month_long = "December"; month_short = "Dec";
      if (tempdate > 31) {year_whole = ++year_whole ; tempmonth = 0; tempdate = tempdate - 31; month_long = "January"; month_short = "Jan"}; break;
  }
//  month_short = month_long.substr(0,3);
  switch (date_format){
// *** Mon. 12/30 ***
    case 0: tempdate = dotw_short + ". " + (tempmonth + 1) + "/" + tempdate; break;
// *** Mon 12/30 ***
    case 1: tempdate = dotw_short + " " + (tempmonth + 1) + "/" + tempdate; break;
// *** Mon 12/30/00 ***
    case 2: tempdate = day_short + " " + (tempmonth + 1) + "/" + tempdate + "/0" + (year_whole - 2000); break;
// *** 12/30/00 ***
    case 3: tempdate = (tempmonth + 1) + "/" + tempdate + "/0" + (year_whole - 2000); break;
// *** Monday, December 30, 2000  ***
    case 4: tempdate = dotw_long + ", " + month_long + " " + tempdate + ", " + year_whole; break;
// *** 12/30/2000 ***
    case 5: tempdate = (tempmonth + 1) + "/" + tempdate + "/" + (year_whole); break;
    
  }
  return tempdate;
}


function display_time()
{
    var date    = new Date();
    var hours   = date.getHours();
    var minutes = date.getMinutes();

    if(hours > 12)
    {
      hours = hours - 12;
    }
    
    if(hours < 10)
    {
      hours = "0" + hours;
    }
    
    if(minutes < 10)
    {
        minutes = "0" + minutes;
    }
        
        var currtime    = hours + ":" + minutes;
    
    return currtime;
}


// *** START: Routine to build customizable rounded corners ***
function cornerbuilder(corner,outlineimg, path) 
{
// corner: ul, ur, bl, br   any of these may have a number at the end from 0-6 representing which line doesn't get drawn
// o: outline   t: transparency   nostrings: nothing
  outlineimgnew = outlineimg;
  
  if (corner == "ul") {
    corner_line[1] = linebuilder("w7","","",1,path);
    corner_line[2] = linebuilder("w5","o2","",1,path);
    corner_line[3] = linebuilder("w3","o2","",1,path);
    corner_line[4] = linebuilder("w2","o1","",1,path);
    corner_line[5] = linebuilder("w2","o1","",1,path);
    corner_line[6] = linebuilder("w1","o1","",1,path);
    corner_line[7] = linebuilder("w1","o1","",0,path);
  }
  if (corner == "ur") {
    corner_line[1] = linebuilder("w7","","",1,path);
    corner_line[2] = linebuilder("o2","w5","",1,path);
    corner_line[3] = linebuilder("t2","o2","w3",1,path);
    corner_line[4] = linebuilder("t4","o1","w2",1,path);
    corner_line[5] = linebuilder("t4","o1","w2",1,path);
    corner_line[6] = linebuilder("t5","o1","w1",1,path);
    corner_line[7] = linebuilder("t5","o1","w1",0,path);
  }
  if (corner == "bl") {
    corner_line[1] = linebuilder("w1","o1","",1,path);
    corner_line[2] = linebuilder("w1","o1","",1,path);
    corner_line[3] = linebuilder("w2","o1","",1,path);
    corner_line[4] = linebuilder("w2","o1","",1,path);
    corner_line[5] = linebuilder("w3","o2","",1,path);
    corner_line[6] = linebuilder("w5","o2","",1,path);
    corner_line[7] = linebuilder("w7","","",0,path);
  }
  if (corner == "br") {
    corner_line[1] = linebuilder("t5","o1","w1",1,path);
    corner_line[2] = linebuilder("t5","o1","w1",1,path);
    corner_line[3] = linebuilder("t4","o1","w2",1,path);
    corner_line[4] = linebuilder("t4","o1","w2",1,path);
    corner_line[5] = linebuilder("t2","o2","w3",1,path);
    corner_line[6] = linebuilder("o2","w5","",1,path);
    corner_line[7] = linebuilder("w7","","",0,path);
  }
  hidden_line = eval(corner.substr(2,1));
  if (hidden_line) corner_line[hidden_line] = "";
  hugelineofcode = "";
  for (anum=1; anum<=7; anum++) {
    hugelineofcode = hugelineofcode + corner_line[anum];
  }
  return hugelineofcode;
}

//not being used because we are not using cornerbuilder for now//
function linebuilder(graphic1,graphic2,graphic3,linefeed,path) 
{
  lineofcode = "";
  if (graphic1 != "")
  {
    if (graphic1.substr(0,1) == "t") graphic1img = "\'" + path + "/spacer.gif\'";
    else if (graphic1.substr(0,1) == "o") graphic1img = "\'" + path + "/" + outlineimgnew + "\'";
    else if (graphic1.substr(0,1) == "w") graphic1img = "\'" + path + "/backcolor.gif\'";
    graphic1width = graphic1.substr(1,1);
    lineofcode = lineofcode + "<img border=0 src=" + graphic1img + " width=" + graphic1width + " height=1>";
  }
  if (graphic2 != "")
  {
    if (graphic2.substr(0,1) == "t") graphic2img = "\'" + path + "/spacer.gif\'";
    else if (graphic2.substr(0,1) == "o") graphic2img = "\'" + path + "/" + outlineimgnew + "\'";
    else if (graphic2.substr(0,1) == "w") graphic2img = "\'" + path + "/backcolor.gif\'";
    graphic2width = graphic2.substr(1,1);
    lineofcode = lineofcode + "<img border=0 src=" + graphic2img + " width=" + graphic2width + " height=1>";
  }
  if (graphic3 != "")
  {
    if (graphic3.substr(0,1) == "t") graphic3img = "\'" + path + "/spacer.gif\'";
    else if (graphic3.substr(0,1) == "o") graphic3img = "\'" + path + "/" + outlineimgnew + "\'";
    else if (graphic3.substr(0,1) == "w") graphic3img = "\'" + path + "/backcolor.gif\'";
    graphic3width = graphic3.substr(1,1);
    lineofcode = lineofcode + "<img border=0 src=" + graphic3img + " width=" + graphic3width + " height=1>";
  }
  
  if (linefeed>0) lineofcode = lineofcode + "<br>";
  
  return lineofcode;
}
// *** END: Routine to build customizable rounded corners ***

// *** START: Builds a button around a JPEG, GIF or Text and assigns a link ***

function ButtonBuilder(CenterElement,ButtonLink,alttext,path) {
  ButtonWidth=DistributorButtonWidth;
  EndOfString = CenterElement.substr(CenterElement.length-4,4); 
  NewCenterElement = CenterElement;
  if (EndOfString == ".gif" || EndOfString == ".jpg")
  {
    NewCenterElement = "<img border=0 src=\"" + path + "/" + CenterElement + "\" alt=" + alttext + ">";
    ButtonContent = "<a href=\"" + ButtonLink + "\">" + NewCenterElement + "</a>";
    FinalButton = "<table border=0 cellspacing=0 cellpadding=0 width=" + ButtonWidth + "> <tr><td class=Button valign=middle align=center width=\"100%\"><span class=Button>" + ButtonContent + "</span></td></tr>" + "</table>";
  }
  else
  {
    ButtonContent = "<a href=\"" + ButtonLink + "\">" + NewCenterElement + "</a>";
    FinalButton = "<table border=0 cellspacing=0 cellpadding=0 width=" + ButtonWidth + "><tr>" +
       "<td class=Button valign=top align=left rowspan=3>" + cornerbuilder("ul","outline1.gif", path) + "<br><img border=0 src=\"" + path + "/outline2.gif\" width=1 height=25><br>" + cornerbuilder("bl","outline1.gif",path) + "</td>" +
       "<td class=Button valign=top><img border=0 src=\"" + path + "/outline2.gif\" width=\"100%\" height=1 alt=" + alttext + "></td>" +
       "<td class=Button valign=top align=right rowspan=3>" + cornerbuilder("ur","outline1.gif", path) + "<br><img border=0 src=\"" + path + "/outline2.gif\" width=1 height=25><br>" + cornerbuilder("br","outline1.gif",path) + "</td></tr>" +
       "<tr><td class=Button valign=middle align=center width=\"100%\"><span class=Button>" + ButtonContent + "</span></td></tr>" +
           "<tr><td class=Button valign=bottom><img border=0 src=\"" + path + "/outline2.gif\" width=\"100%\" height=1></td></tr></table>";
  }
//  ButtonContent = "<a href=\"" + ButtonLink + "\">" + NewCenterElement + "</a>";
//  FinalButton = "<table border=0 cellspacing=0 cellpadding=0 width=" + ButtonWidth + "><tr>" +
//    "<td class=Button valign=top align=left rowspan=3>" + cornerbuilder("ul","outline1.gif", path) + "<br><img border=0 src=\"" + path + "/outline2.gif\" width=1 height=25><br>" + cornerbuilder("bl","outline1.gif",path) + "</td>" +
//    "<td class=Button valign=top><img border=0 src=\"" + path + "/outline2.gif\" width=\"100%\" height=1 alt=" + alttext + "></td>" +
//    "<td class=Button valign=top align=right rowspan=3>" + cornerbuilder("ur","outline1.gif", path) + "<br><img border=0 src=\"" + path + "/outline2.gif\" width=1 height=25><br>" + cornerbuilder("br","outline1.gif",path) + "</td></tr>" +
//    "<tr><td class=Button valign=middle align=center width=\"100%\"><span class=Button>" + ButtonContent + "</span></td></tr>" +
//    "<tr><td class=Button valign=bottom><img border=0 src=\"" + path + "/outline2.gif\" width=\"100%\" height=1></td></tr></table>";

//  FinalButton = 
//  "<table border=0 cellspacing=0 cellpadding=0 width=" + ButtonWidth + "> <tr><td class=Button valign=middle align=center width=\"100%\"><span class=Button>" + ButtonContent + "</span></td></tr>" +
//    "</table>";


  return FinalButton;
}
// *** END: Builds a button around a JPEG, GIF or Text and  assigns a link ***




function roundValue(value, precision)
{
    // THIS METHOD IS USED IN MULTIPLE PLACES TO ROUND DISPLAYED VALUES
    // AFTER JAVASCRIPT CALCULATIONS ARE MADE TO THE PAGE.
    
    var decimalprecision = 1;
    
    // DETERMINE THE NUMBER OF DECIMAL PLACES FOR PRECISION.
    if(precision > 0)
    {
        for(var i=0; i < precision; i++)
        {
            decimalprecision = (decimalprecision * 10);
        }

    }

    var newvalue        = (Math.round(value * decimalprecision)/decimalprecision);
    newvalue        = padDecimalPlaces(newvalue, precision);
    return newvalue;
    
}

function padDecimalPlaces(value, precision)
{
    // ENSURES THAT WE CAN TREAT THE VALUE AS A STRING
    value           = value + "";

    // PAD 0'S TO THE RIGHT FOR ANY EXTRA PLACES
    var decimalindex    = value.indexOf(".")+1; // Add 1 to move past the decimal pt.
    var newvaluelength  = value.length;
    var currdecplaces   = (newvaluelength - decimalindex);

    if(decimalindex == 0 && precision !=0)
    {
        // THERE IS NO DECIMAL POINT AND THERE IS 
        // DECIMAL PRECISION - ADD THE DECIMAL PT. TO VALUE
        value       = value + ".";
        decimalindex    = value.indexOf(".");
        newvaluelength  = value.length;
        currdecplaces   = 0;    
    }

    // LOOP THROUGH REMAINING DECIMAL PLACES AND ADD 0'S
    for(var i= currdecplaces; i < precision; i++)
    {
        value       = value + "0";
    }

    return value;
}


function isIntnum(str) 
{
    var     nstr = "";

    for (var i = 0; i < str.length; i++) {
        var ch = str.substring(i, i + 1);
        if (ch < "0" || ch > "9"){
            return false;
        }
    }
    return true;
}

function isDecimalNum(str) 
{
    var nstr 		= "";
    var decimalfound 	= false;

    for (var i = 0; i < str.length; i++) 
    {
        var ch = str.substring(i, i + 1);
        if ((ch < "0" || ch > "9") && ch !=".")
        {
            return false;
        }
        else
        {
          // Check if the current char is a decimal and
          // if a decimal has already been processed.
          if(ch == "." && decimalfound == true)
          {
            return false;
          }
          else if(ch ==".")
          {
            decimalfound = true;
          }
        }
    }
    return true;
}

function isPosNum(num) 
{
    if (NaN(num))   return false;
    else if (num<0) return false;
    else            return true;
}


function divide(dividend,divisor) {
    if (dividend ==0 || dividend =="")  return "0.00" ;
    else if (divisor ==0 || divisor =="") return "0.00" ; //not mathematical ,but business handling
    else {
            return dividend/divisor ;
    }
}

function setBuyerOrg(value)
 {
    BUYERORG = value;
 }

function ValidatePrecision (num, precision)
/*
Return true if the number of places after the decimal point
in the num argument is no greater than the number specified
by the precision arguement.  It is assumed that num has
already been checked and is a valid number.
*/
{
    var x = num + " " //convert to string

    var start = x.indexOf (".")

    if (start == -1) return true

    else
    {
        places = x.length - start - 2
        return (places <= precision)
    }


}


/*
Strips the spaces 
1)Strip leading
2)Strip trailing
3)Strip both
*/
function trim(strText,choice) {     

// this will get rid of leading spaces      
if(choice==1 || choice==3) {
	while (strText.substring(0,1) == ' ') 
	strText = strText.substring(1, strText.length);
	}
// this will get rid of trailing spaces      
if (choice==2 || choice==3) {
	while (strText.substring(strText.length-1,strText.length) == ' ')
	strText = strText.substring(0, strText.length-1);
	}
return strText;
} 


/*
This method sets the status bar with a message
*/

function StatusBar(message)
{
   window.status=message;
}

function DisableMenuLinks() {
	var linkCollection = document.getElementsByTagName('a') ;	
	var linkCollectionLength = linkCollection.length;
	//Run though the collection and disable the links
	for (var i=0; i < linkCollectionLength; i++) 
	{ 		
		var ParentInnerHTML = linkCollection[i-i].parentNode.innerHTML;
		linkCollection[i-i].parentNode.innerHTML = ParentInnerHTML.substring(0, ParentInnerHTML.indexOf('<A ')) + linkCollection[i-i].innerHTML + ParentInnerHTML.substring(ParentInnerHTML.indexOf('</A>')+4, ParentInnerHTML.length);
	} 	
}
