var id;
id = 'RVPopup';
var divIdName;
var IFrmeName;

function AddDivElement() {
    var newdiv = document.createElement('div');
    var divcssString = 'clear:both';
    divIdName = 'dv' + id;
    newdiv.setAttribute('id', divIdName.toString());
    newdiv.setAttribute('style', divcssString);
    document.getElementsByTagName('FORM')[0].appendChild(newdiv);
}
//create new iframe and append it to div element created above
function AddIFrameElement() {
    var newIFrme = document.createElement("iframe");
    IFrmeName = 'ifrm' + id;
    newIFrme.style.display = 'none';
    newIFrme.style.border = '0px';
    newIFrme.id = IFrmeName;
    newIFrme.frameborder = '0';
    newIFrme.width = '99%';
    newIFrme.height = '99%';
    newIFrme.scrolling = 'auto';
    newIFrme.src = '';
    document.getElementById(divIdName).appendChild(newIFrme);
}

function showRvPopup(url, title, varwidth, varheight) {
    var theurl = url;
    var thetitle = title;
    if (title == null)
        thetitle = "...";

    if (url.toString().indexOf("?") > -1)
        theurl = theurl //+ "&guid=" + generateGuid();
    else
        theurl = theurl //+ "?guid=" + generateGuid();

    $("#" + divIdName).dialog({
        modal: true,
        overlay: {
            opacity: 0.5,
            background: "white"
        },
        title: thetitle,
        width: varwidth + 'px',
        height: varheight + 'px',
        resizable: false,
        autoResize: true,
        draggable: true,
        close: closeRvPopup,
        resizableOptions: { autoResize: true, autoHide: true }
    }).show();
    
    $("#" + IFrmeName).attr("src", theurl);
    $("#" + IFrmeName).css("display", "block");
 document.getElementById(divIdName).style.height="105%";
 document.getElementById(divIdName).style.width = "100%";


}

function showRvPopupWithCloseWithoutPostback(url, title, varwidth, varheight) {
    var theurl = url;
    var thetitle = title;
    if (title == null)
        thetitle = "...";

    if (url.toString().indexOf("?") > -1)
        theurl = theurl //+ "&guid=" + generateGuid();
    else
        theurl = theurl //+ "?guid=" + generateGuid();

    $("#" + divIdName).dialog({
        modal: true,
        overlay: {
            opacity: 0.5,
            background: "white"
        },
        title: thetitle,
        width: varwidth + 'px',
        height: varheight + 'px',
        resizable: false,
        autoResize: true,
        draggable: true,
        close: closedwithoutpostback,
        resizableOptions: { autoResize: true, autoHide: true }
    }).show();

    $("#" + IFrmeName).attr("src", theurl);
    $("#" + IFrmeName).css("display", "block");
}

function closedwithoutpostback() {
    var d = $("#" + divIdName).dialog('destroy');   
}
function bindclose() {
    $(document).bind('click.dialog-overlay', function(e) {
        var el;
        if (e.srcElement)
            el = e.srcElement
        else
            el = e.target
        if (el.className == 'ui-dialog-overlay') {
            $("#" + divIdName).dialog('close');
            //$("#" + IFrmeName).attr("src", "");
        }
    });
}
function closeRvPopup() {
    try {
        var d = $("#" + divIdName).dialog('destroy');
        $("#" + IFrmeName).attr("src", "");
        $('html, body').css("overflow", "scroll");
    }
    catch (obj) {
    }
}
//create new div element
$(document).ready(function() {

    AddDivElement();
    AddIFrameElement();
    
});
