(function($){

$.fn.zoomi = function() {
  $(this).filter("img").each(function(){
    if(!this.z) {
      $(this).zoom1().mouseover(function(){$(this).zoom2().show();});
      $(this.z).mouseout(function(){$(this).hide();}); }
  });
 return this;
}

$.fn.zoom1 = function() {
  $(this).each(function(){
    var e = this;
    $(e).css({'position':'relative','z-index':'8'}).after('<img class="'+e.className+'">');
    e.z = e.nextSibling;
    $(e.z).removeClass("zoomi").addClass("zoom2").attr("src",e.alt || e.src)
    .css({'position':'absolute','z-index':'10'});
    $(e.z).hide();
  });
  return this;
}

$.fn.zoom2 = function() {
  var s = [];
  this.each(function(){
    var e = this;
    if(!e.z) e = $(e).zoom1()[0]; s.push(e.z);
    if(!e.z.complete) return;
    if(!e.z.width) { $(e.z).show(); e.z.width=e.z.width; $(e.z).hide(); }
    $(e.z).css({left:$(e).offsetLeft()-(e.z.width-e.scrollWidth)/2+'px',
    top:$(e).offsetTop()-(e.z.height-e.scrollHeight)/2+'px'});
  });
  return this.pushStack(s);
}

$.fn.offsetLeft = function() {
  var e = this[0];
  if(!e.offsetParent) return e.offsetLeft;
  return e.offsetLeft + $(e.offsetParent).offsetLeft(); }

$.fn.offsetTop = function() {
  var e = this[0];
  if(!e.offsetParent) return e.offsetTop;
  return e.offsetTop + $(e.offsetParent).offsetTop(); }

$(function(){ $('img.zoomi').zoomi(); });

})(jQuery);

function logerr(mes)
{
	alert(mes);
};

function checkLogin()
{
	var login=document.getElementById('loginr').value; 
	if (login!=='')
	{
	   $('#chkl').html("Проверка...");
	   $('#chkl').load('/ac/chklogin.php', {login: login});
	}
	else
	{
	   $('#chkl').html('<font color=\"#FF0000\"><strong>введите логин!</strong></font>');	
	};	
};

function showComments(code)
{
	if (code!=='')
	{
	   $('#comments').html("Загрузка...");
	   $('#comments').load('/ac/comments.php', {code: code});
	};
};

function groupsel(id, opt)
{	
	if (id!=='')
	{
	   if (opt==2)
	   {
    	  grs=document.getElementById('grselect');
    	  id= grs.options[grs.selectedIndex].value;	   	
	   };	   
	   $('#groupsel').html("Загрузка...");	   
	   $('#groupsel').load('/ac/groupsel.php', {id: id, opt: opt});
	};   
};

function groupdel()
{
  opt=3;
  grs=document.getElementById('grselect');
  id= grs.options[grs.selectedIndex].value;  
  if (id>0)
  {	   
    $('#groupsel').load('/ac/groupsel.php', {id: id, opt: opt});
  };   
};

function activsel(grid, acid, opt)
{
	if (grid!=='')
	{
	   if (opt>0)
	   {
    	  grs =document.getElementById('grselect');
    	  grid=grs.options[grs.selectedIndex].value;	   	
 	  };
	   if (opt==2)
	   {
    	  acs =document.getElementById('acselect');
    	  acid=acs.options[acs.selectedIndex].value;	   	
	   };				
	   $('#activsel').html("Загрузка...");
	   $('#activsel').load('/ac/activsel.php', {grid: grid, acid: acid, opt: opt});
	};   
};

function activdel()
{
  opt =3;
  grid=1;
  acs =document.getElementById('acselect');
  acid=acs.options[acs.selectedIndex].value;
  if (acid>0)
  {		   	
    $('#activsel').load('/ac/activsel.php', {grid: grid, acid: acid, opt: opt});
  };   
};

function activseluser(grid, width, tq)
{
	if (grid!=='')
	{				
	   $('#activseluser').html("Загрузка...");
	   $('#activseluser').load('/ac/activseluser.php', {grid: grid, width: width, tq: tq});
	};   
};

