lastTabVisibleId = "advantage";
function changeFeatureSubTab(tabId) {

	var listWrapper = document.getElementById('pCategories');
	var liArr = listWrapper.getElementsByTagName('li');

	// update tab menu
	for (var i = 0; i < liArr.length; i++) {
		if(liArr[i].id==('pCategory'+tabId)) {
			document.getElementById(liArr[i].id).className = "active";
		} else {
			document.getElementById(liArr[i].id).className = "inactive";
		}
	}
    //css function for removing and add css class would not work in IE6 if css class has "classname1 classname 2) format
	// update body content
	var contentArr = util.getElementsByClassName('pSection', document.body);
	for (var i = 0; i < contentArr.length; i++) {
		//css.removeClassName(contentArr[i], 'active');
		contentArr[i].className="pSection";
	}

	//css.addClassName(document.getElementById('pSection' + tabId),'active');

	document.getElementById('pSection' + tabId).className="pSection active";

}

var comparisonVehicles = "";
function addComparisonVehicles(trimID, count) {
	var vehicle = "" + trimID;
	if (count > 0) {
		vehicle = "~" + trimID;
	}
	comparisonVehicles += vehicle;
}

function doRemoveVehicle(trimID, action, newTrimId) {
	if ("" == newTrimId) {
		if (comparisonVehicles.contains("~" + trimID)) {
			comparisonVehicles = comparisonVehicles.replace("~" + trimID, "");
		} else {
			comparisonVehicles = comparisonVehicles.replace(trimID, "");
		}
	} else {
		comparisonVehicles = comparisonVehicles.replace(trimID, newTrimId);
	}
	if (comparisonVehicles.indexOf("~") < 1) {
		comparisonVehicles = comparisonVehicles.replace("~", "");
	}
	if ("" == comparisonVehicles) {
		comparisonVehicles = "NONE";
	}
	$("comparisonVehiclesAddRemove").set('value',comparisonVehicles);
	document.polkComparisonActionForm.action = window.location.pathname;
	document.polkComparisonActionForm.submit();
}

var titleReplace = "Replace";
var titleAdd = "Add";
var linkAdd = "Add";
var linkReplace = "Replace";
var addReplaceTextTitle = 'with (please make selections below):';
function showAddRemoveVehicle(toShowId, toHideId, type, trimName) {
	var anchorObj = $("addvehicle");
	var addReplaceTitle = $("addReplaceTitle");

	$(toHideId).toggleClass("hide");
	$(toShowId).toggleClass("hide");
	anchorObj.setProperty('class','');
	if ("replace" != type) {
		carToReplace = "";
		anchorObj.title = titleAdd;
		anchorObj.addClass("add");
		anchorObj.value = linkAdd;
		addReplaceTitle.innerHTML = linkAdd + " " + addReplaceTextTitle;
	} else {
		anchorObj.title = titleReplace;
		anchorObj.addClass("replace");
		anchorObj.value = linkReplace;
		addReplaceTitle.innerHTML = linkReplace + " " + trimName + " " + addReplaceTextTitle;
	}
}

function clickTrackingAdd(division){
    var divisionObj = division.toUpperCase();
    clickTrack({pageName: divisionObj+' | DIVISIONAL | COMPARISON | RESULTS', prop1: 'DIVISIONAL', prop2:'COMPARISON', prop3: 'DIVISIONAL | COMPARISON', prop4: 'RESULTS', prop5:'COMPARISON | RESULTS', prop6: 'DIVISIONAL | COMPARISON | RESULTS', prop7:'FEATURES COMPARISON', prop8: 'RESULTS | FEATURES COMPARISON', prop9: 'COMPARISON | RESULTS | FEATURES COMPARISON', prop10: 'DIVISIONAL | COMPARISON | RESULTS | FEATURES COMPARISON',prop11:'ADD VEHICLE', prop12:'FEATURES COMPARISON | ADD VEHICLE',prop13:'RESULTS | FEATURES COMPARISON | ADD VEHICLE',prop14:'COMPARISON | RESULTS | FEATURES COMPARISON | ADD VEHICLE',prop15:'DIVISIONAL | COMPARISON | RESULTS | FEATURES COMPARISON | ADD VEHICLE',prop17:'VEHICLE DETAILS', prop18:'RESEARCH',prop24:'EN', prop25:divisionObj, prop26:(new Date()).getHours(), prop27: weekday[(new Date()).getDay()]});
}

var carToReplace = "";
function showReplace(trimId, toShowId, toHideId, trimName) {
	carToReplace = trimId;
	showAddRemoveVehicle(toShowId, toHideId, "replace", trimName);
}
var addBtnClicked = false;
function doAddReplace(trimId, action, message) {
	if (validateDropDowns()) {
		if ("" != carToReplace) {
			doRemoveVehicle(carToReplace, "", trimId);
		} else {
			if (!addBtnClicked) {
				addBtnClicked = true;
				addComparisonVehicles(trimId, 1);
			}
		}
		//document.getElementById("comparisonVehicles").value = comparisonVehicles;
		if (comparisonVehicles.indexOf("~") < 1) {
			comparisonVehicles = comparisonVehicles.replace("~", "");
		}
		document.getElementById("comparisonVehiclesAddRemove").value = comparisonVehicles;
		document.polkComparisonActionForm.action = window.location.pathname;
		document.polkComparisonActionForm.submit();
	} else {
		alert(message);
	}
}
function comparisonTracking (division,tabValue){
	var uTabValue	= tabValue.toUpperCase();
	var divisionObj	= division.toUpperCase();
	var type = [
		divisionObj+': us: compare-features: '+vehicleModel+': '+tabValue,
		divisionObj+': us: vehicles: '+vehicleModel+': compare-features: '+tabValue
	];
	var type1 = ['change vehicle','add vehicle','remove vehicle'];
	var typeKey = 0;
	for ( var i in type1 ) {
		if ( tabValue.toLowerCase() == type1[i] ) {
			typeKey = 1;
			break;
		}
	}
	clickTrack({
		prop18:	divisionObj,
		eVar28: vehicleYear,
		prop23:	'en',
		prop27:	'contentarea',
		prop32:	type[typeKey]
	});
}

//Used to override the default change year behavior in subnav
function changeYearOverride (year){
	var URL = INTERNAL_URL+ '?';
	for (var key in PARAM){
		switch (key) {
		case  'year':
			URL += key + '=' + year+'&';
			URL += 'preYear' + '=' + PARAM[key]+'&';
			break;
		case 'pvc':
			URL += 'prePVC' + '=' + anchorVehiclePVC+'&';
			break;
		default:
			URL += key + '=' + PARAM[key]+'&';
			break;
		}
	}
	window.location.href = BASE_CONTEXT + URL;
}
