    var VALUES_CONTAINER_NAME = "VALUESCONTAINER";
    var LABELS_CONTAINER_NAME = "LABELSCONTAINER";
    var DEFAULT_MENU_BUTTON_POSITION = 2; //default to specs layer when selector is loaded with data for first time
    var trim_url = "";
    var result_url = "";
    var site_Id = "1";
    var menubuttoncounter = 0;
    
    var MSRP_LAYOUT_ID1 = '383';
    var MSRP_LAYOUT_ID2 = '384';
    var MSRP_LAYOUT_ID3 = '385';
    var MSRP_LAYOUT_ID4 = '386';
    
    var HIDE_MSRP_BOOLEAN = false; //default
    
    //This text is overwritten in the code behind with a localized version -- default only here.
    var MSRP_tooltip_text = "* Prices do not include taxes, insurance and license fees, as well as any other products or services not listed that may be made available to you through your selected dealer. Price is based on the Manufacturer's Suggested Retail Price (MSRP) in Canadian dollars. Dealers are free to set their own selling prices for products and services.";

    var BOOL_FEATURED_AD_DISPLAYED = false;
    var INT_AD_DISPLAYS_REMAINING = 1;  //only allow the featured car ad to be triggered this many times per page load
    
    
    //**********************************************************************
    //* ImagePreLoader - This code preloads any images                     *
    //**********************************************************************
    function ImagePreLoader(images, imagescontainer)
    {
       //set properties
       this.associatedimagescontainer = imagescontainer;
       this.totalloaded = 0;
       this.totalprocessed = 0;
       this.imagescache = new Array;
       this.totalimages = 0;
       //do preload
       for(var i = 0; i < images.length; i++){
          //don't preload no photo image
          if(images[i].indexOf("no_photo") < 0){
            this.totalimages += 1;
            this.PreLoad(images[i]);
          }
       }
    }

    ImagePreLoader.prototype.PreLoad = function(imagesrc)
    {
       //create image object and add to images cache
       var image = null;
       if(this.associatedimagescontainer.photogallerydiv){ //is it a photo gallery or main photo container
        image = new Image(200,125); //gallery container
       }else{
        image = new Image(100,62); //main photo container
       }
       this.imagescache.push(image);
       // set events
       image.onload = ImagePreLoader.prototype.onload;
       image.onerror = ImagePreLoader.prototype.onerror;
       image.onabort = ImagePreLoader.prototype.onabort;
       //set properties
       image.imagepreloader = this;
       image.loaded = false;
       image.src = imagesrc;
    }

    ImagePreLoader.prototype.oncomplete = function()
    {
       this.totalprocessed++;
       if (this.totalprocessed == this.totalimages)
       {
          this.associatedimagescontainer.LoadFromPreLoaderCache(this.imagescache);
       }
    }

    ImagePreLoader.prototype.onload = function()
    {
       this.loaded = true;
       this.imagepreloader.totalloaded++;
       this.imagepreloader.oncomplete();
    }

    ImagePreLoader.prototype.onerror = function()
    {
       this.error = true;
       this.style.display = "none";
       this.imagepreloader.oncomplete();
    }

    ImagePreLoader.prototype.onabort = function()
    {
       this.abort = true;
       this.style.display = "none";
       this.imagepreloader.oncomplete();
    }

    //**********************************************************************
    //* PhotoGallery - Contains code relevant to gallery popup on the page *
    //**********************************************************************
    function PhotoGallery()
    {
 		this.photogallerydiv = document.getElementById("photogallery");
 		this.displayphotosdiv = document.getElementById("displayphotoscontainer");
		this.photogallerytitle = document.getElementById("photogallerytitle");
		this.photogallerydiv.container = this; 
		this.displayphotosdiv.container = this.photogallerydiv;
		this.btnClose = document.getElementById("btnCloseGallery");
	    if(this.btnClose){
            this.btnClose.container = this;
		    this.btnClose.onclick = function(){
			    this.container.photogallerydiv.style.display = "none";
		    }
		}		  
    }

    PhotoGallery.prototype.LoadFromPreLoaderCache = function(images)
    {
        //remove previous images
        while (this.displayphotosdiv.childNodes[0]){
            this.displayphotosdiv.removeChild(this.displayphotosdiv.childNodes[0]);
        }
        //add new images
        for(var i = 0; i < images.length; i++)
        {
            this.displayphotosdiv.appendChild(images[i]);    
        }
        //set gallery position on screen
        if(this.displayphotosdiv.childNodes.length > 0){
            //this.SetPosition();
            this.photogallerydiv.style.zIndex = "10001";
            this.photogallerydiv.style.display = "block";
        }
    }
    
    PhotoGallery.prototype.Show = function(selectorid, gallerytitle){
 	    var vehicleSelector = this.container.selections[selectorid];
	    this.photogallerytitle.innerHTML = gallerytitle;
	    if(vehicleSelector){
	        var photos = vehicleSelector.photoscontainer.value; //get photo paths
	        var arrphotos = photos.split("~");
	        var imageloader = new ImagePreLoader(arrphotos,this); //preload images
	    }       
    }
    
    PhotoGallery.prototype.Hide = function(){
        this.photogallerydiv.style.display = "none";
        this.photogallerydiv.style.zIndex = "1";
    }

    //**********************************************************************
    //* VehicleSelections - Contains Collection of VehicleSelectors        *
    //**********************************************************************
	function VehicleSelections(apirooturl,languageid,detailpage,getquotepage,standard_items_containers_text,compare_mode,currentstandarditemscontainerid,printbuttontext,hidegetaquote,resultpage,siteid){
	
        // Displayed messages - customize these on the page based on language
        this.Message_VehiclesInRegion = "{count} vehicles in your area";
        this.Message_ChangeRegion = "Refine my area";

        // Refine Area link - default to # - customize this on the page
        this.RefineAreaLink = "#"; 
	
		this.standard_items_containers_text = standard_items_containers_text; //will contain comma seperated list of info containers ei. Features,Specs,Exterior
		this.apirooturl = apirooturl;
		this.languageid = languageid;
        this.hidegetaquote = hidegetaquote;
        result_url = resultpage;
        site_Id = siteid;
        if(this.hidegetaquote){
            //make the details link point to autotrader folder
            this.detailpage = this.apirooturl + "NewVehicles/AutoTrader/detail_new.aspx";
        }else{
            this.detailpage = detailpage;
        }
		this.getquotepage = getquotepage;
		this.selections = new Array();
		this.menubuttons = new Array();
		this.div = document.getElementById("vehicleselectors");
		this.div.container = this;
		this.CurrentStandardItemsContainerID = null;
		this.standarditemslabelscontainers = document.getElementById("standarditemslabelscontainers");
		this.itemslabelscontainers = new Array(); //will contain references to items labels containers for quick access
		this.GenerateStandardItemsLabelsContainers();
		this.GetAJItemsLabels();
        this.photogallery = new PhotoGallery();
        this.photogallery.container = this;
        this.photogallery.nophotopath = apirooturl + "/imagesdotnet/images_ct/NewCars/no_photo_100_62.gif";
        this.photogallery.Hide();
        this.compare_mode = compare_mode;
        if(currentstandarditemscontainerid != ""){
            this.CurrentStandardItemsContainerID = currentstandarditemscontainerid;
        }
        this.GenerateButtons(printbuttontext);
	}
	
	VehicleSelections.prototype.GetRefreshPageParams = function () {
	    if (this.selections.length ==0)
	        return "";
	    
	    var resultsParams = "?vehicleid=";
	    var i
	    for (i=0; i<=this.selections.length-1; i++)
	    {
	        if(this.selections[i].vehicleid != null){
	            resultsParams += (i>0)?"%2C":"";
	            resultsParams += this.selections[i].vehicleid
	        }
	    }
	    
	    return resultsParams;
	}

    VehicleSelections.prototype.AddStandardItemsLabelsContainer = function(standarditemslabelscontainer){
        this.itemslabelscontainers[this.itemslabelscontainers.length] = standarditemslabelscontainer; //store the container for future retreival     
        this.standarditemslabelscontainers.appendChild(standarditemslabelscontainer.div);//add to global container for all labels containers such as features, exterior
    }
    
    VehicleSelections.prototype.GetStandardItemsLabelsContainer = function(containerid){
       	var i = this.itemslabelscontainers.length-1;
       	var standarditemslabelscontainer = null;
       	if(i > -1){
            do 
            {
                standarditemslabelscontainer = this.itemslabelscontainers[i];
                if(containerid.toUpperCase() == standarditemslabelscontainer.containerid.toUpperCase()){
                    return standarditemslabelscontainer;
                }
            }
            while (i--);
        }
        return null;
    }    

    VehicleSelections.prototype.GenerateStandardItemsLabelsContainers = function(){
        //generate container divs that will house the vehicle values for diffent areas such as features, specs, interiors
        var arrStandardItemsContainers = this.standard_items_containers_text.split(",");
        var containerid = "";
        var standarditemslabelscontainer = null;
        var i = arrStandardItemsContainers.length-1;
        if(i > -1){
            do 
            {   
                containerid = arrStandardItemsContainers[i].toUpperCase() + LABELS_CONTAINER_NAME;
                standarditemslabelscontainer = this.GetStandardItemsLabelsContainer(containerid);
                if(!(standarditemslabelscontainer)){ //does the labels container exists?
                    standarditemslabelscontainer = new StandardItemsContainer(containerid); //create container
                    this.AddStandardItemsLabelsContainer(standarditemslabelscontainer); //add it
                }
            }
            while (i--);
        }
    }

	VehicleSelections.prototype.GetInnerNode = function(parentnode,node,findid){
		if(parentnode==null)
		{
		    //refresh foundnode
		    this.foundnode = null;
		}
		if(node){
	        //get the associated trim dropdown and set the event
	        for(var i=0; i < node.childNodes.length; i++){
		        if(node.childNodes[i].id){
			        if(node.childNodes[i].id == findid){
                        this.foundnode = node.childNodes[i];
                        break;
			        }else{
				        this.foundnode = this.GetInnerNode(node,node.childNodes[i],findid);
			        }
		        }else{
			        this.foundnode = this.GetInnerNode(node,node.childNodes[i],findid);
		        }
	        }
	    }
		return this.foundnode;
	}

	VehicleSelections.prototype.GenerateLabels = function(standarditemslabelstext){
        //split ajax reponse text 
        var arrSIRows = standarditemslabelstext.split("~~");
       	var i = arrSIRows.length-1;
       	var standarditemlabel = null;
       	var standarditemslabelscontainer = null;
       	var inc = 0;
       	var arrSICols = null;
       	if(i > -1){
            do 
            {
                arrSICols = arrSIRows[inc].split("||");
                if(arrSICols.length >= 7){
                    //create instance of vehicleinfo class
                    standarditemlabel = new VehicleStandardItem(arrSICols[0],arrSICols[1],arrSICols[2],arrSICols[3],arrSICols[5],arrSICols[4],arrSICols[6],"");
                    standarditemslabelscontainer = this.GetStandardItemsLabelsContainer(arrSICols[3].toUpperCase() + LABELS_CONTAINER_NAME);
                    if(standarditemslabelscontainer){
                        //add standarditem to container
                        standarditemslabelscontainer.AddStandardItemLabel(standarditemlabel);
                    }
                }
                inc++;
            }
            while (i--);
        }
	}
	
	VehicleSelections.prototype.GetAJItemsLabels = function(){
       var currentvehicleselections = this;
       var aj_requestor = GetRequestor();
       if (aj_requestor) {
            var url =  this.apirooturl + "GeneralAjaxServerPage.aspx?SERVERMETHOD=GetData";
            url += "&RetrievalType=NewCarsGetStandardItemLabels&FilterValue=" + this.languageid;
            aj_requestor.onreadystatechange = function() { 
               if (aj_requestor.readyState == 4) { 
                   if (aj_requestor.status == 200) { 
                        var responsetext = aj_requestor.responseText;
                        responsetext = responsetext.replace("<GeneralAjaxServerPage>","");
                        currentvehicleselections.GenerateLabels(responsetext);
                   }
                   else
                   {
                   }
                   
               } 
            }
            aj_requestor.open('GET', url, true); 
            aj_requestor.send(null);
        }
	}	
	
	VehicleSelections.prototype.StandardItemValueExists = function(itemid,labeltext){
        //iterate through vehicle selectors and get the item based on the layoutid(itemid)
        var j = this.selections.length-1;
        var standarditem = null;
        var standarditemscontainer = null;
        if(j > -1){
            do
            {
                if(this.selections[j]){
                    standarditemscontainer = this.selections[j].GetStandardItemsContainer(this.CurrentStandardItemsContainerID.toUpperCase() + VALUES_CONTAINER_NAME);
                    if(standarditemscontainer){
                        standarditem = standarditemscontainer.GetStandardItem(itemid);
                        if(standarditem){
                            if(standarditem.itemtext!="" && standarditem.itemtext!="&nbsp;"){
                                return true;
                            }
                        }
                    }
                }
            }
            while(j--);
        }	
        return false;
	}
	
    String.prototype.trim = function() {
	    return this.replace(/^\s+|\s+$/g,"");
    }
	
	VehicleSelections.prototype.ShowHideStandardItem = function(itemid,displaymode){
	    //displaymode == "block" || "none"
        //iterate through vehicle selectors again and set the display
        var j = this.selections.length-1;
        var header = null;
        var standarditemscontainer = null;
        var standarditem = null;
        if(j > -1){
            do
            {
                if(this.selections[j]){
                    standarditemscontainer = this.selections[j].GetStandardItemsContainer(this.CurrentStandardItemsContainerID.toUpperCase() + VALUES_CONTAINER_NAME);
                    if(standarditemscontainer){
                        standarditem = standarditemscontainer.GetStandardItem(itemid);
                        if(standarditem){
                            standarditem.itemvaluecontainer.style.display = displaymode;                              
                        }
                    }
                }  
            }
            while(j--);
        }	    
	}

    VehicleSelections.prototype.GenerateAllStandardItems = function(){
        var i = -1;
        var standarditemslabel = null;
        var prevstandarditemslabel = null;
        var standarditemslabelscontainer = this.GetStandardItemsLabelsContainer(this.CurrentStandardItemsContainerID.toUpperCase() + LABELS_CONTAINER_NAME);
        var itemvalueexists = false;
        
        if(standarditemslabelscontainer){
            i = standarditemslabelscontainer.standarditems.length-1;
            if(i > -1){
                do //iterate through labels
                {
                    standarditemslabel = standarditemslabelscontainer.standarditems[i]; //get label
                    if(standarditemslabel){
                        if(prevstandarditemslabel){
                            //add header if not the same as prev item header text
                            if(prevstandarditemslabel.subinfolayerheadertext != standarditemslabel.subinfolayerheadertext){
                                if(itemvalueexists){ //show header for section if one of the items in all the selectors had a value
                                    this.CreateHeader(prevstandarditemslabel); //create header
                                }else{
                                    this.HideHeader(prevstandarditemslabel); //hide header
                                }
                                itemvalueexists = false;
                            }
                        }
                        //check if value exists for any relevant item if so then display it
                        if(this.StandardItemValueExists(standarditemslabel.layoutid,standarditemslabel.itemlabel)){ //check value flag if one of the vehicle selectors items has a value then display relevant items layers
                            standarditemslabel.itemlabelcontainer.style.display = "block";
                            this.ShowHideStandardItem(standarditemslabel.layoutid,"block"); 
                            itemvalueexists = true;
                        }else{
                            standarditemslabel.itemlabelcontainer.style.display = "none";
                            this.ShowHideStandardItem(standarditemslabel.layoutid,"none");
                        }
                        
                        //
                        //  TrackIT#: 18890 -- need to hide MSRP when dealer's price exists
                        //  on page AND is less than dealer's price
                        //
                        //  This rule has been replaced with 20959 -- always show MSRP
                        if (HIDE_MSRP_BOOLEAN && (standarditemslabel.layoutid == MSRP_LAYOUT_ID1 || standarditemslabel.layoutid == MSRP_LAYOUT_ID2 || standarditemslabel.layoutid == MSRP_LAYOUT_ID3 || standarditemslabel.layoutid == MSRP_LAYOUT_ID4))   // <=> MSRP
                        {
                            standarditemslabel.itemlabelcontainer.style.display = "none";
                            this.ShowHideStandardItem(standarditemslabel.layoutid,"none");
                            this.HideHeader(standarditemslabel); //hide header
                            itemvalueexists = false;
                        }
                        else if (!HIDE_MSRP_BOOLEAN && (standarditemslabel.layoutid == MSRP_LAYOUT_ID1 || standarditemslabel.layoutid == MSRP_LAYOUT_ID2 || standarditemslabel.layoutid == MSRP_LAYOUT_ID3 || standarditemslabel.layoutid == MSRP_LAYOUT_ID4))   // <=> MSRP
                        {
                            standarditemslabel.itemlabelcontainer.style.display = "block";
                            standarditemslabel.itemlabelcontainer.style.overflow = "visible";
                            standarditemslabel.itemlabelcontainer.style.zIndex = "10002";
                            
                            //This is to avoid a weird bug where this is being repeated to MSRP under the SPECS tab ONLY.
                            if (standarditemslabel.itemlabelcontainer.innerHTML.indexOf("tooltip") < 0)
                                standarditemslabel.itemlabelcontainer.innerHTML = "<a class='tooltip'>" + standarditemslabel.itemlabelcontainer.innerHTML + "<b>" + MSRP_tooltip_text + "</b></a>";
                            
                        }
                        
                        if(i == 0){ //if at beginning or end of items
                            if(itemvalueexists){ //show header for section if one of the items in all the selectors had a value
                                this.CreateHeader(standarditemslabel); //create header
                            }else{
                                this.HideHeader(standarditemslabel); //hide header
                            }
                            itemvalueexists = false;                        
                        }
                        prevstandarditemslabel = standarditemslabel;
                    }
                }
                while(i--);
            }
        }
        
    }

    VehicleSelections.prototype.CreateHeader = function(headercontaineritem){
        //ADD/SHOW LABEL HEADER
        headercontaineritem.header.style.display = "block";
        if(!headercontaineritem.headeradded){
            if(headercontaineritem.itemlabelcontainer.container){
                headercontaineritem.itemlabelcontainer.container.insertBefore(headercontaineritem.header,headercontaineritem.itemlabelcontainer);
                headercontaineritem.headeradded = true; //set flag so this item doesn't get added again
            }
        }
        //ADD SELECTOR ITEM HEADER ASSOCIATED WITH LABEL HEADER
        var i = this.selections.length-1; //add associated vehicle selector item header spacers
        if(i > -1){
            do
            {
                if(this.selections[i]){
                    standarditemscontainer = this.selections[i].GetStandardItemsContainer(this.CurrentStandardItemsContainerID.toUpperCase() + VALUES_CONTAINER_NAME);
                    if(standarditemscontainer){
                        standarditem = standarditemscontainer.GetStandardItem(headercontaineritem.layoutid); //get associated item
                        if(standarditem){ //found item so add spacers
                            standarditem.header.style.display = "block";
                            if(!standarditem.headeradded){ //don't do insert if previously inserted
                                if(standarditem.itemvaluecontainer.container){
                                    standarditem.itemvaluecontainer.container.insertBefore(standarditem.header,standarditem.itemvaluecontainer);
                                    standarditem.headeradded = true; //set flag so this item doesn't get added again
                                }
                            }
                        }
                    }
                }
           }
           while(i--);
        }       
    }
    
    VehicleSelections.prototype.HideHeader = function(headercontaineritem){
        //hide label header because no items in selectors had values for that section
        headercontaineritem.header.style.display = "none";
        //hide any standard items headers that might have been previously displayed
        var i = this.selections.length-1;
        if(i > -1){
            do
            {
                if(this.selections[i]){
                    standarditemscontainer = this.selections[i].GetStandardItemsContainer(this.CurrentStandardItemsContainerID.toUpperCase() + VALUES_CONTAINER_NAME);
                    if(standarditemscontainer){
                        standarditem = standarditemscontainer.GetStandardItem(headercontaineritem.layoutid); //get associated item
                        if(standarditem){ //found item
                            standarditem.header.style.display = "none"; //hide its header
                        }
                    }
                }
           }
           while(i--);
        }       
    }

	VehicleSelections.prototype.AddSelectorToThisContainer = function(containingDiv){
		var vehicleSelector = new VehicleSelector(this,this.selections.length,null);
		this.selections[this.selections.length] = vehicleSelector;
		containingDiv.appendChild(vehicleSelector.div);
	}

	VehicleSelections.prototype.AddSelector = function(){
		var vehicleSelector = new VehicleSelector(this,this.selections.length,null);
		this.selections[this.selections.length] = vehicleSelector;
		this.div.appendChild(vehicleSelector.div);
	}
	
	VehicleSelections.prototype.AddSelectorByIDToThisContainer = function(vehicleids, containingDiv){
		var arrVehicleids = vehicleids.split(",");

        // Add selectors first because GetVehicleInformation adds the extra selector if there is space.
		for(var i=0; i < arrVehicleids.length; i++)
		    this.AddSelectorToThisContainer(containingDiv); //call method to create selector

		for(var i=0; i < arrVehicleids.length; i++){
		    var vehicleSelector = this.selections[i+1];
		    if(vehicleSelector){ //exists?
		        vehicleSelector.GetVehicleInformation(arrVehicleids[i],true); //load vehicle selector with vehicle information based on vehicle id
		    }
		}
	}

	VehicleSelections.prototype.AddSelectorByID = function(vehicleids){
		var arrVehicleids = vehicleids.split(",");

        // Add selectors first because GetVehicleInformation adds the extra selector if there is space.
		for(var i=0; i < arrVehicleids.length; i++)
		    this.AddSelector(); //call method to create selector

		for(var i=0; i < arrVehicleids.length; i++){
		    var vehicleSelector = this.selections[i];
		    if(vehicleSelector){ //exists?
		        vehicleSelector.GetVehicleInformation(arrVehicleids[i],true); //load vehicle selector with vehicle information based on vehicle id
		    }
		}
	}

	VehicleSelections.prototype.AddSelectorByIDEndFirst = function(vehicleids){
		var arrVehicleids = vehicleids.split(",");

        // Add selectors first because GetVehicleInformation adds the extra selector if there is space.
		for(var i=0; i < arrVehicleids.length; i++)
		    this.AddSelector(); //call method to create selector

		for(var i=0; i < arrVehicleids.length; i++){
		    var vehicleSelector = this.selections[this.selections.length-1-i];
		    if(vehicleSelector){ //exists?
		        vehicleSelector.GetVehicleInformation(arrVehicleids[i],true); //load vehicle selector with vehicle information based on vehicle id
		    }
		}
	}

	VehicleSelections.prototype.RemoveSelector = function(id){
		//rebuild the collection
		var tmpSelectors = new Array();
        var i = this.selections.length-1;
        var vehicleSelector = null;
        var inc = 0;
        if(i > -1){
            do 
            {
		        vehicleSelector = this.selections[inc];
		        if(vehicleSelector.baseid != id){
			        //replace the id with newid
			        vehicleSelector.ReplaceID(tmpSelectors.length);
			        tmpSelectors[tmpSelectors.length] = vehicleSelector;
		        }else{
		            //flush container items
		            vehicleSelector.div.style.display = "none";//hide it before doing disposal
			        vehicleSelector.FlushStandardItemsContainers();
			        //remove div layer and corresponding information layer for selector being removed
			        vehicleSelector.div.parentNode.removeChild(vehicleSelector.div);
                    DisposeAll(vehicleSelector.div); //dispose all sub objects		
		        }
		        inc++;
            }
            while (i--);
        }
        this.selections = null;
		this.selections = tmpSelectors;
		//regenerate standarditems grid
		this.GenerateAllStandardItems();
		
  		if (id = 2)
		    BOOL_FEATURED_AD_DISPLAYED = false;
	}

    VehicleSelections.prototype.GenerateButtons = function(printbuttontext){
        var arrStandardItemsContainers = this.standard_items_containers_text.split(",");
        //add container buttons
        for(var i=0; i < arrStandardItemsContainers.length; i++){
            this.AddMenuButton(arrStandardItemsContainers[i],false);
        }
        if(this.compare_mode){//add print button if in compare mode
            this.AddMenuButton(printbuttontext,true);
        }
    }
    
    VehicleSelections.prototype.AddMenuButton = function(text,isprintbutton){
		var buttonscontainer = document.getElementById("buttons");
		if(buttonscontainer){
		    var menubutton = new MenuButton(text,isprintbutton);
		    menubutton.container = this;
		    menubutton.SetState(2); //default to disabled for the buttons
		    if(this.menubuttons.length == DEFAULT_MENU_BUTTON_POSITION){ //set the default info container id based on corresponding default menu position
		        this.CurrentStandardItemsContainerID = text;
		    }
		    this.menubuttons[this.menubuttons.length] = menubutton;
		    buttonscontainer.appendChild(menubutton.link);
		}
    }
    
    VehicleSelections.prototype.EnableDisableButtons = function(disable){
        for(var i=0; i < this.menubuttons.length; i++){
            var menubutton = this.menubuttons[i];
            if(menubutton){
                if(disable){
                    menubutton.SetState(2); //disabled
                }else{
                    menubutton.SetState(0); //active/enabled
                }
            }
        }
    }	
    
    //**********************************************************************
    //* MAIN MENU BUTTON                                                   *
    //**********************************************************************
	function MenuButton(text,isprintbutton){
	    this.state = 2; //0:active 1:selected 2:disabled
        this.link = document.createElement("a");
        this.id = "btn" + text; 
        this.link.id = this.id;
        this.menubuttoncounterpos = menubuttoncounter;
        this.link.className = "comparebutton a" + this.menubuttoncounterpos;
        menubuttoncounter += 1;
        this.link.setAttribute("href","javascript:void(0);");
        this.link.appendChild(document.createTextNode(text));
        this.link.container = this;
	    if(!isprintbutton){
            this.link.onclick=function(){
                if(this.container.state == 0){ //is button active
                    var standarditemscontainerid = this.id.toUpperCase().replace("BTN","");
                    this.container.container.CurrentStandardItemsContainerID = standarditemscontainerid;
                    if(this.container){
                        var currentmenubutton = null;
                        //iterate through vehicleselectors menubuttons collection and set appropriate status
                        for(var i=0; i < this.container.container.menubuttons.length; i++){
                            currentmenubutton = this.container.container.menubuttons[i];
                            if(currentmenubutton){
                                if(currentmenubutton.id == this.id){
                                    currentmenubutton.SetState(1);
                                }else{
                                    currentmenubutton.SetState(0);
                                }
                            }
                        }
                    }
                    showHideInfoLayer(standarditemscontainerid); //show relevant layer
                }
                return false;
            }	
        }else{
            this.link.onclick=function(){
                if(this.container.state == 0){ //is active
                    PrintPage();
                }
                return false;
            }        
        }    
	}
	
	MenuButton.prototype.SetState = function(stateid){
	    switch(stateid){
	        case 0:
	        //active
	        if(this.id.toUpperCase() == "BTN" + this.container.CurrentStandardItemsContainerID.toUpperCase()){
	            this.link.className = "comparebuttonselected a" + this.menubuttoncounterpos; //selected
	        }else{
	            this.link.className = "comparebutton a" + this.menubuttoncounterpos; //active
	        }
	        break;
	        case 1:
	        //selected
	        this.link.className = "comparebuttonselected a" + this.menubuttoncounterpos;
	        break;
	        default:
	        //disabled
	        this.link.className = "comparebuttondisabled a" + this.menubuttoncounterpos;
	        break;
	    }
	    this.state = stateid;
	}

    //**********************************************************************
    //* VehicleStandardItem                                                *
    //**********************************************************************
    function VehicleStandardItem(layoutid,schemaid,infolayerid,infolayerheadertext,subinfolayerid,subinfolayerheadertext,itemlabel,itemtext){
        this.layoutid = layoutid;
        this.infolayerheadertext = infolayerheadertext;
        this.subinfolayerheadertext = subinfolayerheadertext;
        this.itemlabel = itemlabel.trim();
        this.itemtext = itemtext.trim();
        this.itemvaluecontainer = document.createElement("div");
        this.itemvaluecontainer.container = null; //will be set to values container
        this.itemvaluecontainer.id = "itemvaluecontainer" + this.layoutid;
        this.itemvaluecontainer.className = "vehicle_item_outer_cell";
        this.itemvaluecontainer.style.display = "none"; //default to none
        this.itemvaluecontainer.onmouseover = function(){
            this.style.overflow = "visible";
            this.style.zIndex = 10000;
            this.className = "vehicle_item_outer_cell_mouse_over";
        }        
        this.itemvaluecontainer.onmouseout = function(){
            this.style.overflow = "hidden";
            this.style.zIndex = 1000;
            this.className = "vehicle_item_outer_cell";
        }
        this.itemvalue = document.createElement("div");
        this.itemvalue.container = this.itemvaluecontainer;
        this.itemvalue.id = "itemvalue" + this.layoutid;
        this.itemvalue.className = "vehicle_item_inner_cell";
        
        if(this.itemtext.trim() == this.itemlabel.trim()){
            //replace with checkbox
            this.itemvalue.innerHTML = "<span class='compare_yes_mark'></span>&nbsp;";
        }else{        
            //if (this.itemlabel.trim().toLowerCase() == "trim" && trim_url.length > 0){
                //this.itemvalue.innerHTML = "<a href='" + result_url + trim_url + "'>" + this.itemtext.trim() + "</a>&nbsp;";
		    //}else{   
		        this.itemvalue.innerHTML = this.itemtext.trim() + "&nbsp;";
            //}
        }
        this.itemvaluecontainer.appendChild(this.itemvalue);
        this.itemlabelcontainer = document.createElement("div");
        this.itemlabelcontainer.id = "itemlabel" + this.layoutid;
        this.itemlabelcontainer.container = null; //will be set to labels container
        this.itemlabelcontainer.className = "vehicle_item_label_cell";
        this.itemlabelcontainer.innerHTML = this.itemlabel.trim();
        this.itemlabelcontainer.style.display = "none"; //default to none
        this.header = document.createElement("div");
        this.header.id = "itemheader" + this.subinfolayerheadertext;
        this.header.className = "vehicle_item_empty_header_cell";
        this.header.style.display = "none"; //default to none
        this.header.innerHTML = "&nbsp;";    
        this.headeradded = false;    
    }
    
    //**********************************************************************
    //* StandardItemsContainer                                             *
    //**********************************************************************    
    function StandardItemsContainer(containerid){
        this.standarditems = new Array();
        this.containerid = containerid;
        this.div = document.createElement("div"); //create it
        this.div.id = containerid;
        this.div.container = this;
        this.div.style.display = "none";        
    }
    //**********************************************************************
    //* STANDARD ITEMS CONTAINER FUNCTIONS                                 *
    //**********************************************************************
    StandardItemsContainer.prototype.AddStandardItem = function(standarditem){
        this.standarditems[this.standarditems.length] = standarditem; //store the vehicle item
        standarditem.itemvaluecontainer.container = this.div;
        this.div.appendChild(standarditem.itemvaluecontainer); //add item value container to parent div
    }
    
    StandardItemsContainer.prototype.AddStandardItemLabel = function(standarditem){
        standarditem.header.className = "vehicle_item_header_cell";
        standarditem.header.innerHTML = standarditem.subinfolayerheadertext;
        this.standarditems[this.standarditems.length] = standarditem; //store the vehicle label item
        standarditem.itemlabelcontainer.container = this.div;
        this.div.appendChild(standarditem.itemlabelcontainer); //add item label container to parent div
    }
    
    StandardItemsContainer.prototype.GetStandardItem = function(itemlayoutid){
        var i = this.standarditems.length-1;
        var standarditem = null;
        if(i > -1){
            do 
            {
                standarditem = this.standarditems[i];
                if(standarditem.layoutid == itemlayoutid){
                    return standarditem;
                }
            }
            while (i--);
        }
        return null;
    }  
    
    StandardItemsContainer.prototype.FlushStandardItems = function(){
        DisposeAll(this.div);
        this.standarditems = null;
        this.standarditems = new Array();
    }
    
    StandardItemsContainer.prototype.ClearStandardItemsValues = function(){
        var i = this.standarditems.length-1;
        var standarditem = null;
        if(i > -1){
            do 
            {
                standarditem = this.standarditems[i];
                if(standarditem){
                    //empty cell
                    standarditem.itemvalue.innerHTML = "&nbsp;";
                    standarditem.itemtext = "&nbsp;";
                }
            }
            while (i--);
        }        
    }

    //**********************************************************************
    //* VehicleSelector                                                    *
    //**********************************************************************
	function VehicleSelector(selectorscontainer,id){
		var selectorTemplate = document.getElementById("vehicleselector");
		this.div = selectorTemplate.cloneNode(true);
		this.div.style.display = "block";
		this.vehicleid = null;
		this.baseid = id; //the position in vehicles array(collection)
		this.div.id = "vehicleselection" + id;
		this.div.container = this; //this object is the container of the div
		this.container = selectorscontainer; //this will contain a reference to the array(collection) that stores vehicle selectors	
		this.itemscontainers = new Array(); //will contain references to items containers for quick access
        this.standarditemscontainers = this.container.GetInnerNode(null,this.div,"standarditemscontainers");
        this.standarditemscontainers.container = this;        
        this.GenerateStandardItemsContainers();
        this.dropdownareacontainer = this.container.GetInnerNode(null,this.div,"dropdownareacontainer");
        this.dropdownareacontainer.container = this;
        this.mainphotocontainer = this.container.GetInnerNode(null,this.dropdownareacontainer,"mainphotocontainer");
        this.mainphotocontainer.container = this;
        //This is for the featured car for mazda/toyota campaign -------
        this.featuredAdLogoPlaceholder = this.container.GetInnerNode(null,this.dropdownareacontainer,"featuredAdLogoPlaceholder");
        this.featuredAdLogoPlaceholder.container = this;
        this.iframewrapper = this.container.GetInnerNode(null,this.dropdownareacontainer,"iframewrapper");
        this.iframewrapper.container = this;
        this.iframecontainer = this.container.GetInnerNode(null,this.iframewrapper,"iframecontainer");
        this.iframecontainer.container = this.iframewrapper;
        this.iframe = this.container.GetInnerNode(null,this.iframecontainer,"ifOAS");
        this.iframe.container = this.iframecontainer;
        //--------------------------------------------------------------
        this.suggestionscontainer = this.container.GetInnerNode(null,this.dropdownareacontainer,"suggestionscontainer");
        this.suggestionscontainer.container = this;
        this.suggestionslinkscontainer = this.container.GetInnerNode(null,this.suggestionscontainer,"suggestionslinkscontainer");
        this.suggestionslinkscontainer.container = this;
        this.photoscontainer = this.container.GetInnerNode(null,this.dropdownareacontainer,"photoscontainer");
        this.photoscontainer.container = this;        
        this.linkscontainer = this.container.GetInnerNode(null,this.dropdownareacontainer,"linkscontainer");
        this.linkscontainer.container = this;
        this.vehicledetailslink = this.container.GetInnerNode(null,this.linkscontainer,"vehicledetailslink");
        this.vehicledetailslink.container = this;
        this.getapricequotelink = this.container.GetInnerNode(null,this.linkscontainer,"getapricequotelink");
        this.getapricequotelink.container = this;
        this.RegionMatchCount = "0";
        
        this.SetEvents(this.div);
	}
	
    //**********************************************************************
    //* VEHICLE SELECTOR MISC. FUNCTIONS                                   *
    //**********************************************************************
	VehicleSelector.prototype.SetEvents = function(node){
	    this.ddlYears = this.container.GetInnerNode(null,node,"ddlYears");
	    if(this.ddlYears){
	        this.ddlYears.container = this;
	        //this.GetAJLists(null, this.ddlYears, "", "", "");                 //this old line
	        this.ddlMakes = this.container.GetInnerNode(null,node,"ddlMakes");  //replaced with this one
	        this.GetAJLists(null,this.ddlMakes,"","","");                       //and this one!
            this.ddlYears.onchange = function(){
                if(this.selectedIndex >= 0){
                    this.container.Reset(0);    
                    this.container.GetAJLists(this,this.container.ddlMakes,this.options[this.selectedIndex].value,"","");
                }
            } 
	        //set dropdowns and events
            this.ddlMakes = this.container.GetInnerNode(null,node,"ddlMakes");
            if(this.ddlMakes){
                this.ddlMakes.container = this;
                this.ddlMakes.onchange = function(){
                    if(this.selectedIndex >= 0){
                        this.container.Reset(1); 
                        this.container.GetAJLists(this,this.container.ddlModels,this.options[this.selectedIndex].value,"","");
                    }
                } 
                this.ddlModels = this.container.GetInnerNode(null,node,"ddlModels");
                    if(this.ddlModels){
                     this.ddlModels.container = this;
                     this.ddlModels.onchange = function(){
                        if(this.selectedIndex >= 0){
                            var make = this.container.ddlMakes.options[this.container.ddlMakes.selectedIndex].value;
                            var model = this.options[this.selectedIndex].value;
                            this.container.Reset(2);
                            this.container.GetAJLists(this,this.container.ddlTrims,this.container.ddlMakes.options[this.container.ddlMakes.selectedIndex].value,this.options[this.selectedIndex].value,"");
                        }
                    }                
		            this.ddlTrims = this.container.GetInnerNode(null,node,"ddlTrims");
		            if(this.ddlTrims){
		                this.ddlTrims.container = this;
			            this.ddlTrims.onchange = function(){
			                if(this.selectedIndex == 0){
			                    this.container.Reset(4);
			                }
			                if(this.selectedIndex > 0){
                                this.container.GetVehicleInformation(this.options[this.selectedIndex].value,false);
		                    }
			            }			        
		            }
			    }
            }
        }
        //set close button
		this.btnClose = this.container.GetInnerNode(null,node,"btnClose");
	    if(this.btnClose){
            this.btnClose.container = this;
		    this.btnClose.onclick = function(){
			    if((this.container.container.selections.length >= 3) &&
			        (this.container.baseid == 1) && (BOOL_FEATURED_AD_DISPLAYED)) //middle position w/ featured ad showing -- don't remove, just clear
			    {
			        this.container.Reset(0);
			        this.container.Reset(1);
                    this.container.Reset(2);
                    this.container.Reset(4);
                    this.container.ddlYears.selectedIndex = 0;
			    }
			    else
			    {
			        this.container.container.RemoveSelector(this.container.baseid); //call the associated collections remove method
		            if(this.container.container.selections.length <= 1){
		                this.container.container.AddSelector();
		            }
			    }
		    }	    
	        //hide button if the baseid is 0 which is the first position in selections array
	        if(this.baseid == 0){
                this.btnClose.style.display = "none";
			}
	    }
        this.viewgallerylink = this.container.GetInnerNode(null,this.linkscontainer,"viewgallerylink");
        if(this.viewgallerylink){
            this.viewgallerylink.container = this;
            this.viewgallerylink.onclick = function(){ //set photo gallery link
                //onclick will display relevant photo gallery by calling vehicleselectors showphotogallery method
                this.container.container.photogallery.Show(this.container.baseid, this.container.GetTitle());
            }
        }
	}
	
	VehicleSelector.prototype.GetTitle = function(){
	    return this.ddlYears.options[this.ddlYears.selectedIndex].value + " " + this.ddlMakes.options[this.ddlMakes.selectedIndex].value + " " + this.ddlModels.options[this.ddlModels.selectedIndex].value;
	}

	VehicleSelector.prototype.ReplaceID = function(newid){
		var oldid = this.baseid;
		this.baseid = newid;
		this.div.id = "vehicleselection" + newid;
	}

    VehicleSelector.prototype.Reset = function(resettype){
        this.container.photogallery.Hide();
        if(resettype==0){ //years onchange event reset
            this.ddlMakes.selectedIndex = 0;
            this.ddlMakes.disabled = true;
        }
        if(resettype==0 || resettype==1){ //years or makes onchange event reset
            this.ddlModels.selectedIndex = 0;
            this.ddlModels.disabled = true;
        }
        if (resettype == 4){
            // when trim selectedIndex is 0
            this.vehicledetailslink.style.display = "none";
            this.viewgallerylink.style.display = "none";
            this.getapricequotelink.style.display = "none";
        }
        else{
            //below all get reset no matter what onchange resets it
            this.ddlTrims.selectedIndex = 0;
            this.ddlTrims.disabled = true;
            this.mainphotocontainer.style.display = "none"; 
            this.vehicledetailslink.style.display = "none";
            this.viewgallerylink.style.display = "none";
            this.getapricequotelink.style.display = "none";
        }
        this.ClearStandardItemsContainersValues(); //keep formatting if more than one selector
    }
    
    //**********************************************************************
    //* VEHICLE SELECTOR ITEMS CONTAINERS FUNCTIONS                        *
    //**********************************************************************
    VehicleSelector.prototype.FlushStandardItemsContainers = function(){
        var i = this.itemscontainers.length -1;
        var standarditemscontainer = null;
        if(i > -1){
            do
            {
                standarditemscontainer = this.itemscontainers[i];
                if(standarditemscontainer){
                    standarditemscontainer.FlushStandardItems();
                }
            }
            while(i--);
        }
    }
    //this will just clear the cells of there values
    VehicleSelector.prototype.ClearStandardItemsContainersValues = function(){
        var i = this.itemscontainers.length -1;
        var standarditemscontainer = null;
        if(i > -1){
            do
            {
                standarditemscontainer = this.itemscontainers[i];
                if(standarditemscontainer){
                    standarditemscontainer.ClearStandardItemsValues();
                }
            }
            while(i--);
        }
    }
    
    VehicleSelector.prototype.GetStandardItemsContainer = function(containerid){
       	var i = this.itemscontainers.length-1;
       	var standarditemscontainer = null;
       	if(i > -1){
            do 
            {
                standarditemscontainer = this.itemscontainers[i];
                if(containerid.toUpperCase() == standarditemscontainer.containerid.toUpperCase()){
                    return standarditemscontainer;
                }
            }
            while (i--);
        }
        return null;
    }
	
    VehicleSelector.prototype.GenerateStandardItemsContainers = function(){
        //generate container divs that will house the vehicle values for diffent areas such as features, specs, interiors
        var arrStandardItemsContainers = this.container.standard_items_containers_text.split(",");
        var containerid = "";
        var standarditemscontainer = null;
        var i = arrStandardItemsContainers.length-1;
        if(i > -1){
            do 
            {   
                containerid = arrStandardItemsContainers[i].toUpperCase() + VALUES_CONTAINER_NAME;
                standarditemscontainer = this.GetStandardItemsContainer(containerid);
                if(!(standarditemscontainer)){ //does the info items container exists?
                    standarditemscontainer = new StandardItemsContainer(containerid); //create container
                    this.AddStandardItemsContainer(standarditemscontainer); //add it
                }
            }
            while (i--);
        }
    }

    VehicleSelector.prototype.AddStandardItemsContainer = function(standarditemscontainer){
        this.itemscontainers[this.itemscontainers.length] = standarditemscontainer; //store the container for future retreival     
        this.standarditemscontainers.appendChild(standarditemscontainer.div);//add to global container for all standard items containers such as features, exterior
    }
    
    //**********************************************************************
    //* VEHICLE SELECTOR STANDARD ITEMS FUNCTIONS                          *
    //**********************************************************************
	VehicleSelector.prototype.GetAJStandardItems = function(vehicleid){
       var aj_requestor = GetRequestor();
       var currentvehicleselector = this;
       if (aj_requestor) {
            var url =  this.container.apirooturl + "GeneralAjaxServerPage.aspx?SERVERMETHOD=GetData";
            url += "&RetrievalType=NewCarsVehicleStandardItems&FilterValue=" + vehicleid + "&FilterValue1=" + this.container.languageid;
            aj_requestor.onreadystatechange = function() { 
               if (aj_requestor.readyState == 4) { 
                   if (aj_requestor.status == 200) {
                        //set vehicle info layers
                        var responsetext = aj_requestor.responseText;
                        responsetext = responsetext.replace("<GeneralAjaxServerPage>","");
	                    if(responsetext != ""){
	                        //flush existing items
	                        currentvehicleselector.FlushStandardItemsContainers();
	                        //split responsetext and add vehicleinfo object to current vehicleselector vehicleinfo collection
	                        currentvehicleselector.GenerateStandardItemsFromText(responsetext);
	                        currentvehicleselector.container.GenerateAllStandardItems();
                            showHideInfoLayer(currentvehicleselector.container.CurrentStandardItemsContainerID); 
                            currentvehicleselector.container.EnableDisableButtons(false);  
                        }
                        aj_requestor = null;
                   }
               } 
            }
            aj_requestor.open('GET', url, true); 
            aj_requestor.send(null);            
       }
	}

    VehicleSelector.prototype.GenerateStandardItemsFromText = function(standarditemstext){
        //split ajax reponse text 
        var arrSIRows = standarditemstext.split("~~");
       	var i = arrSIRows.length-1;
       	var standarditem = null;
       	var standarditemscontainer = null;
       	var inc = 0;
       	var arrSICols = null;
       	if(i > -1){
            do 
            {
                arrSICols = arrSIRows[inc].split("||");
                if(arrSICols.length >= 8){
                    //create instance of vehicleinfo class
                    standarditem = new VehicleStandardItem(arrSICols[0],arrSICols[1],arrSICols[2],arrSICols[3],arrSICols[5],arrSICols[4],arrSICols[6],arrSICols[7]);
                    standarditemscontainer = this.GetStandardItemsContainer(arrSICols[3].toUpperCase() + VALUES_CONTAINER_NAME);
                    if(standarditemscontainer){
                        //add standarditem to container
                        standarditemscontainer.AddStandardItem(standarditem);
                    }
                }
                inc++;
            }
            while (i--);
        }
    }
    
    VehicleSelector.prototype.DisplayRegionInfo = function (vehicleId)
    {
        var selections = this.container;
        if (selections.standarditemslabelscontainers)
        {
            //Add Header
            if (!selections.standarditemslabelscontainers.regionMatchHeader)
            {
                //labels container
                var regionlabelscontainer = document.createElement ('div');
                regionlabelscontainer.setAttribute ("id", "region_match_header");                
                regionlabelscontainer.setAttribute ("class", "region_footer");
                regionlabelscontainer.setAttribute ("style", "display: block;");
                regionlabelscontainer.container = selections.standarditemslabelscontainers;
                
                //link
                var refineRegionHref; 
                refineRegionHref = "<a href='{refineregionlink}'>{refineregionmessage}</a>";
                refineRegionHref = refineRegionHref.replace ("{refineregionlink}", this.container.RefineAreaLink);
                refineRegionHref = refineRegionHref.replace ("{refineregionmessage}", this.container.Message_ChangeRegion);

                //container that holds the label text
                var labelcontainer = document.createElement("div");
                labelcontainer.id = "regionlabeltext";
                labelcontainer.container = regionlabelscontainer; //will be set to labels container
                labelcontainer.className = "vehicle_item_header_cell region_footer";
                labelcontainer.style.display = "block";
                labelcontainer.innerHTML = refineRegionHref;
                
                //add label container to region labels container 
                regionlabelscontainer.appendChild(labelcontainer);

                //add region labels container to labels container collection
                selections.standarditemslabelscontainers.regionMatchHeader = regionlabelscontainer;
                selections.standarditemslabelscontainers.appendChild (regionlabelscontainer);
            }
            
            // Add region for this vehicle selector
            if (!this.standarditemscontainers.RegionMatchItem)
            {
                var valueoutercontainer = document.createElement("div");
                valueoutercontainer.container = null; //will be set to values container
                valueoutercontainer.id = "region_match_item_container_"+this.baseid;
                valueoutercontainer.className = "vehicle_item_outer_cell_vnum region_footer_vnum";
                valueoutercontainer.style.display = "block"; //default to none

                var valueinnercontainer = document.createElement("div");
                valueinnercontainer.container = valueoutercontainer;
                valueinnercontainer.id = "region_match_item_"+this.baseid;
                valueinnercontainer.className = "vehicle_item_inner_cell";
                valueinnercontainer.setAttribute ("style", "display: block;clear:both; background:none; background-image:none;");
                
                if(this.RegionMatchCount != "" && this.RegionMatchCount != "0"){
                    var vehiclematchMessage = this.container.Message_VehiclesInRegion;
                    vehiclematchMessage = vehiclematchMessage.replace ("{count}", "<div class=\"region_count\" style=\"background:none; background-image:none; margin-right:10px;\">" + this.RegionMatchCount + "</div><div class=\"compare_match_text\">");
                    valueinnercontainer.innerHTML = "<a href='" + result_url + this.regioninfoparams + "' style='text-decoration:none;'>" + vehiclematchMessage + "</a></div>";
                }else{
                    valueinnercontainer.innerHTML = "";
                }

                valueoutercontainer.appendChild(valueinnercontainer);
                this.standarditemscontainers.RegionMatchItem = valueoutercontainer;
                this.standarditemscontainers.appendChild(valueoutercontainer);
             }else{
                var valueinnercontainer = this.container.GetInnerNode(null,this.standarditemscontainers.RegionMatchItem,"region_match_item_"+this.baseid);
                if(valueinnercontainer)
                {
                    if(this.RegionMatchCount != "" && this.RegionMatchCount != "0"){
                        var vehiclematchMessage = this.container.Message_VehiclesInRegion;
                        vehiclematchMessage = vehiclematchMessage.replace ("{count}", "<div class=\"region_count\" style=\"background:none; background-image:none; margin-right:10px;\">" + this.RegionMatchCount + "</div><div class=\"compare_match_text\">");
                        var strAmp = "?";
                        if (this.regioninfoparams.substring(this.regioninfoparams.length-1,1) == "?")
                            strAmp = "&";
                        valueinnercontainer.innerHTML = "<a href='" + result_url + this.regioninfoparams + strAmp + "id=" + this.vehicleid + "' style='text-decoration:none;'>" + vehiclematchMessage + "</a></div>";
                    }else{
                        valueinnercontainer.innerHTML = "";
                    }
                }
             }
        }
    } 
    
    //**********************************************************************
    //* VEHICLE SELECTOR VEHICLE INFORMATION FUNCTIONS                     *
    //**********************************************************************
    VehicleSelector.prototype.GetVehicleInformation = function(vehicleid,getvidata){
        this.container.EnableDisableButtons(true);
        this.GetAJStandardItems(vehicleid);
        this.vehicleid = vehicleid;
        if(getvidata){
            this.GetAJVehicleInformation(vehicleid);
        }else{
            this.regioninfoparams ='';
            if (this.ddlTrims != null && this.ddlTrims.options.length > 0 && this.ddlTrims.selectedIndex > 0){
                this.regioninfoparams = '?vehicleid=' + this.ddlTrims.options[this.ddlTrims.selectedIndex].value;
            } 
            if (this.ddlMakes != null && this.ddlMakes.options.length > 0 && this.ddlMakes.selectedIndex > 0){
                if(this.regioninfoparams == ''){
                    this.regioninfoparams = '?';
                }else{
                    this.regioninfoparams = this.regioninfoparams + '&';
                }
                this.regioninfoparams = this.regioninfoparams + 'mk=' + this.ddlMakes.options[this.ddlMakes.selectedIndex].value;
            }
            if (this.ddlModels != null && this.ddlModels.options.length > 0 && this.ddlModels.selectedIndex > 0){
                if(this.regioninfoparams == ''){
                    this.regioninfoparams = '?';
                }else{
                    this.regioninfoparams = this.regioninfoparams + '&';
                }
                this.regioninfoparams = this.regioninfoparams + 'md=' + this.ddlModels.options[this.ddlModels.selectedIndex].value;
            }
            if(this.regioninfoparams != ''){
                if (this.container.compare_mode)
                    this.GetAJRegionMatches(); //build region info counts etc.
            }else{
                this.RegionMatchCount = 0;
                this.DisplayRegionInfo();
            }
        }
        this.GetAJPhotos(this.photoscontainer,vehicleid);
        this.suggestionscontainer.style.display = "none";
        this.vehicledetailslink.style.display = "block";
        if (this.container.detailpage.indexOf("?") >= 0) {
        this.vehicledetailslink.href = this.container.detailpage + "&mk=" + this.ddlMakes.options[this.ddlMakes.selectedIndex].value + "&md=" + this.ddlModels.options[this.ddlModels.selectedIndex].value + "&id=" + vehicleid;
        } else {
        this.vehicledetailslink.href = this.container.detailpage + "?mk=" + this.ddlMakes.options[this.ddlMakes.selectedIndex].value + "&md=" + this.ddlModels.options[this.ddlModels.selectedIndex].value + "&id=" + vehicleid;
        }
        if(!this.container.hidegetaquote){
            this.getapricequotelink.href = this.container.getquotepage + "?vehicleid=" + vehicleid + "&mk=" + this.ddlMakes.options[this.ddlMakes.selectedIndex].value + "&md=" + this.ddlModels.options[this.ddlModels.selectedIndex].value + "&compare=1";
            this.getapricequotelink.style.display = "block"; 
        }
        //don't add any new selectors if in details page view
        if(this.container.compare_mode){   		                        
            
            var featuredAdVehicleID = -1;   //this means no featured comparison ad - default
            var make = this.ddlMakes.options[this.ddlMakes.selectedIndex].value;
            var model = this.ddlModels.options[this.ddlModels.selectedIndex].value;
            var trim = this.ddlTrims.options[this.ddlTrims.selectedIndex].text;
            var trimId = this.ddlTrims.options[this.ddlTrims.selectedIndex].value;
            var advertiser; //used as a parameter to be passed into OAS for iframe content.
            
            //returnDataType = 1 = vehicleID
            //returnDataType = 2 = advertiser
            //(*** from FACObject.js which reads FACRules.xml)
            featuredAdVehicleID = returnFeaturedVehicleData(trimId, 1);
            advertiser = returnFeaturedVehicleData(trimId, 2);

            if (INT_AD_DISPLAYS_REMAINING > 0 && ((this.baseid + 1) == 2 && featuredAdVehicleID > -1))
            {
                //do not add a selector for suggestions but just display the featured ad
            }
            else
            {
                //only allow up to 3 vehicle selectors to fit page properly
                if(this.container.selections.length < 3 && this.container.selections.length == (this.baseid + 1)){
                    this.container.AddSelector();
                } 
                //make sure there is an addselector after this one in order to add suggestion links to it
                if(this.container.selections.length > (this.baseid + 1)){
                    var nextVehicleSelector = this.container.selections[this.baseid + 1];
                    if(nextVehicleSelector){
                        if(nextVehicleSelector.vehicledetailslink.style.display == "none" && nextVehicleSelector.viewgallerylink.style.display == "none" && (nextVehicleSelector.ddlTrims.selectedIndex > 0 || nextVehicleSelector.ddlTrims.disabled)){ //check if suggestions area is taken up by main photo and/or details/quote links if not then add suggestions
                            nextVehicleSelector.GetAJVehicleSuggestions(); //get the suggestions link for selector being added
                        }
                    }
                }
            }
            if (INT_AD_DISPLAYS_REMAINING > 0 && (this.container.selections.length < 3 && featuredAdVehicleID > -1))
            {
                this.container.AddSelectorByIDEndFirst(featuredAdVehicleID);
                BOOL_FEATURED_AD_DISPLAYED = true;
                INT_AD_DISPLAYS_REMAINING--;
                var featuredAdVehicleSelector = this.container.selections[2];
                if (advertiser == 'mazda')
                {
                    featuredAdVehicleSelector.featuredAdLogoPlaceholder.innerHTML = document.getElementById('featuredCarLogo_mazda').innerHTML;
                    featuredAdVehicleSelector.iframewrapper.style.display = 'block';
                }
                else if (advertiser == 'toyota')
                {
                    featuredAdVehicleSelector.featuredAdLogoPlaceholder.innerHTML = document.getElementById('featuredCarLogo_toyota').innerHTML;
                    featuredAdVehicleSelector.iframewrapper.style.display = 'block';
                }
                else if (advertiser == 'hyundai')
                {
                    featuredAdVehicleSelector.featuredAdLogoPlaceholder.innerHTML = document.getElementById('featuredCarLogo_hyundai').innerHTML;
                    featuredAdVehicleSelector.iframewrapper.style.display = 'block';
                }
                else if (advertiser == 'nissan')
                {
                    featuredAdVehicleSelector.featuredAdLogoPlaceholder.innerHTML = document.getElementById('featuredCarLogo_hyundai').innerHTML;
                    featuredAdVehicleSelector.iframewrapper.style.display = 'block';
                }

                featuredAdVehicleSelector.div.id += "_featuredAd";
                
                if (document.getElementById('ifOAS'))
                {
                    if (advertiser == "")    
                        alert("ERROR: cannot associate an advertiser with this featured ad display.")
                    
                    //alert(featuredAdVehicleSelector.iframe.id);
                    featuredAdVehicleSelector.iframe.src = "/NewVehicles/OASIframeContent.aspx?advertiser=" + advertiser + "&triggerMake=" + make + "&triggerModel=" + model + "&triggerTrim=" + trim;
                    //objs[2].src = "/NewVehicles/OASIframeContent.aspx?advertiser=" + advertiser + "&triggerMake=" + make + "&triggerModel=" + model;
                    //alert(objs[2].src);
                    
                }
                
            }
            
        }
    }
    
	VehicleSelector.prototype.GetAJVehicleInformation = function(vehicleid){
       var aj_requestor = GetRequestor();
       var currentvehicleselector = this;
       if (aj_requestor) {
            var url =  this.container.apirooturl + "GeneralAjaxServerPage.aspx?SERVERMETHOD=GetData";
            url += "&RetrievalType=NewCarsVehicleInformation&FilterValue=" + vehicleid;
            aj_requestor.onreadystatechange = function() { 
               if (aj_requestor.readyState == 4) { 
                   if (aj_requestor.status == 200) {
                        //set vehicle info layers
                        var responsetext = aj_requestor.responseText;
                        responsetext = responsetext.replace("<GeneralAjaxServerPage>","");
	                    if(responsetext != ""){
	                        //split responsetext and add vehicleinfo object to current vehicleselector vehicleinfo collection
	                        currentvehicleselector.GenerateVehicleInformation(responsetext);
                        }
                        aj_requestor = null;
                   }
               } 
            }
            aj_requestor.open('GET', url, true); 
            aj_requestor.send(null);
       }
	}    

    VehicleSelector.prototype.GenerateVehicleInformation = function(vehicleinfotext){
        //split ajax reponse text 
        var arrRows = vehicleinfotext.split("~~");
   	    var arrCols = null;
   	    if(arrRows.length > 0){
            arrCols = arrRows[0].split("||");
            if(arrCols.length >= 3){ //populate dropdowns based on returned text
                this.GetAJLists(null, this.ddlYears, "", "", arrCols[1]);
                var preppedMake = arrCols[2].replace(' ', '+');
                //Bug fix: ticket 37176
                //Need to replace the space with a '+' char in the make in order for the
                //make dropdown's value to correctly be set.
                //
                //   i.e. Aston Martin => Aston+Martin
                this.GetAJLists(this.ddlYears,this.ddlMakes,arrCols[1],"",preppedMake);
                this.GetAJLists(this.ddlMakes,this.ddlModels,preppedMake,"",arrCols[3]);
                this.GetAJLists(this.ddlModels,this.ddlTrims,preppedMake,arrCols[3],arrCols[0]);
	            this.regioninfoparams ='';
	            if (arrCols[0] != ""){
	                this.regioninfoparams = '?vehicleid=' + arrCols[0];
	            } 
	            if (arrCols[2] != ""){
                    if(this.regioninfoparams == ''){
                        this.regioninfoparams = '?';
                    }else{
                        this.regioninfoparams = this.regioninfoparams + '&';
                    }
	                this.regioninfoparams = this.regioninfoparams + 'mk=' + arrCols[2];
	            }
	            if (arrCols[3] != ""){
                    if(this.regioninfoparams == ''){
                        this.regioninfoparams = '?';
                    }else{
                        this.regioninfoparams = this.regioninfoparams + '&';
                    }
	                this.regioninfoparams = this.regioninfoparams + 'md=' + arrCols[3];
       	        }
       	        if(this.regioninfoparams != ''){
                    if (this.container.compare_mode)
                        this.GetAJRegionMatches(); //build region info counts etc.
       	        }else{
                    this.RegionMatchCount = 0;
                    this.DisplayRegionInfo();
       	        }
       	        this.vehicledetailslink.href = this.container.detailpage + "&mk=" + arrCols[2] + "&md=" + arrCols[3] + "&id=" + arrCols[0];

                this.getapricequotelink.href = this.container.getquotepage + "?vehicleid=" + arrCols[0] + "&mk=" + arrCols[2] + "&md=" + arrCols[3] + "&compare=1";
            }
        }
    }

    //**********************************************************************
    //* VEHICLE SELECTOR SUGGESTION LINKS FUNCTIONS                        *
    //**********************************************************************
    VehicleSelector.prototype.GetAJVehicleSuggestions = function(){
       if(this.baseid > 0){//make sure this isn't the first vehicle selector
           var aj_requestor = GetRequestor();
           var currentvehicleselector = this;
           var previousvehicleselector = null;
           var vehicleids = "";
           if (aj_requestor) {
                if(this.container.selections.length > 1){ //more than one vehicle selector being displayed at the moment?
                    //get the vehicle ids from the previous vehicle suggestions trims
                    for(var i=0; i < this.container.selections.length-1; i++){
                        previousvehicleselector = this.container.selections[i];
                        if(previousvehicleselector != null){
                            if(vehicleids != ""){
                                vehicleids += ",";
                            }
                            vehicleids += previousvehicleselector.vehicleid;
                        }
                    }
                }
                if(vehicleids != ""){ //vehicleids found?
                    var url =  this.container.apirooturl + "GeneralAjaxServerPage.aspx?SERVERMETHOD=GetData";
                    url += "&RetrievalType=NewCarsVehicleSuggestions&FilterValue=" + vehicleids;
                    aj_requestor.onreadystatechange = function() { 
                       if (aj_requestor.readyState == 4) { 
                           if (aj_requestor.status == 200) {
                                //set vehicle info layers
                                var responsetext = aj_requestor.responseText;
                                responsetext = responsetext.replace("<GeneralAjaxServerPage>","");
                                if(responsetext != ""){
                                    //call method that will diplay suggestions
                                    currentvehicleselector.GenerateVehicleSuggestions(responsetext);
                                }
                           }
                       } 
                    }
                    aj_requestor.open('GET', url, true); 
                    aj_requestor.send(null); 
                }         
           } 
       }   
    }
    
    VehicleSelector.prototype.GenerateVehicleSuggestions = function(suggestionstext){
        if(this.suggestionslinkscontainer){
            //clear previous links if any
            DisposeAll(this.suggestionslinkscontainer);
            //split ajax reponse text 
            var arrSIRows = suggestionstext.split("~~");
       	    var i = arrSIRows.length-1;
       	    var inc = 0;
       	    var arrSICols = null;
       	    var suggestionlink = null;
       	    if(i > -1){
                do 
                {
                    arrSICols = arrSIRows[inc].split("||");
                    if(arrSICols.length >= 2){
                        suggestionlink = document.createElement("a");
                        suggestionlink.id = "suggestionlink" + arrSICols[0];
                        suggestionlink.className = "suggestionslink";
                        suggestionlink.container = this;
                        suggestionlink.setAttribute("href","javascript:void(0);");
                        suggestionlink.onclick = function(){
                            this.container.GetVehicleInformation(this.id.toUpperCase().replace("SUGGESTIONLINK",""),true);
                        }
                        suggestionlink.appendChild(document.createTextNode(arrSICols[1]));
                        this.suggestionslinkscontainer.appendChild(suggestionlink);
                        this.suggestionslinkscontainer.appendChild(document.createElement("br"));
                    }
                    inc++;
                }
                while (i--);
                this.suggestionscontainer.style.display = "block"; //show suggestions
            }
        }
    }

    VehicleSelector.prototype.LoadFromPreLoaderCache = function(images)
    {
        //remove previous images
        while (this.mainphotocontainer.childNodes[0]){
            this.mainphotocontainer.removeChild(this.mainphotocontainer.childNodes[0]);
        }
        //add new images
        for(var i = 0; i < images.length; i++)
        {
            this.mainphotocontainer.appendChild(images[i]);    
        }
        //set gallery position on screen
        if(this.mainphotocontainer.childNodes.length > 0){
            //set gallery link if in compare mode
            if(this.container.compare_mode){
                this.viewgallerylink.style.display = "block";
            }        
            this.mainphotocontainer.style.display = "block"; //display main photo now that it is loaded
        }
    }
    
    VehicleSelector.prototype.GetAJRegionMatches = function(){
       var vehicleid = this.vehicleid;
       var aj_requestor = GetRequestor();
       var currentvehicleselector = this;
       if (aj_requestor) {
            var url =  this.container.apirooturl + "GeneralAjaxServerPage.aspx?SERVERMETHOD=GetData";
            url += "&RetrievalType=NewCarRegionSearch&FilterValue=" + vehicleid + "&FilterValue1=" + this.container.languageid + "&FilterValue2=" + site_Id + "&FilterValue3=";
            aj_requestor.onreadystatechange = function() { 
               if (aj_requestor.readyState == 4) { 
                   if (aj_requestor.status == 200) {
                        //set vehicle info layers
                        var responsetext = aj_requestor.responseText;
                        responsetext = responsetext.replace("<GeneralAjaxServerPage>","");
	                    if(responsetext != ""){
                            currentvehicleselector.RegionMatchCount = responsetext;
                        }else{
                            currentvehicleselector.RegionMatchCount = 0;
                        }
                        currentvehicleselector.DisplayRegionInfo();
                        aj_requestor = null;
                   }
               } 
            }
            aj_requestor.open('GET', url, true); 
            aj_requestor.send(null);            
       }
	}

    //**********************************************************************
    //* VEHICLE SELECTOR MISC. AJAX FUNCTIONS                              *
    //**********************************************************************
	VehicleSelector.prototype.GetAJPhotos = function(photoscontainer,vehicleid){
       var aj_requestor = GetRequestor();
       if (aj_requestor) {
            var url =  this.container.apirooturl + "GeneralAjaxServerPage.aspx?SERVERMETHOD=GetData";
            url += "&RetrievalType=NewCarsTrimPhotos&FilterValue=" + vehicleid;
            aj_requestor.onreadystatechange = function() { 
               if (aj_requestor.readyState == 4) { 
                   if (aj_requestor.status == 200) { 
                        var responsetext = aj_requestor.responseText;
                        photoscontainer.value = responsetext.replace("<GeneralAjaxServerPage>","");
                        var photos = photoscontainer.value;
                        var arrphotos = photos.split("~");
                        if(arrphotos.length > 0){
                            //hide suggestions
                            photoscontainer.container.suggestionscontainer.style.display = "none";
                            //set main photo
                            var imageloader = new ImagePreLoader(new Array(arrphotos[0]),photoscontainer.container); //preload images
                        }
                        aj_requestor = null;
                   }
               } 
            }
            aj_requestor.open('GET', url, true); 
            aj_requestor.send(null);
        }
	}

	VehicleSelector.prototype.GetAJLists = function(parentlist,list,parentlistvalue1,parentlistvalue2,listdefaultvalue){
       var aj_requestor = GetRequestor();
       if (aj_requestor) {
            var url =  this.container.apirooturl + "DynamicDropDownServerPage.aspx?SERVERMETHOD=GetData";
            switch(list.id){
                case "ddlYears":
                    url += "&KeyColumn=&GlobalFilterValue=&DataTable=NewCarsYearsCategoryList&ValueColumn=YearValue&DisplayColumn=YearDisplay&FilterValue="
                break;
                case "ddlMakes":
                    url += "&KeyColumn=&GlobalFilterValue=&DataTable=NewCarsYearMakesCategoryList&ValueColumn=MakeValue&DisplayColumn=MakeDisplay&FilterValue=0"; //" + parentlistvalue1.replace("All","");
                break;
                case "ddlModels":
                    url += "&KeyColumn=&GlobalFilterValue=&DataTable=NewCarsModelsCategoryList&ValueColumn=ModelValue&DisplayColumn=ModelDisplay&FilterValue=" + parentlistvalue1.replace("All","");
                break;
                case "ddlTrims":
                    url += "&KeyColumn=&GlobalFilterValue=&DataTable=NewCarsTrimsCategoryList&ValueColumn=TrimValue&DisplayColumn=TrimDisplay&FilterValue=" + parentlistvalue1.replace("All","") + "&FilterValue1=" + parentlistvalue2.replace("All","");
                break;
                default:
                break;
            }
            aj_requestor.onreadystatechange = function() { 
               if (aj_requestor.readyState == 4) { 
                   if (aj_requestor.status == 200) { 
                        var responsetext = aj_requestor.responseText;
                        var arrRows = responsetext.replace("<DynamicDropDownServerPageBase>","").split("|");
                        list.disabled = false;                        
                        for(var i=list.options.length-1;i>=1;i--) //remove old options
                        {
                            list.remove(i);
                        }
                        for(var i=0; i < arrRows.length; i++){ //add new options
                            var arrOptionTextValues = arrRows[i].split("~");
                            if(arrOptionTextValues.length == 2){
                                if(arrOptionTextValues[1].toLowerCase() != "all" && arrOptionTextValues[1] != "" && arrOptionTextValues[1].toLowerCase().indexOf("choose") == -1){
                                    list.options[list.options.length] = new Option(arrOptionTextValues[1],arrOptionTextValues[0]);
                                    if(listdefaultvalue != ""){
                                        if(arrOptionTextValues[0] == listdefaultvalue){
                                            list.selectedIndex = (list.options.length-1); //if a match set the index
                                            if (list.container.baseid == 2 && BOOL_FEATURED_AD_DISPLAYED)
                                            {
                                                list.disabled=true;
                                                list.style.backgroundColor='White';
                                                list.style.color='Black';
                                            }
                                            
                                        }
                                    }
                                    if(list.id == "ddlTrims" && list.options.length == 2){ //get the pictures for first trim
                                        //Force click of btnSpecs OR btnSpécifications (3rd button) regardless of language            
                                        //TrackIT#: 16785
                                        if (document.getElementById('buttons').childNodes[2])
                                            document.getElementById('buttons').childNodes[2].onclick();
                                        list.container.GetAJPhotos(list.container.photoscontainer,arrOptionTextValues[0]);
                                    }
                                }
                            }
                        }
                        aj_requestor = null; 
                   }
               } 
            }
            aj_requestor.open('GET', url, true); 
            aj_requestor.send(null);
        }
	}

    //**********************************************************************
    //* GLOBAL FUNCTIONS                                                   *
    //**********************************************************************
    function GetRequestor(){
		//build ajax request object for the current vehicle selector
        var ajax_requestor = false;
        if (window.XMLHttpRequest) { //Mozilla etc..
           ajax_requestor = new XMLHttpRequest(); 
        }else if (window.ActiveXObject) { //IE 
           try { 
               ajax_requestor = new ActiveXObject("Msxml2.XMLHTTP"); 
           } catch (e) { 
               try { 
                   ajax_requestor = new ActiveXObject("Microsoft.XMLHTTP"); 
               } catch (e) {} 
           } 
        }
        return ajax_requestor;		
	}

	function DisposeAll(Node){
        while (Node.childNodes[0]){
            DisposeAll(Node.childNodes[0]);
            Node.removeChild(Node.childNodes[0]);
        }
	}

    function PrintPage(){
        if(vehicleSelections){ //instance exists?
            var vehicleids = "";
            var vehicleid = "";
            for(var i=0; i < vehicleSelections.selections.length; i++){
                if(vehicleSelections.selections[i].ddlTrims){
                   vehicleid = vehicleSelections.selections[i].ddlTrims.options[vehicleSelections.selections[i].ddlTrims.selectedIndex].value;
                   if(vehicleid != ""){
                        if(i > 0){
                            vehicleids += ",";
                        }
                        vehicleids += vehicleid;
                   }
                }
            }
            if(vehicleids != ""){
                window.open(vehicleSelections.apirooturl + "NewVehicles/sidebyside_comparepf.aspx?vehicleid=" + vehicleids + "&cntr=" + vehicleSelections.CurrentStandardItemsContainerID);
            }
        }
    }

	function showHideInfoLayer(standarditemscontainerid)
	{
	    //display appropriate items values layer
	    var i = vehicleSelections.selections.length-1;
	    var vehicleSelection = null;
	    var standarditemsvaluescontainer = null;
	    var standarditemslabelscontainer = null;
	    var j = 0;
	    if(i > -1){
            do 
            {
                j = vehicleSelections.selections[i].itemscontainers.length-1;
                if(j > -1){
                    do
                    {
                        standarditemscontainer = vehicleSelections.selections[i].itemscontainers[j];
                        if(standarditemscontainer){
                            if(standarditemscontainerid.toUpperCase() + VALUES_CONTAINER_NAME == standarditemscontainer.containerid.toUpperCase()){
                                standarditemscontainer.div.style.display = "block";
                            }else{
                                standarditemscontainer.div.style.display = "none";
                            }
                        }
	                }
	                while (j--);
	            }
            }
            while (i--);
        }
        i = vehicleSelections.itemslabelscontainers.length-1;
        if(i > -1){
            do
            {
                standarditemslabelscontainer = vehicleSelections.itemslabelscontainers[i];
                if(standarditemslabelscontainer){
                    if(standarditemscontainerid.toUpperCase() + LABELS_CONTAINER_NAME == standarditemslabelscontainer.containerid.toUpperCase()){
                        standarditemslabelscontainer.div.style.display = "block";
                    }else{
                        standarditemslabelscontainer.div.style.display = "none";
                    }
                }
            }
            while (i--);
        }
        vehicleSelections.CurrentStandardItemsContainerID = standarditemscontainerid;
		vehicleSelections.GenerateAllStandardItems();
	}

