// Copyright (c) 2004 by One Degree, LLC. All rights reserved worldwide.
// Common.js
// -----------------------------------------------------------------------
var waitwin=null;
var wwin;
var aC = new Array();       // category cache array
var aI = new Array();       // item cache array
var aHN = new Array();   // horizontal nav cache array
var aP = new Array();       // pages cache array
var aD = new Array();       // document cache array
var aG = new Array();       // gallery cache array
var aX = new Array();       // collection cache array
var aM = new Array();       // image cache array
var aV = new Array();       // variation array, global - obsolete, needed for interim
var aVSet = new Array();    // variation set array, see loadvset() and vsnode()
var aVData = new Array();       // variation data array, for single variation, see
var aRP = new Array();
var aProp = new Array();
var afx = new Array();      // form vars
var aCode = new Array();

var allowalldivs = false;
// Shadow settings
var navshadow = "";
var popupshadow = "";
var rpshadow = "";
if (applynavshadow && applynavshadow == true) {
    navshadow = "filter:progid:DXImageTransform.Microsoft.Shadow(color=" +shadowcolor + ", Direction=135, Strength=4);";
}
if (applypopupshadow == true) {
    popupshadow = "filter:progid:DXImageTransform.Microsoft.Shadow(color=" +shadowcolor + ", Direction=135, Strength=4);";
}
if (applyrpshadow == true) {
    rpshadow = "filter:progid:DXImageTransform.Microsoft.Shadow(color=" +shadowcolor + ", Direction=135, Strength=2);";
}

// browser detection
var ie = (document.all);
var ns = (document.layers);
var wc = (document.getElementById);
var is = new Is();

// Special keycodes for keystroke checking
var aKeys = new Array();
aKeys[0] = 3;           //  ctrl-C
aKeys[1] = 8;           // backspace
aKeys[2] = 9;           // tab
aKeys[3] = 13;          // enter
aKeys[4] = 16;          // shift
aKeys[5] = 17;          // ctrl
aKeys[6] = 18;          // alt
aKeys[7] = 20;          // capslock
aKeys[8] = 22;          //  ctrl-V
aKeys[9] = 24;          //  ctrl-X
aKeys[10] = 46;  // delete
aKeys[11] = 52;  // dollar sign
aKeys[12] = 91;  // windows key
aKeys[13] = 110;    // decimal point (on keypad)
aKeys[14] = 144;     // numlock
aKeys[15] = 190;     //  period (on keyboard)

// afx slot assignments - must match dims.asp list
var fxuid = 0;
var fxclientid = 1;
var fxprofid = 2;
var fxprofname = 3;
var fxcxt = 4;
var fxtableh = 5;
var fxact = 6;
var fxgs = 7;
var fxgc = 8;
var fxgp = 9;
var fxby1 = 10;
var fxby2 = 11;
var fxpreview = 12;
var fxe = 13;
var fxcs = 14;
var fxpoptop = 15;
var fxsd = 16;
var fxsno = 17;
var fxcatid = 18;
var fxprodid = 19;
var fximageid = 20;
var fxcatimage = 21;
var fxcatclick = 22;
var fxcatname = 23;
var fxprodname = 24;
var fxrprice = 25;
var fxsprice = 26;
var fxpex = 27;
var fxqex = 28;
var fxsubst = 29;
var fxpv = 30;
var fxxc = 31;
var fxpstrat = 32;
var fxqstrat = 33;
var fxpf = 34;
var fxolist = 35;
var fxqops = 36;
var fxqid = 37;
var fxwork_qid = 38;
var fxaddflag = 39;
var fxaddmode = 40;
var fxos = 41;
var fxrpstring = 42;
var fxcvnav = 43;
var fxnotax = 44;
var fxhpage = 45;
var fxkeypg = 46;
var fxpg = 47;
var fxsec = 48;
var fxxstyle = 49;
var fxxtype = 50;
var fxxvalue = 51;
var fxhst = 52;
var fxpageid = 53;
var fxship = 54;
var fxectop = 55;
var fxwork_qty = 56;
var fxwork_ochoices = 57;
var fxwork_savings = 58;
var fxwork_cprice = 59;
var fxwork_qtotal = 60;
var fxocstr = 61;
var fxoldcxt = 62;
var fxod = 63;
var fxud = 64;
var fxord = 65;
var fxtx = 66;
var fxdis = 67;
var fxpt = 68;
var fxnos = 69;
var fxpickimg = 70;
var fxnoship = 71;
var fxsubc = 72;
var fxxtx = 73;
var fxxshp = 74;
var fxstot = 75;
var fxxtot = 76;
var fxs = 77;
var fxstran = 78;
var fxcoup = 79;
var fxrmsg = 80;
var fxprofdata = 81;
var fxprofedit = 82;
var fxdel = 83;
var fxadm = 84;
var fxifa = 85;
var fxifaqs = 86;
var fxupd = 87;
var fxz = 88;
var fximage_file = 89;
var fxepg = 90;
var fxst = 91;
var fxc = 92;
var fxnewuid = 93;
var fxsource = 94;
var fxxid = 95;
var fxtest = 96;
var fxcxcxt = 97;
var fxbgpic = 98;
var fxnf = 99;

function vsnode(vrn) {
  if (vrn.length > 0) {
    av = vrn.split("|");
    this.vid = av[0];
    this.vname = av[1];
    this.vpattern = av[2];
    this.vdata = av[3];
  }

//  var spot = vrn.indexOf("/");
//  this.ovpair = "";               // option-value pair:   <option id>:<value id>
//  this.atstring = "";         // attribute string: <2-char code><value>,<...>,...
//  if (spot > -1) {
//      this.ovpair = vrn.substring(0,spot-1);
//      this.atstring = vrn.substring(spot+1,999);
//  }
}

function isnum(e, nozero) {
  // allows only those keystrokes that are valid for numeric input
  // Numeric textboxes must have:  onkeydown="return isnum(event);"
  // If currency, follow with onblur call to toFormatted().
  var k = e.keyCode?e.keyCode:e.charCode?e.charCode:e.which?e.which:void 0;

    // if we need the actual key character:
    //  var key;
    //      if (k) {
    //      key = String.fromCharCode(k);
    //  }
  return chknum(k,nozero);
}

function chknum(k,nz) {
    var ok = false;
    // valid keycode ranges for numbers: 33-40, 48-57, 96-105
    iszero = (k==48 || k==96);
    ok = ((k >= 33 && k <= 40) || (k >= 48 && k <= 57) || (k >= 96 && k <= 105));
    ok = ((iszero==true) && (nz==1))?false:ok;
    if (!ok) {
        for (var i=0;i<aKeys.length;i++) {
            if (k==aKeys[i]) {
                ok = true;
                break;
            }
        }
    }
    if (ok) {
        // Assumptions:
        //      - save changes buttons, if present, are always called sub1, sub2
        //      - if sub1 exists, sub2 also exists
        var df = document.form1;
        if (df.sub1) {
            df.sub1.disabled = false;
            df.sub2.disabled = false;
            df.sub1.style.cursor = (is.pointer)?"pointer":"hand";
            df.sub2.style.cursor = (is.pointer)?"pointer":"hand";
        }
    }
    return ok;
}

function IsNumeric(sText) {
  // general function for numeric input
  var ValidChars = "0123456789.";
  var IsNumber=true;
  var Char;
  for (i = 0; i < sText.length && IsNumber == true; i++) {
    Char = sText.charAt(i);
    if (ValidChars.indexOf(Char) == -1) {
      IsNumber = false;
    }
  }
  return IsNumber;
}

function trappaste(e,nozero) {
  var pdata = window.clipboardData.getData("Text");
  pdata = trim(pdata);
  ad = pdata.split("");
  okpaste = true;
  for (var j=0;j<ad.length;j++) {
    thisk = ad[j].charCodeAt(0);
    okpaste = chknum(thisk,nozero);
    if (!okpaste) {
      break;
    }
  }
  return okpaste;
}

String.prototype.replace_old = function(ftext,rtext,dbg) {
    var o = new String(this);
    var pos = 0;
    var len = ftext.length;

    // check for ftext within rtext, to avoid an infinite loop
    var frpos = rtext.indexOf(ftext);
    if (frpos == -1) {
        // ok to proceed
        pos = o.indexOf(ftext);
        var workstr = o;
        while (pos != -1) {
            pre = o.substring(0,pos);
            post = o.substring(pos+len,o.length);
            o = pre + rtext + post;
            pos = o.indexOf(ftext);
        }
    } else {
        // brute force it?
    }
    return o;
}

String.prototype.replace = function(ftext,rtext,dbg) {
    // new version
    var o=new String(this);
    var pos=0, len=ftext.length, res="";

    // check for ftext within rtext, to avoid an infinite loop
    var frpos = rtext.indexOf(ftext);
    if (frpos == -1) {
        // ok to proceed
        pos = o.indexOf(ftext);
        while (pos != -1) {
            res += o.substring(0,pos) + rtext;
            o = o.substring(pos+len,o.length);
            pos = o.indexOf(ftext);
        }
        res += o;
    } else {
        res = o;
    }
    return res;
}

String.prototype.occurs = function(ptn) {
  var o = new String(this);
  var oc = 0; // count
  for (var oi=0;oi<o.length;oi++) {
    if (o.substr(oi,ptn.length) == ptn) {
      oc++;
    }
  }
  return oc;
}

function TextDecode(pc,xbr,quotecode,showit) {
    if (!pc)      // D Page Manager bug fix
      return "";  // D
    if (!showit) {
        var showit = 0;
    }
    if (!xbr) {
        var xbr = 1;
    }
    if (!quotecode) {
        var quotecode = 0;
    }
    var crlf = (xbr==1)?"<br>":String.fromCharCode(13) + String.fromCharCode(10);

    var chunk=500;
    aCode.length = 0;
    if (pc.length<chunk){
        aCode[0] = pc;
    } else {
        var ptr = 0;
        var x="";
        var charx = "";
        var xlen = chunk;
        for (var i=0;i<10000;i++) {
            xlen = chunk;
            x = pc.substring(ptr,ptr+xlen);
            charx = x.charAt(x.length-1);
            while (charx=="1" || charx=="d") {
                xlen += 1;
                x = pc.substring(ptr,ptr+xlen);
                charx = x.charAt(x.length-1);
            }
            aCode[i] = x;
            ptr += xlen;
            if (ptr > pc.length) {
                break;
            }
        }
    }

    if (showit==1) {
        alert(pc);
    }

    for (var i=0;i<aCode.length;i++) {
        if (quotecode==0) {
            aCode[i] = aCode[i].replace("%2q","\"");
            aCode[i] = aCode[i].replace("1d2q","\"");
            aCode[i] = aCode[i].replace("1d2","\"");
            aCode[i] = aCode[i].replace("&quot;","\"");
            aCode[i] = aCode[i].replace("%1q","'");
            aCode[i] = aCode[i].replace("1d1q","'");
            aCode[i] = aCode[i].replace("1d1","'");
            aCode[i] = aCode[i].replace("&#39;","'");
            aCode[i] = aCode[i].replace("&#x27;","'");
        } else {
            aCode[i] = aCode[i].replace("\"","&#8221;");
            aCode[i] = aCode[i].replace("1d2q","&#8221;");
            aCode[i] = aCode[i].replace("1d2","&#8221;");
            aCode[i] = aCode[i].replace("'","&#39;");
            aCode[i] = aCode[i].replace("1d1q","&#39;");
            aCode[i] = aCode[i].replace("1d1","&#39;");
        }
        aCode[i] = aCode[i].replace("1d3","&");
        aCode[i] = aCode[i].replace("%20"," ");
        aCode[i] = aCode[i].replace("%crlf", crlf);
        aCode[i] = aCode[i].replace("1d4", crlf);
        aCode[i] = aCode[i].replace("1d5","<");
        aCode[i] = aCode[i].replace("1d6",">");
        aCode[i] = aCode[i].replace("1d7","…");
        aCode[i] = aCode[i].replace("1d8","&#233;");
    }

    var pcres = "";
    for (var i=0;i<aCode.length;i++) {
        pcres += aCode[i];
    }
    if (showit==1) {
        alert(pcres);
    }

    return pcres;
}

