function dlgConfirm(txtMsg)
{
 var agree=confirm(txtMsg + "\n\nAre you sure you want to perform the above action?");
 if (agree) { return true; }
 else { return false ; }
}

 function Dialog(url, WIDTH, HEIGHT, action, init) {
         if (typeof init == "undefined") {
                 init = window; // pass this window object by default
         }
         Dialog._geckoOpenModal(url, WIDTH, HEIGHT, action, init);
 }

 // should be a function, the return handler of the currently opened dialog.
 Dialog._return = null;

 // constant, the currently opened dialog
 Dialog._modal = null;

 // the dialog will read it's args from this variable
 Dialog._arguments = null;

 Dialog._geckoOpenModal = function(url, WIDTH, HEIGHT, action, init) {
         var dlg = window.open(url, "hadialog",
                               "toolbar=no,menubar=no,personalbar=no,width="+WIDTH+",height="+HEIGHT+"," +
                               "scrollbars=no,resizable=yes,modal=yes,dependable=yes");
         Dialog._modal = dlg;
         Dialog._arguments = init;

         for (var i = 0; i < window.frames.length; i++) {try { capwin(window.frames[i]); } catch(e) { } };
         // make up a function to be called when the Dialog ends.
         Dialog._return = function (val) {
                 if (val) {
                  if(action) {
                         action(val);
                  }
                 }
                 relwin(window);
                 // capture other frames
                 for (var i = 0; i < window.frames.length; i++) { try { relwin(window.frames[i]); } catch(e) { } };
                 Dialog._modal = null;
         };
   Dialog._modal.focus();
 };

function popBox(URL, WIDTH, HEIGHT, X, Y)
{
 popBoxScroll(URL,WIDTH,HEIGHT,X,Y,0,0);
}

function popBoxScroll(URL, WIDTH, HEIGHT, X, Y, S, P)
{
 day = new Date();
 id = day.getTime();
 var options = "'toolbar=0,scrollbars=" + S + ",location=0,statusbar=0,menubar=0,resizable=0,width="+WIDTH+",height="+HEIGHT+",left="+X+",top="+Y+"'";

 myWindow = window.open(URL, id, options);
 if( P == 1 )
 {
  myWindow.print();
 }
}

function openWindow( name, url )
{
 var myWindow = window.open( url, name, "");
 myWindow.focus();
}

function toggleDiv( divid, divlabel )
{
 el_div = document.getElementById(divid);
 el_lbl = document.getElementById(divlabel);

 if( el_div.style.display == "none" )
 {
  el_div.style.display = "inline";
  el_lbl.innerHTML = "[-]";
 }
 else
 {
  el_div.style.display = "none";
  el_lbl.innerHTML = "[+]";
 }
}

function toggleName( divname, divlabel )
{
 el_div = document.getElementsByName(divname);
 el_lbl = document.getElementById(divlabel);

 for( var x=0; x < el_div.length; x++ )
 {
  if( el_div[x].style.display == "none" )
  {
   el_div[x].style.display = "inline";
   el_lbl.innerHTML = "[-]";
  }
  else
  {
   el_div[x].style.display = "none";
   el_lbl.innerHTML = "[+]";
  }
 }
}

function clearField(searchfieldname, dflt_value)
{
 var el = document.getElementsByName(searchfieldname);
 if( el[0].value == dflt_value )
 {
  el[0].style.color="black";
  el[0].style.fontStyle="normal";
  el[0].style.textAlign="left";
  el[0].value = "";
 }
}

function resetField(searchfieldname, dflt_value)
{
 var el = document.getElementsByName(searchfieldname);
 if( el[0].value == '' )
 {
  el[0].style.color="gray";
  el[0].style.fontStyle="italic";
  el[0].style.textAlign="center";
  el[0].value = dflt_value;
 }
}

function searchCombo(fieldname, searchpart, name_or_value)
{
 var el = document.getElementsByName(fieldname);
 var len = searchpart.length;

 if( len > 0 )
 {
  for(x=0; x < el[0].length; x++)
  {
   if( name_or_value == "name" )
   {
    //if( el[0].options[x].innerHTML.substr(0,len).toUpperCase() == searchpart.toUpperCase() ) { el[0].selectedIndex = x; break; }
    if( el[0].options[x].innerHTML.toUpperCase().match(searchpart.toUpperCase()) != null ) { el[0].selectedIndex = x; }
   }
   else
   {
    if( el[0].options[x].value.substr(0,len).toUpperCase() == searchpart.toUpperCase() ) { el[0].selectedIndex = x; break; }
   }
  }
 }
}

function noDoubleQuotes(e)
{
 var key;

 var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;

 if(window.event)
  key = window.event.keyCode;     //IE
 else
  key = e.which;     //firefox

 keychar = String.fromCharCode(key);

 if(keychar == "\"")
 {
  alert("Please use Single Quotes.  It will be converted for you.");
  return false;
 }
 else
  return true;
}

