// тестирование подключения этого модуля
function mtest()
{
	alert('test');
}

/***********************  Работа с элементами *********************************/

// возвращает элемент по его id 
function findElement(elem_id)
 {
 	if (document.getElementById(elem_id)) // dom browsers
 	 {
 	 	return document.getElementById(elem_id); 
 	 }
 	else
 	 {
      if (document.all) // older ie-browsers
       { 
       	 return document.all(elem_id);
       }
     }  
 }

// очистить элемент
function f_clr(elem_id)
 {
	findElement(elem_id).value = '';
 }

// изменить высоту элемента
function el_h(elem_id, delta, point)
 {
 	if(point == '+')
 		findElement(elem_id).style.height = findElement(elem_id).offsetHeight + delta;

 	if(point == '-' && findElement(elem_id).offsetHeight > delta)
 		findElement(elem_id).style.height = findElement(elem_id).offsetHeight - delta;

 	if(point == '')
 		findElement(elem_id).style.height = delta;
 }

/***********************  Работа с окнами (документом) *********************************/

// открыть окно
function wopen(theURL, w, h)
{
  var sX = (screen.width-w)/2;
  var sY = (screen.height-h)/2;

  window.open(theURL,'','status=yes,  width='+w+',height='+h+',screenX='+sX+',screenY='+sY+',top='+sY+',left='+sX);
}

// открыть окно
function w_open(theURL, type)
 {
  w = 1024;
  h = 768;

  var sX = (screen.width-w)/2;
  var sY = (screen.height-h)/2;


  if(type == 'html')
  	window.open(theURL,'','scrollbars=no, menubar=no, status=no, resizable=yes, toolbar=no, location=no,  width='+w+',height='+h+',screenX='+sX+',screenY='+sY+',top='+sY+',left='+sX);

  if(type == 'm2m')
  	window.open(theURL,'','scrollbars=yes, menubar=no, status=no, resizable=yes, toolbar=no, location=no,  width='+w+',height='+h+',screenX='+sX+',screenY='+sY+',top='+sY+',left='+sX);

  if(type == 'popup')
  	window.open(theURL,'','scrollbars=no, menubar=no, status=no, resizable=yes, toolbar=yes, location=no,  width='+w+',height='+h+',screenX='+sX+',screenY='+sY+',top='+sY+',left='+sX);

 }



function popup(url)
{

	var win_w, win_h;
	win_w = screen.availWidth - 10;
	win_h = screen.availHeight - 40;

	myWindow = window.open(url, "", "top=1, left=1, width=" + win_w + ", height=" + win_h + ", toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no");
	if (!myWindow.opener) myWindow.opener = self;
	
}

// получить параметры, переданные через GET
function get_params(key)
 {
 	get = window.location.search.substr(1); // все после ?

	param_couples = get.split('&');

	var result = new Array(param_couples.length);

	for(i in param_couples)
	 {
	  couple = param_couples[i].split('=');
	  result[couple[0]] = couple[1];
	 }

	if(key)
		return result[key];
	else
		return result;
}

// refresh
function _refresh()
{
	window.location = window.location; 
}

/***********************  Работа с изображениями *********************************/

// открытие картинки в отдельном окне по ее размеру
function img_big(path, w, h)
{
	if( (w+30)>screen.width || (h+30)>screen.height )
	{
		var scroll_on = 'yes';
		var window_width = Math.floor(screen.width - 10);
		var window_height = Math.floor(screen.height - 100);
		var x_pos = 0;
		var y_pos = 0;
	}
	else
	{
		var scroll_on = 'no';
		var window_width = Math.floor(w);
		var window_height = Math.floor(h);
		var x_pos = Math.floor((screen.width - w)/2);
		var y_pos = Math.floor((screen.height - h)/2);
	}
	
	var html = '<html><head><title>Просмотр изображения</title><META HTTP-EQUIV="Pragma" CONTENT="no-cache"></head><body style="margin:0;padding:0;text-align:center"><img src="' + path + '" /></body></html>';
	
	img_window = window.open('', '', 'height=' + window_height + ', width=' + window_width + ', location=no, scrollbars=' + scroll_on + ', status=no, menubar=no, toolbar=no, resizable=yes, top=' + y_pos + ', left=' + x_pos );
	img_window.document.write(html);
	img_window.document.close();
}

/***********************  Работа со всплывающими подсказками *********************************/

// отображение help-бокса
function salt(mes)
 {
      document.onmousemove=malt;

      var help = findElement('help');

      help.innerHTML = mes;

      // если IE, то можно сразу вызвать позиционирование по курсору
      if (typeof window.event !="undefined")
      	malt();

      help.style.visibility = 'visible';
 }

// сокрытие help-бокса
 function halt()
 {
      findElement('help').style.visibility = 'hidden';
       document.onmousemove="";
 }

// возвращает body, в зависимости от броузера
function truebody()
 {
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
 }

// передвигает подсказку за мышью
function malt(e)
 {
	var help = findElement('help').style;

    if (typeof e != "undefined") {
      // Mozilla
      xcoord = e.pageX
      ycoord = e.pageY
    }
    else if (typeof window.event !="undefined") {
      // IE browser
      xcoord = truebody().scrollLeft+event.clientX
      ycoord = truebody().scrollTop+event.clientY
    }

 	 help.left = xcoord + 10;
 	 help.top  = ycoord + 10;
 }
 
 /***********************  Работа со ссылками *********************************/
 
 // no in dex ссылка
 function ou(u, t, _target, _class)
 {
	t = (t == undefined || t == 0) ? u : t;
	u = u.replace('http://', '');
	_target = (_target == undefined) ? '' : 'target="' + _target + '" ';
	_class = (_class == undefined) ? '' : 'class="' + _class + '" ';
 
	document.write('<'+'a '+_class+_target+'hr'+'ef=\"ht'+'tp:\/\/' + u + '">' + t + '<\/a>');
 }