﻿function popup(mylink, windowname) {
    if (!window.focus) return true;
    var href;
    if (typeof (mylink) == 'string')
        href = mylink;
    else
        href = mylink.href;
    window.open(href, windowname, 'width=1400,height=800,scrollbars=yes');
    return false;
}
function execJson() {
    $("#statusBox").html("<p>processing...</p>");
    $("#resultsBox").val("");

    var format = $("#format").val();
    var indentXmlFormatting = false;
    var formatParameters = "";
    if (format == "XML") {
        if ($("#indent")[0].checked) {
            indentXmlFormatting = true;
        }
    } else if (format == "JSON") {
        formatParameters = "&format=JSON";
        var callback = $("#callback").val();
        if (callback != "") {
            formatParameters += "&callback=" + callback;
        }
    }

    var url = $("#url").val() + "?" + $("#parameters").val() +
        "&consumerKey=" + $("#consumerKey").val() +
        formatParameters;

    $("#queryUrl").html("<a href='http://api.gigjunkie.net" + url +
        "' target='_blank'>http://api.gigjunkie.net" + url + "</a>");

    var storeKey = $("#storeKey")[0].checked;
    $.ajax({ url: url, data: {
        storeKey: storeKey ? "true" : "",
        indent: indentXmlFormatting ? "true" : ""
    }, dataType: "text", type: "GET", success: successCallback, error: errorCallback
    });
}
function successCallback(data) {
    $("#statusBox").html("<p>success</p>");
    $("#resultsBox").val(data);
}
function errorCallback(data) {
    $("#statusBox").html("<p>" + data.status + ": " + data.statusText + "</p>");
    $("#resultsBox").val(data.responseText);
}
function onChangeFormat() {
    var format = $("#format").val();
    $("#formatOptions DIV").hide();
    $("#formatOptions DIV." + format).show();
}
