var jsEnabled = (document.getElementById ? true : false);

function show(elementId)
{
	document.getElementById(elementId).style.display = '';
	//document.getElementById(elementId).style.visibility = 'visible';
}

function hide(elementId)
{
	document.getElementById(elementId).style.display = 'none';
	//document.getElementById(elementId).style.visibility = 'hidden';
}

function popup(
	location, target, width, height,
	resizable, scrollbars, status, menubar, toolbar
)
{
	var str = '';
	if (width > 0 && height > 0) {
		str = str + 'width=' + width + ',height=' + height + ',';
	}
	var resizable_str  = resizable ? 'yes' : 'no';
	var scrollbars_str = scrollbars ? 'yes' : 'no';
	var status_str     = status  ? 'yes' : 'no';
	var menubar_str    = menubar ? 'yes' : 'no';
	var toolbar_str    = toolbar ? 'yes' : 'no';

	window.open(
		location,
		target,
		str +
		'resizable='  + resizable_str + ',' +
		'scrollbars=' + scrollbars_str + ',' +
		'status='     + status_str + ',' +
		'menubar='    + menubar_str + ',' +
		'toolbar='    + menubar_str
	);
}

function popupImages(location, target, width, height) {
	if (! width > 0)  { width = 560;  }
	if (! height > 0) { height = 500; }
	popup(location, target, width, height, true, true);
}

function showFormPart(part)
{
	var natural_fields = Array('name', 'surname', 'age', 'education', 'occupation');
	var juristic_fields = Array('company', 'fax', 'reg_num', 'fax', 'reg_num', 'jur_address', 'quantity_of_copies');
	if (part == 'natural'){
		for(i=0; i < natural_fields.length; i++){
			el = document.getElementById(natural_fields[i]);
			el.style.display = '';
//			for(j=0; j < el.children.length; j++){
//				el.children[j].style.display = 'block';
//			}
		}
		for(i=0; i < juristic_fields.length; i++){
			el = document.getElementById(juristic_fields[i]);
			el.style.display = 'none';
//			for(j=0; j < el.children.length; j++){
//				el.children[j].style.display = 'none';
//			}
		}
	}
	else{
		for(i=0; i < juristic_fields.length; i++){
			el = document.getElementById(juristic_fields[i]);
//			alert(el.innerHTML);
			el.style.display = '';
//			alert(el.innerHTML);
//			for(j=0; j < el.children.length; j++){
//				el.children[j].style.display = 'block';
//			}
		}
		for(i=0; i < natural_fields.length; i++){
			el = document.getElementById(natural_fields[i]);
//			alert(el.innerHTML);
			el.style.display = 'none';
//			alert(el.innerHTML);
//			for(j=0; j < el.children.length; j++){
//				el.children[j].style.display = 'none';
//			}
		}
	}


}

function show_props(obj, objName, line_end) {
   var result = "";
   for (var i in obj) {
      result += objName + "." + i + " = " + obj[i] + line_end;
   }
   return result;
}




var objects_edit_value;
var over_div;
var over_input;

function showList()
{
	var objects_edit = document.getElementsByName('title')[0];
	var postop = 0;
	var posleft = 0;
	for(i=objects_edit; i; i = i.offsetParent){
		posleft += i.offsetLeft;
		postop += i.offsetTop;
	}
	postop = postop+objects_edit.offsetHeight;

	var objects_list = document.getElementById('objects_listing');
//	document.write(show_props(objects_list, 'objects_list', "<br>"));

	var browser = navigator.appName;
	if (browser == 'Microsoft Internet Explorer' && navigator.userAgent.indexOf('Opera') == -1){
		el = document.all.place_for_frame;
		el.innerHTML = '<iframe id="ifr" style="position: absolute;  width: 350px; height: 100px; z-index: 2;" frameborder="no"></iframe>';
		var objects_ifr = document.getElementById('ifr');
		objects_ifr.style.posTop = postop;
		objects_ifr.style.posLeft = posleft;
	}

	objects_list.style.top = postop+'px';
	objects_list.style.left = posleft+'px';
	objects_list.style.display = 'block';

	if (objects_edit.value != objects_edit_value)
		rebuildList(objects_list, objects_edit.value);
	objects_edit_value = objects_edit.value;
}

function rebuildList(list, val)
{
	var list_html = '';
	var div_prop = 'onMouseOver="this.style.backgroundColor = '+"'"+'#000077'+"'"+'; this.style.color = '+"'"+'#FFFFFF'+"'"+';"  onMouseOut="this.style.backgroundColor = '+"'"+'#FFFFFF'+"'"+'; this.style.color = '+"'"+'#000000'+"'"+';" onClick="setEditValue(this.innerHTML)"';
	reg_val = val;
	reg_val = reg_val.replace(/[āa]/gi,'[āa]');
	reg_val = reg_val.replace(/[čc]/gi,'[čc]');
	reg_val = reg_val.replace(/[ēe]/gi,'[ēe]');
	reg_val = reg_val.replace(/[ģg]/gi,'[ģg]');
	reg_val = reg_val.replace(/[īi]/gi,'[īi]');
	reg_val = reg_val.replace(/[ķk]/gi,'[ķk]');
	reg_val = reg_val.replace(/[ļl]/gi,'[ļl]');
	reg_val = reg_val.replace(/[ņn]/gi,'[ņn]');
	reg_val = reg_val.replace(/[šs]/gi,'[šs]');
	reg_val = reg_val.replace(/[ūu]/gi,'[ūu]');
	reg_val = reg_val.replace(/[žz]/gi,'[žz]');
	regex = eval('/^'+reg_val+'/gi');
	for (var i in arr_proj_titles){
		if (val != ''){
			if (arr_proj_titles[i].match(regex)){
				list_html += '<div '+div_prop+'>' + arr_proj_titles[i] + '</div>';
			}
		}
		else{
			list_html += '<div '+div_prop+'>' + arr_proj_titles[i] + '</div>';
		}
	}
	if(list_html == '')
		hideList();
	else{
		list.innerHTML = list_html;
		list.scrollTop = 0;
	}
}

function setEditValue(val){
	var objects_edit = document.getElementsByName('title')[0];
	objects_edit.value=val;
	over_div = 0;
	hideList();
}

function hideList()
{
	if (!(over_input || over_div)){
		objects_edit = document.getElementsByName('title');
		objects_list = document.getElementById('objects_listing');
		browser = navigator.appName;
		if (browser == 'Microsoft Internet Explorer' && navigator.userAgent.indexOf('Opera') == -1){
			el = document.all.place_for_frame;
			el.innerHTML = '';
		}
		objects_list.style.display = 'none';
	}
}
