function pageCleanUp()
{
	filterPageForShipping();
	hideUnwantedCategoryFilters();
}


//CATEGORIES FILTER LISTS RELATED
function hideUnwantedCategoryFilters()
{
	hideRefinementPriceList();
	filterNonRelevantSortByOptions();
}


function hideRefinementPriceList()
{
   var body = document.getElementsByTagName("body")[0];
   var spans = body.getElementsByTagName("span");
   var span;
   for (i = 0; i < spans.length; i++)
   {
      span = spans[i];
      if(span.className=="refinement_price_section")
      {
      		span.style.display = "none";
      }
   }
}

function filterNonRelevantSortByOptions()
{
	var sortByList = document.getElementById("SortBy");
	if(sortByList != null)
	{
		
		//sortByList.removeChild(sortByList.options[0]);
		//sortByList.removeChild(sortByList.options[1]);
		sortByList.removeChild(sortByList.options[2]);
		//sortByList.removeChild(sortByList.options[3]);
		sortByList.removeChild(sortByList.options[3]);
		sortByList.removeChild(sortByList.options[3]);
		sortByList.removeChild(sortByList.options[3]);
		sortByList.removeChild(sortByList.options[3]);
		//sortByList.removeChild(sortByList.options[3]);
		
		//sortByList.removeChild(sortByList.options[3]);
		//sortByList.removeChild(sortByList.options[4]);
		//sortByList.removeChild(sortByList.options[6]);
		//sortByList.removeChild(sortByList.options[7]);
		/*
		for (i=0; i < sortByList.options.length; i++ ) 
		{
			//if(sortByList.options[i].getElementsByTagName("span").className=="PageText_L518n")
			//{
			//	sortByList.options[i] = null;
			//}
			sortByList.removeChild(). options[2].
			if(sortByList.options[i].value == "5" || 
				sortByList.options[i].value == "9" || 
				sortByList.options[i].value == "3" ||
				sortByList.options[i].value == "4" ||
				sortByList.options[i].value == "11")
				sortByList.options[i].style.display = "none";//null;
			else if(sortByList.options[i].value == "7")
			{
				sortByList.options[i].getElementsByTagName("span").value="Name";
			}
				
		}
		//sortByList.style.display = "none"
		*/
	}
}


//SHIPPING LISTS RELATED
function filterPageForShipping()
{
	if(isShoppingCartPage())
	{
		filterShoppingCartPage();
	}
	else if(isOnePageCheckoutPagePage())
	{
		filterOnePageCheckoutPage();	
	}
}

function filterOnePageCheckoutPage()
{

	var copyBillingLink = document.getElementById("v65-onepage-CopyBillingToShippingLink");
	copyBillingLink.parentNode.removeChild(copyBillingLink);	
		
	var shipCountryList = document.getElementById("ShipCountry");
	clearSelectBox(shipCountryList);
	addShippingCountries(shipCountryList);
	
	var shipSateList = document.getElementById("ShipState_dropdown");
	clearSelectBox(shipSateList);
	addShippingStates(shipSateList);
}

function filterShoppingCartPage()
{	
	var shipCountryList = document.getElementById("ShipCountry");
	clearSelectBox(shipCountryList);
	addShippingCountries(shipCountryList);
	
	var shipSateList = document.getElementById("ShipState_dropdown");
	clearSelectBox(shipSateList);
	addShippingStates(shipSateList);
}

function clearSelectBox(selectBox)
{
	// Set each option to null thus removing it
	while ( selectBox.options.length ) 
	{
		selectBox.options[0] = null;
	}
}

function addShippingCountries(selectBox)
{
	var optn = document.createElement("OPTION");
	optn.text = "United States";
	optn.value = "United States";
	selectBox.options.add(optn);	
}

function addShippingStates(selectBox)
{
	var validStates = new Array(	
	"Then, Select State","",	
	
	"Arizona","AZ",
	"California","CA",
	"Colorado","CO",
	"Connecticut","CT",
	"Florida","FL",
	"Georgia","GA",
	
	"Idaho","ID",
	"Illinois","IL",
	"Indiana","IN",
	"Iowa","IA",
	"Kansas","KS",
	"Louisiana","LA",
	"Maine","ME",
	"Maryland","MD",
	"Michigan","MI",
	"Minnesota","MN",
	"Missouri","MO",
	"Nebraska","NE",
	"Nevada","NV",
	"New Hampshire","NH",
	"New Jersey","NJ",
	"New Mexico","NM",
	"New York","NY",
	"North Carolina","NC",
	"North Dakota","ND",
	"Ohio","OH",
	"Oregon","OR",
	"Pennsylvania","PA",
	"Rhode Island","RI",
	"South Carolina","SC",
	"Tennessee","TN",
	
	"Virginia","VA",
	"Washington","WA",
	"Washington DC","DC",
	"West Virginia","WV",
	"Wisconsin","WI",
	"Wyoming","WY");

	for(var i=0; i<validStates.length; i= i+2)
	{
		var optn = document.createElement("OPTION");
		optn.text = validStates[i];
		optn.value = validStates[i+1];
		selectBox.options.add(optn);
	}
}


function isShoppingCartPage()
{
	var page = getPageFilename();
	if(page == 'ShoppingCart.asp')
	{
		return true;
	}
}

function isOnePageCheckoutPagePage()
{
	var page = getPageFilename();
	if(page == 'one-page-checkout.asp')
	{
		return true;
	}
}


function getPageFilename()
{
	var url = window.location.pathname;
	var lastSlash = url.lastIndexOf("/");
	var firstQuestionMark = url.indexOf("?");
	if(firstQuestionMark == -1)
	{
		firstQuestionMark = url.length;
	}

	var fileName = url.substring(lastSlash + 1, firstQuestionMark);
	
	//alert(fileName);
	
	return fileName; 
}
