/*
globalfc.js global function library

created by: msr 05-11-2009

*/

/* define global variables */

var PopWin = "";

/* variables used to determine screen size */
var wid;
var lpos;
var ht;
var tpos;
var myWidth = 0;
var myHeight = 0;



/* determines browser type and screen size so we can put 
   popups windows in the center of the screen              */

if ( typeof( window.innerWidth ) == "number" ) {
  //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
  //IE 6+ in "standards compliant mode"
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
  //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
    }

lpos = myWidth / 2;
tpos = myHeight / 2;



/* ************************************************************************************************* 
common functions 
**************************************************************************************************** */
/* ----------------------------------------------------------------------
   generic functions
   ---------------------------------------------------------------------- */
/* allow user to log out - clears username, customer number, password */
function logout() {
    document.linkform.custnum.value = "";
    document.linkform.radlogin.value = "";
    document.linkform.radpswd.value = "";
    document.linkform.submit();
    return false;
    }

/* navigate to custreg.p so a new user can open an online account */
function signup() {
    document.linkform.progname.value = "custreg.p";
    document.linkform.cmd.value = "signup";
    document.linkform.submit();
    return false;
    }

/* navigate to weblogin.p page so user can log into their account */
function signon() {
    document.linkform.progname.value = "weblogin.p";
    document.linkform.radlogin.value = document.loginform.radlogin.value;
    document.linkform.radpswd.value = document.loginform.radpswd.value;
    document.linkform.cmd.value = "login";
    document.linkform.submit();
    return false;
    }

/* ----------------------------------------------------------------------
   popup windows 
   ---------------------------------------------------------------------- */
/* function to open pop-up window and display large image */
function largeImg(co,it) {
    winargs = "resizable=yes,scrollbars=yes,width=560,height=400,left=" + lpos + ",top=" + tpos;
    PopWin = window.open("displgimg.p?itemnum="+it.replace(/&/, "%26")+"&conum="+co,"pwin",winargs);
    PopWin.focus();
    }

/* function to open pop-up window and display product quantity available, quantity on order 
   and display estimated lead time */
function dispavail(co,it) {
    winargs = "resizable=yes,scrollbars=yes,width=560,height=400,left=" + lpos + ",top=" + tpos;
    PopWin = window.open("dispavail.p?itemnum="+it.replace(/&/, "%26")+"&conum="+co,"pwin",winargs);
    PopWin.focus();
    }

/* function to open pop-up window and allow user to request lead time information for an item */
function reqLT(co,it) {
    winargs = "resizable=yes,scrollbars=yes,width=560,height=500,left=" + lpos + ",top=" + tpos;
    PopWin = window.open("rqst_lead.p?itemnum="+it.replace(/&/, "%26")+"&conum="+co,"pwin",winargs);
    PopWin.focus();
    }

/* function to open pop-up window and display the standard price (in the cart price) for items 
   where the vendor demands that that we display list price (no discounts) */
function priceincart(it,co) {
    winargs = "resizable=yes,scrollbars=yes,width=450,height=350,left=" + lpos + ",top=" + tpos;
    PopWin = window.open("dispcartpr.p?itemnum="+it.replace(/&/, "%26")+"&conum="+co,"pwin",winargs);
    PopWin.focus();
    }

/* function to open pop-up window and display price schedule details (quantity breaks) */
function priceinfo(sid,it,co) {
    winargs = "resizable=yes,scrollbars=yes,width=560,height=650,left=" + lpos + ",top=" + tpos;
    PopWin = window.open("dispprsch.p?schid="+sid+"&itemnum="+it.replace(/&/, "%26")+"&conum="+co,"pwin",winargs);
    PopWin.focus();
    }

/* function to open a pop-up window to allow a user to request their password via email */
function sendpswd() {
    winargs = "resizable=yes, scrollbars=yes, width=480, height=300, left=" + lpos + ", top=" + tpos;
    PopWin = window.open("mailpswd.p?emailaddr="+document.loginform.radlogin.value+"&conum="+document.linkform.conum.value,"pwin",winargs);
    PopWin.focus();
    }

