/*
 * Общие скрипты
 */


function strtrim( str )
{
  var tmp = '';
  for (var i = 0; i < str.length; i++) {
    if (
      (str.charCodeAt(i)!=32) &&
      (str.charCodeAt(i)!=10) &&
      (str.charCodeAt(i)!=13)
    )
    {
      tmp += str.charAt(i);
    }
  }
  return tmp;
}


/**
 * Возвращает true если параметр -- число
 */
function isNumeric( val )
{
	var re = /^\d+$/;
	
	return (re.test(val) == true);
}


/**
 * Открыть отдельное окно для просмотра полноразмерной картинки
 */
function popupImage( url, w, h ) {
	var params = '';
	w = w+20;
	h = h+30;
	params = 'dependent=1,width='+w+',height='+h+',scrollbars=no,menubar=no,status=no,location=no,fullscreen=no,directories=no,resizable=yes';
	var win = window.open( url, "popupImage", params );
	win.focus();
}


/**
 * Открыть отдельное окно для просмотра страницы (например, новости)
 */
function popup( url, name ) {
	var params = '';
	w = 400;
	h = 300;
	params = 'dependent=1,width='+w+',height='+h+',scrollbars=yes,menubar=no,status=no,location=no,fullscreen=no,directories=no,resizable=yes';
	var win = window.open( url, name, params );
	win.focus();
}


/*
 * from windows.js
 * Popup windows
 *
 */

var activeWindow="";
var timer;

function getLayer(layerName) {
    if ( document.getElementById )
        return document.getElementById(layerName).style;
    if ( document.all )
        return document.all[layerName].style;
    if ( document.layers )
	return document.layers[layerName];
    return 0;
}
    	       
function showLayer(layerName) {
    layer = getLayer(layerName);
    layer.visibility = "visible";
    layer.display = "block";
}
				        
function hideLayer(layerName) {
    layer = getLayer(layerName);
    layer.visibility = "hidden";
    layer.display = "none";
}

function switchWindow(windowName) {
    if ( activeWindow != windowName ) {
    	showWindow(windowName);
    } else {
    	hideActiveWindow();
    }
}

function showWindow(windowName) {
    if ( activeWindow != "" ) {
	hideLayer( activeWindow );
    }
    activeWindow=windowName;
    showLayer( activeWindow );
    dontHideWindow();
}

function hideActiveWindow() {
    if ( activeWindow != "" ) {
		hideLayer( activeWindow );
    }
    activeWindow = "";
}


/* Set timer to hide active window */
function hideWindow() {
    if ( activeWindow != "" ) {
		timer = setTimeout("hideActiveWindow()", 100);
    }
}

/* Cancel previously set timer to prevent hiding active window */
function dontHideWindow() {
    clearTimeout( timer );
}



