var lastPropId = 16;
var isIE = navigator.appVersion.indexOf("MSIE") > 0 ? true : false;
var fn_main = 'edit_property_choice1';
var showMode = 'table-cell';
if (document.all) showMode='block';
var filters = new Array;

function showCells(numFilters, filterId) {
	for (i = 1; i <= filters.length; i++) {
		if (filters[i] == filterId) {
			mode = showMode;
			link_color = '#ff6600';
		} else {
			mode = 'none';
			link_color = '#6666ff';
		}
		fid = filters[i];
		cells = document.getElementsByName('edit_property_choice1_purchase_price_'+fid);
		for(j = 0; j < cells.length; j++) cells[j].style.display = mode;
		cells = document.getElementsByName('edit_property_choice1_street_price_'+fid);
		for(j = 0; j < cells.length; j++) cells[j].style.display = mode;
		cells = document.getElementsByName('edit_property_choice1_vat_id_'+fid);
		for(j = 0; j < cells.length; j++) cells[j].style.display = mode;
		links = document.getElementsByName('filterlink_'+fid);
		for(j = 0; j < links.length; j++) links[j].style.color = link_color;
	}
}
function setCheckBoxes(field, form, fieldName, fieldId) {
	var fn_value_name = fieldName+'['+fieldId+'][property_name]';
	var fn_active = fieldName+'['+fieldId+'][property_status]';
	var fn_changes_current_price = fieldName+'['+fieldId+'][changes_current_price]';
	if (field.value == '' && form.elements[fn_value_name].value == '') {
		if (form.elements[fn_active] != undefined) {
			form.elements[fn_active].checked = true;
		}
		if (form.elements[fn_changes_current_price] != undefined) {
			form.elements[fn_changes_current_price].checked = true;
		}
		for (i = 1; i < filters.length; i++) {
			fn_avail = fieldName+'['+fieldId+'][avail]['+filters[i]+']';
			if (form.elements[fn_avail] != undefined) {
				form.elements[fn_avail].checked = true;
			}
		}
	}
}
function clearCheckBoxes(field, form, fieldName, fieldId) {
	var fn_value_name = fieldName+'['+fieldId+'][property_name]';
	var fn_active = fieldName+'['+fieldId+'][property_status]';
	var fn_changes_current_price = fieldName+'['+fieldId+'][changes_current_price]';
	if (field.value == '' && form.elements[fn_value_name].value == '') {
		if (form.elements[fn_active] != undefined) {
			form.elements[fn_active].checked = false;
		}
		if (form.elements[fn_changes_current_price] != undefined) {
			form.elements[fn_changes_current_price].checked = false;
		}
		for (i = 1; i < filters.length; i++) {
			fn_avail = fieldName+'['+fieldId+'][avail]['+filters[i]+']';
			if (form.elements[fn_avail] != undefined) {
				form.elements[fn_avail].checked = false;
			}
		}
	}
}
function setAllProperties(form, filterId, checkBoxesSet) {
	var fn_matrix_checkbox;
	for (i = 1; i <= lastPropId; i++) {
		fn_matrix_checkbox = 'search_form_choice1['+i+'][avail]['+filterId+']';
		if (form.elements[fn_matrix_checkbox] != undefined) {
			form.elements[fn_matrix_checkbox].checked = checkBoxesSet ? true : false;
		}
	}
	return false;
}
function addOneRow() {
	var rowSpan = 1;
	if (lastPropId < 9999999) {
		var even = lastPropId%2;
		if (even == 0) {
			bgColor = '#f0f0f0';
			rowClass = 'row_even'
		} else {
			bgColor = '#e0e0e0';
			rowClass = 'row_odd'
		}
		var theTable = document.getElementById('tableId');
		if (isIE) {
			theTR = theTable.tBodies[0].appendChild(document.createElement('<TR class="'+rowClass+'">'));
			theTD = theTR.appendChild(document.createElement('<TD rowspan="'+rowSpan+'" align="center">'));
		} else {
			theTR = theTable.tBodies[0].appendChild(document.createElement('TR'));
			theTR.setAttribute('class', rowClass);
			theTD = theTR.appendChild(document.createElement('TD'));
			theTD.setAttribute('rowspan', rowSpan);
			theTD.setAttribute('align', 'center');
		}
		theTD.appendChild(document.createTextNode(lastPropId+1));
		if (isIE) {
			theINPUT = theTD.appendChild(document.createElement('<INPUT type="hidden" name="edit_property_choice1['+(lastPropId+1)+'][product_property_id]" value="'+(lastPropId+1)+'" style="width:200px;">'));
		} else {
			theINPUT = theTD.appendChild(document.createElement('INPUT'));
			theINPUT.setAttribute('type', 'hidden');
			theINPUT.setAttribute('name', 'edit_property_choice1['+(lastPropId+1)+'][product_property_id]');
			theINPUT.setAttribute('value', (lastPropId+1));
		}
		if (isIE) {
			theINPUT = theTD.appendChild(document.createElement('<INPUT type="hidden" name="edit_property_choice1['+(lastPropId+1)+'][product_id]" value="'+(lastPropId+1)+'" style="width:200px;">'));
		} else {
			theINPUT = theTD.appendChild(document.createElement('INPUT'));
			theINPUT.setAttribute('type', 'hidden');
			theINPUT.setAttribute('name', 'edit_property_choice1['+(lastPropId+1)+'][product_id]');
			theINPUT.setAttribute('value', (lastPropId+1));
		}	theTD = theTR.appendChild(document.createElement('TD'));
		if (isIE) {
			theINPUT = theTD.appendChild(document.createElement('<INPUT style="width:220px;" type="text" name="edit_property_choice1['+(lastPropId+1)+'][property_name]" value="" maxlength="64" size="42" onfocus="javascript: setCheckBoxes(this, this.form, fn_main, '+(lastPropId+1)+');"  onblur="javascript: clearCheckBoxes(this, this.form, fn_main, '+(lastPropId+1)+');">'));
		} else {
			theINPUT = theTD.appendChild(document.createElement('INPUT'));
			theINPUT.setAttribute('type', 'text');
			theINPUT.setAttribute('name', 'edit_property_choice1['+(lastPropId+1)+'][property_name]');
			theINPUT.setAttribute('value', '');
			theINPUT.setAttribute('maxlength', '64');
			theINPUT.setAttribute('size', '42');
			theINPUT.setAttribute('onfocus', "javascript: setCheckBoxes(this, this.form, 'edit_property_choice1', "+(lastPropId+1)+");");
			theINPUT.setAttribute('onblur', "javascript: clearCheckBoxes(this, this.form, 'edit_property_choice1', "+(lastPropId+1)+");");
		}	theTD = theTR.appendChild(document.createElement('TD'));
		if (isIE) {
			theINPUT = theTD.appendChild(document.createElement('<INPUT style="width:220px;" type="text" name="edit_property_choice1['+(lastPropId+1)+'][property_value]" value="" maxlength="64" size="42" onfocus="javascript: setCheckBoxes(this, this.form, fn_main, '+(lastPropId+1)+');"  onblur="javascript: clearCheckBoxes(this, this.form, fn_main, '+(lastPropId+1)+');">'));
		} else {
			theINPUT = theTD.appendChild(document.createElement('INPUT'));
			theINPUT.setAttribute('type', 'text');
			theINPUT.setAttribute('name', 'edit_property_choice1['+(lastPropId+1)+'][property_value]');
			theINPUT.setAttribute('value', '');
			theINPUT.setAttribute('maxlength', '64');
			theINPUT.setAttribute('size', '42');
			theINPUT.setAttribute('onfocus', "javascript: setCheckBoxes(this, this.form, 'edit_property_choice1', "+(lastPropId+1)+");");
			theINPUT.setAttribute('onblur', "javascript: clearCheckBoxes(this, this.form, 'edit_property_choice1', "+(lastPropId+1)+");");
		}	theTD = theTR.appendChild(document.createElement('TD'));
		if (isIE) {
			theTD.setAttribute('align', 'right');
			theINPUT = theTD.appendChild(document.createElement('<input type="checkbox" name="edit_property_choice1['+(lastPropId+1)+'][property_status]" value="1">'));
		} else {
			theTD.setAttribute('align', 'right');
			theINPUT = theTD.appendChild(document.createElement('input'));
			theINPUT.setAttribute('type', 'checkbox');
			theINPUT.setAttribute('name', 'edit_property_choice1['+(lastPropId+1)+'][property_status]');
			theINPUT.setAttribute('value', '1');
		}	lastPropId++;
	}
}
