if(document.all){ // IE
	tr_style_visible='block';
} else {
	tr_style_visible='table-row';
}

function open_sendurl_win(loc, language, htmlrootpath, page_title){
	var reply_width = 500;
	var reply_height = 230;
	send_page_query=loc.search;
//	alert('page_title=' + loc.title);
	if(send_page_query=='') send_page_query='?use_language=' + language;
		else send_page_query=send_page_query + '&use_language=' + language;

	if(loc.hash!='') send_page_hash='&send_page_hash=' + loc.hash.replace('#', '');
	else send_page_hash='';
	
	send_page=escape(loc.protocol + '\/\/' + loc.host + loc.pathname + send_page_query + send_page_hash);
	var url= htmlrootpath + '/about/sendurl.htm?url='+ send_page + '&title=' + page_title;
	if(document.all){
		var w = window.open('', 'PhotoWindow', 'width='+reply_width+',height='+reply_height+',resizable=1');
		w.location = url;
	}else{
		window.open(url,'_blank', 'width='+reply_width+',height='+reply_height+',titlebar=no,menubar=no,status=no,location=no,fullscreen=no,directories=no,resizable=no');
	}
}

function open_html(url, wwidth, wheight, resized, scrolls, fullscreen){
//	alert(wheight);
	if(fullscreen!='yes') fullscreen='no';
	if(resized) resizable_par=resized?',resizable=yes':',resizable=no'; else resizable_par=',resizable=no';
	if(scrolls) scroll_par=scrolls?',scrollbars=yes':',scrollbars=no'; else scroll_par=',scrollbars=no';
	pX = Math.round((screen.width - wwidth) / 2);
	pY = Math.round((screen.height - wheight) / 2);
	var rnd=Math.round(1000*Math.random());
	if(document.all){
		win_coords =',left='+pX+',top='+pY;
		new_window = window.open('', 'NewWindow'+rnd, 'width='+wwidth+',height='+wheight+',titlebar=no,fullscreen='+fullscreen+'' + resizable_par + scroll_par + win_coords);
		new_window.location = url;
	}else{
		win_coords =',screenX='+pX+',screenY='+pY;
		new_window = window.open(url,'_blank', 'width='+wwidth+',height='+wheight+',titlebar=no,menubar=no,status=no,location=no,fullscreen='+fullscreen+',directories=no' + resizable_par + scroll_par + win_coords);
	}
}
function open_picture(url, wwidth, wheight){
	pX = Math.round((screen.width - wwidth) / 2);
	pY = Math.round((screen.height - wheight) / 2);
	if(document.all){
		win_coords =',left='+pX+',top='+pY;
		var w = window.open('', 'NewWindow', 'width='+wwidth+',height='+wheight+',titlebar=no,resizable=no,scrollbars=no'+win_coords);
		w.location = url;
	}else{
		win_coords =',screenX='+pX+',screenY='+pY;
		window.open(url,'_blank', 'width='+wwidth+',height='+wheight+',titlebar=no,menubar=no,status=no,location=no,fullscreen=no,directories=no,resizable=no,scrollbars=no'+win_coords);
	}
}

function switch_element(id){
	var status = document.getElementById(id).style.display;
	document.getElementById(id).style.display = (status=='none' || status=='')?'block':'none';
}

function switch_tr(id){
	var status = document.getElementById(id).style.display;
	document.getElementById(id).style.display = (status=='none')?tr_style_visible:'none';
}
function show_tr(id){
	if(document.all) var show='block'; else var show='table-row';
	document.getElementById(id).style.display = show;
}
function hide_tr(id){
	document.getElementById(id).style.display = 'none';
}

function switch_checkboxes_old(form, group_name, status){
	var pat = new RegExp(group_name + "\[[0-9]+\]", "i")
	for (e in form.elements) {
		matched=e.match(pat);
		if(matched && form.elements[e].type=='checkbox'){
			form.elements[e].checked=status;
		}
	}
}

function switch_checkboxes(form, group_name, status){
	var pat = new RegExp(group_name + "\[[0-9]+\]", "i");
	var arr = form.elements;	var a;
	for (var i=0;i<arr.length;i++) {
		a = arr[i];
		if(a.name != null){
			matched=a.name.match(pat);
			if(matched && a.type=='checkbox'){
				a.checked=status;
			}
		}
	}
}

