var nWinExist=0; // признак открытия доп.окна
var nWinBExist=0; // признак открытия большого доп.окна
var nWinExistXY=0; // признак открытия доп.окна с координатами
var name_field;
var nPostidEx=-1; // уже открытая форма комментариев

function init() {
  //закругляем углы
  $("#razd_1").corner("round 4px");
  $("#radio").corner("round 6px");
  $(".block").corner("round 4px");
  $(".r_corner").corner("round 4px");
  $(".b_corner").corner("corners right round 16px");
  $("#page_table").corner("round 6px");
  $(".tab1c").corner("corners top round 4px");
  $(".tab2c").corner("corners top round 4px");
  $("#window_a").corner("round 6px");
  $(".float_fix").corner("corners top round 6px");
  $("#logo").corner("corners left round 6px");
  $("#shapka").corner("corners right round 6px");
  $(".menu_unsel").corner("round 3px");
  $(".menu_sel").corner("round 3px");
  $("#footer").corner("round 6px");
  $("#maincol").corner("round 6px");
  

  //setInterval("setClock()",999);
  //setClock();

  //блоки прокрутки
  $('#content_news').cycle({ 
  fx:     'scrollHorz',
  easing: 'easeInOutExpo',
  prev:   '#prev',
  next:   '#next',
  height: 1650,
  timeout: 0
  });
  $("#c_1").css("display", "block");
  
  $("#logo").get(0).onclick = function(){  
    window.location.href="/";
    return false;
  }
  
  // отображение содержания статьи
  //var aSizes = GetSizes();
  //wHeight = aSizes.winHeight + 'px';
  //$("#article").css("height", wHeight);

  // float-кнопки слева
  var cBrow = BrowserDetect.browser;
  if (cBrow == 'Explorer') {
    var fix_top = $(window).height() + $(document).scrollTop() -1 + "px";
 	$('.float_fix').css("top", fix_top);
  }
  $('.float_fix').css("display", "block");

   // функции всплывающих окон
   $('#windowMax').hide();
   $('#wSetting').bind(
	   'click',
		function(event) {
			if ($('#window').css('display') == 'none') {
              if (window.event) {
                evt = window.event;
                if (evt.pageX) {
                  nX = evt.pageX;
                  nY = evt.pageY;
                }    		  
      		    else if (evt.clientX) {
    		      nX = evt.clientX + document.body.scrollLeft - document.body.clientLeft;
    		      nY = evt.clientY + document.body.scrollTop - document.body.clientTop;
    		      if (document.body.parentElement && document.body.parentElement.clientLeft) {
                    var bodParent = document.body.parentElement;
                    nX += bodParent.scrollLeft - bodParent.clientLeft; 
                    nY += bodParent.scrollTop - bodParent.clientTop; 
                  }
                }
              }
    		  else {
    		    nX = event.pageX;
    		    nY = event.pageY;
    		  }
    		  var nTop = nY - 140;
     		  nTop +=  'px';
			  $('#window').animate({opacity: "show", top: nTop}, "slow");
			  loadOptions();
		      $('#window').show();
			}
		}
	);

    $('#windowClose_a').bind(
	  'click',
      function(event) {		
        $("#wblack").css("display", "none");
  	    $('#window_a').hide();
  	  }
    );

	$('#windowClose').bind(
		'click',floatWindowClose);
	$('#windowMin').bind(
		'click',
		function()
		{
			$('#windowContent').SlideToggleUp(300);
			$('#window').animate({height:30},300).get(0).isMinimized = true;
			$(this).hide();
			$('#windowResize').hide();
			$('#windowMax').show();
		}
	);
	$('#windowMax').bind(
		'click',
		function()
		{
			var windowSize = $.iUtil.getSize(document.getElementById('windowContent'));
			$('#windowContent').SlideToggleUp(300);
			$('#window').animate({height:windowSize.hb+43}, 300).get(0).isMinimized = false;
			$(this).hide();
			$('#windowMin, #windowResize').show();
		}
	);
	$('#window').Resizable(
		{
			minWidth: 200,
			minHeight: 60,
			maxWidth: 700,
			maxHeight: 400,
			dragHandle: '#windowTop',
			handlers: {
				se: '#windowResize'
			},
			onResize : function(size, position) {
				var windowContentEl = $('#windowContent').css('width', size.width - 25 + 'px');
				if (!document.getElementById('window').isMinimized) {
					windowContentEl.css('height', size.height - 48 + 'px');
				}
			}
		}
	);

    $(window).resize(function () { 
      var aSizes = GetSizes();
      wWidth = aSizes.pageWidth + 'px';
      wHeight = aSizes.pageHeight + 120 + 'px';
      $("#wblack").css("width", wWidth).css("height", wHeight);
      //wHeight = aSizes.winHeight + 'px';
      //$("#article").css("height", wHeight);
    });
}

