// Функция вывода дополнительной информации в отдельном окне
function enlarge(winText, winWidth, winHeight, winTitle) {
var posCode = '';
if (document.all || document.layers || document.createTextNode) {
	posX = Math.round((screen.width - winWidth) / 2);
	posY = Math.round((screen.height - winHeight) / 2);
	posCode = (document.all)? 'left='+posX+',top='+posY : 'screenX='+posX+',screenY='+posY;
}
cardWindow = window.open('','_blank','menubar=no,toolbar=no,scrollbars=yes,status=yes,width='+winWidth+',height='+winHeight+','+posCode);
cardWindow.document.open();
cardWindow.document.write('<html><head><title>banki.ru &#151 '+winTitle+'<\/title><\/head>');
cardWindow.document.write('<link rel=\"stylesheet\" type=\"text/css\" href=\"/banki_main.css\"><\/head>');
cardWindow.document.write('<body bgcolor="#FFFFFF" style="margin:1em;">');
cardWindow.document.write('<p>'+winText+'</p>');
cardWindow.document.write('<p style=\"text-align: right;\"><a href="#" onClick="window.close()" style="color:#F30;">[X] Закрыть окно<\/a></p><\/body><\/html>');
cardWindow.document.close();
cardWindow.focus();
}

// Получение элемента по ID
function $ob(A){
    return document.all ? document.all[A] : document.getElementById(A)
}

// Функция изменения src картинки
function ChangePicSrc(id,url) {
	if(url!="" && id!="") {
		try {
			document.getElementById(id).src = url;
		}
		catch(e){};
	}
}

// Функция предзагрузки картинок
function MM_preloadImages() {
	var d=document; if(d.images) {
		if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}
  	}
}

// Функция работы с клавиатурой
function keyInit(formName) {
	if (document.getElementById) {
		document.onkeydown = keyAction(formName);
	}
}

// Функция работы с клавиатурой
function keyAction(formName) {

	if(!formName) formName = 'REPLIER';

    var code;
	var e = window.event;
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;

	if ((code == 13) && (e.ctrlKey == true)) document.forms[formName].submit();
}

// Функция вывода справки
function showRef(id){
	var div1 = document.getElementById('block1_view_'+id);
	var div2 = document.getElementById('block2_view_'+id);
	div1.style.display = (div1.style.display != 'none' ? 'none' : 'block');
	div2.style.display = (div1.style.display != 'none' ? 'none' : 'block');
	return false;
}

function inNewWindow(link) {
	nWindow = window.open(link,'_blank');
	nWindow.focus();
}

// Служебные функции
// код функций getPageScroll() и getPageSize() взят из бибилиотеки Lightbox2 (http://www.huddletogether.com/projects/lightbox2/)

// Returns array with x,y page scroll values.
// Core code from - quirksmode.com
function getPageScroll(){
	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) { // all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;
	}

	arrayPageScroll = new Array(xScroll,yScroll)
	return arrayPageScroll;
}

// Returns array with page width, height and window width, height
// Core code from - quirksmode.com
// Edit for Firefox by pHaez
function getPageSize(){

	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}
	else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}


	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth;
		}
		else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}
	else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	}
	else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = xScroll;
	} else {
		pageWidth = windowWidth;
	}

	arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight)
	return arrayPageSize;
}

// ---------------------------------------------------

function showSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}

// ---------------------------------------------------

function hideSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}


// Работа с блоком вывода информации над контентом страницы
// *****************************************************************************

// Формирование блока оверлэя
function makeOverlay() {
	hideSelectBoxes();
	var overBox = document.getElementById('overlay');
	overBox.style.display = 'block';
	// Назначаем прозрасность элементу
	if(/MSIE/.test(navigator.userAgent)) { overBox.style.filter = 'alpha(opacity=80)';} //Если это контуженый по колено Осел
	else { overBox.style.opacity = 0.8;} // коли нормальный браузер

	// Устанавливаем высоту div'а
	var wSize = getPageSize();
	overBox.style.height = wSize[1];

	return false;
}

function closeOverlay() {
	showSelectBoxes();
	var overBox = document.getElementById('overlay');
	overBox.style.display = 'none';
	overBox.innerHTML = '';

	var infoBox = document.getElementById('infoBox');
	infoBox.style.display = 'none';
	infoBox.innerHTML = '';
}


