var g_id;
g_id=1;

    jQuery(document).ready(
	function() {
        jQuery("#inlineCity").fancybox({
        'frameWidth'         : 200,
        'frameHeight'         : 190,
        'hideOnContentClick': true,
        'modal'             : true,
        'showCloseButton'   : true,
        'transitionIn'        : 'none',
        'transitionOut'        : 'none' //,
		});
        jQuery("#inlineCat").fancybox({
        'frameWidth'         : 200,
        'frameHeight'         : 190,
        'hideOnContentClick': true,
        'modal'             : true,
        'showCloseButton'   : true,
        'transitionIn'        : 'none',
        'transitionOut'        : 'none' //,
		});
		if (document.getElementById("theme_out")) 
			refreshTheme();
    });
function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}
function refreshTheme()
{
	$.ajax({
		url: "a_forum.php",
		type : "POST",
		data : "forum="+document.getElementById("forum").value+"\
				&forum_id="+document.getElementById('forum_id').value+"\
				&page="+document.getElementById('a_page').value+"\
				&city="+document.getElementById('city').value+"\
				&id="+getCookie("id")+"\
				&category="+document.getElementById('category').value+"\
				",
		context: document.body,
		success: function(data){
				document.getElementById("theme_out").innerHTML=data;
			}
	}); 
}
function filterReset()
{
	document.getElementById('city').value=1;
	document.getElementById('category').value=1;
	document.getElementById("inlineCity").innerHTML=document.getElementById("city1").innerHTML;
	document.getElementById("inlineCat").innerHTML=document.getElementById("cat1").innerHTML;
	refreshTheme();
}
function setCity(a)
{
	b=document.getElementById("city"+a);
	c=b.innerHTML;
	document.getElementById("inlineCity").innerHTML=c;
	document.getElementById("city").value=a;
	if (a == 1)
			document.getElementById("category").value=1;
	$.fancybox.close();
//	document.getElementById("filterForm").submit();
	refreshTheme();
}
function setCat(a)
{
	b=document.getElementById("cat"+a);
	c=b.innerHTML;
	document.getElementById("inlineCat").innerHTML=c;
	document.getElementById("category").value=a;
	$.fancybox.close();
//	document.getElementById("filterForm").submit();
	refreshTheme();
}
function file_send() {
  hideFileLoad();
  d=document.getElementsByName('radio1');
  if (d[1].checked)
  {
	if (document.getElementById("file_url").value.substr(0,7) != "http://")
		document.getElementById("file_url").value="http://"+document.getElementById("file_url").value;
  }
  create_id=document.getElementById("create_id").value;
  if (document.getElementById("addComForm"))
	frm="addComForm";
  if (document.getElementById("addtopic"))
	frm="addtopic";

  sendForm(frm, "photo_load.php?crid="+create_id, callback);
  return false;
}
function sendForm(form, url, callfunc) {
  if (!document.createElement) return;
  if (typeof(form)=="string") form=document.getElementById(form);
  var frame=createIFrame();
  var act = form.getAttribute('action');
  frame.onSendComplete = function() {callfunc(form,act,getIFrameXML(frame));};
  form.setAttribute('target', frame.id);
  old_url=form.getAttribute('action');
  form.setAttribute('action', url);
  form.submit();
  form.setAttribute('action',old_url);
}

function createIFrame() {
  var id = 'f' + Math.floor(Math.random() * 99999); 
  var div = document.createElement('div');
  div.innerHTML = "<iframe style=\"display:none\" src=\"about:blank\" id=\""+id+"\" name=\""+id+"\" onload=\"sendComplete('"+id+"')\"></iframe>";
  document.body.appendChild(div);
  return document.getElementById(id);
}

function sendComplete(id) {
  var iframe=document.getElementById(id);
  if (iframe.onSendComplete &&
  typeof(iframe.onSendComplete) == 'function')  iframe.onSendComplete();
}

