var pArray = new Array();
pArray['find_a_store'] = ['/store/store+locator','store_locator.asp'];
pArray['shop_by_catalog'] = ['/store/catalog','catalog.asp'];
pArray['search_results'] = ['/store/search+results','shelf page'];
pArray['product_view'] = ['/store','product.asp'];
pArray['add_cart'] = ['/store','product.asp'];
pArray['checkout'] = ['/store/CHECKOUT/payment','checkout_payment.asp'];
pArray['order_confirm'] = ['/store/CHECKOUT/CONFIRMATION','checkout_confirm.asp'];
pArray['sale'] = ['/store/sale',''];

var _hbEC=0,_hbE=new Array;function _hbEvent(a,b){b=_hbE[_hbEC++]=new Object();b._N=a;b._C=0;return b;}
var hbx=_hbEvent("pv");hbx.vpc="HBX0200u";hbx.gn="ehg-chicos.hitbox.com";

var _lp = location.pathname;
if(location.hostname&&(location.hostname.indexOf("alpha")==0||location.hostname.indexOf("dev")==0)){
	hbx.acct="DM56092102BB";
	hbx.cacct="975609261541";
} else {
	hbx.acct="DM550809G1EZ";
	hbx.cacct="975605102374";
}
hbx.tz="EST";
hbx.fv="none";//FORM VALIDATION MINIMUM ELEMENTS
hbx.lt="auto";//LINK TRACKING
hbx.eacct=hbx.acct;
hbx.lc="y";

//utility functions
function _TO(a){return(typeof eval("window."+a)!='undefined')};
function _II(a,b,c){return a.indexOf(b,c?c:0)}
function _IL(a){return a!='undefined'?a.length:0}
function _IS(a,b,c){return b>_IL(a)?"":a.substring(b,c!=null?c:_IL(a))}
function _QSP(a,b,c,d,e){c=_II(a,"&"+b+"=");c=c<0?_II(a,"?"+b+"="):c;if(c>-1){d=_II(a,'&',c+_IL(b)+2);e=_IS(a,c+_IL(b)+2,d>-1?d:_IL(a));return e}return ""}
function _A(v){return escape(v)}

function _hbOnPrePVR(){
    //related products
    if(hbx.mlc.indexOf(pArray['product_view'][0])==0&&hbx.pn==pArray['product_view'][1]){
        for(var i=0; i<document.links.length; i++){
          var a=document.links[i];
            if(a.href.indexOf("&related=yes")>0&&a.innerText&&a.innerText.length>0){
                a.name = "&lid="+"related - " + a.innerText;
                var b=document.links[i-1];
                b.name = "&lid="+"related - " + a.innerText + " - img";
            }
        }
    }    
    //strip spaces from pagenames
    _pn = (_pn.split("'")).join("");
}

if(_TO("hbxObj")){
    if(_TO("hbxObj.pn"))hbx.pn=hbxObj.pn.toLowerCase();
    if(_TO("hbxObj.mlc"))hbx.mlc=hbxObj.mlc.toLowerCase();else hbx.mlc="/unknown";
}

