//////////////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------------//
// GLOBAL JAVSCRIPT FUNCTIONS
// THESE FUNCTIONS ARE UNIVERSAL AND CAN BE USED ANYWHERE
//----------------------------------------------------------------------------------//
//////////////////////////////////////////////////////////////////////////////////////


function fn_ClearSearch()
{
document.move.strSearch.value="";
}


/////////////////////////////////////////////////////////////
//---------------------------------------------------------//
// JUMP FROM ONE FORM FIELD TO ANOTHER
//---------------------------------------------------------//
/////////////////////////////////////////////////////////////
var _console = null;
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
var allow_implicit_submit = true;
var selectName;
var fieldSize;
var nextField;

function keyDown(e)
{
    if (! allow_implicit_submit)
    {
  var myKeyCode;
  var mySrcElement;

  if (e != null)
    myKeyCode = e.which;
  else if (event != null)
    myKeyCode = event.keyCode;
  else
    return true;

  if (e != null)
    mySrcElement = e.target;
  else if (event != null)
  {
    if (event.target != null)
      mySrcElement = event.target;
    else if (event.srcElement != null)
      mySrcElement = event.srcElement;
  }
  else
    return true;

  // debug("EventType=" + ((e != null) ? e.type : event.type) + " KeyCode=" + myKeyCode + " mySrcElement=" + mySrcElement.name + " selectName=" + selectName);

  // enter key pressed
    if (myKeyCode == 13 && selectName != '')
  {
          mySrcElement.form.elements['Select'].value = selectName;
            mySrcElement.form.submit();
            return false
    }
    else if (myKeyCode == 13)
  {
    // debug("Cancel enter key");
    if (event != null)
    {
      event.cancelBubble = true;  // IE stop event from being passed along to other Elements
      event.returnValue = false;  // IE prevents default action
      if (event.preventDefault) event.preventDefault(); // DOM 2 prevents default action
      if (event.stopPropagation) event.stopPropagation(); // DOM 2 stop event from being passed along to other Elements
    }
    return false;
    }
   }
   return true;
}

function keyUp(e)
{
    if (! allow_implicit_submit)
    {
  var myKeyCode;
  var mySrcElement;

  if (e != null)
    myKeyCode = e.which;
  else if (event != null)
    myKeyCode = event.keyCode;
  else
    return true;

  if (e != null)
    mySrcElement = e.target;
  else if (event != null)
  {
    if (event.target != null)
      mySrcElement = event.target;
    else if (event.srcElement != null)
      mySrcElement = event.srcElement;
  }
  else
    return true;

  // debug("EventType=" + ((e != null) ? e.type : event.type) + " KeyCode=" + myKeyCode + " mySrcElement=" + mySrcElement.name + " selectName=" + selectName);

  // 48 is the Unicode character for 0 (zero) this is the first printable character
  // in the sequence. We don't want to mess with keys like backspace, home, end, arrows, etc.
  if (myKeyCode >= 48)
  {
    if (fieldSize != -1 && nextField != '')
    {
      if (mySrcElement.value.length == fieldSize)
      {
        mySrcElement.form.elements[nextField].focus();
      }
    }
  }
   }
   return true
}
document.onkeyup=keyUp;
document.onkeydown=keyDown;
if (isNN) document.captureEvents(Event.KEYUP|Event.KEYDOWN);




/////////////////////////////////////////////////////////////
//---------------------------------------------------------//
// MINIMIZE BROWSER WINDOW
//---------------------------------------------------------//
/////////////////////////////////////////////////////////////
minflag = false; 
function fn_Minimize() 
{
  top.window.moveTo(10000,10000); 
  minflag = true; 
  top.window.blur(); 
  top.window.opener.focus(); 
} 



/////////////////////////////////////////////////////////////
//---------------------------------------------------------//
// MAXIMIZE BROWSER WINDOW
//---------------------------------------------------------//
/////////////////////////////////////////////////////////////
function fn_Maximize() 
{
  if (window.screen) {
    var aw = screen.availWidth;
    var ah = screen.availHeight;
    top.window.moveTo(0, 0);
    top.window.resizeTo(aw, ah);
  }
}




/////////////////////////////////////////////////////////////
//---------------------------------------------------------//
// MAKE SURE YOU ONLY HIT SUBMIT BUTTON ONCE
//---------------------------------------------------------//
/////////////////////////////////////////////////////////////
var submitted = 0;
function LockButton (form,element) 
{
  if ( ! submitted ) 
  { 
    form.elements[element].disabled=false;
    submitted = 1;
    form.submit;
  }
  else { alert("Form already submitted, please be patient"); }
}