function getIFrameXML(iframe) {
  var doc=iframe.contentDocument;
  if (!doc && iframe.contentWindow) doc=iframe.contentWindow.document;
  if (!doc) doc=window.frames[iframe.id].document;
  if (!doc) return null;
  if (doc.location=="about:blank") return null;
  if (doc.XMLDocument) doc=doc.XMLDocument;
  return doc;
}
function chChange(a)
{
	ch=document.getElementById("ch"+a).checked;
	$.ajax({
		url: "photo_check.php?id="+a+"&ch="+ch,
		type : "GET", 
		context: document.body,
		success: function(){
			//$(this).addClass("done");
							}
	}); 

	document.getElementById("ph"+a).style.display="none";
}
function chPreChange(a)
{
	ch=document.getElementById("ch"+a).checked;
	$.ajax({
		url: "photo_check.php?id="+a+"&pre=1"+"&ch="+ch,
		type : "GET", 
		context: document.body,
		success: function(){
			//$(this).addClass("done");
		}
	}); 
	document.getElementById("ph"+a).style.display="none";
}

function callback(form,act,doc) {
  form.setAttribute('action', act);
  form.removeAttribute('target');
  a=doc.body.innerHTML.split("|");
  if (a[0] == "Error")
  {
    alert(a[1]);
  } else
  {
	var ndiv=document.createElement('div');
	ndiv.className="photo-item";
	if (a[1].substr(0,7) == "http://")
	{
		ns="<img src="+a[1]+" width=120>"
		ns=ns+"<br><span><input id='ch"+a[4]+"' name='ph"+a[4]+"' type=checkbox checked onchange=chPreChange('"+a[4]+"')>"; // onchange=chChange('";
		ndiv.innerHTML=ns;
	} else
	{
		ns="<img src=topic_photo/thumb/"+a[1]+"><br />";
		ns=ns+"<br><span><input id='ch"+a[4]+"'name='ph"+a[4]+"' type=checkbox checked onchange=chPreChange('"+a[4]+"')>"; // onchange=chChange('";
		ns=ns+"</span><span>"+a[2]+"</span><br />";
		ns=ns+"<br />"+(a[3]/1024).toFixed(1)+" kb";
		ndiv.innerHTML=ns;
	}
    document.getElementById("photo_place").appendChild(ndiv);
	hideFileLoad();
  }
}
function showFileLoad()
{
	document.getElementById("file_input_div").innerHTML = 
    document.getElementById("file_input_div").innerHTML;
	document.getElementById("file_url").value=""; //"http://";
	
	d=document.getElementsByName("radio1");
	d[0].checked="checked";
	d[1].checked="";
	
	document.getElementById("file_url").disabled=true;
	document.getElementById("file_choise").disabled=false;
	document.getElementById("fcomm").value="";

   document.getElementById('fileInterface').style.display = 'block';
	return false;
}
function hideFileLoad()
{
   document.getElementById('fileInterface').style.display = 'none';
   return false;
}
function checkBodyComment()
{
	if (document.getElementById("t1").value="")
	{
		alert('Поле "Сообщение" обязатеельно для заполнения');
		return false;
	}; 
}
function ch_subscribe(a,b)
{
	ch=document.getElementById("ch_sub").checked;
	$.ajax({
		url: "subscribe.php?id="+a+"&th="+b+"&ch="+ch,
		type : "GET", 
		context: document.body,
		success: function(){
			//$(this).addClass("done");
			}
	}); 
//	document.getElementById("ph"+a).style.display="none";
//	document.getElementById("ch_sub").checked
}
function smpAddForm()
{
return;		
  a=document.createElement('div');
  a.style.border='1px solid #000';
  a.style.margin='10px';
  b='<table style="margin:10px auto">\
<tr><td>Ник :<br/>&nbsp;<td><input type=\"text\" name=\"nik[]\" id=\"nik_'+g_id+'\" size=\"20\" lenght=\"20\" onkeyup=\"nik_check('+g_id+')\"><input type=checkbox id=\"nik_check_out_'+g_id+'\" >\
<tr><td>Пароль :<br/>&nbsp;<td><input type=text name=passwd[] size=20 lenght=20>\
<tr><td>Статус :<br/>&nbsp;<td><select><option>барабанщик</option><option>начинающий</option><option>сочувствующий</option></select>\
<tr><td>Город :<br/>&nbsp;<td><select><option>Питер</option><option>Москва</option></select>\
<tr><td>Возраст :<br/>&nbsp;<td><input type=\"text\" name=\"age[]\" size=3 lenght=3>\
<tr><td>E-mail :<br/>&nbsp;<td><input type=\"text\" name=\"mail[]\" id=\"mail_'+g_id+'\" size=20 lenght=40 onkeyup=\"mail_check('+g_id+')\"><input type=checkbox id=\"mail_check_out_'+g_id+'\" >\
<tr><td>Тема :<br/>&nbsp;<td><input type=text name=thema[] size=20 lenght=20>\
<tr><td>Действие :<br/>&nbsp;<td><input type=text name=action[] size=20 lenght=20>\
<tr valign=top><td style=\"vertical-align : middle;\">Сообщение :<td><textarea cols=40 rows=10></textarea>\
</table><br />';
g_id=g_id+1;
  a.innerHTML=b;
  c=document.getElementById("smp_form");
  c.appendChild(a);
}
function nik_check(a)
{
	b=document.getElementById('nik_'+a).value;
	c="nik_check_out"+a;
	if (b == "")
	{
		document.getElementById(c).checked="";
		return false;
	}
	$.ajax({
		url: "spamm.php?nik="+b+"&check=1",
		type : "POST", 
		context: document.body,
		success: function(data){
			if (data == "Yes")
				document.getElementById(c).checked="checked";
			else
				document.getElementById(c).checked="";
			}
	}); 
}
function smpreg()
{
//	b=document.getElementById('mail_'+a).value;
//	c="mail_check_out_"+a;
//	if (b == "")
//	{
//		document.getElementById(c).checked="";
//		return false;
//	}
	$.ajax({
		url: "register.php",
		type : "POST",
		data : "newlogin="+document.getElementById("nik_0").value+"\
				&oldlogin=&password="+document.getElementById('password').value+"\
				&password2="+document.getElementById('password').value+"\
				&email="+document.getElementById('email').value+"\
				&status="+document.getElementById('status').value+"\
				&age=\
				&icq=\
				&experience=\
				&style=\
				&instrument=\
				&teacher=\
				&musicien=\
				&city=\
				&url=\
				&quest=Лед Зеппелин\
				",
		context: document.body,
		success: function(data){
			if (data == "Yes")
				document.getElementById(c).checked="checked";
			else
				document.getElementById(c).checked="";
			}
	}); 
}
function showCityChoice()
{
	a=document.createElement('div');
	a.style.width="100%";
	a.style.height="100%";
	document.appendChild(a);
	return false;
}
function showCitySelectBox()
{
	document.getElementById('citySelectBox').style.display="box";
}
function fileSendUrl()
{
	a=document.getElementsByName("radio1");
	if (a[0].checked)
	{
		document.getElementById("file_choise").disabled=false;
		document.getElementById("file_url").disabled=true;
		document.getElementById("li0").className="";
		document.getElementById("li1").className="disabled";
	} else
	{
		document.getElementById("li1").className="";
		document.getElementById("li0").className="disabled";
		document.getElementById("file_url").disabled=false;
		document.getElementById("file_choise").disabled=true;
	}
}
function hideURLInterface()
{
	document.getElementById("urlInterface").style.display="none";
}
function showURLInterface()
{
	document.getElementById("valueURL").value="";
	document.getElementById("opisURL").value="";
	document.getElementById("urlInterface").style.display="block";
}
function insertURLTag()
{
	if (document.getElementById("valueURL").value == "")
	{
		alert("Не введён адрес ссылки.");
		return false;
	}
	if (document.getElementById("opisURL").value == "")
	{
		alert("Нет названия ссылки.");
		return false;
	}
	if (document.getElementById("valueURL").value.substr(0,7) != "http://")
		document.getElementById("valueURL").value="http://"+document.getElementById("valueURL").value;
	document.getElementById("t1").value=document.getElementById("t1").value+"[url="+document.getElementById("valueURL").value+"]"+document.getElementById("opisURL").value+"[/url]";
	document.getElementById("urlInterface").style.display="none";
}