function collect_checkboxes(form, group_name){
	var pat = new RegExp(group_name + "\[[0-9]+\]", "i");
	var listvar = 0;
	var arr = form.elements;	
	var a;
	for (var i=0;i<arr.length;i++) {
		a = arr[i];
		if(a.name != null){
			matched=a.name.match(pat);
			if(matched && a.type=='checkbox'){
				if(a.checked){
					eval('listvar = listvar + "," + a.name.replace(/'+group_name+'\\[/g,"").replace(/\\]/g, "")');
				}
			}
		}
	}
	if(listvar!='0') listvar = listvar.replace(/^0,/,'');
	return(listvar);
}

function collect_IDs(obj, ID, direct) {
	var listvar = obj.value;
	switch(direct){
		case(true):{
			listvar = listvar+((listvar=='')?'':',')+ID;
			break;
		}
		case(false):{
			var listvar2 = ','+listvar+',';
			var pattern = ','+ID+',';
			eval('listvar = listvar2.replace(/'+pattern+'/g,",").replace(/^,/,"").replace(/,$/,"");');
			break;
		}
	}
	obj.value = listvar;
}

function oldswitcher(form, f, s){
	for (i = 1; i < ids.length; i++) {
		c=eval('form[\"' + f + '[' + ids[i] + ']\"]');
		c.checked = s;
	}		
}

function TagInsert(form, field, Tag, Tag2){
	var obj = form[field];
	obj.focus();
	if(document.selection){
		var sel = document.selection.createRange();
		sel.text= Tag+sel.text+Tag2;
	} else {
		var start=obj.selectionStart;
		var end=obj.selectionEnd;
		var text=obj.value;
		var len=text.length;
		obj.value=text.substring(0, start) + Tag + 
			text.substring(start, end) + Tag2 +
			text.substring(end, len);
	}
}

function __________TagInsert(form, field, Tag, Tag2){
	form[field].focus();
	sel = document.selection.createRange();
	alert(sel.text);
	sel.text= Tag+sel.text+Tag2;
}



function big_photo(url){
	var screen_w = screen.width;
	var screen_h = screen.height;
	if(document.all){
		window.open(url,'','left=0,top=0,width=screen_w,height=screen_h,scrollbars=yes,fullscreen=yes');
	}else{
		window.open(url,'_blank', 'width='+screen_w+',height='+screen_h+',titlebar=no,menubar=no,status=no,location=no,fullscreen=yes,directories=no,resizable=no,screenX=0,screenY=0');
	}
}


function autofit_and_center(){
	window.resizeBy(document.body.scrollWidth-document.body.offsetWidth, document.body.scrollHeight-document.body.offsetHeight+5);
	pX = Math.round((screen.width - document.body.offsetWidth) / 2);
	pY = Math.round((screen.height - document.body.offsetHeight) / 2);
	window.moveTo(pX,pY);
}

function CheckText(form, field){
	// функция частично слизана с hiero.ru. спасибо Давиду за идею
	var result = true; 
	var obj=document.forms[form][field];
	var original_text=obj.value;
	var text=original_text.replace(/([^\d])\1{2,}/g, "$1$1$1").replace(/^\s+|\s+$/g, '');
	obj.value=text;
//	return false;
	var lext=text.toLowerCase();
	var c=0;
	for(i=0; i<text.length; i++){
		if(text.charAt(i)!=lext.charAt(i)) c++;
	}
	cc=(c/text.length)*100;
	if(cc>20 && text.length>10){
		alert("Слишком много заглавных букв! \n" + cc + "%, а допускаетс\я не более 20% 8-)");
		result = false;
	}
	if(text.match(/нравитьс\я/i)) return confirm("Вы уверены, что слово \"нравитс\я\" здесь следует писать именно с мягким знаком?");
	if(text.match(/кажетьс\я/i)) { alert("Вот уж где-где, а в слове \"кажетс\я\" мягкого знака быть никак не может. Согласны?"); return false;}
	if(text.match(/смотритьс\я/i)) { alert("В слове \"смотритс\я\" мягкого знака быть не может. Да и вообще такого слова нет. 8-)"); return false;}
	if(text.match(/чавств/i)) return confirm("'учаВствовать' - это от слова 'чаВкать', не так ли?");
	if(text.match(/н[еиe]д[оаoa]ш[аa][рp]п/i)) { alert("Вы уж простите, но слова \"недошарп\" не существует в русском языке."); return false;}
	if(text.match(/^[0-9!]+[0-9!. ]*$/i)) { alert("Бессодержательный комментарий 8-("); return false;}

	return result;
}