function timestamp() {
    var timenow = new Date();
    return timenow.getTime();
}

function TextEncode(pc,chunk) {
    if (!chunk) {
        var chunk=500;
    }
    aCode.length = 0;
    if (pc.length<chunk){
        aCode[0] = pc;
    } else {
        var ptr = 0;
        var x="";
        var charx = "";
        var xlen = chunk;
        for (var i=0;i<10000;i++) {
            xlen = chunk;
            x = pc.substring(ptr,ptr+xlen);
            charx = x.charAt(x.length-1);
            while (charx=="1" || charx=="d") {
                xlen += 1;
                x = pc.substring(ptr,ptr+xlen);
                charx = x.charAt(x.length-1);
            }
            aCode[i] = x;
            ptr += xlen;
            if (ptr > pc.length) {
                break;
            }
        }
    }

    for (var i=0;i<aCode.length;i++) {
        aCode[i] = aCode[i].replace(String.fromCharCode(13) + String.fromCharCode(10),"1d4");
        aCode[i] = aCode[i].replace("'","1d1");
        aCode[i] = aCode[i].replace("%1q","1d1");
        aCode[i] = aCode[i].replace("1d1q","1d1");
        aCode[i] = aCode[i].replace("&#39;","1d1");
        aCode[i] = aCode[i].replace("&#x27;","1d1");
        aCode[i] = aCode[i].replace("\"","1d2");
        aCode[i] = aCode[i].replace("1d2q","1d2");
        aCode[i] = aCode[i].replace("%2q","1d2");
        aCode[i] = aCode[i].replace("&quot;","1d2");
        aCode[i] = aCode[i].replace("&","1d3");
        aCode[i] = aCode[i].replace("%26","1d3");
        aCode[i] = aCode[i].replace("%20"," ");
        aCode[i] = aCode[i].replace("%crlf","1d4");
        aCode[i] = aCode[i].replace("<","1d5");
        aCode[i] = aCode[i].replace(">","1d6");
        aCode[i] = aCode[i].replace("…","1d7");         // ellipses, = 1 character
        aCode[i] = aCode[i].replace(String.fromCharCode(233),"1d8");            // e with accent
        aCode[i] = aCode[i].replace("&#233;","1d8");
    }
    var pcres = "";
    for (var i=0;i<aCode.length;i++) {
        pcres += aCode[i];
    }
    return pcres;
}

function handleerror(msg, url, line) {
   var errstr = 'Problem:   ' + msg + '\n\n' + 'URL:   ' + url + '\n' + 'Line:   ' + line;
    var errstr2 = escape(msg + "|" + url + "|" + line + "|" + new Date() + "|");
    alert(errstr);

    var x = "<html><head><title>Script Problem</title><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'></head><body>";
    x += "<form name='eform' method='post' action='http://www.1degree.com/errors.asp'>";
    x += "<input type='hidden' name='errmsg' value='" + errstr2 + "'>" + errstr2;
    x += "<br><br><center><input type='button' value='Close window' onClick='alert(document.eform.errmsg.value);document.eform.submit();'></form></center></body></html>";

    if (ie) {
        var xMax = screen.width, yMax = screen.height;
    } else {
        if (ns) {
            var xMax = window.outerWidth, yMax = window.outerHeight;
        } else {
            var xMax = 640, yMax=480;
        }
    }
    var xOffset = (xMax - 300)/2, yOffset = (yMax - 200)/2;
// window code rem'd out - database logging has errors I haven't debugged yet
//  errorwindow=window.open('','','width=300,height=200,screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset + "'");
//  errorwindow.document.write(x);
//  errorwindow.document.close();
//  errorwindow.document.bgColor="white";
    return true;
}

function toFormatted(num) {
    orignum = num;
    if (typeof(num) != "string") {
        num = num.toString();
    }
    var newnum = "";
    var whole = "";
    var part = "";
    period = num.indexOf(".");
    whole = (period >= 0)?num.substring(0,period):num;
    part = (period >= 0)?num.substring(period+1,num.length):"";
    whole = (whole.length == 0)?"0":whole;
    while (part.length > 2) {
        partnum = part.substring(0,2) + "." + part.substring(2,part.length);
        partnum = parseFloat(partnum);
        partnum = Math.round(partnum);
        islow = (partnum < 10);
        ishigh = (partnum >= 100);
        part = partnum.toString();
        if (islow) {
            part = "0" + part;
        }
        if (ishigh) {
            whole = parseFloat(whole)+1;
            whole = whole.toString();
            part = "00";
        }
    }
    switch (part.length) {
        case 0:
            part = "00";
            break;
        case 1:
            part = part + "0";
            break;
    }
    whole = whole.replace(",","");
    if (whole.length > 3) {
        spot = whole.length;
        while (spot > 0) {
            spot -= 3;
            if (spot <= 0) {
                break;
            }
            whole = whole.substring(0,spot) + "," + whole.substring(spot, whole.length);
        }
    }
    newnum = "$" + whole + "." + part;
    return newnum;
}

function toUnformatted(num) {
    orignum = num;
    if (typeof(num) != "string") {
        num = num.toString();
    }
    num = toFormatted(num);
    num = num.replace("$","");
    num = num.replace(",","");
    return num;
}

function showclass(e) {
    var targ;
    if (!e) var e = window.event;
    if (e.target) targ = e.target;
    else if (e.srcElement) targ = e.srcElement;
    if (targ) {
        ename = targ.id;
        if (ename.length == 0) {
            ename = "[not defined]";
        }
        window.status = "Element name: " +ename + " - Classname: " + targ.className;
    }
}

function showclassinit() {
    if (showclasses) {
        window.event.cancelBubble = true;
        document.onclick = showclass;
    }
}

function rnd() {
    rnd.seed = (rnd.seed*9301+49297) % 233280;
    return rnd.seed/(233280.0);
}

function rand(digits) {
    var rx = Math.pow(10,digits);
    var res = "";
    do {
        res += Math.ceil(rnd()*rx);
        if (res.length > 5) {
            res = res.substring(0,5);
            break;
        }
    } while (res.length < 5) ;
    return res;
}

function divchg(idx) {
    // toggle for expanding/collapsing div's in clienteditor.asp
    var adminif = top.frames["adminiframe"];
    var imageif = adminif.frames["imageiframe"];
    var fileif  = adminif.frames["fileiframe"];							// helen new
    var fileupif= adminif.frames["fupliframe"];							// helen new
    var divname = "";
    var haveimageframe = (imageif)?true:false;
    var havefileframe  = (fileif)?true:false;							// helen new
    var havefileupframe  = (fileupif)?true:false;							// helen new
    //var inthisdoc = (window.name == "imageiframe") ? false : (window.name == "fileiframe") ? false : true;
    var inthisdoc = (window.name == "imageiframe" || window.name == "fileiframe" || window.name == "fupliframe") ? false : true;	// new
    var x=0;
    if (!inthisdoc && idx == -1) {
        if (document.form1.step) {
            var step = document.form1.step.value;
            divname = "div" + step;
            var obj = document.getElementById(divname);
            if (obj && imageif) {
                var idisp = obj.style.display;
                if (idisp == "none") {
                    imageif.height = 22;
                } else {
                    imageif.height = 285;
                }
            }
            if (obj && fileif) {
                var idisp = obj.style.display;
                if (idisp == "none") {
                    fileif.height = 22;
                } else {
                    fileif.height = 285;
                }
            }
        }
        return;
    }

    // up to 10 steps provided for here
    for (var i=1;i<11;i++) {
        x = (i==idx)?1:0;
        if (allowalldivs==true) {
            if (x==0) {
                continue;
            }
        }
        divname = "div" + i;
        if (!inthisdoc) {
            if (x==0) {
                // clicked on image frame's band, but this is another band, in parent
                var obj = parent.document.getElementById(divname);
            } else {
                // we want to open or close image frame's div
                var obj = document.getElementById(divname);
            }
        } else {
            var obj = document.getElementById(divname);
            if (!obj && (haveimageframe || havefileframe || havefileupframe)) {		// helen new
                for (var j=0;j<window.frames.length;j++) {
                    var obj = window.frames[j].document.getElementById(divname);
                    if (obj) {
                        // close iframe on click of another band
                        obj.style.display = "none";
              
                        if (haveimageframe) {						// helen new
                          ifo = document.getElementById("imageiframe");
                          ifo.height = 22;
                        }
                        if (havefileframe) {						// helen new
                          ifo = document.getElementById("fileiframe");			// helen new
                          ifo.height = 22;						// helen new
                        }								// helen new
                        if (havefileupframe) {						// helen new
                          ifo = document.getElementById("fupliframe");			// helen new
                          ifo.height = 22;						// helen new
		          document.body.style.overflowY="hidden";
                        }								// helen new
                        break;
                    }
                }
                continue;
            }
        }

        if (obj) {
            var ioff = true;
            if (x==0) {
                obj.style.display = "none";
            } else {
                if (obj.style.display == "none") {
                    obj.style.display = "";
                    ioff = false
                } else {
                    obj.style.display = "none";
                }
            }

            if (!inthisdoc && x==1) {
                // we've clicked inside an image band area, adjust height of  iframe
                // code requires that iframes hosting an image area be named "imageiframe"
                if (imageif && (idx==9 || idx==2 || idx==4)) { // helen added idx==4 condition
                    ifo = parent.document.getElementById("imageiframe");
                    ifh = (ioff)?22:185;
                    ifo.height = ifh;
                }
                if (fileif && (idx==10 || idx==4)) {				// helen new - start
                    ifo = parent.document.getElementById("fileiframe");
                    ifh = (ioff)?22:360;
                    ifo.height = ifh;
                }								// helen new - end
                if (fileupif && (idx==10 || idx==4 || idx==2)) {		// helen new - start
                    ifh = (ioff)?22:400;
                    ifo = parent.document.getElementById("fupliframe");
		    if (ifh==22)
		      document.body.style.overflowY="hidden";
		    else
		      document.body.style.overflowY="auto";
		    if (ifo)
		      ifo.height = ifh;
		    else {
                      parent.frames["fupliframe"].height = ifh;
		    }
                }								// helen new - end
            }
        }
    }
}