/////////////////////////////////////////////////////////////
//---------------------------------------------------------//
// CONFIRM THAT YOU WANT TO DELETE ITEM
//---------------------------------------------------------//
/////////////////////////////////////////////////////////////
function fn_ConfirmDelete() 
{
var message ="Are you sure you want to proceed?";
var agree = confirm(message);

if (agree)
  return true;
else
  return false;
}



/////////////////////////////////////////////////////////////
//---------------------------------------------------------//
// CONFIRM THAT YOU WANT TO SUBMIT A PO
//---------------------------------------------------------//
/////////////////////////////////////////////////////////////
function fn_ConfirmPOSubmit()
{
var message ="If you submit a purchase order, it can no longer be edited.  To change a purchase order once it has been submitted, you must cancel the current purchase order and create a new one. Are you sure you want to proceed?";
var agree = confirm(message);

if (agree)
  return true;
else
  return false;
}




/////////////////////////////////////////////////////////////
//---------------------------------------------------------//
// AUTOSUBMIT FORM
//---------------------------------------------------------//
/////////////////////////////////////////////////////////////
function fn_AutoSubmit(formName)
{
  formName.submit();
}



/////////////////////////////////////////////////////////////
//---------------------------------------------------------//
// CENTER OPEN WINDOW
//---------------------------------------------------------//
/////////////////////////////////////////////////////////////
function fn_ReceiptPop(url,popName,popWidth,popHeight) 
{
  var popWidth;
  var popHeight;
  var screenWidth  = window.screen.width;
  var screenHeight = window.screen.height;
  var placementx   = (screenWidth/2)-((popWidth)/2);
  var placementy   = (screenHeight/2)-((popHeight+50)/2);

  window.open(url,popName,"width="+popWidth+",height="+popHeight+",toolbar=0,location=0,status=0,scrollbars=yes,menubar=0,resizable=0,left="+placementx+",top="+placementy+",screenX="+placementx+",screenY="+placementy+",");
}







//////////////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------------//
// SPECIFIC JAVSCRIPT FUNCTIONS
// THESE FUNCTIONS ARE USED FOR A PARTICULAR PART AND ARE NOT UNIVERSAL
//----------------------------------------------------------------------------------//
//////////////////////////////////////////////////////////////////////////////////////






/////////////////////////////////////////////////////////////
//---------------------------------------------------------//
// ADMIN_EMPLOYEES.ASP : CLEAR HOURLY RATE
//---------------------------------------------------------//
/////////////////////////////////////////////////////////////
function fn_ClearHourly() 
{
document.employees.eHourlyRate.value = 0;
document.employees.eHourly.checked = false;
}


/////////////////////////////////////////////////////////////
//---------------------------------------------------------//
// ADMIN_EMPLOYEES.ASP : CLEAR SALARY RATE
//---------------------------------------------------------//
/////////////////////////////////////////////////////////////
function fn_ClearSalary() 
{
document.employees.eSalaryRate.value = 0;
document.employees.eSalary.checked = false;
}




/////////////////////////////////////////////////////////////
//---------------------------------------------------------//
// FILL IN SHIPPING INFORMATION
//---------------------------------------------------------//
/////////////////////////////////////////////////////////////
function fn_FillInShip()
{
  document.customers.ShipAddress.value = document.customers.Address.value;
  document.customers.ShipCity.value = document.customers.City.value;
  document.customers.ShipState.value = document.customers.State.value;
  document.customers.ShipZip.value = document.customers.Zip.value;
}


/////////////////////////////////////////////////////////////
//---------------------------------------------------------//
// FOCUS ON USERNAME LOGIN
//---------------------------------------------------------//
/////////////////////////////////////////////////////////////
function fn_FocusLogin() 
{
  document.login.Username.focus()
}


/////////////////////////////////////////////////////////////
//---------------------------------------------------------//
// CHECK LOGIN INFORMATION
//---------------------------------------------------------//
/////////////////////////////////////////////////////////////
function fn_CheckLogin() 
{
 if (document.login.Username.value == "") {
   window.alert ("Error: You need to enter a Username")
   return false;
 }
 if (document.login.Password.value == "") {
   window.alert ("Error: You need to enter a Password")
   return false;
 }
}




