﻿function HiddenDisplay(spanObj, obj) {
    if (obj.style.display == "none") {
        obj.style.display = "block";
        spanObj.innerHTML = "O";
    }
    else {
        obj.style.display = "none";
        spanObj.innerHTML = "A";
    }
}

function HiddenDisplayMore(spanObj, obj) {
    if (obj.style.display == "none") {
        obj.style.display = "block";
        spanObj.innerHTML = "less...";
    }
    else {
        obj.style.display = "none";
        spanObj.innerHTML = "more...";
    }
}

/******************************************************************************/
//
// NOTE TO DEVELOPERS:
// The following code should be integrated with your web page in order to open
// the presentation in a new window.  To launch the presentation immediately, 
// simply copy the code below into your web page.  To launch the presentation
// when a button or link is clicked, call LaunchPresentation when the onClick
// event is triggered.
//
// 
// LaunchPresentation(bChromeless, bResize)
//
// Parameters:
//	bChromeless - Opens a new window without the toolbar, addressbar, statusbar,
//		      menubar, and scrollbars
//	
//	bResize - Determines whether or not the new window can be resized
//
/******************************************************************************/
function PopupFlvPlayer(pUrl,strOptions) {
	
	strOptions += ", screenX=50, screenY=50";
	strOptions += ",resizable=0, statusbar=0, toolbar=0, location=0, menubar=0, scrollbars=0";
    window.open(pUrl, "_blank", strOptions);
}


function LaunchPresentation(pUrl, bChromeless, bResize) {
    var nWidth = screen.availWidth;
    var nHeight = screen.availHeight;

    // Get the width
    if (nWidth > 820) {
        nWidth = 980;
        nHeight = 640;
    }

    // Build the options string
    var strOptions = "width=" + nWidth + ",height=" + nHeight;
    if (bResize) {
        strOptions += ",resizable=yes"
    }

    if (bChromeless) {
        strOptions += ", status=0, toolbar=0, location=0, menubar=0, scrollbars=0";
    }
    else {
        strOptions += ", status=1, toolbar=1, location=1, menubar=1, scrollbars=1";
    }

    // Launch the URL
    window.open(pUrl, "_blank", strOptions);

}

// 05/05/2008	Neil Chen
// Check client's browser type
function getOs() {
    var OsObject = "";

    if (navigator.userAgent.indexOf("MSIE") > 0) {
        return "MSIE";
    }

    if (isFirefox = navigator.userAgent.indexOf("Firefox") > 0) {
        return "Firefox";
    }

    if (isSafari = navigator.userAgent.indexOf("Safari") > 0) {
        return "Safari";
    }

    if (isCamino = navigator.userAgent.indexOf("Camino") > 0) {
        return "Camino";
    }

    if (isMozilla = navigator.userAgent.indexOf("Gecko/") > 0) {
        return "Gecko";
    }
}

function insertFlash(elm, url, w, h) 
{
    if (!document.getElementById(elm)) return;
    var str = '';
    str += '<object width="'+ w +'" height="'+ h +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0">';
    str += '<param name="movie" value="'+ url +'">';
    str += '<param name="wmode" value="transparent">';
    str += '<param name="quality" value="autohigh">';
    str += '<embed width="'+ w +'" height="'+ h +'" src="'+ url +'" quality="autohigh" wmode="transparent" type="application/x-shockwave-flash" plugspace="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed>';
    str += '</object>';
    document.getElementById(elm).innerHTML = str;
}

function popup_VideoGuide(pSection) {
    var confirmWin = null;
    confirmWin = window.open('/videopopup.aspx?id=' + pSection, 'VideoWindow', 'width=640,height=510,status=no');
    //psection = videocategoryID in illuminatitrader DB
}

function pop_StrategyAnalyzer(pStrategyAnalyzerURL) {
    if (getOs() == "MSIE") {
        var confirmWin = null;
        confirmWin = window.open(pStrategyAnalyzerURL, 'AnalyzerWindow', 'width=655,height=750,location=no, menubar=no,resizable=yes, scrollbars=yes, status=no, titlebar=no, toolbar=no');
    }
    else {
        window.modal(pStrategyAnalyzerURL, 'width=655,height=750,toolbars=0,resizable=0'); return false;
    }
}

function popup_EditResource(name) {
    window.open("/Admin/Manage/ResourcesEditor.aspx?FileName=" + name, "Edit", "width=655,height=750,location=no, menubar=no,resizable=yes, scrollbars=yes, status=no, titlebar=no, toolbar=no");
}

// 05/05/2008	Neil Chen
// Trims left and right space of string object.
String.prototype.Trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

// 05/05/2008	Neil Chen
// Trims left space of string object.
String.prototype.LTrim = function() {
    return this.replace(/(^\s*)/g, "");
}

// 05/05/2008	Neil Chen
// Trims right space of string object.
String.prototype.RTrim = function() {
    return this.replace(/(\s*$)/g, "");
}

function toBreakWord(iPerLineLen, id){
        var sStr=document.getElementById(id).innerHTML;  
        
        if(sStr.replace(/[^\x00-\xff]/g,"xx").length <= iPerLineLen){  
            return -1;  
        }  
      
        var str="";  
        var l=0;
        var schar;  
        
        for(var i=0;schar=sStr.charAt(i);i++){  
            str+=schar;
            l += (schar.match(/[^\x00-\xff]/) != null ? 2 : 1);  
            
            if(l>= iPerLineLen){  
                str+="\n";  
                l=0;  
            }
        }  
        
        document.getElementById(id).innerHTML=str;
    }

    function breakWord(dEl) {
        if (!dEl || dEl.nodeType !== 1) {

            return false;

        } else if (dEl.currentStyle && typeof dEl.currentStyle.wordBreak === 'string') {

            //Lazy Function Definition Pattern, Peter's Blog
            //From http://peter.michaux.ca/article/3556

            breakWord = function(dEl) {
                //For Internet Explorer
                dEl.runtimeStyle.wordBreak = 'break-all';
                return true;
            }

            return breakWord(dEl);

        } else if (document.createTreeWalker) {

            //Faster Trim in Javascript, Flagrant Badassery
            //http://blog.stevenlevithan.com/archives/faster-trim-javascript

            var trim = function(str) {
                str = str.replace(/^\s\s*/, '');
                var ws = /\s/,
      i = str.length;
                while (ws.test(str.charAt(--i)));
                return str.slice(0, i + 1);
            }

            //Lazy Function Definition Pattern, Peter's Blog
            //From http://peter.michaux.ca/article/3556

            breakWord = function(dEl) {

                //For Opera, Safari, and Firefox
                var dWalker = document.createTreeWalker(dEl, NodeFilter.SHOW_TEXT, null, false);
                var node, s, c = String.fromCharCode('8203');
                while (dWalker.nextNode()) {
                    node = dWalker.currentNode;
                    //we need to trim String otherwise Firefox will display
                    //incorect text-indent with space characters
                    s = trim(node.nodeValue).split('').join(c);
                    node.nodeValue = s;
                }
                return true;
            }

            return breakWord(dEl);


        } else {
            return false;
        }
    }

    void function() {
        var aEl = document.getElementsByTagName('div');
        var dEl, i;
        var sName = "break-word";
        var oReg = new RegExp('(\\s|^)' + sName + '(\\s|$)');
        for (i = 0; dEl = aEl[i]; i++) {
            if (dEl.className.match(oReg)) {
                breakWord(dEl);
            }
        }
    } ();