function addVar(varScope,varName,varValue){
	if(varValue != ""){
		tagVars = tagVars + '&' + varScope + '!' + varName + '=' + escape(varValue);
	}	
}

function addPageVar(varName, varValue){
	addVar('PAGEVAR',varName,varValue);
}

function addSessionVar(varName, varValue){
	addVar('SESSIONVAR',varName,varValue);	
}

function addVisitorVar(varName, varValue){
	addVar('VISITORVAR', varName, varValue);
}

if (typeof(tagVars)=="undefined")
	tagVars = "";

// add OrderTotal
if(typeof(lpUASorderTotal) != "undefined"){
	addPageVar("OrderTotal",lpUASorderTotal);
	addPageVar(lpUASunit + "_OrderTotal",lpUASorderTotal);
	addSessionVar("Conversion",1);
}


if(typeof(lpUASerrorName) != "undefined"){
    addPageVar("ErrorName",lpUASerrorName);
}
if(typeof(lpUASerrorCounter) != "undefined"){
    addPageVar("ErrorCounter",lpUASerrorCounter);
}
if(typeof(lpUAScartTotal) != "undefined"){
    addPageVar("CartTotal",lpUAScartTotal);
}
if(typeof(lpUASconversionStage) != "undefined"){
    addPageVar("ConversionStage",lpUASconversionStage);
}
if(typeof(lpUASmake) != "undefined"){
    addPageVar("Make",lpUASmake);
}
if(typeof(lpUASmodel) != "undefined"){
    addPageVar("Model",lpUASmodel);
}
if(typeof(lpUASyear) != "undefined"){
    addPageVar("Year",lpUASyear);
}
if(typeof(lpUAScategory) != "undefined"){
    addPageVar("Category",lpUAScategory);
}
if(typeof(lpUASsearch) != "undefined"){
    addPageVar("Search",lpUASsearch);
}
if(typeof(lpUASnoResults) != "undefined"){
    addPageVar("NoResults",lpUASnoResults);
}
if(typeof(lpUASproduct) != "undefined"){
    addPageVar("Product",lpUASproduct);
}
if(typeof(lpUASbrand) != "undefined"){
    addPageVar("Brand",lpUASbrand);
}
if(typeof(lpUASrevOrdernumber) != "undefined"){
    addPageVar("RevOrdernumber",lpUASrevOrdernumber);
}
if(typeof(lpUAScommerceOrdernumber) != "undefined"){
    addPageVar("CommerceOrdernumber",lpUAScommerceOrdernumber);
}
if(typeof(lpUASsection) != "undefined"){
    addPageVar("Section",lpUASsection);
}
if(typeof(lpUASconversionDetails) != "undefined"){
    addPageVar("ConversionDetails",lpUASconversionDetails);
}
if(typeof(lpUASorderDetails) != "undefined"){
    addPageVar("OrderDetails",lpUASorderDetails);
}


var INITIAL_MAX_SIZE = 300;
var MAX_TAGVARSURL_SIZE = 1600;
var INITIAL_STRING = document.location.toString() + document.title;
var STRING_MAX_SIZE = INITIAL_STRING.length + INITIAL_MAX_SIZE;

if ((typeof(tagVars) == "undefined") || (tagVars == null))
	tagVars = "";
while ((tagVars.length + STRING_MAX_SIZE > MAX_TAGVARSURL_SIZE) && (tagVars.length > 0)) {
	var idx = tagVars.lastIndexOf("&");
	if (idx > 0)
		tagVars = tagVars.substring(0, idx);
	else
		tagVars = "";
}
