var reOrderMode = true;
function possiblyReOrder(){
	if(reOrderMode){
		return false;
	}
	return true;
}

var pseudo_ph, fake_ph;
var pseudo_ph_pos;
var mouseOnPhoto = 0;
var src_ondragstart = src_ondrag = src_ondragend = null;
function phOnDragStart(ele, mx, my){
	var documentBody = document.getElementsByTagName('BODY')[0];
	var ele_div = ele.parentNode;

	// создаем копию блока фотки, но уже плавающую...
	pseudo_ph = ele_div.cloneNode(true);
	pseudo_ph.className = 'picBlockFloating';
	documentBody.appendChild(pseudo_ph);

	// создаем "заглушку" блока фотки для имитации "дырки"...
	fake_ph = document.createElement('div');
	fake_ph.className = 'picBlockFake';
	documentBody.appendChild(fake_ph);

	// определяем координаты блока фотки
	var xL = xPageX(ele_div);
	var xT = xPageY(ele_div);

	// ставим копию строго поверх оригинала
	xLeft(pseudo_ph, xL);
	xTop(pseudo_ph, xT);

	// ставим "заглушку" строго поверх оригинала
	xLeft(fake_ph, xL);
	xTop(fake_ph, xT);

	// бежим по всем видимым на листе фоткам и определяем их координаты на странице
	for(i in photo)
		if(i.match(/\d+/)){
			photo[i].left = xPageX('picBlock_'+i);
			photo[i].top = xPageY('picBlock_'+i);
		}

	// создаем слой-индикатор исходной позиции...
	pseudo_ph_pos = document.createElement('div');
	pseudo_ph_pos.className = 'picBlockFloatingPos';
	documentBody.appendChild(pseudo_ph_pos);
}
function phOnDrag(ele, mdx, mdy){
	var xDx, xDy, phPosX, phPosY, resPosX, resPosY;

	// перемещаем копию
	xMoveTo(pseudo_ph, xLeft(pseudo_ph) + mdx, xTop(pseudo_ph) + mdy);
	
	// определяем текущие координаты копии
	var xL = xPageX(pseudo_ph);
	var xT = xPageY(pseudo_ph);

	mouseOnPhoto = 0;
	// бежим по всем видимым на листе фоткам и определяем над какой находимся
	for(i in photo)
		if(i.match(/\d+/)){
			phPosX = photo[i].left;
			phPosY = photo[i].top;
			xDx = xL-phPosX;
			xDy = xT-phPosY;
			if((xDx<photoBlock_width && xDx>0) && (xDy<photoBlock_height && xDy>0)){
				mouseOnPhoto = i;
				resPosX = phPosX - 5;
				resPosY = phPosY;
			}
		}

	// ставим указатель исходной позиции слева от фотки над которой находимся
	if(mouseOnPhoto!=0) xMoveTo(pseudo_ph_pos, resPosX, resPosY);
}
function phOnDragEnd(ele, mx, my){
	var documentBody = document.getElementsByTagName('BODY')[0];
	var ele_div = ele.parentNode;

	// убиваем копию
	documentBody.removeChild(pseudo_ph);

	// убиваем "заглушку"
	documentBody.removeChild(fake_ph);

	// убиваем слой-индикатор позиции
	documentBody.removeChild(pseudo_ph_pos);

	// перемещаем блок фотки внутри DOM
	var ele_div_new = placePhotoBefore(ele_div.id.replace(/^picBlock_/, ''), mouseOnPhoto);

}

