/* util.js, //_lib
   Website Utilities
   JavaScript 1.2
   (c)2001 Network Design Consulting.  All rights reserved.
   --------------------------------------------------------------------
   1.0.0  12/07/2001  rmg  created at NetDCon.com
   --------------------------------------------------------------------
   This script provides a variety of small semi-useful functions
   See comments above each function for further details.
   -------------------------------------------------------------------- */

/* hullo(); 
   Print time-sensitve greeting --------------------------------------- */
function hullo() {
  rightnow = new Date();
  righthour = rightnow.getHours();
  if (righthour < 12) { greeting = "Good Morning,"; }
  else 
    if (righthour < 18) { greeting = "Good Afternoon,"; }
    else { greeting = "Good Evening,"; }
  document.write(greeting);
}

/* prmd_slides(image_number, total_number_of_images)
   Display inline product picture slide show -------------------------- */
function prmd_slides(picnum, numpix) {
  if (picnum == 1) { imgnum = 1; }
  if (picnum == 0) { imgnum = imgnum - 1;
    if (imgnum < 1) { imgnum = numpix; } }
  if (picnum == 2) { imgnum = imgnum + 1;
    if (imgnum > numpix) { imgnum = 1; } }
  document.prmg_slide.src = prmg_i[imgnum].src;
  // Caption display ------------------------------------------
  if (prmg_c[imgnum].length < 1) { prmg_c[imgnum] = "&nbsp;"; }
  if (document.layers) {
    document.layers.imgc.document.write(prmg_c[imgnum]);
    document.layers.imgc.document.close(); }
  else {
    msg = document.getElementById('imgc');
    msg.innerHTML = prmg_c[imgnum]; }
  return; 
}

/* prmd_popup(image_number, x_resolution, y_resolution)
   Display inline product picture slide show -------------------------- */
function prmd_popup(qpid, numpix, picnum) {
  // Calculate window size --------------------------------------------
  picw = prmg_f[imgnum].width * 1.05;
  pich = prmg_f[imgnum].height * 1.05;
  
  popfeat = "height=" + pich + ","
          + "width=" + picw + ","
          + "resizable=no";
  popup = window.open("http://dev.reelinndealin.com/_art/prmg.php?pid=" + qpid +"&qid=" + prmg_q[imgnum],"",popfeat,true);

  // Caption display ------------------------------------------
/*
  if (prmg_c[imgnum].length < 1) { prmg_c[imgnum] = "&nbsp;"; }
  if (document.layers) {
    document.layers.imgc.document.write(prmg_c[imgnum]);
    document.layers.imgc.document.close(); }
  else {
    msg = document.getElementById('imgc');
    msg.innerHTML = prmg_c[imgnum]; }
*/

  return; 
}




// Pop-up Photograph ------------------------------------------
function picpop(lurl) {
  var pic = new Array();
  pic[1] = new Image();
  pic[1].src = lurl;
  pic[1].border = 0;
  picw = pic[1].width + (pic[1].width * .05);
  pich = pic[1].height + (pic[1].height * .05);
  popfeat = "height=" + pich + ","
          + "width=" + picw + ","
          + "resizable=no";
  popup = window.open(lurl,"",popfeat,true);
}

// Dynamic Clock ----------------------------------------------
function clock() {
  if (!document.layers && !document.all) return;
  var digital = new Date();
  var hours = digital.getHours();
  var minutes = digital.getMinutes();
  var seconds = digital.getSeconds();
  var amOrPm = "AM";
  if (hours > 11) amOrPm = "PM";
  if (hours > 12) hours = hours - 12;
  if (hours == 0) hours = 12;
  if (minutes <= 9) minutes = "0" + minutes;
  if (seconds <= 9) seconds = "0" + seconds;
  dispTime = hours + ":" + minutes + ":" + seconds + " " + amOrPm;
  if (document.layers) {
    document.layers.pendule.document.write(dispTime);
    document.layers.pendule.document.close(); }
  else {
    if (document.all)
      pendule.innerHTML = dispTime;
      setTimeout("clock()", 1000); }
}

// Push to new URL --------------------------------------------
function pushURL(urlid) { location.replace(urlid); return; }

// Push to submit URL -----------------------------------------
function submitURL(urlid) {
  document.pcae.action = urlid;
  document.pcae.submit(urlid); 
  return; }

// SubCategory selection processing ---------------------------
function opidn2() {
  ix = document.nc2i.idn2.selectedIndex;
  if (document.nc2i.idn2.options[ix].value.length > 2) {
    var lurl = 'category.php?nc2=' + document.nc2i.idn2.options[ix].value; }
  else {
    var lurl = 'category.php?nc1=' + document.nc2i.idn2.options[ix].value; }
  location.replace(lurl); 
  return; 
}  
// TERRITORY selection processing -----------------------------
function opid_ter() {
  var ix = document.pcae.s_id_ter.selectedIndex;
  var lurl = 'cart.php';
  if (document.pcae.s_id_ter.options[ix].value != '') {
    document.pcae.id_ter.value = document.pcae.s_id_ter.options[ix].value;
    document.pcae.submit();
//    location.replace(lurl);
     }
  return;
}

function qohmsg(falm) {
  if (falm > 0) {
    window.alert('One or more items` quantity adjusted for available quantity on hand.') }
  return;
}

/* dmsg(message_text)
   Flash message  ----------------------------------------------------- */
function dmsg(mtxt) {
  clr = "&nbsp;";
  if (document.layers) {
    document.layers.xmsg.document.write(mesg);
    tic = setTimeout('document.layers.emsg.document.write(\'&nbsp;\')', 5000);
    document.layers.xmsg.document.close(); }
  else {
    msg = document.getElementById('emsg');
    msg.innerHTML = mtxt;
    tic = setTimeout('msg.innerHTML = clr', 5000); }
return;
}
// Format numeric value ---------------------------------------
function fmt_num(pnumber,decimals) {
//  if (pnumber.indexOf('.') == -1) { pnumber = pnumber + '.0' }
  if (isNaN(pnumber)) { return 0};
  if (pnumber=='') { return 0};
  var IsNegative=(parseInt(pnumber)<0);
  if(IsNegative)pnumber=-pnumber;
  var snum = new String(pnumber);
  var sec = snum.split('.');
  var whole = parseInt(sec[0]);
  var result = '';
  if(sec.length > 1) {
    var dec = new String(sec[1]);
    dec = parseInt(dec)/Math.pow(10,parseInt(dec.length-decimals-1));
    Math.round(dec);
    dec = parseInt(dec)/10;
    if(IsNegative) {
      var x = 0-dec;
      x = Math.round(x);
      dec = - x; }
    else {
      dec = Math.round(dec); }
    if(dec==Math.pow(10, parseInt(decimals))) {
      whole+=1;
    dec="0"; }
  dec = String(whole) + "." + String(dec);
  var dot = dec.indexOf('.');
  if(dot == -1) {
    if (decimals > 0) { dec += '.'; }
    dot = dec.indexOf('.'); }
  var l=parseInt(dot)+parseInt(decimals);
  while(dec.length <= l) { dec += '0'; }
  result = dec; }
  else {
    var dot;
    var dec = new String(whole);
    if (decimals > 0) { dec += '.'; }
    dot = dec.indexOf('.');
    var l=parseInt(dot)+parseInt(decimals);
    while(dec.length <= l) { dec += '0'; }
    result = dec; }
  if(IsNegative)result="-"+result;
  return result;
}

