/*     * partner_product_details_soap_client.js  Version 3.0    * All functions, classes related to product pricing.    *	* 7/9/2010	*	Improved the compression ratio to reduce cookie size	*	Added method for new compression    * 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:	** status related	    getStatusTCO() getStatusTCS()	** Partner related		getPartnerInfo()::getPartnerCID()::getPartnerName()::getPartnerType()::getPartnerWelcome()		getPartnerOtpPartnerId()::getPartnerTunnel()::getPartnerID()::getPartnerActive()::	** Product related		getProductInfo()::getProductId()::getProductBasePrice()::getProductPartnerPrice()		getProductName()::getProductStartNow()::getProductLearnMore()::getProductSKU()::getProductPlatform()		getProductOmnitureName()::getProductsByPlatform()::getCompressedStr()::updatePartnerProduct()::getDecompressedStr()*/function PartnerProduct() {        this._partner_product;		this.isValued = function(){			try			{				//var tempObj = this.getObj();				var tempObj = this._partner_product.prodList;				if (typeof tempObj == 'undefined')				{					g_log.debug('g_hrb_partner_product.isValued(): 1 returning false');					return false;				}			}			catch (e)			{				g_log.debug('g_hrb_partner_product.isValued(); 2 returning false');				return false;			}			return true;		}        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;        }				this.getVer=function () {			if((typeof this._partner_product.status.ver != 'undefined') && this._partner_product.status.ver !=null){            return this._partner_product.status.ver;			}			else{			return null;			}        }          /*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;        }	     /*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;			return getPageXref(prodID);		        }        /*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 returns an array of product objects            Platform type 'O':online 'S':software 'R':retail        */        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			this._partner_product.partner.partnerName='';			this._partner_product.partner.partnerWelcome='';            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 = jsonToString(this._partner_product);			return resizeWSC(str,"compress");        }        /*        shows the current wsc cookie in decompressed format. call by        javascript:g_hrb_partner_product.getDecompressedStr();        */        this.getDecompressedStr=function(){            var tmpWin = window.open();            tmpWin.document.write(resizeWSC(unescape(getCookie("wsc")),"decompress"));        }                /*  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= resizeWSC(str,"decompress");            }            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;            }//end of try            catch (e){            	g_log.error('setPartnerProduct:decompress=='+decompress+":failed:e=="+e.message);                setCookie("wsc", "", null, "/");				return false; // let caller know parsing failed            }			return true;        }        }  function resizeWSC(wscstr,typ){		var ct ={"a":/\/universal\/office_locator.html/g,"b":/\/loginRedirect.html/g,"c":/\.html\",bpr:\"/g,"d":/\"},{pid:\"/g,"e":/\",ppr:\"/g,"f":/\",lm:\"/g,"g":/\",sk:\"/g,"h":/\",pn:\"/g,"i":/\",sn:\"/g,"j":/\",pl:\"/g,"k":/\",on:\"/g,"l":/0.00/g,"m":/9.95/g,"n":/4.95/g,"o":/TaxType=/g,"p":/Target=/g,"q":/product.jsp/g,"r":/office/g,"s":/NOT_APPLICABLE/g,"t":/default/g,"u":/Online/g,"v":/partner/g,"w":/TaxYear=20/g,"x":/otpPartnerID=/g,"y":/productId=/g,"z":/&FV=T&HT=F/g,"1":/state/g,"2":/taxcut/g,"3":/premium/g,"4":/software/g,"5":/online/g};		if (typ=="compress"){			for (var j in ct){				wscstr = wscstr.replace(ct[j],"*"+j)			}			return wscstr;		}		else if (typ=="decompress"){			for (var j in ct){				var tmpsrc =(ct[j].source).replace(/\\/g,'');				wscstr = wscstr.replace(new RegExp("\\*"+j,"g"),tmpsrc);			}			return wscstr;		}	}     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+')'));		*/		setFinalResp();        if (getWebServiceCookie(partnerid))        {            g_log.debug('getProductInfo webService call is NOT needed ');			// Also check if cookie version is current			var def_ver = (g_online_def_price.match(/ver:[0-9]/))[0].split(':')[1];//def version			var cookie_ver =g_hrb_partner_product.getVer(); //version from cookie			g_log.debug('Default WSC version is '+def_ver+' Cookie version is '+cookie_ver);			if (cookie_ver==null || cookie_ver!= parseInt(def_ver)){				callpartnerJSON(partnerid);			}else{	            webServiceCallNotNeeded();   // shares much logic with the webServiceCallSuccess()			}        }        else{        	g_log.debug('getWebServiceCookie("'+partnerid+'") failed. calling callpartnerJSON("'+partnerid+'")"');            callpartnerJSON(partnerid);        }    }	function setFinalResp()	{		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+')'));	}//initialize the product info objectvar g_hrb_partner_product= new PartnerProduct();
