// object representation of a verfproduct
function Verfproduct(id,name,surface,type,treatment,appliance,undergrounds) {
	this.name = name;					// string
	this.id = id;						// int
	this.surface = surface;				// double
	this.type = type;					// id
	this.treatment = treatment;			// id
	this.appliance = appliance;			// id
	this.undergrounds = undergrounds;	// array of id's
	
	this.toString = function() {
		var output = "";
		output += "ID:\t\t" + this.id;
		output += "\nName:\t\t" + this.name;
		output += "\nSurface:\t\t" + this.surface;
		output += "\nType:\t\t" + this.type;
		output += "\nTreatment:\t" + this.treatment;
		output += "\nAppliance:\t" + this.appliance;
		output += "\nUnders:\t\t";
		
		for ( var i = 0 ; i < this.undergrounds.length ; i++ ) {
			if (i > 0) {
				output += ", ";
			}
			
			output += this.undergrounds[i];
		}
		
		return output;
	}
}			

// array for holding verfproducts
var verfproducten = new Array();

var tempTextEl;

// search for verfproduct objects in array with given characteristics, return suitable in an array
function getVerfproducts( type, appliance, treat, under ) {
	var results = new Array();

	for ( var i = 0 ; i < verfproducten.length ; i++ ) {
		// first, check type
		if ( verfproducten[i].type == type || type == 'all' ) {
			// check appliance
			if ( verfproducten[i].appliance == appliance || verfproducten[i].appliance == '3' ) {
				// check treatment of underground
				if ( verfproducten[i].treatment == treat || verfproducten[i].treatment == '3' ) {
					// loop undergrounds supported to find if selected underground is supported
					for ( var j = 0 ; j < verfproducten[i].undergrounds.length ; j++ ) {
						if ( verfproducten[i].undergrounds[j] == under ) {
							// we've got a matching verfproduct, add to results
							results[results.length] = verfproducten[i];
							
							// debug
							//window.alert( results[results.length - 1].toString() );
							
							// found, so exit loop
							break;
						}
					}
				}
			}
		}
	}

	return results;
}

function findProduct(objectId) {
	if (objectId != "0") {
		for ( var i = 0 ; i < verfproducten.length ; i++ ) {
			if (verfproducten[i].id == objectId) {
				// found, return it
				return verfproducten[i];
			}
		}
	}
	// if not found, return null;
	return null;
}

// removes child div from results container 'paint_result_column'
function deletediv(divid) {
 	var cont = document.getElementById('paint_result_column')
 	var div = document.getElementById(divid);
 	cont.removeChild(div);
 	
 	// if container empty, add temporary text
 	if ( cont.innerHTML.match(/^\s*$/) ) {
		cont.appendChild(tempTextEl);
	}
}