var hint_timeout = new Array();
function placePhotoBefore(id1, id2){
	if(id1==id2) return null;

	// перемещаем объект внутри DOM
	var ph_new = moveNodeBefore(xGetElementById('picBlock_'+id1), xGetElementById('picBlock_'+id2))

	// определяем новому объекту драг-обработчики
	xEnableDrag(xGetElementById('picBlockTbl_'+id1), phOnDragStart, phOnDrag, phOnDragEnd);

	return ph_new;
}
function moveNodeBefore(obj1, obj2){
	if(!obj1 || !obj2 || (obj1==obj2)) return null;
	var obj_new = obj1.parentNode.insertBefore(obj1.cloneNode(true), obj2);
	var obj3 = obj1.parentNode.removeChild(obj1);
	return obj3;
}
function showHint(id){
	var ph_div = xGetElementById('picBlock_'+id);
	if(ph_div.className=='picBlockFloating') return false;
	
	var hint_div = xGetElementById('picBlockHint_'+id);
	if(!hint_div){
		var documentBody = document.getElementsByTagName('BODY')[0];
		var hint_div = document.createElement('div');
		documentBody.appendChild(hint_div);
	}
	hint_div.id = 'picBlockHint_'+id;
	hint_div.className = 'picBlockHint';
	hint_div.style.zIndex = 10;
	hint_div.innerHTML = '&copy;'+photo[id].authors.replace(/<[^>]+>/g, '')+'<br />'+photo[id].date;
	xHeight(hint_div, parseInt(xHeight('picBlockBot_'+id))-2);
	xLeft(hint_div, xPageX('picBlock_'+id)+1);
	xTop(hint_div, xPageY('picBlock_'+id)+parseInt(xHeight('picBlock_'+id))-parseInt(xHeight(hint_div))-1);
	xDisplay(xGetElementById('picBlockHint_'+id), 'block');
	clearTimeout(hint_timeout[id]);
}
function hideHint(id){
	var ph_div = xGetElementById('picBlock_'+id);
	if(ph_div.className=='picBlockFloating') return false;

	hint_timeout[id] = setTimeout('destroyHint('+id+')', 100);
}
function destroyHint(id){
	if(isDefined(id) && xGetElementById('picBlockHint_'+id)){
		var documentBody = document.getElementsByTagName('BODY')[0];
		documentBody.removeChild(xGetElementById('picBlockHint_'+id));
	}
}
function icon(type, form){
	var ic = new Array();
	ic['in_menu'] = {alt:unlanguage('Убрать из меню###Hide in menu'), src:''};
	ic['not_in_menu'] = {alt:unlanguage('Показать в меню###Show in menu'), src:''};
	ic['show'] = {alt:unlanguage('Спрятать###Hide'), src:''};
	ic['hide'] = {alt:unlanguage('Показать###Show'), src:''};
	ic['eye_opened'] = {alt:unlanguage('Спрятать###Hide'), src:''};
	ic['eye_closed'] = {alt:unlanguage('Показать###Show'), src:''};
	ic['up'] = {alt:unlanguage('Переместить выше###Move up'), src:''};
	ic['edit'] = {alt:unlanguage('Редактировать###Edit'), src:''};
	ic['recycle'] = {alt:unlanguage('Удалить###Delete'), src:''};
	ic['trash'] = {alt:unlanguage('Удалить###Delete'), src:''};
	ic['zoom'] = {alt:'', src:''};
	ic['create'] = {alt:unlanguage('Создать подраздел###Create sub-section'), src:''};
	ic['save_template'] = {alt:unlanguage('Создать файл###Create file'), src:''};
	ic['node-leaf'] = {alt:'', src:''};
	ic['node-expand'] = {alt:unlanguage('Свернуть###Collapse'), src:''};
	ic['node-collapse'] = {alt:unlanguage('Раскрыть###Expand'), src:''};
	
	ic['ico-zoom'] = {alt:unlanguage('Увеличить###Zoom'), src:''};
	ic['ico-edit'] = {alt:unlanguage('Редактировать###Edit'), src:''};
	ic['ico-left'] = {alt:unlanguage('Поменять местами с предыдущей###Switch with previous'), src:''};
	ic['ico-right'] = {alt:unlanguage('Поменять местами со следующей###Switch with next'), src:''};
	ic['ico-delete'] = {alt:unlanguage('Удалить###Delete'), src:''};
	ic['ico-synch'] = {alt:unlanguage('Синхронизировать описания###Synchronize properties'), src:''};
	ic['ico-to-album'] = {alt:unlanguage('Поместить в текущий альбом###Add to current album'), src:''};
	ic['ico-to-cart'] = {alt:unlanguage('Добавить в корзину###Add to cart'), src:''};
	ic['ico-from-album'] = {alt:unlanguage('Изъять из текущего альбома###Remove from current album'), src:''};
	ic['ico-from-cart'] = {alt:unlanguage('Удалить из корзины###Remove from cart'), src:''};

	var big = (form && form=='big');
	var size = ((type.match(/^node-/))?11:16);
	
	return '<img src="'+htmlrootpath+'/images/icons/'+(big?('big/'+type+'.png'):(type+'.gif'))+'" border=0 alt="'+ic[type].alt+'" title="'+ic[type].alt+'" '+(big?'':('width='+size+' height='+size+' hspace=2'))+' />';
}
function icons(pid, in_album, in_cart, w_edit, w_delete, w_synch, w_orderctrl){
	return '<center><table cellpadding=0 cellspacing=0 border=0 class=picIconsTbl><tr>' + 
		(isDefined(w_orderctrl)?'<td id=picIcon_'+pid+'_synch class=picIcon>'+icon_w_link(pid, 'switch_left')+'<'+'/td>':'')+
		'<td id=picIcon_'+pid+'_zoom class=picIcon>'+icon_w_link(pid, 'zoom')+'<'+'/td>' +
		'<td id=picIcon_'+pid+'_album class=picIcon>'+icon_w_link(pid, (in_album?'from':'to')+'_album')+'<'+'/td>' +
		'<td id=picIcon_'+pid+'_cart class=picIcon>'+icon_w_link(pid, (in_cart?'from':'to')+'_cart')+'<'+'/td>' +
		(w_edit?'<td id=picIcon_'+pid+'_edit class=picIcon>'+icon_w_link(pid, 'edit')+'<'+'/td>':'') +
		(w_delete?'<td id=picIcon_'+pid+'_delete class=picIcon>'+icon_w_link(pid, 'delete')+'<'+'/td>':'') +
		(w_synch?'<td id=picIcon_'+pid+'_synch class=picIcon>'+icon_w_link(pid, 'synch')+'<'+'/td>':'') +
		(isDefined(w_orderctrl)?'<td id=picIcon_'+pid+'_synch class=picIcon>'+icon_w_link(pid, 'switch_right')+'<'+'/td>':'')+
		'<'+'/tr><'+'/table><'+'/center>';
}
function iconAction(type, id, num){
	// stopBubble(event);
	switch(type){
		case('zoom'):{
			maximize(htmlrootpath + '/index.htm?id='+id+'&maxsize=1');
			break;
		}
		case('synch'):{
			document.location = htmlrootpath + '/admin/synch/index.htm?id=' + id;
			break;
		}
		case('edit'):{
			document.location = htmlrootpath + '/system/edit_something.htm?tblname=photos&id=' + id + '&referer=' + encoded_uri;
			break;
		}
		case('delete'):{
			document.location = htmlrootpath + '/pagegen.php3?action=something&edit_action=Delete&tblname=photos&id=' + id + '&referer=' + encoded_uri;
			break;
		}
		case('switch_left'):{
			var ph = xGetElementById('picBlock_'+id);
			if(ph!=ph.parentNode.firstChild){
				ph = moveNodeBefore(ph, ph.previousSibling);
			} else {
				ph.parentNode.appendChild(ph.cloneNode(true));
				ph.parentNode.removeChild(ph);
			}
			break;
		}
		case('switch_right'):{
			var ph = xGetElementById('picBlock_'+id);
			if(ph!=ph.parentNode.lastChild){
				var ph_next = ph.nextSibling;
				if(isDefined(ph_next.nextSibling))
					ph = moveNodeBefore(ph, ph_next.nextSibling);
				else {
					ph.parentNode.appendChild(ph.cloneNode(true));
					ph.parentNode.removeChild(ph);
				}
			} else
				ph = moveNodeBefore(ph, ph.parentNode.firstChild);
			break;
		}
		case('info'):{
			var keys_str = keywords_block(id);
			var str = '' +
				'<table border=0 cellspacing=0 cellpadding=0>' +
				'<tr valign=top>' +
					'<td><img src='+htmlrootpath+photo[id].r_filename+' width='+photo[id].width+' height='+photo[id].height+' alt=\"'+photo[id].name+'\" onClick=\"hideAlert()\"></td>' +
				'</tr>' +
				'</table>';
			showAlert(str, 'butClose');
			break;
		}
		case('check'):{
			var match = ','+id+',';
			if ((','+document.photos.photosID_list.value+',').indexOf(match)==-1) {
				if(reset_all) break;
				document.photos.photosID_list.value = (document.photos.photosID_list.value+','+id).replace(/^,/,'');
				document.getElementById('picPreviewCell'+id).className='picSelected';
				document.getElementById('picCheck_'+id).checked=true;
			}
			else {
				if(set_all) break;
				eval('document.photos.photosID_list.value = (\',\'+document.photos.photosID_list.value+\',\').replace(/'+match+'/, \',\').replace(/^,/, \'\').replace(/,$/, \'\');');
				document.getElementById('picPreviewCell'+id).className='picNonSelected';
				document.getElementById('picCheck_'+id).checked=false;
			}
			break;
		}
		case('to_album'):{
			var str = '' + id;
			str = (str.replace(/[^,]/g, '').length+1);
			var act = 'fillContainerBy(\''+htmlrootpath+'/profile/albums/?body=no&posted=!&action=add_photos&from='+document.photos.from.value+'&photosID_list='+id+'&viewed_photosIDs='+document.photos.viewed_photosIDs.value+'&curr_albumsID='+document.albums_form.curr_albumsID.value+'\');confirmWindow2.die();';
			if(num=='woRequest'){
				eval(act);
			} else {
				var links = '<ul>' +
					'<li><a href=' + document.location.href.replace(/&/g, '&amp;') + ' onClick=\'showAlert(\"Выберите из списка:<br /><br />\"+albs_carts_list(\"albums\", ' + id + '),\"butClose\");return false\'><b>Выбрать другой альбом&hellip;<'+'/b><'+'/a><'+'/li>' +
					'<li><a href=' + document.location.href.replace(/&/g, '&amp;') + ' onClick=\'showPrompt(\"Введите имя альбома\", \"add_album(this.win_prompt_text.value, ' + id + ')\", \"\"); return false\'><b>Создать новый альбом<'+'/b><'+'/a><'+'/li>' +
					'<'+'/ul>';
	
				confirmWindow2 = new floatWindow();
				confirmWindow2.width = 300;
				confirmWindow2.height = 200;
				confirmWindow2.butType = 'butNone';
				confirmWindow2.text = 'Вы добавляете фотографии ('+str+') в альбом '+document.getElementById('curr_album').innerHTML+'<br /><br />' + links;
				confirmWindow2.zIndex = 600;
				confirmWindow2.buttons = Array({title:'OK', action:act},{title:unlanguage('Отмена###Cancel'), action:'confirmWindow2.die();'});
				confirmWindow2.create();
				xResizeTo(confirmWindow2.titlebar, 20, 20);
				xMoveTo(confirmWindow2.titlebar, 180, 0);
				xEnableDrag(confirmWindow2.titlebar, myOnDragStart, myOnDrag, myOnDragEnd); 
				confirmWindow2.show();
			}
			break;
		}
		case('to_cart'):{
			fillContainerBy(htmlrootpath+'/profile/carts/?body=no&posted=!&action=add_photos&from='+document.photos.from.value+'&photosID_list='+id+'&viewed_photosIDs='+document.photos.viewed_photosIDs.value+'&curr_cartsID=' + curr_cartsID);
			break;
		}
		case('to_cart_w_calc'):{
			fillContainerBy(htmlrootpath+'/profile/carts/?body=no&posted=!&action=add_and_save_prices&from='+document.photos.from.value+'&photosID_list='+id+'&viewed_photosIDs='+document.photos.viewed_photosIDs.value+'&price='+usage_price+'&usage_pricesID='+usage_pricesID+'&curr_cartsID=' + curr_cartsID);
			break;
		}
		case('from_album'):{
			fillContainerBy(htmlrootpath+'/profile/albums/?body=no&posted=!&hide_photos=' + (document.location.href.match(/albumsID=/)?1:0) + '&action=remove_photos&from='+document.photos.from.value+'&photosID_list='+id+'&viewed_photosIDs='+document.photos.viewed_photosIDs.value+'&curr_albumsID='+document.albums_form.curr_albumsID.value);
			break;
		}
		case('from_cart'):{
			fillContainerBy(htmlrootpath+'/profile/carts/?body=no&posted=!&hide_photos=' + (document.location.href.match(/cartsID=/)?1:0) + '&action=remove_photos&from='+document.photos.from.value+'&photosID_list='+id+'&viewed_photosIDs='+document.photos.viewed_photosIDs.value+'&curr_cartsID=' + curr_cartsID);
			break;
		}
		case('syns_delete_synonim'):{
			if(document.syns.synsIDs.value=='')
				showAlert('Не выбраны синонимы.');
			else {
				var act = 'document.syns.syns_action.value=\"'+type+'\";document.syns.submit();';
				showConfirm2('Вы действительно хотите удалить выбранные синонимы из базы данных?', act, '');
			}
			break;
		}
		case('syns_delete_syn_link'):{
			if(document.syns.synsIDs.value=='')
				showAlert('Не выбраны синонимы.');
			else {
				var act = 'document.syns.syns_action.value=\"'+type+'\";document.syns.submit();';
				showConfirm2('Вы действительно хотите удалить выбранные синонимы ключевого слова, оставив их в базе данных?', act, '');
			}
			break;
		}
		case('syns_delete_meaning'):{
			if(document.syns.meaningsID.value=='')
				showAlert('Не выбрано толкование.');
			else {
				var act = 'document.syns.syns_action.value=\"'+type+'\";document.syns.submit();';
				showConfirm2('Вы действительно хотите удалить выбранное толкование данного ключевого слова из базы данных?', act, '');
			}
			break;
		}
		case('syns_associate_keyword'):{
			if(document.syns.meaningsID.value=='')
				showAlert('Не выбрано толкование.');
			else
				if(document.syns.synsIDs.value=='')
					showAlert('Не выбраны синонимы.');
				else {
					var act = 'document.syns.syns_action.value=\"'+type+'\";document.syns.submit();';
					showConfirm2('Вы действительно хотите ассоциировать выбранные снинонимы с выбранным толкованием ключевого слова?', act, '');
				}
			break;
		}
		case('syns_set_baseform'):{
			if(document.syns.baseform.value=='')
				showAlert('Не выбрана основная форма.');
			else {
				var act = 'document.syns.syns_action.value=\"'+type+'\";document.syns.submit();';
				showConfirm2('Вы действительно хотите установить выделенную основную форму для текущего ключевого слова?', act, '');
			}
			break;
		}
		case('syns_save_empty'):{
			var act = 'document.syns.syns_action.value=\"'+type+'\";document.syns.submit();';
			showConfirm2('Вы действительно закончили обработку текущего ключевого слова?', act, '');
			break;
		}
	}
	return false;
}


