var blog_mode = false;

function check_loginform(){
if ((document.loginform.user.value.length == 0)||(document.loginform.pass.value.length == 0)){
	alert('Вы заполнили не все поля! Укажите своё имя и пароль!')
	return false;
 }
return true;
}

function submit_once(theform){
if (document.all||document.getElementById){
	for (i=0; i<theform.length; i++){
		var tempobj=theform.elements[i]
		if (tempobj.type.toLowerCase()=="submit" || tempobj.type.toLowerCase()=="reset") {tempobj.disabled=true}
	}
}
}

function getCookie(name) {
var prefix = name + "="
var StartIndex = document.cookie.indexOf(prefix)
if (StartIndex == -1)
return null
var EndIndex = document.cookie.indexOf(";", StartIndex + prefix.length)
if (EndIndex == -1)
EndIndex = document.cookie.length
return unescape(document.cookie.substring(StartIndex + prefix.length, EndIndex))
}

function set_albumform_view(param){
v1 = document.getElementById('view1').style;
v2 = document.getElementById('view2').style;
v1.display = v2.display = 'none';
if (param==5) v1.display = '';
if (param==6) v2.display = '';
}

function check_albumform(){
if (document.album.albumdelete.checked){
	return confirm('Вы действительно хотите удалить альбом со всеми фотографиями?');
}
if (document.album.name.value.length == 0){
	alert('Вы не указали имя альбома!');
	document.album.name.focus();
	return false;
}
if ((document.album.access.selectedIndex==4) && (document.album.password.value.length == 0)){
	alert('Вы не указали пароль доступа к альбому!');
	document.album.password.focus();
	return false;
}
if ((document.album.access.selectedIndex==5) && (document.album.users.value.length == 0)){
	alert('Вы не указали имена посетителей, допущенных к просмотру альбома!');
	document.album.users.focus();
	return false;
}
return true;
}

function check_deletephoto(){
return confirm('Вы действительно хотите удалить фотографию?');
}

function check_editphotoform(){
if (document.photo.delete_photo.checked){
	return confirm('Вы действительно хотите удалить фотографию?');
}
}

function hex_color(v){
var hex="0123456789abcdef";
color=hex.charAt(v/16)+hex.charAt(v%16);
return '#'+color+color+color;
}

function fullscreen_image(url) {
var win = window.open('','','fullscreen=yes,menubar=0,location=0,scrollbars=0,directories=0,resizable=0,status=0');
var doc = win.document;
var td_text = '';
for (i=0; i<=255; i++) {
	color=hex_color(i);
	td_text+='<td width=2 class="s" bgcolor="'+color+'" onMouseOver="document.bgColor=\''+color+'\'"><br>&nbsp;</td>\n';
}
doc.writeln('<html><head><style type="text/css">.s {font-family: Small Fonts, Verdana, Arial; font-size: 5pt}</style></head><body bgcolor="#808080"><table width="100%" height="100%" cellpadding="0" cellspacing="0" border="0"><tr><td align="center" onClick="window.close()"><a href="#" onClick="window.close()"><img border=0 src="'+url+'"></a></td></tr><tr><td height="2%">\n');
doc.writeln('<table align="center" cellpadding="0" cellspacing="0" border="0"><tr style="cursor: crosshair">'+td_text+'</tr></table></td></tr></table></body></html>');
}

function expand_menu(expand_id) {
var e = document.getElementById(expand_id).style;
var i = document.getElementById(expand_id+'-img');
if (e.display=="none") {
	e.display=""
	if (i) i.src = 'img/menu-array-up.gif';
} else {
	e.display="none"
	if (i) i.src = 'img/menu-array-down.gif';
}; 
}

function print_size(size){
return (size>1024*1024) ? Math.round(size*100/1024/1024)/100+" Мб" : Math.round(size*100/1024)/100+" Кб";
}

