/*Default Javascript*/
document.getElementsByClassName = function(cl) {
	var retnode = [];
	var myclass = new RegExp('\\b'+cl+'\\b');
	var elem = this.getElementsByTagName('*');
	for (var i = 0; i < elem.length; i++) {
		var classes = elem[i].className;
		if (myclass.test(classes)) retnode.push(elem[i]);
	}
	return retnode;
};

/*DRAG BOX*/

$(function(){
	$('.dragbox')
	.each(function(){
		$(this).hover(function(){
			$(this).find('h2').addClass('collapse');
		}, function(){
			$(this).find('h2').removeClass('collapse');
		})
		.find('h2').hover(function(){
			$(this).find('.configure').css('visibility', 'visible');
		}, function(){
			$(this).find('.configure').css('visibility', 'hidden');
		})
		.click(function(){
			//$(this).siblings('.dragbox-content').toggle();
		})
		.end()
		.find('.configure').css('visibility', 'hidden');
	});
	$('.dgbcolumn').sortable({
		connectWith: '.dgbcolumn',
		handle: 'h2',
		cursor: 'move',
		placeholder: 'placeholder',
		forcePlaceholderSize: true,
		opacity: 0.4,
		stop: function(event, ui){
			$(ui.item).find('h2').click();
			var sortorder='';
			$('.dgbcolumn').each(function(){
				var itemorder=$(this).sortable('toArray');
				var columnId=$(this).attr('rel');
				sortorder+="|"+columnId+'~'+itemorder.toString();
			});do_sort_order(sortorder);
		}
	})
	.disableSelection();
});

function clear_class(divid){document.getElementById(divid).setAttribute("class","");}
function set_style(divid,style){document.getElementById(divid).cssText=style;}
   
function do_sort_order(so){
	run("noticecontainer",document.getElementById('jxdx').value+"&_sdd="+so);
}

function fade_out(id) {$("#"+id).fadeOut().empty();}

function switch_divs(def,res){for(r in res){if(res[r]!=def){$("#"+res[r]).hide();}else{$("#"+res[r]).fadeIn("slow");}}}

function highlight_class(classi,h){
	var css=document.getElementsByClassName(String(classi));
	for (i=0;i<css.length;i++){
		var c=css[i];
		if(h=="un"){c.style.outline="";}else{c.style.outline="thick solid #990000";}
	}
}

function highlight_div(div,class){
	if(class==null){class='outlinediv';}
	if($('#'+div).hasClass(class)==true){$('#'+div).removeClass(class);}else{$('#'+div).addClass(class);}
}

function occ_div(divid,w,h,mess){	
	if(w==null)w=30;if(h==null)w=30;
	if(mess==''||mess==null){ihtm='<img src="img/loading.gif" border="0" align="center" valgin="center" width="'+w+'px" height="'+h+'px"/>';}
	else{ihtm='<img src="img/loading.gif" border="0" align="center" valgin="center" width="'+w+'px" height="'+h+'px"/><p>'+mess+'</p>';}
	document.getElementById(divid).innerHTML=ihtm;
}

function run(divid,encode,callback){
	exists=true;if(!document.getElementById(divid)||divid==''){exists=false}
	if(exists==true){occ_div(divid);}
	AjaxRequest.get(
	  {
		'url':'index.php?_ajx='+encode
		,'onSuccess':function(req){
						if(req.responseText=='##terminate##'){redirect('index.php?_v=default');}
						else{
							if(exists==true){
								document.getElementById(divid).innerHTML=req.responseText;
								setTimeout('fade_out(\'noticebox\')', 3000);
							}else{eval(callback+'('+req.responseText+');');}
						}
					 }
		,'onError':function(req){ alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
	  }
	);
	
}

function set_el_value(id,val){
	div=document.getElementById(id);
	div.value=val;
}

function switch_image(id,im1,im2){
	div=document.getElementById(id);
	idsr=div.src;
	if(idsr==im1){div.src=im2;}
	if(idsr==im2){div.src=im1;}
	if(idsr!=im1&&idsr!=im2){div.src=im1;}
}

function confirm_msg(message,url){var r=confirm(message);if(r==true){redirect(url);}else{return false;}}

function redirect(url){
	var browser_type=navigator.appName
	var browser_version=parseInt(navigator.appVersion)	
	
	if(browser_type=="Netscape"&&browser_version>=5){
		window.location.replace(url)
	}else if (browser_type=="Microsoft Internet Explorer"&&browser_version>=4){
		window.location.replace(url)
	}else if(browser_type=="Netscape"&&browser_version>=4){
		window.location.replace(url)
	}else{
		window.location=url
	}
}

function show_div(divid){
     ID = document.getElementById(divid);
     if(ID.style.display == ""){
		 	$('#'+divid).fadeOut();ID.style.display='hidden';
		}else{
			$('#'+divid).fadeIn();ID.style.display='';
		}
}

function display_div(divid){
	d = document.getElementById(divid);
	if(d.style.visibility=="hidden"){d.style.visibility = "visible";}else{d.style.visibility = "hidden";}
}


function show_aux(parent, child){
  var p = document.getElementById(parent);
  var c = document.getElementById(child );
  var top  = (c["at_position"] == "y") ? p.offsetHeight+1 : 0;
  var left = (c["at_position"] == "x") ? p.offsetWidth +1 : 0;
  for (; p; p = p.offsetParent){
    top  += p.offsetTop;
    left += p.offsetLeft;
  }
  c.style.position   = "absolute";
  c.style.top        = '180px';
  c.style.left       = left+'px';
  c.style.visibility = "visible";
}

function show_d(){
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);
  show_aux(p.id, c.id);
  clearTimeout(c["at_timeout"]);
}

