
var Util = {
 popup:  function(url, window_name, width,  height, x_pos, y_pos,  options) { 
 if(!options) { 
 options = { 
 'resizable': 1, 
 'scrollbars': 1, 
 'menubar': 1, 
 'toolbar': 1, 
 'status': 1, 
 'titlebar': 1, 
 'fullscreen': 0 
 }; 
 } 
 // If illegal values are set for the top and left positions then center the window. 
 if(window.innerWidth) { 
 options.width = width || window.innerWidth - 50; 
 options.height = height || window.innerHeight - 50; 
  
 if(isNaN(x_pos) || x_pos < 0) { 
 options.x_pos = (window.innerWidth - options.width) / 2; 
 } 
  
 if(isNaN(y_pos) || y_pos < 0) { 
 options.y_pos = ((window.innerHeight - options.height) / 4) - 50; 
 } 
 } 
 else { 
 options.width = width || window.screen.width - 50; 
 options.height = height || window.screen.height - 50; 
  
 if(isNaN(x_pos) || x_pos < 0) { 
 options.x_pos = (parseInt(window.screen.width) - options.width) / 2; 
 } 
 if(isNaN(y_pos) || y_pos < 0) { 
 options.y_pos = ((parseInt(window.screen.height) - options.height) / 2) - 50; 
 } 
 } 
  
 var total_options = 0; 
 for(var key in options) { 
 total_options++; 
 } 
  
 var window_attributes_str = ''; 
 var att_counter = 0; 
 for(var key in options) { 
 value = options[key]; 
 if(value === true) { 
 value = '1'; 
 } 
 else if(value === false || value === null || value === undefined) { 
 value = '0'; 
 } 
 window_attributes_str += key + '=' + value; 
 if(att_counter < (total_options)) { 
 window_attributes_str += ','; 
 }
 att_counter++;
 }
 window_name = window_name ? this.replaceAll('-', '_', window_name) : '_blank';
 window_name = window_name ? this.replaceAll(' ', '_', window_name) : '_blank';
  
 popup_window = window.open(url, window_name, window_attributes_str);
  
 return popup_window; 
 }, 
 replaceAll: function(target, replacement, string) { 
 var match_index = string.indexOf(target); 
 while(match_index != -1) { 
 string = string.replace(target, replacement); 
 match_index = string.indexOf(target); 
 } 
 }, 
 isPopupClosed: function(wndw) { 
 return wndw.closed; 
 }
};
