﻿$(function() {
    // add form to end of page and event to link
    var domain = "chevron.cgconverge.com";
    $("a[href*='" + domain + "'], a[@href*='" + domain + "']").unbind("click").click(function() {
        var cgnoVal = $("div.bogus").text();
        if (cgnoVal && cgnoVal.length > 0 && cgnoVal != "0") {
            if (cgnoVal == "external") {
                // default to external check message
                return true;
            } else {
                var $newForm = $("<form action='https://secure.cgconverge.com/singlesignonhandler.aspx?SiteID=61' method='post' target='_blank'></form>");
                $newForm.append("<input type='hidden' id='cgno' name='cgno' value='" + cgnoVal + "' />");
                $("#aspnetForm").after($newForm);

                $newForm.submit();
                return false;
            }
        } else {
            alert("Authentication failed, refresh the page or try again later.");
            return false;
        }
    });
});