function OpenAjaxDialog(dialogName, width, height) {    
    if (typeof(pageTracker) != "undefined") {
        pageTracker._trackPageview(asn_scriptVariables.Community_ChannelURL+"Dialogs/" + dialogName);
    }
    if ($("#" + dialogName + "CommunityDialog").length == 1) {
        $("#" + dialogName + "CommunityDialog").dialog("open");
    } else {
        $.ajax({
            type: "POST",
            url:  asn_scriptVariables.Community_PostbackURL+"/GetDialogContent",
            data: "{'dialogChannelPath':'"+asn_scriptVariables.Community_DialogChannelPath+"','dialogName':'" + dialogName + "','postingUrl':'"+asn_scriptVariables.Community_PostingUrl+"', 'propId':'"+asn_scriptVariables.Community_CommunityId+"'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(arg) {
                var html = typeof(arg) == "string" ? arg : arg.d;
                var htmlOnly = html;
                var start = html.indexOf("<!--Begin JavaScript-->");
                if (start > 0) {
                    htmlOnly = html.substr(0, start) + 
                    html.substr(html.indexOf("<!--End JavaScript-->") + "<!--End JavaScript-->".length);
                }
                var el = $("<div id=\"" + dialogName + "CommunityDialog\" class=\"flora\">" + htmlOnly + "</div>");
                
                
                
                var elDlg = el.dialog({
                    modal: true, 
                    width: width,
                    height: height,
                    overlay: { 
                        opacity: 0.6, 
                        background: "black" 
                    },
                    close: function() {
                        if (start > 0) {
                            $("#" + dialogName + "CommunityDialog").dialog("destroy").remove();
                        }
                    }
                });
                
                if (start > 0) {
                    eval(html.substr(start + "<!--Begin JavaScript-->".length, html.indexOf("<!--End JavaScript-->") - (start + "<!--Begin JavaScript-->".length)));
                    
                }
                var anchor = elDlg.parent().find(".ui-dialog-titlebar-close");
                if (anchor.length > 0) {
                    var href = anchor.attr("href");
                    href = decodeURIComponent(href.substr(href.indexOf("&NRORIGINALURL=") + 15, href.indexOf("&NRCACHEHINT=") - (href.indexOf("&NRORIGINALURL=") + 15)));
                    if (href.indexOf("?") > 0) {
                        href = href.substr(0, href.indexOf("?"));
                    }
                    anchor.attr("href", href);
                }
                
            }
        });
        
    }
    return false;
}

function playVideoInDialog(videoId, width, height, replacementContentId) {       
    if (navigator.userAgent.indexOf('iPhone') != -1) {        
        $("[id$=CommunityDialog]").dialog("close");        
        window.location.href = "http://www.youtube.com/watch?v=" + videoId;
    }
    else {
        $(".dialog").css({'width': width + "px", 'margin-left':'auto', 'margin-right':'auto'});
        var params = { allowScriptAccess: "always" };
        var atts = { id: "myytplayer" };
        swfobject.embedSWF("http://www.youtube.com/v/" + videoId +"&enablejsapi=1&rel=0&autoplay=1&playerapiid=ytplayer", 
                       replacementContentId, width, height, "8", null, null, params, atts);
    }
}
