// Author: Bil Bas
// Modified: $Date: 2004/12/12 21:12:32 $
// Opens a popup containing a picture.
function popupPic(dir, pic, w, h, title, desc) {
 var win=window.open('/pic_popup.php?dir=' + dir + '&pic=' + pic +
                 '&title=' + title + '&desc=' + desc,
                 'ClaWin',
                 'width=' + (w + 80) + ', height=' + (h + 160));
 win.resizeTo(w + 80, h + 140);
 win.focus();
}

function popupGallery(baseImage, subImages, w, h, author, title) {
 var totWidth=w + ((subImages.length>2) ? 320 : 200); 
 var win=window.open('/gallery_popup.php?baseImage=' + baseImage +
                '&subImages=' + subImages +
                 '&title=' + title + '&author=' + author,
                 'ClaWin',
                 'width=' + totWidth + ', height=' + (h + 160));
 win.resizeTo(totWidth, h + 160);
 win.focus();
}

// Opens a popup containing text.
function popupText(file) {
 var win=window.open('/text_popup.php?file=' + file,
                 'ClaWin',
                 'scrollbars=yes,width=300,height=300');
 win.resizeTo(300, 300);
 win.focus();
}

// Lightens/darkens input button onmouseover/onmouseout
function lighten(ob) {
 ob.style.background='eeddbb';
}
function darken(ob){
 ob.style.background='ddccaa';
}

// deletes/writes standard text from search box.
function selSearch(me,def) {
 if(me.value==def) me.value='';
}
function unselSearch(me,def) {
 if(me.value=='') me.value=def;
}

// Checks that one of the varnish options has been checked.
function isChecked(formNo,min,max) {
 var v1 = document.getElementById("varnish_" + formNo + "_1");
 var v2 = document.getElementById("varnish_" + formNo + "_2");
 var v3 = document.getElementById("varnish_" + formNo + "_3");

 var varnishSelected = (
  (typeof(v1) != 'undefined' && v1.checked) ||
  (typeof(v2) != 'undefined' && v2.checked) ||
  (typeof(v3) != 'undefined' && v3.checked)
 );

 var q = document.getElementById("quantity_" + formNo);
 var validQuantity =
  (typeof(q) != 'undefined') && (q.value >= min) && (q.value <= max);

 if(!varnishSelected) {
  alert("Välj färgnyans innan du beställer.");
  return false;
 } else if(!validQuantity) {
  if(!q.value) { q.value=0; }
  alert("'"+q.value+"' är inte ett giltigt antal. Vänligen välj korrekt antal.");
  return false;
 } else {
  return true;
 }
}