function print_thumbs_table(table_id, reinit){
table_width = (document&&document.body && document.body.clientWidth) ? document.body.clientWidth : window.innerWidth;
table_width = Math.round(table_width*0.8);
old_table_id=table_id;
columns =  Math.round(table_width/200);
if (columns<3) columns = 3;
if ((columns!=old_columns) || reinit){
	old_columns=columns;
	cell_width=Math.ceil(100/columns);
	text='<table class="viewalbumpreview">'
	i=columns; tr1=''; tr2=''; tr3='';
	for (j=0; j<data.length; j++) {
		i++;
		if (i>columns){
			if (j>0) text+='<tr>'+tr1+'</tr><tr>'+tr2+'</tr><tr>'+tr3+'</tr>';
			i=1; 	tr1=''; tr2=''; tr3='';
		}
		if (blog_mode){
			tr1+='<td id="td1'+data[j][3]+'" align=center valign=top width="'+cell_width+'%" onclick="blog_code_check('+data[j][3]+')" style="cursor: hand; border-right: 2px white solid"><div style="float:left"><input type=checkbox id="cb'+data[j][3]+'" onclick="blog_code_check('+data[j][3]+')"></div><a href="'+site_prefix+data[j][3]+'"><img border=0 style="margin: 17px" src="'+data[j][4]+'"></a></td>';
			tr2+='<td id="td2'+data[j][3]+'" align=center valign=center class="d" width="'+cell_width+'%" onclick="blog_code_check('+data[j][3]+')" style="cursor: hand;border-right: 2px white solid">'+data[j][1]+'</td>';
			tr3+='<td id="td3'+data[j][3]+'" align=center valign=top class="d2" width="'+cell_width+'%" onclick="blog_code_check('+data[j][3]+')" style="cursor: hand; border-right: 2px white solid; border-bottom: 2px white solid">'+data[j][2]+'</td>';
		} else {
			tr1+='<td align=center valign=top width="'+cell_width+'%">'+data[j][0]+'</td>';
			tr2+='<td align=center valign=center class="d" width="'+cell_width+'%">'+data[j][1]+'</td>';
			tr3+='<td align=center valign=top class="d2" width="'+cell_width+'%">'+data[j][2]+'</td>';
		}
	}
	if (data.length>0) text+='<tr>'+tr1+'</tr><tr>'+tr2+'</tr><tr>'+tr3+'</tr>';
	text+='</table>'
	document.getElementById('thumbs_table'+table_id).innerHTML=text;
}
}

function blog_code_init(){
blog_mode = (document.getElementById('blogdiv').style.display=='none');
if (blog_mode){
	document.getElementById('blogdiv').style.display = '';
} else {
	document.getElementById('blogdiv').style.display = 'none';
}
print_thumbs_table(old_table_id, true)
}

function blog_code_check(id){
document.getElementById('cb'+id).checked = (document.getElementById('cb'+id).checked) ? false  : true;
if (document.getElementById('cb'+id).checked){
	document.getElementById('td1'+id).style.backgroundColor='#eef0f7';
	document.getElementById('td2'+id).style.backgroundColor='#eef0f7';
	document.getElementById('td3'+id).style.backgroundColor='#eef0f7';
} else {
	document.getElementById('td1'+id).style.backgroundColor='white'
	document.getElementById('td2'+id).style.backgroundColor='white'
	document.getElementById('td3'+id).style.backgroundColor='white'
}
blog_code_update();
}

function blog_code_update(){
text1 = "";
text2 = "";
text3 = "";
for (i=0; i<data.length; i++) {
	id=data[i][3];
	if (document.getElementById('cb'+id).checked){
		text1+='<a href="'+site_prefix+id+'">'+data[i][5]+':<br><img src="'+data[i][4]+'"></a><br><br>\n';
		text2+='[url='+site_prefix+id+']'+data[i][5]+':\n[img]'+data[i][4]+'[/img][/url]\n\n';
		text3+=site_prefix+id+'\n';
	}
}
document.getElementById('blog_code_text1').value=text1;
document.getElementById('blog_code_text2').value=text2;
document.getElementById('blog_code_text3').value=text3;
document.getElementById('blog_code_block').style.display = (text1=='') ? 'none' : ''
}


