
if (!window.adItemList) 
	window.adItemList = '';


//adItems is formatted as follows: adfilterid|zipcode or  adfilterid|mlsid|Lag|zipcode - used for listing banners
function logJsRnAdHit(key, adItems, acc) {
	var location = document.location
	var host = location.host
	var path = location.pathname
	
	 //if acc is passed in, lets tack it to the queystring
    var qAccountID = acc ? '&acc=' + acc : '';
	
	var sitedirectory = path.substring(0, path.indexOf('/',1))
	var imgpath = 'http://' + host + sitedirectory + '/modules/internet/logging/logadhit.aspx';
	//prompt('', imgpath + '?acc=' + acc + '&keyname=' + key  + '&domainentrycode=' + domainEntryCode + '&rnd=' + Math.floor(Math.random() * (new Date()) + 1));
	rnImage = new Image();
	rnImage.src = imgpath + '?keyname=' + key + '&aditems=' + adItems + qAccountID + '&rnd=' + Math.floor(Math.random() * (new Date()) + 1);
	rnImage.onload = function() {return;}
	return;
}

function logJsRnWebHit(acc, key, domainEntryCode, builderID, builderCommunityID, adFilterID, clientID, zipCode) {
    var location = document.location
    var host = location.host
    var path = location.pathname

    //if ClientID passed in, lets tack it to the queystring
    var qClientID = clientID ? '&clientID=' + clientID : '';

    //if zipcode passed in, lets tack it to the queystring
    var qZipCode = zipCode ? '&zipcode=' + zipCode : '';

    if (domainEntryCode.length == 0) {
        var cookieMatch = document.cookie.match("(?:^|;)[ ]?domainentrycode=([^;]*)(?:;|$)");
        if (cookieMatch != null) {
            domainEntryCode = unescape(cookieMatch[1]);
        }
    }

    var sitedirectory = path.substring(0, path.indexOf('/', 1))
    var imgpath = 'http://' + host + sitedirectory + '/modules/internet/logging/logwebhit.aspx';
    //prompt('', imgpath + '?acc=' + acc + '&keyname=' + key  + '&domainentrycode=' + domainEntryCode + '&rnd=' + Math.floor(Math.random() * (new Date()) + 1));
    rnImage = new Image();
    rnImage.src = imgpath + '?acc=' + acc + '&keyname=' + key + '&domainentrycode=' + domainEntryCode + '&bldrID=' + builderID + '&bcID=' + builderCommunityID + '&adfilterid=' + adFilterID + qClientID + qZipCode + '&rnd=' + Math.floor(Math.random() * (new Date()) + 1);
    rnImage.onload = function() { return; }
    return;
}

function logJsRnBuilderCommunityWebHit(acc, key, domainEntryCode, builderCommunityCompanyID, mlsCity,  stateAbbreviation, builderCommunityID, builderID, adFilterID, zipCode) {
	logJsRnListingWebHit(acc, key, domainEntryCode, builderCommunityCompanyID, '', '', mlsCity, '', '', '', stateAbbreviation, builderCommunityID, builderID, adFilterID, zipCode); 
	return;
}

function logJsRnListingWebHit(acc, key, domainEntryCode, listingCompanyID, listingLag, listPrice, mlsCity, mlsID, mlsNumber, mlsNumberAlpha, stateAbbreviation, builderCommunityID, builderID, adFilterID, zipCode) {
	var location = document.location;
	var host = location.host;
	var path = location.pathname;
	var builderIDQuerystring='';
	var builderCommunityIDQuerystring='';
	var qAdFilterID ='';
	
	var qZipCode = zipCode ? '&zipcode=' + zipCode : '';
	
	if (builderID > 0) {
		builderIDQuerystring = '&bldrID=' + builderID
	}

	if (builderCommunityID > 0) {
		builderCommunityIDQuerystring = '&bcID=' + builderCommunityID
	}
	
	//if AdFilterID passed in, lets tack it to the queystring
	if (adFilterID > 0) {
	 qAdFilterID = '&adfilterid=' + adFilterID;
	}
	
	var sitedirectory = path.substring(0, path.indexOf('/',1));
	var imgpath = 'http://' + host + sitedirectory + '/modules/internet/logging/logwebhit.aspx';
	//prompt('', imgpath + '?acc=' + acc + '&keyname=' + key  + '&domainentrycode=' + domainEntryCode + '&listingcompanyid=' + listingCompanyID  + '&listinglag=' + listingLag + '&listprice=' + listPrice  + '&mlscity=' + mlsCity  + '&mlsnumber=' + mlsNumber + '&mlsnumberalpha=' + mlsNumberAlpha + '&stateabbreviation=' + stateAbbreviation +  '&rnd=' + Math.floor(Math.random() * (new Date()) + 1));
	rnImage = new Image();
	rnImage.src = imgpath + '?acc=' + acc + '&keyname=' + key  + '&domainentrycode=' + domainEntryCode + '&listingcompanyid=' + listingCompanyID  + '&listinglag=' + listingLag + '&listprice=' + listPrice  + '&mlscity=' + mlsCity  + '&mlsid=' + mlsID + '&mlsnumber=' + mlsNumber + '&mlsnumberalpha=' + mlsNumberAlpha + '&stateabbreviation=' + stateAbbreviation + qZipCode  + builderIDQuerystring + builderCommunityIDQuerystring + qAdFilterID + '&rnd=' + Math.floor(Math.random() * (new Date()) + 1);
	rnImage.onload = function() {return;}
	return;
}

