
/* IOK 2010-03-18 this does not work for IE7 and older when called by img.onload */
function resize(elem, max) {
//  var elem = document.getElementById(which);

  if (elem == undefined || elem == null) return false;
  if (max == undefined) max = 100;
  if (elem.width > elem.height) {
    if (elem.width > max) { 
      elem.width = max;
    }
  } else {
    if (elem.height > max) {
      elem.height = max;
    }
  }
	elem.style.visibility='visible';
}


function setImage(filename){
 document.getElementById('mainimage').src='/images/large' + filename;
 var hmtl='';
 for(image in images){
  if(typeof(images[image].filename) !='undefined'){
   if(images[image].filename != filename){
     hmtl += '<a href="#" onclick="setImage(\'' + images[image].filename +'\');return false;" title="Klikk for å vise full størrelse"><img border=0 src="/images/thumb' + images[image].filename + '"></a>&nbsp; ' ;
   } else {
  // current image
	current_image = images[image];
}	 
  }
 }
 document.getElementById('imagelist').innerHTML = hmtl;

}


var mX;
var mY;

function storeCoordinates(e) {
   if (navigator.appName == "Microsoft Internet Explorer"){

    mX = event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
    mY = event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
  }
  else {
    mX = e.pageX;
    mY = e.pageY;
  }
}


document.onmousedown = storeCoordinates;


function showImg(fname, width, height){


//imgsrc =  '/images/' + fname ;
imgsrc =  '/images/' + current_image.filename ;
// window.open(imgsrc,'img','width=' + width + ',height=' + height + ',resizable=yes');
 window.open(imgsrc,'img','width=' + current_image.width + ',height=' + current_image.height + ',resizable=yes, top='+ mY+',left='+mX);

}



function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}



function doCheckout() {
	var payment;
	try {
		payment = getCheckedValue(document.forms['order'].elements['paymentmethods']);
	}
	catch(err) {
		payment = "null";
	}
	self.location='/index.php?do=checkout&paymentmethod='+payment;
}
