﻿$(document).ready(function() {
    if (getCookie('popUpSubscribe') == null) {//show popup if it is the first time visit
        $.modal("<iframe id='bizform' scroll='no' style='overflow:hidden; border:none; border-width:0' src='/CMSPages/PopupSignup.aspx' height='610px' width='480px' />", {
            minHeight: 625,
            minWidth: 485,
            overlayCss: { backgroundColor: "#000" },
            containerCss: {
                borderColor: "#fff",
                height: 623,
                padding: 0,
                width: 483
            },
            containerId: 'modal-container'
        });
        if (IE.Version() <= 8) { //IE version < 8 tends to generate an extra Iframe
            $('iframe')[1].style.display = 'none'; //so lets hide it :D
        }
        $('.simplemodal-wrap').css('overflow-x', 'hidden');
        $('.simplemodal-wrap').css('overflow-y', 'hidden');
        setCookie('popUpSubscribe', true, 120);
    }
});

//check IE version
var IE = {
    Version: function() {
        var version = 999; // we assume a sane browser
        if (navigator.appVersion.indexOf("MSIE") != -1)
        // bah, IE again, lets downgrade version number
            version = parseFloat(navigator.appVersion.split("MSIE")[1]);
        return version;
    }
}

//function to set cookies on the browser
function setCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

//function to get cookies on the browser
function getCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}