//DEPRECATED - Replaced by logJsAdViewAndBuildLink (below) - ad logging no longer uses many of these variables
function logJsAndAdRedirect(acc, adFilterID, url, domainEntrycode, zipCode, clientID){
	height = window.screen.height * .85;
	width = window.screen.width * .85;
	window.open(url, null, 'toolbar=yes,location=no,scrollbars=yes,menubar=no,status=yes,resizable=yes,width='+width+',height='+height);
	//logJsRnWebHit(acc, 'AdClick', domainEntrycode, '', '', adFilterID, clientID, zipCode);
	logJsRnAdHit('AdClick', adFilterID + "|" + zipCode, acc);
}


// 
//this builds the ad link and window size and logs the click
// ad logging requires much fewer params than regular
//
function logJsAdViewAndBuildAdLink(acc, url, adFilterID, zipCode, mlsID, lag){
	height = window.screen.height * .85;
	width = window.screen.width * .85;
	
	var adItem = mlsID ? adFilterID + "|" + mlsID + "|" + lag + "|" + zipCode : adFilterID + "|" + zipCode;
	
	window.open(url, null, 'toolbar=yes,location=no,scrollbars=yes,menubar=no,status=yes,resizable=yes,width='+width+',height='+height);

	logJsRnAdHit('AdClick', adItem, acc);
}

function logSearch(acc) {
	var location = document.location
	var host = location.host
	var path = location.pathname
	var sitedirectory = path.substring(0, path.indexOf('/',1))
	var imgpath = 'http://' + host + sitedirectory + '/modules/internet/logging/logsearch.aspx';
	
	rnImage = new Image();
	rnImage.src = imgpath + '?acc=' + acc + '&x=' + Math.floor(Math.random() * (new Date()) + 1);
	rnImage.onload = function() {return;}
	return;
}

function logSearchResultsHistory(mlsIDs, mlsNumbers) {

	var location = document.location
	var host = location.host
	var path = location.pathname
	var sitedirectory = path.substring(0, path.indexOf('/',1))
	var imgpath = 'http://' + host + sitedirectory + '/modules/internet/logging/logsearchresultshistory.aspx';
	
	rnImage = new Image();
	rnImage.src = imgpath + '?M1=' + mlsIDs + '&M2=' + mlsNumbers;
	rnImage.onload = function() {return;}
	return;
}

function AddAdItem(adFilterID, zipCode) {
  adItemList += adFilterID + '|' + zipCode + ',';
}

function logAdImpressionItems(acc) {
  if (adItemList.length > 0) {
	var location = document.location
	var host = location.host
	var path = location.pathname
	
   var qAccountID = acc ? '&acc=' + acc : '';
	
	var sitedirectory = path.substring(0, path.indexOf('/',1))
	var imgpath = 'http://' + host + sitedirectory + '/modules/internet/logging/logadhit.aspx';
	rnImage = new Image();
	rnImage.src = imgpath + '?keyname=AdView&aditems=' + adItemList + qAccountID + '&rnd=' + Math.floor(Math.random() * (new Date()) + 1);
	rnImage.onload = function() {return;}
	return;
  }
}