/*--
Copyright © 1998, 2012, Oracle and/or its affiliates.  All rights reserved.
--*/

var embedded = false;

$(document).ready(function () {
    if (opener && opener.isTestItOnTouchDevice)
        embedded = opener.isTestItOnTouchDevice();
    else if (parent && parent.isTestItOnTouchDevice)
        embedded = parent.isTestItOnTouchDevice();
    var browser = "";
    if (navigator) {
        if (navigator.userAgent) {
            if (navigator.userAgent.indexOf("Safari") > 0) {
                browser = "Safari";
            }
        }
    }
    fillTestDate();
    fillTestName(R_testit_entertester);
    fillTestNotes(R_testit_enternotes);
    var o = getElement("*[name='ActualTime'] ~ p");
    o.attr('contentEditable', true);
    o = getElement("*[name^='TestNotesFrameID']");
    o.parent().css('height', '100%');
    if (browser == "Safari")
        o.parent().attr('contentEditable', true);
    o.parent().html(function () {
        var tt = '<div id="' + $(this).find(o).attr("name") + '" style="width:100%; height:100%; cursor:text"' + ((browser == 'Safari') ? '' : ' contenteditable') + '><br></div>';
        return tt;
    });
    if (opener && opener.GITestItReportReady) {
        opener.GITestItReportReady();
    }
    else if (parent && parent.GITestItReportReady) {
        opener = parent;
        parent.GITestItReportReady();
    }
});

function getElement(q) {
    return o = (embedded) ? $("#if1").contents().find(q) : $(q);
}

function fillTestDate() {
    var d = new Date();
    getElement("*[name='TestDate'] ~ p").text(d.toDateString());
};

function fillTestName(s) {
    getElement("*[name='TestName'] ~ p").text(s).attr('contentEditable', true);
}

function fillTestNotes(s) {
    getElement("*[name='TestNotes'] ~ p").text(s).attr('contentEditable', true);
}

function fillTestResults(passed) {
    var o = getElement("*[name='TestResults'] ~ p");
    if (passed) {
        o.html("<img src='../../img/empty.gif' style='vertical-align:text-top' class='sum_passed'> " + R_testit_passed)
    }
    else {
        o.html("<img src='../../img/empty.gif' style='vertical-align:text-top' class='sum_failed'> " + R_testit_failed)
    }
}

function fillActualTime(s) {
    getElement("*[name='ActualTime'] ~ p").text(s);
}

function fillActionTesterNotes(fid, aid, s) {
    var q = "#TestNotesFrameID" + fid + "_" + aid;
    getElement(q).html(s);
}

function fillActionTestResult(fid, aid, s) {
    var o = getElement("*[name='TestResultFrameID" + fid + "_" + aid + "'] ~ p");
    switch (s) {
        case "passed":
            o.html("<img src='../../img/empty.gif' style='vertical-align:text-top' class='sum_passed'> " + R_testit_passed)
            break;
        case "failed":
            o.html("<img src='../../img/empty.gif' style='vertical-align:text-top' class='sum_failed'> " + R_testit_failed)
            break;
        case "skipped":
            o.html("<img src='../../img/empty.gif' style='vertical-align:text-top' class='sum_skipped'> " + R_testit_skipped)
            break;
    }
    //    $("*[name=TestResultFrameID" + fid + "_" + aid + "] ~ p").text(s);
}