function cecursor(o,xmode,idx) {
  var x = ""
  var disp = "";
  var obj1 = new getObj("div" + idx);
  var obj2 = new getObj("divtext" + idx);
  if (obj1.style) {
    disp = obj1.style.display;
  }
  if (xmode==1) {
    o.style.cursor = (is.pointer)?"pointer":"hand";
    x = (disp=="none")?"<span class='bodytextwhite'>Click to Expand&nbsp;&nbsp;</span>":"<span class='bodytextwhite'>Click to Collapse&nbsp;&nbsp;</span>";
  }
  if (obj2.obj) {
    obj2.obj.innerHTML = x;
  }
}

//helen new for reports page - start
function recursor(o,rmode,idx, disp) {
    var x = ""
    var objR2 = new getObj("rdivtext" + idx);
    if (rmode==1) {
        o.style.cursor = (is.pointer)?"pointer":"hand";
        x = (disp=="0")?"<span class='bodytextwhite'>Click for Report&nbsp;&nbsp;</span>":"<span class='bodytextwhite'>Click to Collapse&nbsp;&nbsp;</span>";
    }
    if (objR2.obj) {
        objR2.obj.innerHTML = x;
    }
}
//helen new for reports page - end


function getObj(name,showit) {
    // Cross-browser way to get any object reference.
    // Call:  var x = new getObj('objectname');
    // Returns object x with 2 properties:
    //      x.obj = reference to the object itself - example usage: alert(x.obj.id) will show id
    //      x.style = ref to the object's style object - example: x.style.top = '20px'; will set top
    // Some object types lack a style property (e.g., iframes), so we must test for it
    // After calling getObj(), the calling code should test for x.obj to see if it has an object

    var x = "";
    if (document.getElementById) {
        x += "1"
        this.obj = document.getElementById(name);
        if (this.obj) {
        } else {
            x += "\n2"
            if (window.frames) {
                x += "\n3"
                this.obj = getObjGEBI(window,name);
            }
        }
        if (!this.obj) {
            x += "\n4"
            if (parent.document) {
                x += "\n5"
                this.obj = parent.document.getElementById(name);
            }
        }
        if (this.obj) {
                x += "\n6"
            if (this.obj.style) {
                x += "\n7"
                this.style = this.obj.style;
            }
        }
    } else {
        if (document.all)   {
                x += "\n8"
            this.obj = document.all[name];
            if (this.obj) {
            } else {
                x += "\n9"
                if (document.frames) {
                    x += "\n10"
                    this.obj = getObjIE(document,name);
                }
            }
            if (!this.obj) {
                x += "\n11"
                if (parent.document) {
                x += "\n12"
                    this.obj = parent.document.getObjIE(name);
                }
            }
            if (this.obj) {
                x += "\n13"
                if (this.obj.style) {
                x += "\n14"
                    this.style = this.obj.style;
                }
            }
        } else {
            x += "\n15"
            if (document.layers)    {
                x += "\n16"
                this.obj = getObjNN4(document,name);
                if (this.obj) {
                    x += "\n17"
                    this.style = this.obj;
                }
            }
        }
    }
    if (showit) {
        alert("Finding: " + name + "\n" + x);
    }
}

function getObjGEBI(obj,name) {
    // Special function for handling nested frames in DOM-compliant browsers, called by getObj() above.
    // Recursively explores nested frames to find named object.
    // Note - this is used for NN6+ - document.layers is NN4 only
    // Opera 7+ does not support numbered ref's in a frame array ("x[0]"). Must refer to the object
    // by name
    var x = obj.frames;
    var foundLayer,frameob,tmp;
    for (var i=0;i<x.length;i++) {
        frameob=obj.document.getElementById(x[i].name);
        if (isUndefined(frameob.document)) {
//          if (name=="imgcapcell") {alert("frameob.document is undefined, using x[i].document")}
            tmp = x[i].document.getElementById(name);
        } else {
//          if (name=="imgcapcell") {alert("using frameob.document")}
            tmp = frameob.document.getElementById(name);
        }
//      alert("tmp = " + tmp);
        if (tmp) {
            foundLayer = tmp;
        } else {
            var foframes=frameob.frames;
            if (foframes) {
                if (foframes.length) {
                    var tmp = getObjGEBI(frameob,name);
                    if (tmp) {
                        foundLayer = tmp;
                    }
                }
            }
        }
    }
    return foundLayer;
}

function getObjIE(obj,name) {
    // Special function for handling nested frames in IE, called by getObj() above.
    // Recursively explores nested frames to find named object.
    var x = obj.frames;
    var foundLayer;
    for (var i=0;i<x.length;i++) {
        var tmp = x[i].document.all(name);
        if (tmp) {
            foundLayer = tmp;
        } else {
            if (x[i].frames.length) {
                var tmp = getObjIE(x[i],name);
                if (tmp) {
                    foundLayer = tmp;
                }
            }
        }
    }
    return foundLayer;
}

function getObjNN4(obj,name) {
    // Special function for handling nested layers in NN4, called by getObj() above.
    // Recursively explores nested layers to find named layer.
    var x = obj.layers;
    var foundLayer;
    for (var i=0;i<x.length;i++) {
        if (x[i].id == name) {
            foundLayer = x[i];
        } else {
            if (x[i].layers.length) {
                var tmp = getObjNN4(x[i],name);
                if (tmp) {
                    foundLayer = tmp;
                }
            }
        }
    }
    return foundLayer;
}

function scrload(scr) {
    var newscr = "../js/temp/" + scr + ".js";
    var sHTML="<html><head><scri"+"pt language='javascript' src='" + newscr + "'></sc"+"ript></head></html>";
//alert(sHTML);
    var hiddenfrm = new getObj("hiddenfrm");
    if (hiddenfrm.obj) {
        hiddenfrm.obj.document.write(sHTML);
        hiddenfrm.obj.document.close;
    }
}

function cnode(catname, catid, parentrow, catlevel, expflag, showflag, subcatcount, publish, imageid, prodcount, priority) {
    // category cache array
    this.catname = catname;
    this.catid = catid;
    this.parentrow = parentrow;
    this.catlevel = catlevel;
    this.expflag = expflag;
    this.showflag = showflag;
    this.subcatcount = subcatcount;
    this.publish = publish;
    this.imageid = imageid;
    this.prodcount = prodcount;
    this.priority = priority;
    this.selected = false;
}

function inode(catid, prodname, prodid, publish, brand, version, priority,imageid,sku,notax,dispname,onsale) {
    // product cache array
    this.catid = catid;
    this.prodname = prodname;
    this.prodid = prodid;
    this.publish = publish;
    this.brand = brand;
    this.version = version;
    this.priority = priority;
    this.imageid = imageid;
    this.sku = sku;
    this.notax = notax;
    this.dispname = dispname;
    this.onsale = onsale;
}

function pgnode(pageid, pagename, level,pagelistv,pagelisth, cvn,pagelistb,pagelistpt,homepg,gohome,newwin,publish,pagelista) {
    // page cache array
    this.pageid = pageid;
    this.pagename = pagename;
    this.level = level;
    this.pagelistv = pagelistv;
    this.pagelisth = pagelisth;
    this.pagelistb = pagelistb;
    this.pagelistpt = pagelistpt;
    this.pagelista = pagelista;
    this.homepg= homepg;
    this.gohome = gohome;
    this.newwin = newwin;
    this.publish = publish;
    this.cvn1 = "";
    this.cvn2 = "";
    this.cvn3 = "";
    this.cvn4 = "";
    this.cvn5 = "";
    this.cvn6 = "";
    if (cvn) {
        if (cvn.length > 0) {
            var acv = cvn.split(",");
            this.cvn1 = acv[0];
            this.cvn2 = acv[1];
            this.cvn3 = acv[2];
            this.cvn4 = acv[3];
            this.cvn5 = acv[4];
            this.cvn6 = acv[5];
        }
    }
}

function docnode(docid, docname, doctype, publish) {
    // document cache array
    this.docid = docid;
    this.docname = docname;
    this.doctype = doctype;
    this.publish = publish;
}

function galnode(galid, galname, publish) {
    // gallery cache array
    this.galid = galid;
    this.galname = galname;
    this.publish = publish;
}

function hnnode(xnav) {
    // horizontal nav cache array
    if (xnav.length > 0) {
        var ax = xnav.split("|");
        this.src = ax[0];
        this.oversrc = ax[1];
        this.alt = ax[2];
        this.pageid = ax[3];        // where it goes
        this.pagelist = ax[4];  // submenu pages
        this.publish = ax[5];   // publish flag
        this.istext = (ax[0].indexOf(".gif")>0 || ax[0].indexOf(".jpg")>0)?false:true;
        this.divup = 0;
    }
}

function xnode(xid, xowner,xname, xtype, xseq, xregid, publish, xstyle, expires, perspos,xmethod,xfreeship,xaffpg,xbanner,xshipmsg,xstate) {
    // collection cache array
    this.xid = xid;
    this.xowner = xowner;
    this.xname = xname;
    this.xtype = xtype;         // eg 0=client-defined, 4=registry, 5=affiliate
    this.xseq = xseq;
    this.xregid = xregid;
    this.publish = publish;
    this.xstyle = xstyle;       //0=items,1=cats
    this.expires = expires;
    this.perspos = perspos;
    this.xmethod = xmethod;
    this.xfreeship = xfreeship;
    this.xaffpg = xaffpg;
    this.xbanner = xbanner;
    this.xshipmsg = xshipmsg;
    this.xstate = xstate;
}

function mnode(xid, xname, xcode, useorig, isgif,sizelist) {
    // image cache array
    this.imageid = xid;
    this.imagename = xname;
    this.imagecode = xcode;
    this.useorig = useorig;
    this.isgif = isgif;
    this.sizelist = sizelist;
}

function vnode(xid, xvar) {
    // variation array
    this.itemid = xid;
    this.vnstring = xvar;
}

function rpnode(rpx) {
    this.prodid = 0;
    this.title = "";
    this.text = "";
    this.sizecode = 0;
    this.showbrand = 0;
    this.brand = "";
    this.imageid = 0;
    this.prodname= "";
    if(rpx.length > 0) {
        var foundit = 0;
        var ax = rpx.split("|");
        if (parseInt(ax[0])>0) {
            for (var j=0;j<aI.length;j++) {
                if (aI[j].prodid == ax[0]) {
                    foundit = 1;
                    this.brand = aI[j].brand;
                    this.imageid = aI[j].imageid;
                    this.prodname= aI[j].prodname;
                    break;
                }
            }
        }
        if (foundit==1) {
            // if not found, the related item is not yet published
            this.prodid = parseInt(ax[0]);
            this.title = ax[1];
            this.text = ax[2];
            this.sizecode = (ax[3].length>0)?parseInt(ax[3]):1;
            this.showbrand = ax[4];
        }
    }
}

function makerp() {
    var xrp = "";
    if (document.form1.rpstring) {
        xrp = document.form1.rpstring.value;
    }
    if (xrp.length==0 && window.frames["adminiframe"]) {
        if (window.frames["adminiframe"].document.form1.rpstring) {
            xrp = window.frames["adminiframe"].document.form1.rpstring.value;
        }
    }
    if (xrp.length==0 && parent.afx[0].rpstring) {
        xrp = parent.afx[0].rpstring;
    }
    if (xrp.length>0) {
        parent.afx[0].rpstring = xrp;
        var rpstring = xrp;
        var ar = rpstring.split("^");
        var x = "";
        for (var i=0;i<ar.length;i++) {
            x = ar[i];
            if (x.length > 0) {
                aRP[i] = new rpnode(x);
            }
        }
    } else {
        for (var i=0;i<3;i++) {
            aRP[i] = new rpnode("");
        }
    }
}

