//######################################################
//##        version date: 2011 may 26
//######################################################
// create com_hp_hope namespace if it does not yet exist:
if (typeof (com_hp_hope) == 'undefined')
{ 
	com_hp_hope = {};
};

com_hp_hope.oidMap = {
    'notebooks':321957,
    'desktops':12454,
    'printers':18972
};

com_hp_hope.segmentMap = {
    'any': 'a',
    'hho': 'h',
    'smb': 's',
    'ga':  'g',
    'ent': 'e',
    'edu': 'p',
    'otr': 'o'
};

com_hp_hope.isEmptyObj = function(obj){
    for(var p in obj){
        if(obj[p] != obj.constructor.prototype[p]){
            return false;
        }
    }
    return true;
}

// read bounce counter form cookie:
com_hp_hope.hopeCookieHandler.prototype.getBounce = function()
{
	var bounceCounter = { b:0, r:0 };
	var bounceString = this.read('o');
	if (bounceString != null)
	{
		var tmp = bounceString.split('|');
		bounceCounter.b = tmp[0];
		bounceCounter.r = tmp[1];
	}
	return bounceCounter;
};

// write bounce counter to cookie:
com_hp_hope.hopeCookieHandler.prototype.setBounce = function(bounceCounter)
{
	if (bounceCounter != null)
	{
		this.update('o', bounceCounter.b + '|' + bounceCounter.r);
	}
};

com_hp_hope.collectGrowthData = function (){
    var tmp, sgm, pto, counters, mkscounters, tstamp, bc, ptc = {};
    
    //return visit counter
	if (com_hp_hope.hopeCookie.isNewVisit()){
	    com_hp_hope.hopeCookie.write('r',parseInt(com_hp_hope.hopeCookie.read('r'))+1);
	}
	
    //bounce counter
	bc = com_hp_hope.hopeCookie.getBounce();
	if (com_hp_hope.hopeCookie.isNewVisit()){
		bc.b++;
	}else{
		bc.b = 0;
	}
	com_hp_hope.hopeCookie.setBounce(bc);

    //product type counters
    counters = com_hp_hope.hopeCookie.getProdTypeCounter();
    if(typeof(s_prop3)!=='undefined' && s_prop3!==null){
        //get product segment key, product type oid
        tmp = s_prop3.split(':');
        if(typeof(com_hp_hope.segmentMap[tmp[0]])!=='undefined'){
            sgm = com_hp_hope.segmentMap[tmp[0]];
        }
        if(typeof(com_hp_hope.oidMap[tmp[2]])!=='undefined'){
            pto = com_hp_hope.oidMap[tmp[2]];
        }
        
    }
    for(var segment in counters[pto]){
        if(segment === sgm){
            counters[pto][segment] = { 'total': parseInt(counters[pto][segment]['total']) + 1 + '', 'lastAccess': '0', 'interval': '0' };
        }
    }
	com_hp_hope.hopeCookie.setProdTypeCounter(counters);
	
    //last visited product type
	com_hp_hope.hopeCookie.setLastProdType(pto);

/*
    //market segment counters
	mkscounters = com_hp_hope.hopeCookie.getSegmentCounter();
	for(var segment in mkscounters){
	    if(segment === sgm){
	        mkscounters[segment] = { 'total': parseInt(mkscounters[segment]['total']) + 1 + '', 'lastAccess': '0', 'interval': '0' };
	    }
	}
	com_hp_hope.hopeCookie.setSegmentCounter(mkscounters);
*/
}();

