/*== 
	Analytics.js for webtrends analytics
	- Uses page variables envData, controller, and action.	
  ==*/

function tag(p,a) {
	addStandardPageAttributes(p,a);
	_processTag();
}

function postSearchCallback(f){
	if (f.req_no <= 1){
		addSearchPageAttributes(f);
	}
	_processTag();
}

function addBaseAttributes(){
	_tag.dcsid = 'dcs9z19gi00000c9vvcd741iy_5p5f';
	_tag.fpcdom = '.' + envData.HTTP_HOST;
	_tag.onsitedoms = 'www.' + envData.HTTP_HOST;
}

function addStandardPageAttributes(p,a){
	addBaseAttributes();
	_tag.DCSext.MCG = pageType();
	_tag.WT.cg_n = pageType();
	_tag.WT.pi = pageType();
        _tag.DCSext.s_loc = p.town ; // town
        _tag.DCSext.client = a.name;
        _tag.DCSext.s_range = p.price;
        _tag.DCSext.s_pricetype = controller.CONTROLLER_NAME;
        _tag.DCSext.s_propertytype = p.property_type + '-' + p.bedrooms + 'bedrooms';

}

function addSearchPageAttributes(f) {
	addBaseAttributes();
	_tag.DCSext.MCG = 'Search';
	_tag.WT.cg_n = 'Search';
	_tag.WT.pi = 'Search';
        _tag.DCSext.s_type = "dynamic"
        _tag.WT.oss = f.search.query; //search keyword
        _tag.WT.oss_r = f.property_count //number of results
}

function pageType(){
	var type = '';
	if(controller.CONTROLLER_NAME == 'home' && action.ACTION_NAME == 'index') type = 'Home';
	if(controller.CONTROLLER_NAME == 'properties' && action.ACTION_NAME == 'show') type = 'Property';
	return type;
}

function _processTag() {
	_tag.dcsGetId();
	_tag.dcsCollect();
}