function rpedit(e,b) {
    var df = document.form1;
    switch (e) {
        case 1:
        // radio button - RP number 1,2,3
            var rel = b;
            var oref = df.relnum;
            if (rel >= 0) {
                df.rel.value = rel;
                var xrp = new getObj("preview");
                if (xrp.obj) {
                    xrp.obj.innerHTML = "<span class='admintitle'>Preview for:  </span><br><span class='adminbodytextgray'>Product </span><span class='relprodnum'>" + rel + " </span>";
                }
                var xrtitle = new getObj("reltitle");
                var xrtext = new getObj("reltext");
                var xpname = new getObj("pname");
                var xptitle = new getObj("ptitle");
                var xpdesc = new getObj("pdesc");
                var xpimage = new getObj("pimage");
                if (aRP[rel-1].prodid > 0) {
                    hidecover();
                    var xsize = aRP[rel-1].sizecode;
                    df.sizecode[xsize].checked = true;

                    if (xrtitle.obj) {
                        xrtitle.obj.disabled = false;
                    }
                    if (xrtext.obj) {
                        xrtext.obj.disabled = false;
                    }
                    SetProd(aRP[rel-1].prodid);
                    rpedit(3,0);
                    if (xrtext.obj) {
                        xrtext.obj.style.textAlign="left"
                    }
                } else {
                    showcover();
                    df.reltitle.value = "";
                    df.reltext.value = "";
                    if (xpname.obj) {
                        xpname.obj.innerHTML = "";
                    }
                    if (xptitle.obj) {
                        xptitle.obj.innerHTML = "";
                    }
                    if (xpdesc.obj) {
                        xpdesc.obj.innerHTML = "";
                    }
                    if (xpimage.obj) {
                        xpimage.obj.src = "";
                    }
                    if (xrtitle.obj) {
                        xrtitle.obj.disabled = true;
                    }
                    if (xrtext.obj) {
                        xrtext.obj.disabled = true;
                        xrtext.obj.value = "\nDouble-click on a product to relate it to this category.";
                        xrtext.obj.style.textAlign="center"
                    }
                }
            }
            break;
        case 2:
        // cat list
            catchg();
            break;
        case 3:
        // product list assignment, via dblclick
            hidecover();
            var rel = df.rel.value;
            var pidx = df.selprod.selectedIndex;
            pidx = df.selprod.options[pidx].value;
            var pid = aI[pidx].prodid;
            var prname = TextDecode(aI[pidx].prodname);
            var pimg = aI[pidx].imageid;
            var newassign = 0;
            if (aRP[df.rel.value-1].prodid != pid) {
                newassign = 1;
                aRP[df.rel.value-1].prodid = pid;
                aRP[df.rel.value-1].prodname = prname;
                for (var j=0;j<aI.length;j++) {
                    if (aI[j].prodid == pid) {
                        aRP[df.rel.value-1].brand = aI[j].brand;
                        aRP[df.rel.value-1].imageid = aI[j].imageid;
                        break;
                    }
                }
            }
            df.reltitle.value = aRP[rel-1].title;
            df.reltext.value = TextDecode(aRP[rel-1].text);

            // write title, and divider line if we have a title - see title edit below, must match
            xtitle = TextDecode(aRP[rel-1].title);
            var ttable = "";
            if (xtitle.length>0) {
                ttable = "<table width='100%' cellpadding='2' cellspacing='0' border='0'><tr><td class='relprodtitle' bgcolor='"+colorrpheader+"' align='center'>"+xtitle+"</td></tr><tr><td  bgcolor='"+colorrpbody+"'><img src='../i/s.gif' border='0' height='1' width='1'></td></tr></table>";
            } else {
                ttable = "<img src='../i/s.gif' border='0' height='1' width='1'>";
            }
            xob = new getObj("ptitle");
            if (xob.obj) {
                xob.obj.innerHTML = ttable;
            }

            // write image
            var scode = aRP[rel-1].sizecode;
            if (isNaN(scode) || scode.length==0) {
                scode = 0;
            }
            scode=parseInt(scode);
            psize = (scode==0)?50:75;
            if (pimg > 0) {
                isrc = "../Client_Images/ProdImages/" + pimg + "_" + psize + ".jpg";
            } else {
                isrc = "../i/NoImage" + psize + ".gif";
            }
            var pim = new getObj("pimage");
            if (pim.obj) {
                pim.obj.src = isrc;
            }

            // write name, and following divider line
            var xbr = new getObj("showbrand");
            var xpname = new getObj("pname");
            var namestr = prname;

            if (aRP[rel-1].showbrand==1) {
                namestr += "<br>by " + aRP[rel-1].brand;
                if (xbr.obj) {
                    xbr.obj.checked = true;
                }
            } else {
                if (xbr.obj) {
                    xbr.obj.checked = false;
                }
            }
            if (xpname.obj) {
                xpname.obj.innerHTML = namestr;
            }

            // write description
            xdesc = TextDecode(aRP[rel-1].text);

            var tstr = "";
            if (xdesc.length > 0) {
                tstr += "<img src='../i/green_dot.gif' height='1' width='70' border='0' align='middle' vspace='3'><br>";
            }
            tstr += xdesc;
            xob = new getObj("pdesc");
            if (xob.obj) {
                xob.obj.innerHTML = tstr;
            }

            var xrtitle = new getObj("reltitle");
            var xrtext = new getObj("reltext");
            if (newassign == 1) {
                df.edits.value = 1;
                parent.document.form1.sub1.disabled = false;
                parent.document.form1.sub1.style.cursor = "pointer";
                if (xrtitle.obj) {
                    xrtitle.obj.disabled = false;
                }
                if (xrtext.obj) {
                    xrtext.obj.disabled = false;
                }
            }
            if (xrtext.obj) {
                xrtext.obj.style.textAlign="left";
            }
            break;
        case 4:
        // title edit
            hidecover();
            var rel = df.rel.value;
            var xtitle = df.reltitle.value;
            aRP[rel-1].title = xtitle;
            var ttable = "";
            // write title, and divider line if we have a title
            if (xtitle.length>0) {
                ttable = "<table width='100%' cellpadding='2' cellspacing='0' border='0'><tr><td class='relprodtitle' bgcolor='"+colorrpheader+"' align='center'>"+TextDecode(aRP[rel-1].title)+"</td></tr><tr><td  bgcolor='"+colorrpbody+"'><img src='../i/s.gif' border='0' height='1' width='1'></td></tr></table>";
            } else {
            ttable = "<img src='../i/s.gif' border='0' height='1' width='1'>";
            }
            xob = new getObj("ptitle");
            if (xob.obj) {
                xob.obj.innerHTML = ttable;
            }

            if (aRP[rel-1].prodid=="0" || aRP[rel-1].prodid.length==0) {
                var pim = new getObj("pimage");
                if (pim.obj) {
                    isrc = "../i/NoImage50.gif";
                    pim.obj.height=50;
                    pim.obj.width=50;
                    pim.obj.src = isrc;
                }
            }
            break;
        case 5:
        // text edit
            hidecover();
            CheckData(df.reltext,100);
            var rel = df.rel.value;
            var xdesc = df.reltext.value;
            aRP[rel-1].text = xdesc;

            // write name, and following divider line
            var tstr = "";
            if (xdesc.length > 0) {
                tstr += "<img src='../i/green_dot.gif' height='1' width='70' border='0' align='middle' vspace='3'><br>";
            }
            tstr += xdesc;
            xob = new getObj("pdesc");
            if (xob.obj) {
                xob.obj.innerHTML = tstr;
            }
            if (aRP[rel-1].prodid=="0" || aRP[rel-1].prodid.length==0) {
                isrc = "../i/NoImage50.gif";
                var xpimage = new getObj("pimage");
                if (xpimage.obj) {
                    xpimage.obj.src = isrc;
                }
            }
            break;
        case 6:
        // clear assignment
            var rel = df.rel.value;
            aRP[rel-1].prodid = "";
            aRP[rel-1].title = "";
            aRP[rel-1].text = "";
            rpedit(1,rel);
            showcover();
            break;
        case 7:
        // size code choice
            var rel = df.rel.value;
            var xob = df.sizecode;
            var scode = 0;
            if (xob) {
                if (xob[1].checked) {
                    scode = 1;
                }
            }
            var psize = (scode==0)?50:75;
            aRP[rel-1].sizecode = scode;
            rpedit(1,rel);
            break;
        case 8:
        // show brand
            var rel = df.rel.value;
            var showbrand = df.showbrand.checked;
            showbrand=(showbrand)?1:0;
            aRP[rel-1].showbrand = showbrand;
            rpedit(1,rel);
            break;
    }
    if (e >= 4) {
        df.edits.value = 1;
        parent.document.form1.sub1.disabled = false;
        parent.document.form1.sub1.style.cursor = "pointer";
    }
}

function showcover() {
    var xcover = new getObj("cover");
    if (xcover.style) {
        xcover.style.visibility = "visible";
    }
    var xclear = new getObj("clear");
    if (xclear.obj) {
        xclear.obj.disabled = true;
        xclear.style.cursor = "default";
    }
    var xbr = new getObj("showbrand");
    if (xbr.obj) {
        xbr.obj.checked = true;
    }
}

function hidecover() {
    var xcov = new getObj("cover");
    var xclear = new getObj("clear");
    if (xcov.obj) {
        xcov.style.visibility = "hidden";
        if (xclear.obj) {
            xclear.obj.disabled = false;
            xclear.style.cursor = "pointer";
        }
    }
}

function catchg() {
    var xo = new getObj("selcat");
    if (xo.obj) {
        var o = xo.obj;
        var x=o.selectedIndex;
        if (x >= 0) {
            var xidx = o.options[x].value;
            if (xidx >= 0) {
                xid = aC[xidx].catid;
                LoadProd(xid,-1);
            } else {
                var os = document.form1.selprod;
                os.options.length = 0;
            }
        }
    }
}

