/*     * partner_product_details_soap_client.js  Version 3.0    * All functions, classes related to product pricing.    *     * 10/28/2009    *   Updated products for 2010      *   Moved JSON string conversion to commons since now we need it as a generic function    *    * Copyright HRB Digital LLC*/ /*    An instance of PartnerProduct() represents a partner and its software, office and online product information.        Methods of the PartnerProduct() object are:    getObj()    getStatusTCO()    getStatusTCS()    getPartnerInfo()    getPartnerCID()    getPartnerName()    getPartnerType()    getPartnerWelcome()    getPartnerOtpPartnerId()    getPartnerTunnel()    getPartnerID()    getPartnerActive()    getProductInfo()    getProductId()    getProductBasePrice()    getProductPartnerPrice()    getProductName()    getProductStartNow()    getProductLearnMore()    getProductSKU()    getProductPlatform()    getProductOmnitureName()    getProductsByPlatform()    getCompressedStr()    updatePartnerProduct()    toString()*/function PartnerProduct() {        this._partner_product;        this.getObj =function()        {            return this._partner_product;        }                this.setObj =function(prodlist)        {   // prodList also includes partner information also such as name, cid, etc.            this._partner_product=prodlist;        }        // **********************************************************        // ************** BEGIN STATUS GETTER METHODS **************        // **********************************************************        /*Fetch the status for TCO requests*/        this.getStatusTCO=function () {            return this._partner_product.status.tco;        }        /*Fetch the status for TCS requests*/        this.getStatusTCS=function () {            return this._partner_product.status.tcs;        }        // **********************************************************        // ************** BEGIN PARTNER GETTER METHODS **************        // **********************************************************                /*Fetch the partner info object*/        this.getPartnerInfo=function () {            return this._partner_product.partner;        }        /*Fetch the partnerCID for this partner*/        this.getPartnerCID=function () {            return this._partner_product.partner.cid;        }        /*Fetch the partnerName for this partner*/        this.getPartnerName=function () {            return this._partner_product.partner.partnerName;        }        /*Fetch the for partnerType this partner*/        this.getPartnerType=function () {            return this._partner_product.partner.partnerType;        }        /*Fetch the partnerWelcome text for this partner*/        this.getPartnerWelcome=function () {            return this._partner_product.partner.partnerWelcome;        }        /*Fetch the otpPartnerID for this partner*/        this.getPartnerOtpPartnerId=function () {            return this._partner_product.partner.otpPartnerID;        }        /*Fetch the partnerTunnel indicator for this partner*/        this.getPartnerTunnel=function () {            return this._partner_product.partner.partnerTunnel;        }        /*Fetch the yearly CMS partner Id (NOT the otp partner id) for this partner*/        this.getPartnerID=function () {            return this._partner_product.partner.partnerID;        }        /*Fetch the partnerActive indicator for this partner*/        this.getPartnerActive=function () {            return this._partner_product.partner.partnerActive;        }        // **********************************************************        // ************** BEGIN PRODUCT GETTER METHODS **************        // **********************************************************                /*get the product info for a given product*/        this.getProductInfo=function (prodID){            var t_prodlist=this._partner_product.prodList;            for (var i=0; i<t_prodlist.length;i++ ){                if (t_prodlist[i].pid==prodID){                    return t_prodlist[i];                }            }            return null;        }        /*get the product id for a product*/        this.getProductId=function (prodID){            return this.getProductInfo(prodID).pid;        }                /*get the base price for a product*/        this.getProductBasePrice=function (prodID){           return this.getProductInfo(prodID).bpr;        }        /*get the partner price for a product*/        this.getProductPartnerPrice=function (prodID){            return this.getProductInfo(prodID).ppr;        }        /*get the Name for a product*/        this.getProductName=function (prodID){            return this.getProductInfo(prodID).pn;        }        /*get the Start Now for a product*/        this.getProductStartNow=function (prodID){            return this.getProductInfo(prodID).sn;        }        /*get the Learn More for a product*/        this.getProductLearnMore=function (prodID){            return this.getProductInfo(prodID).lm;        }        /*get the SKU for a product*/        this.getProductSKU=function (prodID){            return this.getProductInfo(prodID).sk;        }        /*get the Platform for a product*/        this.getProductPlatform=function (prodID){            return this.getProductInfo(prodID).pl;        }        /*get the Omniture Name for a product*/        this.getProductOmnitureName=function (prodID){            return this.getProductInfo(prodID).on;        }                        // **********************************************************        // **************     BEGIN OTHER FUNCTIONS    **************        // **********************************************************                /*  fetch list of products by a given platform            Platform type 'O':online 'S':software 'R':retail            returns an array of product objects        */        this.getProductsByPlatform=function (platform){            var prodarr= new Array();            var t_prodlist=this._partner_product.prodList;            for (var i=0; i<t_prodlist.length;i++ )            {                if (t_prodlist[i].pl==platform)                {                    prodarr[prodarr.length]=t_prodlist[i];                }            }            return prodarr;        }                /*  compresses the complete product list object            returns a JSON string which is compressed            used to store the data in the cookies        */        this.getCompressedStr=function()        {                              //remove the product name and SK text to compress            for (var k=0;k< this._partner_product.prodList.length;k++ ){               this._partner_product.prodList[k].pn='-';               this._partner_product.prodList[k].sk='-';               this._partner_product.prodList[k].on='-';            }            var str=this.toString();            //var str = jsonToString(this._partner_product);            str = str.replace(/partner/g,"^a");            str = str.replace(/TaxYear=20/g, "^b");            str = str.replace(/TaxType=/g, "^c");            str = str.replace(/Target=/g, "^d");            str = str.replace(/\/loginRedirect.html/g, "^e");            str = str.replace(/product.jsp/g, "^f");            str = str.replace(/\/universal\/office_locator.html/g, "^g");            str = str.replace(/office/g, "^h");            str = str.replace(/NOT_APPLICABLE/g, "^i");            str = str.replace(/.html/g, "^j");            str = str.replace(/productId=/g, "^1");            str = str.replace(/otpPartnerId=/g, "^2");            str = str.replace(/&FV=T&HT=F/g, "^3");            str = str.replace(/state/g, "^4");            str = str.replace(/taxcut/g, "^5");            str = str.replace(/premium/g, "^6");            str = str.replace(/software/g, "^7");            str = str.replace(/online/g, "^8");            str = str.replace(/\/taxes\/doing_my_taxes\/products\/popup\/otp_compare_popup.html/g, "^9");                        return str;        }        /*  Passes a string representation of the product info            to be converted into JSON object form            Normally updated from the cookie value        */        this.setPartnerProduct=function(str,decompress)        {               if (decompress)            {                str = str.replace(/\^a/g, "partner");                str = str.replace(/\^b/g, "TaxYear=20");                str = str.replace(/\^c/g, "TaxType=");                str = str.replace(/\^d/g, "Target=");                str = str.replace(/\^e/g, "/loginRedirect.html");                str = str.replace(/\^f/g, "product.jsp");                str = str.replace(/\^g/g, "/universal/office_locator.html");                str = str.replace(/\^h/g, "office");                str = str.replace(/\^i/g, "NOT_APPLICABLE");                str = str.replace(/\^j/g, ".html");                str = str.replace(/\^1/g, "productId=");                str = str.replace(/\^2/g, "otpPartnerId=");                str = str.replace(/\^3/g, "&FV=T&HT=F");                str = str.replace(/\^4/g, "State");                str = str.replace(/\^5/g, "taxcut");                str = str.replace(/\^6/g, "premium");                str = str.replace(/\^7/g, "software");                str = str.replace(/\^8/g, "online");                str = str.replace(/\^9/g, "/taxes/doing_my_taxes/products/popup/otp_compare_popup.html");            }            try            {                this._partner_product=eval('('+str+')');                var _defresp =  g_online_def_price;                //strip starting and ending square brackets off the software pricing                var _tmpSoft=g_soft_def_price.replace(/\[/,'').replace(/\]/,'');                _defresp=_defresp.replace(/\]}/g, ','+_tmpSoft+']}');                var _tmp_ppobj=eval('('+_defresp+')');                //since the object from the cookie does not have sk and on info, add it back from                 //default obj                for (var k=0;k< _tmp_ppobj.prodList.length;k++ )                {                        this._partner_product.prodList[k].sk= _tmp_ppobj.prodList[k].sk;                        this._partner_product.prodList[k].on= _tmp_ppobj.prodList[k].on;                }                _tmp_ppobj=null;            }            catch (e)            {                setCookie("wsc", "", null, "/");                //document.location = document.location.href;            }                    }                var $ = {"boolean":function(){return Boolean},            "function":function(){return Function},            "number":function(){return Number},            "object":function(o){return o instanceof o.constructor?o.constructor:null},            "string":function(){return String},            "undefined":function(){return null}            }        /*            converts the object JSON object to string        */        this.toString = function(){            var self = arguments.length ? arguments[0] : this._partner_product,                result, tmp;            if(self === null){                result = "null";            }            else if(self !== undefined && (tmp = $[typeof self](self))) {                switch(tmp){                    case    Array:                        result = [];                        for(var i = 0, j = 0, k = self.length; j < k; j++) {                            if(self[j] !== undefined && (tmp = this.toString(self[j]))){                                result[i++] = tmp;                            }                        };                        result = "[".concat(result.join(","), "]");                        break;                    case    Boolean:                        result = String(self);                        break;                    case    Date:                        break;                    case    Function:                        break;                    case    Number:                        result = isFinite(self) ? String(self) : "null";                        break;                    case    String:                        result = '"'.concat(self, '"');                        break;                    default:                        var i = 0, key;                        result = [];                        for(key in self) {                            if(self[key] !== undefined && (tmp = this.toString(self[key]))){                                result[i++] = ''.concat(key, ':', tmp);                            }                        };                        result = "{".concat(result.join(","), "}");                        break;                }            };            return result;        };            }        function checkRespIntegrity(keywords, txt)    {                var chkformat_reg= /[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/;        try{            var rc=new RegExp(keywords)            if (chkformat_reg.test(txt) && rc.test(txt) ){                return true;            }             else{                g_log.error('E21:'+txt.length+':'+keywords);            }        }        catch (e){            g_log.error('E22')            return true;        }        return false;    }    function partnerProductSuccess(resp)    {        g_log.debug('<b>Inside partnerProductSuccess.</b>');        if (resp==''){            g_log.error('E13');        }        /*if the response looks valid, copy required attributes to template obj*/        if (checkRespIntegrity('{partner:', resp)){            g_log.debug('partnerProductSuccess partnerinfo from webservice is ok.');            var _ppobj= g_hrb_partner_product.getObj();            _ppobj.status.tco=1;            var _json_partner_prod = eval('('+resp+')');                        var tmppartner=g_hrb_partner_product.getPartnerInfo();            tmppartner.cid=_json_partner_prod.partner.cid;            tmppartner.partnerName  =_json_partner_prod.partner.partnerName;            tmppartner.partnerType  =_json_partner_prod.partner.partnerType;            tmppartner.otpPartnerID =_json_partner_prod.partner.otpPartnerID;            tmppartner.partnerTunnel=_json_partner_prod.partner.partnerTunnel;            tmppartner.partnerID    =_json_partner_prod.partner.partnerID;            tmppartner.partnerActive=_json_partner_prod.partner.partnerActive;            var _add_prod=new Array();//store the products not found in the default list            for (var j=0;j<_json_partner_prod.prodList.length ;j++ ){                var tmpprodobj= g_hrb_partner_product.getProductInfo(_json_partner_prod.prodList[j].pid);                                if (tmpprodobj!=null)                {                    g_log.debug('partnerProductSuccess WS response::(for products in def) bpr:'+_json_partner_prod.prodList[j].bpr+' | ppr:'+_json_partner_prod.prodList[j].ppr + ' | pid:'+_json_partner_prod.prodList[j].pid);                    tmpprodobj.bpr=_json_partner_prod.prodList[j].bpr;                    tmpprodobj.ppr=_json_partner_prod.prodList[j].ppr;                    tmpprodobj.sn=_json_partner_prod.prodList[j].sn;                    tmpprodobj.lm=_json_partner_prod.prodList[j].lm;                    tmpprodobj.sk=_json_partner_prod.prodList[j].sk;                }                else{//find products not in the default list                    g_log.debug('partnerProductSuccess WS response::<b>(products not in def)</b> bpr:'+_json_partner_prod.prodList[j].bpr+' | ppr:'+_json_partner_prod.prodList[j].ppr + ' | pid:'+_json_partner_prod.prodList[j].pid);                    _add_prod[_add_prod.length]={pid:_json_partner_prod.prodList[j].pid,pn:"-",sn:_json_partner_prod.prodList[j].sn,lm:_json_partner_prod.prodList[j].lm,bpr:_json_partner_prod.prodList[j].bpr,ppr:_json_partner_prod.prodList[j].ppr,sk:"-",pl:_json_partner_prod.prodList[j].pl,on:"-"};                }            }            //add products to the default object            for (var k=0; k<_add_prod.length ;k++ ){                _ppobj.prodList.push(_add_prod[k]);                                    }            //_json_partner_prod=null;            //_add_prod=null;        }else{            g_log.error("E12");            g_hrb_partner_product.getObj().status.tco=0;        }        webServiceCallSuccess();        }    function partnerProductFailure(errorcode)    {        g_log.debug('<b>Inside partnerProductFailure</b>');        g_log.error("E11:"+errorcode);        webServiceCallFailed();    }     function callpartnerJSON(partnerid){        g_log.debug('<b>Inside callpartnerJSON</b>');        /************** START ONLY for testing **************/        var failpartner= queryString('forcefail_partner');        if (failpartner!= null && (failpartner=="true" || failpartner==true))        {            partnerProductFailure("404");            return;        }        /************** END   ONLY for testing **************/        var url='/HrbWebservices/services/servlet/JsonProductInfo';                postData="otpPartnerID="+partnerid;        new ajaxreq(url,postData,"partnerProductSuccess","partnerProductFailure","");    }    function callsoftwarepricing(offer,pgm)    {        g_log.debug('<b>Inside callsoftwarepricing</b>::offer::'+offer+' pgm::'+pgm);                /************** START ONLY for testing **************/        /****************************************************/        var failsoft= queryString('forcefail_software');        if (failsoft!= null && (failsoft=="true" || failsoft==true))        {            softwareFailure("error");            return;        }        /************** END   ONLY for testing **************/        /****************************************************/        var softobj=eval('('+g_soft_def_price+')');        var prod_params="";        for (var j=0;j<softobj.length ;j++ )        {            if (softobj[j].sk=="-" || softobj[j].sk=="")            {                continue;            }            prod_params+= (softobj[j].sk+ ""+ ( (j==(softobj.length-1))?"":":"));        }        softobj=null;        var postdata=null;                var url1="/json/JSONProxyServlet";                if (offer=='' || offer==null ||offer=='0'){                postdata="pid_list="+prod_params;        }        else{            var add_args="";            if (offer!=null && offer!='' ){                add_args+="&off_id="+offer;            }                        if (pgm!=null && pgm!='' ){                add_args+="&pgm_id="+pgm;            }            else  {                add_args+="&pgm_id="+14166300;            }            postdata="pid_list="+prod_params+add_args;        }        g_log.debug('callsoftwarepricing ::postdata'+postdata);        new ajaxreq(url1,postdata,"softwareSuccess","softwareFailure","");    }     function softwareSuccess(resp)    {        g_log.debug('<b>Inside softwareSuccess</b>');        if (resp==''){            g_log.error('E18');        }        resp=resp.substring(resp.indexOf('[{'),resp.indexOf('}}]')+3);        if (checkRespIntegrity('productID',resp)) {            g_log.debug('Software info from DR is ok.');            g_hrb_partner_product.getObj().status.tcs=1;            var _softprod_dr = eval('('+resp+')');            g_log.debug('softwareSuccess DR resp total products '+_softprod_dr.length);            var _softprod_def= g_hrb_partner_product.getProductsByPlatform('S');            for (var j=0;j<_softprod_def.length ;j++ ){                 // remove the dollar sign since online pricing does not have $                 var  priceobj='-';                 //if the product is not found in the DR response                 try{                        priceobj=_softprod_dr[j].price;                        g_log.debug('softwareSuccess bpr:'+priceobj.unitPrice+' | ppr:'+priceobj.unitPriceWithDiscount+' | sk:'+_softprod_def[j].sk+ ' | pid:'+_softprod_def[j].pid);                        _softprod_def[j].bpr=(priceobj.unitPrice!=null || typeof priceobj.unitPrice != 'undefined')?(priceobj.unitPrice.substring(1)):priceobj.unitPrice ;                        _softprod_def[j].ppr=(priceobj.unitPriceWithDiscount !=null || typeof priceobj.unitPriceWithDiscount != 'undefined')?(priceobj.unitPriceWithDiscount.substring(1)):priceobj.unitPriceWithDiscount ;                }catch(e){                    if( (typeof _softprod_dr[j]!='undefined') && _softprod_dr[j].pid!=null && _softprod_dr[j].pid!='34')                    g_log.error("E19:"+_softprod_dr[j].pid);                }            }        }        else{            g_log.error('E17');            g_hrb_partner_product.getObj().status.tcs=0;        }       remoteDataProcessComplete();        }    function softwareFailure(errorcode)    {        g_log.error('E17');        g_log.debug('<b>Inside softwareFailure</b>');        remoteDataProcessComplete();    }    function getPartnerProduct(partnerid)    {           g_log.debug('<b>Inside getProductInfo</b> :partnerid::'+partnerid);        //Initialize the final JSON str with onlinepricig        var finalresp =  g_online_def_price;        //strip starting and ending square brackets off the software pricing        var tmpSoftStr=g_soft_def_price.replace(/\[/,'').replace(/\]/,'');        finalresp=finalresp.replace(/\]}/g, ','+tmpSoftStr+']}');        g_hrb_partner_product.setObj(eval('('+finalresp+')'));        if (getWebServiceCookie(partnerid))        {            g_log.debug('getProductInfo webService call is NOT needed ');            webServiceCallNotNeeded();   // shares much logic with the webServiceCallSuccess()        }        else        {            callpartnerJSON(partnerid);        }    }    //initialize the product info objectvar g_hrb_partner_product= new PartnerProduct();