//JavaScript standard library functions

//Set focus to the first text element on the page.
function setFocusFirst() {
   var firstForm = document.forms[0];
   if (firstForm != null) {
       for (i = 0; i < firstForm.elements.length; i++) {
          var firstElement = firstForm.elements[i];
          if (firstElement != null && firstElement.type == "text") {
              firstElement.focus();
              break;
          }
       }
   }
}

//Open the find code window
function openFindCode() {
    findwin = open("/action/quote/showFindCode", "findWin", "width=350,height=500,toolbars=no,resizable=yes,scrollbars=yes");
    findwin.focus();
}

//Open the Terminal Help window
function openTerminalHelp() {
    helpWin = open("/help/term_help.php",
      "_blank", "width=780,height=650,toolbars=no,resizable=yes,scrollbars=yes");
    helpWin.focus();
}

//Open the Level2 window
function openLevel2() {
    level2win = open("/action/nav/level2", "_blank", "width=785,height=690,toolbars=no,resizable=yes,scrollbars=yes");
    //    level2win = open("/action/nav/level2", "_blank", "width=400,height=200,toolbars=no,resizable=yes,scrollbars=yes");
    level2win.focus();
}

function openAbsoluteLevel2() {
    level2win = open("http://www.moneyam.com/action/nav/level2", "_blank", "width=785,height=690,toolbars=no,resizable=yes,scrollbars=yes");
    //    level2win = open("/action/nav/level2", "_blank", "width=400,height=200,toolbars=no,resizable=yes,scrollbars=yes");
    level2win.focus();
}
function openLevel2WithEpic(epic) {
    level2win = open("/action/nav/level2?epic=" + epic, "_blank", "width=785,height=690,toolbars=no,resizable=yes,scrollbars=yes");
    //    level2win = open("/action/nav/level2?epic=" + epic, "_blank", "width=400,height=200,toolbars=no,resizable=yes,scrollbars=yes");
        level2win.focus();
}

function oasisAdvert(s,x,y,adServer) {

	adServerBaseURL = "http://campaigns.moneyam.com/";

//	document.write ("<div style='border:1px solid #bbb;width:"+x+";height:"+y+";'>");
	document.write ("<NOLAYER>");
	document.write ("<IFRAME SRC='" + adServerBaseURL + "oasisi-i.php?s=" + s + "&w=" + x + "&h=" + y + "&t=_blank' WIDTH=" + x + " HEIGHT=" + y + " FRAMEBORDER='no' BORDER=0 MARGINWIDTH=0 MARGINHEIGHT=0 SCROLLING='no'>");
	document.write("<A HREF='" + adServerBaseURL + "oasisc.php?s=" + s + "&w=" + x + "&h=" + y + "&t=_blank' TARGET='_blank'>");
	document.write("<IMG SRC='" + adServerBaseURL + "oasisi.php?s=" + s + "&w=" + x + "&h=" + y + "&t=_blank' BORDER=0 WIDTH=" + x + " HEIGHT=" + y + ">");
	document.write("</A>");
	document.write("</IFRAME>");
	document.write("</NOLAYER>");
	document.write("<ILAYER ID='layer" + s + "' VISIBILITY='hidden' WIDTH=" + x + " HEIGHT=" + y + "></ILAYER>");
	document.write("<LAYER SRC='" + adServerBaseURL + "oasisi.php?s=" + x + "&w=" + x + "&h=" + y + "&t=_blank' WIDTH=" + x + " HEIGHT=" + y + " VISIBILITY='hidden' ");
	document.write("onLoad='moveToAbsolute(layer" + s + ".pageX,layer" + s + ".pageY);clip.height=" + y + ";clip.width=" + x + ";visibility='show';></LAYER>");
//	document.write("</div>");
}

