
// This method does not return a value (window object or null)
function OpenNewWindow(winName, Page, y, x, w, h, tool, menu, scroll, location, directories, status, resize, fullscreen) {
    OpenAndReturnNewWindow(winName, Page, y, x, w, h, tool, menu, scroll, location, directories, status, resize, fullscreen)
}


// This method returns a value (window object or null)
function OpenAndReturnNewWindow(winName, Page, y, x, w, h, tool, menu, scroll, location, directories, status, resize, fullscreen, returnWindow) {
    var IE = navigator.appName.indexOf("Microsoft") != -1;

    if (window.OpenWindow)
        if (!window.OpenWindow.closed)
        window.OpenWindow.StayIN = true

    if (fullscreen == 'no')
        var objWindow = window.open(Page, winName, 'width=' + w + ',height=' + h + ',toolbar=' + tool + ',menubar=' + menu + ',scrollbars=' + scroll + ',location=' + location + ',directories=' + directories + ',status=' + status + ',resizable=' + resize + ',top=' + x + ',left=' + y + ';')
    else
        var objWindow = IE ? window.open(Page, winName, 'fullscreen=yes') : OpenFullWindow(winName, Page);

    if (objWindow) {
        objWindow.focus();
        return objWindow;
    }
    else
        return null;
}


function OpenFullWindow(winName, Page, realFullScreen) {
    w = 800
    h = 600
    if (window.screen) {
        w = window.screen.availWidth - 10;
        h = window.screen.availHeight - 30;
    }

    if (realFullScreen == true) {
        var StrDefine = 'fullscreen=yes,toolbar=no,menubar=no,scrollbars=yes,location=no,directories=no,status=no,resizable=yes'
    }
    else {
        var StrDefine = 'width=' + w + ',height=' + h + ',toolbar=no,menubar=no,scrollbars=yes,location=no,directories=no,status=no,resizable=yes,top=1,left=1'
    }

    var OpenWindow = window.open(Page, winName, StrDefine);
    OpenWindow.focus()
}

function OpenWindow(strUrl, winName, intWidth, intHeight) {
    var strFeatures = "toolbar=no,menubar=no,location=no,directories=no,status=no"
    if (intWidth != undefined) strFeatures += (",width=" + intWidth);
    if (intHeight != undefined) strFeatures += (",height=" + intHeight);
    var objWindow = window.open(strUrl, winName, strFeatures);

    if (objWindow) {
        objWindow.focus()
        return objWindow;
    }
    else
        return null;
}

//fermeture de la fenetre
function CloseWindow() {
    self.close();
}

function MoveLang(element, Page) {
    if (Page == undefined) {
        Page = window.location.href
    }


    if (Page.match(/([\?|\&])lang=([a-zA-Z\-]*)/i)) {
        Page = Page.replace(/([\?|\&])lang=([a-zA-Z\-]*)/i, "$1Lang=" + element.options[element.selectedIndex].value);
    }
    else {
        Page = Page + (Page.indexOf("?") == -1 ? "?" : "&") + "Lang=" + element.options[element.selectedIndex].value;
    }

    window.location = Page;
}


function replaceSubstring(inputString, fromString, toString) {

    var temp = inputString;
    if (fromString == "") {
        return inputString;
    }
    if (toString.indexOf(fromString) == -1) {
        while (temp.indexOf(fromString) != -1) {
            var toTheLeft = temp.substring(0, temp.indexOf(fromString));
            var toTheRight = temp.substring(temp.indexOf(fromString) + fromString.length, temp.length);
            temp = toTheLeft + toString + toTheRight;
        }
    } else {
        var midStrings = new Array("~", "`", "_", "^", "#");
        var midStringLen = 1;
        var midString = "";
        while (midString == "") {
            for (var i = 0; i < midStrings.length; i++) {
                var tempMidString = "";
                for (var j = 0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
                if (fromString.indexOf(tempMidString) == -1) {
                    midString = tempMidString;
                    i = midStrings.length + 1;
                }
            }
        }
        while (temp.indexOf(fromString) != -1) {
            var toTheLeft = temp.substring(0, temp.indexOf(fromString));
            var toTheRight = temp.substring(temp.indexOf(fromString) + fromString.length, temp.length);
            temp = toTheLeft + midString + toTheRight;
        }

        while (temp.indexOf(midString) != -1) {
            var toTheLeft = temp.substring(0, temp.indexOf(midString));
            var toTheRight = temp.substring(temp.indexOf(midString) + midString.length, temp.length);
            temp = toTheLeft + toString + toTheRight;
        }
    }
    return temp;
}

function unescapeHtmlCodes(strText) {

    strText = strText.replace(/&nbsp;/g, " ");
    strText = strText.replace(/&quot;/g, "\"");
    strText = strText.replace(/&amp;/g, "&");
    strText = strText.replace(/&lt;/g, "<");
    strText = strText.replace(/&gt;/g, ">");

    return strText;
}


function createScormTagObject(PATH_SERVER) {
    document.write('<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" width="0" height="0" id="APIAdapter" codebase="http://java.sun.com/products/plugin/autodl/jinstall-1_3_1_09-windows-i586.cab#Version=1,3,0,0">');
    document.write('<param name = "code" value = "com/strategia/applet/APIAdapterApplet.class" >');
    document.write('<param name = "codebase"" 	value = "' + PATH_SERVER + 'Includes/Scorm" >');
    document.write('<param name = "type" 		value = "application/x-java-applet;version=1.3">');
    document.write('<param name = "mayscript" 	value = "true" >');
    document.write('<param name = "scriptable" 	value = "true" >');
    document.write('<param name = "archive" 	value = "applet.jar,jaxp.jar,parser.jar" >');
    document.write('<comment>');
    document.write('<applet   code="com/strategia/applet/APIAdapterApplet.class"');
    document.write('archive="applet.jar,jaxp.jar,parser.jar"');
    document.write('codebase=" & PATH_SERVER & "Includes/Scorm"');
    document.write('src="' + PATH_SERVER + 'Includes/Scorm"');
    document.write('height="1"');
    document.write('id="APIAdapter"');
    document.write('name="APIAdapter"');
    document.write('width="1"');
    document.write('mayscript= "true">');
    document.write('</applet>');
    document.write('</comment>');
    document.write('</object>');

}

function ResizeLegacyFrame(iframe) {
    try {
        var increment = 50;
        if (document.all) // if IE
        {
            if (iframe && document.frames[iframe.name] && document.frames[iframe.name].document && document.frames[iframe.name].document.body) {
                var newHeight = document.frames[iframe.name].document.body.scrollHeight;
                newHeight = (Math.floor((newHeight-1) / increment) + 1) * increment;
                iframe.style.height = newHeight;
            }
        }
        else {
            if (iframe && iframe.contentDocument.body) {
                var newHeight = getIFrameDocument(iframe).body.offsetHeight;
                newHeight = (Math.floor((newHeight-1) / increment) + 1) * increment;
                iframe.height = newHeight;
            }
        }
    }
    catch (err) {
    }
}

function eventKeyDownNumericOnly() {
    var str = event.srcElement.value + String.fromCharCode(event.keyCode) + "0";
    event.returnValue = !isNaN(str * 1);
}


function getIFrameDocument(frame) {
    var rv = null;
    // if contentDocument exists, W3C  compliant(e.g.Mozilla)
    if (frame.contentDocument)
        rv = frame.contentDocument;
    else // bad Internet Explorer  ;)
        rv = document.frames[aID].document;
    return rv;
}

