function vaeg_vaeg_taeppe() {
	this.vareid=0;
	this.tilbudsindex=100;
	this.kmpris = 0;
	this.antal = 1;
	
	this.change_antal = function(val) {
		this.antal = val;
		a = parseFloat(this.antal.replace(",", "."));
		if(isNaN(a) || Math.round(a)<1) {
			document.getElementById('pris_'+this.vareid).value="-";
			document.getElementById('gem_'+this.vareid).disabled='true';
		} else {
			a = Math.round(a);
			if(a==0) a=1;
			this.antal = a;
			
			this.get_price(document.getElementById('bredde_'+this.vareid).value, document.getElementById('hojde_'+this.vareid).value);
		}
	}	
	
	this.get_price = function(w, l) {
		if(parseInt(w)>0 && parseInt(l)>0) {
			w = w.replace(",", ".");
			w = w/100;
			l = l.replace(",", ".");
			l = l/100;
			pris = w*l*this.kmpris*this.antal;
			if(this.tilbudsindex < 100) {
				i=(100-this.tilbudsindex)/100;
				pris = pris-(pris*i);
			}
			pris = this.CurrencyFormatted(pris);
			document.getElementById('pris_'+this.vareid).value="DKK "+pris;
			document.getElementById('gem_'+this.vareid).disabled='';
		} else {
			document.getElementById('pris_'+this.vareid).value="-";
			document.getElementById('gem_'+this.vareid).disabled='true';
		}
	}
	
	this.CurrencyFormatted = function(amount)
	{
		var i = parseFloat(amount);
		if(isNaN(i)) { i = 0.00; }
		var minus = '';
		if(i < 0) { minus = '-'; }
		i = Math.abs(i);
		i = parseInt((i + .005) * 100);
		i = i / 100;
		s = new String(i);
		if(s.indexOf('.') < 0) { s += '.00'; }
		if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
		s = minus + s;
		s=s.replace(".", ",");
		return s;
	}
	this.vareprove_submit = function() {
		document.getElementById('vareprove_'+this.vareid).value='1';
		document.getElementById('pris_'+this.vareid).value="DKK 10,00";
		document.getElementById('formen_'+this.vareid).submit();
	}
	this.tilbehor = function() {
		window_name='pop_tilbehor';
		props = 'width=450,height=450, resizable=no, scrollbars=yes, toolbars=no, location=no, directories=no, status=no, menubar=no, copyhistory=no';
		window.open('includes/tilbehor.php?vareid='+this.vareid, window_name, props);
	}
}

function vaeg_vaeg_taeppe_old()
{
	this.vareid=0;
	this.tilbudsindex=100;
	this.matrix=new Array();
	this.min_bredde = 0;
	this.max_bredde = 0;
	this.min_hojde = 0;
	this.min_hojde = 0;
	
	this.init_matrix = function() {
		var nb = 1;
		var last = this.matrix.length;
		for(x in this.matrix) {
			if(nb==1) {
				this.min_bredde = x;
				last2 = this.matrix[x].length;
				nb2 = 1;
				for(b in this.matrix[x]) {
					if(nb2==1) {
						this.min_hojde = b;
					}
					if(b==last2-1) {
						this.max_hojde = b;
					}
					nb2 = nb2+1;
				}
			}
			if(x==last-1) {
				this.max_bredde = x;
			}
			nb = nb+1;
		}
		this.matrix.splice(this.min_bredde, 1);
	}
	
	this.CurrencyFormatted = function(amount)
	{
		var i = parseFloat(amount);
		if(isNaN(i)) { i = 0.00; }
		var minus = '';
		if(i < 0) { minus = '-'; }
		i = Math.abs(i);
		i = parseInt((i + .005) * 100);
		i = i / 100;
		s = new String(i);
		if(s.indexOf('.') < 0) { s += '.00'; }
		if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
		s = minus + s;
		s=s.replace(".", ",");
		return s;
	}
	this.vareprove_submit = function() {
		document.getElementById('vareprove_'+this.vareid).value='1';
		document.getElementById('pris_'+this.vareid).value="DKK 10,00";
		document.getElementById('formen_'+this.vareid).submit();
	}
	
	this.get_price = function(w, l) {
		w = w.replace(",", ".");
		l = l.replace(",", ".");
		if(parseInt(w)<=parseInt(this.max_bredde) && parseInt(l)<=parseInt(this.max_hojde) && parseInt(w)>=parseInt(this.min_bredde) && parseInt(l)>=parseInt(this.min_hojde)) {
			count_x = 1;
			w = w*1;
			l = l*1;
			for(x in this.matrix) {
				x = parseInt(x);
				if(x > 0) {
					if(count_x==1 && w < (x+1)) {
						tmp_ary = this.matrix[x];
						count_y = 1;
						for(y in tmp_ary) {
							if(count_y > 1) {
								y = y * 1;
								if(count_y==2 && l < y) {
									if(this.tilbudsindex > 0){
										pris = tmp_ary[y] - ((this.tilbudsindex / 100) * tmp_ary[y]);
									} else {
										pris = tmp_ary[y];
									}
									document.getElementById('pris_'+this.vareid).value="DKK "+this.CurrencyFormatted(pris);
									break;
								}
								if(y >= l) {
									if(this.tilbudsindex > 0){
										pris = tmp_ary[y] - ((this.tilbudsindex / 100) * tmp_ary[y]);
									} else {
										pris = tmp_ary[y];
									}
									document.getElementById('pris_'+this.vareid).value="DKK "+this.CurrencyFormatted(pris);
									break;
								}
							}
							count_y=count_y+1;
						}
						break;
					} else if((x+1) >= w) {
						tmp_ary = this.matrix[x];
						count_y = 1;
						for(y in tmp_ary) {
							if(count_y > 1) {
								y = y * 1;
								if(count_y==2 && l < y) {
									if(this.tilbudsindex > 0){
										pris = tmp_ary[y] - ((this.tilbudsindex / 100) * tmp_ary[y]);
									} else {
										pris = tmp_ary[y];
									}
									document.getElementById('pris_'+this.vareid).value="DKK "+this.CurrencyFormatted(pris);
									break;
								}
								if(y >= l) {
									if(this.tilbudsindex > 0){
										pris = tmp_ary[y] - ((this.tilbudsindex / 100) * tmp_ary[y]);
									} else {
										pris = tmp_ary[y];
									}
									document.getElementById('pris_'+this.vareid).value="DKK "+this.CurrencyFormatted(pris);
									break;
								}
							}
							count_y=count_y+1;
						}
						break;
					}
					count_x=count_x+1;
				}
			}
			document.getElementById('gem_'+this.vareid).disabled='';
		} else {
			document.getElementById('pris_'+this.vareid).value="-";
			document.getElementById('gem_'+this.vareid).disabled='true';
		}
	}
	
	this.tilbehor = function() {
		window_name='pop_tilbehor';
		props = 'width=450,height=450, resizable=no, scrollbars=yes, toolbars=no, location=no, directories=no, status=no, menubar=no, copyhistory=no';
		window.open('includes/tilbehor.php?vareid='+this.vareid, window_name, props);
	}
}
