function number(e) {
	var key;

	if (window.event)
		key = window.event.keyCode;
	else if (e)
		key = e.which;
	else
	   return true;

	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) ) return true;

	if (key < 48) return false;
	if (key > 57) return false;

	return true;
}

function change_factor(prod) {
	var o_cnt = $("input[name='cnt_"+prod+"']")[0];	// the 'real' count
	var o_tmp = $("input[name='tmp_"+prod+"']")[0];	// the visible count (no of units)

	var o_dd = $("select[name='factor_"+prod+"']")[0];
	var f_new = o_dd.options[o_dd.selectedIndex].value;
	var f_old = o_dd.options[1 - o_dd.selectedIndex].value; // must be the other option

	o_cnt.value = o_tmp.value * f_new;
	update_or_submit(prod);

}

function change_cnt_pkg(prod,factor) {
	if (!factor) {
		var o_dd =  $("select[name='factor_"+prod+"']")[0];
		factor = o_dd.options[o_dd.selectedIndex].value;
	}
	 $("input[name='cnt_"+prod+"']")[0].value =  $("input[name='tmp_"+prod+"']")[0].value * factor;

	update_or_submit(prod);
}

function cart_set_cnt(prod,cnt) {
	 $("input[name='cnt_"+prod+"']")[0].value=cnt; // TODO:  change....
	document.productform.update_action.value=document.productform.update_action.value+'?rel=volume&prod='+prod+'&cnt='+cnt; // TODO: Change......
	update_or_submit(prod);
	return false;
}

function change_cnt(prod) {
	update_or_submit(prod);
}

function update_or_submit(prod){
	var form=$("input[name='cnt_"+prod+"']").parents("form:last");
	var o = form.attr('update');
	if (o) { o.click(); }
	//else { single_buy($("input[name='cnt_"+prod+"']", form)[0]); }
}

function single_buy(t) {
	var form=$(t).parents("form:last");
	if (!$("input[name^='cnt_']", form).val()) {
		return;
	}
	$(t).removeAttr('onclick');	// prevent double click
	form.submit();
}

function bigPicture(pic) {
	var picture = "/gfx/imager/catalog/"+pic+"?s=product_details"
	win = window.open("","Stortbillede","width=750,height=650,scrollbars=1,toolbar=0,menubar=0,location=0,resizable=1");
	win.document.open();
	win.document.writeln("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>");
	win.document.writeln("<!-- Produced by www.adapt.dk -->");
	win.document.writeln("<html lang='da'><head><title>CarlRas</title>");
	win.document.writeln("<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>");
	win.document.writeln("</head><body onclick='window.close();' style='cursor:pointer;'>");
	win.document.writeln("<img src='"+picture+"' border='0' alt=''>");
	win.document.writeln("</body></html>")
	win.document.close();
	win.focus();
	return false
}

function addMagnify(picture,shop) {
	var magnify = document.createElement("img");
	if (shop) {
		magnify.src = "/gfx/shops/"+shop+"/magnify.gif";
	} else {	
		magnify.src = "/gfx/magnify.gif";
	}
	picture.parentNode.insertBefore(magnify,picture);
	magnify.style.position = "absolute";
	
//	document.title = picture.width+","+picture.height;
	
	magnify.style.marginLeft = picture.width - magnify.width + "px";
	magnify.style.marginTop = picture.height - magnify.height + "px";
	
	if (shop == "dewalt") {
		magnify.style.marginLeft = picture.width - magnify.width - 15 + "px";
		magnify.style.marginTop = picture.height - magnify.height - 15 + "px";
	}
}
