﻿/* Imano AB 2010 */

function SurveyData() {
    this.width = 670;
    this.height = 500;
    this.url = 'http://nourlset';
    this.pageid = '';
}

var sd = new SurveyData();

function LoadSurvey(url, pageid, height, width)
{
    sd.height = parseInt(height);
    sd.width = parseInt(width);
    sd.url = url;    
    sd.pageid = pageid;   
    setTimeout("LoadPopup()", 1000);
}

function ClosePopup() {
    jQuery("#modal-overlay").fadeOut(800, function() {
        jQuery("#modal-window").remove();
        jQuery("#modal-overlay").remove();
    });
}

function LoadPopup()
{
      var maxw = 0;
      var maxh = 0;
      var title = "";

      //Popup size
      if (sd.width) {
          maxw = sd.width;
          maxh = sd.height;
      }
      
      w = jQuery(window).width();
      h = jQuery(window).height();

      var middleH = (w) / 2;
      var middleV = (h) / 2;
      var endleft = (w - maxw) / 2;
      var endtop = ((h - maxh) / 2);

      //Popup window
      var el = jQuery("<div id='modal-window'>");
      el.css({ width: maxw + 'px',
          height: maxh + 'px',
          position: 'fixed',
          border: '10px solid #303132',
          background: '#222',
          left: endleft + "px",
          top: endtop + "px",
          cursor: 'pointer',
          'z-index': 102
      });

      //Overlay background
      var bg = jQuery("<div id='modal-overlay'>");
      bg.css({
          position: 'fixed',
          top: '0',
          right: '0',
          bottom: '0',
          left: '0',
          height: '100%',
          width: '100%',
          margin: '0',
          padding: '0',
          background: '#131313',
          opacity: '.55',
          filter: 'alpha(opacity=55)',
          'z-index': '101'
      });

      //Close button
      var cl = jQuery("<img id='closer' src='/surveyloader/closed.png'>");
      cl.css({
          width: '24px',
          height: '24px',
          position: 'absolute',
          top: '-20px',
          right: '-20px',
          'z-index': '103'
      });

      el.append(cl);

      //Close overlay
      el.click(function() {
          jQuery(this).fadeOut(500, function() {
              el.empty();
              el.remove();
          });
          bg.remove();
      });    

      //Add objects to html body
      jQuery("body").append(el);
      jQuery("body").append(bg);

      var div = jQuery("<div>");
      div.css({
          height: maxh - 40,
          width: maxw - 40
      });

      var x = jQuery("<iframe>");
      x.css({
          height: maxh,
          width: maxw
      });
            
      x.attr("src", "/surveyloader/survey.aspx?url=" + sd.url + "&pageid=" + sd.pageid);
      
      div.append(x);
      el.append(div);
}