function oasisSSLAdvert(s,x,y) {

		adServerBaseURL = "https://campaigns.moneyam.com/";

	document.write ("<NOLAYER>");
	document.write ("<IFRAME SRC='" + adServerBaseURL + "oasisi-i.php?s=" + s + "&w=" + x + "&h=" + y + "&t=_blank' WIDTH=" + x + " HEIGHT=" + y + " FRAMEBORDER='no' BORDER=0 MARGINWIDTH=0 MARGINHEIGHT=0 SCROLLING='no'>");
	document.write("<A HREF='" + adServerBaseURL + "oasisc.php?s=" + s + "&w=" + x + "&h=" + y + "&t=_blank' TARGET='_blank'>");
	document.write("<IMG SRC='" + adServerBaseURL + "oasisi.php?s=" + s + "&w=" + x + "&h=" + y + "&t=_blank' BORDER=0 WIDTH=" + x + " HEIGHT=" + y + ">");
	document.write("</A>");
	document.write("</IFRAME>");
	document.write("</NOLAYER>");
	document.write("<ILAYER ID='layer" + s + "' VISIBILITY='hidden' WIDTH=" + x + " HEIGHT=" + y + "></ILAYER>");
	document.write("<LAYER SRC='" + adServerBaseURL + "oasisi.php?s=" + x + "&w=" + x + "&h=" + y + "&t=_blank' WIDTH=" + x + " HEIGHT=" + y + " VISIBILITY='hidden' ");
	document.write("onLoad='moveToAbsolute(layer" + s + ".pageX,layer" + s + ".pageY);clip.height=" + y + ";clip.width=" + x + ";visibility='show';></LAYER>");
}

function changeAd(oasis_url) {
    frames["terminalAdFrame"].location.href = oasis_url;
    setTimeout("changeAd('" + oasis_url + "')", 90000);
}

function oasisTerminalAdvert(s,x,y) {
        var oasis_url = "http://campaigns.moneyam.com/oasisi-i.php?s=" + s + "&w=" + x + "&h=" + y + "&t=_blank";
	document.write("<IFRAME id='terminalAdFrame' name='terminalAdFrame' SRC='" + oasis_url + "' WIDTH=" + x + " HEIGHT=" + y + " FRAMEBORDER='no' BORDER=0 MARGINWIDTH=0 MARGINHEIGHT=0 SCROLLING='no'>");
	document.write("</IFRAME>");
        changeAd(oasis_url);
}

function changeAdRolling(oasis_url, name, timeout) {
/*	alert("2:" + name);
	alert("3:" + oasis_url);
	alert("4:" + timeout); */
    frames[name].location.href = oasis_url;
    setTimeout("changeAdRolling('" + oasis_url + "','" + name + "'," + timeout + ")", timeout);
}

function oasisAdRolling(s,x,y,name,timeout) {
        var oasis_url = "http://campaigns.moneyam.com/oasisi-i.php?s=" + s + "&w=" + x + "&h=" + y + "&t=_blank";
	document.write("<IFRAME id='" + name + "' name='" + name + "' SRC='" + oasis_url + "' WIDTH=" + x + " HEIGHT=" + y + " FRAMEBORDER='no' BORDER=0 MARGINWIDTH=0 MARGINHEIGHT=0 SCROLLING='no'>");
	document.write("</IFRAME>");
	
	/* alert("1:" + name); */
        changeAdRolling(oasis_url, name, timeout);  
}

function getWindowDetails() {
    return self.name + "," + self.width + "," + self.height;
}

function refreshFrames(frameList) {
    var fl = frameList;
    var stop = false;
    while (!stop) {
        var frameId = "";
        var commaIndex = fl.indexOf(",");
        if (commaIndex == -1) {
            stop = true;
            frameId = fl;
        } else {
            frameId = fl.slice(0, commaIndex);
            fl = fl.substr(commaIndex + 1);
        }
        
        var winlist = window.terminal_framelist;
        
        var frameName = "frame" + frameId;
        
        if (frames[frameName] != null) {
            var loc = frames[frameName].location.href;
            frames[frameName].location.href = loc;
        } else {
            for (var i = 0; i < frames.length; i++) {
                var nextFrame = frames[i];
                if (nextFrame.name != "headerFrame" && nextFrame.name != "contentFrame" && nextFrame.name != "hiddenframe") {
                    try {
                        if (nextFrame.refreshFrames)
                            nextFrame.refreshFrames(frameList);
                    } catch (error) {
                    }
                }
            }
        }
    }
}


//function createAuthCheckFrame()
///{
//	var url = "/checkAuth.php";
//	var x = 1;
//	var y = 1;
//	
//	document.write("<IFRAME id='checkAuthFrame' name='checkAuthFrame' SRC='"+ url +"' WIDTH=" + x + " HEIGHT=" + y + " FRAMEBORDER='no' BORDER=0 MARGINWIDTH=0 MARGINHEIGHT=0 SCROLLING='no'>");
//	document.write("</IFRAME>");
//}

// do comman js functions
//createAuthCheckFrame();

