// The main codes
var shortkeysReady = false;
var refreshContentAfterLogin = false;
var firstLoginLoad = true;
var shortkeys=new Array(100)
var ExitFlag = true;
var loadedScripts = new Array();
var loadedStyleSheets = new Array();

function reset_shortkeys_array()
{
	for (i=0; i <100; i++)
	{
		shortkeys[i]=new Array(2)				
		shortkeys[i][0] = '';
		shortkeys[i][1] = '';
	}
}

function init_shortkeys()
{
	var theOptions = {
		'type':'keydown',
		'propagate':false,
		'target':document
	}; 
	for (i=0; i <100; i++)
	{
		if (shortkeys[i][0] != '')
		{
			shortcut.add(shortkeys[i][0],shortkeys[i][1],theOptions);
		}
	}
}

function remove_shortkeys()
{
	var theOptions = {
		'type':'keydown',
		'propagate':true,
		'target':document
	}; 
	for (i=0; i <100; i++)
	{
		if (shortkeys[i][0] != '')
		{
			shortcut.remove(shortkeys[i][0]);
		}
	}
}

reset_shortkeys_array();

function apply_child_shortkeys()
{
	remove_shortkeys();
	try{
		init_shortkeys();
	}
	catch(e)
	{
		setTimeout("apply_child_shortkeys();",500);
	}
}
		
		
function changeActiveMenu(miId) 
{	
	return;
	allLinks = document.getElementsByTagName("a");
	for (var i = 0; i < allLinks.length; i++)
	{
		linkId = allLinks[i].id;
		pos = linkId.indexOf('mi_link_');
		if (pos == 0)
		{
			menuItemId = linkId.substr(8,10);
			menuItemPadId = 'mi_pad_' + menuItemId;
			menuItemLinkId = 'mi_link_' + menuItemId;
			menuItemPad = document.getElementById(menuItemPadId);
			menuItemLink = document.getElementById(menuItemLinkId);
			menuItemPad.className = 'menu_item';
			menuItemLinkId.className = 'menu_item_text';
		}
	}
	menuItemPadId = 'mi_pad_' + miId;
	menuItemLinkId = 'mi_link_' + miId;
	menuItemPad = document.getElementById(menuItemPadId);
	menuItemLink = document.getElementById(menuItemLinkId);
	menuItemPad.className = 'active_menu_item';
	menuItemLinkId.className = 'active_menu_item_text';
}


function changeMenu(newContent)
{
	document.getElementById('menu_module').innerHTML =  newContent;
}

function changeMainView()
{
	document.getElementById('main_module').style.display = 'block';
	document.getElementById('waitDiv').style.display = 'none';	
	try
	{	
		var childFrame = window.frames['loadIframe'];
		document.getElementById('main_module').innerHTML =  
		childFrame.document.getElementById('main_module').innerHTML;
		refreshContentAfterLogin = childFrame.refreshContentAfterLogin;
		miId = childFrame.miId;
		changeActiveMenu(miId);
	}
	catch (e)
	{
		alert(javascriptTexts[0])
	}
	try
	{	
		var childFrame = window.frames['loadIframe'];
		childFrame.parentCall();
	}
	catch (e)
	{
	}	
}

function onChildLoad()
{
	//setTimeout("changeMainView();",20);	
	document.getElementById('main_module').style.display = 'block';
	document.getElementById('waitDiv').style.display = 'none';	
}

function onChildUnload()
{	
	document.getElementById('main_module').style.display = 'none';
	document.getElementById('waitDiv').style.display = 'block';			
}


function show_content_detail(textId)
{
	fullTextDivId = 'fullText_'+textId;
	fullTextDiv = document.getElementById(fullTextDivId);
	fullTextDiv.style.display = 'block';
	showLinkDivId = 'showLink_'+textId;
	showLinkDiv = document.getElementById(showLinkDivId);
	showLinkDiv.style.display = 'none';
}

function hide_content_detail(textId)
{
	fullTextDivId = 'fullText_'+textId;
	fullTextDiv = document.getElementById(fullTextDivId);
	fullTextDiv.style.display = 'none';
	showLinkDivId = 'showLink_'+textId;
	showLinkDiv = document.getElementById(showLinkDivId);
	showLinkDiv.style.display = 'block';
}

function change_content_visible(textId)
{
	textDivId = 'text_'+textId;
	textDiv = document.getElementById(textDivId);
	if (textDiv.style.display == 'none')
	{
		textDiv.style.display = 'block';
	}
	else
	{
		textDiv.style.display = 'none';
	}
}

function onLoginLoad()
{
	shortkeysReady = true;
	loginFrame = window.frames['loginIframe'];
	username = loginFrame.GetUserName();	
	if (username=='guest')
	{
		document.getElementById('loginFeilds').style.display = 'block';
		document.getElementById('waitForLogin').style.display = 'none';
		document.getElementById('logedinUser').style.display = 'none';
		document.getElementById('loginform_username').focus();
	}
	else
	{
		document.getElementById('loginFeilds').style.display = 'none';
		document.getElementById('waitForLogin').style.display = 'none';
		document.getElementById('logedinUser').style.display = 'block';				
		document.getElementById('currentUser').innerHTML = username;
	}
	document.onkeydown = "";
	apply_child_shortkeys();
	if (! firstLoginLoad)
	{
		if (refreshContentAfterLogin)
		{
			childFrame = window.frames['loadIframe'];
			childFrame.location.reload(false); ;				
		}
	}
	else
	{
		firstLoginLoad = false;
	}
	
}

function onLoginUnload()
{	
	shortkeysReady = false;
	remove_shortkeys();
	document.getElementById('loginFeilds').style.display = 'none';
	document.getElementById('waitForLogin').style.display = 'block';
	document.getElementById('logedinUser').style.display = 'none';
}

function do_for_login()
{
	onLoginUnload();
	lUsername = document.getElementById('loginform_username').value;
	lPassword = document.getElementById('loginform_password').value;
	loginFrame = window.frames['loginIframe'];
	loginFrame.Login(lUsername,lPassword);
	document.getElementById('loginform_username').value = '';
	document.getElementById('loginform_password').value = '';
}

function do_for_logout()
{
	onLoginUnload();
	loginFrame = window.frames['loginIframe'];
	loginFrame.LogOff();
}				

function prevent_logoff()
{
	onLoginUnload();
	loginFrame = window.frames['loginIframe'];
	loginFrame.ExitFlag = false;
	ExitFlag = false;
}

function change_loadframe_location(location)
{
	var loadFrame = window.frames['loadIframe'];
	loadFrame.location = location;
}

function SetCookie(cookieName,cookieValue, nMinute) {
 var today = new Date();
 var expire = new Date();
 if (nMinute==null || nMinute==0) nMinute=1;
 expire.setTime(today.getTime() + 60000*nMinute);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}

function page_unload()
{
	if (ExitFlag && (username != 'guest'))	
	{
		loginFrame = window.frames['loginIframe'];
		loginFrame.LogOff();
		if (BrowserDetect.browser != 'Firefox')
		{
			alert(javascriptTexts[2]);
		}
	}
}

var contentRefreshUrl = "";
function Refresh_Content()
{
	if (contentRefreshUrl == "")
		return;
	var loadFrame = window.frames['loadIframe'];
	loadFrame.location = contentRefreshUrl;
}
function Change_Content(location)
{
	var loadFrame = window.frames['loadIframe'];
	loadFrame.location = location;
}