var menuLayers = {
  timer: null,
  activeMenuID: null,
  offX: 4,   // horizontal offset
  offY: 6,   // vertical offset
  show: function(id, e) {
    var mnu = document.getElementById? document.getElementById(id): null;
    if (!mnu) return;
    this.activeMenuID = id;
    if ( mnu.onmouseout == null ) mnu.onmouseout = this.mouseoutCheck;
    if ( mnu.onmouseover == null ) mnu.onmouseover = this.clearTimer;
    viewport.getAll();
    this.position(mnu,e);
  },

  hide: function() {
    this.clearTimer();
    if (this.activeMenuID && document.getElementById)
      this.timer = setTimeout("document.getElementById('"+menuLayers.activeMenuID+"').style.visibility = 'hidden'", 200);
  },

  msg: function(id, txt, clr, e) {
    var mnu = document.getElementById? document.getElementById(id): null;
    var msg = document.getElementById? document.getElementById(id+"_MSG"): null;
    msg.innerHTML=''+txt+'';
    msg.style.background=clr;
    if (!mnu) return;
    if (!msg) return;
    this.activeMenuID = id;
    if ( mnu.onmouseout == null ) mnu.onmouseout = this.mouseoutCheck;
    if ( mnu.onmouseover == null ) mnu.onmouseover = this.clearTimer;
    viewport.getAll();
    this.position(mnu,e);
  },

  position: function(mnu, e) {
    var x = e.pageX? e.pageX: e.clientX + viewport.scrollX;
    var y = e.pageY? e.pageY: e.clientY + viewport.scrollY;

    if ( x + mnu.offsetWidth + this.offX > viewport.width + viewport.scrollX )
      x = x - mnu.offsetWidth - this.offX;
    else x = x + this.offX;

    if ( y + mnu.offsetHeight + this.offY > viewport.height + viewport.scrollY )
      y = ( y - mnu.offsetHeight - this.offY > viewport.scrollY )? y - mnu.offsetHeight - this.offY : viewport.height + viewport.scrollY - mnu.offsetHeight;
    else y = y + this.offY;

    mnu.style.left = x + "px"; mnu.style.top = y + "px";
    this.timer = setTimeout("document.getElementById('" + menuLayers.activeMenuID + "').style.visibility = 'visible'", 200);
  },

  mouseoutCheck: function(e) {
    e = e? e: window.event;
    // is element moused into contained by menu? or is it menu (ul or li or a to menu div)?
    var mnu = document.getElementById(menuLayers.activeMenuID);
    var toEl = e.relatedTarget? e.relatedTarget: e.toElement;
    if ( mnu != toEl && !menuLayers.contained(toEl, mnu) ) menuLayers.hide();
  },

  // returns true of oNode is contained by oCont (container)
  contained: function(oNode, oCont) {
    if (!oNode) return; // in case alt-tab away while hovering (prevent error)
    while ( oNode = oNode.parentNode )
      if ( oNode == oCont ) return true;
    return false;
  },

  clearTimer: function() {
    if (menuLayers.timer) clearTimeout(menuLayers.timer);
  }

}

function pagePrint(URL)
{
 day = new Date();
 id = day.getTime();
 eval("popupwindow = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=554px,height=756px,left = 550,top = 350');");
 popupwindow.print();
}

function OpenChild(lnk,obj,submit)
{
 var WinSettings = "center:yes;status:no;resizable:no;dialogHeight:400px;dialogWidth:710px"
 //ALTER BELOW LINE - supply correct URL for Child Form
 var retval = window.showModalDialog(lnk, obj, WinSettings);
 if (retval == null)
 {
     //window.alert(
       //"Nothing returned from child. No changes made to input boxes")
 }
 if(submit)
 {
  obj.form.submit();
 }
}

function set_val(obj,tval)
{
 obj.value = tval;
}

function doNothing()
{
 window.location.reload();
 return;
}

function replaceDoc(newurl)
{
 window.location.replace(newurl)
}

function gCheckAll (formid, group, tf)
{
 var el = document.getElementById(formid);

//alert("nelements="+el.elements.length);
 for (var i = 0; i < el.elements.length; i++)
 {
  var str = el.elements[i].name;
  if (group == str.substring(0,group.length))
  {
   if( el.elements[i].checked == false ) { el.elements[i].checked = true; }
   else if( el.elements[i].checked == true ) { el.elements[i].checked = false; }
  }
 }
}

function makeRequest()
{
 client = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");

}

function loadAjax( url, divId )
{
 var self = this;
 var result = 0;

 xmlHttpReq = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");

 self.xmlHttpReq.open('GET', url, false);
 self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
 self.xmlHttpReq.send(null);

 var el = document.getElementById( divId );
 el.innerHTML = self.xmlHttpReq.responseText;
}

function saveAjax(saveurl, url, divId)
{
 var self = this;
 var result = 0;

 xmlHttpReq = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");

 self.xmlHttpReq.open('GET', saveurl, false);
 self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
 self.xmlHttpReq.send(null);
 loadAjax( url, divId );
}

function saveDetailAjax(orderid, url, divId)
{
 var self = this;
 var result = 0;

 xmlHttpReq = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");

 el_docsdone = document.getElementsByName("docsdone_"+orderid);

 var docsdone = 0;
 if( el_docsdone[0].checked == true )
 {
  docsdone = 1;
 }

 var saveurl = "/shipping/process_detail.csl?orderid="+orderid+"&docsdone="+docsdone;

 self.xmlHttpReq.open('GET', saveurl, false);
 self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
 self.xmlHttpReq.send(null);
 loadAjax( url, divId );
}

