function MM_openBrWindow(theURL,winName,features) { //v2.0
  oNewWindow = window.open(theURL,winName,features);
  oNewWindow.focus();
  return oNewWindow;
}

function ow(url,namewindow,width,height)
{
	
	var myWin=window.open(url,namewindow,'width='+width+',height='+height+' toolbar=no scrollbars=yes resizable=yes');
	myWin.focus();
}


function ShowHideSubMenu(id) {
		
	if(!document.all[id]) return true;
    
	if (navigator.appName == "Netscape")
	{
		sub = document.getElementById(id);
		if (sub.className == 'showsubmenu')
			sub.className = 'hidesubmenu';
		else
			sub.className = 'showsubmenu';
     	}
     	else
     	{
		sub = document.all[id];
		if (sub.className == 'showsubmenu')
			sub.className = 'hidesubmenu';
		else
			sub.className = 'showsubmenu';
	}
	return false;
}

function sh(nameDiv)
{

if (navigator.appName == "Netscape")
	{
	  if(document.getElementById(nameDiv).style.display=='none')
		document.getElementById(nameDiv).style.display = 'block';
	  else
		document.getElementById(nameDiv).style.display = 'none';
	}
else
	{
	  eval('s='+nameDiv+'.style.display;');
	  if(s=='none')
		  eval(nameDiv+'.style.display="block";');
	  else
		  eval(nameDiv+'.style.display="none";');
	}
}

function ShowField(tr_id,tr_space_id,tr_space_ch_id,field_id)
{
	if(document.all[tr_id] != null)
		document.all[tr_id].style.display = 'block';
	if(document.all[field_id] != null)
		document.all[field_id].disabled = false;
	if(document.all[tr_space_id] != null)
		document.all[tr_space_id].style.display = 'block';
	if(document.all[tr_space_ch_id] != null)
		document.all[tr_space_ch_id].style.display = 'none';
}

function HideField(tr_id,tr_space_id,tr_space_ch_id,field_id)
{
	if(document.all[tr_id] != null)
		document.all[tr_id].style.display = 'none';
	if(document.all[field_id] != null)
		document.all[field_id].disabled = true;
	if(document.all[tr_space_id] != null)
		document.all[tr_space_id].style.display = 'none';
	if(document.all[tr_space_ch_id] != null)
		document.all[tr_space_ch_id].style.display = 'block';
}

function rotateImages() {
	if (document.images) {
		for (var i=0; i<rotateImages.arguments.length; i+=2) {
			document.all[rotateImages.arguments[i]].src = rotateImages.arguments[i+1];
		}
	}
}


function hlc(col,n) {
	r=1;	//количество строк в таблице
	eval('l'+n+'.style.background="'+col+'";');
//c0_0.style.background='red';
	for(i=0;i<r;i++)
		eval('c'+n+'_'+i+'.style.background="'+col+'";');
}

function AddAddressatRow(name, AddressatId, AddressatName)
{
//  tab = window.opener.document.all['tab_'+name];
  tab = window.opener.document.getElementById('tab_'+name);
//  LastRowIndex = window.opener.document.all['tr_last'].rowIndex;
  LastRowIndex = window.opener.document.getElementById('tr_last');
  if(tab == null)
    return false;
  tab.style.display = "block";
  row = tab.insertRow(LastRowIndex);
  row.id = AddressatId;

  cell = row.insertCell(0);
  cell.innerHTML = AddressatName+"<input type='hidden' name='addressat["+AddressatId+"]' value='"+AddressatId+"' />";
}

function AddContactRow()
{
  tab = document.getElementById('tab_ur');
  LastRowIndex = document.getElementById('tr_last_row').rowIndex;
  if(tab == null)
    return false;

  col = document.getElementById('rows_inserted').value;
  col++;
  
  ind = 0;
  bgcolor = "#a0a0a0"

  if (col != 1) {
      row = tab.insertRow(LastRowIndex + ind);
      cell = row.insertCell(0);
      cell.height = 5;
      ind++;

      row = tab.insertRow(LastRowIndex + ind);
      cell = row.insertCell(0);
      cell.height = 1;
      cell.bgColor = bgcolor;
      ind++;
    
      row = tab.insertRow(LastRowIndex + ind);
      cell = row.insertCell(0);
      cell.height = 5;
      ind++;
  } else {
      row = tab.insertRow(LastRowIndex + ind);
      cell = row.insertCell(0);
      cell.height = 5;
      ind++;
  }

  row = tab.insertRow(LastRowIndex + ind);
  cell = row.insertCell(0);
  cell.innerHTML = "Фамилия, имя, отчество";
  ind++;

  row = tab.insertRow(LastRowIndex + ind);
  cell = row.insertCell(0);
  cell.innerHTML = "<input type='text' name='reg_ur[contact]["+ col +"][name]' value='' size='50' maxlength='100'>";
  ind++;

  row = tab.insertRow(LastRowIndex + ind);
  cell = row.insertCell(0);
  cell.height = 10;
  ind++;

  row = tab.insertRow(LastRowIndex + ind);
  cell = row.insertCell(0);
  cell.innerHTML = "Должность";
  ind++;

  row = tab.insertRow(LastRowIndex + ind);
  cell = row.insertCell(0);
  cell.innerHTML = "<input type='text' name='reg_ur[contact]["+ col +"][position]' value='' size='50' maxlength='100'>";
  ind++;

  document.getElementById('rows_inserted').value = col;
}

function open_add_window()
{
    MM_openBrWindow('/cabinet/add_addressat/','add_object','scrollbars=1, resizable=1, width=350, height=550');
}
