var span_html=new Array;
var desc_html=new Array;
var text_html=new Array;
var _desc_clicked=0;

function toggleDisclosureWidget(id){var div=document.getElementById(id);if(div.className=='sshow'){div.className='shide';}else{div.className='sshow';}
return(false);}
function toggleOpenWidget(id){var div=document.getElementById(id); vis = div.style; vis.display='block'; return(false);}
function toggleCloseWidget(id){var div=document.getElementById(id); vis = div.style; vis.display='none'; return(false);}
function tcw2(id){setTimeout("alert('hello')",1250); var div=document.getElementById(id); vis = div.style; vis.display='none'; }
function toggleOpenWidget2(id){var div=document.getElementById(id); div.className='sshow'; return(false);}
function toggleCloseWidget2(id){var div=document.getElementById(id); div.className='shide'; return(false);}
function ChangeColor(id){var div=document.getElementById(id); div.className='sort_changed'; return(false);}
function tdw(id){return(toggleDisclosureWidget(id));}
function tow(id){return(toggleOpenWidget(id));}
function tcw(id){return(toggleCloseWidget(id));}
function col(id){return(ChangeColor(id));}

function tgl( whichLayer )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

function copy_name() { document.forms.form.russian.value = document.forms.form.name.value; }

function changepassword(value) {
if (document.form.aparts.checked) {document.form.part.disabled = false; document.form.part.focus();}
else {document.form.part.disabled = true; document.form.part.value = "0";}
return true; }

function trans() {
 val = document.forms.form.name.value;
 val = val.replace(/\./g, ''); val = val.replace(/\…/g, ''); val = val.replace(/\à/g, 'a');  val = val.replace(/\á/g, 'b'); val = val.replace(/\â/g, 'v');  val = val.replace(/\ã/g, 'g'); val = val.replace(/\ä/g, 'd');  val = val.replace(/\å/g, 'e'); val = val.replace(/\¸/g, 'jo');  val = val.replace(/\æ/g, 'zh'); val = val.replace(/\ç/g, 'z');   val = val.replace(/\è/g, 'i'); val = val.replace(/\é/g, 'j');   val = val.replace(/\ê/g, 'k'); val = val.replace(/\ë/g, 'l');   val = val.replace(/\ì/g, 'm'); val = val.replace(/\í/g, 'n');   val = val.replace(/\î/g, 'o'); val = val.replace(/\ï/g, 'p');   val = val.replace(/\ð/g, 'r'); val = val.replace(/\ñ/g, 's');   val = val.replace(/\ò/g, 't'); val = val.replace(/\ó/g, 'u');   val = val.replace(/\ô/g, 'f'); val = val.replace(/\õ/g, 'h');   val = val.replace(/\ö/g, 'c'); val = val.replace(/\÷/g, 'ch');  val = val.replace(/\ø/g, 'sh'); val = val.replace(/\ù/g, 'sch'); val = val.replace(/\ú/g, ''); val = val.replace(/\û/g, 'y');   val = val.replace(/\ü/g, ''); val = val.replace(/\ý/g, 'e');   val = val.replace(/\þ/g, 'ju'); val = val.replace(/\ÿ/g, 'ya');  val = val.replace(/\À/g, 'A'); val = val.replace(/\Á/g, 'B');   val = val.replace(/\Â/g, 'V'); val = val.replace(/\Ã/g, 'G');   val = val.replace(/\Ä/g, 'D'); val = val.replace(/\Å/g, 'E');   val = val.replace(/\¨/g, 'JO'); val = val.replace(/\Æ/g, 'ZH');  val = val.replace(/\Ç/g, 'Z'); val = val.replace(/\È/g, 'I');   val = val.replace(/\É/g, 'J'); val = val.replace(/\Ê/g, 'K');   val = val.replace(/\Ë/g, 'L'); val = val.replace(/\Ì/g, 'M');   val = val.replace(/\Í/g, 'N'); val = val.replace(/\Î/g, 'O');   val = val.replace(/\Ï/g, 'P'); val = val.replace(/\Ð/g, 'R');   val = val.replace(/\Ñ/g, 'S'); val = val.replace(/\Ò/g, 'T');   val = val.replace(/\Ó/g, 'U'); val = val.replace(/\Ô/g, 'F');   val = val.replace(/\Õ/g, 'H'); val = val.replace(/\Ö/g, 'C');   val = val.replace(/\×/g, 'CH'); val = val.replace(/\Ø/g, 'SH');  val = val.replace(/\Ù/g, 'SCH'); val = val.replace(/\Ú/g, '');   val = val.replace(/\Û/g, 'Y'); val = val.replace(/\Ü/g, '');   val = val.replace(/\Ý/g, 'E'); val = val.replace(/\Þ/g, 'JU');  val = val.replace(/\ß/g, 'YA'); val = val.replace(/\—/g, '-'); val = val.replace(/\’/g, ''); val = val.replace(/\“/g, '\"'); val = val.replace(/\”/g, '\"');
 document.forms.form.english.value = val;
}

