function SelectAll(fName,Name)      // Выбор/инверсия всех чекбоксов в форме
{
//  f = document.forms.Form;
//	alert (f);
    f = document.forms[fName];
    l = f.length;
    for (i = 0;i < l;i++)  {
       if (f[i].name == Name)  {
            if (f[i].checked)
                f[i].checked = false;
            else
                f[i].checked = true;
       }
    }
}

function CheckAll(Element,Name)
{
    thisCheckBoxes = Element.parentNode.parentNode.parentNode.getElementsByTagName('input');
    for (i = 1; i < thisCheckBoxes.length; i++) {
        if (thisCheckBoxes[i].name == Name) {
            thisCheckBoxes[i].checked = Element.checked;
        }
    }
}

function get_center_coord(width, height){
    var return_obj  = new Object();
    return_obj.x    = 0;
    return_obj.y    = 0;
    if(window.screenLeft && document.body.offsetWidth){
        return_obj.x        += window.screenLeft + Math.ceil(document.body.offsetWidth/2) - Math.ceil(width/2);
        return_obj.y        += window.screenTop + Math.ceil(document.body.offsetHeight/2) - Math.ceil(height/2);
    }else{
        return_obj.x        += Math.ceil(screen.width/2) - Math.ceil(width/2);
        return_obj.y        += Math.ceil(screen.height/2) - Math.ceil(width/2);
    }
    return return_obj;
}

function openWindow(str_url,width,height,scrolls){
    var center_coord        = get_center_coord(width, height);
    if (!scrolls) scrolls = "no";
    else scrolls="yes";
    wnd = window.open(""+str_url, "wnd", "width="+width+",height="+height+", top=" + center_coord.y + ", left=" + center_coord.x + ", titlebar=no, scrollbars="+scrolls+", dependent=no, resizable=yes");
//  wnd.moveTo(center_coord.x, center_coord.y);
    wnd.focus();
    return wnd;
}

function openSndDialog(str_url,width, height){
    var center_coord        = get_center_coord(width, height);
    snd_wnd = window.open(""+str_url, "snd_wnd", "width="+width+",height="+height+", top=" + center_coord.y + ", left=" + center_coord.x + ", titlebar=no, scrollbars=no, dependent=no, resizable=yes");
    snd_wnd.focus();
    return snd_wnd;
}

function openPicWindow(str_url,width,height,title,scrolls){
    var center_coord        = get_center_coord(width, height);
    if (!scrolls) scrolls = "no";
    else scrolls="yes";
    if (!title) title="Picture Window";
    pic_wnd = window.open(""+str_url, "wnd", "width="+width+",height="+height+", top=" + center_coord.y + ", left=" + center_coord.x + ", titlebar=no, scrollbars="+scrolls+", dependent=no, resizable=yes");
    pic_wnd.document.open();
    pic_wnd.document.writeln("<html><head><title>",title,"</title></head>");
    pic_wnd.document.writeln("<body topmargin=0 leftmargin=0 marginwidth=0 marginheight=0 bgcolor=#FFFAF0>");
    pic_wnd.document.writeln("<center><a href='javascript: this.window.close();' onMouseOut='window.status=\"\"' onMouseOver='window.status=\"Закрыть окно\"; return true'><img src=",str_url," border=0 width=",width," height=",height," alt='Закрыть окно'></center>");
    pic_wnd.document.writeln("</body></html>");
    pic_wnd.focus();
    return pic_wnd;
}

function _getElementById(id){
  var item = null;

  if (document.getElementById){
    item = document.getElementById(id);
  } else if (document.all){
    item = document.all[id];
  } else if (document.layers){
    item = document.layers[id];
  }

  return item;
}

function DoDiv(id) {
  var item = _getElementById(id);

  if (!item){
  } else if (item.style){
    if (item.style.display == 'none'){
        item.style.display = '';
    } else {
        item.style.display = 'none';
      }
  } else {
      item.visibility = 'show';
  }
}

function ShowOrHide(d1, d2) {
  if (d1 != ''){
      DoDiv(d1);
  }

  if (d2 != ''){
      DoDiv(d2);
  }
}

function show_login () {
	var login=document.getElementById("login");
	if (login.style.display == "none") {
		login.style.display = "block"; 
	} else { 
		login.style.display = "none";  
	}	
	return false;
}

// Show Picture when MouseOver from object
function show_pic(text, evt) {
evt = (evt) ? evt : event;
    if (evt) {
var elem = document.getElementById("picblock");
  elem.innerHTML = text;
  elem.style.display = 'block';
  elem.style.position = 'absolute';
  var coords = getEventCoords(evt);
  elem.style.left = coords.left;
  elem.style.top = coords.top;
    }
}
function getEventCoords(evt) {
    var coords = {left:0, top:0};
    if (evt.pageX) {
        coords.left = evt.pageX;
        coords.top = evt.pageY;
    } else if (evt.clientX) {
        coords.left = evt.clientX + document.body.scrollLeft - document.body.clientLeft;
        coords.top = evt.clientY + document.body.scrollTop - document.body.clientTop;
        if (document.body.parentElement && document.body.parentElement.clientLeft) {
            var bodParent = document.body.parentElement;
            coords.left += bodParent.scrollLeft - bodParent.clientLeft;
            coords.top += bodParent.scrollTop - bodParent.clientTop;
        }
    }
    return coords;
}
function hide_pic() {
 var elem = document.getElementById("picblock").style;
 elem.display = 'none';
}

function checkMail(email)	{
    var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
    if (filter.test(email)) {
        return true;
	}
    return false;
}