/* Trim leading and trailing blanks from an input field */
function alltrim(obj){
   var trimmedstring="",startpos=0, endpos=obj.value.length - 1
   /* find start position of string */	
   while (startpos<=obj.value.length && obj.value.substring(startpos, startpos+1)==" ") {
 	   startpos++
   }
   /* null string */
   if (endpos == -1) {
     endpos=0
   }
   /* find end position of string */
   while (endpos >= 0 && obj.value.substring(endpos,endpos+1)==" ") {
	   endpos--
   }
   /* replace value with trimmed string */
   obj.value=obj.value.substring(startpos,endpos+1)
   return obj
}

function ajust_div_width(div_style, w){
	var size=document.body.offsetWidth;
	if(size<w){
		div_style.paddingRight=0;
	} else {
		div_style.paddingRight=size-w;
	}
}

function win_fit_and_center(){
	resizeX=document.body.scrollWidth-document.body.offsetWidth;
	resizeY=document.body.scrollHeight-document.body.offsetHeight;
	if(document.body.scrollHeight>screen.height){
		resizeY=screen.height-document.body.offsetHeight-100;
	}
//	alert(document.body.scrollHeight);
//	alert(document.body.offsetHeight);
	if(document.all){ // fix for MSIE
		resizeX = resizeX + 20;
		resizeY = resizeY + 4;
	}
//	alert(resizeX + ' ' + resizeY);
	
	window.resizeBy(resizeX, resizeY);
	new_width=document.body.scrollWidth;
	new_height=document.body.scrollHeight;
	pX = Math.round((screen.width - new_width) / 2);
	pY = Math.round((screen.height - new_height) / 2);
	if(pY<0) pY=0;
	window.moveTo(pX,pY);
}

function edit_tagselect(list){
    if (!list) return;
    var selected = new Array();  // tagnames, for display
    for ( i = 0; i < list.options.length; i++ ) {
        if (list.options[i].selected) {
            selected.push(list.options[i].value);
        }
    }
	document.getElementById('tagfield').value = selected.join(", ");
}

function ajax_indicator_on(div){
	var indicator_pic='<img src=' + htmlrootpath + '/static/design/images/ajax/indicator.gif>';
	if (div){ 
		document.getElementById(div).innerHTML=indicator_pic; 
	}
}
function ajax_indicator_off(div){
	if (div){ document.getElementById(div).innerHTML=''; }
}

function select_content(id){
	document.getElementById(id).focus();
	document.getElementById(id).select();
}

function blog_code(page_url, pic_url, pic_name){
	var thumb_url=pic_url.replace('pictures', 'previews');
	var html="<fieldset class=commonFset>"+
"<legend class=commonLeg>Код для вставки в блоги</legend>"+
"<table cellspacing=0 cellpadding=0 style='margin-top:10px; width:100%'>"+
"	<tr><td style=padding-left:8px; class=smallerFont>Код фотографии со ссылкой на ее страницу:</td></tr>"+
"	<tr><td style=padding:8px;><textarea onClick=\"select_content('blog_code1')\" id=blog_code1 rows=3 style='width:100%'><a href='" + page_url + "'><img src='" + pic_url + "' border='0' alt='" + pic_name + "'></a></textarea></td></tr>"+
"	<tr><td style=padding-left:8px; class=smallerFont>Код превью фотографии со ссылкой на ее страницу:</td></tr>"+
"	<tr><td style=padding:8px;><textarea onClick=\"select_content('blog_code2')\" id=blog_code2 rows=3 style='width:100%'><a href='" + page_url + "'><img src='" + thumb_url + "' border='0' alt='" + pic_name + "'></a></textarea></td></tr>"+
"	<tr><td style=padding-left:8px; class=smallerFont>Ссылка на фотографию:</td></tr>"+
"	<tr><td style=padding:8px;><textarea onClick=\"select_content('blog_code3')\" id=blog_code3 rows=2 style=width:100%>" + pic_url + "</textarea></td></tr>"+
"</table>"+
"</fieldset>";
	document.getElementById('blog_code').innerHTML=html;

	switch_element('blog_code');
}

function xpand_textarea(a, el){
	var h = Number( document.getElementById(el).style.height.replace('px','') );
	if(a==1) h+=100; else  h-=100;
	if(h>1600) h=1600;
	if(h<100) h=100;
	document.getElementById(el).style.height = h+'px';
	return false;
}



function open_subscribe_win(){
	if(document.all){
		var w = window.open('','','left=100,top=100,width=300,height=170,scrollbars=no,resizable=1,titlebar=no');
		w.location = htmlrootpath + '/registration/subscribe.htm';
	}else{
		window.open(htmlrootpath + '/registration/subscribe.htm','_blank', 'width=300,height=170,titlebar=no,menubar=no,status=no,location=no,directories=no,resizable=no,screenX=100,screenY=100');
	}
}