function change_curr_album(id, add_photos_id){
	document.getElementById('curr_album').innerHTML='<b>...</b>';
	fillContainerBy(htmlrootpath + '/profile/albums/index.htm?body=no&action=make_curr&from_form=1&curr_albumsID='+id+'&viewed_photosIDs='+((document.photos!=null)?document.photos.viewed_photosIDs.value:'')+(add_photos_id?'&add_photos_id='+add_photos_id:''));
	return false;
}

function change_curr_cart(id){
	document.getElementById('curr_cart').innerHTML='<b>...</b>';
	fillContainerBy(htmlrootpath + '/profile/carts/index.htm?body=no&action=make_curr&from_form=1&curr_cartsID='+id+'&viewed_photosIDs='+((document.photos!=null)?document.photos.viewed_photosIDs.value:''));
	return false;
}

function albs_carts_list(what, add_photos_id){
	eval('var arr = '+what+'_arr');
	var str = '<ul>';
	for(var i=0;i<arr.length;i++){
		str += '<li><a href=./ onClick="change_curr_'+what.replace(/.$/, '')+'('+arr[i].id+(add_photos_id?', '+add_photos_id:'')+');return false">'+arr[i].name+' ('+arr[i].cnt+')</a></li>';
	}
	str += '</ul>';
	return str;
}