function highlight(field) {
       field.focus();
       field.select();
}

function hide_d(){
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);
  c["at_timeout"] = setTimeout("document.getElementById('"+c.id+"').style.visibility = 'hidden'", 333);
}
function click_d(){
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);
  if (c.style.visibility != "visible") show_aux(p.id, c.id); else c.style.visibility = "hidden";
  return false;
}

// PARAMETERS:
// parent   - id of the parent html element
// child    - id of the child  html element that should be droped down
// showtype - "click" = drop down child html element on mouse click
//            "hover" = drop down child html element on mouse over
// position - "x" = display the child html element to the right
//            "y" = display the child html element below
// cursor   - omit to use default cursor or specify CSS cursor name
function attach_div(parent, child, showtype, position, cursor){
  var p = document.getElementById(parent);
  var c = document.getElementById(child);
  p["at_parent"]     = p.id;
  c["at_parent"]     = p.id;
  p["at_child"]      = c.id;
  c["at_child"]      = c.id;
  p["at_position"]   = "x";
  c["at_position"]   = "y";
  c.style.position   = "absolute";
  c.style.visibility = "hidden";
  if (cursor != undefined) p.style.cursor = cursor;
  switch (showtype){
    case "click":
      p.onclick     = click_d;
      p.onmouseout  = hide_d;
      c.onmouseover = show_d;
      //c.onmouseout  = hide_d;
      break;
    case "hover":
      p.onmouseover = show_d;
      p.onmouseout  = hide_d;
      c.onmouseover = show_d;
      c.onmouseout  = hide_d;
      break;
  }
}
//MODAL WINDOW
(function($) { 

	// static constructs
	$.tools = $.tools || {};
	
	$.tools.overlay = {
		
		version: '1.1.2',
		
		addEffect: function(name, loadFn, closeFn) {
			effects[name] = [loadFn, closeFn];	
		},
	
		conf: {  
			top: '10%', 
			left: 'center',
			absolute: false,
			
			speed: 'normal',
			closeSpeed: 'fast',
			effect: 'default',
			
			close: null,	
			oneInstance: true,
			closeOnClick: false,
			closeOnEsc: true, 
			api: false,
			expose: null,
			
			// target element to be overlayed. by default taken from [rel]
			target: null 
		}
	};

	
	var effects = {};
		
	// the default effect. nice and easy!
	$.tools.overlay.addEffect('default', 
		
		/* 
			onLoad/onClose functions must be called otherwise none of the 
			user supplied callback methods won't be called
		*/
		function(onLoad) { 
			this.getOverlay().fadeIn(this.getConf().speed, onLoad); 
			
		}, function(onClose) {
			this.getOverlay().fadeOut(this.getConf().closeSpeed, onClose); 			
		}		
	);
	
		
	var instances = [];		

	
	function Overlay(trigger, conf) {		
		
		// private variables
		var self = this, 
			 $self = $(this),
			 w = $(window), 
			 closers,
			 overlay,
			 opened,
			 expose = conf.expose && $.tools.expose.version;
		
		// get overlay and triggerr
		var jq = conf.target || trigger.attr("rel");
		overlay = jq ? $(jq) : null || trigger;	
		
		// overlay not found. cannot continue
		if (!overlay.length) { throw "Could not find Overlay: " + jq; }
		
		// if trigger is given - assign it's click event
		if (trigger && trigger.index(overlay) == -1) {
			trigger.click(function(e) {				
				self.load(e);
				return e.preventDefault();
			});
		}   			
		
		// bind all callbacks from configuration
		$.each(conf, function(name, fn) {
			if ($.isFunction(fn)) { $self.bind(name, fn); }
		});   
		
		
		// API methods  
		$.extend(self, {

			load: function(e) {
				
				// can be opened only once
				if (self.isOpened()) { return self; } 

				
				// find the effect
		 		var eff = effects[conf.effect];
		 		if (!eff) { throw "Overlay: cannot find effect : \"" + conf.effect + "\""; }
				
				// close other instances?
				if (conf.oneInstance) {
					$.each(instances, function() {
						this.close(e);
					});
				}
				
				// onBeforeLoad
				e = e || $.Event();
				e.type = "onBeforeLoad";
				$self.trigger(e);				
				if (e.isDefaultPrevented()) { return self; }				

				// opened
				opened = true;
				
				// possible expose effect
				if (expose) { overlay.expose().load(e); }				
				
				// calculate end position 
				var top = conf.top;					
				var left = conf.left;

				// get overlay dimensions
				var oWidth = overlay.outerWidth({margin:true});
				var oHeight = overlay.outerHeight({margin:true}); 
				
				if (typeof top == 'string')  {
					top = top == 'center' ? Math.max((w.height() - oHeight) / 2, 0) : 
						parseInt(top, 10) / 100 * w.height();			
				}				
				
				if (left == 'center') { left = Math.max((w.width() - oWidth) / 2, 0); }
				
				if (!conf.absolute)  {
					top += w.scrollTop();
					left += w.scrollLeft();
				} 
				
				// position overlay
				overlay.css({top: top, left: left, position: 'absolute'}); 
				
				// onStart
				e.type = "onStart";
				$self.trigger(e); 
				
		 		// load effect  		 		
				eff[0].call(self, function() {					
					if (opened) {
						e.type = "onLoad";
						$self.trigger(e);
					}
				}); 				
		
				// when window is clicked outside overlay, we close
				if (conf.closeOnClick) {					
					$(document).bind("click.overlay", function(e) { 
						if (!self.isOpened()) { return; }
						var et = $(e.target); 
						if (et.parents(overlay).length > 1) { return; }
						$.each(instances, function() {
							this.close(e);
						}); 
					});						
				}						
				
				// keyboard::escape
				if (conf.closeOnEsc) {
					
					// one callback is enough if multiple instances are loaded simultaneously
					$(document).unbind("keydown.overlay").bind("keydown.overlay", function(e) {
						if (e.keyCode == 27) {
							$.each(instances, function() {
								this.close(e);								
							});	 
						}
					});			
				}

				return self; 
			}, 
			
			close: function(e) {

				if (!self.isOpened()) { return self; }
				
				e = e || $.Event();
				e.type = "onBeforeClose";
				$self.trigger(e);				
				if (e.isDefaultPrevented()) { return; }				
				
				opened = false;
				
				// close effect
				effects[conf.effect][1].call(self, function() {
					e.type = "onClose";
					$self.trigger(e); 
				});
				
				// if all instances are closed then we unbind the keyboard / clicking actions
				var allClosed = true;
				$.each(instances, function() {
					if (this.isOpened()) { allClosed = false; }
				});				
				
				if (allClosed) {
					$(document).unbind("click.overlay").unbind("keydown.overlay");		
				}
				
							
				return self;
			}, 
			
			// @deprecated
			getContent: function() {
				return overlay;	
			}, 
			
			getOverlay: function() {
				return overlay;	
			},
			
			getTrigger: function() {
				return trigger;	
			},
			
			getClosers: function() {
				return closers;	
			},			

			isOpened: function()  {
				return opened;
			},
			
			// manipulate start, finish and speeds
			getConf: function() {
				return conf;	
			},

			// bind
			bind: function(name, fn) {
				$self.bind(name, fn);
				return self;	
			},		
			
			// unbind
			unbind: function(name) {
				$self.unbind(name);
				return self;	
			}			
			
		});
		
		// callbacks	
		$.each("onBeforeLoad,onStart,onLoad,onBeforeClose,onClose".split(","), function(i, ev) {
			self[ev] = function(fn) {
				return self.bind(ev, fn);	
			};
		});
		
		
		// exposing effect
		if (expose) {
			
			// expose configuration
			if (typeof conf.expose == 'string') { conf.expose = {color: conf.expose}; }
						
			$.extend(conf.expose, {
				api: true,
				closeOnClick: conf.closeOnClick,
				
				// only overlay control's the esc button
				closeOnEsc: false
			});
			
			// initialize expose api
			var ex = overlay.expose(conf.expose);
			
			ex.onBeforeClose(function(e) {
				self.close(e);		
			});
			
			self.onClose(function(e) {
				ex.close(e);		
			});
		}		
		
		// close button
		closers = overlay.find(conf.close || ".close");		
		
		if (!closers.length && !conf.close) {
			closers = $('<div class="close"></div>');
			overlay.prepend(closers);	
		}		
		
		closers.click(function(e) { 
			self.close(e);  
		});					
	}
	
	// jQuery plugin initialization
	$.fn.overlay = function(conf) {   
		
		// already constructed --> return API
		var el = this.eq(typeof conf == 'number' ? conf : 0).data("overlay");
		if (el) { return el; }	  		 
		
		if ($.isFunction(conf)) {
			conf = {onBeforeLoad: conf};	
		}
		
		var globals = $.extend({}, $.tools.overlay.conf); 
		conf = $.extend(true, globals, conf);
		
		this.each(function() {		
			el = new Overlay($(this), conf);
			instances.push(el);
			$(this).data("overlay", el);	
		});
		
		return conf.api ? el: this;		
	}; 
	
})(jQuery);