function goto_search(){
	document.location=htmlrootpath + '/search/index.htm?items_on_page=10&search_string=' + document.searchform.search_string.value;
}


function open_fullscreen(url){
	var screen_w = screen.width;
	var screen_h = screen.height;
	if(document.all){
		var w = window.open('','','left=0,top=0,width=screen_w,height=screen_h,scrollbars=yes,fullscreen=yes');
		w.location = url;
	}else{
		window.open(url,'_blank', 'width='+screen_w+',height='+screen_h+',titlebar=no,menubar=no,status=no,location=no,fullscreen=yes,directories=no,resizable=no,screenX=0,screenY=0');
	}
}

function pulldownblock(id, handler){
	skipHiding = true;
	switch_element(id);
	xMoveTo(id, xPageX(handler), xPageY(handler)+xHeight(handler)+1);
}


function pulldown(id){
	skipHiding = true;
	
	if(xGetElementById(id).pulled){
		hidepulldown(xGetElementById(id));
		return;
	}

	var submenus = xGetElementsByClassName('submenu_div');
	for(var i=0, sml=submenus.length; i<sml; i++){
		hidepulldown(submenus[i]);
	}
	xDisplay(xGetElementById(id), 'block');

	var mm = xGetElementById(id.replace('sm', 'mm'));
	var pu = xGetElementById(id.replace('sm', 'pu'));
	mm.oldclassName=mm.className;
	
	if(mm.className=='mm_td_a')
		pu.oldclassName='pu_td_a';
	else
		pu.oldclassName='pu_td';

	mm.oldonMouseOver=mm.onmouseover;
	pu.oldonMouseOver=pu.onmouseover;
	mm.oldonMouseOut=mm.onmouseout;
	pu.oldonMouseOut=pu.onmouseout;

	mm.className='mm_td_ap';
	pu.className='pu_td_a';
	mm.onmouseover='';
	pu.onmouseover='';
	mm.onmouseout='';
	pu.onmouseout='';

	xGetElementById(id).pulled=true;
}

function hidepulldown(obj){
	if(!obj.pulled) return;
	xDisplay(obj, 'none');
	var mm = xGetElementById(obj.id.replace('sm', 'mm'));
	var pu = xGetElementById(obj.id.replace('sm', 'pu'));
	if(mm.oldclassName!=undefined){
		mm.className=mm.oldclassName;
		pu.className=pu.oldclassName;
		mm.onmouseover=mm.oldonMouseOver;
		pu.onmouseover=pu.oldonMouseOver;
		mm.onmouseout=mm.oldonMouseOut;
		pu.onmouseout=pu.oldonMouseOut;
	}
	obj.pulled=false;
}

function hideAllSubMenus(){
//	xDisplay(xGetElementById('calendar-container'), 'none');

	if(!skipHiding){
		var submenus = xGetElementsByClassName('submenu_div');
		for(var i=0, sml=submenus.length; i<sml; i++){
			hidepulldown(submenus[i]);
		}

		sm_cities=xGetElementById('sm_cities');
		if(sm_cities){
			xDisplay(sm_cities, 'none');
		}

	}
	skipHiding = false;
}

function browseto(url){
	if(htmlrootpath===false) return;
	window.location=url;
	htmlrootpath=false;
}

function cclass(w, cl){
	if(w){
//		alert(cl);
		w.className=cl;
	}
}


function add_kicker(){
	var val=document.getElementById('new_kickers').value;
	if(val=='') return;
//	alert(val)
	ajax_indicator_on('kickers_wait');
	xajax__respondent('AddKicker', "$newkicker='" + val + "';");
	return false;
}

