function lamelgardiner()
{
	this.vareid = 0;
	this.tilbudsindex=100;
	this.matrix = new Array();
	this.min_bredde = 0;
	this.max_bredde = 0;
	this.min_hojde = 0;
	this.max_hojde = 0;
	this.antal = 1;
	
	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.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) {
		l = parseFloat(l.replace(",", "."));
		w = parseFloat(w.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) && !isNaN(l) && !isNaN(w)) {
			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]);
										var vejl_pris = tmp_ary[y];
										var rabat_pris = vejl_pris - pris;
									} else {
										pris = tmp_ary[y];
									}
									document.getElementById('pris_'+this.vareid).value="DKK "+this.CurrencyFormatted(pris*this.antal);
									if(this.tilbudsindex > 0)
									{
										document.getElementById('vejl_pris_'+this.vareid).value="DKK "+this.CurrencyFormatted(vejl_pris*this.antal);
										document.getElementById('rabat_pris_'+this.vareid).value="DKK "+this.CurrencyFormatted(rabat_pris*this.antal);
									}									
									break;
								}
								if(y >= l) {
									if(this.tilbudsindex > 0){
										pris = tmp_ary[y] - ((this.tilbudsindex / 100) * tmp_ary[y]);
										var vejl_pris = tmp_ary[y];
										var rabat_pris = vejl_pris - pris;
									} else {
										pris = tmp_ary[y];
									}
									document.getElementById('pris_'+this.vareid).value="DKK "+this.CurrencyFormatted(pris*this.antal);
									if(this.tilbudsindex > 0)
									{
										document.getElementById('vejl_pris_'+this.vareid).value="DKK "+this.CurrencyFormatted(vejl_pris*this.antal);
										document.getElementById('rabat_pris_'+this.vareid).value="DKK "+this.CurrencyFormatted(rabat_pris*this.antal);
									}									
									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]);
										var vejl_pris = tmp_ary[y];
										var rabat_pris = vejl_pris - pris;										
									} else {
										pris = tmp_ary[y];
									}
									document.getElementById('pris_'+this.vareid).value="DKK "+this.CurrencyFormatted(pris*this.antal);
									if(this.tilbudsindex > 0)
									{
										document.getElementById('vejl_pris_'+this.vareid).value="DKK "+this.CurrencyFormatted(vejl_pris*this.antal);
										document.getElementById('rabat_pris_'+this.vareid).value="DKK "+this.CurrencyFormatted(rabat_pris*this.antal);
									}									
									break;
								}
								if(y >= l) {
									if(this.tilbudsindex > 0){
										pris = tmp_ary[y] - ((this.tilbudsindex / 100) * tmp_ary[y]);
										var vejl_pris = tmp_ary[y];
										var rabat_pris = vejl_pris - pris;										
									} else {
										pris = tmp_ary[y];
									}
									document.getElementById('pris_'+this.vareid).value="DKK "+this.CurrencyFormatted(pris*this.antal);
									if(this.tilbudsindex > 0)
									{
										document.getElementById('vejl_pris_'+this.vareid).value="DKK "+this.CurrencyFormatted(vejl_pris*this.antal);
										document.getElementById('rabat_pris_'+this.vareid).value="DKK "+this.CurrencyFormatted(rabat_pris*this.antal);
									}									
									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.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();
	}
}
