/* Global useful functions */

// swap images if the page contains the picturebox element:
function swap() {
      var numimages=5;
      rndimg = new Array("/fragr_image/picturebox-001", 
                         "/fragr_image/picturebox-002", 
                         "/fragr_image/picturebox-003", 
                         "/fragr_image/picturebox-004", 
                         "/fragr_image/picturebox-005"); 
      x=(Math.floor(Math.random()*numimages));
      randomimage=(rndimg[x]);
      if (document.getElementById("picturebox")) {
        document.getElementById("picturebox").style.backgroundImage = "url("+ randomimage +")"; 
      }
}

function set_background_image(subject) {
      if (document.getElementById("picturebox")) {
        var subj_image_url = "url(/fragr_image/images/"+ subject +")";
        document.getElementById("picturebox").style.backgroundImage = subj_image_url; 
      }
}

function initClassBehaviour() {
    
    // find all elements of class "submitonchange" and add the following
    // onchange handler to them, so they autosubmit
    //
    var selects = document.getElementsByTagName('select');
    for (var i = 0; i < selects.length; i++) {
      if (selects[i].className.indexOf('submitonchange') != -1) {
           selects[i].onchange = function() {
              if (this.selectedIndex > 0) {
                this.form.submit();
              }
           }     
      }else if (selects[i].className.indexOf('submitallonchange') != -1) {
           selects[i].onchange = function() {
                this.form.submit();
           }     
      }      
    }

}
document.observe("dom:loaded",initClassBehaviour);
function popup(mylink, windowname, style)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, style);
return false;
}