/* ----------------------------------------------------------------------
   navigation
   ----------------------------------------------------------------------  */
/* navigate to prodinfo page */
function pinfo(pn,cn) {
    document.linkform.progname.value = "prodinfo.p";
    document.linkform.itemnum.value = pn;
    document.linkform.conum.value = cn;
    document.linkform.submit();
    return false;
    }

/* --------------------------------------------------------------------
   form processing
   -------------------------------------------------------------------- */
/* submit buy form */
function buy() {
    document.buyform.cmd.value = "buy";
    document.buyform.submit();
    return false;
    }


/* ************************************************************************************************* 
functions for banner.i
**************************************************************************************************** */
/* ----------------------------------------------------------------------
   form processing
   ----------------------------------------------------------------------  */
/* function to submit search form in banner */
function bannersrch() {
    document.linkform.progname.value = "prodsrch.p";
    document.linkform.cmd.value = "srch";
    document.linkform.vendor.value = "";
    document.linkform.major.value = "";
    document.linkform.minor.value = "";
    document.linkform.crit1.value = document.bannersrchform.keyword.value;
    if (document.bannersrchform.srch[0].checked) {
        document.linkform.crit2.value = document.bannersrchform.srch[0].value;
        }
    if (document.bannersrchform.srch[1].checked) {
        document.linkform.crit2.value = document.bannersrchform.srch[1].value;
        }
    if (document.bannersrchform.srch.length == 3 && document.bannersrchform.srch[2].checked) {
        document.linkform.crit2.value = document.srchform.srch[2].value;
        }
    document.linkform.submit();
    return false;
    }

/* ************************************************************************************************* 
functions for leftpanel.i
**************************************************************************************************** */
/* ----------------------------------------------------------------------
   navigation
   ----------------------------------------------------------------------  */
function catsrch(mjct) {
    document.linkform.progname.value = "prodsrch.p";
    document.linkform.major.value = mjct;
    document.linkform.minor.value = "";
    document.linkform.vendor.value = "";
    document.linkform.crit1.value = "";
    document.linkform.submit();
    return false;
    }


/* ************************************************************************************************* 
functions for addredit.p
**************************************************************************************************** */
/* ----------------------------------------------------------------------
   general functions
   ----------------------------------------------------------------------  */
function addredit_go() {
    document.adderessform.cmd.value = "submit";
    document.adderessform.submit();
    return false;
    }


/* ************************************************************************************************* 
functions for bulkorder.p
**************************************************************************************************** */
/* ----------------------------------------------------------------------
   form processing
   ----------------------------------------------------------------------  */
function bulkorder_addl() {
    document.buyform.cmd.value = "addl";
    document.buyform.submit();
    return false;
    }


/* ************************************************************************************************* 
functions for checkout.p and order.p and order.i
**************************************************************************************************** */
/* ----------------------------------------------------------------------
   form processing
   ----------------------------------------------------------------------  */
function order_alts() {
    winargs = "resizable=yes,scrollbars=yes,width=300,height=480,left=" + lpos + ",top=" + tpos;
    PopWin = window.open("pickalts.p","pwin",winargs);
    PopWin.focus();
    }

function order_popfreight() {
    winargs = "resizable=yes,scrollbars=yes,width=600,height=480,left=" + lpos + ",top=" + tpos;
    PopWin = window.open("popfreight.p","pwin",winargs);
    PopWin.focus();
    }

function order_upd() {
    document.ordform.cmd.value = "update";
    document.ordform.submit();
    }


/* ************************************************************************************************* 
functions for custreg.p
**************************************************************************************************** */
/* ----------------------------------------------------------------------
   form processing
   ----------------------------------------------------------------------  */
/* submit registration form */
function register() {
    document.regform.cmd.value = "submit";
    document.regform.radlogin.value = document.regform.email.value;
    document.regform.radpswd.value = document.regform.pswd1.value;
    document.regform.submit();
    return false;
    }

/* ************************************************************************************************* 
functions for myaddresses.p
**************************************************************************************************** */
/* ----------------------------------------------------------------------
   forms processing
   ----------------------------------------------------------------------  */