function LoadCat() {
    var xo = new getObj("selcat");
    var xoj = new getObj("jumpcat");

    if (xo.obj) {
        var os = xo.obj;
        os.innerHTML = "";
        os.options[0] = new Option("Select a category...",-1);
        var x = "";
        var sel = 0;
        var xid = -1;
        var rel = document.form1.rel.value;
        if (rel > 0 && aRP[rel-1].prodid > 0) {
            // find its catid
            for (var i=0;i<aI.length;i++) {
                if (aI[i].prodid == aRP[rel-1].prodid) {
                    xid = aI[i].catid;
                    break;
                }
            }
        }
        for (var i=0;i<aC.length;i++) {
            switch (aC[i].catlevel) {
                case 1:
                    x = "  ";
                    break;
                case 2:
                    x = "    ";
                    break;
                default:
                    x = "";
                    break;
            }
            catname = TextDecode(aC[i].catname);
            os.options[i+1] = new Option(x + catname ,i);
            if (aC[i].catid == xid) {
                sel = i+1;
            }
        }
        os.selectedIndex = sel;
        catchg();
        rpedit(1,rel);
    }

    if (xoj.obj) {
        var oj = xoj.obj;
        oj.innerHTML = "";
        oj.options[0] = new Option("Select a category...",-1);
        var x = "";
        var sel = 0;
        var xid = -1;
        var rel = document.form1.rel.value;
        for (var i=0;i<aC.length;i++) {
            switch (aC[i].catlevel) {
                case 1:
                    x = "  ";
                    break;
                case 2:
                    x = "    ";
                    break;
                default:
                    x = "";
                    break;
            }
            catname = TextDecode(aC[i].catname);
            oj.options[i+1] = new Option(x + catname ,i);
            if (aC[i].catid == xid) {
                sel = i+1;
            }
        }
        oj.selectedIndex = sel;
        catchg();
    }

}

function SetProd(pid) {
    // find its catid
    var xid = -1;
    for (var i=0;i<aI.length;i++) {
        if (aI[i].prodid == pid) {
            xid = aI[i].catid;
            break;
        }
    }
    //set selcat index to that category
    os = document.form1.selcat;
    for (var i=0; i<os.options.length;i++) {
        if (aC[i].catid == xid) {
            os.selectedIndex = i+1;
            break;
        }
    }
    //load products for that cat
    LoadProd(xid,pid);
}

function LoadProd(xid,pid) {
    var os = document.form1.selprod;
    os.innerHTML = "";
    var x = "";
    var sel = 0;
    var inrange = 0;
    var idx = -1;
    for (var i=0;i<aI.length;i++) {
        if (aI[i].catid == xid) {
            inrange = 1;
        } else {
            if (inrange == 1) {
                break;
            }
        }
        if (inrange==0) {
            continue;
        }
        idx += 1;
        os.options[idx] = new Option(TextDecode(aI[i].prodname),i);
        if (aI[i].prodid == pid) {
            sel = idx;
        }
    }
    if (idx >= 0) {
        os.selectedIndex = sel;
    }
}

function LoadRP() {
    var xx = "";
    var res = 0;
    var msg = "";
    var mnum = 0;
    for (var i=0;i<3;i++) {
        xx += aRP[i].prodid + "|" + TextEncode(aRP[i].title) + "|" + TextEncode(aRP[i].text) + "|" + aRP[i].sizecode +  "|" + aRP[i].showbrand +  "|^";
    }
    document.form1.rpstring.value= xx;
    return res;
}

function showproperties(oObject) {
    // test function to iterate and display all object properties
    var oname = oObject.name;
    if (!oname) {
        oname = oObject.id;
    }
    var sMsg = "Properties of "+ oname + "\n";
    aProp.length=0;
    var i=0;
    for (sProp in oObject) {
        aProp[i]=sProp + " = " + oObject[sProp];
        i += 1;
    }
    aProp.sort(gensort);
    var innercount = 0;
    for (var i=0;i<aProp.length;i++) {
        sMsg += aProp[i]+ "\n";
        innercount += 1;
        if (innercount>25) {
            alert(sMsg);
            sMsg = "";
            innercount=0;
        }
    }
    alert(sMsg);
}

function GenRP(adm) {
    // generates category image and related item content on the front side's right column.
    // Each product shown indexes here, in display order.
    // Gen 3 related product tables from that offset.
    var df = document.form1;
    makerp();
    if (!adm) {
        adm=0;
    }
    if ((adm==0 && !afx[0].catimage) || (adm==1 && !parent.afx[0].catimage)) {
        var thiscat = (adm==0)?afx[0].catid:parent.afx[0].catid;
        if (thiscat>0) {
            for (var i=0;i<aC.length;i++) {
                if (aC[i].catid == thiscat) {
                    var imgid = aC[i].imageid;
                    break;
                }
            }
        } else {
            return;
        }
    } else {
        var imgid = (adm==0)?afx[0].catimage:parent.afx[0].catimage;
    }

    if (imgid > 0) {
        imgid = parseInt(imgid);
    } else {
        return;
    }
    imouse = "";
    iclick = "";
    img = "";
    var catname = (adm==0)?TextDecode(afx[0].catname,1,1):TextDecode(parent.afx[0].catname,1,1);
    ialt = " Category: " + catname;

    // this is going to be switchable by the admin, default on for now
    var spht=8;
    if (showcatimage) {
        if (imgid == 0) {
            img = "../i/NoImage50.gif";
        } else {
            img = "../Client_Images/CatImages/" + imgid + "_50.jpg";
        }
        var iclick="",imouse="",ialt="";
//      alert(adm + "\n" + afx[0].catclick);
        if ((adm==0 && afx[0].catclick==1) || (adm==1 && parent.afx[0].catclick==1)) {
            iclick = "saveexp(0,"+((adm==0)?afx[0].catid:parent.afx[0].catid) + ",0)";
            imouse = "chgcursor(this,1,-1)";
            ialt = "Jump to " + catname + " Category";
        }

        var x = "<table width='100' cellspacing='0' cellpadding='0' border='0'><tr><td width='25' align='center'><img src='../i/s.gif' border='0' height='1' width='25'></td><td width='50' height='"+spht+"' align='center' background='" + img + "'><img src='../i/mask.gif' border='0' onclick='" + iclick + "' onmouseover='" +imouse + "' alt=\"" + ialt + "\"></td><td width='25' align='center'><img src='../i/s.gif' border='0' height='1' width='25'></td></tr><tr><td align='center' colspan='3' class='orderproductsku'>"+catname+"</td></tr></table>";
    } else {
        var x = "<table width='100' cellspacing='0' cellpadding='0' border='0'><tr><td width='25' align='center'><img src='../i/s.gif' border='0' height='1' width='25'></td><td width='50' height='"+spht+"' align='center'><img src='../i/s.gif' border='0' height='"+spht+"' width='1'></td><td width='25' align='center'><img src='../i/s.gif' border='0' height='1' width='25'></td></tr><tr><td align='center' colspan='3' class='orderproductsku'></td></tr></table>";
    }

    var xcell = new getObj("catimagecell");
    if (xcell.obj) {
        xcell.obj.innerHTML = x;
    }
    x = "";
    var ptitle = "", pimg = "", pname = "", ptext = "", pid = "", newx = "";
    var psize = -1, psizex = -1, haverp = 0;

    var rplen = (adm==0)?aRP.length:parent.aRP.length;
    var p = parent;

    for (var i=0;i<rplen;i++) {
        newx = "";
        if (adm==0) {
            pid = aRP[i].prodid;
            ptitle = aRP[i].title;
            ptext = aRP[i].text;
            pname = aRP[i].prodname;
            psize = aRP[i].sizecode;
            showbrand = aRP[i].showbrand;
            pbrand = aRP[i].brand;
            pimg = aRP[i].imageid;
        } else {
            pid = p.aRP[i].prodid;
            ptitle = p.aRP[i].title;
            ptext = p.aRP[i].text;
            pname = p.aRP[i].prodname;
            psize = p.aRP[i].sizecode;
            showbrand = p.aRP[i].showbrand;
            pbrand = p.aRP[i].brand;
            pimg = p.aRP[i].imageid;
        }

        psize = (psize==0)?"50":"75";
        psizex = (psize==75)?"75":"50";

        pimg = (pimg > 0)?"../Client_Images/ProdImages/" + pimg + "_" + psizex + ".jpg":"../i/NoImage" + psize + ".gif";
        if (pid > 0) {
            haverp = 1;
            rpshadow = "";
            if (applyrpshadow==true) {
                rpshadow = "filter:progid:DXImageTransform.Microsoft.Shadow(color=#666666, Direction=135, Strength=2);"
            }
            newx += "<table style='border:1px solid " + colorrpouterborder + ";" + rpshadow + "' align='center' width='100' cellspacing='0' cellpadding='3' border='0'><tr><td align='center' bgcolor='"+colorrpbackground+"'><table style='border:1px solid "+colorrpinnerborder+";' align='center' width='94' cellspacing='0' cellpadding='2' border='0'><tr><td id='ptitle' bgcolor='FFFFFF'>";
            var pttrim = ptitle.replace(" ","");
            if (pttrim.length>0) {
                newx += "<table width='100%' cellpadding='2' cellspacing='0' border='0'><tr><td class='relprodtitle' bgcolor='"+colorrpheader+"' align='center'>"+ptitle+"</td></tr><tr><td  bgcolor='"+colorrpbody+"'><img src='../i/s.gif' border='0' height='1' width='1'></td></tr></table>";
            }
            var pn = TextDecode(pname);
            newx += "</td></tr><tr><td align='center' bgcolor='"+colorrpbody+"'><table width='"+psize+"' height='"+psize+"' cellpadding='0' cellspacing='0' border='0'><tr><td background='"+pimg+"'><img id='pimage' src='../i/image_locked.gif' border='"+rpimageborder+"' height='"+psize+"' width='"+psize+"'  onMouseOver='chgcursor(this,1,-1)' onclick='rpgo("+pid+")' alt=\""+TextDecode(pname,1,1)+"\"></td></tr></table></td></tr><tr><td id='pname' class='relprodname' align='center' bgcolor='"+colorrpbody+"'>"+pn + "</td></tr><tr><td id='pdesc' class='relprodtext'  bgcolor='"+colorrpbody+"' valign='top'>";

            if (ptext.length > 0) {
                newx += "<img src='../i/green_dot.gif' height='1' width='70' border='0' align='middle' vspace='3'><br>";
            }
            newx += ptext+"</td></tr></table></td></tr></table><img src='../i/s.gif' height='5' width='100' border='0'><br>";
        }
        x += newx;
    }

    if (haverp==1) {
        if (!rpsectiontitle) {
            rpsectiontitle = "Related Items";
        }
        x = "<table align='center' width='100' cellspacing='0' cellpadding='0' border='0'><tr><td align='center' class='salecaption'>"+rpsectiontitle+"</td></tr></table><br>" + x;
    }

    var xrp = new getObj("rptable");
    if (xrp.obj) {
        xrp.obj.innerHTML = x;
    }
}

