includes/clientside/static/paginate.js
changeset 1227 bdac73ed481e
parent 1173 b5b8e7ab0914
equal deleted inserted replaced
1226:de56132c008d 1227:bdac73ed481e
    11  
    11  
    12 var pagin_objects = new Object();
    12 var pagin_objects = new Object();
    13 
    13 
    14 window.paginator = function(data, callback, offset, perpage, passer, ov_num_pages, ov_flip_func)
    14 window.paginator = function(data, callback, offset, perpage, passer, ov_num_pages, ov_flip_func)
    15 {
    15 {
    16   load_component('flyin');
    16 	load_component('flyin');
    17   if ( !perpage || typeof(perpage) != 'number' || ( typeof(perpage) == 'number' && perpage < 1 ) )
    17 	if ( !perpage || typeof(perpage) != 'number' || ( typeof(perpage) == 'number' && perpage < 1 ) )
    18   {
    18 	{
    19     this.perpage = 10;
    19 		this.perpage = 10;
    20   }
    20 	}
    21   else
    21 	else
    22   {
    22 	{
    23     this.perpage = perpage;
    23 		this.perpage = perpage;
    24   }
    24 	}
    25   if ( typeof(offset) != 'number' )
    25 	if ( typeof(offset) != 'number' )
    26     this.offset = 0;
    26 		this.offset = 0;
    27   else
    27 	else
    28     this.offset = offset;
    28 		this.offset = offset;
    29   if ( typeof(passer) != 'undefined' )
    29 	if ( typeof(passer) != 'undefined' )
    30     this.passer = passer;
    30 		this.passer = passer;
    31   else
    31 	else
    32     this.passer = false;
    32 		this.passer = false;
    33   if ( ov_num_pages )
    33 	if ( ov_num_pages )
    34   {
    34 	{
    35     this.num_pages = ov_num_pages;
    35 		this.num_pages = ov_num_pages;
    36     this.flip_func = ov_flip_func;
    36 		this.flip_func = ov_flip_func;
    37   }
    37 	}
    38   else
    38 	else
    39   {
    39 	{
    40     this.num_pages = Math.ceil(data.length / perpage);
    40 		this.num_pages = Math.ceil(data.length / perpage);
    41     this.flip_func = false;
    41 		this.flip_func = false;
    42   }
    42 	}
    43   this.random_id = 'autopagin_' + Math.floor(Math.random() * 1000000);
    43 	this.random_id = 'autopagin_' + Math.floor(Math.random() * 1000000);
    44   this._build_control = _build_paginator;
    44 	this._build_control = _build_paginator;
    45   this.set_page = function(number)
    45 	this.set_page = function(number)
    46   {
    46 	{
    47     this.offset = number * this.perpage;
    47 		this.offset = number * this.perpage;
    48     var html = this._build_control(number);
    48 		var html = this._build_control(number);
    49     var elements = getElementsByClassName(document.body, 'div', this.random_id + '_control');
    49 		var elements = getElementsByClassName(document.body, 'div', this.random_id + '_control');
    50     for ( var i = 0; i < elements.length; i++ )
    50 		for ( var i = 0; i < elements.length; i++ )
    51       elements[i].innerHTML = html;
    51 			elements[i].innerHTML = html;
    52   }
    52 	}
    53   if ( this.num_pages > 1 )
    53 	if ( this.num_pages > 1 )
    54   {
    54 	{
    55     var pg_control = '<div class="'+this.random_id+'_control">'+this._build_control(0)+'</div>';
    55 		var pg_control = '<div class="'+this.random_id+'_control">'+this._build_control(0)+'</div>';
    56   }
    56 	}
    57   else
    57 	else
    58   {
    58 	{
    59     var pg_control = '';
    59 		var pg_control = '';
    60   }
    60 	}
    61   this.html = pg_control;
    61 	this.html = pg_control;
    62   var i = 0;
    62 	var i = 0;
    63   while ( i < data.length )
    63 	while ( i < data.length )
    64   {
    64 	{
    65     if ( i % this.perpage == 0 )
    65 		if ( i % this.perpage == 0 )
    66     {
    66 		{
    67       if ( i > 0 )
    67 			if ( i > 0 )
    68         this.html += '</div>';
    68 				this.html += '</div>';
    69       var display = ( ( i * this.perpage ) == this.offset ) ? '' : 'display: none;';
    69 			var display = ( ( i * this.perpage ) == this.offset ) ? '' : 'display: none;';
    70       var thispage = Math.floor(i / this.perpage);
    70 			var thispage = Math.floor(i / this.perpage);
    71       this.html += '<div id="' + this.random_id + '_' + thispage + '" style="' + display + '">';
    71 			this.html += '<div id="' + this.random_id + '_' + thispage + '" style="' + display + '">';
    72     }
    72 		}
    73     this.html += callback(data[i], this.passer);
    73 		this.html += callback(data[i], this.passer);
    74     i++;
    74 		i++;
    75   }
    75 	}
    76   this.html += '</div>';
    76 	this.html += '</div>';
    77   this.html += pg_control;
    77 	this.html += pg_control;
    78   pagin_objects[this.random_id] = this;
    78 	pagin_objects[this.random_id] = this;
    79 }
    79 }
    80 
    80 
    81 /**
    81 /**
    82  * Yet another demonstration of the fact that with the right tools, any amount of Javascript can be ported from PHP.
    82  * Yet another demonstration of the fact that with the right tools, any amount of Javascript can be ported from PHP.
    83  * @access private
    83  * @access private
    84  */
    84  */
    85 
    85 
    86 window._build_paginator = function(this_page)
    86 window._build_paginator = function(this_page)
    87 {
    87 {
    88   var div_styling = ( IE ) ? 'width: 1px; margin: 10px auto 10px 0;' : 'display: table; margin: 10px 0 10px auto;';
    88 	var div_styling = ( IE ) ? 'width: 1px; margin: 10px auto 10px 0;' : 'display: table; margin: 10px 0 10px auto;';
    89   var begin = '<div class="tblholder" style="'+div_styling+'"><table border="0" cellspacing="1" cellpadding="4"><tr><th>' + $lang.get('paginate_lbl_page') + '</th>';
    89 	var begin = '<div class="tblholder" style="'+div_styling+'"><table border="0" cellspacing="1" cellpadding="4"><tr><th>' + $lang.get('paginate_lbl_page') + '</th>';
    90   var block = '<td class="row1" style="text-align: center; white-space: nowrap;">{LINK}</td>';
    90 	var block = '<td class="row1" style="text-align: center; white-space: nowrap;">{LINK}</td>';
    91   var end = '</tr></table></div>';
    91 	var end = '</tr></table></div>';
    92   var blk = new templateParser(block);
    92 	var blk = new templateParser(block);
    93   var inner = '';
    93 	var inner = '';
    94   var cls = 'row2';
    94 	var cls = 'row2';
    95   
    95 	
    96   if ( this_page > 0 )
    96 	if ( this_page > 0 )
    97   {
    97 	{
    98     var url = '#page_'+(this_page);
    98 		var url = '#page_'+(this_page);
    99     var link = "<a href=\""+url+"\" onclick=\"jspaginator_goto('"+this.random_id+"', "+(this_page-1)+"); return false;\" style='text-decoration: none;'>&laquo; " + $lang.get('paginate_btn_prev') + "</a>";
    99 		var link = "<a href=\""+url+"\" onclick=\"jspaginator_goto('"+this.random_id+"', "+(this_page-1)+"); return false;\" style='text-decoration: none;'>&laquo; " + $lang.get('paginate_btn_prev') + "</a>";
   100     cls = ( cls == 'row1' ) ? 'row2' : 'row1';
   100 		cls = ( cls == 'row1' ) ? 'row2' : 'row1';
   101     blk.assign_vars({
   101 		blk.assign_vars({
   102         CLASS: cls,
   102 				CLASS: cls,
   103         LINK: link
   103 				LINK: link
   104       });
   104 			});
   105     inner += blk.run();
   105 		inner += blk.run();
   106   }
   106 	}
   107   if ( this.num_pages < 5 )
   107 	if ( this.num_pages < 5 )
   108   {
   108 	{
   109     for ( var i = 0; i < this.num_pages; i++ )
   109 		for ( var i = 0; i < this.num_pages; i++ )
   110     {
   110 		{
   111       cls = ( cls == 'row1' ) ? 'row2' : 'row1';
   111 			cls = ( cls == 'row1' ) ? 'row2' : 'row1';
   112       var j = i + 1;
   112 			var j = i + 1;
   113       var url = '#page_'+j;
   113 			var url = '#page_'+j;
   114       var link = ( i == this_page ) ? "<b>"+j+"</b>" : "<a href=\""+url+"\" onclick=\"jspaginator_goto('"+this.random_id+"', "+i+"); return false;\" style='text-decoration: none;'>"+j+"</a>";
   114 			var link = ( i == this_page ) ? "<b>"+j+"</b>" : "<a href=\""+url+"\" onclick=\"jspaginator_goto('"+this.random_id+"', "+i+"); return false;\" style='text-decoration: none;'>"+j+"</a>";
   115       blk.assign_vars({
   115 			blk.assign_vars({
   116           CLASS: cls,
   116 					CLASS: cls,
   117           LINK: link
   117 					LINK: link
   118         });
   118 				});
   119       inner += blk.run();
   119 			inner += blk.run();
   120     }
   120 		}
   121   }
   121 	}
   122   else
   122 	else
   123   {
   123 	{
   124     if ( this_page + 5 > this.num_pages )
   124 		if ( this_page + 5 > this.num_pages )
   125     {
   125 		{
   126       var list = new Array();
   126 			var list = new Array();
   127       var tp = this_page;                    // The vectors below used to be 3, 2, and 1
   127 			var tp = this_page;                    // The vectors below used to be 3, 2, and 1
   128       if ( this_page + 0 == this.num_pages ) tp = tp - 2;
   128 			if ( this_page + 0 == this.num_pages ) tp = tp - 2;
   129       if ( this_page + 1 == this.num_pages ) tp = tp - 1;
   129 			if ( this_page + 1 == this.num_pages ) tp = tp - 1;
   130       if ( this_page + 2 == this.num_pages ) tp = tp - 0;
   130 			if ( this_page + 2 == this.num_pages ) tp = tp - 0;
   131       for ( var i = tp - 1; i <= tp + 1; i++ )
   131 			for ( var i = tp - 1; i <= tp + 1; i++ )
   132       {
   132 			{
   133         list.push(i);
   133 				list.push(i);
   134       }
   134 			}
   135     }
   135 		}
   136     else
   136 		else
   137     {
   137 		{
   138       var list = new Array();
   138 			var list = new Array();
   139       var current = this_page;
   139 			var current = this_page;
   140       var lower = ( current < 3 ) ? 1 : current - 1;
   140 			var lower = ( current < 3 ) ? 1 : current - 1;
   141       for ( var i = 0; i < 3; i++ )
   141 			for ( var i = 0; i < 3; i++ )
   142       {
   142 			{
   143         list.push(lower + i);
   143 				list.push(lower + i);
   144       }
   144 			}
   145     }
   145 		}
   146     var url = '#page_1';
   146 		var url = '#page_1';
   147     var link = ( 0 == this_page ) ? "<b>" + $lang.get('paginate_btn_first') + "</b>" : "<a href=\""+url+"\" onclick=\"jspaginator_goto('"+this.random_id+"', 0); return false;\" style='text-decoration: none;'>&laquo; " + $lang.get('paginate_btn_first') + "</a>";
   147 		var link = ( 0 == this_page ) ? "<b>" + $lang.get('paginate_btn_first') + "</b>" : "<a href=\""+url+"\" onclick=\"jspaginator_goto('"+this.random_id+"', 0); return false;\" style='text-decoration: none;'>&laquo; " + $lang.get('paginate_btn_first') + "</a>";
   148     blk.assign_vars({
   148 		blk.assign_vars({
   149         CLASS: cls,
   149 				CLASS: cls,
   150         LINK: link
   150 				LINK: link
   151       });
   151 			});
   152     inner += blk.run();
   152 		inner += blk.run();
   153 
   153 
   154     // if ( !in_array(1, $list) )
   154 		// if ( !in_array(1, $list) )
   155     // {
   155 		// {
   156     //   $cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
   156 		//   $cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
   157     //   $blk->assign_vars(array('CLASS'=>$cls,'LINK'=>'...'));
   157 		//   $blk->assign_vars(array('CLASS'=>$cls,'LINK'=>'...'));
   158     //   $inner .= $blk->run();
   158 		//   $inner .= $blk->run();
   159     // }
   159 		// }
   160 
   160 
   161     for ( var k in list )
   161 		for ( var k in list )
   162     {
   162 		{
   163       var i = list[k];
   163 			var i = list[k];
   164       if ( i == this.num_pages )
   164 			if ( i == this.num_pages )
   165         break;
   165 				break;
   166       cls = ( cls == 'row1' ) ? 'row2' : 'row1';
   166 			cls = ( cls == 'row1' ) ? 'row2' : 'row1';
   167       var j = i + 1;
   167 			var j = i + 1;
   168       var url = '#page_'+j;
   168 			var url = '#page_'+j;
   169       var link = ( i == this_page ) ? "<b>"+j+"</b>" : "<a href=\""+url+"\" onclick=\"jspaginator_goto('"+this.random_id+"', "+i+"); return false;\" style='text-decoration: none;'>"+j+"</a>";
   169 			var link = ( i == this_page ) ? "<b>"+j+"</b>" : "<a href=\""+url+"\" onclick=\"jspaginator_goto('"+this.random_id+"', "+i+"); return false;\" style='text-decoration: none;'>"+j+"</a>";
   170       blk.assign_vars({
   170 			blk.assign_vars({
   171           CLASS: cls,
   171 					CLASS: cls,
   172           LINK: link
   172 					LINK: link
   173         });
   173 				});
   174       inner += blk.run();
   174 			inner += blk.run();
   175     }
   175 		}
   176 
   176 
   177     if ( this_page < this.num_pages )
   177 		if ( this_page < this.num_pages )
   178     {
   178 		{
   179       // $cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
   179 			// $cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
   180       // $blk->assign_vars(array('CLASS'=>$cls,'LINK'=>'...'));
   180 			// $blk->assign_vars(array('CLASS'=>$cls,'LINK'=>'...'));
   181       // $inner .= $blk->run();
   181 			// $inner .= $blk->run();
   182 
   182 
   183       cls = ( cls == 'row1' ) ? 'row2' : 'row1';
   183 			cls = ( cls == 'row1' ) ? 'row2' : 'row1';
   184       var url = '#page_' + String( this.num_pages-1 );
   184 			var url = '#page_' + String( this.num_pages-1 );
   185       var link = ( ( this.num_pages - 1 ) == this_page ) ? "<b>" + $lang.get('paginate_btn_last') + "</b>" : "<a href=\""+url+"\" onclick=\"jspaginator_goto('"+this.random_id+"', "+(this.num_pages-1)+"); return false;\" style='text-decoration: none;'>" + $lang.get('paginate_btn_last') + " &raquo;</a>";
   185 			var link = ( ( this.num_pages - 1 ) == this_page ) ? "<b>" + $lang.get('paginate_btn_last') + "</b>" : "<a href=\""+url+"\" onclick=\"jspaginator_goto('"+this.random_id+"', "+(this.num_pages-1)+"); return false;\" style='text-decoration: none;'>" + $lang.get('paginate_btn_last') + " &raquo;</a>";
   186       blk.assign_vars({
   186 			blk.assign_vars({
   187           CLASS: cls,
   187 					CLASS: cls,
   188           LINK: link
   188 					LINK: link
   189         });
   189 				});
   190       inner += blk.run();
   190 			inner += blk.run();
   191     }
   191 		}
   192 
   192 
   193   }
   193 	}
   194 
   194 
   195   if ( this_page < ( this.num_pages - 1 ) )
   195 	if ( this_page < ( this.num_pages - 1 ) )
   196   {
   196 	{
   197     var url = '#page_' + String(this_page + 2);
   197 		var url = '#page_' + String(this_page + 2);
   198     var link = "<a href=\""+url+"\" onclick=\"jspaginator_goto('"+this.random_id+"', "+(this_page+1)+"); return false;\" style='text-decoration: none;'>" + $lang.get('paginate_btn_next') + " &raquo;</a>";
   198 		var link = "<a href=\""+url+"\" onclick=\"jspaginator_goto('"+this.random_id+"', "+(this_page+1)+"); return false;\" style='text-decoration: none;'>" + $lang.get('paginate_btn_next') + " &raquo;</a>";
   199     cls = ( cls == 'row1' ) ? 'row2' : 'row1';
   199 		cls = ( cls == 'row1' ) ? 'row2' : 'row1';
   200     blk.assign_vars({
   200 		blk.assign_vars({
   201           CLASS: cls,
   201 					CLASS: cls,
   202           LINK: link
   202 					LINK: link
   203         });
   203 				});
   204       inner += blk.run();
   204 			inner += blk.run();
   205   }
   205 	}
   206 
   206 
   207   inner += '<td class="row2" style="cursor: pointer;" onclick="paginator_goto(this, '+this_page+', '+this.num_pages+', '+this.perpage+', {js: true, random_id: \''+this.random_id+'\'});">&darr;</td>';
   207 	inner += '<td class="row2" style="cursor: pointer;" onclick="paginator_goto(this, '+this_page+', '+this.num_pages+', '+this.perpage+', {js: true, random_id: \''+this.random_id+'\'});">&darr;</td>';
   208 
   208 
   209   var paginator = "\n"+begin+inner+end+"\n";
   209 	var paginator = "\n"+begin+inner+end+"\n";
   210   return paginator;
   210 	return paginator;
   211   
   211 	
   212 }
   212 }
   213 
   213 
   214 var __paginateLock = false;
   214 var __paginateLock = false;
   215 
   215 
   216 window.jspaginator_goto = function(pagin_id, jump_to)
   216 window.jspaginator_goto = function(pagin_id, jump_to)
   217 {
   217 {
   218   if ( __paginateLock )
   218 	if ( __paginateLock )
   219     return false;
   219 		return false;
   220   var theobj = pagin_objects[pagin_id];
   220 	var theobj = pagin_objects[pagin_id];
   221   if ( theobj.flip_func )
   221 	if ( theobj.flip_func )
   222   {
   222 	{
   223     theobj.flip_func(theobj, jump_to);
   223 		theobj.flip_func(theobj, jump_to);
   224     __paginateLock = false;
   224 		__paginateLock = false;
   225     return true;
   225 		return true;
   226   }
   226 	}
   227   var current_div = false;
   227 	var current_div = false;
   228   var new_div = false;
   228 	var new_div = false;
   229   for ( var i = 0; i < theobj.num_pages; i++ )
   229 	for ( var i = 0; i < theobj.num_pages; i++ )
   230   {
   230 	{
   231     var thediv = document.getElementById(pagin_id + '_' + i);
   231 		var thediv = document.getElementById(pagin_id + '_' + i);
   232     if ( !thediv )
   232 		if ( !thediv )
   233     {
   233 		{
   234       // if ( window.console )
   234 			// if ( window.console )
   235         // window.console.error('jspaginator_goto(): got a bad DOM object in loop');
   235 				// window.console.error('jspaginator_goto(): got a bad DOM object in loop');
   236       return false;
   236 			return false;
   237     }
   237 		}
   238     // window.console.debug("Div "+i+' of '+(theobj.num_pages-1)+': ', thediv);
   238 		// window.console.debug("Div "+i+' of '+(theobj.num_pages-1)+': ', thediv);
   239     if ( thediv.style.display != 'none' )
   239 		if ( thediv.style.display != 'none' )
   240       current_div = thediv;
   240 			current_div = thediv;
   241     else if ( i == jump_to )
   241 		else if ( i == jump_to )
   242       new_div = thediv;
   242 			new_div = thediv;
   243   }
   243 	}
   244   
   244 	
   245   if ( !new_div )
   245 	if ( !new_div )
   246   {
   246 	{
   247     // if ( window.console )
   247 		// if ( window.console )
   248       // window.console.error('jspaginator_goto(): didn\'t get new div');
   248 			// window.console.error('jspaginator_goto(): didn\'t get new div');
   249     return false;
   249 		return false;
   250   }
   250 	}
   251   if ( !current_div )
   251 	if ( !current_div )
   252   {
   252 	{
   253     // if ( window.console )
   253 		// if ( window.console )
   254       // window.console.error('jspaginator_goto(): didn\'t get current div');
   254 			// window.console.error('jspaginator_goto(): didn\'t get current div');
   255     return false;
   255 		return false;
   256   }
   256 	}
   257   
   257 	
   258   // window.console.debug(current_div);
   258 	// window.console.debug(current_div);
   259   // window.console.debug(new_div);
   259 	// window.console.debug(new_div);
   260   
   260 	
   261   // White-out the old div and fade in the new one
   261 	// White-out the old div and fade in the new one
   262   
   262 	
   263   if ( IE || is_Safari || aclDisableTransitionFX )
   263 	if ( IE || is_Safari || aclDisableTransitionFX )
   264   {
   264 	{
   265     current_div.style.display = 'none';
   265 		current_div.style.display = 'none';
   266     new_div.style.display = 'block';
   266 		new_div.style.display = 'block';
   267   }
   267 	}
   268   else
   268 	else
   269   {
   269 	{
   270     __paginateLock = true;
   270 		__paginateLock = true;
   271     var fade_time = 375;
   271 		var fade_time = 375;
   272     var code = 'var old = \'' + current_div.id + '\';';
   272 		var code = 'var old = \'' + current_div.id + '\';';
   273     code    += 'var newer = \'' + new_div.id + '\';';
   273 		code    += 'var newer = \'' + new_div.id + '\';';
   274     code    += 'document.getElementById(old).style.display = "none";';
   274 		code    += 'document.getElementById(old).style.display = "none";';
   275     code    += 'changeOpac(0, newer);';
   275 		code    += 'changeOpac(0, newer);';
   276     code    += 'document.getElementById(newer).style.display = "block";';
   276 		code    += 'document.getElementById(newer).style.display = "block";';
   277     code    += 'opacity(newer, 0, 100, '+fade_time+');';
   277 		code    += 'opacity(newer, 0, 100, '+fade_time+');';
   278     code    += '__paginateLock = false;';
   278 		code    += '__paginateLock = false;';
   279     // if ( window.console )
   279 		// if ( window.console )
   280       // window.console.debug('metacode for fader: ', code);
   280 			// window.console.debug('metacode for fader: ', code);
   281     opacity(current_div.id, 100, 0, fade_time);
   281 		opacity(current_div.id, 100, 0, fade_time);
   282     setTimeout(code, (fade_time + 50));
   282 		setTimeout(code, (fade_time + 50));
   283   }
   283 	}
   284   
   284 	
   285   
   285 	
   286   var pg_control = theobj._build_control(jump_to);
   286 	var pg_control = theobj._build_control(jump_to);
   287   var divs = getElementsByClassName(document, 'div', pagin_id + '_control');
   287 	var divs = getElementsByClassName(document, 'div', pagin_id + '_control');
   288   for ( var i = 0; i < divs.length; i++ )
   288 	for ( var i = 0; i < divs.length; i++ )
   289   {
   289 	{
   290     divs[i].innerHTML = pg_control;
   290 		divs[i].innerHTML = pg_control;
   291   }
   291 	}
   292 }
   292 }
   293 
   293 
   294 window.paginator_goto = function(parentobj, this_page, num_pages, perpage, additive, url_string)
   294 window.paginator_goto = function(parentobj, this_page, num_pages, perpage, additive, url_string)
   295 {
   295 {
   296   load_component('flyin');
   296 	load_component('flyin');
   297   
   297 	
   298   var height = $dynano(parentobj).Height();
   298 	var height = $dynano(parentobj).Height();
   299   var width  = $dynano(parentobj).Width();
   299 	var width  = $dynano(parentobj).Width();
   300   var left   = $dynano(parentobj).Left();
   300 	var left   = $dynano(parentobj).Left();
   301   var top    = $dynano(parentobj).Top();
   301 	var top    = $dynano(parentobj).Top();
   302   var left_pos = left + width ;
   302 	var left_pos = left + width ;
   303   var top_pos = height + top;
   303 	var top_pos = height + top;
   304   var div = document.createElement('div');
   304 	var div = document.createElement('div');
   305   div.style.position = 'absolute';
   305 	div.style.position = 'absolute';
   306   div.style.top = top_pos + 'px';
   306 	div.style.top = top_pos + 'px';
   307   div.className = 'question-box';
   307 	div.className = 'question-box';
   308   div.style.margin = '1px 0 0 2px';
   308 	div.style.margin = '1px 0 0 2px';
   309   var vtmp = 'input_' + Math.floor(Math.random() * 1000000);
   309 	var vtmp = 'input_' + Math.floor(Math.random() * 1000000);
   310   var regex = new RegExp('\"', 'g');
   310 	var regex = new RegExp('\"', 'g');
   311   var submit_target = ( typeof(url_string) == 'object' ) ? ( toJSONString(url_string) ).replace(regex, '\'') : 'unescape(\'' + escape(url_string) + '\')';
   311 	var submit_target = ( typeof(url_string) == 'object' ) ? ( toJSONString(url_string) ).replace(regex, '\'') : 'unescape(\'' + escape(url_string) + '\')';
   312   var onclick = 'paginator_submit(this, '+num_pages+', '+perpage+', '+additive+', '+submit_target+'); return false;';
   312 	var onclick = 'paginator_submit(this, '+num_pages+', '+perpage+', '+additive+', '+submit_target+'); return false;';
   313   div.innerHTML = $lang.get('paginate_lbl_goto_page') + '<br /><input type="text" size="2" style="padding: 1px; font-size: 8pt;" value="'+(parseInt(this_page)+1)+'" id="'+vtmp+'" />&emsp;<a href="#" onclick="'+onclick+'" style="font-size: 14pt; text-decoration: none;">&raquo;</a>&emsp;<a href="#" onclick="var _pn = this.parentNode; setTimeout(function() { _pn.parentNode.removeChild(_pn); }, 2000); fly_out_top(this.parentNode, false, true); return false;" style="font-size: 14pt; text-decoration: none;">&times;</a>';
   313 	div.innerHTML = $lang.get('paginate_lbl_goto_page') + '<br /><input type="text" size="2" style="padding: 1px; font-size: 8pt;" value="'+(parseInt(this_page)+1)+'" id="'+vtmp+'" />&emsp;<a href="#" onclick="'+onclick+'" style="font-size: 14pt; text-decoration: none;">&raquo;</a>&emsp;<a href="#" onclick="var _pn = this.parentNode; setTimeout(function() { _pn.parentNode.removeChild(_pn); }, 2000); fly_out_top(this.parentNode, false, true); return false;" style="font-size: 14pt; text-decoration: none;">&times;</a>';
   314   
   314 	
   315   var body = document.getElementsByTagName('body')[0];
   315 	var body = document.getElementsByTagName('body')[0];
   316   domObjChangeOpac(0, div);
   316 	domObjChangeOpac(0, div);
   317   
   317 	
   318   body.appendChild(div);
   318 	body.appendChild(div);
   319   
   319 	
   320   document.getElementById(vtmp).onkeypress = function(e)
   320 	document.getElementById(vtmp).onkeypress = function(e)
   321     {
   321 		{
   322       if ( e.keyCode == 13 )
   322 			if ( e.keyCode == 13 )
   323         this.nextSibling.nextSibling.onclick();
   323 				this.nextSibling.nextSibling.onclick();
   324     };
   324 		};
   325   document.getElementById(vtmp).focus();
   325 	document.getElementById(vtmp).focus();
   326   
   326 	
   327   // fade the div
   327 	// fade the div
   328   /*
   328 	/*
   329   if(!div.id) div.id = 'autofade_'+Math.floor(Math.random() * 100000);
   329 	if(!div.id) div.id = 'autofade_'+Math.floor(Math.random() * 100000);
   330   var from = '#33FF33';
   330 	var from = '#33FF33';
   331   Fat.fade_element(div.id,30,2000,from,Fat.get_bgcolor(div.id));
   331 	Fat.fade_element(div.id,30,2000,from,Fat.get_bgcolor(div.id));
   332   */
   332 	*/
   333   
   333 	
   334   fly_in_bottom(div, false, true);
   334 	fly_in_bottom(div, false, true);
   335   
   335 	
   336   var divh = $dynano(div).Width();
   336 	var divh = $dynano(div).Width();
   337   left_pos = left_pos - divh;
   337 	left_pos = left_pos - divh;
   338   div.style.left = left_pos + 'px';
   338 	div.style.left = left_pos + 'px';
   339 }
   339 }
   340 
   340 
   341 window.paginator_submit = function(obj, max, perpage, additive, formatstring)
   341 window.paginator_submit = function(obj, max, perpage, additive, formatstring)
   342 {
   342 {
   343   var userinput = obj.previousSibling.previousSibling.value;
   343 	var userinput = obj.previousSibling.previousSibling.value;
   344   userinput = parseInt(userinput);
   344 	userinput = parseInt(userinput);
   345   var offset = (( userinput - 1 ) * perpage) + additive;
   345 	var offset = (( userinput - 1 ) * perpage) + additive;
   346   if ( userinput > max || isNaN(userinput) || userinput < 1 )
   346 	if ( userinput > max || isNaN(userinput) || userinput < 1 )
   347   {
   347 	{
   348     load_component(['messagebox', 'fadefilter', 'flyin']);
   348 		load_component(['messagebox', 'fadefilter', 'flyin']);
   349     new MessageBox(MB_OK|MB_ICONSTOP, $lang.get('paginate_err_bad_page_title'), $lang.get('paginate_err_bad_page_body', { max: max }));
   349 		new MessageBox(MB_OK|MB_ICONSTOP, $lang.get('paginate_err_bad_page_title'), $lang.get('paginate_err_bad_page_body', { max: max }));
   350     return false;
   350 		return false;
   351   }
   351 	}
   352   if ( typeof(formatstring) == 'object' )
   352 	if ( typeof(formatstring) == 'object' )
   353   {
   353 	{
   354     fly_out_top(obj.parentNode, false, true);
   354 		fly_out_top(obj.parentNode, false, true);
   355     jspaginator_goto(formatstring.random_id, ( offset / perpage ));
   355 		jspaginator_goto(formatstring.random_id, ( offset / perpage ));
   356   }
   356 	}
   357   else
   357 	else
   358   {
   358 	{
   359     var url = sprintf(formatstring, String(offset));
   359 		var url = sprintf(formatstring, String(offset));
   360     fly_out_top(obj.parentNode, false, true);
   360 		fly_out_top(obj.parentNode, false, true);
   361     window.location = url;
   361 		window.location = url;
   362   }
   362 	}
   363 }
   363 }
   364 
   364 
   365 // This code is in the public domain. Feel free to link back to http://jan.moesen.nu/
   365 // This code is in the public domain. Feel free to link back to http://jan.moesen.nu/
   366 function sprintf()
   366 function sprintf()
   367 {
   367 {
   368   if (!arguments || arguments.length < 1 || !RegExp)
   368 	if (!arguments || arguments.length < 1 || !RegExp)
   369   {
   369 	{
   370     return;
   370 		return;
   371   }
   371 	}
   372   var str = arguments[0];
   372 	var str = arguments[0];
   373   var re = /([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X)(.*)/;
   373 	var re = /([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X)(.*)/;
   374   var a = b = [], numSubstitutions = 0, numMatches = 0;
   374 	var a = b = [], numSubstitutions = 0, numMatches = 0;
   375   while (a = re.exec(str))
   375 	while (a = re.exec(str))
   376   {
   376 	{
   377     var leftpart = a[1], pPad = a[2], pJustify = a[3], pMinLength = a[4];
   377 		var leftpart = a[1], pPad = a[2], pJustify = a[3], pMinLength = a[4];
   378     var pPrecision = a[5], pType = a[6], rightPart = a[7];
   378 		var pPrecision = a[5], pType = a[6], rightPart = a[7];
   379     
   379 		
   380     //alert(a + '\n' + [a[0], leftpart, pPad, pJustify, pMinLength, pPrecision);
   380 		//alert(a + '\n' + [a[0], leftpart, pPad, pJustify, pMinLength, pPrecision);
   381 
   381 
   382     numMatches++;
   382 		numMatches++;
   383     if (pType == '%')
   383 		if (pType == '%')
   384     {
   384 		{
   385       subst = '%';
   385 			subst = '%';
   386     }
   386 		}
   387     else
   387 		else
   388     {
   388 		{
   389       numSubstitutions++;
   389 			numSubstitutions++;
   390       if (numSubstitutions >= arguments.length)
   390 			if (numSubstitutions >= arguments.length)
   391       {
   391 			{
   392         alert('Error! Not enough function arguments (' + (arguments.length - 1) + ', excluding the string)\nfor the number of substitution parameters in string (' + numSubstitutions + ' so far).');
   392 				alert('Error! Not enough function arguments (' + (arguments.length - 1) + ', excluding the string)\nfor the number of substitution parameters in string (' + numSubstitutions + ' so far).');
   393       }
   393 			}
   394       var param = arguments[numSubstitutions];
   394 			var param = arguments[numSubstitutions];
   395       var pad = '';
   395 			var pad = '';
   396              if (pPad && pPad.substr(0,1) == "'") pad = leftpart.substr(1,1);
   396  						if (pPad && pPad.substr(0,1) == "'") pad = leftpart.substr(1,1);
   397         else if (pPad) pad = pPad;
   397 				else if (pPad) pad = pPad;
   398       var justifyRight = true;
   398 			var justifyRight = true;
   399              if (pJustify && pJustify === "-") justifyRight = false;
   399  						if (pJustify && pJustify === "-") justifyRight = false;
   400       var minLength = -1;
   400 			var minLength = -1;
   401              if (pMinLength) minLength = parseInt(pMinLength);
   401  						if (pMinLength) minLength = parseInt(pMinLength);
   402       var precision = -1;
   402 			var precision = -1;
   403              if (pPrecision && pType == 'f') precision = parseInt(pPrecision.substring(1));
   403  						if (pPrecision && pType == 'f') precision = parseInt(pPrecision.substring(1));
   404       var subst = param;
   404 			var subst = param;
   405              if (pType == 'b') subst = parseInt(param).toString(2);
   405  						if (pType == 'b') subst = parseInt(param).toString(2);
   406         else if (pType == 'c') subst = String.fromCharCode(parseInt(param));
   406 				else if (pType == 'c') subst = String.fromCharCode(parseInt(param));
   407         else if (pType == 'd') subst = parseInt(param) ? parseInt(param) : 0;
   407 				else if (pType == 'd') subst = parseInt(param) ? parseInt(param) : 0;
   408         else if (pType == 'u') subst = Math.abs(param);
   408 				else if (pType == 'u') subst = Math.abs(param);
   409         else if (pType == 'f') subst = (precision > -1) ? Math.round(parseFloat(param) * Math.pow(10, precision)) / Math.pow(10, precision): parseFloat(param);
   409 				else if (pType == 'f') subst = (precision > -1) ? Math.round(parseFloat(param) * Math.pow(10, precision)) / Math.pow(10, precision): parseFloat(param);
   410         else if (pType == 'o') subst = parseInt(param).toString(8);
   410 				else if (pType == 'o') subst = parseInt(param).toString(8);
   411         else if (pType == 's') subst = param;
   411 				else if (pType == 's') subst = param;
   412         else if (pType == 'x') subst = ('' + parseInt(param).toString(16)).toLowerCase();
   412 				else if (pType == 'x') subst = ('' + parseInt(param).toString(16)).toLowerCase();
   413         else if (pType == 'X') subst = ('' + parseInt(param).toString(16)).toUpperCase();
   413 				else if (pType == 'X') subst = ('' + parseInt(param).toString(16)).toUpperCase();
   414     }
   414 		}
   415     str = leftpart + subst + rightPart;
   415 		str = leftpart + subst + rightPart;
   416   }
   416 	}
   417   return str;
   417 	return str;
   418 }
   418 }