(function($) { 	

	// static constructs
	$.tools = $.tools || {};
	
	$.tools.expose = {
		version: '1.0.5',  
		conf: {	

			// mask settings
			maskId: null,
			loadSpeed: 'slow',
			closeSpeed: 'fast',
			closeOnClick: true,
			closeOnEsc: true,
			
			// css settings
			zIndex: 9998,
			opacity: 0.8,
			color: '#456',
			api: false
		}
	};

	/* one of the greatest headaches in the tool. finally made it */
	function viewport() {
				
		// the horror case
		if ($.browser.msie) {
			
			// if there are no scrollbars then use window.height
			var d = $(document).height(), w = $(window).height();
			
			return [
				window.innerWidth || 							// ie7+
				document.documentElement.clientWidth || 	// ie6  
				document.body.clientWidth, 					// ie6 quirks mode
				d - w < 20 ? w : d
			];
		} 
		
		// other well behaving browsers
		return [$(window).width(), $(document).height()];
		
	} 
	
	function Expose(els, conf) { 
		
		// private variables
		var self = this, $self = $(this), mask = null, loaded = false, origIndex = 0;		
		
		// bind all callbacks from configuration
		$.each(conf, function(name, fn) {
			if ($.isFunction(fn)) { $self.bind(name, fn); }
		});	 

		// adjust mask size when window is resized (or firebug is toggled)
		$(window).resize(function() {
			self.fit();
		}); 
		
		
		// public methods
		$.extend(this, {
		
			getMask: function() {
				return mask;	
			},
			
			getExposed: function() {
				return els;	
			},
			
			getConf: function() {
				return conf;	
			},		
			
			isLoaded: function() {
				return loaded;	
			},
			
			load: function(e) { 
				
				// already loaded ?
				if (loaded) { return self;	}
	
				origIndex = els.eq(0).css("zIndex"); 				
				
				// find existing mask
				if (conf.maskId) { mask = $("#" + conf.maskId);	}
					
				if (!mask || !mask.length) {
					
					var size = viewport();
					
					mask = $('<div/>').css({				
						position:'absolute', 
						top:0, 
						left:0,
						width: size[0],
						height: size[1],
						display:'none',
						opacity: 0,					 		
						zIndex:conf.zIndex	
					});						
					
					// id
					if (conf.maskId) { mask.attr("id", conf.maskId); }					
					
					$("body").append(mask);	
					
					
					// background color 
					var bg = mask.css("backgroundColor");
					
					if (!bg || bg == 'transparent' || bg == 'rgba(0, 0, 0, 0)') {
						mask.css("backgroundColor", conf.color);	
					}   
					
					// esc button
					if (conf.closeOnEsc) {						
						$(document).bind("keydown.unexpose", function(evt) {							
							if (evt.keyCode == 27) {
								self.close();	
							}		
						});			
					}
					
					// mask click closes
					if (conf.closeOnClick) {
						mask.bind("click.unexpose", function(e)  {
							self.close(e);		
						});					
					}					
				}				
				
				// possibility to cancel click action
				e = e || $.Event();
				e.type = "onBeforeLoad";
				$self.trigger(e);			
				
				if (e.isDefaultPrevented()) { return self; }
				
				// make sure element is positioned absolutely or relatively
				$.each(els, function() {
					var el = $(this);
					if (!/relative|absolute|fixed/i.test(el.css("position"))) {
						el.css("position", "relative");		
					}					
				});
			 
				// make elements sit on top of the mask				
				els.css({zIndex:Math.max(conf.zIndex + 1, origIndex == 'auto' ? 0 : origIndex)});				

				
				// reveal mask
				var h = mask.height();
				
				if (!this.isLoaded()) { 
					
					mask.css({opacity: 0, display: 'block'}).fadeTo(conf.loadSpeed, conf.opacity, function() {

						// sometimes IE6 misses the height property on fadeTo method
						if (mask.height() != h) { mask.css("height", h); }
						e.type = "onLoad";						
						$self.trigger(e);	
						 
					});					
				}
					
				loaded = true;
				
				return self;
			}, 
			
			
			close: function(e) {
								
				if (!loaded) { return self; }   

				e = e || $.Event();
				e.type = "onBeforeClose";
				$self.trigger(e);				
				if (e.isDefaultPrevented()) { return self; }
				
				mask.fadeOut(conf.closeSpeed, function() {
					e.type = "onClose";
					$self.trigger(e);
					els.css({zIndex: $.browser.msie ? origIndex : null});
				});        										
				
				loaded = false;
				return self; 
			},
			
			fit: function() {
				if (mask) {
					var size = viewport();				
					mask.css({ width: size[0], height: size[1]});
				}	
			},
			
			bind: function(name, fn) {
				$self.bind(name, fn);
				return self;	
			},			
			
			unbind: function(name) {
				$self.unbind(name);
				return self;	
			}				
			
		});		
		
		// callbacks	
		$.each("onBeforeLoad,onLoad,onBeforeClose,onClose".split(","), function(i, ev) {
			self[ev] = function(fn) {
				return self.bind(ev, fn);	
			};
		});			

	}
	
	
	// jQuery plugin implementation
	$.fn.expose = function(conf) {
		
		var el = this.eq(typeof conf == 'number' ? conf : 0).data("expose");
		if (el) { return el; }
		
		if (typeof conf == 'string') {
			conf = {color: conf};
		}
		
		var globals = $.extend({}, $.tools.expose.conf);
		conf = $.extend(globals, conf);		

		// construct exposes
		this.each(function() {
			el = new Expose($(this), conf);
			$(this).data("expose", el);	 
		});		
		
		return conf.api ? el: this;		
	};		


})(jQuery);


