var g_strBase = "/XperLCMS";
String.prototype.replaceText=function(strOld,strNew)
{
	var strList = this.split(strOld);
	var strValue ="";
	for(var i=0;i<strList.length;i++)
	{
		if(i>0)
			strValue+=strNew;
		strValue+=strList[i];
	}
	return strValue;
}

String.prototype.trim = function ()
{
	var objRegExp = /^(\s*[¡¡]*[ ]*)$/;
	if(objRegExp.test(this))
	{
		var strValue = this.replace(objRegExp,'');
		if( strValue.length == 0 ) return strValue;
	}

	objRegExp = /^(\s*[¡¡]*[ ]*)([\w\W]*)(\b\s*[¡¡]*[ ]*$)/;
	if(objRegExp.test(this))
	{
		return this.replace(objRegExp,'$2');
	}

	return this;
}

function openPopUpWindow(strURL,strName,nWidth,nHeight)
{
	var strMsg	=	"can't open popup";
	//var strFeatures	=	"";
	
	var nTop=getCenterTop(nHeight);
	var nLeft = getCenterLeft(nWidth);
	
	var nToolbar=0;
	var nDirectory=0;
	var nFullscreen=0;

	var nLocation=0;
	var nMenubar =0;
	var nResizable =1;
	var nScrollbars = 0;		
	var nStatus  = 0;
	var nTitlebar = 0;
	strFeatures="top=" + nTop;
	strFeatures+=",left=" + nLeft;
	strFeatures+=",width=" + nWidth;
	strFeatures+=",height=" + nHeight;
	strFeatures+=",toolbar=" + nToolbar;
	strFeatures+=",directory=" + nDirectory;
	strFeatures+=",fullscreen=" + nFullscreen;
	strFeatures+=",location=" + nLocation;
	strFeatures+=",menubar=" + nMenubar;
	strFeatures+=",resizable=" + nResizable;
	strFeatures+=",scrollbars =" + nScrollbars;
	strFeatures+=",status = " + nStatus;
	strFeatures+=",titlebar=" + nTitlebar;
	var popWnd=window.open(strURL,strName,strFeatures);
	/*********************
	½ÇÆÐ½Ã ¸Þ¼¼Áö¸¦ ´øÁö°í ³ª°£´Ù.
	****************/
	if(popWnd==null)
	{
		alert(strMsg);
		return null;
	}
	popWnd.focus();
	return popWnd;

}

function getModalValue(strURL,objArg,width,height)
{
	if(typeof(strURL)=="undefined")
		return null;
	if(strURL=="")
		return null;

	strURL=encodeURI(strURL);
	strURL = strURL.replaceText("&","_AMP_");
	strURL=g_strBase+"/function/modalWindow.aspx?url="+strURL;
	var strParam = getDialogParameter(width,height)
	var objReturn= showModalDialog(strURL,objArg,strParam);
	if(typeof(objReturn)=="undefined")
		objReturn=null;
	return objReturn;

}

function getPackage()
{

	var strURL = g_strBase+"/LCMS/package/selectPackage.aspx";

	var objReturn = getModalValue(strURL,null,835,600);
	if(objReturn==null)
		return -1;
	return objReturn;
}

function getItems()
{
		var strURL = g_strBase+"/LCMS/package/selectItems.aspx";
		return getModalValue(strURL,null,835,600);
}
function getOrganizations()
{
	var strURL = g_strBase+"/LCMS/package/selectOrganization.aspx";

	return getModalValue(strURL,null,835,600);
}

function getDialogParameter(width,height)
{
	var nMaxWidth=width;
	var nMaxHeight=height;
	var nHeight=getMaxHeight()>nMaxHeight?nMaxHeight:screen.availHeight;
	var nWidth=getMaxWidth()>nMaxWidth?nMaxWidth:screen.availWidth;
	var strEdge="Raised";
	var strCenter="Yes";
	var strHelp="No";
	var strResizeable="No";
	var strStatus="No";
	var strParameter;
	strParamenter="dialogHeight:"+ nHeight +"px;";
	strParamenter+="dialogWidth:"+ nWidth +"px;";
	strParamenter+="edge:"+ strEdge +";";
	strParamenter+="center:"+ strCenter +";";
	strParamenter+="help:"+ strHelp +";";
	strParamenter+="resizable:"+ strResizeable +";";
	strParamenter+="status:"+ strStatus +";";
	return strParamenter;
}

