/*-----------------STORE JS CONFIG--------------------------
#
# Store-wide Javascript configuration variables
# Use these variables to set configuration for different
# scripts that run store wide. 
#
--------------------------------------------------------------------*/
//This is just variable declarations.  Leave this alone:
var Retail_Payment_Methods, Dealer_Payment_Methods, Retail_Customer_Shipping_Preference_IDs, 
Dealer_Shipping_Preference_IDs, Dealer_Only_Category_ID, Current_Product_Accessories_Title, Slide_Down_Contact_Us_Options;
/*------------------------------------------------------------------
#
#                Payment Method removal
#
# Payment methods for retail or dealer types
# ***IMPORTANT: ONLY ENTER the ones that
# are to be removed if customer type does not
# meet type specified.***
#
# In other words, if both types use the same method
# do not enter that method.  Enter the ones that each
# uses exclusively.  If only Dealers have "Purchase Order"
# then enter that in to the Dealer_Payment_Methods array.
# 
# Enter them exactly as the name appears:
#
--------------------------------------------------------------------*/
Retail_Payment_Methods = [];

Dealer_Payment_Methods = ['Purchase Order Number', 'COD'];

/*------------------------------------------------------------------
#
#                Shipping Preference Removal
#
# Shipping preferences for retail or dealer customer types:
# Enter the ID's of the preferences that will be kept for each type.
# The ID goes into the Array(), separated by commas.
# Be sure to describe each ID with a name in the comment
# under the array, using "//"
#
# You can find the shipping preference ID on the
# shipping preferences table where you created
# the preferences:
# http://www.allparts.com/admin/tableviewer.asp?table=shippingmethods
#
# ***IMPORTANT: ONLY ENTER the ones that
# are to be removed if customer type does not
# meet type specified.***
#
# In other words, if both types use the same method
# do not enter that method.  Enter the ones that each
# uses exclusively.  If only Dealers have preference "109"
# then enter that in to the Dealer_Shipping_Preference_IDs.
#
--------------------------------------------------------------------*/

Retail_Customer_Shipping_Preference_IDs = [775, 776, 777, 778];
// 775=$18.50 Fixed International
// 776=$24.50 Fixed International
// 777=$7 Fixed Ground
// 778=$13.50 Fixed Ground

Dealer_Shipping_Preference_IDs = [108, 109, 110, 111, 112, 113, 205];
// 101 Next Day Air, Early AM
// 102 Next Day Air
// 104 Next Day Air Saver
// 105 2 Day Air AM
// 106 2 Day Air
// 107 3 Day
// 108 Ground
// 109 UPS Standard - NOT IN USE
// 110 International Next Day AM - NOT IN USE
// 111 International Next Day Early AM - NOT IN USE
// 112 UPS Worldwide Expedited
// 113 UPS Worldwide Saver
// 205 USPS Priority Mail
// 214 Express Mail International

//ID number of the category used to determine whether someone is a dealer or not.
Dealer_Only_Category_ID = "270";

//Whatever the title for the accessories related to products is, list it here, so that this
//script can automatically change the titles for specified products.  By default, it is
//"Accessories for this product...".  If it is changed across all products, you'll need to
//change it here.
Current_Product_Accessories_Title = "Accessories for this product...";

/*------------------------------------------------------------------
#
# Select box options for Contact Us page:
# Set the desired text to be displayed to the corresponding select box options
# For page http://www.allparts.com/Articles.asp?ID=135
# Enclose each in quotes separated by a comma, in the order that they appear
# in the select box on that page.  If one does not have a corresponding text,
# use a blank string like this "".  Break the line AFTER THE COMMA.
# If you need quotation marks inside the string, put a \ in front of them 
# You can also use HTML, but just remember to \ the double quotes and \n\ any line breaks.
#
--------------------------------------------------------------------*/


Slide_Down_Contact_Us_Options = [
        "Please include the product code or a link to the part you are inquiring about.",
        "Please include as much information as possible, including part numbers and/or links, about third party products. ",
        "Please include your web order number, invoice number, and/or the date of your purchase for the fastest response.",
        "This option is for reporting website errors and erroneous information.  If you have a question about a product, please select the appropriate option.",
        "To best serve our customers, questions regarding products and orders are given the highest priority.",        
];