function foverlay(id) {
	$('#'+id).overlay().load();
}

function encodeurl (str) {
	str = escape(str);
	return str.replace(/[*+\/@#]|%20/g,
		function (s) {
			switch (s) {
				case "*": s = "%2A"; break;
				case "+": s = "%2B"; break;
				case "/": s = "%2F"; break;
				case "@": s = "%40"; break;
				case "%20": s = "+"; break;
				case "#": s = "%23"; break;
			}
			return s;
		}
	);
}

(function($){                               // anonymous function wrapper

    $.fn.extend({                           // attach new method to jQuery
    
        scale: function( arg1, arg2 ){// declare plugin name and parameter
        
            // iterate over current set of matched elements
            return this.each( function() {
                safelog( "jquery.scale is starting...");
                
                safelog( "jquery.scale: Using browser \"" + navigator.appName +
                    "\" version \"" + navigator.appVersion + "\"");
            
                // capture the object
                var obj = $(this);
                
                // if this is the plugin's first run on the object, and the
                // object is an image, force a reload
                if( obj.attr('src') && 
                    !obj.attr('jquery.scale_orig-height') ){
                    
                    safelog( "jquery.scale: object is an image" );
                    var date = new Date();
                    var cursrc = obj.attr("src");
                    var newsrc = cursrc;
                    if( cursrc.indexOf('?') != -1 )
                        newsrc = cursrc.substring( 0, cursrc.indexOf('?'));
                    newsrc = newsrc + "?" + date.getTime();
                    obj.attr( "src", newsrc );
                    safelog( "jquery.scale: img src changed to " + newsrc + 
                        " to force a reload");
                    this.onload = scale;
                    
                } else {
                    safelog("jquery.scale: object is NOT an image");
                    scale();
                }
                
                // plugin's main function
                function scale(){

                    // if this is the plugin's first run on the object, capture
                    // the object's original dimensions
                    if( !obj.attr('jquery.scale_orig-height') ){
                        obj.attr('jquery.scale_orig-height', obj.height() );
                        obj.attr('jquery.scale_orig-width', obj.width() );
                        
                        safelog( "jquery.scale: is starting for the first " + 
                            "time. Captured the original dimensions of " + 
                            obj.width() + "x" + obj.height() );
                    
                    // if this is NOT the plugin's first run on the object,
                    // reset the object's dimensions
                    } else {           
                        obj.height( parseInt( 
                            obj.attr('jquery.scale_orig-height') ) );
                        obj.width( parseInt( 
                            obj.attr('jquery.scale_orig-width') ) );
                        
                        safelog( "jquery.scale: has been run before. Reset " +
                            "the object to its original dimensions of " + 
                            obj.width() + "x" + obj.height() );
                    }

                    safelog( "jquery.scale: BEFORE scaling, object's outer " +
                        "size = " + obj.outerWidth() + "x" + 
                        obj.outerHeight() + ", object's parent's inner size " +
                        "= " + obj.parent().innerWidth() + "x" + 
                        obj.parent().innerHeight() );
                    
                    // Object too tall, but width is fine. Need to shorten.
                    if( obj.outerHeight() > obj.parent().innerHeight() && 
                        obj.outerWidth() <= obj.parent().innerWidth() ){

                        safelog( "jquery.scale: object is too tall, but width" +
                            " is OK" );
                        matchHeight();       
                    }
                    
                    // Object too wide, but height is fine. Need to diet.
                    else if( obj.outerWidth() > obj.parent().innerWidth() && 
                             obj.outerHeight() <= obj.parent().innerHeight() ){

                        safelog( "jquery.scale: object is too wide, but " +
                            "height is OK" );
                        matchWidth();    
                    }
                    
                    // Object too short and skinny. If "stretch" option enabled,
                    // match the dimenstion that is closer to being correct.
                    else if( obj.outerWidth() < obj.parent().innerWidth() && 
                             obj.outerHeight() < obj.parent().innerHeight() &&
                             (arg1 == "stretch" || arg2 == "stretch" ) ){
                      
                        safelog( "jquery.scale: object is too short and " +
                            "skinny, and stretch option enabled" );
                        if( obj.parent().innerHeight()/obj.outerHeight() <= 
                            obj.parent().innerWidth()/obj.outerWidth() ){
                            
                            safelog( "jquery.scale: height is closer to " +
                                "being correct, or height and width are " +
                                "equally close to being correct");
                            matchHeight();
                            
                        } else {
                            safelog( "jquery.scale: width is closer to being " +
                                "correct");
                            matchWidth();
                        }
                    
                    // Object too tall and wide. Need to match the dimension 
                    // that is further from being correct.
                    } else if( obj.outerWidth() > obj.parent().innerWidth() && 
                               obj.outerHeight() > obj.parent().innerHeight() ){
                               
                        safelog( "jquery.scale: object is too tall and wide");
                        if( obj.parent().innerHeight()/obj.outerHeight() >
                            obj.parent().innerWidth()/obj.outerWidth() ){
                            
                            safelog( "jquery.scale: width is closer to being " +
                                "correct");
                            matchWidth();
                            
                        } else {
                            safelog( "jquery.scale: height is closer to " +
                                "being correct, or height and width are " +
                                "equally close to being correct");
                            matchHeight();
                        }                            

                    }//else, object is the same size as the parent. Do nothing.

                    // if the center option is enabled, also center the object 
                    // within the parent
                    if( arg1 == "center" || arg2 == "center" ){
                        safelog( "jquery.scale: centering option enabled" );
                        obj.css( 'position', 'relative' );
                        obj.css( 'margin-top', 
                             obj.parent().innerHeight()/2 - 
                                        obj.outerHeight()/2  );
                        obj.css( 'margin-left', 
                             obj.parent().innerWidth()/2 - 
                                        obj.outerWidth()/2  );
                    }

                    // reset the onload pointer so the object doesn't flicker
                    // when reloaded other ways.
                    this.onload = null;

                    safelog( "jquery.scale: AFTER scaling, object's size = " +
                        obj.outerWidth() + "x" + obj.outerHeight() + 
                        ", object's parent's size = " + 
                        obj.parent().innerWidth() + "x" + 
                        obj.parent().innerHeight() + ".'" );                    
                
                }   //END scale
                
                // match the height while maintaining the aspect ratio
                function matchHeight(){
                    safelog( "jquery.scale: matching height" );
                    obj.width( obj.outerWidth() * 
                        obj.parent().innerHeight()/obj.outerHeight() - 
                        (obj.outerWidth() - obj.width()));
                    obj.height( obj.parent().innerHeight() - 
                        (obj.outerHeight() - obj.height()) );
                }
                
                // match the width while maintaining the aspect ratio
                function matchWidth(){
                    safelog( "jquery.scale: matching width" );
                    obj.height(  obj.outerHeight() * 
                        obj.parent().innerWidth()/obj.outerWidth() - 
                        (obj.outerHeight() - obj.height())  );
                    obj.width( obj.parent().width() - 
                        (obj.outerWidth() - obj.width()));
                }
                
                // a function to safely log
                function safelog( msg ){ 
                    if( window.console ) console.log( msg );
                }
                            
            });     //END matched element iterations
        }           //END plugin declaration
    });             //END new jQuery method attachment
})(jQuery);         //END anonymous function wrapper

$(document).ready(function(){

	// scale the example objects
	$(".ex_no-opts").scale();
	$(".ex_center").scale("center");
	$(".ex_stretch").scale("stretch");
	$(".ex_center-stretch").scale("center", "stretch");
});


function show_upload_form(dest){
	uploadfom.setData({'dest': dest});
	foverlay('fileuploadscreen');
}


function do_upload_form(rd){
	var upbutton = new AjaxUpload('upload_button',{
		action: 'index.php?_ajx='+rd,
		name: 'files',
		onSubmit : 	function(file, ext){
  						occ_div('uploadnoticebox',100,100,'Uploading "'+file+'" ...');
						this.disable();
					},
		onChange: function(file, extension){
						
				  },
		onComplete: function(file, response){
						document.getElementById('uploadnoticebox').innerHTML=response;
						$('<li></li>').appendTo('#fileuploadform .uploadfilelist').text(file+' uploaded...');
						this.enable();
					}
	});return upbutton;
}

$.expr[":"].containsNoCase = function(el, i, m) {
    var search = m[3];
    if (!search) return false;
    return eval("/" + search + "/i").test($(el).text());
};

/*---------------*/
/*
 * jQuery UI Accordion 1.6
 * 
 * Copyright (c) 2007 Jörn Zaefferer
 *
 * http://docs.jquery.com/UI/Accordion
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 * Revision: $Id: jquery.accordion.js 4876 2008-03-08 11:49:04Z joern.zaefferer $
 *
 */

;(function($) {
	
// If the UI scope is not available, add it
$.ui = $.ui || {};

$.fn.extend({
	accordion: function(options, data) {
		var args = Array.prototype.slice.call(arguments, 1);

		return this.each(function() {
			if (typeof options == "string") {
				var accordion = $.data(this, "ui-accordion");
				accordion[options].apply(accordion, args);
			// INIT with optional options
			} else if (!$(this).is(".ui-accordion"))
				$.data(this, "ui-accordion", new $.ui.accordion(this, options));
		});
	},
	// deprecated, use accordion("activate", index) instead
	activate: function(index) {
		return this.accordion("activate", index);
	}
});

$.ui.accordion = function(container, options) {
	
	// setup configuration
	this.options = options = $.extend({}, $.ui.accordion.defaults, options);
	this.element = container;
	
	$(container).addClass("ui-accordion");
	
	if ( options.navigation ) {
		var current = $(container).find("a").filter(options.navigationFilter);
		if ( current.length ) {
			if ( current.filter(options.header).length ) {
				options.active = current;
			} else {
				options.active = current.parent().parent().prev();
				current.addClass("current");
			}
		}
	}
	
	// calculate active if not specified, using the first header
	options.headers = $(container).find(options.header);
	options.active = findActive(options.headers, options.active);

	if ( options.fillSpace ) {
		var maxHeight = $(container).parent().height();
		options.headers.each(function() {
			maxHeight -= $(this).outerHeight();
		});
		var maxPadding = 0;
		options.headers.next().each(function() {
			maxPadding = Math.max(maxPadding, $(this).innerHeight() - $(this).height());
		}).height(maxHeight - maxPadding);
	} else if ( options.autoheight ) {
		var maxHeight = 0;
		options.headers.next().each(function() {
			maxHeight = Math.max(maxHeight, $(this).outerHeight());
		}).height(maxHeight);
	}

	options.headers
		.not(options.active || "")
		.next()
		.hide();
	options.active.parent().andSelf().addClass(options.selectedClass);
	
	if (options.event)
		$(container).bind((options.event) + ".ui-accordion", clickHandler);
};

$.ui.accordion.prototype = {
	activate: function(index) {
		// call clickHandler with custom event
		clickHandler.call(this.element, {
			target: findActive( this.options.headers, index )[0]
		});
	},
	
	enable: function() {
		this.options.disabled = false;
	},
	disable: function() {
		this.options.disabled = true;
	},
	destroy: function() {
		this.options.headers.next().css("display", "");
		if ( this.options.fillSpace || this.options.autoheight ) {
			this.options.headers.next().css("height", "");
		}
		$.removeData(this.element, "ui-accordion");
		$(this.element).removeClass("ui-accordion").unbind(".ui-accordion");
	}
}

function scopeCallback(callback, scope) {
	return function() {
		return callback.apply(scope, arguments);
	};
}

function completed(cancel) {
	// if removed while animated data can be empty
	if (!$.data(this, "ui-accordion"))
		return;
	var instance = $.data(this, "ui-accordion");
	var options = instance.options;
	options.running = cancel ? 0 : --options.running;
	if ( options.running )
		return;
	if ( options.clearStyle ) {
		options.toShow.add(options.toHide).css({
			height: "",
			overflow: ""
		});
	}
	$(this).triggerHandler("change.ui-accordion", [options.data], options.change);
}

function toggle(toShow, toHide, data, clickedActive, down) {
	var options = $.data(this, "ui-accordion").options;
	options.toShow = toShow;
	options.toHide = toHide;
	options.data = data;
	var complete = scopeCallback(completed, this);
	
	// count elements to animate
	options.running = toHide.size() == 0 ? toShow.size() : toHide.size();
	
	if ( options.animated ) {
		if ( !options.alwaysOpen && clickedActive ) {
			$.ui.accordion.animations[options.animated]({
				toShow: jQuery([]),
				toHide: toHide,
				complete: complete,
				down: down,
				autoheight: options.autoheight
			});
		} else {
			$.ui.accordion.animations[options.animated]({
				toShow: toShow,
				toHide: toHide,
				complete: complete,
				down: down,
				autoheight: options.autoheight
			});
		}
	} else {
		if ( !options.alwaysOpen && clickedActive ) {
			toShow.toggle();
		} else {
			toHide.hide();
			toShow.show();
		}
		complete(true);
	}
}

function clickHandler(event) {
	var options = $.data(this, "ui-accordion").options;
	if (options.disabled)
		return false;
	
	// called only when using activate(false) to close all parts programmatically
	if ( !event.target && !options.alwaysOpen ) {
		options.active.parent().andSelf().toggleClass(options.selectedClass);
		var toHide = options.active.next(),
			data = {
				instance: this,
				options: options,
				newHeader: jQuery([]),
				oldHeader: options.active,
				newContent: jQuery([]),
				oldContent: toHide
			},
			toShow = options.active = $([]);
		toggle.call(this, toShow, toHide, data );
		return false;
	}
	// get the click target
	var clicked = $(event.target);
	
	// due to the event delegation model, we have to check if one
	// of the parent elements is our actual header, and find that
	if ( clicked.parents(options.header).length )
		while ( !clicked.is(options.header) )
			clicked = clicked.parent();
	
	var clickedActive = clicked[0] == options.active[0];
	
	// if animations are still active, or the active header is the target, ignore click
	if (options.running || (options.alwaysOpen && clickedActive))
		return false;
	if (!clicked.is(options.header))
		return;

	// switch classes
	options.active.parent().andSelf().toggleClass(options.selectedClass);
	if ( !clickedActive ) {
		clicked.parent().andSelf().addClass(options.selectedClass);
	}

	// find elements to show and hide
	var toShow = clicked.next(),
		toHide = options.active.next(),
		//data = [clicked, options.active, toShow, toHide],
		data = {
			instance: this,
			options: options,
			newHeader: clicked,
			oldHeader: options.active,
			newContent: toShow,
			oldContent: toHide
		},
		down = options.headers.index( options.active[0] ) > options.headers.index( clicked[0] );
	
	options.active = clickedActive ? $([]) : clicked;
	toggle.call(this, toShow, toHide, data, clickedActive, down );

	return false;
};

function findActive(headers, selector) {
	return selector != undefined
		? typeof selector == "number"
			? headers.filter(":eq(" + selector + ")")
			: headers.not(headers.not(selector))
		: selector === false
			? $([])
			: headers.filter(":eq(0)");
}

$.extend($.ui.accordion, {
	defaults: {
		selectedClass: "selected",
		alwaysOpen: true,
		animated: 'slide',
		event: "click",
		header: "a",
		autoheight: true,
		running: 0,
		navigationFilter: function() {
			return this.href.toLowerCase() == location.href.toLowerCase();
		}
	},
	animations: {
		slide: function(options, additions) {
			options = $.extend({
				easing: "swing",
				duration: 300
			}, options, additions);
			if ( !options.toHide.size() ) {
				options.toShow.animate({height: "show"}, options);
				return;
			}
			var hideHeight = options.toHide.height(),
				showHeight = options.toShow.height(),
				difference = showHeight / hideHeight;
			options.toShow.css({ height: 0, overflow: 'hidden' }).show();
			options.toHide.filter(":hidden").each(options.complete).end().filter(":visible").animate({height:"hide"},{
				step: function(now) {
					var current = (hideHeight - now) * difference;
					if ($.browser.msie || $.browser.opera) {
						current = Math.ceil(current);
					}
					options.toShow.height( current );
				},
				duration: options.duration,
				easing: options.easing,
				complete: function() {
					if ( !options.autoheight ) {
						options.toShow.css("height", "auto");
					}
					options.complete();
				}
			});
		},
		bounceslide: function(options) {
			this.slide(options, {
				easing: options.down ? "bounceout" : "swing",
				duration: options.down ? 1000 : 200
			});
		},
		easeslide: function(options) {
			this.slide(options, {
				easing: "easeinout",
				duration: 700
			})
		}
	}
});

})(jQuery);
(function($) {
 
  $.fn.jclock = function(options) {
    var version = '2.3.0';
 
    // options
    var opts = $.extend({}, $.fn.jclock.defaults, options);
         
    return this.each(function() {
      $this = $(this);
      $this.timerID = null;
      $this.running = false;
 
      // Record keeping for seeded clock
      $this.increment = 0;
      $this.lastCalled = new Date().getTime();
 
      var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
 
      $this.format = o.format;
      $this.utc = o.utc;
      // deprecate utc_offset (v 2.2.0)
      $this.utcOffset = (o.utc_offset != null) ? o.utc_offset : o.utcOffset;
      $this.seedTime = o.seedTime;
      $this.timeout = o.timeout;
 
      $this.css({
        fontFamily: o.fontFamily,
        fontSize: o.fontSize,
        backgroundColor: o.background,
        color: o.foreground
      });
 
      // %a
      $this.daysAbbrvNames = new Array(7);
      $this.daysAbbrvNames[0] = "Sun";
      $this.daysAbbrvNames[1] = "Mon";
      $this.daysAbbrvNames[2] = "Tue";
      $this.daysAbbrvNames[3] = "Wed";
      $this.daysAbbrvNames[4] = "Thu";
      $this.daysAbbrvNames[5] = "Fri";
      $this.daysAbbrvNames[6] = "Sat";
 
      // %A
      $this.daysFullNames = new Array(7);
      $this.daysFullNames[0] = "Sunday";
      $this.daysFullNames[1] = "Monday";
      $this.daysFullNames[2] = "Tuesday";
      $this.daysFullNames[3] = "Wednesday";
      $this.daysFullNames[4] = "Thursday";
      $this.daysFullNames[5] = "Friday";
      $this.daysFullNames[6] = "Saturday";
 
      // %b
      $this.monthsAbbrvNames = new Array(12);
      $this.monthsAbbrvNames[0] = "Jan";
      $this.monthsAbbrvNames[1] = "Feb";
      $this.monthsAbbrvNames[2] = "Mar";
      $this.monthsAbbrvNames[3] = "Apr";
      $this.monthsAbbrvNames[4] = "May";
      $this.monthsAbbrvNames[5] = "Jun";
      $this.monthsAbbrvNames[6] = "Jul";
      $this.monthsAbbrvNames[7] = "Aug";
      $this.monthsAbbrvNames[8] = "Sep";
      $this.monthsAbbrvNames[9] = "Oct";
      $this.monthsAbbrvNames[10] = "Nov";
      $this.monthsAbbrvNames[11] = "Dec";
 
      // %B
      $this.monthsFullNames = new Array(12);
      $this.monthsFullNames[0] = "January";
      $this.monthsFullNames[1] = "February";
      $this.monthsFullNames[2] = "March";
      $this.monthsFullNames[3] = "April";
      $this.monthsFullNames[4] = "May";
      $this.monthsFullNames[5] = "June";
      $this.monthsFullNames[6] = "July";
      $this.monthsFullNames[7] = "August";
      $this.monthsFullNames[8] = "September";
      $this.monthsFullNames[9] = "October";
      $this.monthsFullNames[10] = "November";
      $this.monthsFullNames[11] = "December";
 
      $.fn.jclock.startClock($this);
 
    });
  };
       
  $.fn.jclock.startClock = function(el) {
    $.fn.jclock.stopClock(el);
    $.fn.jclock.displayTime(el);
  }
 
  $.fn.jclock.stopClock = function(el) {
    if(el.running) {
      clearTimeout(el.timerID);
    }
    el.running = false;
  }
 
  $.fn.jclock.displayTime = function(el) {
    var time = $.fn.jclock.getTime(el);
    el.html(time);
    el.timerID = setTimeout(function(){$.fn.jclock.displayTime(el)},el.timeout);
  }
 
  $.fn.jclock.getTime = function(el) {
    if(typeof(el.seedTime) == 'undefined') {
      // Seed time not being used, use current time
      var now = new Date();
    } else {
      // Otherwise, use seed time with increment
      el.increment += new Date().getTime() - el.lastCalled;
      var now = new Date(el.seedTime + el.increment);
      el.lastCalled = new Date().getTime();
    }
 
    if(el.utc == true) {
      var localTime = now.getTime();
      var localOffset = now.getTimezoneOffset() * 60000;
      var utc = localTime + localOffset;
      var utcTime = utc + (3600000 * el.utcOffset);
      now = new Date(utcTime);
    }
 
    var timeNow = "";
    var i = 0;
    var index = 0;
    while ((index = el.format.indexOf("%", i)) != -1) {
      timeNow += el.format.substring(i, index);
      index++;
 
      // modifier flag
      //switch (el.format.charAt(index++)) {
      //}
      
      var property = $.fn.jclock.getProperty(now, el, el.format.charAt(index));
      index++;
      
      //switch (switchCase) {
      //}
 
      timeNow += property;
      i = index
    }
 
    timeNow += el.format.substring(i);
    return timeNow;
  };
 
  $.fn.jclock.getProperty = function(dateObject, el, property) {
 
    switch (property) {
      case "a": // abbrv day names
          return (el.daysAbbrvNames[dateObject.getDay()]);
      case "A": // full day names
          return (el.daysFullNames[dateObject.getDay()]);
      case "b": // abbrv month names
          return (el.monthsAbbrvNames[dateObject.getMonth()]);
      case "B": // full month names
          return (el.monthsFullNames[dateObject.getMonth()]);
      case "d": // day 01-31
          return ((dateObject.getDate() < 10) ? "0" : "") + dateObject.getDate();
      case "H": // hour as a decimal number using a 24-hour clock (range 00 to 23)
          return ((dateObject.getHours() < 10) ? "0" : "") + dateObject.getHours();
      case "I": // hour as a decimal number using a 12-hour clock (range 01 to 12)
          var hours = (dateObject.getHours() % 12 || 12);
          return ((hours < 10) ? "0" : "") + hours;
      case "m": // month number
          return (((dateObject.getMonth() + 1) < 10) ? "0" : "") + (dateObject.getMonth() + 1);
      case "M": // minute as a decimal number
          return ((dateObject.getMinutes() < 10) ? "0" : "") + dateObject.getMinutes();
      case "p": // either `am' or `pm' according to the given time value,
          // or the corresponding strings for the current locale
          return (dateObject.getHours() < 12 ? "am" : "pm");
      case "P": // either `AM' or `PM' according to the given time value,
          return (dateObject.getHours() < 12 ? "AM" : "PM");
      case "S": // second as a decimal number
          return ((dateObject.getSeconds() < 10) ? "0" : "") + dateObject.getSeconds();
      case "y": // two-digit year
          return dateObject.getFullYear().toString().substring(2);
      case "Y": // full year
          return (dateObject.getFullYear());
      case "%":
          return "%";
    }
 
  }
       
  // plugin defaults (24-hour)
  $.fn.jclock.defaults = {
    format: '%H:%M:%S',
    utcOffset: 0,
    utc: false,
    fontFamily: '',
    fontSize: '',
    foreground: '',
    background: '',
    seedTime: undefined,
    timeout: 1000 // 1000 = one second, 60000 = one minute
  };
 
})(jQuery);