// Создание контейнера для показа видео
function makeVideoBox(videoWidth, videoHeight, videoNote){
	makeOverlay();
	var infoBox = document.getElementById('infoBox');
	infoBox.style.display = 'block';

	// Устанавливаем отступ от верхнего края до места показа ролика
	var wSize = getPageSize();
	var wScroll = getPageScroll();
	infoBox.style.top = wScroll[1]+wSize[3]/2-videoHeight/2;

	var infoContent = '<table class="videoView" align="center" style="width: '+videoWidth+';"> '
				+'<tr><td class="video">';
	infoContent += '<div id="overlayPlayer"></div>';
	infoContent += '</td><td class="close"><img onClick="closeOverlay(); return false;" '
				+'src="/_com/ico_close_13x13_grey.gif" width="13" height="13" border="0" alt="[x]" title="закрыть" /></div>'
	infoContent += '</td></tr>';
	if(videoNote){
		infoContent +='<tr><td colspan="2" class="videoNote">'+videoNote+'</td></tr>';
	}
	infoContent += '</table>';
	infoBox.innerHTML = infoContent;
};

// *** Показ видео - настройка и запуск видеоролика *************************************
// *****************************************************************************
function showVideo(vURL, vWidth, vHeight, vText, vEvent1, vEvent3, vShowCounterId) {
	// Если функцию вызвали без параметров - не работаем
	if(!arguments.length) return false;
	// Определяемся с умолчаниями для аргументов функции
	if(!vWidth) vWidth = 400;
	if(!vHeight) vHeight = 300;
	if(!vText) vText = '';
	if(!vEvent1) vEvent1 = 'video';
	if(!vEvent3) vEvent3 = vURL;
	if(!vShowCounterId) vShowCounterId = false;

	// Запускаем просмотр видеоролика
	makeVideoBox(vWidth, vHeight, vText);

	// Регистрируем события запуска видео
	JsHttpRequest.query(
		"/_banners/_video/ajax_show_video_stat.php",
		{
			'event1' : vEvent1,
			'event2' : 'play',
			'event3' : vEvent3,
			'vShowCounterId' : vShowCounterId
		},
		function (result, errors){

		},
		false
	);

	/* Формируем блок вызова FLV-плеера --- */
	var so = new SWFObject('/_lib/jw_flv_player/flvplayer.swf','overlaySwf',vWidth,vHeight,'8');
	so.addParam('allowscriptaccess','always');
	so.addParam('allowfullscreen','true');
	//so.addVariable('logo','http://www.banki.ru/_com/banki_ru_sign.png');
	so.addVariable('height',vHeight);
	so.addVariable('width',vWidth);
	so.addVariable('file',vURL);
	so.addVariable('displayheight',vHeight);
	so.addVariable('autostart','true');
	so.addVariable('bufferlength','5');
	so.write('overlayPlayer');
}

// *** Показ фотографии *************************************
// *********************************************************

// Создание контейнера для показа видео
function zoomImage(imgSrc, imgWidth, imgHeight, imgNote){
	makeOverlay();
	var infoBox = document.getElementById('infoBox');
	infoBox.style.display = 'block';

	// Устанавливаем отступ от верхнего края до места показа ролика
	var wSize = getPageSize();
	var wScroll = getPageScroll();
	infoBox.style.top = wScroll[1]+wSize[3]/2-imgHeight/2;

	var infoContent = '<table class="videoView" align="center" style="width: '+imgWidth+';"> '
				+'<tr><td class="video">';
	infoContent += '<img src="'+imgSrc+'"'
				+ 'onClick="closeOverlay(); return false;"'
				+ 'style="width: '+imgWidth+'px; height: '+imgHeight+'px;" />';
	infoContent += '</td><td class="close"><img onClick="closeOverlay(); return false;" '
				+'src="/_com/ico_close_13x13_grey.gif" width="13" height="13" border="0" alt="[x]" title="закрыть" /></div>'
	infoContent += '</td></tr>';
	if(imgNote){
		infoContent +='<tr><td colspan="2" class="videoNote">'+imgNote+'</td></tr>';
	}
	infoContent += '</table>';
	infoBox.innerHTML = infoContent;
};