/*------------------------------------------------------------------
#
# Highslide Photo Gallery Pop-up overlay for images.  Set to true to enable or false
# to disable.
#
--------------------------------------------------------------------*/


var Enable_Photo_Gallery_For_Product_Photos = true;


/*------------------------------------------------------------------
#                           Functions
#
# Remove Shipping Preferences for Volusion sites depending on the customer type
# Requires another script with some method of determining which kind of customer is on the site.
# One method is to give dealers Allow_Access_To_Private_Sections in the Special Privileges section
# of the Customer's profile page in /Admin, and then create a Private Section Only category that
# only one kind of customer will see.  Then use javascript to determine if that category is visible
# in the Navigation menu.
#
--------------------------------------------------------------------*/
function removeShippingPref(type)
{
	var ShipMethodList=document.getElementsByName('ShippingSpeedChoice');
        if(ShipMethodList.length==0) ShipMethodList=document.getElementsByName('ShippingSpeedChoice1');
        var PrefsToBeRemoved=new Array();
	if(ShipMethodList.length>0)
	{
		if(type=='retail')
		{
			for(x=0;x<ShipMethodList[0].getElementsByTagName('option').length;x++)
			{
				for(i=0;i<Retail_Customer_Shipping_Preference_IDs.length;i++)
				{
					if(ShipMethodList[0].getElementsByTagName('option')[x].value==Retail_Customer_Shipping_Preference_IDs[i].toString())
					{
						PrefsToBeRemoved[PrefsToBeRemoved.length]=ShipMethodList[0].getElementsByTagName('option')[x];
                                                
					}
				}
			}
		}
		else if(type=='dealer')
		{
			for(x=0;x<ShipMethodList[0].getElementsByTagName('option').length;x++)
			{
				for(i=0;i<Dealer_Shipping_Preference_IDs.length;i++)
				{
//alert(Dealer_Shipping_Preference_IDs[i]);
					if(ShipMethodList[0].getElementsByTagName('option')[x].value==Dealer_Shipping_Preference_IDs[i].toString())
					{
						PrefsToBeRemoved[PrefsToBeRemoved.length]=ShipMethodList[0].getElementsByTagName('option')[x];
					}
				}
			}
		}
                for(i=0;i<PrefsToBeRemoved.length;i++)
                {
                        ShipMethodList[0].removeChild(PrefsToBeRemoved[i]);
                }
        }
}

//Function to remove payment methods
function removePaymentMethods(type)
{
	var PaymentMethodList=document.getElementsByName('PaymentMethodType');
        var MethodsToBeRemoved=new Array();
	if(PaymentMethodList.length>0)
	{
		if(type=='retail')
		{
			for(x=0;x<PaymentMethodList[0].getElementsByTagName('option').length;x++)
			{
				for(i=0;i<Retail_Payment_Methods.length;i++)
				{
					if(PaymentMethodList[0].getElementsByTagName('option')[x].value==Retail_Payment_Methods[i].toString())
					{
						MethodsToBeRemoved[MethodsToBeRemoved.length]=PaymentMethodList[0].getElementsByTagName('option')[x];
                                                
					}
				}
			}
		}
		else if(type=='dealer')
		{
                        for(x=0;x<PaymentMethodList[0].getElementsByTagName('option').length;x++)
			{
				for(i=0;i<Dealer_Payment_Methods.length;i++)
				{
					if(PaymentMethodList[0].getElementsByTagName('option')[x].value==Dealer_Payment_Methods[i].toString())
					{
						MethodsToBeRemoved[MethodsToBeRemoved.length]=PaymentMethodList[0].getElementsByTagName('option')[x];
					}
				}
			}
		}
                for(i=0;i<MethodsToBeRemoved.length;i++)
                {
                        PaymentMethodList[0].removeChild(MethodsToBeRemoved[i]);
                }
        }
}

