function ReklanetForm(jsonEmtId){
	this.defaultLocale = "fi_FI";
	
	this.jsonStr = document.getElementById(jsonEmtId).innerHTML;
	this.selectArray = null;
	this.select1 = document.getElementById("tmp1");
	this.select2 = document.getElementById("tmp2");
	
	this.valueField = document.getElementById("tmpnro");
	
	this.errorCount = 0;
	this.errorMessage = "";
	this.errorPrefix = "\n- ";
	
	
	this.removeOptions = function(emt){
		var children = emt.getElementsByTagName("option");
		for(var i = (children.length - 1); i >= 1; i--){
			emt.removeChild(children[i]);
		}
	}
	
	this.updateField = function(selectEmt){
		var value = selectEmt.options[selectEmt.selectedIndex].value;
		this.valueField.value = value.replace("$", "@"); // Set the facility id
	}
	
	this.updateSelects = function(selectEmt){
		this.removeOptions(this.select2);
		
		var idx = selectEmt.selectedIndex;
		
		if(this.selectArray[idx][1].length > 1){
			for(var i = 0; i < this.selectArray[idx][1].length; i++){
				var text = this.selectArray[idx][1][i][0];
				var value = this.selectArray[idx][1][i][1];
				if(value.length > 2){
					while(value.length < 8){
						value = "0" + value;
					}
				}
				var optionEmt = document.createElement("option");
				var textNode = document.createTextNode(text);
				optionEmt.value = value;
				optionEmt.appendChild(textNode);
				this.select2.appendChild(optionEmt);
			}
			document.getElementById("tmp2_row").className = "";
			this.valueField.value = "";
		}
		else{
			document.getElementById("tmp2_row").className = "hidden";
			var value = this.selectArray[idx][1][0];
			if(value.length > 2){
				while(value.length < 8){
					value = "0" + value;
				}
			}
			this.valueField.value = value.replace("$", "@"); // Set the facility id
		}
	}
	
	
	this.buildSelect1 = function(){
		this.selectArray = eval("(" + this.jsonStr.replace(/&nbsp;/g, '').replace(/&amp;/g, '&') + ")");
		var optionEmts = new Array();
		
		for(var i = 0; i < this.selectArray.length; i++){
			var text = this.selectArray[i][0];
			var optionEmt = document.createElement("option");
			var textNode = document.createTextNode(text);
			optionEmt.appendChild(textNode);
			this.select1.appendChild(optionEmt);
		}
		this.updateSelects(this.select1);
	}
	
	
	this.addError = function(str){
		this.errorCount++;
		this.errorMessage += this.errorPrefix + str;
	}
	
	this.someSelected = function(emtArray){
		var checkedCount = 0;
		for(var i = 0; i < emtArray.length; i++){
			if(emtArray[i].checked) checkedCount++;
		}

		return (checkedCount > 0) ? true : false;
	}
	
	this.haveValues = function(emtArray){
		var valueCount = 0;
		for(var i = 0; i < emtArray.length; i++){
			if(emtArray[i].value != '') valueCount++;
		}

		return (valueCount == emtArray.length) ? true : false;
	}
	
	
	this.check = function(){
		var rf1 = document.getElementById("tmpnro");
		var rf2 = new Array(document.getElementById("fbt_1"),document.getElementById("fbt_2"),document.getElementById("fbt_3"),document.getElementById("fbt_4"));
		var rf3 = new Array(document.getElementById("fba_5"),document.getElementById("fba_4"),document.getElementById("fba_2"),document.getElementById("fba_3"));
		var rf4 = document.getElementById("txt_palaute");
		var rf5 = new Array(document.getElementById("fbc_1"),document.getElementById("fbc_2"),document.getElementById("fbc_3"),document.getElementById("fbc_4"));
		
		var cf1 = new Array();
		cf1.push(document.getElementById("txt_etunimi"));
		cf1.push(document.getElementById("txt_sukunimi"));
		cf1.push(document.getElementById("txt_katuosoite"));
		cf1.push(document.getElementById("txt_postinumero"));
		cf1.push(document.getElementById("txt_postitoimipaikka"));
		
		var cf2 = new Array();
		cf2.push(document.getElementById("txt_etunimi"));
		cf2.push(document.getElementById("txt_sukunimi"));
		cf2.push(document.getElementById("txt_puhelin"));
		
		var cf3 = new Array();
		cf3.push(document.getElementById("txt_etunimi"));
		cf3.push(document.getElementById("txt_sukunimi"));
		cf3.push(document.getElementById("txt_sposti"));
		
		this.errorCount = 0;
		this.errorMessage = errorHeader;
		
		if(rf1.value == '') this.addError(localizedFields[0]);
		if(!this.someSelected(rf2)) this.addError(localizedFields[1]);
		if(!this.someSelected(rf3)) this.addError(localizedFields[2]);
		if(rf4.value == '') this.addError(localizedFields[3]);
		if(!this.someSelected(rf5)) this.addError(localizedFields[4]);
	
		if(rf5[1].checked && !this.haveValues(cf3)){this.addError(localizedFields[5]); this.addError(localizedFields[6]); this.addError(localizedFields[11]);}
		if(rf5[2].checked && !this.haveValues(cf2)){this.addError(localizedFields[5]); this.addError(localizedFields[6]); this.addError(localizedFields[10]);}
		if(rf5[3].checked && !this.haveValues(cf1)){this.addError(localizedFields[5]); this.addError(localizedFields[6]); this.addError(localizedFields[7]); this.addError(localizedFields[8]); this.addError(localizedFields[9]);}
		
		if(this.errorCount == 0){
			return true;
		}
		else{	
			alert(this.errorMessage);
			
			this.errorCount = 0;
			this.errorMessage = "";
			
			if(window.location.href.indexOf("debug") > -1){
				alert(rf1.value);
			}
			
			return false;
		}
	}
	
	
	
	
	
	this.showAsterisk = function(fieldArr){
		for(var i = 1; i < 8; i++){
			document.getElementById("c_label" + i).getElementsByTagName("span")[0].style.display = "none";
		}
		for(var i = 1; i < 8; i++){
			var currentLabel = document.getElementById("c_label" + i);
			for(var j = 0; j < fieldArr.length; j++){
				if(fieldArr[j] == i){
					currentLabel.getElementsByTagName("span")[0].style.display = "inline";
				}
			}
		}
	}
	
	
	this.buildSelect1();
}