$(document).ready(function(){
   $("a[rel*='Popup']").each(function(){
    var width;
        if ( $(this).attr('rel').split(',')[1] ){
            width = $(this).attr('rel').split(',')[1];
        }else{
            width = 600;
        }
        var height;
        if ( $(this).attr('rel').split(',')[2] ){
            height = $(this).attr('rel').split(',')[2];
        }else{
            height = 500;
        }
     //manipulate a rel=popup into out popup.
      this.href = "javascript:WindowOpenWindowCentered('"+this.href+"/popup', 'popup',"+width+","+height+",1,1)"
      this.title = this.title + " - opens in a new window";
   });
});


function WindowOpenWindowCentered(url, name, width, height, resizable, scrollbars){

    var w = 800, h = 600;

    if (document.all) {
       /* the following is only available after onLoad */
       w = document.body.clientWidth;
       h = document.body.clientHeight;
    }
    else if (document.layers) {
       w = window.innerWidth;
       h = window.innerHeight;
    }


    var popW = width, popH = height;

    var leftPos = (w-popW)/2, topPos = (h-popH)/2;
    
    var win = window.open( url, name, 'width=' + popW + ',height=' + popH + ',top=' + topPos+',left=' + leftPos + ',resizable=' + resizable + ',scrollbars=' + scrollbars );
    win.focus();

}

function WindowOpenScreenCentered(url, name, width, height, resizable, scrollbars){
    var w = 800, h = 600;

    if (document.all || document.layers) {
       w = screen.availWidth;
       h = screen.availHeight;
    }

    var popW = width, popH = height;

    var leftPos = (w-popW)/2, topPos = (h-popH)/2;

    var win = window.open( url, name, 'width=' + popW + ',height=' + popH + ',top=' + topPos+',left=' + leftPos + ',resizable=' + resizable + ',scrollbars=' + scrollbars );
    win.focus();
}