function add_album(name, add_photos_id, authorsID, wDynamicRefresh){
	if(name!=""){
		stayAlertWin = 1;
		fillContainerBy(htmlrootpath + '/profile/albums/index.htm?body=no&posted=!&action=add&from_form=1'+(isDefined(add_photos_id)?'&add_photos_id='+add_photos_id:'')+(isDefined(authorsID)?'&authorsID='+authorsID:'')+(isDefined(wDynamicRefresh)?'&wDynamicRefresh='+wDynamicRefresh:'')+'&alb_name=' + name, '', 'Подождите, осуществляется создание альбома');
	}
}

function add_order(name, onlycreate){
	if(name!=""){
		stayAlertWin = 1;
		fillContainerBy(htmlrootpath + '/profile/orders/index.htm?body=no&posted=!&action=add&from_form=1&onlycreate='+((onlycreate=="onlycreate")?1:0)+'&ord_name=' + name, '', 'Подождите, осуществляется создание заказа');
	}
}

function albumCreateForm(authorsID, wDynamicRefresh){
	showPrompt(unlanguage('Введите имя альбома###Input album title'), 'add_album(document.getElementById("win_prompt_text").value'+(isDefined(authorsID)?', null, '+authorsID+(isDefined(wDynamicRefresh)?', '+wDynamicRefresh:''):'')+')', '');
}


