
var isIE = (document.all); 

var MESmai1 = "Popup window failed to open.  If you have popup blocking\nsoftware running, you will need to disable it in order to view this window.";

function isWindow(object)
{
return typeof(object) != "undefined" && object && (object != null) && (typeof(object.document) != 'undefined');
}

function findWindow(name)
{
var currentWindow = window;
var rootWindow = null;
var i = 0; 

while (rootWindow == null && i < 20)
{
if (currentWindow == null)
return null;

if (currentWindow.name == name)
return currentWindow;

if (currentWindow == currentWindow.parent)
rootWindow = currentWindow;
else
currentWindow = currentWindow.parent;

i++;
} 

if (rootWindow != null)
{
return findWindowInChildrenRecursive(name, rootWindow);
} 

return null;
}

function findWindowInChildrenRecursive(name, currentWindow)
{
try
{
var nameAccessTest = currentWindow.name;
} 
catch(e)
{
return null;
} 

if (currentWindow == null)
return null;
else if (currentWindow.name == name)
return currentWindow; 

var children = currentWindow.frames;

if (children == null)
return null;

var i = 0;
for (i = 0; i < children.length; i++)
{
var nextRecursiveAttempt = findWindowInChildrenRecursive(name, children[i]);
if (nextRecursiveAttempt != null)
return nextRecursiveAttempt;
} 

return null;
}

function openView(theUrl, name, initial)
{
openView( theUrl, name, initial, false);
}

function openView( theUrl, name, initial, isRemoveHistory){
var rhsWindow = findWindow('rhs');

var clearHistory = '';
if (isRemoveHistory){
clearHistory = '&clearHistory=' + escape(theUrl);
}

if (rhsWindow != null)
{
if (initial != null){
rhsWindow.location.href = '/ilrn/bca/user/home/rhs?open=' + escape(theUrl) + '&openInitial=' + escape(initial) + '&name=' + encodeURIComponent(name) + clearHistory;
} else {
rhsWindow.location.href = '/ilrn/bca/user/home/rhs?open=' + escape(theUrl) + '&name=' + encodeURIComponent(name) + clearHistory;
}
}
else
{
if (initial != null) {
window.open( '/ilrn/bca/user/home/rhs?open=' + escape(theUrl) + '&openInitial=' + escape(initial) + '&name=' + encodeURIComponent(name) + clearHistory,'rhs');
} else {
window.open( '/ilrn/bca/user/home/rhs?open=' + escape(theUrl) + '&name=' + encodeURIComponent(name) + clearHistory, 'rhs');
}
}    
}

function openViewFromIFrame(theURL, requestArgs)
{
var contentWindow = findWindow('contentWindow');

if(requestArgs)
theURL += escape(requestArgs);

contentWindow.location.href = theURL;
}

function openViewInIFrame(theURL, requestArgs)
{
var contentIFrame = findWindow('contentiFrame');

if(requestArgs)
theURL += escape(requestArgs);

contentIFrame.location.href = theURL;
}

function openViewWithCheck(theUrl, name, initial)
{
if (isOkToLoadNewPage()) {
openView(theUrl, name, initial);
}
}

function replaceView( theUrl, name, old, initial )
{
var rhsWindow = findWindow('rhs');

if (rhsWindow != null)
{
if (typeof(initial)!='undefined')
rhsWindow.location.href = '/ilrn/bca/user/home/rhs?open=' + escape(theUrl) + '&openInitial=' + escape(initial) + '&name=' + encodeURIComponent(name) + '&close=' + escape(old);
else
rhsWindow.location.href = '/ilrn/bca/user/home/rhs?open=' + escape(theUrl) + '&name=' + encodeURIComponent(name) + '&close=' + escape(old);
} 
else
{
if (typeof(initial)!='undefined')
window.open( '/ilrn/bca/user/home/rhs?open=' + escape(theUrl) + '&openInitial=' + escape(initial) + '&name=' + encodeURIComponent(name) + '&close=' + escape(old), 'rhs' );
else
window.open( '/ilrn/bca/user/home/rhs?open=' + escape(theUrl) + '&name=' + encodeURIComponent(name) + '&close=' + escape(old), 'rhs' );
} 
}


