
// 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(form,Page){
  	 location=Page+"&Lang="+form.LangTraduite.options[form.LangTraduite.selectedIndex].value;
}


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
    {
        if (document.all) // if IE
        {
            if (iframe && document.frames[iframe.name] && document.frames[iframe.name].document && document.frames[iframe.name].document.body)
            {
                iframe.style.height = document.frames[iframe.name].document.body.scrollHeight;
            }
        }
        else
        {
            if (iframe && iframe.contentDocument.body)
            {
                iframe.style.height = iframe.contentDocument.body.scrollHeight;
            }
        }
    }
    catch (err)
    {
    }
}

function eventKeyDownNumericOnly() {
    var str = event.srcElement.value + String.fromCharCode(event.keyCode) + "0";
    event.returnValue = !isNaN(str * 1);
}