function noquotes(str) {
    // eliminate single quotes by adding slashes
    str = TextDecode(str);
    if (str.indexOf("'")>-1) {
        str = str.replace(/\'/g, "\'");
    }
    if (str.indexOf("\"")>-1) {
        str = str.replace(/\"/g, "\\\"");
    }

    return str;
}

function codedump(x) {
    var xdbs = new getObj("dbspacer");
    var xdba = new getObj("dbarea");
    if (xdbs.obj) {
        xdbs.obj.innerHTML = "<img src='../i/s.gif' height='1' width='"+(vnavdivleft+20)+"' border='0'>";
    }
    if (x && xdba.obj) {
        xdba.obj.innerHTML = "<code>" + x + "</code>";
    }
}

function Is() {
    var agt=navigator.userAgent.toLowerCase();
    // --- BROWSER VERSION ---
    var navver = navigator.appVersion;
    this.major = stringToNumber(navver);
    this.minor = parseFloat(navver);

    // used in code
    this.nav  = ((agt.indexOf('mozilla')!=-1) && ((agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1)));
    this.ie   = (agt.indexOf("msie") != -1);
    this.app = navigator.appName;
    this.version = parseFloat(navver);
    var navua = navigator.userAgent;
    this.platform = navigator.platform;
    if (navver.indexOf("MSIE")!=-1) {
        var temp=navver.split("MSIE");
        this.version=parseFloat(temp[1]);
    }
    this.ie6 = (this.version==6)?true:false;
    this.opera6 = ((navua.indexOf("Opera 6")!=-1) || (navua.indexOf("Opera/6")!=-1))?true:false;
    this.pointer = (!this.ie || this.ie6);
    this.report = this.app + ", version " + this.version + " on " + this.platform + "\nFull version: " + navver;

    // others
    this.nav2 = (this.nav && (this.major == 2));
    this.nav3 = (this.nav && (this.major == 3));
    this.nav4 = (this.nav && (this.major == 4));

    //Netscape 6
    this.nav5 = (this.nav && (this.major == 5));
    this.nav6 = (this.nav && (this.major == 5));
    this.gecko = (this.nav && (this.major >= 5));

    this.ie3  = (this.ie && (this.major == 2));
    this.ie4  = (this.ie && (this.major == 3));
    this.ie5  = (this.ie && (this.major == 4));
    this.opera = (agt.indexOf("opera") != -1);
    this.nav4up = this.nav && (this.major >= 4);
    this.ie4up  = this.ie  && (this.major >= 4);
}

function stringToNumber(s) {
    return parseInt(('0' + s), 10);
}

//new start - test
function showwait(msg,upone) {
// show wait message
	//var rootlead = "../"; //helen commented old no need remove later
	//if (upone) {
	//	rootlead = "../../";
	//}
if (showpopupwait) {	
	if (msg) {
		if (msg.length>0) {
			//var hfile = rootlead + "/\incs/loading.asp?msg=" + msg;//helen commented old no need - remove after testing
			var hfile = "/incs/loading.asp?msg=" + msg;
		}
	} else {
		//var hfile = rootlead + "incs/loading.asp";//helen commented old no need - remove after testing
		var hfile = "/incs/loading.asp";
	}
	var h = screen.height //height of screen, not just the parent window
	var w = screen.width //width of the screen
	var popw = 200;
	var poph = 60;
	var browserName=navigator.appName;                            // helen new - browser detection
	var browserAgent=navigator.userAgent;                         // helen new  
	if (browserName=="Netscape")                                  // helen new  
	{                                                             // helen new  
		if(browserAgent.indexOf("Netscape")!=-1) poph = 240;  // helen new  
		if(browserAgent.indexOf("Firefox")!=-1) poph = 130;   // helen new  
	}                                                             // helen new  
	var l = parseInt((w-popw)/2);
	var t = parseInt((h-poph)/2);
	waitwin = window.open(hfile,"wwin","width="+popw+",height="+poph+",left="+ l + ",top="+t+",toolbar=no");//helen note comment if don't need popup showwait
}	
	return true;
}

function closewait() {// helen note if everything is working remove this function and all calls of it
	// clear wait message
	//testwin = window.open("","wwin","top=1000,height=5,width=5,toolbar=no");
	//self.focus();
	//if (typeof(testwin) == "object") 
	//  testwin.close();
}
//new end - test
function gensort(a,b){
    // general sort of array of strings
    // call with arrayname.sort(gensort);
    var astr = a.toLowerCase();
    var bstr = b.toLowerCase();
    if (astr > bstr) {
        return 1;
    } else {
        if (astr < bstr) {
            return -1;
        } else {
            return 0;
        }
    }
}

function dbug(dbmsg) {
    var dbs = new getObj("dbspacer");
    var dbx = new getObj("dbarea");
    if (dbs.obj) {
        dbs.obj.innerHTML = "<img src='../i/s.gif' height='1' width='160' border='0'>";
    }
    if (dbx.obj) {
        var oldtext = dbx.obj.innerHTML + "<br>";
        dbx.obj.innerHTML = oldtext + dbmsg;
    }
}

function sizetofit() {
    var winWidth = window.outerWidth ? window.outerWidth : document.body && document.body.clientWidth ? document.body.clientWidth : null;
    if (winWidth>0) {
        var tblwidth = winWidth-31;
        var xtbl = new getObj("maintbl");
        if (xtbl.obj) {
            xtbl.obj.width=tblwidth;
        }
    }
    var docHeight = document.height ? document.height : document.body && document.body.scrollHeight ? document.body.scrollHeight : null;
    if (winWidth && docHeight) {
        if (docHeight) {
            docHeight += 50;
            docHeight = Math.max(docHeight,10);
            docHeight = Math.min(docHeight,screen.height-50);
        }
        self.resizeTo(winWidth,docHeight)
    }
}

function makefx(clientid) {
    var df = document.form1;
    if (clientid) {
        afx[0] = new fxnode("");
        afx[0].clientid = clientid;
    } else {
        if (df.fx) {
            afx[0] = new fxnode(df.fx.value);
        } else {
            afx[0] = new fxnode("");
        }
    }
}

function showfx() {
    var fx = "";
    fx += "uid = " + afx[0].uid + "\n";
    fx += "clientid = " + afx[0].clientid + "\n";
    fx += "profid = " + afx[0].profid + "\n";
    fx += "profname = " + afx[0].profname + "\n";
    fx += "context = " + afx[0].cxt + "\n";
    fx += "h = " + afx[0].tableh + "\n";
    fx += "act = " + afx[0].act + "\n";
    fx += "gs = " + afx[0].gs + "\n";
    fx += "gc = " + afx[0].gc + "\n";
    fx += "gp = " + afx[0].gp + "\n";
    fx += "by1 = " + afx[0].by1 + "\n";
    fx += "by2 = " + afx[0].by2 + "\n";
    fx += "preview = " + afx[0].preview + "\n";
    fx += "e = " + afx[0].e + "\n";
    fx += "cs = " + afx[0].cs + "\n";
    fx += "poptop = " + afx[0].poptop + "\n";
    fx += "sd = " + afx[0].sd + "\n";
    fx += "sno = " + afx[0].sno + "\n";
    fx += "catid = " + afx[0].catid + "\n";
    fx += "prodid = " + afx[0].prodid + "\n";
    fx += "imageid = " + afx[0].imageid + "\n";
    fx += "catimage = " + afx[0].catimage + "\n";
    fx += "catclick = " + afx[0].catclick + "\n";
    fx += "catname = " + afx[0].catname + "\n";
    fx += "prodname = " + afx[0].prodname + "\n";
    alert(fx);

    fx = "rprice = " + afx[0].rprice + "\n";
    fx += "sprice = " + afx[0].sprice + "\n";
    fx += "pex = " + afx[0].pex + "\n";
    fx += "qex = " + afx[0].qex + "\n";
    fx += "subst = " + afx[0].subst + "\n";
    fx += "pv = " + afx[0].pv + "\n";
    fx += "xc = " + afx[0].xc + "\n";
    fx += "pstrat = " + afx[0].pstrat + "\n";
    fx += "qstrat = " + afx[0].qstrat + "\n";
    fx += "pf = " + afx[0].pf + "\n";
    fx += "olist = " + afx[0].olist + "\n";
    fx += "qops = " + afx[0].qops + "\n";
    fx += "qid = " + afx[0].qid + "\n";
    fx += "work_qid = " + afx[0].work_qid + "\n";
    fx += "addflag = " + afx[0].addflag + "\n";
    fx += "addmode = " + afx[0].addmode + "\n";
    fx += "os = " + afx[0].os + "\n";
    fx += "rpstring = " + afx[0].rpstring + "\n";
    fx += "cvnav = " + afx[0].cvnav + "\n";
    fx += "notax = " + afx[0].notax + "\n";
    fx += "hpage = " + afx[0].hpage + "\n";
    fx += "keypg = " + afx[0].keypg + "\n";
    fx += "pg = " + afx[0].pg + "\n";
    fx += "sec = " + afx[0].sec + "\n";
    fx += "xstyle = " + afx[0].xstyle + "\n";
    fx += "xtype = " + afx[0].xtype + "\n";
    fx += "xvalue = " + afx[0].xvalue + "\n";
    alert(fx);

    fx = "hst = " + afx[0].hst + "\n";
    fx += "pageid = " + afx[0].pageid + "\n";
    fx += "ship = " + afx[0].ship + "\n";
    fx += "ectop = " + afx[0].ectop + "\n";
    fx += "work_qty = " + afx[0].work_qty + "\n";
    fx += "work_ochoices = " + afx[0].work_ochoices + "\n";
    fx += "work_savings = " + afx[0].work_savings + "\n";
    fx += "work_cprice = " + afx[0].work_cprice + "\n";
    fx += "work_qtotal = " + afx[0].work_qtotal + "\n";
    fx += "ocstr = " + afx[0].ocstr + "\n";
    fx += "oldcxt = " + afx[0].oldcxt + "\n";
    fx += "od = " + afx[0].od + "\n";
    fx += "ud = " + afx[0].ud + "\n";
    fx += "ord = " + afx[0].ord + "\n";
    fx += "tx = " + afx[0].tx + "\n";
    fx += "dis = " + afx[0].dis + "\n";
    fx += "pt = " + afx[0].pt + "\n";
    fx += "nos = " + afx[0].nos + "\n";
    fx += "pickimg = " + afx[0].pickimg + "\n";
    fx += "noship = " + afx[0].noship + "\n";
    fx += "subc = " + afx[0].subc + "\n";
    fx += "xtx = " + afx[0].xtx + "\n";
    fx += "xshp = " + afx[0].xshp + "\n";
    fx += "stot = " + afx[0].stot + "\n";
    alert(fx);

    fx = "xtot = " + afx[0].xtot + "\n";
    fx += "s = " + afx[0].s + "\n";
    fx += "stran = " + afx[0].stran + "\n";
    fx += "coup = " + afx[0].coup + "\n";
    fx += "rmsg = " + afx[0].rmsg + "\n";
    fx += "profdata = " + afx[0].profdata + "\n";
    fx += "profedit = " + afx[0].profedit + "\n";
    fx += "del = " + afx[0].del + "\n";
    fx += "adm = " + afx[0].adm + "\n";
    fx += "ifa = " + afx[0].ifa + "\n";
    fx += "ifaqs = " + afx[0].ifaqs + "\n";
    fx += "upd = " + afx[0].upd + "\n";
    fx += "z = " + afx[0].z + "\n";
    fx += "image_file = " + afx[0].image_file + "\n";
    fx += "epg = " + afx[0].epg + "\n";
    fx += "st = " + afx[0].st + "\n";
    fx += "c = " + afx[0].c + "\n";
    fx += "newuid = " + afx[0].newuid + "\n";
    fx += "source = " + afx[0].source + "\n";
    fx += "xid = " + afx[0].xid + "\n";
    fx += "test = " + afx[0].test + "\n";
    fx += "cxcxt = " + afx[0].cxcxt + "\n";
    fx += "bgpic = " + afx[0].bgpic + "\n";
    fx += "nf = " + afx[0].nf + "\n";
    alert(fx);
}

function fxnode(fxstr) {
    if (fxstr.length > 0) {
        var af = fxstr.split("::");
    } else {
        var af = new Array();
        af[fxact] = "";
        af[fxaddflag] = 0;
        af[fxaddmode] = "";
        af[fxby1] = "";
        af[fxby2] = "";
        af[fxcatclick] = 0;
        af[fxcatid] = -1;
        af[fxcatimage] = -1;
        af[fxcatname] = "";
        af[fxclientid] = -1;
        af[fxxstyle] = 0;
        af[fxcs] = "";
        af[fxcvnav] = "";
        af[fxcxt] = "";
        af[fxe] = "";
        af[fxxtype] = 0;
        af[fxxvalue] = "";
        af[fxgc] = -1;
        af[fxgp] = -1;
        af[fxgs] = -1;
        af[fxhpage] = -1;
        af[fxhst] = "";
        af[fximageid] = -1;
        af[fxkeypg] = -1;
        af[fxnotax] = "";
        af[fxolist] = "";
        af[fxos] = "";
        af[fxpageid] = 0;
        af[fxpex] = "";
        af[fxpf] = "";
        af[fxpg] = -1;
        af[fxpoptop] = -1;
        af[fxpreview] = "";
        af[fxprodid] = -1;
        af[fxprodname] = "";
        af[fxprofid] = -1;
        af[fxprofname] = "";
        af[fxpstrat] = "";
        af[fxpv] = "";
        af[fxqex] = "";
        af[fxqid] = -1;
        af[fxqops] = "";
        af[fxqstrat] = "";
        af[fxrprice] = 0;
        af[fxrpstring] = "";
        af[fxsd] = "";
        af[fxsec] = 0;
        af[fxsno] = "";
        af[fxsprice] = 0;
        af[fxsubst] = "";
        af[fxtableh] = -1;
        af[fxuid] = -1;
        af[fxwork_qid] = -1;
        af[fxxc] = "";
        af[fxoldcxt] = ""
        af[fxod] = ""
        af[fxud] = ""
        af[fxord] = ""
        af[fxship] = ""
        af[fxtx] = ""
        af[fxdis] = ""
        af[fxsubc] = ""
        af[fxxtx] = 0
        af[fxxshp] = 0
        af[fxstot] = 0
        af[fxxtot] = 0
        af[fxs] = 0
        af[fxstran] = 0
        af[fxpt] = ""
        af[fxnos] = ""
        af[fxsd] = ""
        af[fxpickimg] = ""
        af[fxcoup] = 0
        af[fxnoship] = ""
        af[fxrmsg] = "";
        af[fxprofdata] = "";
        af[fxprofedit] = 0;
        af[fxdel] = "";
        af[fxadm] = "";
        af[fxifa] = 0;
        af[fxifaqs] = "";
        af[fxupd] = "";
        af[fxz] = "";
        af[fximage_file] = "";
        af[fxepg] = "";
        af[fxst] = "";
        af[fxc] = "";
        af[fxnewuid] = 0;
        af[fxsource] = "";
        af[fxxid] = -1;
        af[fxtest] = "";
        af[fxcxcxt] = -1;
        af[fxbgpic] = "";
        af[fxnf] = 0;
    }
    this.uid = af[fxuid];
    this.clientid = af[fxclientid];
    this.profid = af[fxprofid];
    this.profname = af[fxprofname];
    this.cxt = af[fxcxt];
    this.tableh = af[fxtableh];
    this.act = af[fxact];
    this.gs = af[fxgs];
    this.gc = af[fxgc];
    this.gp = af[fxgp];
    this.by1 = af[fxby1];
    this.by2 = af[fxby2];
    this.preview = af[fxpreview];
    this.e = af[fxe];
    this.cs = af[fxcs];
    this.poptop = af[fxpoptop];
    this.sd = af[fxsd];
    this.sno = af[fxsno];
    this.catid = af[fxcatid];
    this.prodid = af[fxprodid];
    this.imageid = af[fximageid];
    this.catimage = af[fxcatimage];
    this.catclick = af[fxcatclick];
    this.catname = af[fxcatname];
    this.prodname = af[fxprodname];
    this.rprice = af[fxrprice];
    this.sprice = af[fxsprice];
    this.pex = af[fxpex];
    this.qex = af[fxqex];
    this.subst = af[fxsubst];
    this.pv = af[fxpv];
    this.xc = af[fxxc];
    this.pstrat = af[fxpstrat];
    this.qstrat = af[fxqstrat];
    this.pf = af[fxpf];
    this.olist = af[fxolist];
    this.qops = af[fxqops];
    this.qid = af[fxqid];
    this.work_qid = af[fxwork_qid];
    this.addflag = af[fxaddflag];
    this.addmode = af[fxaddmode];
    this.os = af[fxos];
    this.rpstring = af[fxrpstring];
    this.cvnav = af[fxcvnav];
    this.notax = af[fxnotax];
    this.hpage = af[fxhpage];
    this.keypg = af[fxkeypg];
    this.pg = af[fxpg];
    this.sec = af[fxsec];
    this.xstyle = af[fxxstyle];
    this.xtype = af[fxxtype];
    this.xvalue = af[fxxvalue];
    this.hst = af[fxhst];
    this.pageid = af[fxpageid];
    this.ship = af[fxship];
    this.ectop = af[fxectop];
    this.work_qty = af[fxwork_qty];
    this.work_ochoices = af[fxwork_ochoices];
    this.work_savings = af[fxwork_savings];
    this.work_cprice = af[fxwork_cprice];
    this.work_qtotal = af[fxwork_qtotal];
    this.ocstr = af[fxocstr];
    this.oldcxt = af[fxoldcxt];
    this.od = af[fxod];
    this.ud = af[fxud];
    this.ord = af[fxord];
    this.tx = af[fxtx];
    this.dis = af[fxdis];
    this.pt = af[fxpt];
    this.nos = af[fxnos];
    this.pickimg = af[fxpickimg];
    this.noship = af[fxnoship];
    this.subc = af[fxsubc];
    this.xtx = af[fxxtx];
    this.xshp = af[fxxshp];
    this.stot = af[fxstot];
    this.xtot = af[fxxtot];
    this.s = af[fxs];
    this.stran = af[fxstran];
    this.coup = af[fxcoup];
    this.rmsg = af[fxrmsg];
    this.profdata = af[fxprofdata];
    this.profedit = af[fxprofedit];
    this.del = af[fxdel];
    this.adm = af[fxadm];
    this.ifa = af[fxifa];
    this.ifaqs = af[fxifaqs];
    this.upd = af[fxupd];
    this.z = af[fxz];
    this.image_file = af[fximage_file];
    this.epg = af[fxepg];
    this.st = af[fxst];
    this.c = af[fxc];
    this.newuid = af[fxnewuid];
    this.source = af[fxsource];
    this.xid = af[fxxid];
    this.test = af[fxtest];
    this.cxcxt = af[fxcxcxt];
    this.bgpic = af[fxbgpic];
    this.nf = af[fxnf];
}

function newfx() {
    var fx = document.form1.fx.value;
    var af = fx.split("::");
    af[fxuid] = afx[0].uid;
    af[fxclientid] = afx[0].clientid;
    af[fxprofid] = afx[0].profid;
    af[fxprofname] = afx[0].profname;
    af[fxcxt] = afx[0].cxt;
    af[fxtableh] = afx[0].tableh;
    af[fxact] = afx[0].act;
    af[fxgs] = afx[0].gs;
    af[fxgc] = afx[0].gc;
    af[fxgp] = afx[0].gp;
    af[fxby1] = afx[0].by1;
    af[fxby2] = afx[0].by2;
    af[fxpreview] = afx[0].preview;
    af[fxe] = afx[0].e;
    af[fxcs] = afx[0].cs;
    af[fxpoptop] = afx[0].poptop;
    af[fxsd] = afx[0].sd;
    af[fxsno] = afx[0].sno;
    af[fxcatid] = afx[0].catid;
    af[fxprodid] = afx[0].prodid;
    af[fximageid] = afx[0].imageid;
    af[fxcatimage] = afx[0].catimage;
    af[fxcatclick] = afx[0].catclick;
    af[fxcatname] = afx[0].catname;
    af[fxprodname] = afx[0].prodname;
    af[fxrprice] = afx[0].rprice;
    af[fxsprice] = afx[0].sprice;
    af[fxpex] = afx[0].pex;
    af[fxqex] = afx[0].qex;
    af[fxsubst] = afx[0].subst;
    af[fxpv] = afx[0].pv;
    af[fxxc] = afx[0].xc;
    af[fxpstrat] = afx[0].pstrat;
    af[fxqstrat] = afx[0].qstrat;
    af[fxpf] = afx[0].pf;
    af[fxolist] = afx[0].olist;
    af[fxqops] = afx[0].qops;
    af[fxqid] = afx[0].qid;
    af[fxwork_qid] = afx[0].work_qid;
    af[fxaddflag] = afx[0].addflag;
    af[fxaddmode] = afx[0].addmode;
    af[fxos] = afx[0].os;
    af[fxrpstring] = afx[0].rpstring;
    af[fxcvnav] = afx[0].cvnav;
    af[fxnotax] = afx[0].notax;
    af[fxhpage] = afx[0].hpage;
    af[fxkeypg] = afx[0].keypg;
    af[fxpg] = afx[0].pg;
    af[fxsec] = afx[0].sec;
    af[fxxstyle] = afx[0].xstyle;
    af[fxxtype] = afx[0].xtype;
    af[fxxvalue] = afx[0].xvalue;
    af[fxhst] = afx[0].hst;
    af[fxpageid] = afx[0].pageid;
    af[fxship] = afx[0].ship;
    af[fxectop] = afx[0].ectop;
    af[fxwork_qty] = afx[0].work_qty;
    af[fxwork_ochoices] = afx[0].work_ochoices;
    af[fxwork_savings] = afx[0].work_savings;
    af[fxwork_cprice] = afx[0].work_cprice;
    af[fxwork_qtotal] = afx[0].work_qtotal;
    af[fxocstr] = afx[0].ocstr;
    af[fxoldcxt] = afx[0].oldcxt;
    af[fxod] = afx[0].od;
    af[fxud] = afx[0].ud;
    af[fxord] = afx[0].ord;
    af[fxtx] = afx[0].tx;
    af[fxdis] = afx[0].dis;
    af[fxpt] = afx[0].pt;
    af[fxnos] = afx[0].nos;
    af[fxpickimg] = afx[0].pickimg;
    af[fxnoship] = afx[0].noship;
    af[fxsubc] = afx[0].subc;
    af[fxxtx] = afx[0].xtx;
    af[fxxshp] = afx[0].xshp;
    af[fxstot] = afx[0].stot;
    af[fxxtot] = afx[0].xtot;
    af[fxs] = afx[0].s;
    af[fxstran] = afx[0].stran;
    af[fxcoup] = afx[0].coup;
    af[fxrmsg] = afx[0].rmsg;
    af[fxprofdata] = afx[0].profdata;
    af[fxprofedit] = afx[0].profedit;
    af[fxdel] = afx[0].del;
    af[fxadm] = afx[0].adm;
    af[fxifa] = afx[0].ifa;
    af[fxifaqs] = afx[0].ifaqs;
    af[fxupd] = afx[0].upd;
    af[fxz] = afx[0].z;
    af[fximage_file] = afx[0].image_file;
    af[fxepg] = afx[0].epg;
    af[fxst] = afx[0].st;
    af[fxc] = afx[0].c;
    af[fxnewuid] = afx[0].newuid;
    af[fxsource] = afx[0].source;
    af[fxxid] = afx[0].xid;
    af[fxtest] = afx[0].test;
    af[fxcxcxt] = afx[0].cxcxt;
    af[fxbgpic] = afx[0].bgpic;
    af[fxnf] = afx[0].nf;

    var fx = "";
    for (var i=0;i<af.length;i++) {
        fx += af[i]  + "::";
    }
    document.form1.fx.value = fx;
    //alert("fx=" + fx)//helen debug
}

function ltrim(str) {
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // leading blanks found
      var j=0, i = s.length;
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1) {
         j++ ;
        }
      s = s.substring(j, i);
   }
   return s;
}