function replaceViewWithCheck (theUrl, name, old, initial )
{
if (isOkToLoadNewPage()) {
replaceView(theUrl, name, old, initial );
}
}

function closeView( url )
{
var rhsWindow = findWindow('rhs');

if (rhsWindow != null)
{
rhsWindow.location.href = '/ilrn/bca/user/home/rhs?close=' + escape(url);
} 
}

function closeViewWithCheck( url )
{
if (isOkToLoadNewPage()) {
if (isOkToCloseOldPage()) {
closeView(url);
}
}
}

function openUrlWithCheck( url, target ) {
if (isOkToLoadNewPage()) {
if (typeof(target) != "undefined" && target != null) {
window.open(url, target);
}
else {
window.open(url, "_self");
}
}
}

function openUrlWithCheck2(url, target)
{
if (isOkToLoadNewPage()) {
if (typeof(target) != "undefined" && target != null) {
window.open("/ilrn/bca/user/home" + url, target);
} else {
window.open(url, "_self");
}
}
}


function openHelp( context )
{

var newUrl = '/ilrn/bca/user/home/?show-help=' + escape( context ) ;


if ( navigator.userAgent.indexOf("Mac") != -1 )
var helpWindow = window.open(newUrl, 'helpPopup', 'width=640,height=480,resizable=1,top=0,right=100%,status');
else
var helpWindow = window.open(newUrl, 'helpPopup', 'width=640,height=480,resizable=1,top=0,right=100%');

if (isWindowLocalToMainJS(helpWindow))
helpWindow.focus()
else
alert(MESmai1);
}

function closeHelp()
{

parent.close();
}


function openPaste(pasteType, pasteID)
{
win = window.open("/ilrn/bca/user/paste/target?pasteType="+pasteType+"&pasteID="+pasteID,
'clipPop', 'toolbar=no,location=no,width=640,height=480,resizable,scrollbars');
if (isWindowLocalToMainJS(win))
{
win.focus();
return win;
}
else
alert(MESmai1);
}


function openModal( loc , width , height )
{
if (navigator.userAgent.indexOf('MSIE')!=-1)
{
window.showModalDialog( loc , window ,'dialogWidth:' + width +'px; dialogHeight:' + height +'px; scroll: no; help: no; center: yes; resizable: yes; status: no')
}
else
{
window.open( loc ,'editScore','width=' + width +',height=' + height +',scrollbars=0,resizable=1,modal=1')
}
}


function processImageEventHandlers()
{
for ( var i = 0; i < document.images.length; i++ )
{
var overSrc = document.images[i].getAttribute( 'overSrc' );
var outSrc = document.images[i].getAttribute( 'outSrc' );
var origSrc = document.images[i].getAttribute( 'src' );

if ( overSrc != null && overSrc != "" )
{
document.images[i].onmouseover = new Function ( 'this.src = "' + overSrc +'"' );
var x = new Image();
x.src = overSrc;

if ( outSrc != null && outSrc != "" )
{
document.images[i].onmouseout = new Function ( 'this.src = "' + outSrc +'"' );
var x = new Image();
x.src = outSrc;
}
else
{
document.images[i].onmouseout = new Function ( 'this.src = "' + origSrc +'"' );
}
}

document.images[i].onerror = new Function ( 'setTimeout( "this.src =\'' + origSrc + '\'" , 2000)' );
}
}


function printWindow() {
bV = parseInt(navigator.appVersion);
window.parent.helpText.focus();
if (bV >= 4) window.print();
}


function isOkToLoadNewPage() {
try {
if (typeof(preUnloadCallback) != "undefined" && preUnloadCallback != null) {
return preUnloadCallback();
}
else {
return true;
}
}
catch (e) {
return true;
}
}


function isOkToCloseOldPage() {
try {
if (typeof(preCloseCallback) != "undefined" && preCloseCallback != null) {
return preCloseCallback();
}
else {
return true;
}
}
catch (e) {
return true;
}
}


function getViewportHeight()
{
if( window.innerHeight )
return window.innerHeight;
if( window.document.documentElement.clientHeight )
return document.documentElement.clientHeight;
return window.document.body.clientHeight;
}

