
$(document).ready(function(){

	$(".sitestr").treeTable();
	
	$("#archivemp3table").dataTable({"oLanguage": {"sUrl": "../styles/ru_RU.txt"},"iDisplayLength": 25});

		
		$.datePicker.setLanguageStrings(
		['Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота'],
		['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'],
		{p:'Пред', n:'След', c:'Закрыть', b:'Выберите дату'}
);
		$.datePicker.setDateFormat('dmy','.');
		//$('.datepick').datePicker({startDate:'01/01/2008'});
		$(".datepick").live("mousemove",function(){
			$(this).datePicker({startDate:'01/01/2008'})
			return false;
		});			
	//toggle message_body
	$(".sub_head").live("click",function(){
		$(this).next(".sub_body").slideToggle(500)
		return false;
	});

	//collapse all messages
	$(".collpase_all_subs").live("click",function(){
		$(".sub_body").slideUp(500)
		return false;
	});


	//show all messages
	$(".show_all_subs").live("click",function(){
		$(".sub_body").slideDown()
		return false;
	});


	$('.nyrocls').live("mousemove",function(){
		$(".nyrocls").click(function(){$.nyroModalRemove();});
		return false;
	});
  	
	$('.light_text').live("mousemove",function(){
		$('.light_text').wysiwyg({
	
	    controls : {

			bold :{ visible : true },
			italic :{ visible : true },
			strikeThrough :{ visible : true },
			underline :{ visible : true },
			separator00 :{ visible : true },
			justifyLeft :{ visible : false },
			justifyCenter :{ visible : false },
			justifyRight :{ visible : false },
			justifyFull :{ visible : false },
			separator01 :{ visible : false },
			indent :{ visible : false },
			outdent :{ visible : false },
			separator02 :{ visible : false }, 
			subscript :{ visible : true },
			superscript :{ visible : true },
			separator03 :{ visible : true },
			undo :{ visible : false },
			redo :{ visible : false },
			separator04 :{ visible : false },
			insertOrderedList :{ visible : false },
			insertUnorderedList :{ visible : false },
			insertHorizontalRule :{ visible : false },
			separator05 :{ visible : false },	 	
			createLink :{ visible : false },
			insertImage :{ visible : false },
			separator06 :{ visible : false },	 
			h1mozilla:{ visible : false },
			h2mozilla:{ visible : false },
			h3mozilla:{ visible : false },
			h1 :{ visible : false },
			h2 :{ visible : false },
			h3:{ visible : false },
			separator07 :{ visible : false },
			cut :{ visible : false },
			copy :{ visible : false },
			paste :{ visible : false },
			separator08 :{ visible : false },	 
			increaseFontSize :{ visible : false },
			decreaseFontSize :{ visible : false },
			separator09 :{ visible : false },	 
			html:{ visible : false },
			removeFormat :	{ visible : true }
	       
	    }
	});
	});
	
$('.rich_text').live("mousemove",function(){
$('.rich_text').wysiwyg({
	    controls : {
			 bold :{ visible : true },
			italic :{ visible : true },
			strikeThrough :{ visible : true },
			underline :{ visible : true },
			separator00 :{ visible : true },
			justifyLeft :{ visible : true },
			justifyCenter :{ visible : true },
			justifyRight :{ visible : true },
			justifyFull :{ visible : true },
			separator01 :{ visible : true },
			indent :{ visible : true },
			outdent :{ visible : true },
			separator02 :{ visible : true }, 
			subscript :{ visible : true },
			superscript :{ visible : true },
			separator03 :{ visible : true },
			undo :{ visible : true },
			redo :{ visible : true },
			separator04 :{ visible : true },
			insertOrderedList :{ visible : true },
			insertUnorderedList :{ visible : true },
			insertHorizontalRule :{ visible : true },
			separator05 :{ visible : true },	 	
			createLink :{ visible : true },
			insertImage :{ visible : true },
			separator06 :{ visible : false },	 
			h1mozilla:{ visible : false },
			h2mozilla:{ visible : false },
			h3mozilla:{ visible : false },
			h1 :{ visible : false },
			h2 :{ visible : false },
			h3:{ visible : false },
			separator07 :{ visible : true },
			cut :{ visible : true },
			copy :{ visible : true },
			paste :{ visible : true },
			separator08 :{ visible : true },	 
			increaseFontSize :{ visible : true },
			decreaseFontSize :{ visible : true },
			separator09 :{ visible : true },	 
			html:{ visible : true },
			removeFormat :	{ visible : true }
	    }
	});
	});
});	
 

formAjax = function (type,form) {
    // do an ajax post request
    $.ajax({
    url: "x_post.php?type="+type,
    type: "POST",
    data: $('form#'+form).formToArray(true),
    dataType : "json",
     
    beforeSend: function(){
    return php.beforeSend();
    },
    success: function(data, textStatus){
    return php.success(data, textStatus);
    },
    error: function (xmlEr, typeEr, except) {
    return php.error(xmlEr, typeEr, except);
    },
    complete: function (XMLHttpRequest, textStatus) {
    return php.complete(XMLHttpRequest, textStatus);
    }
    });
    return false;
    } 

	function ajaxFileUpload(prefix,file,path,filetype,targ,dtarg)
	{//,path,target,dtarget
		$("#"+prefix+"_loading")
		.ajaxStart(function(){
			$(this).show();
		})
		.ajaxComplete(function(){
			$(this).hide();
		});
	
		$.ajaxFileUpload
		(
			{//"+prefix+"_"+file
				url:"file_upload.php?field="+prefix+"_"+file+"&path="+path,
				secureuri:false,
				fileElementId:""+prefix+"_"+file+"",
				dataType: "json",
				success: function (data, status)
				{
					if(typeof(data.error) != "undefined")
					{
						if(data.error != "")
						{	
							alert(data.error);
						}else
						{
							if(filetype=='img')
							{	
								value = data.filepath;
								$('#'+targ).attr('value',value);
								div = '<img src="tumb.php?src='+data.filepath+'&size=100" border="1">';
								$('#'+dtarg).html(div).show("slow");
							}
							else
							{	
								value = data.filepath;
								$('#'+targ).attr('value',value);
								div = 'Имя файла: '+data.filename+'<br>Размер: '+data.filename;
								$('#'+dtarg).html(div).show("slow");
							}
							//alert(data.filepath);
							//alert(data.other);
						}
					}
				},
				error: function (data, status, e)
				{
					alert(e);
				}
			}
		)
		
		return false;

	}

	