// первая загрузка - реклама
function firstAdvert() {
  var cBrow = BrowserDetect.browser;
  var aSizes = GetSizes();
  wWidth = aSizes.pageWidth + 'px';
  wHeight = aSizes.pageHeight + 120+ 'px';
  if (cBrow == 'Explorer') {
    wSt = aSizes.winScrollTop + 300 + 'px';
    $("#window_a").css("top", wSt);
  }
  $("#wblack").css("width", wWidth).css("height", wHeight).css("display", "block");
  $('#window_a').animate({opacity: "show"}, "slow");
  $('#window_a').show();
  $('#windowClose_a').stopAll().fadeIn(30000,0, function(){$(this).show();});
}  

// работа с всплывающими окнами
function loadOptions(cStroka,imageWidth,imageHeight) {
  var nW = imageWidth + 30 + 'px';
  $("#window").css('width', nW);
  $("#window").css('min-width', nW);
  $("#windowResult").hide();
  $("#windowContent").empty();
  $("#windowContent").append(cStroka);
  $("#windowContent").show();
}
function floatWindowClose() {
  $('#window').hide();
}
// конец работы со вспл.окнами

// окно для радио
function popupw(URL,w,h,uid,dp,id){ 
if(!w||w<100)w=100; 
if(!h||h<100)h=100; 
if(!id)id=''; 
var www;if(!uid) uid='';if(!dp) dp=''; 
www=window.open(URL+id,'aod'+uid,'width='+w+',height='+h+',top=0,toolbar=no,personalbar=no,location=no,directories=no,statusbar=no,menubar =no,status=no,resizable=yes,left=60,screenX=60,top=100,screenY=100'+dp); 
return false; 
} 
function pppwnew(URL) {return popupw(URL, 390, 100, 'rambleraudioplayer', false, '');} 
// конец окна для радио

function ShowHide(pid1)
{
  pid=pid1;
  var container = document.getElementById("tr_" + pid1);		
  if (container!=null)
  {
    if (container.style.display != "none")
      container.style.display = 'none';
    else
      container.style.display = 'block';
  }
}

function winop(cPage) {
 if (nWinExist==1) {
   windop.close();
   nWinExist=0;
 }
 windop = window.open(cPage,"mywin","toolbar=yes,resizable=yes,scrollbars=yes,height=500,width=700,left=100,top=30");
 nWinExist=1;
} 

function winopxy(cPage,nHeight,nWidth) {
// height +30 width +20 
 if (nWinExistXY==1) {
   windopxy.close();
   nWinExistXY=0;
 }
 windopxy = window.open(cPage,"mywin","toolbar=no,scrollbars=no,height="+nHeight+",width="+nWidth+",left=50,top=50");
 nWinExistXY=1;
}

function winopxysc(cPage,nHeight,nWidth) {
// height +30 width +20 
 if (nWinExistXY==1) {
   windopxy.close();
   nWinExistXY=0;
 }
 windopxy = window.open(cPage,"mywin","toolbar=no,scrollbars=yes,resizable=yes,height="+nHeight+",width="+nWidth+",left=100,top=30");
 nWinExistXY=1;
}

function winbop(cPage) {
 if (nWinBExist==1) {
   winbdop.close();
   nWinBExist=0;
 }
 winbdop = window.open(cPage,"mywinb","");
 nWinBExist=1;
}


function fconfirm(inForm)
{
  var cError="Форма не заполнена:";
  
  if (inForm.name=='coment_form')
  {
    if (inForm.poster.value=='')
      cError=cError+"\n- Не введено имя";
    if (inForm.ftitle.value=='')
      cError=cError+"\n- Не введена тема";
    if (inForm.message.value=='')
      cError=cError+"\n- Не введен ответ";
    if (inForm.control.value=='')
      cError=cError+"\n- Не введено контрольное число";
  }
  if (inForm.name=='forget_form')
  {
    if (inForm.useremail.value=='')
      cError=cError+"\n- Не введен E-mail";
    if (inForm.control.value=='')
      cError=cError+"\n- Не введено контрольное число";
  }  
  if (inForm.name=='message_form')
  {
    if (inForm.author.value=='')
      cError=cError+"\n- Вы не представились";
    if (inForm.useremail.value=='')
      cError=cError+"\n- Не введен E-mail";
    if (inForm.mescont.value=='')
      cError=cError+"\n- Нет текста сообщения";
    if (inForm.control.value=='')
      cError=cError+"\n- Не введено контрольное число";
  }  
  if (inForm.name=='gbook_form')
  {
    if (inForm.author.value=='')
      cError=cError+"\n- Вы не представились";
    if (inForm.useremail.value=='')
      cError=cError+"\n- Не введен E-mail";
    if (inForm.contgbook.value=='')
      cError=cError+"\n- Нет текста сообщения";
    if (inForm.control.value=='')
      cError=cError+"\n- Не введено контрольное число";
  }  
  if (inForm.name=='login_form')
  {
    if (inForm.username.value=='')
      cError=cError+"\n- Нет выражения для поиска";
  }
  if (inForm.name=='poisk_form')
  {
    if (inForm.poisk.value=='')
      cError=cError+"\n- Нет выражения для поиска";
  }
  if (inForm.name=='coment_form')
  {
    if (inForm.author.value=='')
      cError=cError+"\n- Вы не представились";
    if (inForm.useremail.value=='')
      cError=cError+"\n- Не введен E-mail";
    if (inForm.contcoment.value=='')
      cError=cError+"\n- Нет комментария";
  }
  if (inForm.name=='new_blog_form')
  {
    if (inForm.content.value==0)
      cError=cError+"\n- Не выбрана категория";
    if (inForm.mainrazd.value==0)
      cError=cError+"\n- Не выбрана подкатегория";
    if (inForm.statusblog.value==0)
      cError=cError+"\n- Не выбран статус статьи";
    if (inForm.nameblog.value=='')
      cError=cError+"\n- Нет названия статьи";
    if (inForm.keywords.value=='')
      cError=cError+"\n- Нет ключевых слов";
    if (inForm.contblog.value=='')
      cError=cError+"\n- Нет анотации статьи";
    if (inForm.contsubrazd.value=='')
      cError=cError+"\n- Нет текста статьи";
//    if (inForm.useremail.value=='')
//      cError=cError+"\n- Не введен E-mail";

//    cUserEmail=inForm.useremail.value;    
//    if (cUserEmail=='') {
//    } 
    //   проверяет наличи  '@' 
//    else if (cUserEmail.indexOf("@",4)==-1) 
//      cError=cError+"\n- Ваш электронный адрес не содержит в себе '@'";
    //  проверяет наличие 'точки'
//    else if (cUserEmail.indexOf(".",7)==-1 ) 
//      cError=cError+"\n- Ваш электронный адрес не содержит в себе '.'";
  }  
  if (cError!="Форма не заполнена:")
    alert (cError);
  else
  {
    if (confirm("Подтверждаете выполнение операции ?"))
      inForm.submit();
  }
}


var hotkey=13;
var inFormObj;
if (document.layers)
  document.captureEvents(Event.KEYPRESS);

function confirmobj(inForm,inFormOb)
{
  if (confirm("Подтверждаете выполнение операции ?"))
  {
    inFormObj=inFormOb;
    inFormObj.value=true;
    inForm.submit();
  }
}  

function pressonoff(onoff,inFormOb)
{
  inFormObj=inFormOb;
  if (inFormObj==null)
  {
    document.onkeypress=null;
    return;
  }
  if (onoff==1)
    document.onkeypress=mypress;
  else
    document.onkeypress=null;
}

function mypress(key)
{
 if (document.layers)
 {
   if (key.which==hotkey)
     inFormObj.value=inFormObj.value+"<BR>";
 }
 else if (!document.all)
 {
   if (key.which==hotkey)
     inFormObj.value=inFormObj.value+"<BR>";
 }

 if (document.all)
 {
   if (event.keyCode==hotkey)
     inFormObj.value=inFormObj.value+"<BR>";
 }
}

function fnApplyTag(inForm, sTag) {
  if (inForm.name=='edit_blog_form') {
    if (document.selection) 
       var selection = document.selection.createRange().text;
    else        
       var selection = inForm.contsubrazd.value.substring(inForm.contsubrazd.selectionStart, inForm.contsubrazd.selectionEnd);
    inForm.contsubrazd.value=inForm.contsubrazd.value.replace(new RegExp(selection, ''), '['+sTag+']'+selection+'[/'+sTag+']');
  } else {
    if (document.selection) 
       var selection = document.selection.createRange().text;
    else        
       var selection = inForm.message.value.substring(inForm.message.selectionStart, inForm.message.selectionEnd);
    inForm.message.value=inForm.message.value.replace(new RegExp(selection, ''), '['+sTag+']'+selection+'[/'+sTag+']');
  }
}

function pastesmile(text)
{
  if (document.new_post_form) 
  {
    if (document.selection) 
    { 
      if (name_field=='title') 
  	    document.new_post_form.ftitle.focus();
  	  else
	    document.new_post_form.message.focus();

  	  document.new_post_form.document.selection.createRange().text = text;
    } 
    else
    { 
      if (name_field=='title') 
        document.new_post_form.ftitle.value += text;
  	  else
        document.new_post_form.message.value += text;
    }
  }
}


function pastesmile_com(inForm,text)
{
  if (inForm) 
  {
    if (document.selection) { 
      if (name_field=='message') 
        inForm.message.focus();
      else
        inForm.ftitle.focus();
  	  
  	  inForm.document.selection.createRange().text = text;
    } 
    else {
      if (name_field=='message') 
        inForm.message.value += text;
      else
        inForm.ftitle.value += text;
    }
  }
}


function ShowHide_Com(pid1,pid2)
{
  var container1 = document.getElementById("ttr_" + pid1);		
  var container2 = document.getElementById("ttr_" + pid2);		
  var container3 = document.getElementById("ttr_3");		
  if (container1)
  {    
    if (container1.style.display != "none")
    {
    }   
    else
      container1.style.display = 'block';
  }
  if (container2)
  {    
    if (container2.style.display != "none")   
      container2.style.display = 'none';
  }
  if (container3)
  {    
    if (pid1==2)
    {
      if (container3.style.display != "none")   
      {
      }
      else  
        container3.style.display = 'block';
    }
    if (pid1==1)
    {
      if (container3.style.display != "none")   
        container3.style.display = 'none';
    }
  }
}


function chTab(nTab) 
{
  if (nTab==1) {
    $('#tab1c').css('background', '#202020');
    $('#tab2c').css('background', '#4E4E4E');
    $('#tab1c').css('padding', '8px 20px 7px 20px'); 
    $('#tab2c').css('padding', '6px 20px 5px 20px'); 
    $('#c_1').css('display', 'block');
    $('#c_2').css('display', 'none');
  }
  else {
    $('#tab2c').css('background', '#202020');
    $('#tab1c').css('background', '#4E4E4E');
    $('#tab2c').css('padding', '8px 20px 7px 20px'); 
    $('#tab1c').css('padding', '6px 20px 5px 20px'); 
    $('#c_2').css('display', 'block');
    $('#c_1').css('display', 'none');
  }
  $(".tab1c").corner("corners top round 4px");
  $(".tab2c").corner("corners top round 4px");
}

function chPicture(cPicture,nWidth){
  cPicture = '"./images/content/'+cPicture+'.jpg"';
  var cDivContent = '<A href='+cPicture+' class=thickbox><IMG style="BORDER: #D9D9D9 1px solid; padding: 10px;" src='+cPicture+' width='+nWidth+' border=0 align=middle HSPACE=5 VSPACE=0 ALT="Увеличить изображение"></A>';    
  var cZoomContent = '<IMG SRC=./images/lupa.gif BORDER=0 ALIGN=middle HSPACE=2 WIDTH=16 HEIGHT=16 VSPACE=0><A HREF='+cPicture+' class=thickbox>увеличить изображение</A>';
  $("#cPicture").empty().hide();  
  $("#cPicture").append(cDivContent).show("slow");  
  $("#cZoom").empty();  
  $("#cZoom").append(cZoomContent);  
}

function Comment_Div(nPostid) 
{
  if (nPostidEx >= 0) {
    if (nPostidEx != nPostid) 
      $('#comment_div'+nPostidEx).css('display', 'none');
    else
      $('#comment_div'+nPostidEx).hide("slow");  
    $('#nComHref'+nPostidEx).empty();  
    
    if (nPostidEx==0)
      $('#nComHref'+nPostidEx).append('Написать комментарий');  
    else
      $('#nComHref'+nPostidEx).append('Ответить');  
    if (nPostidEx == nPostid) {
      nPostidEx = -1;
      return;
    }
  }

  if (nPostidEx != nPostid) {
    $('#nComHref'+nPostid).empty();  
    $('#comment_div'+nPostid).show("slow");  
    $('#nComHref'+nPostid).append('Скрыть');  
    nPostidEx = nPostid;
  }
}


