﻿var request = null;

// configuration
var BecomeMemberLink = "upgrade.php";
var SignUpAction = "http://braveheartwomen.com/account!default.jspa";
var LogInAction = "http://braveheartwomen.com/login.jspa?successURL=/gallery/ConnectionSection/1";

// DHTML helper functions
function dis(id) { obj(id).style.display = "block"; }
function nne(id) { obj(id).style.display = "none"; }
function obj(id) { return document.getElementById(id); }
function shuffle(a) { var i = a.length; while (--i) { var j = Math.floor(Math.random() * (i + 1)); var ti = a[i]; var tj = a[j]; a[i] = tj; a[j] = ti; } }

// brightcove web service call
var content, player, video;

function onTemplateLoaded(o) {
    player = brightcove.getExperience(o);
    video = player.getModule(APIModules.VIDEO_PLAYER);
    content = player.getModule(APIModules.CONTENT);
}

// query string
function qs(ji) {
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    for (i = 0; i < gy.length; i++) {
        ft = gy[i].split("=");
        if (ft[0] == ji) {
            return ft[1];
        }
    }
}

// load xml from file
function LoadXML(url, onchange) {
    if (window.XMLHttpRequest) {
        request = new XMLHttpRequest();
        request.onreadystatechange = onchange;
        request.open("GET", url, true);
        request.send(null);
    }
    else if (window.ActiveXObject) {
        request = new ActiveXObject("Microsoft.XMLHTTP");
        if (request) {
            request.onreadystatechange = onchange;
            request.open("GET", url, true);
            request.send();
        }
    }
}

// configure sign up / login in form
function SetupForm() {
    obj("TabButton1").onclick = function() {
        obj("TabButton1").parentNode.parentNode.style.backgroundPosition = "top";
        obj("TabButton1").className = "tabOn"; obj("TabButton2").className = "tabOff";
        obj("TabBody1").className = "bodyOn"; obj("TabBody2").className = "bodyOff";
    };
    obj("TabButton2").onclick = function() {
        obj("TabButton2").parentNode.parentNode.style.backgroundPosition = "bottom";
        obj("TabButton2").className = "tabOn"; obj("TabButton1").className = "tabOff";
        obj("TabBody2").className = "bodyOn"; obj("TabBody1").className = "bodyOff";
    };
    obj("btnSignUp").onclick = function() {
        var n = document.getElementById("txtUsername1");
        var e = document.getElementById("txtEmail1");

        if (n.value.length + e.value.length == 0) {
            alert("Please enter your Full Name and Email.");
            n.focus();
        } else if (n.value.length == 0) {
            alert("Please enter your Full Name.");
            n.focus();
        } else if (e.value.length == 0) {
            alert("Please enter your Email.");
            e.focus();
        } else {
            obj("btnSignUp").style.display = "none";
            obj("msgSignUp").style.display = "block";

            document.getElementById("frmSignUp").action = SignUpAction;
            setTimeout("document.getElementById('frmSignUp').submit()", 2000);

            document.getElementById("txtInfusionsoftName").value = n.value;
            document.getElementById("txtInfusionsoftEmail").value = e.value;
            document.getElementById("frmInfusionsoft").submit();
        }
    };
    obj("btnLogIn").onclick = function() {
        var f = document.getElementById("frmLogIn");
        var n = document.getElementById("txtUsername2");
        var p = document.getElementById("txtPassword2");

        if (n.value.length + p.value.length == 0) {
            alert("Please enter your User Name and Password.");
            n.focus();
        } else if (n.value.length == 0) {
            alert("Please enter your User Name.");
            n.focus();
        } else if (p.value.length == 0) {
            alert("Please enter your Password.");
            p.focus();
        } else {
            f.action = LogInAction;
            f.submit();
        }
    };
}

// become a member link
function BecomeMember() {
    document.location.href = BecomeMemberLink;
}

// email video to a friend
function EmailVideoToFriend(emailFrom, emailTo, message) {
    var social = player.getModule(APIModules.SOCIAL);
    if (message == null || message.length == 0) message = "Enjoy and share with your friends!";
    if (emailFrom.length > 0 && emailTo.length > 0 && social.shareVideoViaEmail(emailFrom, emailTo, message)) {
        myLytebox.end();
        
        s.pageName = "Email Confirmation Page";
        s.prop15 = emailFrom;
        s.t();

        document.getElementById("txtInfusionsoftEmailTo").value = emailTo;
        document.getElementById("txtInfusionsoftEmailFrom").value = emailFrom;
        document.getElementById("frmInfusionsoft").submit();
        
        alert("Your email message has been sent.  Thank you!");
    } else {
        alert("Either your email address or your friend's email address is not valid.");
    }
}



