﻿//SETTING UP OUR POPUP 0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup()
{
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.4"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#proBox").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup()
{
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").hide();
		$("#proBox").hide();
		popupStatus = 0;
	}
}

// getPageScroll() by quirksmode.com
  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
  }
  
//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#proBox").height();
	var popupWidth = $("#proBox").width();
	
	$('#proBox').css({
	    "position": "absolute",
        "top":	getPageScroll()[1] + (getPageHeight()/ 10) - 40,
        "left":	windowWidth/2-popupWidth/2
      });	
}

function plRequest(msg)
{
    $('#loader').remove();
	$('body').prepend('<span id="loader">LOADING '+ msg +'...</span>');
	$('#loader').fadeIn('normal');
}

function OpenDetails()
{
    //centering with css
	centerPopup();
	//load popup
	loadPopup();
	$("#backgroundPopup").css({"height": $(document).height(),"width":$(window).width()});
}

function plFinish(did)
{
    $('#loader').fadeOut(2000);
    $(did).show();
}

$(document).ready(function()
{
    $(".guideline").click(function() {
        //centering with css
        centerPopup();
        //load popup
        loadPopup();
        var id = "#" + $(this).attr("title");
        $("#proBoxContainer .page-content", "#proBox").html($(id).html());
        $("#backgroundPopup").css({ "height": $(document).height(), "width": $(window).width() });
        return false;
    });
    				
    //CLOSING POPUP Click the x event!
    $("#proBoxClose").click(function(){
	    disablePopup();
    });
    
    $("#agreed").click(function(){
	    
	    var wtf = $(this).attr('checked');
	    
	    if(wtf)
	    {
	        $("#reg-button").attr('disabled','').addClass("active");
	    }
	    else
	        $("#reg-button").attr('disabled','disabled').removeClass("active");
    });
	
    //Press Escape event!
    $(document).keypress(function(e){
	    if(e.keyCode==27 && popupStatus==1){
		    disablePopup();
	    }
    });
  
});