photo = new Array();
keywords = new Array();

function keywords_block(id, allchecked, columns){
	var k_arr = photo[id].keywords;
	if(k_arr && k_arr.length>0){
		var keys_str = '';
		var real_keys = 0;
		for(var i=1;i<=k_arr.length;i++)
			if(isDefined(keywords[k_arr[i-1]]))
				real_keys++;
		$j = 1;
		for(var i=1;i<=k_arr.length;i++)
			if(isDefined(keywords[k_arr[i-1]])) {
				keys_str += "<tr><td style='padding:0px 5px 1px 0px'><input type=checkbox "+(allchecked?"checked":"")+" id=key_"+id+"_"+k_arr[i-1]+" class=commonCheck onClick=\"collect_IDs(this.form.keys_ids, '"+keywords[k_arr[i-1]]+"', this.checked)\" /></td><td width=100%><label for=key_"+id+"_"+k_arr[i-1]+">"+keywords[k_arr[i-1]]+"</label></td></tr>";
				if($j%Math.ceil(real_keys/(columns?columns:1))==0) keys_str += "</td></tr></table></td><td><table cellpadding=0 cellspacing=0 border=0><tr valign=top><td>";
				$j++;
			}
		keys_str = "<form name=keys action=./ onsubmit=\"document.search.in_results.checked=false;document.search.what.value=this.keys_ids.value.replace(/,/g, ' '); document.search.submit(); return false;\"><table cellpadding=0 cellspacing=0 border=0 width=100%><tr valign=top><td><table cellpadding=0 cellspacing=0 border=0>" + keys_str + "</table></td></tr></table><input type=hidden name=keys_ids value=''><br /><input type=submit value='"+unlanguage('найти###search')+"'></form>";
	}
	return keys_str;
}