//To determine whether customer is a dealer or retail;
//Category to search for which determines type:
var Category_To_Find='-s/'+Dealer_Only_Category_ID+'.htm';
function Which_Prefs()
{
        try
        {
                prefs_to_remove=document.getElementById('display_menu_7').innerHTML.toLowerCase().indexOf(Category_To_Find.toLowerCase())>-1?'retail':'dealer';
                return prefs_to_remove;
         }
         catch(e)
         {
                  return false;
         }
}

//Price Name test changer
function changePriceName(type) {
        if (Which_Prefs()=="dealer") {//as in to remove dealer stuff (customer is retail)
                $("#content_area").html(($("#content_area").html()).replace(/Retail Price\:/g,type));
        }
}

//function to show any dealer info
function Show_Hidden_Info() {
        if (Which_Prefs()=='retail') {
                 $('.Dealer_Only_Information').show();
        }
        else if (Which_Prefs()=='dealer') {
                 $('.Retail_Only_Information').show();
       }
}

//Function to make URL variables easy to access
//Access them just like in PHP with $_GET['varname']
function getUrlVars() {
        var vars = [], hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        for(var i = 0; i < hashes.length; i++)
        {
                hash = hashes[i].split('=');
                vars.push(hash[0]);
                vars[hash[0]] = hash[1];
        }
        return vars;
}
var $_GET=getUrlVars();
//function to set customer type on the invoice
function setCustomerTypeField(type) {
        var Customer_Type_Field=document.getElementsByName('Orders.Custom_Field_CustomerType');
        if(Customer_Type_Field.length>0)
        {
                Customer_Type_Field[0].value=type=='retail'?'DEALER':'RETAIL';
                Customer_Type_Field[0].style.display='none';
                var Customer_Type_Display=document.createElement('span');
                var CTD_text=document.createTextNode(Customer_Type_Field[0].value);
                Customer_Type_Display.appendChild(CTD_text);
                Customer_Type_Display.style.color='#333';
                Customer_Type_Display.style.fontWeight='bold';
                Customer_Type_Field[0].parentNode.insertBefore(Customer_Type_Display,Customer_Type_Field[0]);
        }
}
//function for working with empty custom fields
function setCustomField() {
        $(arguments).each(function () {
            cust_field_obj = $("input[name*='" + this + "']");
            cust_field_obj.hide();
            cust_field_obj.parent().prev().empty();
        });
}

//function to change selective Accessories title
function changeAccessoriesName() {
        var accessories_names=document.getElementsByName('Accessories_Name');
        if(accessories_names.length>0)
        {
                var all_fonts_on_page=document.getElementById('content_area').getElementsByTagName('font');
                for(i=0;i<all_fonts_on_page.length;i++)
                {
                        if(all_fonts_on_page[i].innerHTML.indexOf('Accessories for this product...')>-1) all_fonts_on_page[i].innerHTML=all_fonts_on_page[i].innerHTML.replace(Current_Product_Accessories_Title,accessories_names[0].value);
                }
        }
}
//Function for making text appear under subject selection on Contact Us page
function slideText() {
        $('#slideText').slideUp('fast', function() {
                if ($('#email_Subject')[0].selectedIndex > 0 && Slide_Down_Contact_Us_Options[$('#email_Subject')[0].selectedIndex - 1] != "") {
                        $('#slideText').html(Slide_Down_Contact_Us_Options[$('#email_Subject')[0].selectedIndex - 1]);
                        $('#slideText').slideDown('fast');
                }
        });
}

//These are some jQuery calls
$(document).ready(function() {
    var jqzOptions = {
                zoomWidth: 200,
                zoomHeight: 200,
                xOffset: 20,
                title: true,
                lens:false

     };

    //Fill in custom field names which are to be hidden here.  Separate by commas and keep in quotation marks.
    setCustomField('Customers.Custom_Field_companyname');

    //Contact form initializer
    $('#email_Subject').change(slideText);

    
    //jQzoom feature to replace vZoom
    //$('#product_photo_zoom_url').jqzoom(jqzOptions);
});
//Disables soft add to cart pop up
$(document).ready(function() {
    $('#head_cart_link')[0].onmouseover=function() {
        return false;
    };
});