//открытие ссылки в новом окне

function ShowWindows(a_resizable, a_width, a_height, a_toolbar){
var objElement
objElement=event.srcElement
while (objElement.tagName!="A"){objElement=objElement.parentElement;}
if (objElement.tagName=="A"){
var str_resizable="no";
var int_width=500;
var int_height=500;
var str_toolbar="no";
var int_deltaHeight=60;

if (a_resizable!=undefined){str_resizable=a_resizable};
if (a_width!=undefined){int_width=a_width};
if (a_height!=undefined){int_height=a_height};
if (a_toolbar!=undefined){str_toolbar=a_toolbar};
if (str_toolbar=="yes") {int_deltaHeight=150;};

int_left=(screen.width-15-int_width)/2;
if (int_width>screen.width-15){
	int_width=screen.width-15;
	int_left=0;
}
int_top=(screen.height-int_deltaHeight-int_height)/2;
if (int_height>screen.height-int_deltaHeight){
	int_height=screen.height-int_deltaHeight;
	int_top=0;
}
window.open(objElement.href,objElement.target,"resizable=" + str_resizable + ",scrollbars=" + str_resizable + ",toolbar=" + str_toolbar + ",width="+int_width+",height="+int_height+",left="+int_left+", top="+int_top);
event.returnValue = false;
}
}



//подсветка кнопки

function ImgHover(a_FileName){
	if (event.srcElement.tagName=="IMG"){
		if (a_FileName!=undefined){
			if (event.srcElement.DefSrcFileName==undefined){event.srcElement.DefSrcFileName=event.srcElement.src;};
			event.srcElement.src=a_FileName;
		}
		else{
			event.srcElement.src=event.srcElement.DefSrcFileName;
		}
	}
}

//смена бакграунда у незаполненого поля формы при клике

function errfocus() {

if (window.event.srcElement.className=="inp_o_err") {window.event.srcElement.className="inp_o_err_f"};
}

//открытие-закрытие подменю
	function Collapse(a_SubName) {
	document.getElementById(a_SubName).className =(document.getElementById(a_SubName).className == "collapsed")?"":"collapsed";
	returnValue = false;
	}


//Тестирует строку на целое цисло и показывает ошибку
function testNum(obj, err) {
  if (obj.value.match(/[^\d-]/)!=null) {
    alert(err);
    obj.focus();
    return false;
  } else
    return true;
}

//Тестирует строку на целое положительное цисло
function testNumPlus(obj, err) {
  if ((obj.value.match(/[^\d]/)!=null)||((obj.value.match(/[^\d]/)==null)&&(parseInt(obj.value)<=0))) {
    alert(err);
    obj.focus();
    return false;
  } else
    return true;
}


//Тестирует строку на предмет пустотности и показывает ошибку
function testS(obj, err) {
  if (obj.value.length == 0) {
    alert(err);
    obj.focus();
    return false;
  } else
    return true;
}

//Тестирует является ли строка e-mail адресом и показывает ошибку
function testEmail(obj, err) {
  if (is_email(obj.value)== null) {
    alert(err);
    obj.focus();
    return false;
  } else
    return true;
}

//Проверяет, является ли строка e-mail адресом
function is_email(str) {
  return str.match(/^.+@.+\..+$/);
}

//Тестирует пару паролей на предмет пустотности и на совпадение и показывает ошибку
function testPas(obj1, obj2, err1, err2, err3) {
  if (obj1.value.length == 0) {
    alert(err1);
    obj1.focus();
    return false;
  }
  if (obj2.value.length == 0) {
    alert(err2);
    obj2.focus();
    return false;
  }
  
  if (obj1.value!=obj2.value) {
    alert(err3);
    obj1.value="";
    obj2.value="";
    obj1.focus();
    return false;
  }
  return true;    
}