function _hbxProcess(){
    //INTERNAL SEARCH
    if(hbx.mlc==pArray['search_results'][0]&&hbx.pn.indexOf(pArray['search_results'][1])==0){
        hbx.lvm = 400;
        var _kw=_QSP(location.search,"keyword");
        if(_kw.length>0){
            hbx.seg = "3";
            var _search = _hbEvent("search");
            _search.keywords = _kw;
             var rTotal = 1;
            for(var i=0; i<document.links.length; i++){
              var a=document.links[i];
              if(a.href&&a.href.indexOf("product.asp?PID=")>0&&a.innerText&&a.innerText.length>0){
                a.name = "&lid=is_"+a.innerText+"&lpos="+rTotal;
                var b=document.links[i-1];
                b.name = "&lid=is_"+a.innerText+" - img&lpos="+rTotal;
                rTotal++;
              }
            }
            _search.results = rTotal-1;
            _search.attr1 = _QSP(location.search,"selCategory");
            _search.attr2 = _QSP(location.search,"selBraSize");
            _search.attr3 = _QSP(location.search,"selColorFamily");
        }
    }

    //3 handled in search section
    if(hbx.mlc.indexOf(pArray['sale'][0])==0){
        hbx.seg = "4";
    } else if(hbx.mlc==pArray['checkout'][0]&&hbx.pn==pArray['checkout'][1]){
        var _c=document.cookie;
        _c=_c.toLowerCase();
        if(_c.indexOf("passport")>-1){
            hbx.seg = "5";
        } else {
            hbx.seg = "6";
        }
    } else if(hbx.mlc==pArray['find_a_store'][0]&&hbx.pn==pArray['find_a_store'][1]){
        hbx.seg = "7";
    } else if(hbx.mlc==pArray['shop_by_catalog'][0]&&hbx.pn==pArray['shop_by_catalog'][1]){
        hbx.seg = "8";    
    }
    
    //commerce
    if(hbx.mlc.indexOf(pArray['product_view'][0])==0){
    	if(hbx.pn==pArray['product_view'][1] || hbx.pn==pArray['add_cart'][1]){
    		var _ls=location.search;
    		var _idx = _ls.indexOf("&Success=True");
        	if(_idx == -1){
            	//product view
          		hbx.epg="n&cam=0&pv=1&product="+_A(hbxObj.pr)+    "&quantity="+_A(hbxObj.qn)+"&brand="+
          		_A(hbxObj.bd)+"&category="+_A(hbxObj.ca)+"&price="+_A(hbxObj.pc)+"&store="+_A(hbxObj.sr)+"&tz="+hbx.tz+"&aid="+hbx.cacct;
        	} else{
          		//addcart
          		hbx.epg="n&cam=0&pv=0&abd_type=cart_add&product="+_A(hbxObj.pr)+    "&quantity="+_A(hbxObj.qn)+"&brand="+
        		_A(hbxObj.bd)+"&category="+_A(hbxObj.ca)+"&price="+_A(hbxObj.pc)+"&store="+_A(hbxObj.sr)+"&tz="+hbx.tz+"&aid="+hbx.cacct;
			}
		} else if(hbx.pn==pArray['checkout'][1]){
        	//checkout
        	hbx.epg="n&abd_type=checkout&product="+_A(hbxObj.pr)+"&quantity="+ _A(hbxObj.qn)+"&price="+_A(hbxObj.pc)+"&shippingtype="+_A(hbxObj.st)+
        	"&shipping="+_A(hbxObj.sp)+"&store="+_A(hbxObj.sr)+"&tz="+hbx.tz+"&aid="+hbx.cacct; 
    	} else if(hbx.pn==pArray['order_confirm'][1]){
        	//order
        	for(var i in hbxObj){
            	if(typeof hbxObj[i]!='function')
                	hbx[i] = hbxObj[i];
        	}    
        	hbx.pec="";
        	hbx.hlt="";
        	hbx.hla="";
        	hbx.hcn="";
        	hbx.hc1="";
        	hbx.hc2="";
        	hbx.hc3="";
        	hbx.hc4="";
        	hbx.seg="9";
        	hbx.fnl="";
        	hbx.hcv="";
        	hbx.gp="LAST";
          
        	//calculate store: 1 - normal, 2 - allpay
        	if(hbx.oi){
            	var _oi=hbx.oi.toLowerCase();
            	if(_oi.indexOf('w')==0)
               		hbx.sr=2;
            	else
                	hbx.sr=1;
        	}
        }
    }
}
_hbxProcess();


function _hbOnLink(linkObj){ if(typeof linkObj=="object"){ var 
idx=linkObj.lid.indexOf("_on.gif"); var ext=".gif"; if(idx==-1){ 
idx=linkObj.lid.indexOf("_on.jpg"); ext = ".jpg"; } if(idx>-1){ var newLid = 
linkObj.lid.substring(0,idx)+ext; if(linkObj.lid.indexOf("http")==0){ idx = 
newLid.indexOf("/",9); newLid = newLid.substring(idx,newLid.length); } 
_hbSet('lid',newLid); }    } }

