﻿/// <reference path="jQuery/jquery-1.3.2-vsdoc.js" />

$(document).ready(function() {

    //modal content
    $(".join a").click(function(evt) {
        evt.preventDefault();

        //var _source = "/signup/";
        var _source = $(this).attr("href");
        var _width = 880;
        var _height = 640;
        openMyModal(_source, _width, _height);

    });

    $("#progress a").click(function(evt) {
        evt.preventDefault();
    });

    setActive(window.location.href);

});

var setActive = function(url) {
    url = url.toLowerCase();

    var $a;
    if (/thank-you.aspx/.test(url)) {
        $a = $("#progress").find("li#confirmation a");
    }
    else if (/payment.aspx/.test(url)) {
        $a = $("#progress").find("li#payment a");
    }
    else if (/personal-details.aspx/.test(url)) {
        $a = $("#progress").find("li#yourdetails a");
    }
    else if (/membership-summary.aspx/.test(url)) {
        $a = $("#progress").find("li#startdate a");
    }
    else {
        $a = $("#progress").find("li#options a");
    }

    $a.addClass("on");
};

var modalWindow = {
    parent: "body",
    windowId: null,
    content: null,
    width: null,
    height: null,
    close: function() {
        $(".modal-window").remove();
        $(".modal-overlay").remove();
    },
    open: function() {
        var modal = "";
        modal += "<div class=\"modal-overlay\"></div>";
        modal += "<div id=\"" + this.windowId + "\" class=\"modal-window\" style=\"width:" + this.width + "px; height:" + this.height + "px; margin-top:-" + (this.height / 2) + "px; margin-left:-" + (this.width / 2) + "px;\">";
        modal += this.content;
        modal += "</div>";

        $(this.parent).append(modal);

        //$(".modal-window").append("<a class=\"close-window\" title=\"Close\">Close</a>");
        //$(".close-window").click(function() { modalWindow.close(); });
        /*$(".modal-overlay").click(function() { modalWindow.close(); });*/
        $(document).keyup(function(e) { if (e.keyCode == 27) { modalWindow.close(); } });
    }
};

var openMyModal = function(_source, _width, _height) {
    modalWindow.windowId = "myModal";
    modalWindow.width = _width;
    modalWindow.height = _height;
    modalWindow.content = "<iframe width='" + _width + "' height='" + _height + "' frameborder='0' scrolling='auto' allowtransparency='true' src='" + _source + "'></iframe>";
    modalWindow.open();
};


var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1);

function printPage(frame, arg) {
    if (frame == window) {
        printThis();
    } else {
        link = arg; // a global variable 
        printFrame(frame);
    }
    return false;
}

function printThis() {
    if (pr) { // NS4, IE5
        window.print();
    } else if (da && !mac) { // IE4 (Windows)
        vbPrintPage();
    } else { // other browsers
        alert("Sorry, your browser doesn't support this feature.");
    }
}

function printFrame(frame) {
    if (pr && da) { // IE5
        frame.focus();
        window.print();
        link.focus();
    } else if (pr) { // NS4
        frame.print();
    } else if (da && !mac) { // IE4 (Windows)
        frame.focus();
        setTimeout("vbPrintPage(); link.focus();", 100);
    } else { // other browsers
        alert("Sorry, your browser doesn't support this feature.");
    }
}

if (da && !pr && !mac) with (document) {
    writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');
    writeln('<' + 'SCRIPT LANGUAGE="VBScript">');
    writeln('Sub window_onunload');
    writeln('  On Error Resume Next');
    writeln('  Set WB = nothing');
    writeln('End Sub');
    writeln('Sub vbPrintPage');
    writeln('  OLECMDID_PRINT = 6');
    writeln('  OLECMDEXECOPT_DONTPROMPTUSER = 2');
    writeln('  OLECMDEXECOPT_PROMPTUSER = 1');
    writeln('  On Error Resume Next');
    writeln('  WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER');
    writeln('End Sub');
    writeln('<' + '/SCRIPT>');
}
