/*-----------------STORE JS CONFIG--------------------------
#
# Store-wide Javascript configuration variables
# Use these variables to set configuration for different
# scripts that run store wide. 
#
--------------------------------------------------------------------*/

/*------------------------------------------------------------------
#
#                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=new Array();

Dealer_Payment_Methods=new Array('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=new Array(775,776,777,778,500);
// 775=All International Flat Rate
// 776=Australia NZ Flat Rate
// 777=US Flat Rate
// 778=Canada Flat Rate

Dealer_Shipping_Preference_IDs=new Array(108,109,110,111,112,113,214,500);
// 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
// 214 Express Mail International

//ID number of the category used to determine whether someone is a dealer or not.
var 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.
var Current_Product_Accessories_Title="Accessories for this product...";


/*------------------------------------------------------------------
#                           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)
{
        try
        {
                if(Which_Prefs()=="dealer")//as in to remove dealer stuff (customer is retail)
                {
                        document.getElementById("content_area").innerHTML=document.getElementById("content_area").innerHTML.replace(/Retail Price:/g,type);
                }
        }
        catch(e)
        {
        }
}

//function to show any dealer info
function Show_Hidden_Info()
{
        if(Which_Prefs()=='retail') //as in to remove retail stuff (customer is dealer)
        {
                 var All_Dealer_Elements=document.getElementsByName('Dealer_Only_Information');
                 for(i=0;i<All_Dealer_Elements.length;i++)
                 {
                         All_Dealer_Elements[i].style.display='block';
                 }
        }
        else if(Which_Prefs()=='dealer') //as in to remove dealer stuff (customer is retail)
        {
                 var All_Retail_Elements=document.getElementsByName('Retail_Only_Information');
                 for(i=0;i<All_Retail_Elements.length;i++)
                 {
                         All_Retail_Elements[i].style.display='block';
                 }
       }
}
//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 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);
                }
        }
}