Array.prototype.findIndex = function(value){
	var notFound ="";
	for(var i=0;i<this.length;i++){
		if(this[i]==value){
			return i;
		}
	}
	return notFound;
};

Array.prototype.clear=function(){ 
	this.length = 0; 
};

// This is override because the spry taking the index 0 as false
Array.prototype.existsVal = function(value){
	var notFound =false;
	for(var i=0;i<this.length;i++){
		if(this[i]==value){
			return true;
		}
	}
	return notFound;
};

//Here’s the function to insert and extract data from the array:
function manageData(ctrl, floor_number){
	//check the state of the checkbox
	if (ctrl.checked){
		// must be a new floor, were adding
		if(myFloor.length > 3){
			alert('A maximum of four plots can be compared at any one time. Please reselect and try again.');
			ctrl.checked = false;
		} else {
			myFloor.push(floor_number);
		}
	} else {
		// were removing
		idx = myFloor.findIndex(floor_number);
		myFloor.splice(idx,1);
	}

	// reset for good measure
	document.frmFloor.chkvalues.value=myFloor;
	idx="";
	floor_number="";
}

// This gets called by a button being clicked on my form.
function giveMeTheResults(){
	if(myFloor.length < 2){
		alert('You must select at least 2 plots for comparison.');
	} else if(myFloor.length > 4){
		alert('A maximum of four plots can be compared at any one time. Please reselect and try again.');
	} else {
		// plugin your processing script here
		document.frmFloor.chkvalues.value	=	myFloor;
		document.frmFloor.submit();
	}	
	
	return false;
}

function backToDetailPage()	{
	document.getElementById('frmCompare').submit();
	return false;
}