function usercatlist(uid, op)
{
	if (uid!=='')
	{
	   acid=0;
	   if (op==1)
	   {
    	  acs =document.getElementById('acselect');
    	  acid=acs.options[acs.selectedIndex].value;		 		   	
	   };	   	   
	   if (op==2)
	   {
    	  acs =document.getElementById('ucatselect');
    	  acid=acs.options[acs.selectedIndex].value;	   	
	   };	   
	   $('#usercat').html("Загрузка...");
	   $('#usercat').load('/ac/usercatlist.php', {uid: uid, acid: acid, op: op});
	};   
};

function voteex(part, op)
{	
	if (part!=='')
	{				
	   $('#votedata').html("Загрузка...");
	   $('#votedata').load('/ac/vote.php', {part: part, op: op});
	};   
};

function infoeditor(id, op)
{	
	if (id!=='')
	{				
	   $('#infodata').html("Загрузка...");
	   $('#infodata').load('/ac/infoeditor.php', {id: id, op: op});
	};   
};

function delinfodatatable()
{
   $('#infodatatable').html('&nbsp;');	
};

function questeditor(id, op)
{	
	if (id!=='')
	{				
	   $('#questdata').html("Загрузка...");
	   $('#questdata').load('/ac/questeditor.php', {id: id, op: op});
	};   
};

function delquestdatatable()
{
   $('#questdatatable').html('&nbsp;');	
};

function apageeditor(id, op)
{	
	if (id!=='')
	{
	   $('#apagedata').html("Загрузка...");
	   $('#apagedata').load('/ac/apageeditor.php', {id: id, op: op});
	};   
};

function delapagedatatable()
{
   $('#apagedatatable').html('&nbsp;');	
};

function settotinymce(pr)
{
	if (pr>0)
	{
	   var name =document.getElementById('setquername').value;  
	   var code =document.getElementById('setquercode').value;
	   var width=document.getElementById('setquerwidth').value;
	   var lengt=document.getElementById('setquerlen').value;
	   var value=document.getElementById('setquervalue').value;	   
       var cont=tinyMCE.get('mce_30').selection.getContent();	
	   
	   data="";
	   repl=0;
	      
	   ln=name.length;
	   lc=cont.length;  
	   
	   if ((ln==0) && (lc>0)) 
	   {
		  name=cont;
		  repl=1;	
	   }; 
	      
	   if (pr==1)
	   {
	      if (width<50)
	      {
	         width=50;	
	      };
	      
	      if (lengt<1)
	      {
	         lengt=1;	
	      };	      
		  
		  data=data+"<span id=quer_"+code+" "+name+" name=quer_"+code+">"+name+"</span>";
		  data=data+"<input style=\"width:"+width+"px\" type=text id="+code+" name="+code+" maxlength="+lengt+" value=\""+value+"\">";		 	
	   };
	 
       if (repl==0)
	   {
	      tinyMCE.execCommand('mceInsertContent',false,data);
	   }
	   else
	   {
	      tinyMCE.execCommand('mceReplaceContent',false,data);	
	   };   
	};   
};

function doClear(theText) {
	if (theText.value == theText.defaultValue) { theText.value = ""; theText.style.color="black"; }
	if (theText.value !== "поиск по партнерам") {theText.style.color="black";}
};

function doDefault(theText) {
	if (theText.value == "") { theText.value = theText.defaultValue; theText.style.color="gray";}
};

function searchf(searchquer) {
	var searchfld =document.getElementById('searchfld');
	lsq=searchquer.length;
	if (lsq>0)
	{
	   searchfld.value=searchquer;
	};
	//searchfld.focus();
};

function adquernote(op)
{	
	if (op=='')
	{
	   $('#adquernote').html("Загрузка...");
	   $('#adquernote').load('/ac/adquernote.php', {});
	}
	else
	{ 	  
       var qs=$('#adqnForm');
       var qstr='id=1&'+qs.serialize();
       $('#adquernote').html("Сохранение...");
       $.post("/ac/adquernote.php", qstr, function(data){
          $('#adquernote').html(data);
       });
	};   
};