function typo(id, paragrapher){
//	$xajax->debugOn();
	var txt=xGetElementById('edit_' + id).value.replace(/'/g, "&prime;"); //'
	if(txt=='') return;
	ajax_indicator_on('aind'+id);
//	alert(txt);
	xajax__respondent('Typografer', "$txt='" + txt + "'; $id='" + id + "'; $paragrapher=" + paragrapher + ";");
	return false;
}

function hi(obj, cl){
	if(scripts_loaded) obj.className=cl;
}

function edit_picabout(id){
	xajax__respondent('EditPicabout', "$id=" + id + ";");
	return false;
}

function update_picabout(id, about0, about1){
	about0=escape(about0);
	about1=escape(about1);
	xajax__respondent('UpdatePicabout', " $id='" + id + "';  $about0='" + about0 + "';   $about1='" + about1 + "'; ");
	return false;
}



function addrandpar(obj){
	window.location=obj.href + '&roundabout=' + Math.random();
}

function ResizeTextArea(txtBox, nRowMin){
	
	nCols = txtBox.cols;
	sVal = txtBox.value;
	nVal = sVal.length;
	
	nBreakCnt = 0;
	nRowCnt = 1;
	
	for (i=0;i<nVal;i++) { 
		if (sVal.charAt(i) == '\n') { nBreakCnt +=1; } 
	}
	
	nRowCnt = 1 + (nVal / nCols) + nBreakCnt;
	if(nRowCnt < nRowMin) nRowCnt = nRowMin;
	
	nRowCnt = Math.floor(nRowCnt);
	txtBox.rows = nRowCnt;

//	alert(nRowCnt);

	
	//window.defaultStatus= "Luxe.ru: " + txtBox.value;
	//window.status = 'nCols: ' + nCols + ' | nVal: ' + nVal + ' | nRowCnt: ' + nRowCnt + ' | nBreakCnt: ' + nBreakCnt + ' | nCols ' + nCols;
	//document.myform.infoArea.value = 'nCols: ' + nCols + ' | nVal: ' + nVal + ' | nRowCnt: ' + nRowCnt + ' | nBreakCnt: ' + nBreakCnt + ' | nCols ' + nCols;
} 


function trim(string){
	return string.replace(/(^\s+)|(\s+$)/g, "");
}

function ShowPicViewStats(id){
	ajax_indicator_on('picture_views_ind');
	document.getElementById('picture_views').style.display = 'block';
	xajax__respondent('ShowPicViewStats', '$picture_id=' + id + ';');
	return false;
}

function ReplyFormMisc(id){
	if ( typeof ShowForumReplyForm.prev_id != 'undefined' ) {
		ajax_indicator_off('r'+ShowForumReplyForm.prev_id);
		document.getElementById('r'+ShowForumReplyForm.prev_id).style.display = 'none';
	}
	ShowForumReplyForm.prev_id = id;
	document.getElementById('r'+id).style.padding = '5px 0px';
	document.getElementById('r'+id).style.textAlign = 'right';
	document.getElementById('r'+id).style.display = 'block';
	ajax_indicator_on('r'+id);
}

function ShowForumReplyForm(id, topic, expand, expand_branch){
	ReplyFormMisc(id);
	xajax__respondent('ForumReplyForm', 
		'$message_id=' + id + 
		';$topic=' + topic + 
		';$expand=' + expand + 
		';$expand_branch=' + expand_branch + 
		';');
	return false;
}

function ShowForumReplyPreview(id, form, body, noformat){
	ajax_indicator_on('p'+id);

	xajax__respondent('ForumReplyPreview', 
		'$message_id=' + id + 
		';$body="' + body + 
		'";$noformat=' + noformat +
		';');
	return false;
}

function ShowPictureReplyForm(id, topic, obj, messages_count){
	ReplyFormMisc(id);
	xajax__respondent('PictureReplyForm', 
		'$message_id=' + id + 
		';$picture_id=' + topic + 
		';$messages_count=' + messages_count + 
		';$obj="' + obj + 
		'";');
	return false;
}


function days_in_month(month, year){
	if(month!=''){
		var months = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 30, 31);
		var d = months[month-1];
		if((month==2) && ((year%4)==0)) {d++;}
		return d;
	}
}
function fix_date(frm, vname, name){
	if((name.indexOf('mm_')!=-1) || (name.indexOf('yy_')!=-1)) {
		eval('var m_val = frm.mm_'+vname+'.value');
		eval('var y_val = frm.yy_'+vname+'.value');
		eval('var d = frm.dd_'+vname);
		var d_val = d.value;
		d.length = 0;
		for (var i=1;i<=days_in_month(m_val, y_val);i++) {
			d.options[i-1] = new Option(((i<10)?'0':'')+i,((i<10)?'0':'')+i);
		}
		d.options[d_val-1].selected = true;
	}
	eval('frm.'+vname+'.value = frm.yy_'+vname+'.value+"-"+frm.mm_'+vname+'.value+"-"+frm.dd_'+vname+'.value');
}

function refresh_gallery_overlay(){
	
	var imgGallery = $("a[rel='lightbox\[libo10\]']").size(); 
	if(imgGallery){
		$("a[rel='lightbox\[libo10\]']")
			.overlay({ target: '#gallery_overlay', expose: '#f1f1f1', effect: 'apple' })
			.gallery({ 
				speed: 800,
				template: '<strong>${title}</strong> <span>Фото ${index} из ${total}</span>'
			 });
	}
}

var scripts_loaded=true;