﻿ResizeTextAreas("textarea");
SetUpButtons();
SetUpDateFields();

function ResizeTextAreas(ids) {
    $(ids).each(function() {
        if ($(this).isChildOf("#NestedFieldConfiguration")) {
            return;
        }

        $(this).resizable("destroy");
        $(this).css("width", 498).css("height", 150);
        $(this).resizable({
            handles: "se",
            maxWidth: 779,
            start: function(event, ui) {
                event.stopPropagation();
                event.preventDefault();
            }
        });
        $(this).css("z-index", 1000);

        if ($(this).isChildOf("#QuestionEditors") || $(this).isChildOf(".ui-dialog")) {
            $(this).resizable("option", "maxWidth", 500);
        } else if ($(this).isChildOf(".questions")) {
            $(this).resizable("option", "maxWidth", 765);
        } else if ($(this).isChildOf(".FormRow")) {
            $(this).resizable("option", "maxWidth", 780);
        } else if ($(this).isChildOf(".MainDiv")) { // Foundant Panels
            $(this).resizable("option", "maxWidth", 650);
        }
    });

    $(".ui-wrapper").css("padding", "0");
    $(".ui-wrapper").css("overflow", "visible");
    $(".ui-wrapper").css("float", "left");
}

function SetUpButtons() {
    $("input").filter('[type="submit"]').button("destroy");
    $("input").filter('[type="button"]').button("destroy");
    $("button").button("destroy");
    
    $("input").filter('[type="submit"]').button();
    $("input").filter('[type="button"]').button();
    $("button").button();

    $(".ui-button").css("font-size", "1em")
}

function SetUpDateFields() {
    $(function() { $(".DatePicker").datepicker().css("width", "100px"); });
}

function ParseId(parse, type) {
    var regex = new RegExp(".*" + type + "_([0-9]*).*");
    var id = regex.exec(parse);

    return id[1];
}

function GetBaseUrl() {
    var url = location.href;  // entire url including querystring - also: window.location.href;
    return url.substring(0, url.indexOf('/', 8));
}

function AjaxFailed(result) {
    // For now if there are errors, just reload the page (without "reloading" scripts etc.)
    window.location.href = window.location.href;
    //    alert("There was a problem editing the form. Please reload the page and try again.");
    //alert(result);
}