function setPicActivity(pid, pmode){
	var phArrSize = 300;
	var previewSize = 150;
	
	var ph = photo[pid];
	var re = new RegExp('/'+phArrSize+'/', '');
	var src = '' + htmlrootpath + ph.r_filename.replace(re, '/'+previewSize+'/');
	var pic = document.getElementById('picPreview'+pid+'_pic');
	if(pmode){
		pic.src = src;
		xBackground(pic, null, '');
	}
	else {
		pic.src = htmlrootpath+'/images/light_glass.png';
		xBackground(pic, null, src);
	}
	xWidth(pic, ph.width/phArrSize*previewSize);
	xHeight(pic, ph.height/phArrSize*previewSize);
}
function switchPhActButNot(spab_id, spab_mode){
	for(var i=0; i<viewed_photosIDs.length; i++)
		setPicActivity(viewed_photosIDs[i], (spab_mode?(viewed_photosIDs[i]!=spab_id):(viewed_photosIDs[i]==spab_id)));
}
function doCalc(id, from_cart){
	if(from_cart) switchPhActButNot(id, false);
	xDisplay(xGetElementById('usages_td'), 'block');
	xDisplay(xGetElementById('actions_td'), 'none');
	document.prices.photosID.value = id;
	if(from_cart) 
		setLayerItem('preview4calc', document.getElementById('picPreview'+id).innerHTML.replace(/id="[a-zA-Z0-9_]+"/, ''));
	else
		xDisplay(xGetElementById('preview'), 'block');
}

usage_pricesID = 0;
usage_price = 0;

function completeCalc(id, price, from_cart){
	if(from_cart) switchPhActButNot(0, true);
	xDisplay(xGetElementById('usages_td'), 'none');
	xDisplay(xGetElementById('actions_td'), 'block');
	xDisplay(xGetElementById('wcalc_divider'), (isMozilla?'table-row':'block'));
	xDisplay(xGetElementById('wcalc_item'), (isMozilla?'table-row':'block'));
	if(!from_cart) xDisplay(xGetElementById('preview'), 'none');
	if(price!=0 && price!=''){
		usage_price = price;
		usage_pricesID = document.prices.usage_pricesID.value;
		var usage = usage_types[document.prices.usage_typesID.value];
		fillContainerBy(htmlrootpath+'/profile/cart/index.htm?body=no&action=save_prices&photosID='+id+'&price='+price+'&usage_pricesID='+usage_pricesID, '', 'Сохранение параметров...');
		photo[id].price = price;
		if(!from_cart) {
			xGetElementById('total_div').innerHTML = price;
			xGetElementById('calcLink').innerHTML = 'Пересчитать цену';
		}
		else {
			document.getElementById('price_'+id).innerHTML = 'цена: '+price+(usage?'<br /><span class=price_info_span>('+usage+')</span>':'');
			document.getElementById('price_'+id).style.paddingBottom = '20px';
			document.getElementById('price_'+id+'_calc').innerHTML = '<button onClick=\"doCalc('+id+');\">пересчитать</button>';
		}
		reCalcTotalPrice();
	}
}
function reCalcTotalPrice(){
	var pr = 0; 
	// pr = parseFloat(document.total.price.value) + (direct?1:-1)*photo[id].price
	for(var i=0; i<viewed_photosIDs.length; i++)
		if((','+document.photos.photosID_list.value+',').indexOf(','+viewed_photosIDs[i]+',')!=-1) 
			pr = pr + parseFloat(photo[viewed_photosIDs[i]].price);
	/*
	if(user_bill<pr){
		setLayerItem('orderErrors', 'Недостаточно денег на счету для осуществления заказа.');
		xDisplay('orderErrors', 'block');
		xDisplay('groupActs_order', 'none');
		setLayerItem('total_div', '...');
		return;
	}
	else {
		setLayerItem('orderErrors', '');
		xDisplay(xGetElementById('orderErrors'), 'none');
	}
	*/
	xDisplay('groupActs_order', (isMSIE?'block':'table-row'));
	document.total.price.value = pr;
	setLayerItem('total_div', document.total.price.value);
}

