    // Express order flags
    var increment = "append";
    var curexor_row = -1;
    var actexor_row = -1;
    var mode_exor = 0;
    var showitemcnt_delay = 3000;
    
    var skiptimer = false;
    var ALERT10SECS = true;
    var ALERT03SECS = true;
    var SECSLEFT = 0;
    var elapsedTimerOn = false;
     
    function makeRequest(params, opt) {
        params += "&_r_=" + Math.random();
        var url = "/cs/OnlineOrdering";
        if (opt && opt == "exor") {
            var n = curexor_row + 1;
            params += "&xoline=" + n;
        } else if (opt && opt == "exorg") {
            params += "&xoline=" + curexor_row;
        }
        var meth = 'post';
        if (opt && ((opt == 'sitem') || (opt == 'citem') || (opt == 'exorg'))) {
            meth = 'get';
        }
        new Ajax.Request(
            url,
            {
                method:     meth,
                parameters: params,
                onSuccess:  function(transport) {
                                var contents = transport.responseText;
                                pageLoadLogin();//in case of success,load shopping box in header again.
                                //alert(contents);
                                if (contents.indexOf("<!--SEVERE ERROR-->") == 0) {
                                    if ($('grid0')) {
                                        $('grid0').innerHTML = contents;
                                        $('grid0').style.display = '';
                                        return;
                                    }
                                }
                                if (opt != 'shipvia' && opt != 'alert' && contents.indexOf("<!--alert-->")<0) {
                                    contents = '<div>' + transport.responseText + "</div>";
                                }
                                if (opt == "alert") {
                                    alert(contents);
                                } else if (opt == "alupd") {
                                    if (contents.indexOf("<!--alert-->")>=0) {
                                        alert(contents.substring(12));
                                    } else {
                                        $('grid0').innerHTML = contents;
                                        if ($('grid0').style.display == 'none') {
                                            $('grid0').style.display = '';
                                            if ($('listView')) {
                                                $('listView').style.display = 'none';
                                            }
                                        }
                                        
                                        if (contents.indexOf("Template: catalog/onlineordering/shipviapage_tmpl.html") > 0) {
                                            _tag.dcsCleanUp(); dcsMultiTrack('DCS.dcssip', window.location.hostname, 'DCS.dcsuri','Select Shipping and Payment Methods', 'WT.dl','1', 'WT.ti','Select Shipping and Payment Methods', 'WT.si_n','Shopping Box Common Steps', 'WT.si_p','Select Ship and Payment Methods');
                                            if ($('termsChangedMessage')) {
                                                alert($('termsChangedMessage').innerHTML);
                                            }
                                        }
                                        itemgrid_high_vis = 10;
                                        itemgrid_low_vis = 1;
                                        itemgrid_page = 1;
                                    }
                                } else if (opt == "exor") {
                                    var n = curexor_row - 0 + 1; 
                                    curexor_row = n;
                                    var exortable = $('exorforms');
                                    if (exortable == null) {
                                        alert("Express order table not found.");
                                    } else {
                                        var newIndx = curexor_row;
                                        if (increment != "append") {
                                            newIndx = 0;
                                        }
                                        var newRow = exortable.insertRow(newIndx);
                                        var newCell = newRow.insertCell(0);
                                        newCell.id = "exorcell_" + curexor_row;
                                        newCell.innerHTML = contents;
                                    }
                                } else if (opt == 'exorg') {
                                    $('exorcell_' + curexor_row).innerHTML = contents;
                                    if(params.indexOf("SHRB")>0 || params.indexOf("PT61")>0){
                                    $('ExorAddToBoxBtn').style.display = "none";
                                    $('ExorCheckOutBtn').style.display = "none";
                                    }
                                } else if (opt == 'exorq') {
                                    $('ExorMessage_'+actexor_row).innerHTML = "<span style='color:red'>"+contents+"</span>";
                                    $('ExorMessage_'+actexor_row).style.display = "";
                                    $('ExorCheckoutId').style.display = "";
                                } else if (opt == 'exorc') {
                                    $('grid0').innerHTML = contents;
                                    var l0 = contents.indexOf("curexor_row");
                                    if (l0 > 0) {
                                        var l1 = contents.indexOf(";", l0);
                                        if (l1 > 0 && (l1 >= (l0 + 14))) {
                                            curexor_row = contents.substring(l0 + 14, l1);
                                            var n = curexor_row - 0;
                                            if (!isNaN(n) && (n > 0)) {
                                                for (var i=0; i < n; i++) {
                                                    hideExorGrid(i);
                                                }
                                                $('ExorCheckoutId').style.display = "";
                                                actexor_row = -1;
                                            }
                                        }
                                    }
                                } else if (opt == 'exord') {
                                    updcount = true;
                                } else if (opt == 'shipvia') {
                                    $('disablesubmitbtn').style.display = "none";
                                    $('enablesubmitbtn').style.display = "";
                                    setShipVia(contents);
                                } else if (opt == 'redeempromo') {
                                    if (contents.lastIndexOf("is valid")>0) {
                                        $('promocode').readOnly = true;
                                        $('redeempromobtn').style.display = "none";
                                        $('removepromobtn').style.display = "";
                                    }
                                    $('redeempromomsg').innerHTML = contents;
                                    $('redeempromomsg').style.display = "";
                                } else if (opt == 'removepromo') {
                                        $('promocode').readOnly = false;
                                        $('promocode').value = "";
                                        $('redeempromobtn').style.display = "";
                                        $('removepromobtn').style.display = "none";
                                        $('redeempromomsg').style.display = "none";
                                } else if (opt == 'closeoutlists') {
                                    $('listView').innerHTML = contents;
                                    $('listView').style.display = '';
                                    if ($('grid0')) {
                                        $('grid0').style.display = 'none';
                                    }
                                } else if ((opt == 'sitem') || (opt == "citem")) {
                                    $('grid0').innerHTML = contents;
                                    $('grid0').style.display = '';
                                    if ($('listView')) {
                                        $('listView').style.display = 'none';
                                    }
                                    if ($('itemView')) {
                                        $('itemView').style.display = 'none';
                                    }
                                    
                                    $('grid0').focus();
                                    //if (contents.indexOf("Template: catalog/onlineordering/itemgrid_tmpl.html") > 0) {
                                        //if ($('_GridForm_')) {
                                        //    ('_GridForm_').focusFirstElement();
                                        //}
                                    //}
                                } else {
                                    $('grid0').innerHTML = contents;
                                    var pc = $('promocode');
                                    if (pc != null && pc.value != null && pc.value.length > 0) {
                                        var conf = confirm("Do you want to redeem promocode " + pc.value + "?\nClick OK to redeem");
                                        if (conf == true) {
                                            promoCode(pc.value, 'redeem');
                                        } else {
                                            pc.value = "";
                                        }
                                    }
                                    
                                    if (contents.indexOf("Template: catalog/onlineordering/shipviapage_tmpl.html") > 0) {
                                    	_tag.dcsCleanUp(); dcsMultiTrack('DCS.dcssip',window.location.pathname, 'DCS.dcsuri','Select Shipping and Payment Methods', 'WT.dl','1', 'WT.ti','Select Shipping and Payment Methods', 'WT.si_n','Shopping Box Common Steps', 'WT.si_p','Select Ship and Payment Methods');
                                    	if ($('termsChangedMessage')) {
                                            alert($('termsChangedMessage').innerHTML);
                                        }

                        			    if(document.CheckOut.PayMethod.selectedIndex==0){
                        				    $('cc_submit').style.display='None';
                        				    $('terms_submit').style.display='';
                        			    }
                        			    else{
                        				    $('cc_submit').style.display='';
                        				    $('terms_submit').style.display='None';
                        			    }
                                    }
                            		
                                }
                                sfHover;
                                if ($('AddressBookTable') != null) {
                                    addTableRolloverEffect('AddressBookTable','tableRollOverEffect1','tableRowClickEffect1');
                                }
                                var l0 = contents.indexOf("dcsMultiTrack(");
                                if (l0>0 && (opt != 'no_wt')) {
                                    var wt_params = contents.substring(l0);
                                    l0 = wt_params.indexOf("-->");
                                    wt_params = wt_params.substring(0,l0);
                                    //alert("calling dcsMultitrack: " + wt_params);
                                    eval(wt_params);
                                }
                                
                                
                            }
            }
        );
        
        if (opt && (opt == "citem" && !elapsedTimerOn)) {
            displayElapsedTime();
        }
        
    }
            
    function makeRequest1() { 
        var url = "/cs/OnlineOrdering";
        var params = "todo=webrefage";
        params += "&r=" + Math.random();
        
        new Ajax.Request(
            url,
            {
                method:     'get',
                parameters: params,
                onSuccess:  function(transport) {
                                var elapsedTime = transport.responseText;
                                if (elapsedTime.indexOf("ERROR") >= 0) {
                                    skiptimer = true;
                                    elapsedTime = "";
                                } else {
                                    if (elapsedTime.indexOf("alert10")>=0) {
                                        alert("You have less than 10 minutes to complete your order.");
                                    } else if (elapsedTime.indexOf("alert3")>=0) {
                                        alert("You have less than 3 minutes to complete your order.");
                                    } else if (elapsedTime.indexOf("<!--alert00-->")>=0) {
                                        var l = elapsedTime.indexOf("<!--alert00-->");
                                        alert(elapsedTime.substring(l+14));
//                                  } else if ($('elapsedTime')) {
//                                      $('elapsedTime').innerHTML = elapsedTime;
                                    }
                                }
                                
                            }
            }
        )
    }
                
    function makeRequest2() {
    	 
        if ($('shopboxitemcount') == null) {
            return;
        }
        
        $('shopboxitemcount').innerHTML = "<strong><a href='/cs/OnlineOrdering?todo=viewbox&top=Y'>? items in box</a></strong>";
        if ($('shopboxitemcount').style.display == 'none') {
            $('shopboxitemcount').style.display = '';
        }
         
        var url = "/cs/OnlineOrdering";
        var params = "todo=boxpieces" +
                     "&r=" + Math.random();
        
        new Ajax.Request(
            url,
            {
                method:     'post',
                parameters: params,
                onSuccess:  function(transport) {
                                var itemCount = transport.responseText;
                                if ((itemCount.length > 0) && (itemCount.indexOf("ERROR") < 0) && (itemCount.indexOf("item") >= 0)) {
                                    $('shopboxitemcount').innerHTML = "<strong><a href='/cs/OnlineOrdering?todo=viewbox&top=Y'>"+itemCount+"</a></strong>";
                                    $('shopboxitemcount').style.display = "";
                                }
                            }
            }
        )
    }
                
    function makeRequest3(todo) {
        if (todo == null) {
            todo = "user";
        }
        var el = "_"+todo
        if ($(el) == null) {
            return;
        }
                 
        var url = "/sanmar-servlets/OnlineOrdering";
        var params = "todo=get" + todo;
        
        new Ajax.Request(
            url,
            {
                method:     'post',
                parameters: params,
                onSuccess:  function(transport) {
                                var contents3 = transport.responseText;
                                if ((contents3.length > 0) && (contents3.indexOf("ERROR") < 0)) {
                                    $(el).innerHTML = contents3;
                                }
                            }
            }
        )
    }
    
    function checkOrderContinue(fobj) {
        if ((fobj.citem != null && fobj.citem.value == "Y")) {
            //(fobj.sitem != null && fobj.sitem.value == "Y")) {
            var params = "todo=checkordercontinue" +
                         "&webref=" + fobj.webref.value +
                         "&continue=" + fobj.cont.value;
            if (fobj.citem != null) {                         
                params += "&citem=" + fobj.citem.value;
            }
            if (fobj.sitem != null) {
                params += "&sitem=" + fobj.sitem.value;
            }
            makeRequest(params, 'citem');
        } else {
            fobj.submit();
        }
        
        //setTimeout("makeRequest2()", showitemcnt_delay);
    }                                      
        
    function getGridFormEls (fobj, zer, valFunc) {
        var str = ""; 
        var valueArr = null;
        var name = ""; 
        var val = ""; 
        var cmd = "";
        var ok = false;
        if (zer == true) {
            ok = true;
        } 
        for(var i = 0;i < fobj.elements.length;i++) 
        { 
            switch(fobj.elements[i].type) 
            { 
                case "text": 
                     if(valFunc) 
                     { 
                         //use single quotes for argument so that the value of 
                         //fobj.elements[i].value is treated as a string not a literal 
                         cmd = valFunc + "(" + 'fobj.elements[i].value' + ")"; 
                         val = eval(cmd) 
                     } 
                     nam = fobj.elements[i].name;
                     val = fobj.elements[i].value;
                     str += nam + "=" + escape(val) + "&";
                     if (!ok && (nam.indexOf("boxdata") == 0) && val) {
                        v = val - 0;
                        if (!isNaN(v) && (v > 0)) {
                            ok = true;
                        }
                     }
                     break; 
                case "select-one": 
                     str += fobj.elements[i].name + 
                     "=" + fobj.elements[i].options[fobj.elements[i].selectedIndex].value + "&"; 
                     break; 
                case "hidden":
                     str += fobj.elements[i].name +
                      "=" + escape(fobj.elements[i].value) + "&";
                     break;
            } 
        }
        
        if (ok) { 
            str = str.substr(0,(str.length - 1));
        } else {
            str = "";
        } 
        return str;
    }
    
    function getExorFormEls (fobj, zer) {
        var str = ""; 
        var nam = ""; 
        var ok = false;
        if (zer == null)
            ok = true; 
        for(var i = 0;i < fobj.elements.length;i++) 
        {
            nam = fobj.elements[i].name;
            switch(fobj.elements[i].type) 
            {
                case "text":
                    if (nam != 'swatch') { 
                        str += nam + "=" + escape(fobj.elements[i].value) + "&";
                        if (!ok && (nam.indexOf("boxdata") == 0)) {
                            if (fobj.elements[i].value.length > 0) {
                                if (zer == '0') {
                                    ok = true;
                                } else {
                                    var qty = fobj.elements[i].value - 0;
                                    if (!isNaN(qty) && qty > 0) {
                                        ok = true;
                                    }
                                }
                            }
                        }
                    }
                    if ((nam == 'swatch') ||
                        (nam == 'productid')){
                        fobj.elements[i].readOnly = true;
                    } 
                    break; 
                case "hidden":
                     str += fobj.elements[i].name +
                      "=" + escape(fobj.elements[i].value) + "&";
                      break;
            } 
        }
        if (!ok) {
            str = "";
        } else {  
            str = str.substr(0,(str.length - 1));
        } 
        return str;
    }
    
    function checkInv(qobj, qlevel) {
        re = /[^0-9\+]/;
        if (re.test(qobj.value)) {
            alert("\nYou entered '" +qobj.value + "' which is invalid. Only numeric characters are allowed.");
            qobj.value = '';
            qobj.focus();
            return false;
        }
        var v = qobj.value - 0;
        
        if (isNaN(v) || (v < 0)) {
            qobj.focus();
            alert("The number you entered, '" + qobj.value + "' is invalid.");
            qobj.value = "";            
            return false;
        }
        var q = qlevel - 0;
        if (isNaN(q) || (q>=500)) {
            return true;
        }
        if (v>q) {
            qobj.value = qlevel;
            var conf = confirm("The quantity you entered was modified to equal stock-on-hand.");
            return conf;
        }
        return true;
    }
    
    function getExorLineSummary(fobj) {
        var str = "<strong>"
        if ((fobj.closeout != null) && (fobj.closeout.value == "Y")) {
            str += "CLOSEOUT! ";
        }
        str += fobj.productid.value + " &nbsp;&nbsp;&nbsp;" + fobj.swatch.value;
        
        var waistx = "";
        if (fobj.waist != null) {
            waistx = fobj.waist.value+"x";
        }
        var els = fobj.getInputs('text');
        for (var i = 0; i < els.length; i++) {
            el = els[i];
            if ((el.value.length > 0) && (el.name != 'productid') && (el.name != 'swatch') && (el.name != 'waist')) {
                var na = el.name;
                var szs = fobj.getInputs('hidden', 's_'+na);
                str += "&nbsp;&nbsp;&nbsp;<span> " + waistx + szs[0].value + ": " + el.value + " </span>";
            }
        }
        str += "</strong>";
        return str;
    }
                
    
    function doGridSubmit(obj) {
        var params = getGridFormEls(obj, false, null);
        if ((params == null) || (params.length == 0)) {
            alert("There is nothing to submit");
            return false;
        }
        params  += "&todo=updatecart";
        makeRequest(params, "alupd");
        setTimeout("makeRequest2()", showitemcnt_delay);        
        return false;
    }
    
    function doGridSubmitContinue(obj) {
        obj.action = "/cs/OnlineOrdering?todo=viewboxfromgrid";
        obj.method="post";
        obj.submit(); 
        setTimeout("makeRequest2()", showitemcnt_delay);        
    }
    
    function doExorSubmit(obj, inv, xoline, productid) {
        if (!checkInv(obj, inv)) {
            return false;
        }
        var params = "xo=Y&todo=";
        if (mode_exor == 0) {
            if (obj.value.length == 0 || obj.value == "0") {
                return;
            }
            params += "updatecart";
            params += "&productid=" + productid;
            params += "&" + obj.name + "=" + obj.value;
            
            var fobj = $('ExorFormId_' + xoline);
            var selWaist = $('SelWaist_' + xoline);
            if (selWaist != null) {
                var waist = fobj.selectwaist.options[fobj.selectwaist.selectedIndex].value;
                selWaist.innerHTML = "";
            }
            
            var pidEl = fobj.productid;
            pidEl.readOnly = true;
                
            var swEl = fobj.swatch;
            if (swEl.type != "text") {
                $('swatch_'+xoline).innerHTML = "<input type='text' name='swatch' size='10%' value='"+
                                                swEl.options[swEl.selectedIndex].value + "' readonly>";
            }
        } else {
            var v = obj.value;
            if (v.length == 0) {
                v = "0";
            }
            params += "boxupdqty&";
            params += "tagname=" + obj.name + "&tagvalue=" + v;
            params += "&productid=" + productid;
        }
        makeRequest(params, "exorq");
        setTimeout("makeRequest2()", showitemcnt_delay);
        return false;
    }
    
    function doExorRemove(fobj, lineno) {
        var conf = confirm("Are you sure you want to remove line?\nClick OK to remove");
        if (conf == true) {
            var params = "todo=boxdelline&xo=Y&xoline=" + lineno;
            var itemcode = "";
            for (var i=0; i < fobj.elements.length; i++) {
                el = fobj.elements[i];
                if (el.type == "text" && ((el.name).indexOf("boxdata") == 0) &&
                   (el.value.length > 0)) {
                    if (itemcode.length > 0) {
                        itemcode += ":";
                    }
                    itemcode += el.name;
                }
            }
            params += "&tagname=" + itemcode;
            makeRequest(params, "exord");
            
            var exortable = $('exorforms');
            if (exortable == null) {
                alert("Express order table not found.");
            } else {
                exortable.rows[lineno].deleteCell(0);
            }
            if (lineno == actexor_row) {
                actexor_row = -1;
            }
            setTimeout("makeRequest2()", showitemcnt_delay);
        }
    }
    
    function doExorEdit(xoline) {
        var n = xoline - 0;
        if (actexor_row != n && (actexor_row >= 0)) {
            hideExorGrid(actexor_row);
        }
        actexor_row = n;
        mode_exor = 1;
        showExorGrid(xoline);
    }
            
    function doExorContinue() {
        makeRequest('todo=exor&top=C', 'exorc');
    }
    
    function setExorActive(xoline, pid) {
        var n = xoline - 0;
        if (actexor_row == n) {
            $('ExorMessage_'+actexor_row).innerHTML = "&nbsp;";
            return false;
        }
        
        if ((actexor_row >= 0) && (actexor_row != n)) {
            hideExorGrid(actexor_row);
        }
        actexor_row = n;
                
        if (n == curexor_row) {
            var bobj = $('Buttons_' + xoline);
            if (bobj != null) {
                bobj.style.display = "none";
                bobj.innerHTML = "";
            }
            mode_exor = 0;
            makeRequest("todo=exor&productid="+pid, "exor");
        } else if (n == (curexor_row - 1)) {
            mode_exor = 0;
            $('ExorMessage_'+actexor_row).innerHTML = "";
        } else {
            mode_exor = 1;
            $('ExorMessage_'+actexor_row).innerHTML = "";
        }
        return false;
    }
            
    
    function myToggle(el) {
        var obj = $(el);
        if (obj != null) {
            if (obj.style.display == "none") {
		Effect.Appear(el);
            } else {
		Effect.Fade(el);
            }
        }
    }
    
    function showExorGrid(xoline) {
        var obj = $('ExorGrid_' + xoline);
        if (obj.style.display == 'none') {
	    Effect.BlindDown('ExorGrid_' + xoline);
	    Effect.BlindUp('EditButton_' + xoline);
	    Effect.BlindDown('RemoveButton_' + xoline);
	    Effect.BlindDown('ExorName_' + xoline + "_O");
	    Effect.BlindUp('ExorName_' + xoline + "_C");
            $('ExorTable_'+xoline).border = '0';
        }
        return false;
    }    
                
    function hideExorGrid(xoline) {
        var obj = $('ExorGrid_' + xoline);
        if (obj.style.display != 'none') {
	    Effect.BlindUp('ExorGrid_' + xoline);
	    Effect.BlindDown('EditButton_' + xoline);
	    Effect.BlindUp('RemoveButton_' + xoline);
	    Effect.BlindUp('ExorName_' + xoline + "_O");
	    Effect.BlindDown('ExorName_' + xoline + "_C");
            $('ExorMessage_' + xoline).style.display = "none";
            $('ExorName_'+xoline+'_C').innerHTML = getExorLineSummary($('ExorFormId_'+xoline));
            $('ExorTable_'+xoline).border = '0';
        }
        return false;
    }
    function getExorGrid1(pidObj) {
        var val = pidObj.value;
        val = val.toUpperCase();
        if(!checkOrder(val)){
        	pidObj.value = "";
        	return;
        }

        var params = "todo=exor&productid=" + pidObj.value;
        makeRequest(params, 'exorg');
    }
    
    function getExorGrid1C(selObj) {
        var indx = selObj.selectedIndex;
        if (indx > 0) {
            var params = "todo=exor&productid=" + selObj.options[indx].value;
            makeRequest(params, 'exorg');
        }
    }
    
    function styleColorExists(pid, col, xoline) {
        var frms = document.getElementsByTagName("form");
        var found = false;
        for (var i=0; i < frms.length && (found == false); i++) {
            frm = frms[i];
            if (((frm.name).indexOf("ExorForm_") == 0) && (frm.name != ("ExorForm_" + xoline))) {
                if (frm.waist == null &&
                    frm.productid != null && frm.productid.value == pid &&
                    frm.swatch != null && frm.swatch.value == col) {
                    found = true;
                    var xoline1 = (frm.name).substring(9);
                    showExorGrid(xoline1);
                    if (actexor_row >= 0) {
                        hideExorGrid(actexor_row);
                    }
                    actexor_row = xoline1 - 0;
                    frm.swatch.focus();
                }
            }
        }
        return found;
    }
    
    function styleColorWaistExists(pid, col, waist, xoline) {
        var frms = document.getElementsByTagName("form");
        var found = false;
        for (var i=0; i < frms.length && (found == false); i++) {
            frm = frms[i];
            if (((frm.name).indexOf("ExorForm_") == 0) && (frm.name != ("ExorForm_" + xoline))) {
                if (frm.productid != null && frm.productid.value == pid &&
                    frm.swatch != null && frm.swatch.value == col &&
                    frm.waist != null && frm.waist.value == waist) {
                    found = true;
                    var xoline1 = (frm.name).substring(9);
                    showExorGrid(xoline1);
                    if (actexor_row >= 0) {
                        hideExorGrid(actexor_row);
                    }
                    actexor_row = xoline1 - 0;
                    frm.swatch.focus();
                }
            }
        }
        return found;
    }
    
    function styleColorLengthExists(pid, col, lngth, xoline) {
        var frms = document.getElementsByTagName("form");
        var found = false;
        for (var i=0; i < frms.length && (found == false); i++) {
            frm = frms[i];
            if (((frm.name).indexOf("ExorForm_") == 0) && (frm.name != ("ExorForm_" + xoline))) {
                if (frm.productid != null && frm.productid.value == pid &&
                    frm.swatch != null && frm.swatch.value == col &&
                    frm.lngth != null && frm.lngth.value == lngth) {
                    found = true;
                    var xoline1 = (frm.name).substring(9);
                    showExorGrid(xoline1);
                    if (actexor_row >= 0) {
                        hideExorGrid(actexor_row);
                    }
                    actexor_row = xoline1 - 0;
                    frm.swatch.focus();
                }
            }
        }
        return found;
    }
    
    function checkOrder(productId){
    	 if ((productId.toUpperCase() == "PT61") || (productId.toUpperCase() == "SHRB")) {
             alert("We're sorry, but this product cannot be ordered online at this time. Please call to order.");
             productId.value = "";
             return false;
         }
    	 else 
    		 return true;
    }
     
    function getExorGrid2(pid, colSel, xoline, pants, closeout) {
        var indx = colSel.selectedIndex;
      
        if(!checkOrder(pid)){
        	pid = "";
        	return;
        }
        
        if (indx > 0) {
            var swatch = colSel.options[indx].value;
            if (pants != "Yes") {
                if (styleColorExists(pid, swatch, xoline)) {
                    alert("A " + pid + "/" + swatch + " row already exists.\nIf you wish to add/change your order for this product,\nplease edit that row instead.");
                    return;
                }
            }                
            var params = "todo=exor&productid=" + pid +
                         "&swatch="+ swatch;
            if (closeout != null && closeout == "Yes") {
                params += "&closeout=Y";
            }                         
            makeRequest(params, 'exorg');
        }
    }
     
    function getExorGrid3(pid, swatch, colSel, xoline) {
        var indx = colSel.selectedIndex;
        if (indx > 0) {
            var waist = colSel.options[indx].value;
            if (styleColorWaistExists(pid, swatch, waist, xoline)) {
                    alert("A " + pid + "/" + swatch + " row already exists.\nIf you wish to add/change your order for this product,\nplease edit that row instead.");
                    return;
            }
            var params = "todo=exor&productid=" + pid +
                         "&swatch=" + swatch +
                         "&waist=" + waist;
            makeRequest(params, 'exorg');
        }
    } 
    
    function getExorGrid4(pid, swatch, colSel, xoline) {
        var indx = colSel.selectedIndex;
        if (indx >= 0) {
            var lngth = colSel.options[indx].value;
            if (styleColorLengthExists(pid, swatch, lngth, xoline)) {
                    alert("A " + pid + "/" + swatch + " row already exists.\nIf you wish to add/change your order for this product,\nplease edit that row instead.");
                    return;
            }
            var params = "todo=exor&productid=" + pid +
                         "&swatch=" + swatch +
                         "&lngth=" + lngth;
            makeRequest(params, 'exorg');
        }
    } 

    function displayElapsedTime() {
        if (skiptimer) {
            return;
        }
        
        elapsedTimerOn = true;
        setTimeout("displayElapsedTime()", 120000);
        makeRequest1();
    }
   
    function viewShopBox(params) {
        var params = "todo=viewbox" + params;
        makeRequest(params, "alupd");
        setTimeout("makeRequest2()", showitemcnt_delay);
    }
    
    function viewShopBoxFromGrid(fobj, viewboxparams) {
        var params = getGridFormEls(fobj, true, null) + viewboxparams + "&todo=viewboxfromgrid";
        makeRequest(params, "alupd");
        setTimeout("makeRequest2()", showitemcnt_delay);
    }
        
    
    function updShopBoxQty(fobj, tagnam, tagval) {
        $('shopbox_message').innerHTML = "&nbsp;";
        //if ((tagval == null) || (tagval.length == 0) || (tagval == "0")) {
        //    delShopBoxLine(fobj, tagnam);
        //    return;
        //}
        
        var val = tagval - 0;
        var errmsg = "";
        if (isNaN(val)) {
            errmsg = "You must enter a numeric quantity greater than 0.";
        }
        if (val == 0 ) {
            errmsg += "\nIf you don't want to include this item, please check the 'Delete' box instead.";
        }
        if (val < 0 ) {
            errmsg += "\nPlease do not include negative values. To remove product, retype the quantity you would prefer, and click 'Refresh'.";
        }
        if (errmsg.length > 0) {
            alert(errmsg);
            return false;
        } else {
            var params = "todo=boxupdqty&tagname=" + tagnam + "&tagvalue=" + tagval;
            if (fobj.id) {
                params += "&id=" + fobj.id.value;
            }
            if (fobj.swathc) {
                params += "&swatch=" + fobj.swatch.value;
            }
            if (fobj.prodimage) {
                params += "&prodimage=" + fobj.prodimage.value;
            }
            makeRequest(params, "alupd");
            setTimeout("makeRequest2()", showitemcnt_delay);
        }
    }
    
    function updShopBoxWh(fobj, sobj, qobj) {
        $('shopbox_message').innerHTML = "&nbsp;";
        var selindx = sobj.selectedIndex;
        var params = "todo=boxupdwh&tagname=" + qobj.name + "&tagvalue=" + qobj.value +
                     "&pwhse=" + sobj.options[selindx].value;
        if (fobj.id) {
            params += "&id=" + fobj.id.value;
        }
        if (fobj.swathc) {
            params += "&swatch=" + fobj.swatch.value;
        }
        if (fobj.prodimage) {
            params += "&prodimage=" + fobj.prodimage.value;
        }
        if (fobj.xo) {
            params += "&xo=" + fobj.xo.value;
        }
        makeRequest(params, "alupd");
    }
       
    
    function delShopBoxLine(fobj, tagnam, style, qty) {
        var conf = confirm("Are you sure you want to delete item?\nClick 'OK' to proceed");
        if (conf == true) {
            var params = "todo=boxdelline&tagname=" + tagnam;
            if (fobj.id) {
                params += "&id=" + fobj.id.value;
            }
            if (fobj.swatch) {
                params += "&swatch=" + fobj.swatch.value;
            }
            if (fobj.prodimage) {
                params += "&prodimage=" + fobj.prodimage.value;
            }
            _tag.dcsCleanUp();
            dcsMultiTrack('DCS.dcssip', window.location.hostname, 'DCS.dcsuri', window.location.pathname, 'WT.ti','Click: Remove', 'WT.dl','1', 'WT.tx_e','r','WT.tx_u',qty,'WT.pn_sku', style);
            
                   
            makeRequest(params, null);
            setTimeout("makeRequest2()", showitemcnt_delay);
        }
    }
    
    function clearShopBox(fobj) {
        var conf = confirm("Are you sure you want to remove all contents of shopping box?\n"+
                           "Click 'OK' to proceed");
        if (conf == true) {
            params = "todo=clearbox";
            if (fobj.id) {
                params += "&id=" + fobj.id.value;
            }
            if (fobj.swathc) {
                params += "&swatch=" + fobj.swatch.value;
            }
            if (fobj.prodimage) {
                params += "&prodimage=" + fobj.prodimage.value;
            }
            
            makeRequest(params, null);
            setTimeout("makeRequest2()", showitemcnt_delay);
        }
    }

    
    
    //version called from express order page
    function clearExorShopBox() {
        var conf = confirm("Are you sure you want to remove all contents of shopping box?\n"+
                           "Click 'OK' to proceed");
        if (conf == true) {
        
            var exortab = $('exorforms');
            for (var i = 0; i <= curexor_row; i++) {
                exortab.deleteRow(0);
            }
                
            curexor_row = -1;
            actexor_row = -1;
            mode_exor = 0;
            $('ExorCheckoutId').style.display = "none";             
                                                
            params = "todo=clearbox&xo=Y";
            makeRequest(params, 'exor');
            setTimeout("makeRequest2()", showitemcnt_delay);
        }
    }
    
    function updateShipVia(frmObj, selObj, estObj, wh_name, warehouseShipMethodId) {
    	 
    	document.getElementById(warehouseShipMethodId+"HiddenField").value = document.getElementsByName(warehouseShipMethodId)[0].value;
    	    	
        var params = "todo=updshipvia&pwarehouse=" + escape(wh_name);
        params += "&poptcode=" + escape(selObj.options[selObj.selectedIndex].value);
        if (estObj != null && (estObj.value.length > 0)) {
            params += "&pfreightestimate=" + escape(estObj.value);
        }
        if (frmObj.xo != null) {
            params += "&xo=" + frmObj.xo.value;
        }
        $(selObj.name + "_opt").innerHTML = selObj.options[selObj.selectedIndex].text;
        $(selObj.name + "_est").innerHTML = "(Calculating estimate ..)";
        //alert("Todo:\n" + params);
        if ($('enablesubmitbtn') != null) {
            $('enablesubmitbtn').style.display = "none";
        }
        if ($('disablesubmitbtn')) {
            $('disablesubmitbtn').style.display = "";
        }
        if ($('ShipToAddress') != null) {
            if (checkIsShipping() == true) {
                $('ShipToAddress').style.display = '';
            } else {
                $('ShipToAddress').style.display = 'None';
            }
        }
        makeRequest(params, 'shipvia');
    }
    
    function checkIsShipping() {
        if (document.CheckOut.Seattle != null) {
            var i = document.CheckOut.Seattle.selectedIndex;
            if (document.CheckOut.Seattle.options[i].value != "PRE") {
                return true;
            }
        }
        if (document.CheckOut.Cincinnati != null) {
            var i = document.CheckOut.Cincinnati.selectedIndex;
            if (document.CheckOut.Cincinnati.options[i].value != "CIN") {
                return true;
            }
        }
        if (document.CheckOut.Dallas != null) {
            var i = document.CheckOut.Dallas.selectedIndex;
            if (document.CheckOut.Dallas.options[i].value != "COP") {
                return true;
            }
        }
        if (document.CheckOut.Reno != null) {
            var i = document.CheckOut.Reno.selectedIndex;
            if (document.CheckOut.Reno.options[i].value != "REN") {
                return true;
            }
        }
        if (document.CheckOut.NewJersey != null) {
            var i = document.CheckOut.NewJersey.selectedIndex;
            if (document.CheckOut.NewJersey.options[i].value != "NJE") {
                return true;
            }
        }
        if (document.CheckOut.Florida != null) {
            var i = document.CheckOut.Florida.selectedIndex;
            if (document.CheckOut.Florida.options[i].value != "JAC") {
                return true;
            }
        }
        return false;
    }
    
    function setShipVia(contents) {
        if (contents.indexOf("ERROR") > 0) {
            alert(contents);
            return;
        }
        if (contents.indexOf("<p>Sorry") == 0) {
            $('grid0').innerHTML = contents;
            return;
        }
        
        var p = contents.indexOf("?");
        if (p >= 0) {
            contents = contents.substring(p + 1);
        }
        var params = contents.split("&");
        var wh = "";
        var est = "";
        var msg = "";
        for (var i=0; i < params.length; i++) {
            var param = params[i];
            if (param.indexOf("warehouse=") == 0) {
                wh = param.substring(10);
                if (wh == 'New Jersey') {
                    wh = 'NewJersey';
                }
            } else if (param.indexOf("freightestimate=") == 0) {
                est = param.substring(16);
            } else if (param.indexOf("message") == 0) {
                p = param.indexOf("=");
                if (p>0) {
                    msg += param.substring(p+1) + " ";
                }
            }
                    
        }
        $(wh+"_est").innerHTML = "&nbsp;("+est+")";
        if (msg.length > 0) {
            alert(msg);
        }    
    }
        
    
    function checkout(params) {
        if ($('shopboxcheckoutbtn') && $('shopboxwaitbtn')) {
            $('shopboxcheckoutbtn').style.display = "none";
            $('shopboxwaitbtn').style.display = "";
        }
        makeRequest("todo=checkout0&"+params);
    }
        
    function doExorCheckout(stge) {
        if (stge == "0") {
            $('ExorCheckoutId').style.display = "none";
            makeRequest('todo=viewbox&xo=C');
        } else if (stge == '2') {
            if ($('shopboxcheckoutbtn') && $('shopboxwaitbtn')) {
                $('shopboxcheckoutbtn').style.display = "none";
                $('shopboxwaitbtn').style.display = "";
            }
            makeRequest("todo=shipvia&xo=Y");
        } else {
            makeRequest("todo=checkout0&xo=C");
        }
    }
    
    function agreePNTerms(fobj, opt) {
        var params = "todo=agreepnterms&option="+opt+"&";
        params += getGridFormEls (fobj, true, null);
        makeRequest(params);
        if (opt == "Y") {
            alert("Your one-time agreement to the terms has been recorded. Thank you");
        }
    }
        
    
    function openShopBoxWindow() {
        window.open('/cs/OnlineOrdering?todo=viewbox&xo=Y',
                    'ShowBoxViewWindow',
                    'toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,width=620,height=500,left=100,top=25');
    }
                
    function openSavedBoxWindow() {
        window.open('/cs/OnlineOrdering?todo=dispsavebox',
                    'SavedBoxViewWindow',
                    'toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,width=620,height=500,left=100,top=25');
    }            
    
    function setFlag(txtName) {
        var txtEl = $(txtName);
        if (txtEl) {
            txtEl.value = "Y";
        }
    }
    
    
    // Shipping page actions
    function initAddressForm(el, addrForm) {
        var addr = "";
        if (el.type == "select-one") {
            var indx = selectEl.selectedIndex;
            if (indx > 0) {
                addr = selectEl.options[indx].value;
            }
        } else if (el.type == "radio") {
            addr = el.value;
        }
        if (addr.length != 0) {
            addr = addr.split("\|");
            if (addr.length != 7) {
                return;
            }
        } else {
            addr = new Array("","","","","","","");
        }
        addrForm.paddress1.value = addr[0];
        addrForm.paddress2.value = addr[1];
        addrForm.pcity.value =     addr[2];
        addrForm.pstate.value =    addr[3];
        addrForm.pzipcode.value =  addr[4];
        
        var resY = $('residY');
        var resN = $('residN');
        if (addr[5] == "N") {
            resN.checked = true;
            resY.checked = false;
            addrForm.presidence.value = "N";
        } else {
            resN.checked = false;
            resY.checked = true;
            addrForm.presidence.value = "Y";
        }
        addrForm.pemail.value = addr[6];
    }
    function promoCode(code, opt) {
        if (code == null || code.length == 0) {
            return;
        }
            
        var params = "";
        if (opt == "removepromo") {
            params = "todo=removepromo";
        } else {
            params = "todo=redeempromo&ppromocode=" + code;
        }
        makeRequest(params, opt+'promo');
    }
    function sendAddr(addrForm, xo) {
        if (checkAddr(addrForm)) {
            if ($('enablesendaddrbtn')) {
                $('enablesendaddrbtn').style.display = "none";
            }
            if ($('disablesendaddrbtn')) {
                $('disablesendaddrbtn').style.display = "";
            }
            if (xo == null || xo != "Y") {                         
                var params = "paddress1=" + escape(addrForm.paddress1.value) +
                         "&paddress2=" + escape(addrForm.paddress2.value) +
                         "&pcity=" + escape(addrForm.pcity.value) +
                         "&pstate=" + escape(addrForm.pstate.value) +
                         "&presidence=" + escape(addrForm.presidence.value) +
                         "&pzipcode=" + escape(addrForm.pzipcode.value) +
                         "&pemail=" + escape(addrForm.pemail.value) +
                         "&pcustpo=" + escape(addrForm.pcustpo.value) +
                         "&id=" + escape(addrForm.id.value) +
                         "&swatch=" + escape(addrForm.swatch.value) +
                         "&prodimage=" + escape(addrForm.prodimage.value) +
                         "&psave=N";
                if (addrForm.xo) {
                    params += "&xo=" + addrForm.xo.value;
                }                         
                makeRequest("todo=sendaddr&"+params, "alupd");
                setTimeout("makeRequest2()", showitemcnt_delay);
            } else {
            	addrForm.method="post";
                addrForm.action="/cs/OnlineOrdering?todo=sendaddr";
                addrForm.submit();
            }
        }
        return;
    }
    
    function sendAddr0(addrForm) {
        if (checkAddr(addrForm)) {
//          if ($('enablesendaddrbtn')) {
//              $('enablesendaddrbtn').style.display = "none";
//          }
//          if ($('disablesendaddrbtn')) {
//              $('disablesendaddrbtn').style.display = "";
//          }
            var params = "paddress1=" + escape(addrForm.paddress1.value) +
                     "&paddress2=" + escape(addrForm.paddress2.value) +
                     "&pcity=" + escape(addrForm.pcity.value) +
                     "&pstate=" + escape(addrForm.pstate.value) +
                     "&presidence=" + escape(addrForm.presidence.value) +
                     "&pzipcode=" + escape(addrForm.pzipcode.value) +
                     "&pemail=" + escape(addrForm.pemail.value) +
                     "&sendonly=Y";
            makeRequest("todo=sendaddr&"+params, "alert");
        }
    }
    
    function checkAddr(addrForm) {
        var errMsg = "";
        if (addrForm.paddress1.value.length == 0 &&
            addrForm.paddress2.value.length == 0) {
            errMsg = "Address1 and Address2 must not both be blank.";
        }
        if (addrForm.pcity.value.length == 0) {
            errMsg += "\nCity is required.";
        }
        if (addrForm.pstate.value.length == 0) {
            errMsg += "\nState is required.";
        }
        if (addrForm.pzipcode.value.length == 0) {
            errMsg += "\nZipcode is required.";
        }
        
        if (errMsg.length > 0) {
            alert(errMsg);
            return false;
        }
        
        
//      var re = /[\W]/;
//      var str = "";
//      if (addrForm.paddress1.value.length > 0) {
//          str = addrForm.paddress1.value;
//          //str = str.replace(/^%/, "");
//          //str = str.replace(/\s+|\.|#/g, "");
//          str = skipSpecialChars(str); 
//          if (re.test(str)) {
//              errMsg += "\nOnly alpha-numeric characters are allowed in the address field.";
//          }
//      }
//      if (addrForm.paddress2.value.length > 0) {
//          str = addrForm.paddress2.value;
//          //str = str.replace(/\s+|\.|#/g, "");
//          str = skipSpecialChars(str);
//          if (re.test(str)) {
//              errMsg += "\nOnly alpha-numeric characters are allowed in the address field.";
//          }
//      }
//      
//      re = /[^a-zA-Z]/;
//      if (addrForm.pcity.value.length > 0) {
//          str = addrForm.pcity.value;
//          //str = str.replace(/\s+/g, "");
//          str = skipSpecialChars(str);
//          if (re.test(str)) {
//              errMsg += "\nOnly alphabetic characters are allowed in the city field.";
//          }
//      }
//      if (re.test(addrForm.pstate.value)) {
//          errMsg += "\nOnly alphabetic characters are allowed in the state field.";
//      }
//                      
//      re = /[^0-9\-]/;
//      if (re.test(addrForm.pzipcode.value)) {
//          errMsg += "\nOnly numeric characters are allowed in the zipcode field.";
//      }
//      
        
        if (addrForm.pemail.value.length > 0) {
            var re = /[^a-zA-Z0-9@_\.\-]/;
            if (re.test(addrForm.pemail.value)) {
                errMsg += "\nOnly alpha-numeric characters and '@_-.' are allowed in email field.";
            //} else {
            //    var re = /\w+@\w+\.\w+/;
            //    if (!re.test(addrForm.pemail.value)) {
            //        errMsg += "\nIll formatted notify email field.";
            //    }
            }
        }
        
//      if (addrForm.pcustpo.value.length > 0) {
//          var re = /[^a-zA-Z0-9\-]/;
//          str = addrForm.pcustpo.value;
//          str = skipSpecialChars(str);
//          if (re.test(str)) {
//              errMsg += "\nOnly alpha-numeric and '-' characters are allowed in PO# field.";
//          }
//      }
            
        if (errMsg.length > 0) {
            alert (errMsg);
            return false;
        }
        return true;
    }
    
    function skipSpecialChars(str) {
        newstr = str.replace(/[%|(|)|#|\s]/g, "");
        return newstr;
    }
        
    
    function saleItems(sobj) {
        var params = "todo=saleitems&top=N&sortby=" + sobj.options[sobj.selectedIndex].value;
        makeRequest(params, null);
    }
    
    function __doSubmitOrder(fobj, option) {
        if ($('enablesubmitbtn')) {
            $('enablesubmitbtn').style.display = "none";
        }
        if ($('disablesubmitbtn')) {
            $('disablesubmitbtn').style.display = "";
        }
        var whnames = new Array("Cincinnati", "Dallas", "Florida", "NewJersey", "Reno", "Seattle");
        var whparams = new Array("cincinnati", "dallas", "florida", "newjersey", "reno", "seattle"); 
        //fobj.chkoutbtn_logoff.disabled = true;
        //fobj.chkoutbtn_continue.disabled = true;
        //$('a_submitandlogoff').disable = true;
        $('a_submitandcontinue').disable = true;
        var params = "todo=submitorder&";
        for (var i = 0; i < fobj.elements.length; i++) {
            el = fobj.elements[i];
            nam = el.name;
            switch (el.type) {
                case "select-one":
                    val = el.options[el.selectedIndex].value;
                    for (var w = 0; w < whnames.length; w++) {
                        if (nam == whnames[w]) {
                            params += "&pshipvia" + whparams[w] + "=" + escape(val);
                            break;
                        }
                    }
                    break;
                    
                case "text": case "hidden":
                    params += "&" + nam + "=" + escape(el.value);
                    break;
            }
        }
        params += "&option=" + option;
        makeRequest(params, "alupd");
        //setTimeout("makeRequest2()", showitemcnt_delay);        
        
    }
    
    function isShipMethodSelected(shipMethodValue){
    	
    	var warehouseShipMethod = document.getElementsByName("warehouseShipMethod");
    	
    	for(i = 0; i < warehouseShipMethod.length; i++)
    	{
    		if(document.getElementById(warehouseShipMethod[i].id).value == shipMethodValue)
    		{
    			return true;
    		}
    	}
    	
    	return false;
    }
    
    function doSubmitOrder(fobj, option) {

        if ((fobj.PayMethod.selectedIndex == 0) && (document.getElementById("terms").value == "COD")) {
            alert("You must choose a payment method.");
            return;
        }
    	
    	if(isShipMethodSelected("PSST") && document.getElementById("terms").value == "COD")
    	{
    		var message = "PSST orders can only be submitted with a credit card. Please either change the ship method to something other than PSST or select pay by credit card if you want to use PSST as the shipping method.";
    		alert(message);
    		return;
    	}
    	
        if ($('enablesubmitbtn')) {
            $('enablesubmitbtn').style.display = "none";
        }
        if ($('disablesubmitbtn')) {
            $('disablesubmitbtn').style.display = "";
        }
        var whnames = new Array("Cincinnati", "Dallas", "Florida", "NewJersey", "Reno", "Seattle");
        var whparams = new Array("cincinnati", "dallas", "florida", "newjersey", "reno", "seattle"); 
        //$('a_submitandlogoff').disable = true;
        $('a_submitandcontinue').disable = true;
        var params = "todo=submitorder&";
        for (var i = 0; i < fobj.elements.length; i++) {
            el = fobj.elements[i];
            nam = el.name;
            switch (el.type) {
                case "select-one":
                    val = el.options[el.selectedIndex].value;
                    for (var w = 0; w < whnames.length; w++) {
                        if (nam == whnames[w]) {
                            params += "&pshipvia" + whparams[w] + "=" + escape(val);
                            break;
                        }
                    }
                    break;
                    
                //case "text": case "hidden":
                //    params += "&" + nam + "=" + escape(el.value);
                //    break;
            }
        }
        
        
        var optValues=option.split(",");
        
        if(optValues.length>1){
        params += "&option=" + optValues[0];
        params += "&WT.z_ce_cat=" + optValues[1];
        params += "&WT.z_ce_name="+ optValues[2];
        }
        else{        //makeRequest(params, "alupd");
        	params += "&option=" + optValues[0];
        }
        
        fobj.action="/cs/OnlineOrdering?" + params;
        fobj.method="post";
        fobj.submit();
        
    }
                        
    function ccCheckout(fobj) {
        if ($('a_ccCheckOut')) {
            $('a_ccCheckOut').style.display = "none";
        }
        //if ($('a_submitandlogoff')) {
        //    $('a_submitandlogoff').style.display = "none";
        //}
        //if ($('a_submitandcontinue')) {
        //    $('a_submitandcontinue').style.display = "none";
        //}
        fobj.target="_top";
        fobj.action="/cs/OnlineOrdering?todo=cccheckout";
        fobj.method="post";
        fobj.submit();
        //var params = "todo=cccheckout";
        //makeRequest(params);
    }
    
    function toggleSaveBoxForm(opt) {
        if (opt == 1) {
            $("saveboxname").style.display = "";
        } else {
            $("saveboxname").style.display = "none";
        }
        
    }
    
    function validateByRegex(inputString, regex){
    	if(inputString.search(regex)==-1){
    		return false;
    	}else{
    		return true;
    	}	
    }
    
    function validateSpecialChars(inputString)
    {
    	var regex = /^[A-Za-z0-9]+[ -_A-Za-z0-9]*$/;

    	if(validateByRegex(inputString, regex)==true){
        	return true;            		
    	}else{
    		alert ("You have entered: " +inputString+"\nNote: Special Charaters are not allowed. Except for White space, Hyphen and Underscore are allowed between alphanumeric letters");
    		return false;
    	}
    }

    function saveBox() {
        if (document.ShopBoxForm.shopboxname.value.length == 0) {
            alert ("Enter name to be given to your new save box.");
            return;
        }
        else if(validateSpecialChars(document.ShopBoxForm.shopboxname.value)){
            var params = "todo=savebox&shopboxname="+document.ShopBoxForm.shopboxname.value;
            toggleSaveBoxForm(0);
            _tag.dcsCleanUp();
            dcsMultiTrack('DCS.dcssip',window.location.hostname , 'DCS.dcsuri','/SaveShoppingBox', 'WT.ti','Click: SaveShoppingBox', 'WT.dl','1', 'WT.si_n','Shopping Box Common Steps','WT.si_p','SaveShoppingBox');
            makeRequest(params, "alert");
        }

    }
    
    function getPantsGrid(frm) {
        var selectedIndx = frm.waist.selectedIndex;
        if (selectedIndx < 0) {
            return;
        }
        var params = "id=" + frm.id.value;
        params += "&prodimage=" + frm.prodimage.value;
        params += "&swatch=" + frm.swatch.value;
        params += "&waist=" + frm.waist.options[selectedIndx].value;
        if (frm.sitem != null) {
            params += "&sitem=" + frm.siterm.value;
        }
        if (frm.citem != null) {
            params += "&citem=" + frm.citem.value;
        }
        makeRequest(params, "alupd");
    }
    
    function getLRGrid(frm) {
        var selectedIndx = frm.lngth.selectedIndex;
        if (selectedIndx < 1) {
            return;
        }
        var params = "id=" + frm.id.value;
        params += "&prodimage=" + frm.prodimage.value;
        params += "&swatch=" + frm.swatch.value;
        params += "&length=" + frm.lngth.options[selectedIndx].value;
        if (frm.citem) {
            params += "&citem=" + frm.citem.value;
        }
        if (frm.sitem) {
            params += "&sitem=" + frm.sitem.value;
        }
        makeRequest(params, "alupd");
    }
    
    function displayCloseouts(selobj) {
        if (selobj.selectedIndex > 0) {
            var params = "todo=closeout";
            params += "&parent=" + selobj.options[selobj.selectedIndex].value;
            makeRequest(params, 'closeoutlists');
        }
    }
    function displayNewCloseouts() {
        var params = "todo=closeout&parent=RecentlyAdded";
        makeRequest(params, 'closeoutlists');
    }
    function getCloseoutGrid0(id, color) {
        //var params = "todo=closeout&id=" + id + "&swatch=" + escape(color) + "&citem=Y";
        //makeRequest(params, "citem");
        document.CloseoutForm.id.value = id;
        document.CloseoutForm.swatch.value = color;
        document.CloseoutForm.submit();        
    }
    function getCloseoutGrid1(id, selobj) {
        var selIndex = selobj.selectedIndex;
        if (selIndex <= 0) {
            return;
        }
        var params = "todo=closeout&id=" + id + "&swatch=" + escape(selobj.options[selIndex].value);
        makeRequest(params, "alupd");
    }
    function displayCloseoutLists() {
        if ($('grid0')) {
            $('grid0').style.display = 'none';
        }
        $('listView').style.display = '';
    }
    function displayListView() {
        if ($('grid0')) {
            $('grid0').style.display = 'none';
        }
        if ($('itemView')) {
            $('itemView').style.display='none';
            if ($('flvContent')) {
                $('flvContent').innerHTML = "";
            }
        }
        $('listView').style.display = '';
    }
    function displayItemView() {
        if ($('grid0')) {
            $('grid0').style.display = 'none';
        }
        if ($('listView')) {
            $('listView').style.display='none';
        }
        $('itemView').style.display = '';
    }

    function login(fobj) {
        var params = "todo=login&customerno=" + fobj.customerno.value +
                     "&username=" + fobj.username.value +
                     "&password=" + fobj.password.value;
        makeRequest(params, null);
    }
    
    function hiLiteTableRow(tabName, rowName, start) {
        var tt = $(tabName);
        if (tt == null) {
            return;
        }
        trs = tt.getElementsByTagName("tr");
        if (trs == null) {
            return;
        }
        for (var i = start; i < trs.length; i++) {
            if (trs[i].id == rowName) {
                trs[i].style.background="#FFFFCC";
            } else {
                trs[i].style.background = "#ffffff";
            }
        }
    }
    
    function noLiteTable(tabName, start) {
        var tt = $(tabName);
        if (tt == null) {
            return;
        }
        trs = tt.getElementsByTagName("tr");
        if (trs == null) {
            return;
        }
        for (var i = start; i <= trs.length; i++) {
            if (trs[i] != null) {
                trs[i].style.background = "#ffffff";
            }
        }
    }
        
    
    function toggleScroll(el, ht) {
        
        if ($(el)) {
            if ($(el).style.height == "") {
                $(el).style.height = ht;
            } else {
                $(el).style.height = "";
            }
        }
    }
    
    // funtions called from login page
	function CookieDef(expires,path,domain,secure)
	{
	  this.secure = secure;
	  this.path = path;
	  this.domain = domain;
	  this.getValue = getCookie;
	  this.setValue = setCookie;
	  this.expire = deleteCookie;
	  if (expires == 0) {
	    this.expires = "";
	  } else {
	    var today_date = new Date();
		 var expire_seconds = today_date.getTime() + (expires * 24 * 60 * 60  * 1000);
	    today_date.setTime(expire_seconds);
	    this.expires = today_date.toGMTString();
	  }
	}
	function getCV(offset) {
	  var endstr = document.cookie.indexOf(";", offset);
	  if (endstr == -1) endstr = document.cookie.length;
	  return unescape(document.cookie.substring(offset, endstr));
	}
	function getCookie(name) {
	  var arg = name + "=";
	  var alen = arg.length;
	  var clen = document.cookie.length;
	  var i = 0;
	  while (i < clen) {
	    var j = i + alen;
	    if (document.cookie.substring(i, j) == arg)
	      return getCV(j);
	    i = document.cookie.indexOf(" ", i) + 1;
	    if (i == 0) break;
	  }
	  return "";
	}
	function setCookie(name,value)
	{
	  document.cookie = name + "=" + escape(value) +
	    ((this.expires == "") ? "" : ("; expires=" + this.expires)) +
	    ((this.path == "") ? "" : ("; path=" + this.path)) +
	    ((this.domain == "") ? "" : ("; domain=" + this.domain)) +
	    ((this.secure == true) ? "; secure" : "");
	}
	function deleteCookie(name) {
	  document.cookie = name + "=" + "" + "; expires=Thu,01-Jan-70 00:00:01 GMT";
	}
	
	function WA_setCookie(cookieobj, cookiename, cookievalue, cookiecheck, settype)     {
	  var theValue = "";
	  if (settype == 1)     {
	    for (var n=0; n<cookievalue.length; n++)    {
	      if (cookievalue[n].checked)     {
	        theValue = cookievalue[n].value;
	      }
	    }
	  }
	  else      {
	    theValue = cookievalue
	  }
	
	  if (cookiecheck)     {
	    cookieobj.setValue(cookiename, theValue);
	  }
	}
	
	function WA_deleteCookie(cookieobj, cookiename, cookiecheck)     {
	  if (cookiecheck)     {
	    cookieobj.setValue(cookiename, "");
	    cookieobj.expire(cookiename);
	  }
	}
	function CookieDef(expires,path,domain,secure)
	{
	  this.secure = secure;
	  this.path = path;
	  this.domain = domain;
	  this.getValue = getCookie;
	  this.setValue = setCookie;
	  this.expire = deleteCookie;
	  if (expires == 0) {
	    this.expires = "";
	  } else {
	    var today_date = new Date();
		 var expire_seconds = today_date.getTime() + (expires * 24 * 60 * 60  * 1000);
	    today_date.setTime(expire_seconds);
	    this.expires = today_date.toGMTString();
	  }
	}
	function getCV(offset) {
	  var endstr = document.cookie.indexOf(";", offset);
	  if (endstr == -1) endstr = document.cookie.length;
	  return unescape(document.cookie.substring(offset, endstr));
	}
	function getCookie(name) {
	  var arg = name + "=";
	  var alen = arg.length;
	  var clen = document.cookie.length;
	  var i = 0;
	  while (i < clen) {
	    var j = i + alen;
	    if (document.cookie.substring(i, j) == arg)
	      return getCV(j);
	    i = document.cookie.indexOf(" ", i) + 1;
	    if (i == 0) break;
	  }
	  return "";
	}
	function setCookie(name,value)
	{
	  document.cookie = name + "=" + escape(value) +
	    ((this.expires == "") ? "" : ("; expires=" + this.expires)) +
	    ((this.path == "") ? "" : ("; path=" + this.path)) +
	    ((this.domain == "") ? "" : ("; domain=" + this.domain)) +
	    ((this.secure == true) ? "; secure" : "");
	}
	function deleteCookie(name) {
	  document.cookie = name + "=" + "" + "; expires=Thu,01-Jan-70 00:00:01 GMT";
	}
	
	function WA_getCookie(cookieobj, cookiename, cookieset, settype)     {
	  theValue = cookieobj.getValue(cookiename);
	
	  if (settype == 1)     {
	    cookieset.value = theValue;
	  }
	  if (settype == 2)     {
	    cookieset.checked = (String(theValue)!="" && String(theValue).toUpperCase() !="FALSE");
	  }
	  if (settype == 3)     {
	    for (var n=0; n< cookieset.length; n++)     {
	      if (cookieset[n].value == theValue)     {
	        cookieset[n].checked = true;
	        break;
	      }
	    }
	  }
	  if (settype == 4)     {
	    for (var n=0; n< cookieset.options.length; n++)     {
	      if (cookieset.options[n].value == theValue)     {
	        cookieset.selectedIndex = n;
	        break;
	      }
	    }
	  }
	}
    
    var fidalgo = new CookieDef(30,"/","","true");
    
    function __displayElapsedTime__() {
        if (skiptimer || elapsedTimerOn) {
            return;
        }
        
        //makeRequest1();
        var url = "/cs/OnlineOrdering";
        var params = "todo=webrefage";
        params += "&r=" + Math.random();
        
        new Ajax.Request(
            url,
            {
                method:     'get',
                parameters: params,
                onSuccess:  function(transport) {
                                var elapsedTime = transport.responseText;
                                if (elapsedTime.indexOf("ERROR") >= 0) {
                                    skiptimer = true;
                                    elapsedTime = "";
                                } else {
                                    //if (elapsedTime.indexOf("alert10")>=0) {
                                    //    alert("You have less than 10 minutes to complete your order.");
                                    //} else if (elapsedTime.indexOf("alert3")>=0) {
                                    //    alert("You have less than 3 minutes to complete your order.");
                                    //}
                                    if ($('elapsedTime')) {
                                        $('elapsedTime').innerHTML = elapsedTime;
                                    }
                               }
                                
                            }
            }
        )
        
        runTimer();
    }
        
    
    function runTimer() {
        if ($('elapsedTime') == null) {
            return;
        }
                
        if (!elapsedTimerOn) {
            var elapsedTime = $('elapsedTime').innerHTML;
            if (elapsedTime.indexOf("alert10")>=0) {
                ALERT10SECS = false;
            } else if (elapsedTime.indexOf("alert3")>=0) {
                ALERT10SECS = false;
                ALERT03SECS = false;
            }
            
            var l = elapsedTime.indexOf("Time left: ");
            if (l > 0) {
               var tsecs = elapsedTime.substring(l + 11);
               l = tsecs.indexOf("<");
               if (l>0) {
                    tsecs = tsecs.substring(0, l);
                }
               SECSLEFT = tsecs - 0;
               elapsedTimerOn = true;
            }
        }
           
        if (SECSLEFT > 0) {
            if ((SECSLEFT < 600) && ALERT10SECS) {
                alert("You have less than 10 minutes to submit your order.");
                ALERT10SECS = false;
            }
            if ((SECSLEFT < 180) && ALERT03SECS) {
                alert("You have less than 3 minutes to submit your order.");
                ALERT03SECS = false;
            }
            if ($('elapsedTime')) {
                $('elapsedTime').innerHTML = "Time left: " + SECSLEFT + " seconds";
            }
            SECSLEFT = SECSLEFT - 1;
        } else if (elapsedTimerOn) {
            if ($('elapsedTime')) {
                $('elapsedTime').innerHTML = " Sorry, time to shop expired, please re-login to continue shopping.";
            }
        }
        
        setTimeout("runTimer()", 1000);
    }
    
     function runProductVideoPlayer(flvname) {
       if ($('flvContent') == null) {
            return;
        }
        //if ($('_video_').style.display != "none") {
        //    hidediv('_video_');
        //    showdiv('overview');
        //    return;
        //}
        
        //hidediv('overview');
        //hidediv('description');
        //hidediv('comparables');
        //hidediv('catalog');
        //showdiv('_video_');
           
	    //var so = new SWFObject( "/templates/swf/vplayer.swf" , "vplayer" , "371" , "277" , "8.0.22");
		// NOTE: height is actual video height plus 42 px for vcr controls
	    var so = new SWFObject( "/marketing/video/player.swf" , "player" , "358" , "310" , "8.0.22");
	   
	    // this line is a bug fix
	    so.setAttribute("style",";");

	    // Parameters
	    so.addParam( "scale"   , "noscale" );
	    so.addParam( "align"   , "middle" );
	    so.addParam( "salign"  , "TL" );
	    so.addParam( "quality" , "high" );
	    so.addParam( "bgcolor" , "#ffffff" );
		so.addParam("wmode", "opaque");


	    // Receive variables
	   
	    // video url
	    //so.addVariable( "vfile"  , "rtmp://media.sanmar.com/sanmar/" + flvname);
        so.addVariable( "vfile"  , "rtmp://sas-Flash.OnstreamMedia.com/ondemand/FlashDMSP/sanmar/[Inbox]/sanmardotcom/" + flvname);

	    // optional skin
	    so.addVariable( "vskin"  , "/templates/swf/SteelExternalAll.swf" );
	   
        //so.addVariable( "tstring", "Click 'Video' to close");
       // so.addVariable( "tstring", "");
	   
	    // Write the application
	    so.write( "flvContent" );
    }
     
    function submitCheck(evt, fobj, qlevel, qobj) {
        var codeval;
        if (evt.which) {
            codeval = evt.which;
        } else {
            codeval = evt.keyCode;
        }
        
        if (codeval != 13) {
            if ((codeval == 8) || (codeval == 9) || (codeval == 45) || (codeval == 46) || (codeval == 37) || (codeval == 39)) {
                return true;
            }
            var keyChar = String.fromCharCode(codeval);
            var re = /[^\d]/;
            if (re.test(keyChar)) {
                alert("You pressed an invalid key -> " + keyChar);
                //qobj.value = qobj.value.substring(0, qobj.value.length - 1);
                return false;
            }
            return true;
        }
        
        var re = /[^0-9\+]/;
        if (re.test(qobj.value)) {
//          alert("\nYou entered '" +qobj.value + "' which is invalid. Only numeric characters are allowed.");
//          qobj.value = '';
        	qobj.onblur();
            return false;
        }
        var v = qobj.value - 0;
        if (isNaN(v) || (v < 0)) {
//          alert("The number you entered, '" + qobj.value + "' is invalid.");
//          qobj.value = "";            
        	qobj.onblur();
        	return false;
        }
        if (qlevel != "500+") {
            var q = qlevel - 0;
            if (isNaN(q) || (v>q)) {
            	qobj.onblur();
            	return false;
            }
        }
        
        doGridSubmit(fobj);
        return false;
    }   

    function highLiteRow(rr) {
        for (r=1; r<7; r++) {
            if (r==rr) {
                $('ww_'+rr).style.backgroundColor="#ffffcc";
                $('mb_'+rr).style.display="";
            } else {
                $('ww_'+r).style.backgroundColor="#ffffff";
                $('mb_'+r).style.display="none";
            }
        }
    }
    var mxc = 10;
    var itemgrid_high_vis = mxc;
    var itemgrid_low_vis = 1;
    function itemgridToRight(rrr) {
        var high = itemgrid_high_vis + 1 - 0;
        if ($('cell_1_'+high) == null) {
            return;
        }
        
        for (var c=1; c <= rrr; c++) {
            if ($('cell_'+c+'_'+high) == null) {
                break;
            }
            $('cell_'+c+'_'+high).style.display="";
        }
        for (var c=1; c <= rrr; c++) {
            if ($('cell_'+c+'_'+itemgrid_low_vis) == null) {
                break;
            }
            $('cell_'+c+'_'+itemgrid_low_vis).style.display="none";
        }
        itemgrid_high_vis = high;
        itemgrid_low_vis += 1;
        var h = high + 1 -0;
        $('itemgrid_leftarrow').style.display = "";
        $('itemgrid_leftarrow1').style.display = "";
        if ($('cell_1_'+h) == null) {
            $('itemgrid_rightarrow').style.display="none";
            $('itemgrid_rightarrow1').style.display="none";
        }
    }
    function itemgridToLeft(rrr) {
        if (itemgrid_low_vis == 1) {
            return;
        }
        
        var low = itemgrid_low_vis - 1;
        for (var c=1; c <= rrr; c++) {
            if ($('cell_'+c+'_'+low) == null) {
                break;
            }
            $('cell_'+c+'_'+low).style.display="";
        }
        for (var c=1; c <= rrr; c++) {
            if ($('cell_'+c+'_'+itemgrid_high_vis) == null) {
                break;
            }
            $('cell_'+c+'_'+itemgrid_high_vis).style.display="none";
        }
        itemgrid_high_vis -= 1;
        itemgrid_low_vis = low;
        $('itemgrid_rightarrow').style.display = "";
        $('itemgrid_rightarrow1').style.display = "";
        if (low == 1) {
            $('itemgrid_leftarrow').style.display = "none";
            $('itemgrid_leftarrow1').style.display = "none";
        }
    }
    var itemgridPageSize = mxc;
    var itemgrid_page = 1;
    function itemgridNextPage(rrr) {
        var pg = (itemgrid_page - 1) * mxc;
        if ($('cell_1_'+ (pg+1)) == null) {
            return;
        }
        
        for (var c = pg+1; c<=pg+mxc; c++) {
            if ($('cell_1_'+c)==null) {
                break;
            }
            for (var r=1; r<=rrr; r++) {
                if ($('cell_'+r+'_'+c) != null) {
                    $('cell_'+r+'_'+c).style.display = "none";
                } else {
                    continue;
                }
            }
        }
        
        pg = itemgrid_page * mxc;
        for (var c = pg+1; c<=pg+mxc; c++) {
            if ($('cell_1_'+c)==null) {
                break;
            }
            for (var r=1; r<=rrr; r++) {
                if ($('cell_'+r+'_'+c) != null) {
                    $('cell_'+r+'_'+c).style.display = "";
                } else {
                    break;
                }
            }
        }
        itemgrid_page += 1;
        $('itemgrid_prev_page0').style.display = '';
        $('itemgrid_prev_page').style.display = '';
        var c = itemgrid_page*mxc + 1
        if ($('cell_1_'+c) == null) {
            $('itemgrid_next_page0').style.display = 'none';
            $('itemgrid_next_page').style.display = 'none';
        }
    }
        
    function itemgridPrevPage(rrr) {
        if (itemgrid_page <= 1) {
            return;
        }
        
        var pg = (itemgrid_page - 1) * mxc;
        for (var c = pg+1; c<=pg+mxc; c++) {
            if ($('cell_1_'+c)==null) {
                break;
            }
            for (var r=1; r<=rrr; r++) {
                if ($('cell_'+r+'_'+c) != null) {
                    $('cell_'+r+'_'+c).style.display = "none";
                } else {
                    break;
                }
            }
        }
        
        pg = (itemgrid_page-2) * mxc;
        for (var c = pg+1; c<=pg+mxc; c++) {
            if ($('cell_1_'+c)==null) {
                break;
            }
            for (var r=1; r<=rrr; r++) {
                if ($('cell_'+r+'_'+c) != null) {
                    $('cell_'+r+'_'+c).style.display = "";
                } else {
                    break;
                }
            }
        }
        itemgrid_page -= 1;
        if (itemgrid_page == 1) {
            $('itemgrid_prev_page0').style.display = 'none';
            $('itemgrid_prev_page').style.display = 'none';
        }
        $('itemgrid_next_page0').style.display = '';
        $('itemgrid_next_page').style.display = '';
    }

    function itemgridToLast(ncols, rrr) {
        var low = ncols - 9;
        for (var c=1; c <= ncols; c++) {
            if ($('cell_1_'+c) == null) {
                break;
            }
            showOrHide = "";
            if (c < low) {
                showOrHide = "none";
            }
            //alert("C:"+c);
            for (var r = 1; r <= rrr; r++) {
                //alert("r:"+r+"  c:"+c);
                if ($('cell_'+r+'_'+c) == null) {
                    break;
                }
                $('cell_'+r+'_'+c).style.display = showOrHide;
            }
        }
        itemgrid_high_vis = ncols;
        itemgrid_low_vis = low;
        $('itemgrid_leftarrow').style.display = "";
        $('itemgrid_rightarrow').style.display="none";
        $('itemgrid_leftarrow1').style.display = "";
        $('itemgrid_rightarrow1').style.display="none";
    }
    
    function itemgridToFirst(ncols, rrr) {
        for (var c=1; c <= ncols; c++) {
            if ($('cell_1_'+c) == null) {
                break;
            }
            showOrHide = "";
            if (c > 10) showOrHide = "none";
            for (var r = 1; r <= rrr; r++) {
                if ($('cell_'+r+'_'+c) == null) {
                    break;
                }
                $('cell_'+r+'_'+c).style.display = showOrHide;
            }
        }
        itemgrid_high_vis = 10;
        itemgrid_low_vis = 1;
        $('itemgrid_leftarrow').style.display = "none";
        $('itemgrid_rightarrow').style.display="";
        $('itemgrid_leftarrow1').style.display = "none";
        $('itemgrid_rightarrow1').style.display="";
    }
        

