

var userInfo4DownloadcookieName = 'userinfo4download';
var dialogID = 'dialogRMGReg';
function doDownloadByUserinfo(dlurl, regurl){
     var cookieValue = $.cookie(userInfo4DownloadcookieName);
    //alert(cookieValue);
    if(cookieValue == 'ok') {
        var newwindow = window.open(dlurl, '_target');
        //newwindow.focus();
        return;
    }
    showRmgRegDialog(regurl+'?dlurl='+encodeURIComponent(dlurl),'RMG Registration Form');
}

function setUserinfo4DownloadCookie(timeout){
    var date = new Date();
    date.setTime(date.getTime() + (timeout* 60 * 1000));  //timeout:minutes
    $.cookie(userInfo4DownloadcookieName, "ok", {expires: date});
}
function showRmgRegDialog(regurl, title) {
    //alert(window.parent.$('#footer').attr('id'));
    closeRmgRegDialog();
    /*
    //current iframe dialog
     var dialog = $("<div id='"+dialogID+"' style='background-color:gray;'></div>");
     $(dialog).load(regurl, function() {
      $(this).dialog({
        resizable: false,
        title: title,
        //modal: true,
        bgiframe: true,
        width: 400,
        height: 400,
        close: function(){
            $(this).remove();
        }
      });
    });
*/
   
    // global dialog
    window.parent.$('body').append("<div id='"+dialogID+"' style='background-color:gray;' ></div>");
    //alert(window.parent.$(dialog).attr("id"));
    window.parent.$('#'+dialogID).load(regurl, function() {
      window.parent.$('#'+dialogID).dialog({
        resizable: false,
        title: title,
        modal: false,
        bgiframe: true,
        width: 400,
        height: 500,
        close: function(){
            window.parent.$('#'+dialogID).remove();
        }
      });
    });
    
}

function closeRmgRegDialog(){
  //alert('closeRmgRegDialog : ');
  window.parent.$('#'+dialogID).dialog('close');
  //$('#'+dialogID).dialog('close');
}