function getCenterLeft(nWidth)
{
	var nAvail= getMaxWidth()-nWidth;
	if(nAvail<=0)
		return 0;
	return  Number(nAvail/2);

}

function getCenterTop(nHeight)
{
	var nAvail= getMaxHeight()-nHeight;
	if(nAvail<=0)
		return 0;
	return Number(nAvail/2);

}
function getMaxWidth()
{
	return screen.availWidth;
}
function getMaxHeight()
{
	return screen.availHeight-55;
}
function downloadCourses(strCourses)
{

    var Downloader = document.getElementById("cdownloader");
	if(Downloader==null)
	{
		alert("no downloader");
		return ;
	}
	var strPort = document.location.port.toString();
	if(strPort=="80"||strPort=="")
	    strPort="";
	else
	 {
	    Downloader.PORT= parseInt(strPort);
	    strPort=":"+strPort;
	 }
	Downloader.INFO_PAGE="http://"+document.domain+strPort+g_strWasURL+"/course/getCourseList.ashx";
	Downloader.ZIP_PAGE="http://"+document.domain+strPort+g_strWasURL+"/content/makeZip.ashx";
	Downloader.PACKAGE_CODE=strCourses;
	Downloader.Download();
}
/********************************************
                ÀÏ°ý¸ÅÇÎ
*********************************************/
function selectCourse(strParam)
{
	var strURL = g_strBase+ "/course/selectCourse.aspx?param="+strParam;
	objArray =  getModalValue(strURL,null,800,800)
	return objArray;
	/**
	for(objArray.length)
	{
	    obj=objArray[i];
	    obj.strTitle;
	    obj.strID;
	}
	**/
}
/********************************************
                °­¸ÅÇÎ
*********************************************/
function selectOrganization(strParam)
{
    var strURL = g_strBase+ "/course/selectOrganization.aspx?param="+strParam;
    var objOrg = getModalValue(strURL,null,800,810);
    return objOrg;
}
/********************************************
                °­°¡Á®¿À±â
*********************************************/
function selectOrganizations(strParam)
{
    var strURL = g_strBase+ "/course/selectOrganizations.aspx?param="+strParam;
    var objArray = getModalValue(strURL,null,800,850);
    return objArray;
}
/*******************************************************
    LCMS ÇÐ½ÀÇÏ±â
    LMS »ç¿ë¾ÈÇÔ
    crsid       :   °úÁ¤¾ÆÀÌµð
    man         :   ÄÁÅÙÃ÷¾ÆÀÌµð
    org         :   °­ÀÎ½Ä°ª
    item        :   ¾ÆÀÌÅÛÀÎ½Ä°ª
    nWidth      :   °¡·ÎÅ©±â
    nHeight     :   ¼¼·ÎÅ©±â
    lectwin     :   ÇÐ½ÀÃ¢¾ÆÀÌµð
    hquality    :   °íÈ­Áú/ÀúÈ­Áú
*******************************************************/
function studyCourse(usercode,lmskey1,lmskey2,crsid,man,org,item,nWidth,nHeight,lectwin,hquality)
{	
	var strURL =g_strBase+ "/cmi/?mode=100&usercode="+usercode+"&lmskey1="+lmskey1+"&lmskey2="+lmskey2+"&crsid="+crsid+"&man="+man+"&org="+org+"&item="+item+"&lectwin="+lectwin+"&hquality="+hquality;
	openPopUpWindow(strURL,"lectureWindow",nWidth,nHeight);
}
function resetLCMSCmi(usercode,crsid,lmskey1,lmskey2)
{
   var strURL = g_strBase+"/function/resetLCMSCmi.ashx";
   var strParam = "usercode="+usercode+"&crsid="+crsid+"&lmskey1="+lmskey1+"&lmskey2="+lmskey2;
   if(getWeb(strURL,strParam)=="true")
    return true;
   else 
    return false;
}
/*******************************************************
    LCMS ¹Ì¸®º¸±â 
    LMS »ç¿ë¾ÈÇÔ
    crsid       :   °úÁ¤¾ÆÀÌµð
    man         :   ÄÁÅÙÃ÷¾ÆÀÌµð
    org         :   °­ÀÎ½Ä°ª
    item        :   ¾ÆÀÌÅÛÀÎ½Ä°ª
    nWidth      :   °¡·ÎÅ©±â
    nHeight     :   ¼¼·ÎÅ©±â
    lectwin     :   ÇÐ½ÀÃ¢¾ÆÀÌµð
    hquality    :   °íÈ­Áú/ÀúÈ­Áú
*******************************************************/
function previewCourse(crsid,man,org,item,nWidth,nHeight,lectwin,hquality)
{	
	var strURL =g_strBase+ "/cmi/?mode=1&crsid="+crsid+"&man="+man+"&org="+org+"&item="+item+"&lectwin="+lectwin+"&hquality="+hquality;
	openPopUpWindow(strURL,"lectureWindow",nWidth,nHeight);
}
/*******************************************************
    °­ ¹Ì¸®º¸±â
    mapid       : ¸ÅÇÎ¾ÆÀÌµð
    nWidth      : °¡·ÎÅ©±â
    nHeight     : ¼¼·ÎÅ©±â
*******************************************************/
function previewLMSLesson(mapid,nWidth,nHeight)
{	
	var strURL =g_strBase+ "/cmi/?mode=3&mapid="+mapid;
	openPopUpWindow(strURL,"lectureWindow",nWidth,nHeight);
}
/*******************************************************
    ½ºÅÜ ¹Ì¸®º¸±â
    strLMSKey1  : ½ºÅÜ¾ÆÀÌµð
    strLMSKey2  : »ç¿ëÀÚ¾ÆÀÌµð
    mapid       : ¸ÅÇÎ¾ÆÀÌµð
    nWidth      : °¡·ÎÅ©±â
    nHeight     : ¼¼·ÎÅ©±â
*******************************************************/
function previewLMSStep(strLMSKey1,strLMSKey2,mapid,nWidth,nHeight)
{	
	var strURL =g_strBase+ "/cmi/?mode=5&lmskey1="+strLMSKey1+"&lmskey2="+strLMSKey2+"&mapid="+mapid;
	openPopUpWindow(strURL,"lectureWindow",nWidth,nHeight);
}
/*******************************************************
    ½ºÅÜ ¸Àº¸±â
    strLMSKey1  : ½ºÅÜ¾ÆÀÌµð
    strLMSKey2  : »ç¿ëÀÚ¾ÆÀÌµð
    mapid       : ¸ÅÇÎ¾ÆÀÌµð
    nWidth      : °¡·ÎÅ©±â
    nHeight     : ¼¼·ÎÅ©±â
*******************************************************/
function sampleviewLMSStep(strLMSKey1,strLMSKey2,mapid,nWidth,nHeight)
{	
	var strURL =g_strBase+ "/cmi/?mode=4&lmskey1="+strLMSKey1+"&lmskey2="+strLMSKey2+"&mapid="+mapid;
	openPopUpWindow(strURL,"lectureWindow",nWidth,nHeight);
}
/*******************************************************
    LMS ÇÐ½ÀÇÏ±â
    usercode    : ¼ö°­ÀÌ·Â¾ÆÀÌµð
    strLMSKey1  : ½ºÅÜ¾ÆÀÌµð
    strLMSKey2  : »ç¿ëÀÚ¾ÆÀÌµð
    mapid       : ¸ÅÇÎ¾ÆÀÌµð
    nWidth      : °¡·ÎÅ©±â
    nHeight     : ¼¼·ÎÅ©±â
*******************************************************/
function studyLMSStep(usercode,strLMSKey1,strLMSKey2,mapid,nWidth,nHeight)
{	
	var strURL =g_strBase+ "/cmi/?mode=0&usercode="+usercode+"&lmskey1="+strLMSKey1+"&lmskey2="+strLMSKey2+"&mapid="+mapid;
	openPopUpWindow(strURL,"lectureWindow",nWidth,nHeight);
}
