// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

// Enables drop down for IE
startList = function(){
  if (document.all && document.getElementById){
    navRoot = document.getElementById("store_menu");
    for (i=0; i<navRoot.childNodes.length; i++){
      node = navRoot.childNodes[i];
      if (node.nodeName=="LI"){
        node.onmouseover=function(){
          this.className+=" over";
        }
        node.onmouseout=function(){
          this.className=this.className.replace(" over", "");
        }
      }
    }
  }
}

startLabels = function(){
  if(document.all && navigator.appVersion.indexOf("MSIE")>-1 && navigator.appVersion.indexOf("Windows")>-1)
  {
    var a = document.getElementsByTagName("label");
    for(var i=0,j=a.length;i<j;i++){
      if(a[i].hasChildNodes && a[i].childNodes.item(0).tagName == "IMG")
      {
        a[i].childNodes.item(0).forid = a[i].htmlFor;
        a[i].childNodes.item(0).onclick = function(){
          var e = document.getElementById(this.forid);
          switch(e.type){
            case "radio": e.checked|=1;break;
            case "checkbox": e.checked=!e.checked;break;
            case "text": case "password": case "textarea": e.focus(); break;
          }
          checkAllColours();
        }
      }
    }
  }
}

checkAllColours = function(){
  var a = document.getElementsByClassName("colours");
  for(var i=0,j=a.length;i<j;i++){
    var b = a[i].getElementsByTagName("li");
    for(var e=0,f=b.length;e<f;e++){
      if (b[e].getElementsByTagName("input")[0].checked){
        b[e].className = "selected_colour"
      }
      else{
        b[e].className = "non_colour"
      }
    }
  }
}

function replace_feature(feat_id, filename, width, height) {
  replace_it = document.getElementById(feat_id);
  if (replace_it) {
    replace_it.src=filename;
    replace_it.height=height;
    replace_it.width=width;
  }
}

function changePrice(field_id, choice_obj, c_price){
  price_display = document.getElementById("p_price_"+field_id);
  if (price_display) {
    with (new Object(Math.round(100 * (c_price + choice_obj)) + "")) {
      price_display.innerHTML = "$"+String(substring(0, length - 2) + "." + substring(length - 2, length));
    }
  }
}

function changePrice_old(field_id, choice_obj, c_price){
  price_display = document.getElementById("p_price_"+field_id);
  if (price_display){
    bb = new Object(Math.round(100 * (c_price + choice_obj)) + "");
    price_display.update("$"+bb.substring(0, bb.length-2)+"."+bb.substring(bb.length-2, bb.length));
  }
}
