function $(sID) {
    return document.getElementById(sId);
}

function flashMovie(sId) {
    if (document.all) {
        return window[sId];
    } else {
        return document[sId];
    }
}

function showError(message) {
    flashMovie("HopeAmp").showError(message);
}

function startProcess(email, zip) {
    HopeAmpLib.Viral.ViralProcess.Start(email, zip, onStart);
}

function onStart(result) {
    var city = "";
    var state = "";
    var res = eval("(" + result.value + ")");
    var emailOK = res.error != "Email in use";
    if (emailOK && !res.error) {
        var zd = res.results[0];
        state = zd.state;
        city = zd.city;
    }
    flashMovie("HopeAmp").next(state, city, emailOK);
}


/*
Save Contact Functions
*/
function save(fName, lName, email, zip, city, stateCode) {
    HopeAmpLib.Viral.ViralProcess.Finish(fName, lName, email, zip, city, stateCode, onSave);
}

function onSave(result) {
    if (result.error) {
        showError("Error: " + result.error);
    } else {
      alert("finished");
      flashMovie("HopeAmp").finish("done");
    }
}

/*
Get Download Functions
*/
function getDownload(email, pin) {
    HopeAmpLib.Viral.ViralProcess.GetDownload(email, pin, onGetDownload);
}

function onGetDownload(result) {
    if (result.error) {
        showError(result.error);
    } else {
      var res = eval("(" + result.value + ")");
      if (!res.error) {
        flashMovie("HopeAmp").doDownload(res.url, res.id, res.name);
      } else {
        showError(res.error);
      }
    }
}

/*
Viral Functions
*/
function sendContact(name, email, message) {
    HopeAmpLib.Viral.ViralProcess.SendContact(name, email, message, onSendContact);
}

function onSendContact(result) {
    if (result.error) {
        flashMovie("HopeAmpAbout").showError(result.error);
    } else {
      var res = eval("(" + result.value + ")");
      if (!res.error) {
        flashMovie("HopeAmpAbout").onSendContact();
      } else {
        flashMovie("HopeAmpAbout").showError(res.error);
      }
    }
}

function sendViral(name, email, friends, message) {
    HopeAmpLib.Viral.ViralProcess.SendViral(name, email, friends, message, onSendViral);
}

function onSendViral(result) {
    if (result.error) {
        flashMovie("HopeAmp").amplifyError(result.error);
    } else {
      var res = eval("(" + result.value + ")");
      if (!res.error) {
        //success
        flashMovie("HopeAmp").finishAmplify("success");
      } else {
        flashMovie("HopeAmp").amplifyError(res.error);
      }
    }
}