function rtrim(str) {
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      var i = s.length - 1;
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1) {
         i-- ;
        }
      s = s.substring(0, i+1);
   }
   return s;
}

function trim(str) {
   return rtrim(ltrim(str));
}

if (!Number.toFixed) {
    // toFixed is JS1.5+, we're typically in 1.2
    Number.prototype.toFixed = function(f) {
        f = parseInt(f/1 || 0)
        if (f<0 || f>20) // next line was throw ...
        alert("The number of fractional digits is out of range")
        if (isNaN(this)) return "NaN"
        var s = this<0 ? "-" : "", x = Math.abs(this)
        if (x>Math.pow(10,21)) return s + x.toString()
        var m = Math.round(x*Math.pow(10,f)).toString()
        if (!f) return s + m
        while (m.length<=f) m = "0" + m
        return s + m.substring(0,m.length-f)+"."+m.substring(m.length-f)
    }
}

function loadvset(pid) {
    // Same function handles front side and admin. Called as part of form load,
    //  or on ViewCart Edit click
    // Loads all variation data for one item into aVSet[] array. Argument pid is the item id.
    // Data comes from hidden form field(s), named "v_"+<item id>, each string holding "<varn>^<varn>^..."
    // There may be more than one item involved - Item Editor and Details page need data for only
    //  one item, but ViewCart must handle all items in cart. This is handled by multiple hidden "v_" fields,
    //  hence the naming convention to identify relevant data for a given item id.

    // This function reads the relevant v_ string into aVSet[], which holds parsed set of variation data
    //  for a given item. Each row in aVSet[] holds data for a given <varn>, parsed.
    // Resulting fields in aVSet[] are: vid, vname, vpattern, vdata.
    // Once a variation pattern is matched, we will apply it by parsing out the vdata field
    //  into the aVData[] array.

    aVSet.length = 0;
    var v_name = "v_" + pid;
    var vnstring = eval("document.form1." + v_name + ".value");
    alert("vnstring = " + vnstring);  // eval call worked?
    if (vnstring.length > 0) {
        av = vnstring.split("^");
        for (var i=0;i<av.length;i++) {
            aVSet[i] = new vsnode(av[i]);       // parse each variation into fields in the aVSet[] row
        }
    }
    // Now aVSet[] is loaded with all variation data for the item, and we can look to the
    //  vpattern fields when finding matches against selected options.
}