function goDictionary(){
	fillContainerBy(htmlrootpath + '/system/get_' + (document.getElementById('synonims').checked?'synonims':(document.getElementById('wordmeanings').checked?'wordmeanings':'wordforms')) + '.php3?body=no&keyword='+document.getElementById('dictionarytext').value+'&where='+(document.getElementById('wordmeanings').checked?'wordmeanings':'wordforms'));
}

function showDictionary(){
	alertWindow.text = '<table style="width:100%; border:0; padding:0px; margin-bottom:20px">'+
		'<tr>'+
			'<td width="100%">'+
				'<input type="text" name="keyword" id="dictionarytext" onKeyUp="if(event.keyCode==13) goDictionary()" class=inputs style="width:100%">'+
			'</td>'+
			'<td style="padding-left:10px">'+
				'<input type="button" onClick="goDictionary()" value=" ok ">'+
			'</td>'+
		'</tr>'+
		'<tr>'+
			'<td class="small_white" colspan=2>'+
				'<small>'+
					'<input type="radio" class="commonCheck" id="wordmeanings" name="wheregroup" checked value="wordmeanings" /><label for="wordmeanings">толкования</label>  '+
					(0?'<input type="radio" class="commonCheck" id="wordforms" name="wheregroup" value="wordforms" /><label for="wordforms">&nbsp;словоформы</label>':'')+
					'<input type="radio" class="commonCheck" id="synonims" name="wheregroup" value="synonims" /><label for="synonims">&nbsp;синонимы</label>'+
				'</small>'+
			'</td>'+
		'</tr>'+
		'</table>';
	alertWindow.butType = 'butClose';
	alertWindow.show();
	return false;
}

