var FIRE_ONLOAD_FUNCS = [];
function FireOnLoad(func)
{
  FIRE_ONLOAD_FUNCS.push(func);
}
function Start()
{
  for (var i = 0; i < FIRE_ONLOAD_FUNCS.length; i++)
    FIRE_ONLOAD_FUNCS[i]();
}

var Global = {

  doLoad: function()
  {
    if (document.getElementById("slideshow")){
    var strCulture=MM_findObj('slideshow').className;    
    var strUrlSlideshow;
    if (MM_findObj('UrlSlideshow')) strUrlSlideshow = MM_findObj('UrlSlideshow').value;
    document.getElementById("slideshow").innerHTML = this.getFlashObject("slideshowObject", "/media/" + strCulture + "/slideshow.swf?link=" + strUrlSlideshow, "212", "218");}

    if (Spif.ClassNameAbstraction.contains(document.body, "product") && document.getElementById("flashBox")){
      document.getElementById("flashBox").innerHTML = this.getFlashObject("slideshowObject", "/media/" + document.getElementById("flashBox").className + ".swf", "444", "325");
  }
  },

  getFlashObject: function(id, file, width, height)
  {
    var obj = "<object id=\"" + id + "\" width=\"" + width + "\" height=\"" + height + "\" classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" type=\"application/x-shockwave-flash\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\">";
    obj += "<param name=\"allowScriptAccess\" value=\"sameDomain\" />";
    obj += "<param name=\"movie\" value=\"" + file + "\" />";
    /*obj += "<param name=\"bgcolor\" value=\"#FFFFFF\" />";*/
    obj += "<param name=\"wmode\" value=\"transparent\" />";
    obj += "<embed src=\"" + file + "\" width=\"" + width + "\" height=\"" + height + "\" wmode=\"transparent\" allowScriptAccess=\"sameDomain\" bgcolor=\"#FFFFFF\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />";
    obj += "</object>";
    return obj;
  },

  openShowroom: function(b,p,s)
  {
    if (!parent.Lime)
    {
      var lang = document.getElementById("showroomCulture").value;
      var checkoutURL = document.getElementById("domain").value + "/showroom/checkout.aspx";
      var userID = document.getElementById("userID").value;
      var brands= b;
      var product= p;
      var sku= s;
      //xC="http://bonar.tricycleinc.com/launch.htm?lang=" + lang + "&user=" + userID + "&checkouturl=" + checkoutURL + "&brands=" + brands + "&product=" + product + "&sku=" + sku;
    // alert(xC);
     window.open("http://bonar.tricycleinc.com/launch.htm?lang=" + lang + "&user=" + userID + "&checkouturl=" + checkoutURL + "&brands=" + brands + "&product=" + product + "&sku=" + sku, "showroom", "status=1, width=800, height=570,  location=0,  scrollbars=1, left =" + (screen.width - 800)/2 + ", top=" + (screen.height - 570)/2).focus();
    }
    return false;
  },

  openCheckStock: function()
  {
    if (!parent.Lime)
    {
      if (document.getElementById("userID") != null && document.getElementById("userID").value != "" && document.getElementById("userID").value != "guest")
        window.open('/checkstock', 'checkstock', 'status=1, width=1000, height=700,  location=0,  scrollbars=1, resizable=1,left =' + (screen.width - 1000)/2 + ', top=' + (screen.height - 700)/2).focus();
      else
        alert(document.getElementById("loginMessage").value);
    }
    return false;
  }
}

FireOnLoad(Global.doLoad.closure(Global));

function selectLanguage(el)
{
  if (top.window != window && top.window.location.href.indexOf("/lime") != -1)
    window.parent.location.href = 'http://' + el.options[el.selectedIndex].value + '/lime';
  else
    location.href = 'http://' + el.options[el.selectedIndex].value;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }