var photomove = 0;
var tmp;
var tmp_name;
var parent_tmp;
var parent_tmp_name;
var avia_chel = 1;
var file_photo = 1;
var interval = new Array();
var ax = ay = 0;
var ox = oy = 0;

function loadHTML(file, dest, param, add) 
{
  $.ajax(
  {
     url: file,
     type: 'POST',
     data: param,
     enctype: 'multipart/form-data',
     beforeSend: function()
     {
       if ( add != "+" && add != "-" && add != "s")
       {
         $("#"+dest).html("<img src='/images/wait.gif'/>")
                    .slideDown(700);;
       }
     },
     success: function(answ)
     {
       if ( add == "+" )
       {
         $("#"+dest).hide()  
                     .append(answ)
                     .slideDown(700);
       }
       else if ( add == "*" )
       {
         $("#"+dest).hide()  
                     .html(answ)
                     .slideDown(1);
       }
       else
       {
         if ( answ != '' )
         {
            $("#"+dest).hide()  
                        .html(answ)
                        .slideDown(700);
         }
         else
         {
            $("#"+dest).slideUp(700)
                       .html(answ)
                       ;
         }
         if ( add == 's' )
         {
            $("#"+dest).slideUp(700);
         }
       }
     }
  }
  );
}


function show( id )
{
  if ( $('#'+id).length )
  {
     var value = document.getElementById(id).innerHTML;
     if ( value != "" && value != "ok" )
     {
      $("#"+id).slideDown(10);
     }
  }
}
function hide( id )
{
   if ( $('#'+id).length )
   {
      $("#"+id).slideUp(10);
   }
}

function show_time( id, slow )
{
  var value = document.getElementById(id).style.display;
  if ( value == 'block')
  {
      hide_time( id, slow );
  }
  else if ( $('#'+id).length )
  {
     var value = document.getElementById(id).innerHTML;
     if ( value != "" && value != "ok" )
     {
      $("#"+id).slideDown(slow);
     }
  }
}
function hide_time( id, slow )
{
   if ( $('#'+id).length )
   {
      $("#"+id).slideUp(slow);
   }
}

function showsub(id)
{
   $("#"+id).show(0);
   if ( tmp_name == id )
   {
      //clearTimeout(tmp);
   }
}
function hidesub(id)
{
   //tmp = setTimeout('$("#'+id+'").hide(0);',100);
   $("#"+id).hide(0);
}

window.onload = function a1() 
{
   if ( $('#abser2').length )
   {
      $("#abser1").attr("style", "left:0px;top:0px;width:"+getAbsClientWidth()+"px;height:"+getAbsClientHeight()+"px;");
      $("#abser2").attr("style", "top:"+((ay - oy)+(getClientHeight()-20)/2)+"px;");
   }
   if ( $('#cont').length )
   {
        Calendar.setup({
              cont         : "cont",
              weekNumbers  : true,
              onSelect     : getnews
        });
   }
   if ( $('#text').length )
   {
        var oFCKeditor = new FCKeditor( 'text' ) ;
        oFCKeditor.BasePath = "/fckeditor/" ;
        oFCKeditor.Height = "150";
        oFCKeditor.ToolbarSet = "Basic";
        oFCKeditor.ReplaceTextarea() ;
   }
}

var photomove = 0;
function showpic(id, x, y)
{
   div = id;
   if ( !photomove )
   {
      $("#"+id).animate({ width: x, height: y }, 0);
      $("#"+id).attr("class", "photo greyborder");
   }
   photomove = 1;
   
   needx = ox*1.0 + x*1.0;
   needy = oy*1.0 + y*1.0;
   
   leftpos = ax*1.0+20
   toppos = ay*1.0+20
   
   if ( getClientWidth() >  needx )
   {
      leftpos = ax*1.0 + 20
   }
   else 
   {
      leftpos = ax*1.0 - x*1.0 - 10
   }
   
   if ( getClientHeight() >  needy )
   {
      toppos = ay*1.0 + 20;
   }
   else
   {
      toppos = ay*1.0 - (y - (getClientHeight() - oy));
   }
   
   $("#"+id).attr("style", "left:"+leftpos+"px;top:"+toppos+"px;");

}
function hidepic(id)
{
   
   $("#"+id).animate({ width: 0, height: 0 }, 0);
   $("#"+id).attr("class", "hide");
   setTimeout('photomove = 0;', 40);
   
}
function validate(textform, length)
{
   text = eval("document.formchange." + textform + ".value")

   if ( text.length > (length-1) )
   {
      text = text.substring(0, (length-1));
      eval("document.formchange." + textform + ".value = '" + text + "'")
   }
}
function checkall(clas)
{
   $("."+clas).attr("checked","checked");
}
function uncheckall(clas)
{
   $("."+clas).attr("checked","");
}
function get_action_text( id )
{
   if ( $("#full_action_text"+id).html() != "" )
   {
      unget_action_text( id );
   }
   else
   {
      $("#plus"+id).attr("src", "/images/minus.gif");
      $("#short_action_text"+id).hide();
      loadHTML("/actions.php", "full_action_text"+id, {action: 'get_action_text',  id: id}, "");
   }
}
function unget_action_text( id )
{
   $("#plus"+id).attr("src", "/images/plus.gif");
   $("#short_action_text"+id).show();
   $("#full_action_text"+id).html('');
}
function validate(textform, maxlength)
{
    var text = $("#"+textform).val();
    if ( text.length > maxlength )
    {
       text = text.substring(0, maxlength);
       $("#"+textform).val(text);
    }
    document.getElementById(textform+'_v').innerHTML = (maxlength - text.length) + " зн.";
}

function show_big( src, x, y )
{
   html = '<div class="abserror" id="abser1" onclick="hide_time(\'abser2\', 200);hide_time(\'abser1\', 200);"></div>'+
          '    <center>'+
          '     <div class="abseerorramka" id="abser2" onclick="hide_time(\'abser2\', 200);hide_time(\'abser1\', 200);">'+
          '     </div>'+
          '     </center>';
   $('#photka').html(html);
   $("#abser2").html('<img src="/'+src+'" onclick="hide_time(\'abser2\', 200);hide_time(\'abser1\', 200);"/>');
   show_time('abser1', 200);
   show_time('abser2', 200);
   $("#abser1").attr("style", "left:0px;top:0px;width:"+getAbsClientWidth()+"px;height:"+getAbsClientHeight()+"px;");
   $("#abser2").attr("style", "top:"+((ay - oy)+(getClientHeight()-y)/2)+"px;");
}

document.onmousemove = mouseMove

function mouseMove(event){ 
    event = fixEvent(event)
    ax = event.pageX
    ay = event.pageY
    ox = event.x
    oy = event.y

    if ( event.clientX != null ) 
    {
       ox = event.clientX
       oy = event.clientY
    }
}

function fixEvent(e) {
    // получить объект событие для IE
    e = e || window.event
 
    // добавить pageX/pageY для IE
    if ( e.pageX == null && e.clientX != null ) {
        var html = document.documentElement
        var body = document.body
        e.pageX = e.clientX + (html && html.scrollLeft || body && body.scrollLeft || 0) - (html.clientLeft || 0)
        e.pageY = e.clientY + (html && html.scrollTop || body && body.scrollTop || 0) - (html.clientTop || 0)
    }
    else
    {
      
    }

    // добавить which для IE
    if (!e.which && e.button) {
        e.which = e.button & 1 ? 1 : ( e.button & 2 ? 3 : ( e.button & 4 ? 2 : 0 ) )
    }
 
    return e
}
    
function getAbsClientWidth()
{
  return  document.body.scrollWidth > document.body.offsetWidth ?	document.body.scrollWidth : document.body.offsetWidth;
}
function getAbsClientHeight()
{
  return document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight;
}
function getClientWidth()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}




/************/
var styleToSelect;
function onOk() {

}

function open_window(link,w,h) 
{
var win = "width="+w+",height="+h+",menubar=no,location=no,resizable=no,scrollbars=yes";
newWin = window.open(link,'newWin1',win);
};
	
var timeout = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open()
{  jsddm_canceltimer();
   jsddm_close();
   ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

function jsddm_close()
{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{  closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}

$(document).ready(function()
{  $('.jsddm > li').bind('mouseover', jsddm_open)
   $('.jsddm > li').bind('mouseout',  jsddm_timer)});
   
document.onclick = jsddm_close;
/*********************/