function chooseDate(type, postfix){
	switch(type){
		case(1):{
			showAlert(
				'<table align=center border=0 cellspacing=5 cellpadding=0>'+
				'<tr valign=middle>'+
				'<td nowrap=\'nowrap\'>'+
				'<input type=text tabindex=\'1\' name=dd_ph_'+postfix+' id=dd_ph_'+postfix+' value=\'\' maxLength=2 style=\'width:30px\' onKeyDown=\'if(event.keyCode==13) execute_date(1); else  return (isControl(event.keyCode) || isDigit(event.keyCode))\' />.'+
				'<input type=text tabindex=\'2\' name=mm_ph_'+postfix+' id=mm_ph_'+postfix+' value=\'\' maxLength=2 style=\'width:30px\' onKeyDown=\'return (isControl(event.keyCode) || isDigit(event.keyCode))\' />.'+
				'<input type=text tabindex=\'3\' name=yy_ph_'+postfix+' id=yy_ph_'+postfix+' value=\'\' maxLength=4 style=\'width:70px\' onKeyDown=\'return (isControl(event.keyCode) || isDigit(event.keyCode))\' />'+
				'</td>'+
				'</tr>'+
				'<tr height=40 valign=middle>'+
				'<td style=\'padding-top:5px\'>'+
				'<input type=button value=\'Выбрать\' onClick=\'execute_date(1)\' />'+
				'&nbsp;&nbsp;'+
				'<input type=button value=\'Закрыть\' onClick=\'hideAlert()\' />'+
				'</td>'+
				'</tr>'+
				'</table>'
			,
				'butNone'
			);
			break;
		}
		case(2):{
			showAlert(
				'<table align=center border=0 cellspacing=5 cellpadding=0>'+
				'<tr valign=middle>'+
				'<td nowrap=\'nowrap\'>'+
				'<input type=text tabindex=\'1\' name=yy_ph_'+postfix+' id=yy_ph_'+postfix+' value=\'\' maxLength=4 style=\'width:70px\' onKeyDown=\'return (isControl(event.keyCode) || isDigit(event.keyCode))\' />'+
				'</td>'+
				'</tr>'+
				'<tr height=40 valign=middle>'+
				'<td style=\'padding-top:5px\'>'+
				'<input type=button value=\'Выбрать\' onClick=\'execute_date(2)\'>'+
				'&nbsp;&nbsp;'+
				'<input type=button value=\'Закрыть\' onClick=\'hideAlert()\' />'+
				'</td>'+
				'</tr>'+
				'</table>'
			,
				'butNone'
			);
			break;
		}
		case(3):{
			showAlert(
				'<table align=center border=0 cellspacing=5 cellpadding=0>'+
				'<tr valign=middle>'+
				'<td nowrap=\'nowrap\'>'+
				'<input type=text tabindex=\'1\' name=yy_ph_'+postfix+'1 id=yy_ph_'+postfix+'1 value=\'\' maxLength=4 style=\'width:70px\' onKeyDown=\'return (isControl(event.keyCode) || isDigit(event.keyCode))\' />'+
				'&nbsp;&mdash;&nbsp;'+
				'<input type=text tabindex=\'2\' name=yy_ph_'+postfix+'2 id=yy_ph_'+postfix+'2 value=\'\' maxLength=4 style=\'width:70px\' onKeyDown=\'return (isControl(event.keyCode) || isDigit(event.keyCode))\' />'+
				'</td>'+
				'</tr>'+
				'<tr height=40 valign=middle>'+
				'<td style=\'padding-top:5px\'>'+
				'<input type=button value=\'Выбрать\' onClick=\'execute_date(3)\' />'+
				'&nbsp;&nbsp;'+
				'<input type=button value=\'Закрыть\' onClick=\'hideAlert()\' />'+
				'</td>'+
				'</tr>'+
				'</table>'
			,
				'butNone'
			);
			break;
		}
		case(4):{
			showAlert(
				'<table align=center border=0 cellspacing=5 cellpadding=0>'+
				'<tr valign=middle>'+
				'<td nowrap=\'nowrap\'>'+
				'<input type=text tabindex=\'1\' name=yy_ph_'+postfix+' id=yy_ph_'+postfix+' value=\'\' maxLength=2 style=\'width:30px\' onKeyDown=\'return (isControl(event.keyCode) || isDigit(event.keyCode))\' />'+
				'&nbsp;-е&nbsp;г.г.&nbsp;&nbsp;'+
				'<input type=text tabindex=\'2\' name=cent_ph_'+postfix+' id=cent_ph_'+postfix+' value=\'\' maxLength=2 style=\'width:30px\' onKeyDown=\'return (isControl(event.keyCode) || isDigit(event.keyCode))\' />'+
				'&nbsp;в.'+
				'</td>'+
				'</tr>'+
				'<tr height=40 valign=middle>'+
				'<td style=\'padding-top:5px\'>'+
				'<input type=button value=\'Выбрать\' onClick=\'execute_date(4)\' />'+
				'&nbsp;&nbsp;'+
				'<input type=button value=\'Закрыть\' onClick=\'hideAlert()\' />'+
				'</td>'+
				'</tr>'+
				'</table>'
			,
				'butNone'
			);
			break;
		}
	}
}


/* =============================
    ДОПОЛНИТЕЛЬНЫЕ СТИЛИ
============================= */

document.write("<style type=\"text/css\">"+
	".main_menu_stripe {background-image: url("+htmlrootpath+"/images/main_menu_bg.gif);}"+
	".sub_menu, .sub_menu_act, .sub_menu_curr, "+
	".admin_menu, .admin_menu_act "+
	"{background-image:url("+htmlrootpath+"/images/list-bullet-close.gif);background-repeat:no-repeat;background-position:+4px +4px;} "+
	".sub_menu_act, .sub_menu_curr, .tree_node_act, .tree_node_curr {background-color:#F8F8F8;}"+
	cross_PNG_background('.main_menu .l, .main_menu_curr .l, .main_menu_act .l', '/images/main_menu_corner_l.png', '', 'crop')+
	cross_PNG_background('.main_menu .r, .main_menu_curr .r, .main_menu_act .r', '/images/main_menu_corner_r.png', '', 'crop')+
	// cross_PNG_background('#church_block', '/images/Hram_color.png', '', 'crop')+
	// cross_PNG_background('#church_block', '/images/logo.png', '', 'crop')+
	"</style>");