function show_MaxImage(cId) {
  imgLoader = new Image();// preload image
  imgLoader.src = './images/content/'+cId+'.jpg';
  var imageWidth = imgLoader.width;
  var imageHeight = imgLoader.height;
 
  if ($('#window').css('display') == 'none') {
    if (window.event) {
      evt = window.event;
      if (evt.pageX) {
        nX = evt.pageX;
        nY = evt.pageY;
      }    		  
      else if (evt.clientX) {
        nX = evt.clientX + document.body.scrollLeft - document.body.clientLeft;
        nY = evt.clientY + document.body.scrollTop - document.body.clientTop;
        if (document.body.parentElement && document.body.parentElement.clientLeft) {
          var bodParent = document.body.parentElement;
           nX += bodParent.scrollLeft - bodParent.clientLeft; 
           nY += bodParent.scrollTop - bodParent.clientTop; 
        }
      }
    }
    else {
      nX = event.pageX;
      nY = event.pageY;
    }
    var nTop = nY - 140;
    nTop +=  'px';
	$('#window').animate({opacity: "show", top: nTop}, "slow");
    loadOptions('<img src=./images/content/'+cId+'.jpg hspace=10 style="max-width: 600px;">',imageWidth,imageHeight);
	$('#window').show();
  }
}

function setClock() {
  var dLoc=Math.round((D=new Date()).getTime()/1000);
  //var nCorrect = 400; // корректировка времени сервера
  var nCorrect = 0; // корректировка времени сервера
  dLocKiev=(dLoc+tDelta+gmtMsk-nCorrect)*1000;
  dLocMsk=(dLoc+tDelta+gmtMsk+gmtMsk-nCorrect)*1000;
  showTime('tPoint',new Date(dLocKiev+gmtAdd));
  showTime('tPoint_msk',new Date(dLocMsk+gmtAdd));
}
function showTime(cId,tTime) {
  var min,sec;
  $('#'+cId).empty();
  if (cId == 'tPoint')
  	$('#'+cId).append(tTime.getHours()+':'+((min=tTime.getMinutes())<10?'0':'')+min);
  if (cId == 'tPoint_msk')
  	$('#'+cId).append('Московское время'+' &nbsp;'+tTime.getHours()+':'+((min=tTime.getMinutes())<10?'0':'')+min);
}

function  GetSizes() {
    var w=document.documentElement; var d=document.body;
    var tww = document.compatMode=='CSS1Compat' && !window.opera?w.clientWidth:d.clientWidth;
    var twh = document.compatMode=='CSS1Compat' && !window.opera?w.clientHeight:d.clientHeight;
    var sl = (window.scrollX)?window.scrollX:(w.scrollLeft)?w.scrollLeft:d.scrollLeft;
    var st = (window.scrollY)?window.scrollY:(w.scrollTop)?w.scrollTop:d.scrollTop;
    var wW1 = (window.innerHeight && window.scrollMaxY)?d.scrollWidth:(d.scrollHeight > d.offsetHeight)?d.scrollWidth:(w && w.scrollHeight > w.offsetHeight)?w.scrollWidth:d.offsetWidth;
    var wH1 = (window.innerHeight && window.scrollMaxY)?d.scrollHeight:(d.scrollHeight > d.offsetHeight)?d.scrollHeight:(w && w.scrollHeight > w.offsetHeight)?w.scrollHeight:d.offsetHeight;
    var wW2 = (self.innerHeight)?self.innerWidth:(w && w.clientHeight)?w.clientWidth:d.clientWidth; var pW = (wW1 < wW2)?wW2:wW1;
    var wH2 = (self.innerHeight)?self.innerHeight:(w && w.clientHeight)?w.clientHeight:d.clientHeight; var pH = (wH1 < wH2)?wH2:wH1;
    pW = ($.browser.msie)?pW:Math.max(w.scrollWidth, w.clientWidth, d.scrollWidth, d.offsetWidth);
    pH = ($.browser.msie)?pH:Math.max(w.scrollHeight, w.clientHeight, d.scrollHeight, d.offsetHeight);
    if (window.opera){ tww = (d.scrollWidth==d.clientWidth)?w.clientWidth:tww; twh = (d.scrollHeight==d.clientHeight)?w.clientHeight:twh;}
    return { 
        winWidth:tww, 
        winHeight: twh, 
        winScrollLeft: sl, 
        winScrollTop: st, 
        pageWidth: pW, 
        pageHeight: pH
    } 
}

function button_code(inForm){
  inForm.infcode.select();
  Copied = inForm.document.selection.createTextRange()();
  Copied.execCommand('Copy');
}

// - End of JavaScript - -->


