﻿function GotoPurchasePage() {
    var PurchasePage = 'andasoft.com/MyAccount/Payment/Purchase.aspx';
    window.location.href = 'https://m' + PurchasePage;
}

$j(document).ready(function() {
    // Demo Scripts
    $j(".demo").fancybox({
        'width': 870,
        'height': 570,
        'autoScale': false,
        'transitionIn': 'none',
        'transitionOut': 'none',
        'type': 'iframe'
    });

    // Login Scripts
    $j(".loginlink").fancybox({
        'scrolling': 'no',
        'titleShow': false,
        'onClosed': function() {
            $j("#login_error").hide();
        }
    });
    $j("#login_form").bind("submit", function() {

        if ($j("#login_name").val().length < 1 || $j("#login_pass").val().length < 1) {

            $j("#lblErrorMessage").text = "Please enter Email and Password!";
            $j("#login_error").show();
            $j.fancybox.resize();
            return false;
        }

        $j.fancybox.showActivity();

        $j.ajax({
            type: "POST",
            cache: false,
            url: "/MyAccount/LoginX.aspx",
            data: $j(this).serializeArray(),
            success: function(data) {
                if (data != 'success') {
                    $j('#lblErrorMessage').text(data);
                    $j('#login_error').show();
                    $j.fancybox.hideActivity();
                    $j.fancybox.resize();
                }
                else {
                    var url = $j('#hdnRedirect').attr('value');
                    var target = $j('#hdnRedirectTarget').attr('value');
                    $j('#hdnRedirect').attr('value', '/segmentview.aspx');
                    $j('#hdnRedirectTarget').attr('value', '_self');
                    if (target == '_self') {
                        $j(location).attr('href', url);
                    }
                    else {
                        window.open(url);
                    }
                }
            }
        });

        return false;
    });

    // Used to ask server to send password to user's email
    $j("#hypSendPassword").click(function() {
        $j.fancybox.showActivity();
        var url = "/MyAccount/LoginX.aspx?forgot=1&username=" + $j("#login_name").val();
        $j.ajax({
            type: "GET",
            cache: false,
            url: url,
            data: $j(this).serializeArray(),
            success: function(data) {
                $j("#lblErrorMessage").text(data);
                $j("#login_error").show();
                $j.fancybox.hideActivity();
                $j.fancybox.resize();
            }
        });

        return false;

    });

    // This redirects links to privileged functions to Login
    $j(".ReqLogin").click(function() {
        $j('#hdnRedirect').attr('value', $j(this).attr('href'));
        $j('#hdnRedirectTarget').attr('value', $j(this).attr('_self'));
        var Reason = 'this advanced feature';
        if ($j(this).attr('Reason') != null) {
            Reason = $j(this).attr('Reason');
        }
        $j('#lblErrorMessage').text('To Access ' + Reason + ' you must Log in.');
        $j("#login_error").show();
        $j('#hypOrLogin').click();
        return false;
    });

    // This redirects links to premium functions to Upgrade
    $j("#hypUpgrade").fancybox({ 'scrolling': 'no', 'titleShow': false });
    $j(".ReqPremium").click(function() {
        $j('#hypUpgrade').click();
        return false;
    });

    $j('.ShowSpinner').click(function() { DNASpinnerStart(); });
});
