﻿
function myPopupRelocate() {
  var scrolledX, scrolledY;
  if( self.pageYOffset ) {
    scrolledX = self.pageXOffset;
    scrolledY = self.pageYOffset;
  } else if( document.documentElement && document.documentElement.scrollTop ) {
    scrolledX = document.documentElement.scrollLeft;
    scrolledY = document.documentElement.scrollTop;
  } else if( document.body ) {
    scrolledX = document.body.scrollLeft;
    scrolledY = document.body.scrollTop;
  }

  var centerX, centerY;
  if( self.innerHeight ) {
    centerX = self.innerWidth;
    centerY = self.innerHeight;
  } else if( document.documentElement && document.documentElement.clientHeight ) {
    centerX = document.documentElement.clientWidth;
    centerY = document.documentElement.clientHeight;
  } else if( document.body ) {
    centerX = document.body.clientWidth;
    centerY = document.body.clientHeight;
  }

  var leftOffset = scrolledX + (centerX - 250) / 2;
  var topOffset = scrolledY + (centerY - 200) / 2;

  document.getElementById("surveypopup").style.top = topOffset + "px";
  document.getElementById("surveypopup").style.left = leftOffset + "px";
}

function centerPopup() {
    var centerX, centerY;    
    if( self.innerHeight ) {
        centerX = self.innerWidth;
        centerY = self.innerHeight;
    } else if( document.documentElement && document.documentElement.clientHeight ) {
        centerX = document.documentElement.clientWidth;
        centerY = document.documentElement.clientHeight;
    } else if( document.body ) {
        centerX = document.body.clientWidth;
        centerY = document.body.clientHeight;
    }  
    
    centerX = (centerX / 2 ) - 349; /*half the width of the popup*/
    centerY = (centerY / 2 ) - 246; /*half the height of the popup*/      
    
    document.getElementById("surveypopup").style.top = centerY + "px";
    document.getElementById("surveypopup").style.left = centerX + "px";
}

function fireMyPopup() {
  myPopupRelocate();  
  document.getElementById("surveypopup").style.display = "block";  
  document.body.onscroll = myPopupRelocate;
  window.onscroll = myPopupRelocate;
    
  /*window.setTimeout("closeMyPopup()", 5000);*/
}

function setOpacity( value ) {
	document.getElementById("surveypopup").style.opacity = value / 10;
	document.getElementById("surveypopup").style.filter = 'alpha(opacity=' + value * 10 + ')';
}

function fadeInMyPopup() {
	for( var i = 0 ; i <= 100 ; i++ )
		setTimeout( 'setOpacity(' + (i / 10) + ')' , 8 * i );
}

function closeMyPopup() {
	document.getElementById("surveypopup").style.display = "none"
}

function fireMyPopup() {    
	setOpacity( 0 );	
	document.getElementById("surveypopup").style.display = "block";
	fadeInMyPopup();
	
}

function LoadMyPopUp(){
window.setTimeout("fireMyPopup()", 1500);
centerPopup();

// added to close automatically 
window.setTimeout("fadeOutMyPopup()", 15000);
//
}

function fadeOutMyPopup() {
	for( var i = 0 ; i <= 100 ; i++ ) {
		setTimeout( 'setOpacity(' + (10 - i / 10) + ')' , 8 * i );
	}

	setTimeout('closeMyPopup()', 800 );
}