function popaddr(sa) {
    if (sa != "") sa = "?sa=" + sa;
    PopWin = window.open("addredit.p"+sa,"pwin","resizable=yes,scrollbars=yes,width=480,height=500,left="+lpos+",top="+tpos);
    PopWin.focus();
    }

function defship(sa) {
    document.linkform.progname.value = "myaddresses.p";
    document.linkform.cmd.value = "defship";
    document.linkform.arg.value = sa;
    document.linkform.submit();
    return false;
    }

function deladdr(sa) {
    if (confirm("Are you sure you want to permanently delete this address?")) {
        document.linkform.progname.value = "myaddresses.p";
        document.linkform.cmd.value = "delete";
        document.linkform.arg.value = sa;
        document.linkform.submit();
        return false;
        }
    }

/* ************************************************************************************************* 
functions for myhistory.p
**************************************************************************************************** */
/* ----------------------------------------------------------------------
   forms processing
   ----------------------------------------------------------------------  */
function myhistory_next() {
    document.orddataform.progname.value = "myhistory.p";
    document.orddataform.cmd.value = "next";
    document.orddataform.submit();
    return false;
    }

function myhistory_prev() {
    document.orddataform.progname.value = "myhistory.p";
    document.orddataform.cmd.value = "prev";
    document.orddataform.submit();
    return false;
    }
function myhistory_sort(sm,so) {
    document.orddataform.progname.value = "myhistory.p";
    document.orddataform.sorttype.value = sm;
    document.orddataform.sortdocs.value = so;
    document.orddataform.first.value = 1;
    document.orddataform.submit();
    return false;
    }

function myhistory_go() {
    document.linkform.progname.value = "myhistory.p";
    document.linkform.cmd.value = "search";
    document.linkform.arg.value = document.orddataform.keyword.value;
    document.linkform.submit();
    return false;
    }

/* ************************************************************************************************* 
functions for myopeninvc.p
**************************************************************************************************** */
/* ----------------------------------------------------------------------
   forms processing
   ----------------------------------------------------------------------  */
function myopeninvc_next() {
    document.invcdataform.progname.value = "myopeninvc.p";
    document.invcdataform.cmd.value = "next";
    document.invcdataform.submit();
    return false;
    }

function myopeninvc_prev() {
    document.invcdataform.progname.value = "myopeninvc.p";
    document.invcdataform.cmd.value = "prev";
    document.invcdataform.submit();
    return false;
    }
function myopeninvc_sort(sm,so) {
    document.invcdataform.progname.value = "myopeninvc.p";
    document.invcdataform.sorttype.value = sm;
    document.invcdataform.sortdocs.value = so;
    document.invcdataform.first.value = 1;
    document.invcdataform.submit();
    return false;
    }

function myopeninvc_go() {
    document.linkform.progname.value = "myopeninvc.p";
    document.linkform.cmd.value = "search";
    document.linkform.arg.value = document.invcdataform.keyword.value;
    document.linkform.submit();
    return false;
    }

/* ************************************************************************************************* 
functions for mypasswd.p
**************************************************************************************************** */
/* ----------------------------------------------------------------------
   forms processing
   ----------------------------------------------------------------------  */
function mypasswd_go() {
    document.pwdchangeform.cmd.value = "submit";
    document.pwdchangeform.radlogin.value = document.regform.email.value;
    document.pwdchangeform.radpswd.value = document.regform.pswd1.value;
    document.pwdchangeform.submit();
    return false;
    } 


/* ************************************************************************************************* 
functions for myprofile.p
**************************************************************************************************** */
/* ----------------------------------------------------------------------
   forms processing
   ----------------------------------------------------------------------  */
function myprofile_go() {
    document.profileform.cmd.value = "submit";
    document.profileform.radlogin.value = document.profileform.email.value;
    document.profileform.radpswd.value = document.profileform.pswd1.value;
    document.profileform.submit();
    return false;
    }

/* ************************************************************************************************* 
functions for prodsrch.p
**************************************************************************************************** */
/* ----------------------------------------------------------------------
   navigation
   ----------------------------------------------------------------------  */
