function submitForm(){
    try{
        pageTracker._trackPageview('/submit/article/run-bloglines-pipe');
    }catch(e){}

    var scriptUrl = "http://pipes.yahoo.com/pipes/pipe.run?_id=FsKktv5E3BGSRkunyjUFzw"
                  + "&_render=json"
                  + "&_callback=parseJson"
                  + "&relayUrl=yes"
                  + "&username=" + encodeURIComponent(document.getElementById("bloglinesUsername").value)
                  + "&password=" + encodeURIComponent(document.getElementById("bloglinesPassword").value);
    if(document.getElementById("markItemsAsRead").checked){
        scriptUrl = scriptUrl + "&markasread=yes";
    } else {
        scriptUrl = scriptUrl + "&markasread=no";
    }

    var scriptNode = document.createElement("script");
    scriptNode.src = scriptUrl;
    document.getElementsByTagName("head")[0].appendChild(scriptNode);
}

function parseJson(jsonObject){
    var emailSubscriptions = jsonObject.value.items;
    setStatusMessage(emailSubscriptions.length);

    for(var index in emailSubscriptions){
        var emailSubscription = emailSubscriptions[index];

        var trNode = document.createElement("tr");
        document.getElementById("emailSubscriptionsList").appendChild(trNode);

        var leftTdNode = document.createElement("td");
            leftTdNode.appendChild(document.createTextNode(emailSubscription.title));
        trNode.appendChild(leftTdNode);

        var rightTdNode = document.createElement("td");
        var divNode = document.createElement("div");
            divNode.innerHTML = "<iframe scrolling=\"no\" style=\"width:4em;height:4em;margin-left:1em;overflow:hidden;\""
                                  + " name=\"_iframe" + index + "\"></iframe>";
        rightTdNode.appendChild(divNode);
        trNode.appendChild(rightTdNode);

        var readerAddForm = document.forms["readerAddForm"];
        readerAddForm.target = "_iframe" + index;
        readerAddForm.elements["s"].value = "feed/" + emailSubscription.link;
        readerAddForm.elements["t"].value = emailSubscription.title
        readerAddForm.elements["T"].value = document.getElementById("googleToken").value;
        readerAddForm.submit();
    }
}

function setStatusMessage(noOfSubscriptions){
    var text = noOfSubscriptions + " email subscriptions found.";

    if(noOfSubscriptions == 0){
        text = "No email subscriptions found.";
    }
    if(noOfSubscriptions == 1){
        text = "1 email subscription found.";
    }

    var notificationNode = document.getElementById("notificationText");
    notificationNode.style.display = "block";
    notificationNode.firstChild.data = text;

    if(noOfSubscriptions >= 1){
        document.getElementById("emailSubscriptionsList").parentNode.style.display = "block";
    }
}