function getViewportWidth()
{
if( window.innerWidth )
return window.innerWidth;
if( window.document.documentElement.clientWidth )
return document.documentElement.clientWidth;
return window.document.body.clientWidth;
}

function closeTab()
{

if (window.opener)
window.close();
else if (parent.opener)
parent.close();
else    
parent.closeView( 'ACTIVE' );
}



function getArgs()
{
var argHash = new Object();
var arg, val;
var tmp = '' + window.location.search;
if ( tmp.length > 0 )
{
if ( tmp.charAt(0) == '?' )
tmp = tmp.substring( 1 );

if ( tmp.indexOf( '&' ) != -1 )
{
var tmp2 = tmp.split( '&' );
for ( var i=0; i < tmp2.length; i++)
{
if ( tmp2[i].indexOf( '=' ) != -1 )
{
arg = tmp2[i].slice( 0, tmp2[i].indexOf('=') );
val = tmp2[i].slice( tmp2[i].indexOf('=')+1 , tmp2[i].length )
}
else
{
arg = tmp2[i];
val = null;
}
argHash[ arg ] = val;
}
}
else
{
var tmp2 = tmp.split( '=' );
argHash[ tmp2[0] ] = tmp2[1];
}
return argHash;
}
return null;
}

function getQueryString(name)
{
var strName, strValue;
var strTemp = window.location.search;
if (strTemp.length > 0)
{
var arrNames = new Array();
var arrValues = new Array();

if (strTemp.charAt(0) == "?")
strTemp = strTemp.substring(1);

if (strTemp.indexOf("&") != -1)
{
var arrTemp = strTemp.split("&");
for (i = 0; i < arrTemp.length; ++i)
{
if (arrTemp[i].indexOf("=") != -1)
{
arrNames[i] = arrTemp[i].slice(0, arrTemp[i].indexOf("="));
arrValues[i] = arrTemp[i].slice(arrTemp[i].indexOf("=") + 1, arrTemp[i].length)
}
else
{
arrNames[i] = null;
arrValues[i] = null;
}
}
}
else
{
arrNames[0] = strTemp.slice(0, strTemp.indexOf("="));
arrValues[0] = strTemp.slice(strTemp.indexOf("=") + 1, strTemp.length)
}

for (i = 0; i < arrNames.length; ++i)
{
if (arrNames[i] == name)
return arrValues[i];
}
}
return null;
}



function isWindowLocalToMainJS(object)
{
return object && (object != null) && (typeof(object.document) != 'undefined');
}


function onlineCheck(url,heading,cfg)
{
url = escape(url);
url = url.replace(/\//g,"%2f");
url = '/ilrn/bca/user/if-online?on=' + url + '&off=%2fplaceholder.html';
window.open(url,heading,cfg,'_new');
}


function modalAlert(alertMessage)
{
if (window.showModalDialog)
window.showModalDialog("/ilrn/accounts/modalAlert.do",alertMessage,"dialogWidth:500px; dialogHeight:200px; center:yes; help:no; resizable:yes; status:no");
else
alert(alertMessage);
}
function modalConfirm(confirmMessage)
{
if (window.showModalDialog)
return window.showModalDialog("/ilrn/accounts/modalConfirm.do",confirmMessage,"dialogWidth:500px; dialogHeight:200px; center:yes; help:no; resizable:yes; status:no");
else
return confirm(confirmMessage)
return
}


function changeDisplay(div) {
div.style.display = div.style.display == "none" ? "block" : "none"; 
}

function findMyTopWindow(currentWindow)
{
if(typeof(currentWindow) == 'undefined')
currentWindow = window;

if(currentWindow == top)
return currentWindow;

if(!findMyTopWindow.canAccessContainer(currentWindow))
return currentWindow;

return findMyTopWindow(currentWindow.parent);
}

findMyTopWindow.canAccessContainer = function(currentWindow)
{
try
{
if(currentWindow.parent.name == null)
return false;

if(currentWindow.location.host != currentWindow.parent.location.host)
return false;

if(currentWindow.location.protocol != currentWindow.parent.location.protocol)
return false;

if(currentWindow.location.port != currentWindow.parent.location.port)
return false;

return true;
}
catch(e)
{
return false;
}
}
