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


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;
}


/**
 * Проверить форму подписки на рассылку
 *
 * Форма должна иметь имя FORM_SUBSCRIBE
 * и содержать поле типа text с именем EMAIL
 */
function checkFormSubscribe() 
{	
	var email = '';
	var re = /^[a-z0-9\-_\.]+@([a-z0-9\-_]+\.)+(com|net|org|info|biz|name|[a-z]{2})$/i;

	email = document.FORM_SUBSCRIBE.EMAIL.value;
	email = strtrim( email );
	if ( email == '' ) {
		alert('Введите адрес email на который будет приходит рассылка');
		document.FORM_SUBSCRIBE.EMAIL.focus();
		return false;
	}

	if ( !re.test(email) ) {
		alert('Указан неправильный адрес email');
		document.FORM_SUBSCRIBE.EMAIL.focus();
		return false;
	}

	return true;
}


/**
 * Проверить форму отправки вопроса в FAQ
 *
 * Форма должна иметь имя FORM_FAQ
 * и содержать поле типа text с именем QUESTION
 */
function checkFormFAQ() {
	if ( strtrim(document.f.QUESTION.value) == '' ) {
       	alert('Необходимо заполнить текст вопроса.');
		document.f.QUESTION.focus();
		return false;
	} 
	return true;
}



/**
 * Открыть отдельное окно для просмотра полноразмерной картинки
 */
function popupImage( url, w, h ) {
	var params = '';
	w = w+40;
	h = h+40;
	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 );
}

<!--
if (document.images) {
image1on = new Image();
image1on.src = "/images/logo_anim.gif";
image1off = new Image();
image1off.src = "/images/logo_noanim.gif";
}

function turnOn(imageName) {
if (document.images) {
document[imageName].src = eval(imageName + "on.src");
}
}

function turnOff(imageName) {
if (document.images) {
document[imageName].src = eval(imageName + "off.src");
}
}
-->
