/*
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
API CONFIRGURATION
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*/
function $INIT() { with (DCO) { with (p)
{
	if (DCO.PG_IS_WINDOW) return;
	else
	{
		p.BODY		= $C('body','table')[0];
		p.SBOX		= $E('SBOX');
		p.SBUTTON	= $E('SBUTTON');
		p.LOCK		= $E('PG_LOCK');
		
		
		/*
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		Start([int delay])
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		*/
		p.Start=function(delay) { with (this)
		{
			if (delay)
			{
				setTimeout("p.Start()",delay);
				return;
			}
			
			
			/*
			IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
			DATE PICKER
			IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
			*/
			Date.format = 'mm/dd/yyyy';
			
			var cal;
			var $this;
			
			var checkForMouseout = function(event)
			{
				var el=event.target;
				
				while (true)
				{
					if (el == cal) return true;
					else if (el == document) {o=$this;setTimeout("o.dpClose()",300);return false}
					else el = $(el).parent()[0];
				}
			};
			
			$('input.date-pick').datePicker(
				{
					clickInput			: true,
					startDate			: '01/1970',
					createButton		: false,
					verticalOffset		: 0,
					horizontalOffset	: -3
				})
				.bind(
					'dpDisplayed',
					function(event,datePickerDiv)
					{
						cal		= datePickerDiv;
						$this	= $(this);
						
						$(document).bind('mouseover',checkForMouseout)
					}
				).bind(
					'dpClosed',
					function(event,selected)
					{
						$(document).unbind('mouseover',checkForMouseout)
					}
				);
			
			$('#start-date').bind(
				'dpClosed',
				function(e, selectedDates)
				{
					var d = selectedDates[0];
					if (d) {
						d = new Date(d);
						$('#end-date').dpSetStartDate(d.addDays(1).asString());
					}
				}
			);
			$('#end-date').bind(
				'dpClosed',
				function(e, selectedDates)
				{
					var d = selectedDates[0];
					if (d) {
						d = new Date(d);
						$('#start-date').dpSetEndDate(d.addDays(-1).asString());
					}
				}
			);
		}
		};
		
		
		/*
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		PAGE LOCK
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		*/
		LOCK.opened	= false;
		LOCK.guide	= BODY;
		LOCK.oxy	= [23,0];
		
		LOCK.Repos=function() { with (this)
		{
			var xy=getPos(this.guide);
			setPos(this,xy[0]+oxy[0],xy[1]+oxy[1]);
		}
		};
		
		LOCK.Open=function() { with (this)
		{
			if (opened) return;
			else
			{
				var size=getSize(guide);
				setSize(this,null,size[1]);
				
				Repos();
				setVis(this,true,true,85);
				opened=true
			}
		}
		};
		
		LOCK.Hide=function() { with (this)
		{
			if (!opened) return;
			else
			{
				setVis(this,false,true,0);
				opened=false
			}
		}
		};
		
		LOCK.OnResize=function() { with (this)
		{
			if (opened) Repos();
		}
		};
		
		
		/*
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		SEARCH BOX
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		*/
		SBUTTON.onclick=function() { with (p)
		{
			SBOX.opened ? SBOX.Hide() : SBOX.Open()
		}
		};
		
		SBOX.guide		= BODY;
		SBOX.inside		= SBOX.getElementsByTagName('td')[0];
		SBOX.opened		= false;
		SBOX.oxy		= DCO.WE_ARE_HOME ? [30,8] : [281,100];
		SBOX.dd			= $C('dd','input',SBOX);
		SBOX.hiddens	= $C('x-hidden','input',SBOX);
		SBOX.menu		= $C('SBOX_MENU','div');
		SBOX.eraser		= $E('SBOX_ERASER');
		SBOX.closer		= $E('SBOX_CLOSER');
		SBOX.form		= SBOX.getElementsByTagName('form')[0];
		SBOX.b			= $C('x-pointer','img',SBOX);
		SBOX.OnResize	= function(){with(this)if(opened)Repos()};
		
		SBOX.Repos=function() { with (this)
		{
			var xy=getPos(this.guide);
			setPos(this,xy[0]+oxy[0],xy[1]+oxy[1])
		}
		};
		
		SBOX.Open=function() { with (this)
		{
			if (opened) return;
			else
			{
				Repos();
				
				if (!DCO.WE_ARE_HOME)
				{
					p.LOCK.Open();
					closer.Open();
				}
				
				setVis(this,true);
				opened=true;
				
				form.Unlock(1000)
			}
		}
		};
		
		SBOX.Hide=function() { with (this)
		{
			if (!opened) return;
			else
			{
				if (!DCO.WE_ARE_HOME)
				{
					p.LOCK.Hide();
					closer.Hide();
				}
				
				setVis(this,false);
				opened=false
			}
		}
		};
		
		
		/*
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		FORM
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		*/
		with (SBOX)
		{
			form.Lock=function() { with (this)
			{
				parentNode.className='locked';
				parentNode.closer.Hide()
			}
			};
			
			form.Unlock=function(delay) { with (this)
			{
				if (delay)
				{
					setTimeout("p.SBOX.form.Unlock()",1000);
					return
				}
				
				parentNode.className=''
			}
			};
			
			form.Submit=function(bNow) { with (this)
			{
				if (!bNow)
				{
					Lock();
					e.s_phrase.value=sanitize(s_phrase.value);
					setTimeout("p.SBOX.form.Submit(true)",500);
					return
				}
				
				this.submit()
			}
			};
		}
		
		
		/*
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		SUBMITTERS
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		*/
		with (SBOX) { for (var n=0;n<b.length;n++)
		{
			b[n].parent=SBOX;
			
			switch (n)
			{
				default:
				b[n].onclick=function() { with (this.parent)
				{
					if (!form.s_datatype.value)
					{
						form.parentNode.dd[2].menu.items[0].onclick()
					}
					
					form.Submit()
				}
				};
				break;
			}
		}
		}
		
		
		/*
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		CLOSER
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		*/
		with (SBOX)
		{
			closer.parent	= SBOX;
			closer.opened	= false;
			closer.oxy		= [368,6];
			
			closer.OnResize	= function(){with(this)if(opened)Repos()};
			closer.Repos	= function(){with (this){var xy=getPos(parent);setPos(this,xy[0]+oxy[0],xy[1]+oxy[1])}};
			closer.Open		= function(){with(this){if(!opened){Repos();setVis(this,1);opened=true}}};
			closer.Hide		= function(delay){with(this){if(opened){setVis(this,0);opened=false}}};
			closer.onclick	= function(){with(this){Hide();parent.Hide()}};
		}
		
		
		/*
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		DATE RANGES
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		*/
		with (SBOX)
		{
			form.s_date_1.parentNode.onmouseover	= function(){p.SBOX.eraser.Open(this)};
			form.s_date_1.parentNode.onmouseout		= function(){p.SBOX.eraser.Hide(250)};
			form.s_date_2.parentNode.onmouseover	= form.s_date_1.parentNode.onmouseover;
			form.s_date_2.parentNode.onmouseout		= form.s_date_1.parentNode.onmouseout;
			
			eraser.parent	= SBOX;
			eraser.partner	= new Object;
			eraser.timer	= null;
			
			eraser.Stop			= function(){clearTimeout(this.timer)};
			eraser.onmouseover	= function(){this.Open()};
			eraser.onmouseout	= function(){this.Hide()};
			
			eraser.Open=function(caller) { with (this)
			{
				Stop();
				if (caller && caller.nodeName) partner=caller;
				var xy=getPos(partner);
				
				switch (partner.firstChild.name)
				{
					case 's_date_1' : setPos(this,xy[0]+81,xy[1]-14); break;
					case 's_date_2' : setPos(this,xy[0]+81,xy[1]-14); break;
				}
				
				setVis(this,true)
			}
			};
			
			eraser.Hide=function(delay) { with (this)
			{
				Stop();
				
				if (delay)
				{
					timer=setTimeout("p.SBOX.eraser.Hide()",delay);
					return
				}
				
				setVis(this,false)
			}
			};
			
			eraser.onclick=function() { with (this)
			{
				Stop()
				partner.firstChild.value=""
			}
			};
		}
		
		
		/*
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		DROP-DOWN MENUS
		IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
		*/
		with (SBOX) { for (var n=0;n<dd.length;n++)
		{
			if (n >= menu.length) continue;
			else
			{
				dd[n].menu			= menu[n];
				hiddens[n].parent	= dd[n];
				
				menu[n].number	= n;
				menu[n].parent	= SBOX;
				menu[n].opened	= false;
				menu[n].caller	= dd[n];
				menu[n].oxy		= [0,0];
				menu[n].items	= menu[n].getElementsByTagName('td');
				menu[n].dest	= hiddens[n];
				menu[n].timer	= null;
				menu[n].wait	= 250;
				menu[n].Stop	= function(){clearTimeout(this.timer)};
				
				with (menu[n]) { for (var i=0;i<items.length;i++)
				{
					items[i].parent	= menu[n];
					items[i].value	= items[i].title;
					items[i].title	= "";
					
					items[i].onclick=function() { with (this)
					{
						parent.Hide();
						parent.dest.Insert(value,innerHTML)
					}
					};
				}
				}
				
				hiddens[n].Insert=function(x,str) { with (this)
				{
					this.value		= sanitize(x);
					parent.value	= sanitize(str.replace(/&amp;/g,'&'));
				}
				};
				
				switch (n)
				{
					case 0: menu[n].oxy=[0,23]; break;
					case 1: menu[n].oxy=[0,65]; break;
					case 2: menu[n].oxy=[0,107]; break;
				}
				
				if (isIE) menu[n].oxy[1]++;
			}
			
			dd[n].onclick=function() { with (this)
			{
				menu.opened ? menu.Hide() : menu.Open()
			}
			};
			
			menu[n].Open=function() { with (this)
			{
				if (opened) return;
				else
				{
					Stop();
					
					var xy=getPos(parent.inside);
					setPos(this,xy[0]+oxy[0],xy[1]+oxy[1]);
					setVis(this,true);
					opened=true
				}
			}
			};
			
			menu[n].Hide=function(delay) { with (this)
			{
				if (!opened) return;
				else
				{
					Stop();
					
					if (delay)
					{
						timer=setTimeout("p.SBOX.menu["+this.number+"].Hide()",delay);
						return
					}
					
					setVis(this,false);
					opened=false
				}
			}
			};
			
			dd[n].onmouseover	= function(){this.menu.Stop()};
			dd[n].onmouseout	= function(){with(this)menu.Hide(menu.wait)};
			menu[n].onmouseout	= function(){with(this)Hide(wait*2)};
			menu[n].onmouseover	= function(){this.Stop()};
		}
		}
	}
	
	
	/*
	IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
	INITIALIZER
	IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
	*/
	switch (PG_NAME.toUpperCase())
	{
		default:
		$INC(PG_NAME);
		break;
	}
	
	Start(500)
}
}
};

