function getPageScroll() {
    var xScroll, yScroll;
    if (self.pageYOffset) {
      yScroll = self.pageYOffset;
      xScroll = self.pageXOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
      yScroll = document.documentElement.scrollTop;
      xScroll = document.documentElement.scrollLeft;
    } else if (document.body) {// all other Explorers
      yScroll = document.body.scrollTop;
      xScroll = document.body.scrollLeft;
    }
    return new Array(xScroll,yScroll)
  }

  // Adapted from getPageSize() by quirksmode.com
  function getPageHeight() {
    var windowHeight
    if (self.innerHeight) {	// all except Explorer
      windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
      windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
      windowHeight = document.body.clientHeight;
    }
    return windowHeight
  }

/**
 *
 * @access public
 * @return void
 **/
function gift_sender() {
	var $r = $(document.createElement("div"));
	$r.attr('id', 'gifts').appendTo('body');

	$('#gifts').html('<div class="fone_ajax" id="overl"></div><div class="scnt" id="scnt"></div> \
<div class="cnt" id="cnt"> \
	<div class="t_wrap"> \
		<div class="t">Опрос для пользователей X-status</div> \
	</div> \
	<div class="st" id="subt">Этот опрос откроется один раз и более вас беспокоить не будет<span> \
	 \
	</span></div> \
	<div class="r_sh" style="opacity: 0.2; margin-top: 0px;"></div> \
	<div class="r_sh" style="opacity: 0.11; margin-top: 1px;"></div> \
	<div class="r_sh" style="opacity: 0.07; margin-top: 2px;"></div> \
	<div class="r_sh" style="opacity: 0.03; margin-top: 3px;"></div> \
	<div class="b_cnt"> \
	<iframe src="/poll.php" frameborder="no" height="100%" width="100%" />	\
	</div> \
	<div class="ft"> \
	<a href="javascript: void(0);" onclick="hide_sender(); return false;" class="but"><span>Закрыть</span></a> \
	</div> \
	<div class="r_sh" style="opacity: 0.03; margin-top: -37px;"></div> \
	<div class="r_sh" style="opacity: 0.07; margin-top: -36px;"></div> \
	<div class="r_sh" style="opacity: 0.11; margin-top: -35px;"></div> \
	<div class="r_sh" style="opacity: 0.2; margin-top: -34px;"></div> \
</div>');
	$('#overl').css({
		opacity: 0,
		display: 'block'
	}).animate({opacity: 0.6}, 1);
	$('#scnt').css({
        top:	getPageScroll()[1] + (getPageHeight() / 10),
        left:	(document.body.clientWidth/2-309) ,
        width: 618,
        height: 534
      }).animate({opacity: 0.4}, 1);
  	$('#cnt').css({
        top:	getPageScroll()[1] + (getPageHeight() / 10) + 10,
        left:	(document.body.clientWidth/2-299),
        width: 596,
        height: 510
      }).animate({opacity: 1}, 1);
//	$('#scnt').show('fast');
//	$('#cnt').show('fast');
//document.cookie="shown=yes; path=/; expires=Mon, 01-Jan-2001 00:00:00 GMT";

}

function hide_sender(){
	$('#scnt').animate({opacity: 0}, 1).animate({
		width: 0,
		height: 0
	}, 1);
	$('#cnt').animate({opacity: 0}, 1).animate({


		width: 0,
		height: 0
	}, 1);
	$('#overl').animate({opacity:0}, 1).css({
		opacity: 0,
		display: 'none'
	});
}

/**
 *
 * @access public
 * @return void
 **/
function answer(quest, ans){
	$('a#'+quest+'_1').removeClass('active');
	$('a#'+quest+'_0').removeClass('active');
	$('a#'+quest+'_'+ans).addClass('active');
	document.getElementById('answer_'+quest).value = ans;
}

/**
 *
 * @access public
 * @return void
 **/
function answers() {
	var req = new JsHttpRequest();
    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            // Write result to page element (_RESULT become responseJS).
            window.top.hide_sender();
        }
    }
    // Prepare request object (automatically choose GET or POST).
    req.open(null, '/ajax.php', true);
    // Send data to backend.
    req.send( { answer_1: document.getElementById('answer_1').value, answer_2: document.getElementById('answer_2').value, answer_3: document.getElementById('answer_3').value, answer_4: document.getElementById('answer_4').value, answer: '1' } );
}