﻿var JISportProductDetails = {
    autoShowSendToFriendDialog: false,
    ShowSendToFriendDialog: function() {
        var sendToFriendUrlOutputElement = PXClientSideControlHelper.FindControl('160ec103-3adf-4325-9d97-f54658a652ef');
        var sendToFriendUrlTextInputElement = PXClientSideControlHelper.FindControl('5e4a2b7e-129e-4fd6-ae23-d7c641d17203');
        var sendToFriendUrlTextOutputElement = PXClientSideControlHelper.FindControl('d027ce1e-84a1-4e6d-ada4-bede17013748');
        sendToFriendUrlOutputElement.value = window.location;
        sendToFriendUrlTextOutputElement.value = sendToFriendUrlTextInputElement.innerHTML;
        cadSendToFriendDialog.Show();
    },
    PreSendToFriendSubmit: function() {
        var sendToFriendCommentDisplayInputElement = PXClientSideControlHelper.FindControl('b1360101-b6cf-4747-957e-c35f29dd8df0');
        var sendToFriendCommentInputElement = PXClientSideControlHelper.FindControl('96b3d0e7-0c0d-4c75-83dc-9b1216229b17');
        if (sendToFriendCommentDisplayInputElement.value != "") {
            sendToFriendCommentInputElement.value = JISportProductDetails.ReplaceJSLineBreak(sendToFriendCommentDisplayInputElement.value);
        }
        return true;
    },
    ReplaceJSLineBreak: function(string) {
        return JISportProductDetails.ReplaceJSLineBreakInner(JISportProductDetails.ReplaceJSLineBreakInner(JISportProductDetails.ReplaceJSLineBreakInner(string, "\r\n"), "\r"), "\n");
    },
    ReplaceJSLineBreakInner: function(string, text) {
        var stringLength = string.length, textLength = text.length;
        if ((stringLength == 0) || (textLength == 0)) return string;
        var i = string.indexOf(text);
        if ((!i) && (text != string.substring(0, textLength))) return string;
        if (i == -1) return string;
        var newString = string.substring(0, i) + "<br />";
        if (i + textLength < stringLength)
            newString += JISportProductDetails.ReplaceJSLineBreak(string.substring(i + textLength, stringLength), text);
        return newString;
    },
    SetShowFriendDialogAutoShow: function(autoshow) {
        JISportProductDetails.autoShowSendToFriendDialog = autoshow;
    },
    PageLoaded: function(sender, args) {
        if (JISportProductDetails.autoShowSendToFriendDialog)
            cadSendToFriendDialog.Show();
    }
}
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(JISportProductDetails.PageLoaded);

