﻿/* Declare Variables */
var g_b_keyPressed = false;
var g_b_nav		   = window.Event ? true : false;
var g_NEW_LINE     = "\n\r";

/* ------------------------------------------------------------------------------ */
/* Find first textbox on page and set the focus */
function SetFocus()
{
	var o_elem      = null;
	var s_origValue = "";

	try
	{
		if(document.getElementsByTagName)
		{
			o_elem = document.getElementsByTagName("input");
			
			if(o_elem)
			{
				for(var i_num = 0; i_num < o_elem.length; i_num++)
				{			
					if(o_elem[i_num].getAttribute('type') == "text")
					{
					    // if the textbox contains a value
					    // move the cursor to the last character.
						s_origValue = o_elem[i_num].value;
						o_elem[i_num].value = "";
						o_elem[i_num].focus();
						o_elem[i_num].value = s_origValue;
						
						break;
					}
				}
			}
		}
	}
	catch(o_error)
	{
		// do nothing
	}
}

/* ------------------------------------------------------------------------------
Sample: 
<a href="javascript:OpenWin('http://myCompany.com',600,600,1 ,1 ,1 ,1 ,1 ,1 ,10 ,10);">Link text here</a> 

s_url	- The URL of the page to open. 
i_w	    - The width of the window in pixels. 
i_h	    - The height of the window in pixels (doesn't include menubars). 
i_tb	- Toolbar visible?		1 = yes, 0 = no. 
i_stb	- Status bar visible?	1 = yes, 0 = no. 
i_l	    - Linkbar visible?		1 = yes, 0 = no. 
i_mb	- Menubar visible?		1 = yes, 0 = no. 
i_sb	- Scrollbars visible?	1 = yes, 0 = no. 
i_rs	- Resizable window?		1 = yes, 0 = no. 
i_x	    - The horizontal position of the window from the left of the screen. 
i_y	    - The vertical position of the window from the top of the screen.
*/
function OpenWin(
	 s_url
	,i_w
	,i_h
	,i_tb
	,i_stb
	,i_l
	,i_mb
	,i_sb
	,i_rs
	,i_x
	,i_y)
{
	var s_tb, s_stb, s_l, s_mb, s_sb, s_rs, s_temp, o_win

	try
	{
		s_tb  = (i_tb)  ? 'yes' : 'no';
		s_stb = (i_stb) ? 'yes' : 'no'; 
		s_l   = (i_l)   ? 'yes' : 'no'; 
		s_mb  = (i_mb)  ? 'yes' : 'no'; 
		s_sb  = (i_sb)  ? 'yes' : 'no';
		s_rs  = (i_rs)  ? 'yes' : 'no';
		
		// Check for firefox
		s_temp = (document.layers) ? ',screenX=' + i_x + ',screenY=' + i_y : ',left=' + i_x + ',top=' + i_y;
		
		o_win = window.open(
			   s_url, 
			  'win'          + new Date().getTime(),
			  'width='       + i_w + 
			  ',height='     + i_h + 
			  ',toolbar='    + s_tb + 
			  ',status='     + s_stb +
			  ',links='		 + s_l + 
			  ',menubar='    + s_mb + 
			  ',scrollbars=' + s_sb + 
			  ',resizable='  + s_rs + s_temp);
		
		o_win.focus();
	}
	catch(o_error)
	{
		// do nothing
	}
}

function OpenWinModal(
	 s_url
	,i_w
	,i_h
	,i_tb
	,i_stb
	,i_l
	,i_mb
	,i_sb
	,i_rs
	,i_x
	,i_y)
{
	var returnValue = null;

	if(window.showModalDialog)
	{
		try
		{
			returnValue = window.showModalDialog(
				  s_url, 
				  '',
				  'dialogWidth:'   + i_w + 'px' + 
				  ';dialogHeight:' + i_h + 'px' +
				  ';center:'       + 'yes' + 
				  ';dialogHide:'   + 'no' +
				  ';edge:'		   + 'raised' + 
				  ';status:'       + 'yes' + 
				  ';scroll:'       + 'yes' + 
				  ';resizable:'    + 'yes');
				  
			return returnValue;
		}
		catch(o_error){}
	}
	else
	{
		OpenWin(
			 s_url
			,i_w
			,i_h
			,i_tb
			,i_stb
			,i_l
			,i_mb
			,i_sb
			,i_rs
			,i_x
			,i_y);
	}
} 

/* ---------------------------------------- */
/* Disable Enter key press */
if(g_b_nav) 
{ 
	window.captureEvents(Event.KEYDOWN); 
	window.onkeydown = NetscapeEventHandler_KeyDown; 
} 
else 
	document.onkeydown = MicrosoftEventHandler_KeyDown;

function NetscapeEventHandler_KeyDown(e) 
{
	g_b_keyPressed = true;
	if (e.which == 13 && e.target.type != 'textarea' && e.target.type != 'submit') 
		return false;
	else
		return true;
} 

function MicrosoftEventHandler_KeyDown()
{
	g_b_keyPressed = true;
	if (event.keyCode == 13 && event.srcElement.type != 'textarea' && event.srcElement.type != 'submit') 
		return false; 
	else
		return true;
}

function OpenDoc(s_path)
{
	OpenWin(s_path,600,600,0 ,1 ,1 ,0 ,1 ,1 ,10 ,10); 
}

function OpenLink(s_link)
{
	OpenWin(s_link,600,500,0 ,1 ,1 ,0 ,1 ,1 ,10 ,10); 
}
