// Функция открытия нового окна
function WindowOpen (vUrl, vWidth, vHeight, vScroll, vResize) {
	var left = (screen.availWidth - vWidth) / 2;
	var top = (screen.availHeight - vHeight) / 2;
	if (!vScroll) vScroll = "no";
	if (!vResize) vResize = "no";
	wId = window.open (vUrl, "NewWin"+GetRand(), "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars="+vScroll+",resizable="+vResize+",left="+left+",top="+top+",width="+vWidth+",height="+vHeight);
	wId.focus ();
}

// Функция отображения изображения
function WOImage (vPart, vImg, vWidth, vHeight) {
	WindowOpen ("image.php?part="+vPart+"&id="+vImg, vWidth, vHeight);
}

// Функция случайного числа
function GetRand () {
	result = "";
	result = Math.random()+"1";
	result = result.split(".");
	return result[1];
}

function stringTrim (strToTrim) {
	var tmp_str = new String (strToTrim);
	return (tmp_str.replace (/^\s+|\s+$/g, ""));
}

// Функция, возвращающая позицию элемента (слева)
function GetElementOffsetLeft (element) {
	if (element.offsetParent)
		return element.offsetLeft + GetElementOffsetLeft (element.offsetParent);
	else
		return element.offsetLeft;
}

// Функция, возвращающая позицию элемента (сверху)
function GetElementOffsetTop (element) {
	if (element.offsetParent)
		return element.offsetTop + GetElementOffsetTop (element.offsetParent);
	else
		return element.offsetTop;
}

// Функция, возвращающая высоту элемента
function GetElementOffsetHeight (element) {
	return element.offsetHeight;
}

// Функция проверки формы авторизации
function CheckFrmAuth () {
	var error = 0;
	var validtext="^[0-9A-Za-zА-Яа-я._-]{1,}$";
	if (frmAuth.auth_login.value=='' && error==0) { alert ('Заполните поле "Логин".'); error = 1; }
	if (frmAuth.auth_login.value.match(validtext)==null && error==0) { alert ('Введите корректный "Логин"'); error = 1; }
	if (frmAuth.auth_password.value=='' && error==0) { alert ('Заполните поле "Пароль".'); error = 1; }
	if (frmAuth.auth_password.value.match(validtext)==null && error==0) { alert ('Введите корректный "Пароль"'); error = 1; }
	if (error==0) {
		frmAuth.submit ();
	}
}

// Функция отображения большого изображения для модуля "Фотогаллерея"
function ShowGalleryImg (vSessionId, vModule, vId, vWidth, vHeight) {
	WindowOpen ("/template/" + vModule + "/view-big-image.php?ZSID=" + vSessionId + "&id=" + vId, vWidth, vHeight);
}

// Функция pop-up голосования
function VotingAnswer (vSessionId, vModule, vId) {
//	vAllInput = eval ("FrmVoting" + vId + ".all");
	o = document.getElementById("FrmVoting" + vId);
	vAllInput = o.elements;
	for (i=0; i<vAllInput.length; i++)
	{
	 if (vAllInput[i].tagName=="INPUT") 
	 {
	  if (vAllInput[i].type=="radio" && vAllInput[i].checked==true) 
	  {
	   WindowOpen ("/template/" + vModule + "/answer.php?ZSID=" + vSessionId + "&id=" + vId + "&answer=" + vAllInput[i].value, "300", "150");
	  }
	 }
	}
}

// Показ результатов голосования
function VotingShowResult (vSessionId, vModule, vId, vAll) {
	WindowOpen ("/template/" + vModule + "/show.php?ZSID=" + vSessionId + "&id=" + vId + "&all=" + vAll, "500", "400", "yes");
}

function CatalogCategoryRotate(CategoryNum){
 var l = document.getElementById('l_category_'+CategoryNum);
 var i = document.getElementById('i_category_'+CategoryNum);
// alert (l.style.display);
 if(l && i)// && l.style.display)
 {
  if( l.style.display == 'none' )
  {
   l.style.display = '';
   i.src='/images/tree-minus.gif';
  }
  else
  {
   l.style.display = 'none';
   i.src='/images/tree-plus.gif';
  }
 }
 return false;
}

// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
//if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var MouseX = 0
var MouseY = 0

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    MouseX = event.clientX + document.body.scrollLeft
    MouseY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    MouseX = e.pageX
    MouseY = e.pageY
  }  
  // catch possible negative values in NS4
  if (MouseX < 0){MouseX = 0}
  if (MouseY < 0){MouseY = 0}  
  return true
}

function ApplicationMouseOver(oname){
 o = document.getElementById(oname);
 if(o)
 {
  o.style.left = MouseX-350;
  o.style.top = MouseY+5;
  o.style.display = 'block';
 }
}

function ApplicationMouseOut(oname){
 o = document.getElementById(oname);
 if(o)
 {
  o.style.display = 'none';
  o.style.left = 0;
  o.style.top = 0;
 }
}

function WinAdd2Cart (vProductID) {
 WindowOpen ('add2cart.php?product_id='+vProductID, 300, 130);
}
