function getElement(name) {
 if (document.getElementById) {
  this.obj = document.getElementById(name);
  if ( this.obj ) { this.style = document.getElementById(name).style; }
 } else if (document.all) {
  this.obj = document.all[name];
  if ( this.obj ) { this.style = document.all[name].style; }
 } else if (document.layers) {
  this.obj = document.layers[name];
  if ( this.obj ) { this.style = document.layers[name]; }
 }
}
function getElementsByClassName(Element, TagName, ClassNames) {
 var Elements = (TagName == "*" && document.all)? document.all : Element.getElementsByTagName(TagName);
 var ReturnElements = new Array();
 var RegExpClassNames = new Array();
 if(typeof(ClassNames) == "object"){
  for(var x = 0; x < ClassNames.length; x++){
   RegExpClassNames.push(new RegExp("(^|\\s)" + ClassNames[x].replace(/\-/g, "\\-") + "(\\s|$)"));
  }
 } else{
  RegExpClassNames.push(new RegExp("(^|\\s)" + ClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
 }
 var CurrentElement = false;
 var MatchesAll = false;
 for(var x = 0; x < Elements.length; x++){
  CurrentElement = Elements[x];
  MatchesAll = true;
  for(var y = 0; y < RegExpClassNames.length; y++){
   if(!RegExpClassNames[y].test(CurrentElement.className)){
    MatchesAll = false;
    break;
   }
  }
  if(MatchesAll){
   ReturnElements.push(CurrentElement);
  }
 }
 return ReturnElements;
}
function getBrowserIsSafari() {
 if (navigator.userAgent.indexOf("Safari") != -1) {
  return true;
 } else {
  return false;
 }
}
function getBrowserIsIE() {
 if (navigator.appVersion.indexOf("MSIE") != -1) {
  return true;
 } else {
  return false;
 }
}
function readCookie(name) {
 var nameEQ = name + "=";
 var ca = document.cookie.split(";");
 for(var i=0;i < ca.length;i++) {
  var c = ca[i];
  while (c.charAt(0)==" ") {
   c = c.substring(1,c.length);
  }
  if (c.indexOf(nameEQ) == 0) {
   return c.substring(nameEQ.length,c.length);
  }
 }
 return "undefined";
}

var category_theme_data = new Object();
if (window.location.href.toString().indexOf("/wholesale") != -1) {
 category_theme_data.categories = new Array("3ft-Solid-Latex", "5inch-Solid-Latex", "6inch-Solid-Latex", "9inch-Solid-Latex", "11inch-Solid-Latex", "16inch-18inch-24inch-Lat", "Accessories-Baloon", "Decorative-Mylar", "E.p.-Balloons", "Latex-And-Mylars", "Licensed-Latex", "Licensed-Mylar", "Seasonal-Baloon", "Specialty-Latex", "Theme-Latex", "Theme-Mylar");
 category_theme_data.A3ft_DASH_Solid_DASH_Latex = new Array("Assorted-1301");
 category_theme_data.A5inch_DASH_Solid_DASH_Latex = new Array("Assorted-Colors-0313", "Fashion-Color-0305", "Jewel-Color-0303", "Metallic-Color-0307", "Pastel-Pearl-Color-0311", "Radiant-Pearl-Color-0309", "Standard-Color-0301");
 category_theme_data.A6inch_DASH_Solid_DASH_Latex = new Array("Assortment-0501");
 category_theme_data.A9inch_DASH_Solid_DASH_Latex = new Array("Assorted-Colors-0713");
 category_theme_data.A11inch_DASH_Solid_DASH_Latex = new Array("Assorted-Color-0917", "Fashion-Color-0905", "Jewel-Color-0903", "Metallic-Color-0907", "Neon-Color-0915", "Pastel-Pearl-Color-0913", "Radiant-Pearl-Color-0911", "Standard-Color-0901", "Super-Agate-Col-0909");
 category_theme_data.A16inch_DASH_18inch_DASH_24inch_DASH_Lat = new Array("Assorted-Color-1115", "Fashion-Color-1105", "Geo-Shape-1113", "Jewel-Color-1103", "Metallic-Color-1107", "Pastel-Color-1111", "Standard-Color-1101");
 category_theme_data.AAccessories_DASH_Baloon = new Array("Celophane-2802", "Cups-Net-Stick-2812", "Inflators-2810", "Ribbon-2806", "Sculpting-Tools-2814", "Support-And-Education-2804", "Weights-2808");
 category_theme_data.ADecorative_DASH_Mylar = new Array("Circles-Mylar-2406", "Hearts-Mylar-2404", "Stars-Mylar-2402", "Wanderfuls-2410");
 category_theme_data.AE_DOT_p_DOT__DASH_Balloons = new Array("Themes-2903");
 category_theme_data.ALatex_DASH_And_DASH_Mylars = new Array("Betallic-0201");
 category_theme_data.ALicensed_DASH_Latex = new Array("Characters-1501");
 category_theme_data.ALicensed_DASH_Mylar = new Array("Character-Mylar-2002");
 category_theme_data.ASeasonal_DASH_Baloon = new Array("Canada-Balloon-2606", "Easter-Balloon-2610", "Halloween-Balloon-2614", "N.y.-Balloon-2612", "St.-Patricks-Balloon-2604", "Valentines-Balloon-2608", "X-Mas-Balloon-2602");
 category_theme_data.ASpecialty_DASH_Latex = new Array("160-Q-Latex-0101", "260-Q-Latex-0103", "321-Q-Latex-0105", "350-Q-Latex-0107", "646-Q-Latex-0109", "Yo-Yo-Balloons-0113");
 category_theme_data.ATheme_DASH_Latex = new Array("Baby-Latex-1721", "Birthday-Latex-1719", "Casino-Latex-1703", "Decorated-Latex-1717", "Fiesta-Latex-1709", "Get-Well-Latex-1725", "Graduation-1705", "Hollywood-Latex-1701", "Love-Latex-1723", "Music-Latex-1715", "Numbered-Latex-1713", "Sports-Latex-1711", "Tropical-Latex-1707");
 category_theme_data.ATheme_DASH_Mylar = new Array("Airers-Insiders-2220", "Animals-Mylar-2232", "Anniversary-Mylar-2206", "Baby-Mylar-2204", "Birthday-Mylar-2202", "Casino-Mylar-2242", "Decorative-Balloons-2240", "Drinks-Mylar-2236", "Family-Mylar-2216", "Fiesta-Mylar-2224", "Flowers-Mylar-2238", "Flying-Mylar-2234", "Get-Well-2246", "Grad-Mylar-2248", "Love-Mylar-2210", "Mardigras-Mylar-2222", "Music-Mylar-2230", "Numbered-Mylar-2212", "Red-Hat-Mylar-2218", "Sentiment-Mylar-2214", "Sing-Mylar-2244", "Sports-Mylar-2228", "Summer-Mylar-2226", "Wedding-Mylar-2208");
} else {
 category_theme_data.categories = new Array("Carnival", "Celebration", "E.p.-Balloons", "Firework-Glow","Miscellaneous", "Paper-Products", "Seasonal", "Tableware", "Themes");
 category_theme_data.ACelebration = new Array("Birthday-7001", "Confetti-7007", "Float-Fringe-7011", "Pinatas-7003", "Retirement-7013", "Streamers-7009", "Wedding-Anniversary-7005");
 category_theme_data.ACarnival = new Array("Accessories-6005", "Game-Rentals-6009", "Hats-6007", "Plush-6003", "Toys-6001");
 category_theme_data.AE_DOT_p_DOT__DASH_Balloons = new Array("Everyday-Baloon-2901");
 category_theme_data.AFirework_DASH_glow = new Array("Confetti-Cannon-9005", "Fireworks-9001", "Glow-Products-9007", "Sparklers-9003");
 category_theme_data.APaper_DASH_Products = new Array("Coat-Check-8009", "Double-Rolls-8003", "Drums-And-Money-8011", "Prize-Coupons-8007", "Single-Rolls-8005", "Stationary-8013", "Wristbands-8001");
 category_theme_data.ASeasonal = new Array("Canada-Day-4009", "Easter-4005", "Family-4007", "Halloween-4011", "New-Years-4017", "Octoberfest-4019", "St.-Patricks-4003", "Thanks-Giving-4013", "Valentines-4001", "X-Mas-4015");
 category_theme_data.ATableware = new Array("Accessories-3041", "Black-3027", "Brown-3037", "Burgundy-3013", "Clear-3039", "Festive-Green-3025", "Forest-Green-3023", "Gold-3033", "Ivory-3003", "Lavender-3035", "Light-Blue-3019", "Magenta-3011", "Marine-Blue-3021", "Mint-3043", "Navy-Blue-3017", "Orange-3029", "Pink-3009", "Purple-3015", "Red-3007", "Silver-3031", "Yellow-3005", "White-3001");
 category_theme_data.AThemes = new Array("Bachelorette-5007", "Casino-Bingo-5019", "Chinese-5025", "Countries-5027", "Fiesta-5013", "Hollywood-5023", "Luau-5001", "Mardi-Gras-5021", "Music-5015", "Pirate-5003", "School-Grad-5017", "Sports-5009", "Summer-5005", "Western-5011");
}
function setupSearch() {
 if (readCookie("wholesale") == "yes") {
  var banner = new getElement("banner");
  banner.style.backgroundImage = "url(/shop/media/skin/pps_banner_search.jpg)";
  var loginbox = new getElement("loginbox");
  loginbox.obj.className = "search";
  loginbox.obj.innerHTML = "<form action='/cgi-bin/sc/productsearch.cgi?storeid=*26b5dfb114c0c554f3ab0e317bb6e085194ccd4ed6' method='post'><input name='search_field' size='17' class='searchBox' type='text'><input name='storeid' value='*26b5dfb114c0c554f3ab0e317bb6e085194ccd4ed6' type='hidden'><input type='image' class='searchButton' value='Search' src='/shop/media/skin/search.gif' alt='Search' width='70' height='25' border='0' /></form><br />";
 }
}
function removeShippingOptions() {
 if (window.location.href.toString().indexOf("/cgi-bin/sc/order.cgi") != -1) {
  var contentbox = new getElement("contentbox");
  var shippingPrices = getElementsByClassName(contentbox.obj, "TD", "taxnship");
  for (var x = 0; x < shippingPrices.length; x++) {
   if (shippingPrices[x].innerHTML.toString().indexOf("Can$") != -1) {
    shippingPrices[x].style.display = "none";
   }
  }
 }
}
function setupCategories() {
 var category = new getElement("category");
 for (var x = 0; x < category_theme_data.categories.length; x++) {
  var NEWOPTION = document.createElement('OPTION');
  var OPTIONVALUE = document.createAttribute("value");
  NEWOPTION.innerHTML = category_theme_data.categories[x];
  var NEWVALUE = "A" + category_theme_data.categories[x].replace(/-/g, '_DASH_').replace(/\./g, '_DOT_');
  if (getBrowserIsSafari()) {
   OPTIONVALUE.nodeValue = NEWVALUE;
  } else {
   OPTIONVALUE.value = NEWVALUE;
  }
  NEWOPTION.setAttributeNode(OPTIONVALUE);
  category.obj.appendChild(NEWOPTION);
 }
 preloadCategoryAndSubCategory();
}
function preloadCategoryAndSubCategory() {
 var category = new getElement("category");
 var theme = new getElement("theme");
 var URL_DATA = window.location.href.split('/');
 var URL_LENGTH = URL_DATA.length;

 if (window.location.href.toString().indexOf("/wholesale") != -1) {
  var WHOLESALE = 1;
 } else {
  var WHOLESALE = 0;
 }

 if (URL_LENGTH - WHOLESALE == 6 || URL_LENGTH - WHOLESALE == 7) {
  var testing = URL_DATA.pop();
  if (URL_LENGTH - WHOLESALE == 7) {
   var SUB_CATEGORY = URL_DATA.pop();
  }

  var CATEGORY = URL_DATA.pop();
  CATEGORY = "A" + CATEGORY.replace(/-/g, '_DASH_').replace(/\./g, '_DOT_');

  for (var x = 0; x < category.obj.options.length; x++) {
   if (category.obj.options[x].value == CATEGORY) {
    if (getBrowserIsIE()) {
     setTimeout(new Function("preselectCategory(" + x + ", '" + SUB_CATEGORY + "', " + (URL_LENGTH - WHOLESALE == 7) + ")"), 50);
    } else {
     preselectCategory(x, SUB_CATEGORY, (URL_LENGTH - WHOLESALE == 7));
    }
    break;
   }
  }
 }
}

// Need this because IE 6 blows up if you do this too quickly
function preselectCategory(categoryNum, SUB_CATEGORY, doFindTheTheme) {
 var category = new getElement("category");
 category.obj.options[categoryNum].selected = true;
 selectTheme();
 if (doFindTheTheme) {
  if (getBrowserIsIE()) {
   setTimeout(new Function("findTheTheme('" + SUB_CATEGORY + "')"), 50);
  } else {
   findTheTheme(SUB_CATEGORY);
  }
 }
}
// Need this because IE 6 blows up if you do this too quickly
function findTheTheme(SUB_CATEGORY) {
 var theme = new getElement("theme");
 for (var x = 0; x < theme.obj.options.length; x++) {
  if (theme.obj.options[x].value == SUB_CATEGORY) {
   themeNum = x;
   break;
  }
 }
 if (getBrowserIsIE()) {
  setTimeout(new Function("preselectTheme(" + themeNum + ")"), 50);
 } else {
  preselectTheme(themeNum);
 }
}
// Need this because IE 6 blows up if you do this too quickly
function preselectTheme(themeNum) {
 var theme = new getElement("theme");
 theme.obj.options[themeNum].selected = true;
}

function selectTheme() {
 var category = new getElement("category");
 var theme = new getElement("theme");

 // Clear Theme Drop Down
 while (theme.obj.childNodes.length > 0) {
  theme.obj.removeChild(theme.obj.firstChild);
 }

 if (category.obj.options[category.obj.selectedIndex].value) {
  theme.obj.disabled = false;
  var theme_data = eval("category_theme_data." + category.obj.options[category.obj.selectedIndex].value);

  // Add the default Option
  var NEWOPTION = document.createElement('OPTION');
  var VALUE = document.createAttribute("value");
  NEWOPTION.innerHTML = "Select Theme";
  VALUE.value = "";
  NEWOPTION.setAttributeNode(VALUE);
  theme.obj.appendChild(NEWOPTION);

  // Add new Themes into Drop Down
  for (var x = 0; x < theme_data.length; x++) {
   var NEWOPTION = document.createElement('OPTION');
   var OPTIONVALUE = document.createAttribute("value");
   var THEME_DISPLAY = theme_data[x].split('-');
   // Remove the numbers as we don't want to display those
   THEME_DISPLAY.pop();
   NEWOPTION.innerHTML = THEME_DISPLAY.join('-');
   if (getBrowserIsSafari()) {
    OPTIONVALUE.nodeValue = theme_data[x];
   } else {
    OPTIONVALUE.value = theme_data[x];
   }
   NEWOPTION.setAttributeNode(OPTIONVALUE);
   theme.obj.appendChild(NEWOPTION);
  }
 } else {
  theme.obj.disabled = true;

  // Add the default Option
  var NEWOPTION = document.createElement('OPTION');
  var VALUE = document.createAttribute("value");
  NEWOPTION.innerHTML = "Select Category";
  VALUE.value = "";
  NEWOPTION.setAttributeNode(VALUE);
  theme.obj.appendChild(NEWOPTION);
 }
}
function gotoTheme() {
 var category = new getElement("category");
 var theme = new getElement("theme");
 if (window.location.href.toString().indexOf("/wholesale") != -1) {
  var shopUrl = "/shop/wholesale/"
 } else {
  var shopUrl = "/shop/"
 }
 window.location.href = shopUrl + category.obj.options[category.obj.selectedIndex].value.replace(/_DASH_/g, '-').replace(/_DOT_/g, '.').slice(1) + "/" + theme.obj.options[theme.obj.selectedIndex].value;
}
if (window.addEventListener) {
 window.addEventListener('load', setupSearch, false);
 window.addEventListener('load', removeShippingOptions, false);
 window.addEventListener('load', setupCategories, false);
} else if (window.attachEvent) {
 window.attachEvent("onload", setupSearch);
 window.attachEvent("onload", removeShippingOptions);
 window.attachEvent("onload", setupCategories);
}
