﻿/// <reference path="../js/jquery.js" />
String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, "");
}
String.prototype.ltrim = function() {
    return this.replace(/^\s+/, "");
}
String.prototype.rtrim = function() {
    return this.replace(/\s+$/, "");
}

var popupCallBack;

function GetDateValue(d) {
    if (d != null) {

        return d.getFullYear() + '/' + (d.getMonth() + 1) + '/' + d.getDate();
    }

    return '';
}
function openPopup(url, element, width, height, callBack, headerText) {
    //popup.SetContentHtml("Loading...");
    //popup.SetContentUrl('/common/loading.htm');
    popup.SetContentUrl(url);
    //    var s = popup.GetWindowContentIFrame().contentWindow.document.title;
    //    popup.SetHeaderText(s);
    if (popup.IsVisible())
        popup.UpdatePosition();
    if (width && height) {
        popup.SetSize(width, height);
    }
    if (callBack) {
        popupCallBack = callBack;
    }
    if (headerText) {
        popup.SetHeaderText(headerText);
    }
    popup.ShowAtElement(element);

    return void (0);

}
function $Get(elementId) {
    return document.getElementById(elementId);
}
function CloseAndReload() {
    parent.popup.Hide();
    if (parent.gridUser != null)
        parent.gridUser.PerformCallback();
   
}
function ShowLoadingAt(element) {
    loading.ShowInElement(element);
}
function HideLoading() {
    loading.Hide();
}

function OnIdentificationTypeChanged(comb, textbox) {
    var el = $(textbox.GetInputElement());
    el.unmask();
    switch (comb.GetValue()) {
        case 'IdentificationCodeQualifier.CBP':
            el.mask('999999-99999');
            break;
        case 'IdentificationCodeQualifier.EIN':
            el.mask('99-9999999aa');
            break;
        case 'IdentificationCodeQualifier.SSN':
            el.mask('999-99-9999');
            break;
    }
}
function clearform(ele) {
    $(ele).find(':input').each(function () {
        switch (this.type) {
            case 'password':
            case 'select-multiple':
            case 'select-one':
            case 'text':
            case 'textarea':
                $(this).val('');
                break;
            case 'checkbox':
            case 'radio':
                this.checked = false;
        }
    });
}


function autocompleteCityHook(selector) {
    //autocomplete
    $(selector).autocomplete({
        delay: 0,
        minLength: 2,
        autoFocus: true,
        source: function (request, response) {
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "/ComboBoxDataService.asmx/GetCityNames",
                dataType: "json",
                data: "{ text: '" + request.term + "'}",
                success: function (data) {
                    response(data.d);
                }
            });
        }
    });
}


function autocompleteMemHook(selector) {
    //autocomplete
    $(selector).autocomplete({
        delay: 0,
        minLength: 2,
        autoFocus: true,
        source: function (request, response) {
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "/ComboBoxDataService.asmx/GetMembers",
                dataType: "json",
                data: "{ text: '" + request.term + "'}",
                success: function (data) {
                    response(data.d);
                }
            });
        },
        select: function (event, ui) {
            if (ui.item) {
                var self = $(this);
                var elm = self.nextAll("textarea");
                elm.val(ui.item.code);
                //alert(elm.length);
            }
        }
    });
}
