/* 	
	------------------------------------------------------------------------------
	/framework/classes/js/page.js
	
	Page bevat een array waarin alle controls zitten - handig om te loopen
	
 	------------------------------------------------------------------------------
*/

function Page() {

	// methods
	this.controls = new Array();
	this.numControls = 0;
	
	this.addControl = Page_addControl;
	this.removeControl = Page_removeControl;
	
	this.hasErrors = false;
	this.languageStrings = new Array();
	
	this.getLanguageString = Page_getLanguageString;
}

function Page_addControl(obj) {
	//alert("Adding object " + obj + " to Page");
	
	if (obj) {
		if (obj.id) {
			this.controls[this.numControls] = obj;
			this.numControls++;
		}
	}
}

function Page_removeControl(obj) {
	
	var foundAt = -1;
	for (i=0;i < this.numControls; i++) {
		if (this.controls[i].id == obj.id) {
			foundAt = i;
		}
	}
	
	// if we found it at, f.e. 5, 6->5, 7->6, until end of array (f.e. length = 8)
	if (foundAt > 0) {
		for(i=foundAt+1; i <= this.numControls; i++) {
			this.controls[i-1] = this.controls[i]; 
		}
		this.numControls--;
	}
	else if (foundAt == 0) {
		this.controls[0] = null;
		this.numControls = 0;
	}
	else {}	
	
}



function Page_getLanguageString(string, param1, param2, param3, param4, param5) {
	str = this.languageStrings[string];
	if(typeof(this.languageStrings[string]) != "string") {
		return string;
	}
	
	
	if (isDefined(param1))
		str = str.replace("{1}", param1);
	if (isDefined(param2))
		str = str.replace("{2}", param2);
	if (isDefined(param3))
		str = str.replace("{3}", param3);
	if (isDefined(param4))
		str = str.replace("{4}", param4);
	if (isDefined(param5))
		str = str.replace("{5}", param5);
		
	return str;
}
	

