function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function addsellapp() {
   remote = window.open("","remotewin","width=550,height=1000,scrollbars,resizable=yes,left,top");
   remote.location.href = "http://www.makler.ru/cgi-bin/app_sell/add.pl?action=frommain";
   remote.opener.name = "opener";
}
   
function addsdapp() {
   remote = window.open("","remotewin","width=550,height=1000,scrollbars,resizable=yes,left,top");
   remote.location.href = "http://www.makler.ru/cgi-bin/app_sd/add.pl?action=frommain";
   remote.opener.name = "opener";
}
 
function makefrommain() {
   remote = window.open("","remotewin","width=480,height=550,scrollbars,resizable=yes,left,top");
   remote.location.href = "http://www.makler.ru/cgi-bin/agency/ag_add.pl?action=frommain";
   remote.opener.name = "opener";
}

function HideOthRayList(el, HideRayListId) {
  var othray=document.getElementById(HideRayListId);
  if (el.selectedIndex>0) {				// Если выбран р-н в одном из списков, 
	othray.style.visibility = 'hidden';	// то запретить (спрятать) другой
  }
  else {
	othray.style.visibility = 'visible';
  }
  return false;
}

function ChkFill(fld,setfocus,chkempty,chkrus,chkdig,chkdigmin,chkdigmax) {
 if (chkempty) {
	if (fld.value=='' || /^[^А-Яа-яA-Za-z\d]+$/.exec(fld.value)) {
	  if (setfocus){fld.focus();}
	  fld.style.backgroundColor='pink';
	  return false;
	}
	else {
	  fld.style.backgroundColor='white';
	}
  }

  if (chkrus) {
	if ( /^[^А-Яа-я\d]+$/.exec(fld.value) || /[A-Za-z~!@#$%^&*=+?<>\\]+/.exec(fld.value)) {
	  if (setfocus){fld.focus();}
	  fld.style.backgroundColor='pink';
	  alert('Недопустимые символы')
	  return false;
	}
	else {
	  fld.style.backgroundColor='white';
	}
  }

  if (chkdig) {
	if ( ! /^\d+([.,]\d+)? ?$/.exec(fld.value) ) {
	  if (setfocus){fld.focus();}
	  fld.style.backgroundColor='pink';
	  alert('Должно быть число')
	  return false;
	}
	else {
	  fld.style.backgroundColor='white';
	}
  
	if (chkdigmin) {
	  if (fld.value<chkdigmin) {
		if (setfocus){fld.focus();}
		fld.style.backgroundColor='pink';
		alert('Должно быть не меньше '+chkdigmin)
		return false;
	  }
	  else {
		fld.style.backgroundColor='white';
	  }
	}
	if (chkdigmax) {
	  if (fld.value>chkdigmax) {
		if (setfocus){fld.focus();}
		fld.style.backgroundColor='pink';
		alert('Должно быть не больше '+chkdigmax)
		return false;
	  }
	  else {
		fld.style.backgroundColor='white';
	  }
	}
  }
}


function src(theRow, thePointerColor) {
	if (thePointerColor == '' || typeof(theRow.style) == 'undefined') {
      return false;
    }
    if (typeof(document.getElementsByTagName) != 'undefined') {
      var theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
      var theCells = theRow.cells;
    }
    else {
      return false;
    }

    var rowCellsCnt  = theCells.length;
    for (var c = 0; c < rowCellsCnt; c++) {
      theCells[c].style.backgroundColor = thePointerColor;
    }
	return true;
}


function getElementPosition(offsetTrail){
	var offsetLeft = 0;
        var offsetTop = 0;
        while(offsetTrail) {
        	offsetLeft += offsetTrail.offsetLeft;
                offsetTop += offsetTrail.offsetTop;
                offsetTrail = offsetTrail.offsetParent;
        }
        return { left:offsetLeft, top:offsetTop }
}

function HideHlp() {
  var div = document.getElementById('current_footnote');
/*div.className = 'footnote_new'; - не нужно */
  div.style.display = 'none';  /*Прячем окно*/
  return false;
}

function ShowHlp(evt, id) {
  var winWidth = document.body.clientWidth;
  var evt = evt || window.event;
  var o = evt.target || evt.srcElement;
  var div = document.getElementById('current_footnote');
  var coords = getElementPosition(o);
  div.innerHTML = '<a href="#" onclick="return HideHlp()">'+
	  '<img src="images/close.gif" height="13" width="13" border="0" id="close_image" /></a>'+
	  '<div style="padding-left:7px">' + document.getElementById(id).innerHTML + '</div>';
  div.className = 'footnote_new_active';
  div = document.getElementById('current_footnote');
  var w = 200;

/*div.style.top = (coords.top + o.offsetHeight) + 'px';
  if((winWidth - coords.left) < w) 
  	div.style.left = (coords.left  - 10 - (w - (winWidth - coords.left)))+ 'px';
  else
    div.style.left = coords.left + 'px';
*/
  div.style.top = 50+'px';		/*Координаты окна*/ 
  div.style.left =30+'px';		/*В IE поле списка проступает сквозь фон, поэтому слева*/

  div.style.display = 'block';	/*Делает окно видимым*/
  evt.cancelBubble = true;
  return false;
}