/* next search page */
function nxtsrchpage() {
    document.buyform.progname.value = "prodsrch.p";
    document.buyform.cmd.value = "next";
    document.buyform.submit();
    return false;
    }

/* previous search page */
function prvsrchpage() {
    document.buyform.progname.value = "prodsrch.p";
    document.buyform.cmd.value = "prev";
    document.buyform.submit();
    return false;
    }

/* --------------------------------------------------------------------
   form processing
   -------------------------------------------------------------------- */
/* resubmit search page and clear any selected vendor filter criteria - display all vendors */
function allvend() {
    document.linkform.progname.value = "prodsrch.p";
    document.linkform.cmd.value = "srch";
    document.linkform.vendor.value = "";
    document.linkform.major.value = document.srchform.major.value;
    document.linkform.minor.value = document.srchform.minor.value;
    document.linkform.crit1.value = document.srchform.keyword.value;
    if (document.srchform.srch[0].checked) {
        document.linkform.crit2.value = document.srchform.srch[0].value;
        }
    if (document.srchform.srch[1].checked) {
        document.linkform.crit2.value = document.srchform.srch[1].value;
        }
    if (document.srchform.srch.length == 3 && document.srchform.srch[2].checked) {
        document.linkform.crit2.value = document.srchform.srch[2].value;
        }
    document.linkform.submit();
    return false;
    }

/* resubmit search form and clear any selected major and minor category filter criteria */
function major(cat) {
    document.linkform.progname.value = "prodsrch.p";
    document.linkform.cmd.value = "srch";
    document.linkform.vendor.value = document.srchform.vendor.value;
    document.linkform.major.value = cat;
    document.linkform.minor.value = "";
    document.linkform.crit1.value = document.srchform.keyword.value;
    if (document.srchform.srch[0].checked) {
        document.linkform.crit2.value = document.srchform.srch[0].value;
        }
    if (document.srchform.srch[1].checked) {
        document.linkform.crit2.value = document.srchform.srch[1].value;
        }
    if (document.srchform.srch.length == 3 && document.srchform.srch[2].checked) {
        document.linkform.crit2.value = document.srchform.srch[2].value;
        }
    document.linkform.submit();
    return false;
    }

/* submit search form with user filter criteria */
function prodsrch() {
    document.linkform.progname.value = "prodsrch.p";
    document.linkform.cmd.value = "srch";
    document.linkform.vendor.value = document.srchform.vendor.value;
    document.linkform.major.value = document.srchform.major.value;
    document.linkform.minor.value = document.srchform.minor.value;
    document.linkform.crit1.value = document.srchform.keyword.value;
    if (document.srchform.searchtype.checked) {
        document.linkform.searchtype.value = "YES";
        }
    if (!document.srchform.searchtype.checked) {
        document.linkform.searchtype.value = "NO";
        }
    if (document.srchform.srch[0].checked) {
        document.linkform.crit2.value = document.srchform.srch[0].value;
        }
    if (document.srchform.srch[1].checked) {
        document.linkform.crit2.value = document.srchform.srch[1].value;
        }
    if (document.srchform.srch.length == 3 && document.srchform.srch[2].checked) {
        document.linkform.crit2.value = document.srchform.srch[2].value;
        }
    document.linkform.submit();
    return false;
    }

/* process buyform to allow user to change sort criteria */
function prodsrchord(so) {
    document.buyform.progname.value = "prodsrch.p";
    document.buyform.cmd.value = "srch";
    document.buyform.vendor.value = document.srchform.vendor.value;
    document.buyform.major.value = document.srchform.major.value;
    document.buyform.minor.value = document.srchform.minor.value;
    document.buyform.sortorder.value = so;
    document.buyform.crit1.value = document.srchform.keyword.value;

    if (document.srchform.srch[0].checked) {
        document.buyform.crit2.value = document.srchform.srch[0].value;
        }
    if (document.srchform.srch[1].checked) {
        document.buyform.crit2.value = document.srchform.srch[1].value;
        }
    if (document.srchform.srch.length == 3 && document.srchform.srch[2].checked) {
        document.buyform.crit2.value = document.srchform.srch[2].value;
        }
    document.buyform.submit();
    return false;
    }


