function ProductLinePageHelperv2(SiteID,ProductLineID,KeyManager,GlobalAjaxContextHandler)
{
    this.SiteID         = SiteID;
    this.ProductLineID  = ProductLineID;
    this.KeyManager     = KeyManager;
    this.AjaxRoot       = '/shared/php/ajax';
    this.GlobalAjaxContextHandler = GlobalAjaxContextHandler;
    this.AddToCartEnabled= false;
    this.DefaultValues  = Array();
    
    this.YMMBoxSetYear=function()
    {
        var Year            = $('YMMBoxYear').options[$('YMMBoxYear').selectedIndex].value;
        var Parameters      = "key="+this.KeyManager.GetProductLinePageKey()+"&event=ActionYMMBoxSetYear&SiteID="+this.SiteID+"&YMMBoxYear="+Year+"&ProductLineID="+this.ProductLineID;
        var objAjaxv2       = new Ajaxv2(this.AjaxRoot+"/product_line_page_helper_v2.php", this, this.YMMBoxSetYearCallBack, "POST", Parameters, this.GlobalAjaxContextHandler);
        objAjaxv2.EventData = null;
        objAjaxv2.GetPost(true);
    }
    
    this.YMMBoxSetYearCallBack = function(Success,Response,EventData)
    {
        this.GenericCallBack(Success,Response,EventData);        
    }
    
    this.YMMBoxSetMake=function()
    {
        var Year            = $('YMMBoxYear').options[$('YMMBoxYear').selectedIndex].value;
        var Make            = $('YMMBoxMakeID').options[$('YMMBoxMakeID').selectedIndex].value;        
        var Parameters      = "key="+this.KeyManager.GetProductLinePageKey()+"&event=ActionYMMBoxSetMake&SiteID="+this.SiteID+"&YMMBoxYear="+Year+"&YMMBoxMakeID="+Make+"&ProductLineID="+this.ProductLineID;
        var objAjaxv2       = new Ajaxv2(this.AjaxRoot+"/product_line_page_helper_v2.php", this, this.YMMBoxSetMakeCallBack, "POST", Parameters, this.GlobalAjaxContextHandler);
        objAjaxv2.EventData = null
        objAjaxv2.GetPost(true);
    }
    
    this.YMMBoxSetMakeCallBack = function(Success,Response,EventData)
    {
        this.GenericCallBack(Success,Response,EventData);        
    }
    
    this.YMMBoxSetModel=function()
    {
        var Year            = $('YMMBoxYear').options[$('YMMBoxYear').selectedIndex].value;
        var ModelID         = $('YMMBoxModelID').options[$('YMMBoxModelID').selectedIndex].value;        
        var Parameters      = "key="+this.KeyManager.GetProductLinePageKey()+"&event=ActionYMMBoxSetModel&SiteID="+this.SiteID+"&YMMBoxYear="+Year+"&YMMBoxModelID="+ModelID+"&ProductLineID="+this.ProductLineID;
        var objAjaxv2       = new Ajaxv2(this.AjaxRoot+"/product_line_page_helper_v2.php", this, this.YMMBoxSetModelCallBack, "POST", Parameters, this.GlobalAjaxContextHandler);
        objAjaxv2.EventData = null;
        objAjaxv2.GetPost(true);
    }
    this.YMMBoxSetModelCallBack = function(Success,Response,EventData)
    {
        this.GenericCallBack(Success,Response,EventData);        
    }
    
    this.YMMBoxSetAppNote=function()
    {
        //IE6 hits onblur with our ie width fix and has -1 for the index
        if($('YMMBoxApplicationID').selectedIndex < 0)
            return;
        var Year            = $('YMMBoxYear').options[$('YMMBoxYear').selectedIndex].value;
        var ModelID         = $('YMMBoxModelID').options[$('YMMBoxModelID').selectedIndex].value;
        var ApplicationID   = $('YMMBoxApplicationID').options[$('YMMBoxApplicationID').selectedIndex].value;
        if(ApplicationID=='')
            return;
        var AttributeOption1ID='';
        if($('YMMBoxAttributeOption1ID') != null)
            AttributeOption1ID=$('YMMBoxAttributeOption1ID').options[$('YMMBoxAttributeOption1ID').selectedIndex].value;
        var Parameters      = "key="+this.KeyManager.GetProductLinePageKey()+"&event=ActionYMMBoxSetAppNote&SiteID="+this.SiteID+"&YMMBoxYear="+Year+"&YMMBoxModelID="+ModelID+"&YMMBoxApplicationID="+ApplicationID+"&YMMBoxAttributeOption1ID="+AttributeOption1ID+"&ProductLineID="+this.ProductLineID;
        var objAjaxv2       = new Ajaxv2(this.AjaxRoot+"/product_line_page_helper_v2.php", this, this.YMMBoxFetchAppNoteCallBack, "POST", Parameters, this.GlobalAjaxContextHandler);        
        objAjaxv2.GetPost(true);
    }
    this.YMMBoxFetchAppNoteCallBack = function(Success,Response,EventData)
    {
        this.GenericCallBack(Success,Response,EventData);
    }
    
    this.CheckForSingleApp=function()
    {
        if($('YMMBoxApplicationID').length==2)
        {
            $('YMMBoxApplicationID').selectedIndex=1;
            this.YMMBoxSetAppNote();
        }
    }
    
    this.YMMBoxSetAttribute1=function()
    {
        //IE6 hits onblur with our ie width fix and has -1 for the index
        if($('YMMBoxAttributeOption1ID').selectedIndex < 0)
            return;
            
        var Year            = $('YMMBoxYear').options[$('YMMBoxYear').selectedIndex].value;
        var ModelID         = $('YMMBoxModelID').options[$('YMMBoxModelID').selectedIndex].value;
        var AttributeOptionID = $('YMMBoxAttributeOption1ID').options[$('YMMBoxAttributeOption1ID').selectedIndex].value;        
        var Parameters      = "key="+this.KeyManager.GetProductLinePageKey()+"&event=ActionYMMBoxSetAttributeOption1ID&SiteID="+this.SiteID+"&YMMBoxYear="+Year+"&YMMBoxModelID="+ModelID+"&YMMBoxAttributeOption1ID="+AttributeOptionID+"&ProductLineID="+this.ProductLineID;
        var objAjaxv2       = new Ajaxv2(this.AjaxRoot+"/product_line_page_helper_v2.php", this, this.YMMBoxSetAttributeOption1CallBack, "POST", Parameters, this.GlobalAjaxContextHandler);        
        objAjaxv2.GetPost(true);
    }
    
    this.YMMBoxSetAttributeOption1CallBack=function(Success,Response,EventData)
    {
        this.GenericCallBack(Success,Response,EventData);
    }
    
    this.ResetDropDown=function(ControlID)
    {
        if($(ControlID) != null)
        {
            $(ControlID).selectedIndex=0;
            for(var c=$(ControlID).length;c>0;c--)
            {
                $(ControlID).remove(c);
            }
            //$(ControlID).options[0] = new Option(this.DefaultValues[ControlID],'',true);            
            $(ControlID).disabled=true;
            $(ControlID).className='disabled_control';            
        }
    }
    this.DisableAddToCart=function()
    {
        this.AddToCartEnabled=false;
        if($('add_to_cart_button') != null)
            $('add_to_cart_button').src='/shared/images/buttons/add_to_cart_disabled142x31.gif';
        $('product_application_id').value='';
    }
    
    this.EnableAddToCart=function(ApplicationID,Note)
    {
        this.AddToCartEnabled=true;
         if($('add_to_cart_button') != null)
            $('add_to_cart_button').src='/shared/images/buttons/add_to_cart142x31.gif';
         
         if($('scn') != null)
         {
             if(Note === undefined)
                $('scn').value='';
             else
                $('scn').value=Note;
         }
        $('product_application_id').value=ApplicationID;
    }
    this.AddToCart=function()
    {
        if(this.AddToCartEnabled)            
            $('AddToCartForm').submit();        
        else
            alert('Please select all options for your vehicle to order');
    }
    this.ShowWarning=function(Warning)
    {
        alert(Warning);
    }
    this.ClearFitmentWarning=function()
    {
        if($('fitment_warning') != null)
            $('fitment_warning').style.display='none';
    }
    this.SetDefaultOptionValue=function(ID,Value)
    {
        this.DefaultValues[ID]=Value;
    }
    this.GenericCallBack = function(Success, ResponseObject, EventData)
    {
        if(Success)
        {
            var element;
            var event_array = Array();
            try
            {
                eval("var obj= "+ResponseObject.responseText);
                this.LastResponse=obj;
                if(EventData != null)
                {
                    if(EventData.constructor != Array)
                        event_array.push(EventData);
                    else
                        event_array = EventData;
                        
                    for(var c=0; c<event_array.length; c++)
                    {
                        element = document.getElementById(event_array[c]);
                        if(obj.Response != "")
                            element.innerHTML = obj.Response;
                    }
                }                
                
                if(obj.Javascript != null)            
                    window.eval(obj.Javascript);
            }
            catch(ex)
            {
                alert('Sorry an error has occured '+ex.toString());    
            }                
        }
    }
    
    this.dump=function(arr,level)
    {
        var dumped_text = "";
        if(!level) level = 0;
        
        //The padding given at the beginning of the line.
        var level_padding = "";
        for(var j=0;j<level+1;j++) level_padding += "    ";
        
        if(typeof(arr) == 'object') { //Array/Hashes/Objects 
            for(var item in arr) {
                var value = arr[item];
                
                if(typeof(value) == 'object') { //If it is an array,
                    dumped_text += level_padding + "'" + item + "' ...\n";
                    dumped_text += dump(value,level+1);
                } else {
                    dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
                }
            }
        } else
        { //Stings/Chars/Numbers etc.
            dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
        }
        return dumped_text;
    }
    
    this.COC2SelectApplication = function(OptionCount, ApplicationID)
    {
        var CheckboxID         = "product_application_id"+OptionCount;
        var CheckboxElement    = document.getElementById(CheckboxID);
        
        if(ApplicationID != -1)
        {
            CheckboxElement.disabled    = false;
            CheckboxElement.checked     = true;
            CheckboxElement.value        = ApplicationID;
            // update the pricing for the option for the selected application
            // update the image for the option for the selected application
            this.COC2UpdateOptionInformation(OptionCount, ApplicationID);
        }
        else
        {
            CheckboxElement.disabled    = true;
            CheckboxElement.checked     = false;
            CheckboxElement.value         = -1;
        }
    }
    
    this.COC2UpdateOptionInformation = function(OptionCount, ApplicationID)
    {        
        var Parameters        = "key="+this.KeyManager.GetProductLinePageKey()+"&event=ActionCOC2UpdateOptionInfo&SiteID="+this.SiteID+"&ProductLineID="+this.ProductLineID+"&ProductApplicationID="+ApplicationID+"&OptionCount="+OptionCount;
        var objAjaxv2         = new Ajaxv2(this.AjaxRoot+"/product_line_page_helper_v2.php", this, this.GenericCallBack, "POST", Parameters, this.GlobalAjaxContextHandler);
        objAjaxv2.EventData   = null;
        objAjaxv2.GetPost(true);
    }
    
    this.COC2CheckSelectedApplication = function(OptionCount)
    {
        // is the checkbox checked?
        var CheckboxID         = "product_application_id"+OptionCount;
        var CheckboxElement    = document.getElementById(CheckboxID);
        var IsChecked         = (CheckboxElement.checked === true) ? true : false;
        
        // are there multiple applications (i.e. is there a select)
        var MultipleOptionsID     = "multiple_options"+OptionCount;
        var MultipleOptions        = (document.getElementById(MultipleOptionsID).value == 1) ? true : false;
        
        // get the application element
        var ApplicationElementID     = "application"+OptionCount;
        var ApplicationElement        = document.getElementById(ApplicationElementID);
        
        // if there is a select, see if need to reset default value
        if(MultipleOptions === true)
        {
            if(IsChecked === false)
            {
                var DefaultOptionID                    = "option_default"+OptionCount;
                ApplicationElement.selectedIndex     = DefaultOptionID;
                CheckboxElement.value                = -1;
                CheckboxElement.disabled            = true;
            }
        }
        // otherwise, set the value of the checkbox based on if checked or not
        else
        {
            if(IsChecked === false)
                CheckboxElement.value = -1;
            else
                CheckboxElement.value = ApplicationElement.value;
        }
    }
    
    this.COC2AddToCart = function()
    {
        var SelectedApplicationCount     = 0;
        var OptionCount                 = document.getElementById("application_count").value;
        var OptionNumber                = 0;
        var CheckboxID                    = null;
        var CheckboxElement             = null;
        
        // how many applications have been selected?
        for(var i = 0; i <= OptionCount; i++)
        {
            OptionNumber    = i;
            CheckboxID         = "product_application_id"+OptionNumber;
            CheckboxElement    = document.getElementById(CheckboxID);
            // if the checkbox is undefined, that is because it is disabled and it isn't checked
            if(CheckboxElement != undefined)
            {
                // is the checkbox checked?
                if(CheckboxElement.checked === true)
                    SelectedApplicationCount++;
            }
        }
        
        // if no applications have been selected, do not proceed
        if(SelectedApplicationCount == 0)
        {
            alert("You must select at least one Product that you would like to order.");
            return;
        }
        // otherwise it is okay to proceed
        else
        {
            this.AddToCartEnabled=true;
            this.AddToCart();
        }
    }
    
    this.Popup = function(url)
    {
        var newwin = window.open(url, null, "location=no, menubar=no, status=no, toolbar=no, scrollbars=no");
    }
    
    this.GetProductImageWithSize=function(ProductApplicationSelect,Size)
    {
        var ProductApplicationID = ProductApplicationSelect.options[ProductApplicationSelect.selectedIndex].value;        
        var ElementID         = "selected_product_image";        
        var ajaxv2             = new Ajaxv2();
        var Parameters         = "key="+this.KeyManager.GetProductLinePageKey()+"&event=ActionGetProductImage&SiteID="+this.SiteID+"&Size="+Size+"&ProductLineID="+this.ProductLineID+"&ProductApplicationID="+ProductApplicationID
        var objAjaxv2         = new Ajaxv2(this.AjaxRoot+"/product_line_page_helper_v2.php", this, this.GenericCallBack, "POST", Parameters, GlobalAjaxContextHandler);
        objAjaxv2.EventData    = ElementID;
        objAjaxv2.GetPost(true);
    }
    
    this.CO1AttributeYMMAddToCart=function()
    {
        if(this.CO1AttributeYMMValidate() != true)
            return false;
                
        this.AddToCartEnabled=true;
        this.AddToCart();        
    }
    
    this.CO1AttributeYMMValidate=function()
    {
        
        var objects = $('colored_ordering_container').getElementsByTagName('select');
        for(var c = 0; c < objects.length; c++)
        {
            var obj = objects[c];
            if(obj.selectedIndex >=0 && obj.options[obj.selectedIndex].value != "-1")
                return true;
        }
        alert("Please select the colors for the part(s) you would like to order.");
        return false;
    }
    
    this.COSUSelectApplication = function(OptionCount, ApplicationID)
    {
        var CheckboxID         = "product_application_id"+OptionCount;
        var CheckboxElement    = document.getElementById(CheckboxID);
        
        if(ApplicationID != -1)
        {
            CheckboxElement.disabled    = false;
            CheckboxElement.checked     = true;
            CheckboxElement.value        = ApplicationID;            
            // update the image-price for the option for the selected application
            this.COSUUpdateOptionInformation(OptionCount, ApplicationID);
        }
        else
        {
            CheckboxElement.disabled    = true;
            CheckboxElement.checked     = false;
            CheckboxElement.value         = -1;
        }
    }
    
    this.COSUUpdateOptionInformation = function(OptionCount, ApplicationID)
    {
        var Parameters        = "key="+this.KeyManager.GetProductLinePageKey()+"&event=ActionCOSUUpdateOptionInformation&SiteID="+this.SiteID+"&ProductLineID="+this.ProductLineID+"&ProductApplicationID="+ApplicationID+"&OptionCount="+OptionCount;
        var objAjaxv2         = new Ajaxv2(this.AjaxRoot+"/product_line_page_helper_v2.php", this, this.GenericCallBack, "POST", Parameters, this.GlobalAjaxContextHandler);
        objAjaxv2.EventData   = null;
        objAjaxv2.GetPost(true);
    }
    
    this.COSUCheckSelectedApplication = function(OptionCount)
    {
        // is the checkbox checked?
        var CheckboxID         = "product_application_id"+OptionCount;
        var CheckboxElement    = document.getElementById(CheckboxID);
        var IsChecked         = (CheckboxElement.checked === true) ? true : false;
        
        // are there multiple applications (i.e. is there a select)
        var MultipleOptionsID     = "multiple_options"+OptionCount;
        var MultipleOptions        = (document.getElementById(MultipleOptionsID).value == 1) ? true : false;
        
        // get the application element
        var ApplicationElementID     = "application"+OptionCount;
        var ApplicationElement        = document.getElementById(ApplicationElementID);
        
        // if there is a select, see if need to reset default value
        if(MultipleOptions === true)
        {
            if(IsChecked === false)
            {
                var DefaultOptionID                    = "option_default"+OptionCount;
                ApplicationElement.selectedIndex     = DefaultOptionID;
                CheckboxElement.value                = -1;
                CheckboxElement.disabled            = true;
            }
        }
        // otherwise, set the value of the checkbox based on if checked or not
        else
        {
            if(IsChecked === false)
                CheckboxElement.value = -1;
            else
                CheckboxElement.value = ApplicationElement.value;
        }
    }
    
    this.COSUAddToCart = function()
    {
        var SelectedApplicationCount     = 0;
        var OptionCount                 = document.getElementById("application_count").value;
        var OptionNumber                = 0;
        var CheckboxID                    = null;
        var CheckboxElement             = null;
        
        // how many applications have been selected?
        for(var i = 0; i <= OptionCount; i++)
        {
            OptionNumber    = i;
            CheckboxID         = "product_application_id"+OptionNumber;
            CheckboxElement    = document.getElementById(CheckboxID);
            // if the checkbox is undefined, that is because it is disabled and it isn't checked
            if(CheckboxElement != undefined)
            {
                // is the checkbox checked?
                if(CheckboxElement.checked === true)
                    SelectedApplicationCount++;
            }
        }
        
        // if no applications have been selected, do not proceed
        if(SelectedApplicationCount == 0)
        {
            alert("You must select at least one Product that you would like to order.");
            return;
        }
        // otherwise it is okay to proceed
        else
        {
            this.AddToCartEnabled=true;
            this.AddToCart();
        }
    }
    
    this.IOIAddToCart=function(ApplicationID,Note)
    {
        this.EnableAddToCart(ApplicationID,Note);
        this.AddToCart();
    }
    this.BackgroundAddToCart=function(ApplicationID,ResultContainerID)
    {
        var Parameters        = "key="+this.KeyManager.GetProductLinePageKey()+"&event=ActionAddToShoppingCart&SiteID="+this.SiteID+"&ProductLineID="+this.ProductLineID+"&ProductApplicationID="+ApplicationID;
        var objAjaxv2         = new Ajaxv2(this.AjaxRoot+"/product_line_page_helper_v2.php", this, this.GenericCallBack, "POST", Parameters, this.GlobalAjaxContextHandler);
        objAjaxv2.EventData   = ResultContainerID;
        objAjaxv2.GetPost(true);
    }
}