/////////////////////////////////////////////////////////////
//---------------------------------------------------------//
// CLEAR LABOR INFO IF USE GREENBOOTS
//---------------------------------------------------------//
/////////////////////////////////////////////////////////////
function fn_ClearLabor()
{
  var strLayerState = document.labor.lbrState.value
  if (strLayerState==1) {
    document.labor.lbrState.value = 0
    fn_ShowHideLayers('oDiv_lbrMaterial','','hide','oDiv_lbrLabor','','hide');
  }else{
    document.labor.lbrState.value = 1
    fn_ShowHideLayers('oDiv_lbrMaterial','','show','oDiv_lbrLabor','','show');  
  }
  
}



/////////////////////////////////////////////////////////////
//---------------------------------------------------------//
// HIDE LAYERS
//---------------------------------------------------------//
/////////////////////////////////////////////////////////////
function fn_ShowHideLayers() 
{
  var i,p,v,obj,args=fn_ShowHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=fn_FindObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function fn_FindObj(n, d) 
{
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=fn_FindObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}



/////////////////////////////////////////////////////////////
//---------------------------------------------------------//
// CHANGE COLOR FIELD
//---------------------------------------------------------//
/////////////////////////////////////////////////////////////

function fn_SetColor(i)
{
var bgColor = new Array();

bgColor[0] = "#FF9A7B"; 
bgColor[1] = "#FFB284"; 
bgColor[2] = "#FFCB8C"; 
bgColor[3] = "#FFFBA5"; 
bgColor[4] = "#D6E39C"; 
bgColor[5] = "#ADD79C"; 
bgColor[6] = "#8CCB9C"; 
bgColor[7] = "#7BCFCE"; 
bgColor[8] = "#6BCFF7"; 
bgColor[9] = "#7BAAD6"; 
bgColor[10] = "#8492C6"; 
bgColor[11] = "#8C82B5"; 
bgColor[12] = "#A586B5"; 
bgColor[13] = "#C68EB5"; 
bgColor[14] = "#FF9EBD"; 
bgColor[15] = "#FF9A9C"; 
bgColor[16] = "#FF654A"; 
bgColor[17] = "#FF8E52"; 
bgColor[18] = "#FFB25A"; 
bgColor[19] = "#FFF76B"; 
bgColor[20] = "#B5D373"; 
bgColor[21] = "#84C373"; 
bgColor[22] = "#39B673"; 
bgColor[23] = "#00BAb5"; 
bgColor[24] = "#00BAEF"; 
bgColor[25] = "#218AC6"; 
bgColor[26] = "#426DAD"; 
bgColor[27] = "#524D94"; 
bgColor[28] = "#84559C"; 
bgColor[29] = "#AD599C"; 
bgColor[30] = "#F7659C"; 
bgColor[31] = "#F76573"; 
bgColor[32] = "#EF0029"; 
bgColor[33] = "#F75D21"; 
bgColor[34] = "#FF9621"; 
bgColor[35] = "#FFF331"; 
bgColor[36] = "#94C731"; 
bgColor[37] = "#31B242"; 
bgColor[38] = "#189E63"; 
bgColor[39] = "#00A69C"; 
bgColor[40] = "#00B2EF"; 
bgColor[41] = "#0069AD"; 
bgColor[42] = "#004594"; 
bgColor[43] = "#10147B"; 
bgColor[44] = "#5A007B"; 
bgColor[45] = "#8C007B"; 
bgColor[46] = "#EF007B"; 
bgColor[47] = "#EF0052"; 
bgColor[48] = "#9C0018"; 
bgColor[49] = "#A53C18"; 
bgColor[50] = "#AD6510"; 
bgColor[51] = "#BDA221"; 
bgColor[52] = "#638221"; 
bgColor[53] = "#217529"; 
bgColor[54] = "#086942"; 
bgColor[55] = "#006D6B"; 
bgColor[56] = "#00759C"; 
bgColor[57] = "#004573"; 
bgColor[58] = "#002c63"; 
bgColor[59] = "#000852"; 
bgColor[60] = "#390052"; 
bgColor[61] = "#540052"; 
bgColor[62] = "#9C0052"; 
bgColor[63] = "#9C0039"; 
bgColor[64] = "#730010"; 
bgColor[65] = "#732C08"; 
bgColor[66] = "#7B4908"; 
bgColor[67] = "#847518"; 
bgColor[68] = "#425D18"; 
bgColor[69] = "#185521"; 
bgColor[70] = "#004D31"; 
bgColor[71] = "#004D4A"; 
bgColor[72] = "#005573"; 
bgColor[73] = "#003052"; 
bgColor[74] = "#002042"; 
bgColor[75] = "#000439"; 
bgColor[76] = "#290039"; 
bgColor[77] = "#420039"; 
bgColor[78] = "#730039"; 
bgColor[79] = "#730029"; 

document.configure.coBGColor.value = bgColor[i];
}