function st_check(val) {
 //val = document.forms.form.street.value;
 val = val.replace(/ïåðåóëîê/g, '');
 val = val.replace(/ïðîñïåêò/g, '');
 val = val.replace(/óëèöà/g, '');
 val = val.replace(/\ óë\./g, '');
 val = val.replace(/\ óë/g, '');
 val = val.replace(/\óë\. /g, '');
 val = val.replace(/\óë /g, '');
 val = val.replace(/\ ïðîñï\./g, '');
 val = val.replace(/\ïðîñï\./g, '');
 val = val.replace(/\ ïåð\./g, '');
 val = val.replace(/\ïåð\. /g, '');
 val = val.replace(/\./g, '');
 //document.forms.form.street.value = val;
 return val;
}

function st_ttz(val) {
 val = val.replace(/\,/g, '.');
 return val;
}

function showadd(id){return(showadd2(id));}

function showadd2(id) {
var div = document.getElementById(id);
var div2 = document.getElementById('agenadd');
if (document.form.who.value == '3' || document.form.who.value == '4' || document.form.who.value == '6') {div.className='sshow';div2.className='shide';}else{div.className='shide';}
if (document.form.who.value == '3') {div2.className='sshow';}else{div2.className='shide';}
return(false);
}



function span_to_textarea( tid, cols, rows )
{

if ( _desc_clicked )
{
return false;
}
_desc_clicked = 1;
desc_html[ tid ] = document.getElementById( 'tid-text-' + tid ).innerHTML;
document.getElementById( 'tid-text-' + tid ).innerHTML = '<textarea class=edit cols="'+cols+'" rows="'+rows+'" id="edit-'+tid+'" onblur="tid_blur(\''+tid+'\', \'text\')" onkeypress="tid_keypress(event, \''+tid+'\',\'text\')">'+desc_html[tid].replace( /"/g,'&quot;')+'</textarea>';//"'
document.getElementById( 'edit-'+ tid ).focus();
return false;
}

function span_to_input( tid, size )
{

if ( _desc_clicked )
{
return false;
}
_desc_clicked = 1;
desc_html[ tid ] = document.getElementById( 'tid-desc-' + tid ).innerHTML;
document.getElementById( 'tid-desc-' + tid ).innerHTML = '<input id="edit-'+tid+'" class="edit" type="text" size="'+size+'" onblur="tid_blur(\''+tid+'\', \'desc\')" onkeypress="tid_keypress(event, \''+tid+'\',\'desc\')" value="'+desc_html[tid].replace( /"/g,'&quot;')+'" />';//"'
document.getElementById( 'edit-'     + tid ).focus();
return false;
}

tid_blur = function( tid, type )
{
new_text = document.getElementById( 'edit-' + tid ).value;
if( type == 'desc' )
{
tid_save( tid, new_text, type );
}
if( type == 'text' )
{
tid_save( tid, new_text, type );
}
}

tid_keypress = function( evt, tid, type )
{
evt      = evt ? evt : window.event;
new_text = document.getElementById( 'edit-' + tid ).value;
if ( ( evt.keyCode == 13 || evt.keyCode == 3 ) && new_text != "" )
{
tid_save( tid, new_text, type );
}
else if( evt.keyCode == 27 )
{
if( type == 'desc' )
{
document.getElementById( 'tid-desc-' + tid ).innerHTML = desc_html[ tid ];
}
if( type == 'text' )
{
document.getElementById( 'tid-text-' + tid ).innerHTML = desc_html[ tid ];
}
return false;
}
}

tid_save = function( tid, new_text, type )
{
var donotedit = 0;
if ( type == 'desc' )
{
if ( new_text == desc_html[ tid ] )
{
donotedit = 1;
}
_desc_clicked = 0;
sid = 'tid-desc-' + tid;
pole = 'title';
document.getElementById( 'tid-desc-' + tid ).innerHTML = new_text;
}
if ( type == 'text' )
{
if ( new_text == desc_html[ tid ] )
{
donotedit = 1;
}
_desc_clicked = 0;
sid = 'tid-text-' + tid;
pole = 'btext';
document.getElementById( 'tid-text-' + tid ).innerHTML = new_text;
}
if ( donotedit )
{
return false;
}

xajax_update_span(sid, tid, pole, new_text);
return false;
}

/*
 * [\d]
 */
function number(evt)
{
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode :
        ((evt.which) ? evt.which : 0));
    // if 'Arrows' or 'DEL' - for mozilla
    if (charCode == 37 || charCode == 39 || charCode == 46) return true;
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        return false;
    }
    return true;
}

/*
 * [\d-.]
 */
function likephone(evt)
{
	evt = (evt) ? evt : ((window.event) ? event : null);

	if (evt)
	{
		var elem = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
		if (elem)
		{
			var charCode = (evt.charCode) ? evt.charCode :
			((evt.which) ? evt.which : evt.keyCode);

			// if 'Arrows' or 'DEL' - for mozilla
			if (charCode == 37 || charCode == 39 || charCode == 46) return true;

			if ((charCode < 32 ) ||
				(charCode >= 44 && charCode <= 46) ||
				(charCode >= 48 && charCode <= 57))
			{
				return true;
			} else {
				return false;
			}
		}
	}
}
