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) {
    $(".dialog").css({ 'width': width + "px", 'margin-left': 'auto', 'margin-right': 'auto' });
    if (navigator.userAgent.match(/iphone/i) || navigator.userAgent.match(/ipod/i) || navigator.userAgent.match(/ipad/i)) {
        $("#" + replacementContentId).hide();
        $(".dialog").append("<object width='" + width + "' height='" + height + "'><param name='movie' value='http://www.youtube.com/v/" + videoId + "&enablejsapi=1&rel=0&autoplay=1&playerapiid=ytplayer'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed src='http://www.youtube.com/v/" + videoId + "&enablejsapi=1&rel=0&autoplay=1&playerapiid=ytplayer' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='" + width + "' height='" + height + "'></embed></object>");                     
    }
    else {    
        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);
    }
}

