function us_hs_close(  ){
 document.getElementById('urw').style.display="none";
 document.getElementById( 'urw_content' ).innerHTML="";
};



 function us_rat( com_id, user_id, post_id, ot,ur_del, event ){

  var ajax = new dle_ajax();
	ajax.onShow ('');
	var varsString = "user_id=" + user_id;
	 if(event=='all3'){event='all';ajax.setVar("query", document.getElementById('query').value);}
	ajax.setVar("action", event);
  ajax.setVar("com_id", com_id);
	ajax.setVar("post_id", post_id);
	ajax.setVar("ot", ot);
	ajax.setVar("ur_del", ur_del);
	ajax.setVar("skin", dle_skin);
	ajax.requestFile = dle_root + "engine/modules/us_rating/us_rating.ajax.php";
	ajax.method = 'POST';

  if(event!='ur_refresh'){ajax.element = 'urw_content';}else{ajax.element = 'us_rating_'+com_id;}

  if(  event=='show' | event=='all'){
 	  ajax.setVar("urw_height",document.getElementById('urw').style['height']) ;

    if( document.getElementById('urw').style.display!='block'){
     ajax.onCompletion = winshow;
     document.getElementById('urw_resize').style.display='block';
    }
  }

  if(event=='getpage' | event=='delete'){
  	ajax.setVar("urw_height",document.getElementById('urw').style['height']) ;
  }

  if(event!='show'& event!='getpage'& event!='ur_refresh'& event!='delete'& event!='all'){
  ajax.onCompletion = winshow;
  document.getElementById('urw_resize').style.display='none';
  }

  ajax.sendAJAX(varsString);

    return false;
} ;

 function winresize(width,height){
  document.getElementById('urw').style['width']=width+"px";
  document.getElementById('urw').style['height']=height+"px";
 };


 function winshow(){
  urw_init('urw','urw_header','urw_resize');
  return false;
 };


  function us_rat_do( com_id, user_id, post_id,com_char_limit, event ){
  if(document.getElementById( 'us_rat_com' ).value!=''  ){
    if( document.getElementById( 'us_rat_com' ).value.length<=com_char_limit){
     var ajax = new dle_ajax();
	   ajax.onShow ('');
	   var comm_txt = ajax.encodeVAR( document.getElementById('us_rat_com').value );
     var varsString = "comm_txt=" + comm_txt;
     ajax.setVar("user_id", user_id);
     ajax.setVar("action", event);
     ajax.setVar("com_id", com_id);
	   ajax.setVar("post_id", post_id);
	   ajax.setVar("skin", dle_skin);
	   ajax.requestFile = dle_root + "engine/modules/us_rating/us_rating.ajax.php";
	   ajax.method = 'POST';
	   ajax.element = 'us_rating_'+com_id;
	   ajax.onCompletion = us_hs_close;
 	   ajax.sendAJAX(varsString);

     return false;
    }else {alert(' Обьяснение слишком большое! \r\n Сократите его до ' + com_char_limit + ' Символов!')}
  }else{alert('Заполните поля!')}
} ;






 var Drag2 = {

	obj : null,

	init : function(o, oRoot,oResize, minX, maxX, minY, maxY)
	{

    o.onmousedown	= Drag2.start;
 	  o.hmode			= true ;
		o.vmode			= true ;
		o.root = oRoot && oRoot != null ? oRoot : o ;
	},

	start : function(e)
	{
		var o = Drag2.obj = this;
		e = Drag2.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

  	o.minMouseX	= e.clientX - x + o.minX;
	  o.maxMouseX	= o.minMouseX + o.maxX - o.minX;

    o.minMouseY	= e.clientY - y + o.minY;
    o.maxMouseY	= o.minMouseY + o.maxY - o.minY;

		document.onmousemove	= Drag2.resize;
		document.onmouseup		= Drag2.end;

		return false;
	},

	resize : function(e)
	{
		e = Drag2.fixE(e);
		var o = Drag2.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt( o.root.style.height);
		var x = parseInt( o.root.style.width );
		var nx, ny;

		nx = x + (ex - o.lastMouseX) ;
		ny = y + (ey - o.lastMouseY) ;


		Drag2.obj.root.style[ "width" ] = nx + "px";
		Drag2.obj.root.style[ "height" ] = ny + "px";

    document.getElementById('urw_ur').style[ "height" ] = (ny -72) + "px";

    Drag2.obj.lastMouseX	= ex;
    Drag2.obj.lastMouseY	= ey;

		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag2.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};











 var Drag = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : 0;
		o.minY	= typeof minY != 'undefined' ? minY : 0;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

 	if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

  if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

  Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]),
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};

center_div.prototype.Ywindow = function()
{
	var scrollY = 0;
	
	if ( document.documentElement && document.documentElement.scrollTop )
	{
		scrollY = document.documentElement.scrollTop;
	}
	else if ( document.body && document.body.scrollTop )
	{
		scrollY = document.body.scrollTop;
	}
	else if ( window.pageYOffset )
	{
		scrollY = window.pageYOffset;
	}
	else if ( window.scrollY )
	{
		scrollY = window.scrollY;
	}
	
	return scrollY;
};
function urw_init(win,move,resize)
{
	urw_main = document.getElementById( win );

		var my_width  = 0;
		var my_height = 0;



		if ( typeof( window.innerWidth ) == 'number' )
		{
			my_width  = window.innerWidth;
			my_height = window.innerHeight;
		}
		else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
		{
			my_width  = document.documentElement.clientWidth;
			my_height = document.documentElement.clientHeight;
		}
		else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
		{
			my_width  = document.body.clientWidth;
			my_height = document.body.clientHeight;
		}

		var divheight = parseInt( urw_main.style.Height );
		var divwidth  = parseInt( urw_main.style.Width );

		divheight = divheight ? divheight : 250;
		divwidth  = divwidth  ? divwidth  : 400;



	var scrollY = 0;
	
	scrollY = document.documentElement.scrollTop;
	
	if (navigator.appName=="Opera") {scrollY = document.body.scrollTop;}
	if (navigator.appName=="Microsoft Internet Explorer") {scrollY = document.documentElement.scrollTop;}
	
//	var setX = ( my_width  - divwidth  ) / 2;
//	var setY = ( my_height - divheight ) / 2 + scrolly;
	
//	setX = ( setX < 0 ) ? 0 : setX;
//	setY = ( setY < 0 ) ? 0 : setY;
	
	
	urw_main.style.left =  (my_width  / 2  - (divwidth / 2))+document.documentElement.scrollLeft+'px';
	urw_main.style.top  =  ((my_height - divheight) / 2 )+scrollY+'px';

    	urw_main.style.position = 'absolute';
		urw_main.style.display  = 'block';

		urw_main.style.zIndex   = 199;

		var theHandle = document.getElementById(move);
		var theRoot   = document.getElementById(win);
    var theResize   = document.getElementById(resize);


  	Drag.init(theHandle, theRoot);
    Drag2.init(theResize, theRoot);
}