/* ************************************************************************************************* 
functions for prodinfo.p
**************************************************************************************************** */
/* ----------------------------------------------------------------------
   navigation
   ----------------------------------------------------------------------  */
/* nav from prodinfo to prodsrch with specific major/minor criteria */
function pinfospcat(maj,min) {
    document.linkform.major.value = maj;
    document.linkform.minor.value = min;
    document.linkform.progname.value = "prodsrch.p";
    document.linkform.submit();
    return false;
    }

/* nav from prodinfo to prodsrch with no major/minor criteria */
function pinfoallcat() {
    document.linkform.major.value = "";
    document.linkform.minor.value = "";
    document.linkform.progname.value = "prodsrch.p";
    document.linkform.submit();
    return false;
    }

/* ************************************************************************************************* 
functions for mypastbuys.p
**************************************************************************************************** */
/* ----------------------------------------------------------------------
   navigation
   ----------------------------------------------------------------------  */
function mypastbuys_nxt() {
    document.buyform.progname.value = "mypastbuys.p";
    document.buyform.cmd.value = "next";
    document.buyform.submit();
    return false;
    }

function mypasybuys_prv() {
    document.buyform.progname.value = "mypastbuys.p";
    document.buyform.cmd.value = "prev";
    document.buyform.submit();
    return false;
    }

/* --------------------------------------------------------------------
   form processing
   -------------------------------------------------------------------- */
/* change myitems checkbox */
function mypasybuys_itemsper() {
    if (document.itemsperpage.justmyitems.checked) {
        document.itemsperpage.justmyitems.value = "YES";
        }
    if (!document.itemsperpage.justmyitems.checked) {
        document.itemsperpage.justmyitems.value = "NO";
        }
    document.itemsperpage.submit();
    return false;
    }


/* ************************************************************************************************* 
functions for supplier.p and suppliercat.p
**************************************************************************************************** */
/* ----------------------------------------------------------------------
   navigation
   ----------------------------------------------------------------------  */
function supplier_rpt_bad(vndr) {
    document.linkform.progname.value = "supplier.p";
    document.linkform.cmd.value = "report";
    document.linkform.arg.value = vndr;
    document.linkform.submit()
    return false;
    }

function supplier_badlink() {
    document.linkform.progname.value = "supplier.p";
    document.linkform.cmd.value = "badlink";
    document.linkform.submit()
    return false;
    }

function suppliercat_rpt_bad(vndr) {
    document.linkform.progname.value = "suppliercat.p";
    document.linkform.cmd.value = "report";
    document.linkform.arg.value = vndr;
    document.linkform.submit()
    return false;
    }

function suppliercat_badlink() {
    document.linkform.progname.value = "suppliercat.p";
    document.linkform.cmd.value = "badlink";
    document.linkform.submit()
    return false;
    }


/* ************************************************************************************************* 
functions for shopping.p - shopping cart
**************************************************************************************************** */
/* ----------------------------------------------------------------------
   forms processing
   ----------------------------------------------------------------------  */
function shopping_ckout() {
    document.linkform.cmd.value = "";
    document.linkform.progname.value = "checkout.p";
    document.linkform.submit();
    return false;
    }

function shopping_clr() {
    if (confirm("Are you sure you want to completely empty your shopping cart?")) {
        document.shopform.cmd.value = "clear";
        document.shopform.submit();
        }
    return false;
    }

function shopping_updt() {
    document.shopform.cmd.value = "update";
    document.shopform.submit();
    return false;
    }


/* ************************************************************************************************* 
functions for thanks.p
**************************************************************************************************** */
/* ----------------------------------------------------------------------
   general functions
   ----------------------------------------------------------------------  */
function thanks_print(conum,docnum) {
    winargs = "resizable=yes,scrollbars=yes,menubar=yes,width=600,height=480,left=" + lpos + ",top=" + tpos;
    PopWin = window.open("orderprt.p?conum="+conum+"&docnum="+docnum,"pwin",winargs);
    PopWin.focus();
    }