function chkweight(vcart) {
    if (!vcart) {
        vcart=0;
    }
    var xid=0;
    for (var i=0;i<aCart.length;i++) {
        xid = aCart[i].prodid;
        //readvrns(xid); //helen commented - error
        for (var j=0;j<aI.length;j++) {
            if (aI[j].prodid==xid) {
                aCart[i].prodidx = j;
                break;
            }
        }
        //aCart[i].weight=getweight(i,vcart); //helen commented - error
    }
}

function getweight(idx,vc) {
    // get weight of aCart[idx], or if -1, return total weight of shipment
    if (!vc) {
        vc = 0;
    }
    var wttot = 0;
    if (idx==-1) {
        for (var i=0;i<aCart.length;i++) {
            wttot += aCart[i].weight;
        }
    } else {
        var pidx=0,qty=0,opc="",vrns="",avrn="",thisv="",spot=0,vchc="",vv="",avv="",avval="";
        for (var i=0;i<aCart.length;i++) {
            if (idx>0 && i != idx) {
                continue;
            }
            pidx = aCart[i].prodidx;
            qty = aCart[i].qty;
            if (vc==1) {
                opc = aCart[i].ochoices;
            } else {
                opc = aCart[i].opchoices;
            }
            opc = opc.replace(",","");
            if (pidx>=0) {
                vrns = aI[pidx].variations;
                avrn = vrns.split("^");
                for (var j=0;j<avrn.length;j++) {
                    thisv = avrn[j];
                    if (thisv.length>0) {
                        spot = thisv.indexOf("/");
                        if (spot>0) {
                            vchc = thisv.substring(0,spot);
                            vv = thisv.substring(spot+1,99);
                            if (opc.indexOf(vchc)>-1) {
                                avv = vv.split(",");
                                for (var k=0;k<avv.length;k++) {
                                    if (avv[k].substring(0,2)=="wt") {
                                        avval = avv[k].substring(2,9);
                                        wttot += (parseFloat(avval)*qty);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return wttot;
}

function isUndefined(value) {
    var undef;
    return value == undef;
}

function imgWidth(srcStr){ // helen new function - get image width
	imgW = new Image();
	imgW.src = "/i/"+srcStr;
	return imgW.width;
}

function imgHeight(srcStr){ // helen new function - get image height
	imgH = new Image();
	imgH.src = "/i/"+srcStr;
	return imgH.height;
}

// Another dialog box arrangement - Chris - instead of functions in comfr.js

function msgshow(x, xtitle, subtitle, oname, mcode, btnprompts) {
    // x is the raw html to show in the msg
    if (x && x.length > 0) {
        if (!xtitle) {
            xtitle = "";
        }
        if (!subtitle) {
            subtitle = "";
        }

        var xmp = new getObj("msgpanel");

        bords = 0;
        var table = "<table bgcolor='#C0C0C0' border= '"+bords+"' cellpadding='2' cellspacing='1' width='100%'>";
        table += "<tr><td width='95%' bgcolor='"+colormed+"' align='center' class='messagetitle'><span class='dblcolon'>::</span>&nbsp;&nbsp;<span style='color:" + colornavtitletext +  ";'>"+TextDecode(xtitle)+"</span>&nbsp;&nbsp;<span class='dblcolon'>::</span>";
        if (subtitle.length > 0) {
            table += "<br><span class='messagecaption'>" + TextDecode(subtitle) + "</span>";
        }
        table += "</td><td width='30' bgcolor='"+colormed+"' align='center'><img src='../i/info_icon.gif' border='0'></td></tr>";
        table += "<tr><td colspan='2' bgcolor='#FFFFFF'>";
        table += "<table border= '"+bords+"' cellpadding='5' cellspacing='0' width='100%'><tr><td><span class='messagebody'>" + x + "</span></td></tr>";
        if (btnprompts && btnprompts.length > 0) {
            var btnclass =
            abtn = btnprompts.split(",");
            var btns = "<tr><td><table align='center' border= '"+bords+"' cellpadding='0' cellspacing='0'><tr>";
            for (var k=0;k<abtn.length;k++) {
                btns += "<td><input type='button' class='regbtn' id='dlgbtn" + k + "' value='"+abtn[k]+"' onclick='msghide("+mcode + "," + k+")'></td>";
            }
            btns += "</tr><tr><td colspan='" + (abtn.length+1) + "'><img src='../i/s.gif' height='5' width='1' border='0'></td></tr></table></td></tr>";
            table += btns;
        } else {
            table += "<table align='center' border= '"+bords+"' cellpadding='0' cellspacing='0'><tr><td><input type='button' id='dlgbtn1' class='actionbtn' value='Close' onclick='msghide()'></td></tr><tr><td><img src='../i/s.gif' height='5' width='1' border='0'></td></tr></table></td></tr>";
        }
        table += "</table></td></tr></table>";
        msgtop = 100;
        msgleft = 100;

        xtop = 0;
        xleft = 0;
        if (oname && oname.length > 0) {
            xobjx = new getObj(oname);
            if (xobjx.obj) {
                var xobj = xobjx.obj;
                while (xobj.offsetParent) {
                    xtop += xobj.offsetTop;
                    xleft += xobj.offsetLeft;
                    xobj = xobj.offsetParent;
                }
            }
            ey = xtop;
            ex = xleft;
        }

        xmp.obj.className = "msgdiv";
        xmp.obj.innerHTML = table;

        dtop = (document.body.scrollTop + document.body.clientHeight/3 - xmp.obj.scrollHeight/2) + msgtopref;
        dleft = msgleftref - xmp.obj.scrollWidth/2;
        msgtop = dtop;
        msgleft = dleft;

        if (mcode || mcode == 0) {
            msgup = 1;
        }
        xmp.style.top  = dtop;
        xmp.style.left = dleft;
        xmp.style.visibility = "visible";
        ADD_DHTML("msgpanel");
        if (xmp.obj.getElementById) {
			xmp.obj.getElementById("dlgbtn1").focus();
		} else if (xmp.obj.document.all) {
			xmp.obj.document.all("dlgbtn1").focus();
		}
    }
}

function msghide(mcode,msgres) {
    var xmp = new getObj("msgpanel");
    if (xmp.style) {
        xmp.style.visibility = "hidden";
    }
    if (msgup==1) {
        msgup = 0;
        modalresult(mcode,msgres);
    }
}

function modalresult(mcode,mres) {
    switch (mcode) {
        case 0:
            // add to cart instructions, should be unreachable here
            //* These act on calls and variables only found in comfr.js
            if (mres != 2) {
                afx[0].act= "../catalog/orderadd.asp";
                afx[0].gc.value = afx[0].catid;
                afx[0].gp.value = afx[0].prodid;
                afx[0].addflag= 1;
                afx[0].addmode= mres;
                // addmode - 0=increase qty, 1=separate line item (default), 2=cancel
                savee();
                submitform();
            }
            break;
		case 1:
			//* generate metadata instructions
            //* These act on calls and variables only found in adnav.js
			going = false;
			switch (mres) {
			
				//* Unknown, or cancel
				case 0:
					MetaGenDialog.visible = false;
					break;
				//* Pages only
				case 1:
				//* Products only
				case 2:
				//* Both
				case 3:
					going = true;
					afx[0].ifaqs = "&genFlag=" + mres;
					break;
			}
			if (going) {
				go_to(19);
			}
			break;
    }
}

function SafeString(s) {
  var s = this.removeDelimiters(s.toString());
  this.HTML = this.HTMLEscape(s);
  this.toString = function() {
    return s;
  }
}

SafeString.prototype.removeDelimiters = function(s) {
  s = s.replace("//", "");
  s = s.replace("::", "");
  s = s.replace("`", "");
  s = s.replace("|", "");
  return s;
}

SafeString.prototype.HTMLEscape = function(s) {
  var s = s.replace("<", "&lt;");
  var s = s.replace(">", "&gt;");
  var s = s.replace('"', "&quot;");
  var s = s.replace("'", "&#39;");
  var s = s.replace("\/", "&#47");
  var s = s.replace("\\", "&#92");
  return s;
}