/*AutoMend Java File...
*/

function UpdateTotal(frm) {
  order_total = 0;
  for (var i=0; i < frm.elements.length; ++i)
  {
    form_field = frm.elements[i];
    field_name = form_field.name;
    if (field_name.substring(0,5) == 'Price')
    {
      item_value = parseFloat(form_field.value);
      if (item_value >= 0) {
        order_total += item_value;
      }
    }
  }
  frm.total.value = round_decimals(order_total, 2);
}

function round_decimals(original_number, decimals) {
  var result1 = original_number * Math.pow(10, decimals)
  var result2 = Math.round(result1)
  var result3 = result2 / Math.pow(10, decimals)
  return pad_with_zeros(result3, decimals)
}

function pad_with_zeros(rounded_value, decimal_places) {
  var value_string = rounded_value.toString()
  var decimal_location = value_string.indexOf(".")
  if (decimal_location == -1) {
     decimal_part_length = 0
     value_string += decimal_places > 0 ? "." : ""
  }
  else {
     decimal_part_length = value_string.length - decimal_location - 1
  }
  var pad_total = decimal_places - decimal_part_length
  if (pad_total > 0) {
  for (var counter = 1; counter <= pad_total; counter++)
        value_string += "0"
  }
  return value_string
}

function checkmsg(textarea, maxlength, remainingbox) {
  var len = textarea.value.length;
  var cr;

  if (len > maxlength) {
    textarea.value = textarea.value.substring(0, maxlength);
    cr = 0;
  }
  else {
    cr = maxlength - len;
  }

  // Now set the document display of chars remaining...
  remainingbox.value = cr;
}

function detailsPop(url, id) {
  popup = window.open(url, "puw", "location=no,scrollbars=yes,resizable=yes,width=600,height=400");
  popup.focus();
}

function bigpop(url) {
  bigpopwin = window.open(url, "bpw", "location=no,scrollbars=yes,resizable=yes,top=0,left=0,width=800,height=600");
  bigpopwin.focus();
}

function detailsPop2(url, id) {
  if (parseInt(document.SearchForm.stockid.value) > 0)
  {
    var theurl = url + "?showdetails=1&stockid=" + document.SearchForm.stockid.value;
    window.open(theurl, id, "location=no,scrollbars=yes,resizable=yes,width=600,height=400");
  }
  else
  {
    alert('You must first enter a valid Stock ID number');
  }
}

function KeyIsEnter() {
  // if the key IS enter then launch the popup with the correct value for stock ID
  // rather than submitting the form as before.
  if (window.event.keyCode == 13)
  {
    detailsPop2('/cgi-bin/repairables/previewdetails.cgi', 'details');
    return false;
  }
  else
  {
    return true;
  }
}

function cPop(url, wide, high) {
  customWindow = window.open(url,"custompopup",'width=' + wide + ',height=' + high);
}

function Pop(url){
  cuteLittleWindow = window.open(url, "littleWindow", "location=no,scrollbars=yes,width=530,height=380");
}

function dPop(url){
  dLongWindow = window.open(url, "longWindow", "location=no,scrollbars=yes,width=530,height=520");
}

function printWindow(){
   bV = parseInt(navigator.appVersion)
   if (bV >= 4) window.print()
}

function MM_findObj(n, d) { //v3.0
  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=MM_findObj(n,d.layers[i].document); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_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 MM_changeProp(objName,x,theProp,theValue) { //v3.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)) eval("obj."+theProp+"='"+theValue+"'");
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function ConfirmClick(messagetext, imagename) {
  if (confirm(messagetext))
  {
    MM_swapImage(imagename,'','/html/images/processing.gif',1);
    return true;
  }
  else
  {
    return false;
  }
}

function ConfirmClickM(messagetext, imagename) {
  if (confirm(messagetext))
  {
    MM_swapImage(imagename,'','/dmhtml/images/btn_ndmm_processing.gif',1);
    return true;
  }
  else
  {
    return false;
  }
}

function ConfirmClickS(messagetext, imagename) {
  if (confirm(messagetext))
  {
    MM_swapImage(imagename,'','/dmhtml/images/btn_ndms_processing.gif',1);
    return true;
  }
  else
  {
    return false;
  }
}

function ConfirmClickL(messagetext, imagename) {
  if (confirm(messagetext))
  {
    MM_swapImage(imagename,'','/dmhtml/images/btn_ndml_processing.gif',1);
    return true;
  }
  else
  {
    return false;
  }
}

function ConfirmClickNI(messagetext) {
  if (confirm(messagetext))
  {
    return true;
  }
  else
  {
    return false;
  }
}

function write_greeting()
{
  var today = new Date();
  var greeting = '';
  var hrs = today.getHours();

  if (hrs < 5)
    greeting = 'Good morning';
  else if (hrs < 12)
    greeting = 'Good morning';
  else if (hrs <= 18)
    greeting = 'Good afternoon';
  else if (hrs < 24)
    greeting = 'Good evening';

  document.write(greeting);
}

function setCookie (name, value, expires, path, domain, secure) {
      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookie(name) {
  var cookie = " " + document.cookie;
  var search = " " + name + "=";
  var setStr = null;
  var offset = 0;
  var end = 0;
  if (cookie.length > 0) {
    offset = cookie.indexOf(search);
    if (offset != -1) {
      offset += search.length;
      end = cookie.indexOf(";", offset)
      if (end == -1) {
        end = cookie.length;
      }
      setStr = unescape(cookie.substring(offset, end));
    }
  }
  return(setStr);
}

var blnFormSubmitted;
blnFormSubmitted = false;
function checkFormSubmitStatus ()
{
  if (!blnFormSubmitted)
  {
    blnFormSubmitted = true;
    return true;
  }
  else
  {
    alert('Your submission is currently being processed.\nIt will only take a few more seconds,\nsorry for any inconvenience.');
    return false;
  }
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")

