function velux() {
	this.vareid = 0;
	this.tilbudsindex=100;
	this.matrix = new Array();
	this.models = new Array();
	this.types = new Array();
	this.type_selector ='';
	this.hvide_lister = false;
	this.hvide_lister_pris = 0;
	this.elmotor = false;
	this.elmotor_pris = 0;
	this.solceller=false;
	this.solceller_pris = 0;
	this.antal = 1;

	this.discount_update = function(vejl_pris)
	{
		if(this.tilbudsindex < 100)
		{
			vejl_pris = vejl_pris * this.antal.value;
			var i=(100-this.tilbudsindex)/100;
			rabat_pris = vejl_pris*i;			
			document.getElementById('vejl_pris_'+this.vareid).value="DKK "+this.CurrencyFormatted(vejl_pris);
			document.getElementById('rabat_pris_'+this.vareid).value="DKK "+this.CurrencyFormatted(rabat_pris);
		}
	}
	
	this.init_matrix = function() {
		this.models = this.matrix['types'];
		this.matrix = this.matrix['matrix'];
		this.type_selector.options.length = 0;
		for(x in this.matrix) {
			if(x.length>0) {
				this.type_selector.options[this.type_selector.options.length] = new Option(x, x);
			}
		}
		this.selected_type = this.type_selector.options[this.type_selector.selectedIndex].value;
		this.fill_models();
	}
	
	this.fill_models = function() {
		mod_selector = document.getElementById('model_str'+this.vareid);
		mod_selector.disabled=false;
		mod_selector.options.length = 0;
		for(x in this.matrix[this.selected_type]) {
			mod_selector.options[mod_selector.options.length] = new Option(x, x);
		}
		pris = (this.matrix[this.selected_type][mod_selector.options[mod_selector.selectedIndex].value]);
		if(this.hvide_lister.checked) pris = (pris+this.hvide_lister_pris);
		if(this.elmotor.checked) pris = (pris+this.elmotor_pris);
		if(this.solceller.checked) pris = (pris+this.solceller_pris);
		this.discount_update(pris);
		if(this.tilbudsindex < 100) {
			i=(100-this.tilbudsindex)/100;
			pris = pris-(pris*i);
		}
		pris = pris * this.antal.value;		
		document.getElementById('pris_'+this.vareid).value="DKK "+this.CurrencyFormatted(pris);
	}
	
	this.change_type = function() {
		this.selected_type = this.type_selector.options[this.type_selector.selectedIndex].value;
		this.fill_models();
		
//		mod_selector = document.getElementById('model_str'+this.vareid);
//		pris = (this.matrix[this.selected_type][mod_selector.options[mod_selector.selectedIndex].value] * this.antal.value);
//		if(this.hvide_lister.checked) pris = (pris+this.hvide_lister_pris);
//		if(this.elmotor.checked) pris = (pris+this.elmotor_pris);
//		if(this.solceller.checked) pris = (pris+this.solceller_pris);
//		pris = pris * this.antal.value;
//		document.getElementById('pris_'+this.vareid).value="DKK "+this.CurrencyFormatted(pris);
	}
	
	this.change_model = function() {
		mod_selector = document.getElementById('model_str'+this.vareid);
		pris = (this.matrix[this.selected_type][mod_selector.options[mod_selector.selectedIndex].value]);
		pris = pris*1;
		if(this.hvide_lister.checked) pris = (pris+this.hvide_lister_pris);
		if(this.elmotor.checked) pris = (pris+this.elmotor_pris);
		if(this.solceller.checked) pris = (pris+this.solceller_pris);
		this.discount_update(pris);
		if(this.tilbudsindex < 100) {
			i=(100-this.tilbudsindex)/100;
			pris = pris-(pris*i);
		}		
		pris = pris * this.antal.value;
		document.getElementById('pris_'+this.vareid).value="DKK "+this.CurrencyFormatted(pris);
	}
	
	this.hvide_lister_check = function() {
		mod_selector = document.getElementById('model_str'+this.vareid);
		pris = (this.matrix[this.selected_type][mod_selector.options[mod_selector.selectedIndex].value] * 1);
		
		if(this.hvide_lister.checked) {
			pris = pris + this.hvide_lister_pris;
			if(this.elmotor.checked) pris = (pris+this.elmotor_pris);
			if(this.solceller.checked) pris = (pris+this.solceller_pris);
			this.discount_update(pris);
			if(this.tilbudsindex < 100) {
				i=(100-this.tilbudsindex)/100;
				pris = pris-(pris*i);
			}
			pris = pris * this.antal.value;
			document.getElementById('pris_'+this.vareid).value="DKK "+this.CurrencyFormatted(pris);
		} else {
			if(this.elmotor.checked) pris = (pris+this.elmotor_pris);
			if(this.solceller.checked) pris = (pris+this.solceller_pris);
			this.discount_update(pris);
			if(this.tilbudsindex < 100) {
				i=(100-this.tilbudsindex)/100;
				pris = pris-(pris*i);
			}
			pris = pris * this.antal.value;
			document.getElementById('pris_'+this.vareid).value="DKK "+this.CurrencyFormatted(pris);
		}
	}
	
	this.elmotor_check = function() {
		mod_selector = document.getElementById('model_str'+this.vareid);
		pris = (this.matrix[this.selected_type][mod_selector.options[mod_selector.selectedIndex].value] * 1);
		if(this.elmotor.checked) pris = pris+this.elmotor_pris;
		if(this.hvide_lister.checked) pris = pris+this.hvide_lister_pris;
		if(this.solceller) this.solceller.checked=false;
		this.discount_update(pris);
		if(this.tilbudsindex < 100) {
			i=(100-this.tilbudsindex)/100;
			pris = pris-(pris*i);
		}
		pris = pris * this.antal.value;
		document.getElementById('pris_'+this.vareid).value="DKK "+this.CurrencyFormatted(pris);
	}
	
	this.solcelle_check = function() {
		mod_selector = document.getElementById('model_str'+this.vareid);
		pris = (this.matrix[this.selected_type][mod_selector.options[mod_selector.selectedIndex].value] * 1);
		if(this.hvide_lister.checked) pris = pris+this.hvide_lister_pris;
		if(this.solceller.checked) pris = pris+this.solceller_pris;
		if(this.elmotor) this.elmotor.checked=false;
		this.discount_update(pris);
		if(this.tilbudsindex < 100) {
			i=(100-this.tilbudsindex)/100;
			pris = pris-(pris*i);
		}
		pris = pris * this.antal.value;
		document.getElementById('pris_'+this.vareid).value="DKK "+this.CurrencyFormatted(pris);
	}
	
	this.change_antal = function() {
		a = parseFloat(this.antal.value.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;
			mod_selector = document.getElementById('model_str'+this.vareid);
			pris = (this.matrix[this.selected_type][mod_selector.options[mod_selector.selectedIndex].value] * 1);
			if(this.hvide_lister.checked) pris = (pris+this.hvide_lister_pris);
			if(this.elmotor.checked) pris = (pris+this.elmotor_pris);
			if(this.solceller.checked) pris = pris+this.solceller_pris;
			this.discount_update(pris);
			if(this.tilbudsindex < 100) {
				i=(100-this.tilbudsindex)/100;
				pris = pris-(pris*i);
			}
			pris = pris * a;
			document.getElementById('pris_'+this.vareid).value="DKK "+this.CurrencyFormatted(pris);
			document.getElementById('gem_'+this.vareid).disabled='';
			
		}
		//alert(a);
	}
	
	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);
	}
	
	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();
	}
}