
function get_OAS_query(){

	this._get_q = function (v) {
		var q = window.location.search.substring(1);
		var vars = q.split("&");
		for (var i=0;i<vars.length;i++) {
			var p = vars[i].split("=");
			if (p[0] == v) return p[1];
			}
		return "";
	}
	
	var portal = ''
	var category = ''
	var subcategory = ''
	var result = ''
	var loc = /^(.+)\:\/\/(.+?)\/([^?]*)\??(.*)/.exec(document.location)
	var path = loc[3].split("/")
	
	// zope domains (not wickedlocal.com)
	var zope_domains = {}
	zope_domains['www.patriotledger.com'] = 'patriotleder'
	zope_domains['www.enterprisenews.com'] = 'enterprisenews'
	zope_domains['www.heraldnews.com'] = 'heraldnews'
	zope_domains['www.tauntongazette.com'] = 'tauntongazette'
	zope_domains['www.metrowestdailynews.com'] = 'metrowestdailynews'
	zope_domains['www.dailynewstranscript.com'] = 'dailynewstranscript'
	zope_domains['www.dailynewstribune.com'] = 'dailynewstribune'
	zope_domains['www.milforddailynews.com'] = 'milforddailynews'
	
	
	// wickedlocal.com
	if (document.domain == 'www.wickedlocal.com') {
		portal = path[0]
		if (path.length >= 2) {
			category = path[1]
		}
		if (path.length >= 3 && /^x\d+$/.test(path[2]) == false){
			subcategory = path[2]
		}
	}
	// real estate
	else if (document.domain == 'realestate.wickedlocal.com'|| document.domain == 'sob.re.adicio.com') {
		portal = "realestate"
		if (this._get_q('qTerms') == 'sell') {
			category = 'for_sale'
		}
		else if (this._get_q('qTerms') == 'rent'){
			category = 'for_rent'
		}
	}
	// automotive
	else if (document.domain == 'wickedlocalwheels.com'|| document.domain == 'wheels.wickedlocal.com') {
		portal = "automotive"
		// search
		if (/autos\/search/.test(loc[3])){
			if (this._get_q('condradio') == 'new'){
				category = 'search_new'
			} else {
				category = 'search_used'
			}
		}
		if (this._get_q('makes%5B0%5D') != ''){
			subcategory = this._get_q('makes%5B0%5D')
		}
		// build
		else if (/autos\/configurator/.test(loc[3])){
			category = 'build'
		}
		// research
		else if (/autos\/researchCenter|comparator/.test(loc[3])){
			category = 'research'
		}
		// dealers
		else if (/autos\/dealers/.test(loc[3])){
			category = 'dealer'
		}
	}
	// www.wickedlocaljobs.com
	else if (document.domain == 'www.wickedlocaljobs.com') {
		portal = "jobs"
	}
	// non-wickedlocal zope sites
	else if (zope_domains[document.domain]) {
		portal = zope_domains[document.domain]
		if (path.length >= 1) {
			category = path[0]
		}
		if (path.length >= 2 && /^x\d+$/.test(path[1]) == false){
			subcategory = path[1]
		}
	}
	
	// return stuff	
	if(portal){
		result = 'portal='+portal.toLowerCase()
		if(category){
			result = result+"&category="+category.toLowerCase()
			if(subcategory){
				result = result+"&subcategory="+subcategory.toLowerCase()
			}
		}
	}
	result = window.location.search+"&XE&"+result+"+&XE"
	return result
}
