//<!--
/*
このファイルの中身は、NTT オープンソースライセンス　バージョン 1.0（「本
契約」という）の適用を受けます。
本契約を遵守しない限り、このファイルを使用してはなりません。
本契約のコピーは、次のＵＲＬから入手できます。
【配布サイトのURL】 http://www.oss.ecl.ntt.co.jp/lms/

本契約に基づき頒布されるソフトウェアは、現状のまま、明示又は黙示のあらゆ
る種類の保証なしで、頒布されます。本契約に基づく権利及び制限を律する特定
の文言については、本契約を参照してください。

「オリジナルコード」は、 NTT Cyber Space Laboratories Code です。 
「オリジナルコード」の「初期開発者」は、日本電信電話株式会社です。  
日本電信電話株式会社により創作された部分は、Copyright (C) 2004 
日本電信電話株式会社 です。
全ての権利が留保されます。 
「コントリビュータ」：_____________________________________ 


The contents of this file are subject to the NTT Opensource License
Version 1.0 (the License); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
【配布サイトのURL】 http://www.oss.ecl.ntt.co.jp/lms/

Software distributed under the License is distributed on an AS IS
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific language governing rights and limitations
under the License.

The Original Code is NTT Cyber Space Laboratories Code .

The Initial Developer of the Original Code is NIPPON TELEGRAPH AND 
TELEPHONE CORPORATION.
Portions created by the NIPPON TELEGRAPH AND TELEPHONE CORPORATION 
are Copyright (C) 2004 NIPPON TELEGRAPH AND TELEPHONE CORPORATION. 
All Rights Reserved.

Contributor(s) ______________________________________.
*/
//-->

var version = "1.0";

function chg_str1(s){
	if(s == null){
		return "";
	}else{
		return decodeURIComponent(s);
	}
}

function chg_str2(s){
	if(s == null){
		return "";
	}else{
		return encodeURIComponent(s);
	}
}

var postURL;
var postStr;

function setAICC(sid,trg){
	postURL = location.protocol + "//" + trg;
	postStr = "&version=S1.3&session_id=" + sid;
}

function cmiPost(cmd,pStr){
	var postMSG = "command=" + cmd + postStr;

	var xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP");
	if (xmlhttp) {
		xmlhttp.open('POST', postURL, false);
		xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded")
		xmlhttp.send(postMSG + "&aicc_data=" + encodeURIComponent(pStr));
	}
	return xmlhttp.responseText;
}

function makeAjax(){
	this.setAICC = setAICC;
	this.cmiPost = cmiPost;
}

// オブジェクトはつくっておく
var Ajax = new makeAjax();


var sus_dlag = true;
// ---------------------------- start ---------------------------------------
function preRmvB(s){
	var spos,epos;
	s = s.replace(/\s+/g," ");
	spos = (s.charAt(0)==" ")?1:0;
	epos = (s.charAt(s.length-1)==" ")?s.length-1:s.length;
	return s.substring(spos,epos);
}


// ローカルの日付、時刻を返す関数
// in	文字列 d,t,etc
// out	m:1970/01/01からのmミリ秒を返す。
//	d:日付を返す。(YYYY/MM/DD)
//	t:時間を返す。(HH:MM:SS)
//	other:日付と時刻を返す。(YYYY/MM/DD HH:MM:SS)

function t_GetDT(s){
	var dA=new Array(2);var tA=new Array(2);
	var nowday = new Date();
	if(s=="m")return nowday.getTime();

	dA[0]=nowday.getFullYear();dA[1]=nowday.getMonth()+1;dA[2]=nowday.getDate();
	tA[0]=nowday.getHours();tA[1]=nowday.getMinutes();tA[2]=nowday.getSeconds();

	for(i=0;i<3;i++){
		if(dA[i]<=9)dA[i]="0"+dA[i];
		if(tA[i]<=9)tA[i]="0"+tA[i];
	}

	if(s=="d") return dA.join("/");
	else if(s=="t") return tA.join(":");
	else return dA.join("/") + " " + tA.join(":");
}

function t_GetST(n){
	var ms,ss,mm,hh,tmp;
	var num = Math.floor(n/10);

	ms = num % 100;
	num = Math.floor(num / 100);
	ss = num % 60;
	num = Math.floor(num / 60);
	mm = num % 60;
	num = Math.floor(num / 60);
	hh = num % 60;
	num = Math.floor(num / 60);

	if(ms <= 9)ms="0"+ms;
	if(ss <= 9)ss="0"+ss;
	if(mm <= 9)mm="0"+mm;
	if(hh <= 9)hh="000"+hh;
	else if(hh <= 99)hh="00"+hh;
	else if(hh <= 999)hh="0"+hh;

	return hh + ":" + mm + ":" + ss + "." + ms;
}

function t_GetMS(t){
	var num = 0;
	var buf = t.split(":");
	num += eval(buf[0] * 60 * 60 * 1000);
	num += eval(buf[1] * 60 * 1000);
	num += eval(buf[2] * 1000);
	return num;
}

function t_DelS(s,i){
	if(s!=""){
		if(i<0){
			s = s.substring(-i,s.length);
		}else{
			s = s.substring(0,s.length-i);
		}
	}
	return s;
}

function nullToEmp(s){
	if(s == null){
		return "";
	}else{
		return s;
	}
}

function t_DelCrLf(s){
	var pos = s.charAt(s.length - 1);
	while((pos == "\r")||(pos =="\n")){
		s = s.substring(0,s.length - 2);
		pos = s.charAt(s.length - 1);
	}
	return s;
}

function t_DelDQ(s){
	if(s.length<3){
		s = "";
	}else{
		s = s.substring(1,s.length-1);
	}
	return "";
}

function t_AddNode(dom,org,elm){
	if(org.selectSingleNode(elm)==null){
		var nn = dom.createElement(elm);
		org.appendChild(nn);
		return false;
	}else{
		return true;
	}
}

function t_AddText(dom,p,nn,s){
	var pn = dom.selectSingleNode(p)
	if(pn.selectSingleNode(nn)==null){
		var tn = dom.createElement(nn);
		tn.text = s;
		pn.appendChild(tn);
		return false;
	}else{
		return true;
	}
}

// ---------------------------- end ---------------------------------------
function RetErr(s){
	s = t_DelCrLf(s);
	this.error      = "";
	this.error_text = "";
	this.version    = "";
	var i,buf;
	s = s.replace("\r","");
	buf = s.split("\n");
	for(i=0;i<buf.length;i++){
		if(buf[i].indexOf("error=") == 0){
			this.error = parseInt(buf[i].replace("error=",""));
		}else if(buf[i].indexOf("error_text=") == 0){
			this.error_text = buf[i].replace("error_text=","");
		}else if(buf[i].indexOf("version=") == 0){
			this.version = buf[i].replace("version=","");
		}else{
			;
		}
	}
}

function RetSco(dom,s){
	s = t_DelCrLf(s);
	var root = dom.createElement("cmi");
	dom.appendChild(root);
	s = s.replace(/\r/g,"");
	var i,buf,mode;
	var suspend_data = "";
	var launch_data = "";
	var comments_data = "";

	buf = s.split("\n");
	for(i=0;i<buf.length;i++){
		if(buf[i]=="[Core]"){
			mode = 0;
		}else if(buf[i]=="[Core_Lesson]"){
			mode = 1;
		}else if(buf[i]=="[Core_Vendor]"){
			mode = 2;
		}else if(buf[i]=="[Comments]"){
			mode = 3;
		}else if(buf[i]=="[Evaluation]"){
			if(t_AddNode(dom,root,"evaluation")) return false;
			mode = 4;
		}else if(buf[i]=="[Objectives_Status]"){
			if(t_AddNode(dom,root,"objectives")) return false;
			mode = 5;
		}else if(buf[i]=="[Student_Data]"){
			mode = 6;
		}else if(buf[i]=="[Student_Demographics]"){
			if(t_AddNode(dom,root,"student_demographics")) return false;
			mode = 7;
		}else if(buf[i]=="[Student_Preferences]"){
			if(t_AddNode(dom,root,"learner_preference")) return false;
			mode = 8;
		}else{
			if(mode==0){if(SetCoreData(dom,buf[i])){alert(buf[i] + "\nError Core Data!");return false;}
			}else if(mode==1){
				if(buf[i] != ""){
					suspend_data += chg_str1(buf[i]);
				}
			}else if(mode==2){
				if(buf[i] != ""){
					launch_data += chg_str1(buf[i]);
				}
			}else if(mode==3){comments_data += buf[i] + "\r\n";
			}else if(mode==4){if(SetEvaData(dom,buf[i])){alert(buf[i] + "Error Evaluation Data!");return false;}
			}else if(mode==5){if(SetObjData(dom,buf[i])){alert(buf[i] + "Error Obj Data!");return false;}
			}else if(mode==6){if(SetStuData(dom,buf[i])){alert(buf[i] + "Error Student Data!");return false;}
			}else if(mode==7){if(SetDemoData(dom,buf[i])){alert(buf[i] + "Error Demo Data!");return false;}
			}else if(mode==8){if(SetPreData(dom,buf[i])){alert(buf[i] + "Error Pre Data!");return false;}
			}else{alert("Error SCO Init!");return false;}
		}
	}

	if(!sus_dlag){
		if(t_AddText(dom,"/cmi","suspend_data",chg_str1(suspend_data))){
			return false;
		}
	}

	if(t_AddText(dom,"/cmi","launch_data",chg_str1(launch_data)) || t_AddText(dom,"/cmi","comments",comments_data)){
		return false;
	}
	return true;
}

function RetCFL(dom,s){
	s = t_DelCrLf(s);
	s = s.replace(/\r/g,"");
	var i,buf,mode;
	buf = s.split("\n");
	if(buf.length<2){
		return true;
	}
	for(i=0;i<buf.length;i++){
		if(buf[i] == ""){
			;
		}else{
			buf[i] = t_DelDQ(buf[i]);
			tempbuf = buf[i].split('","');

			if(tempbuf.length != 3){
				return false;
			}else{
				tmpbuf[0] = chg_str1(tmpbuf[0]);
				tmpbuf[1] = chg_str1(tmpbuf[1]);
				tmpbuf[2] = chg_str1(tmpbuf[2]);
				t_AddText(dom,"/cmi/comments_from_lms/i" + (i - 1),"date_time", tmpbuf[0]);
				t_AddText(dom,"/cmi/comments_from_lms/i" + (i - 1),"location", tmpbuf[1]);
				t_AddText(dom,"/cmi/comments_from_lms/i" + (i - 1),"comment", tmpbuf[2]);
			}
		}
	}
	return true
}

function SetPreData(dom,s){
	if(s.indexOf("Audio=")==0){
		s = s.replace("Audio=","");
		if(s == ""){
			s = "1";
		}else{
			s = chg_str1(s);
		}
		return t_AddText(dom,"/cmi/learner_preference","audio_level", s);
	}else if(s.indexOf("Language=")==0){
		s = s.replace("Language=","");
		s = chg_str1(s);
		return t_AddText(dom,"/cmi/learner_preference","language",s);
	}else if(s.indexOf("Speed=")==0){
		s = s.replace("Speed=","");
		if(s == ""){
			s = "1";
		}else{
			s = chg_str1(s);
		}
		return t_AddText(dom,"/cmi/learner_preference","delivery_speed",s);
	}else if(s.indexOf("Text=")==0){
		s = s.replace("Text=","");
		if(s == ""){
			s = "0";
		}else{
			s = chg_str1(s);
		}
		return t_AddText(dom,"/cmi/learner_preference","audio_captioning",s);
	}else{return true;}
	return false;
}

function SetDemoData(dom,s){
	if(s.indexOf("City=")==0){s = s.replace("City=","");s = chg_str1(s);return t_AddText(dom,"/cmi/student_demographics","city",s);
	}else if(s.indexOf("Class=")==0){s = s.replace("Class=","");s = chg_str1(s);return t_AddText(dom,"/cmi/student_demographics","class",s);
	}else if(s.indexOf("Company=")==0){s = s.replace("Company=","");s = chg_str1(s);return t_AddText(dom,"/cmi/student_demographics","company",s);
	}else if(s.indexOf("Country=")==0){s = s.replace("Country=","");s = chg_str1(s);return t_AddText(dom,"/cmi/student_demographics","country",s);
	}else if(s.indexOf("Experience=")==0){s = s.replace("Experience=","");s = chg_str1(s);return t_AddText(dom,"/cmi/student_demographics","experience",s);
	}else if(s.indexOf("Familiar_Name=")==0){s = s.replace("Familiar_Name=","");s = chg_str1(s);return t_AddText(dom,"/cmi/student_demographics","familiar_name",s);
	}else if(s.indexOf("Instructor_Name=")==0){s = s.replace("Instructor_Name=","");s = chg_str1(s);return t_AddText(dom,"/cmi/student_demographics","instructor_name",s);
	}else if(s.indexOf("Job_Title=")==0){s = s.replace("Job_Title=","");s = chg_str1(s);return t_AddText(dom,"/cmi/student_demographics","title",s);
	}else if(s.indexOf("Native_Language=")==0){s = s.replace("Native_Language=","");s = chg_str1(s);return t_AddText(dom,"/cmi/student_demographics","native_language",s);
	}else if(s.indexOf("State=")==0){s = s.replace("State=","");s = chg_str1(s);return t_AddText(dom,"/cmi/student_demographics","state",s);
	}else if(s.indexOf("Street_Address=")==0){s = s.replace("Street_Address=","");s = chg_str1(s);return t_AddText(dom,"/cmi/student_demographics","street_address",s);
	}else if(s.indexOf("Telephone=")==0){s = s.replace("Telephone=","");s = chg_str1(s);return t_AddText(dom,"/cmi/student_demographics","telephone",s);
	}else if(s.indexOf("Years_Experience=")==0){s = s.replace("Years_Experience=","");s = chg_str1(s);return t_AddText(dom,"/cmi/student_demographics","years_experience",s);
	}else{return true;}
	return false;
}

function SetStuData(dom,s){
	if(s.indexOf("Attempt_Number=")==0){s = s.replace("Attempt_Number=","");s = chg_str1(s);return t_AddText(dom,"/cmi","attempt_number",s);
	}else if(s.indexOf("Mastery_Score=")==0){
		s = s.replace("Mastery_Score=","");
		s = chg_str1(s);
		if(s != ""){
			return t_AddText(dom,"/cmi","scaled_passing_score",s);
		}
	}else if(s.indexOf("Max_Time_Allowed=")==0){
		s = s.replace("Max_Time_Allowed=","");
		s = chg_str1(s);
		if(s != ""){
			s = ReBTime(s);
			return t_AddText(dom,"/cmi","max_time_allowed",s);
		}
	}else if(s.indexOf("Time_Limit_Action=")==0){
		s = s.replace("Time_Limit_Action=","");
		s = chg_str1(s);
		if(s == ""){
			s = "continue,no message";
		}
		return t_AddText(dom,"/cmi","time_limit_action",s);
	}else{return true;}
	return false;
}

function SetObjData(dom,s){
	var objNode = dom.selectSingleNode("/cmi/objectives");
	if(s.indexOf("J_ID.")==0){
		s = s.replace("J_ID.","")
		oa = s.split("=");
		oa[1] = chg_str1(oa[1]);
		t_AddNode(dom,objNode,"i" + (parseInt(oa[0]) - 1))
		return t_AddText(dom,"/cmi/objectives/i" + (parseInt(oa[0]) - 1),"id",oa[1])
	}else if(s.indexOf("J_Score.")==0){
		s = s.replace("J_Score.","")
		oa = s.split("=")
		oa[1] = chg_str1(oa[1]);
		t_AddNode(dom,objNode,"i" + (parseInt(oa[0]) - 1))
		objNode = objNode.selectSingleNode("i" + (parseInt(oa[0]) - 1));

		var tmp0,tmp1,tmp2,tmp3,tmp4;
		tmp0 = t_AddNode(dom,objNode,"score")
		if(oa[1] == ""){
			tmp1 = tmp2 = tmp3 = tmp4 = "";
		}else{
			var buf = oa[1].split(",");
			if(buf.length == 2){
				if(buf[0] != "")t_AddText(dom,"/cmi/objectives/i" + (parseInt(oa[0]) - 1) + "/score","scaled",buf[0]);
				if(buf[1] != "")t_AddText(dom,"/cmi/objectives/i" + (parseInt(oa[0]) - 1) + "/score","raw",buf[1]);
			}else if(buf.length == 3){
				if(buf[0] != "")t_AddText(dom,"/cmi/objectives/i" + (parseInt(oa[0]) - 1) + "/score","scaled",buf[0]);
				if(buf[1] != "")t_AddText(dom,"/cmi/objectives/i" + (parseInt(oa[0]) - 1) + "/score","raw",buf[1]);
				if(buf[2] != "")t_AddText(dom,"/cmi/objectives/i" + (parseInt(oa[0]) - 1) + "/score","max",buf[2]);
			}else if(buf.length == 4){
				if(buf[0] != "")t_AddText(dom,"/cmi/objectives/i" + (parseInt(oa[0]) - 1) + "/score","scaled",buf[0]);
				if(buf[1] != "")t_AddText(dom,"/cmi/objectives/i" + (parseInt(oa[0]) - 1) + "/score","raw",buf[1]);
				if(buf[2] != "")t_AddText(dom,"/cmi/objectives/i" + (parseInt(oa[0]) - 1) + "/score","max",buf[2]);
				if(buf[3] != "")t_AddText(dom,"/cmi/objectives/i" + (parseInt(oa[0]) - 1) + "/score","min",buf[3]);
			}else{
				return true;
			}
		}
		return false;
	}else if(s.indexOf("J_Status.")==0){
		s = s.replace("J_Status.","")
		oa = s.split("=");
		oa[1] = chg_str1(oa[1]);
		var tbuf = oa[1].split(",");
		t_AddNode(dom,objNode,"i" + (parseInt(oa[0]) - 1))
		if(tbuf.length == 2){
			t_AddText(dom,"/cmi/objectives/i" + (parseInt(oa[0]) - 1),"success_status",tbuf[0]);
			t_AddText(dom,"/cmi/objectives/i" + (parseInt(oa[0]) - 1),"status",tbuf[1]);
		}else{
			t_AddText(dom,"/cmi/objectives/i" + (parseInt(oa[0]) - 1),"success_status",tbuf[0]);
		}
	}
	return false;
}


function SetEvaData(dom,s){
	if(s.indexOf("Course_ID=")==0){s = s.replace("Course_ID=","");s = chg_str1(s);return t_AddText(dom,"/cmi/evaluation","course_id",s);
	}else if(s.indexOf("Comments_File=")==0){
	}else if(s.indexOf("Interactions_File=")==0){
	}else if(s.indexOf("Objectives_Status_File=")==0){
	}else if(s.indexOf("Path_File=")==0){
	}else if(s.indexOf("Performance_File=")==0){
	}else{return true;}
	return false;
}

var Entry = new Array();
Entry["a"] = "ab-initio";
Entry["r"] = "resume";
Entry["n"] = "";

var Credit = new Array();
Credit["c"] = "credit";
Credit["n"] = "no-credit"


function SetCoreData(dom,s){
	if(s.indexOf("Student_ID=")==0){
		s = s.replace("Student_ID=","");
		s = chg_str1(s);
		return t_AddText(dom,"/cmi","learner_id",s);
	}else if(s.indexOf("Student_Name=")==0){
		s = s.replace("Student_Name=","");
		s = chg_str1(s);
		return t_AddText(dom,"/cmi","learner_name",s);
	}else if(s.indexOf("Output_File=")==0){
	}else if(s.indexOf("Credit=")==0){
		s = s.replace("Credit=","");
		s = chg_str1(s);
		if(s == "") s = "n";
		s = s.charAt(0).toLowerCase();
		return t_AddText(dom,"/cmi","credit",Credit[s]);
	}else if(s.indexOf("Lesson_ID=")==0){
	}else if(s.indexOf("Lesson_Location=")==0){
		s = s.replace("Lesson_Location=","");
		s = chg_str1(s);
		return t_AddText(dom,"/cmi","location",s);
	}else if(s.indexOf("Lesson_Status=")==0){
		s = s.replace("Lesson_Status=","");
		s = chg_str1(s);
		var buf = s.split(",");
		if(buf.length == 3){
			if((buf[2].length != 0)&&(buf[2].charAt(0) == "r")){
				t_AddText(dom,"/cmi","success_status",buf[0]);
				t_AddText(dom,"/cmi","completion_status",buf[1]);
				t_AddText(dom,"/cmi","entry","resume");
				sus_dlag = false;
			}else{
				t_AddText(dom,"/cmi","success_status","unknown");
				t_AddText(dom,"/cmi","completion_status","unknown");
				t_AddText(dom,"/cmi","entry",buf[2]);
			}
		}else{
			return true;
		}
	}else if(s.indexOf("Path=")==0){
	}else if(s.indexOf("Score=")==0){
		if(!sus_dlag){
			s = s.replace("Score=","");
			s = chg_str1(s);
			var tmp0,tmp1,tmp2,tmp3,tmp4;
			tmp0 = t_AddNode(dom,dom.selectSingleNode("/cmi"),"score");
			tmp1 = tmp2 = tmp3 = tmp4 = "";
			var buf = s.split(",");
			if(buf.length == 2){
				if(buf[0] != "")t_AddText(dom,"/cmi/score","scaled",buf[0]);
				if(buf[1] != "")t_AddText(dom,"/cmi/score","raw",buf[1]);
			}else if(buf.length == 3){
				if(buf[0] != "")t_AddText(dom,"/cmi/score","scaled",buf[0]);
				if(buf[1] != "")t_AddText(dom,"/cmi/score","raw",buf[1]);
				if(buf[2] != "")t_AddText(dom,"/cmi/score","max",buf[2]);
			}else if(buf.length == 4){
				if(buf[0] != "")t_AddText(dom,"/cmi/score","scaled",buf[0]);
				if(buf[1] != "")t_AddText(dom,"/cmi/score","raw",buf[1]);
				if(buf[2] != "")t_AddText(dom,"/cmi/score","max",buf[2]);
				if(buf[3] != "")t_AddText(dom,"/cmi/score","min",buf[3]);
			}else{
				return true;
			}
		}
		return false;
	}else if(s.indexOf("Time=")==0){
		s = s.replace("Time=","");
		if(s == ""){
			s = "PT0H0M0S";
		}else{
			s = chg_str1(s);
		}
		return t_AddText(dom,"/cmi","total_time",s);
	}else if(s.indexOf("Lesson_Mode=")==0){
		s = s.replace("Lesson_Mode=","");
		return t_AddText(dom,"/cmi","mode",s);
	}else if(s.indexOf("Completion_Threshold=")==0){
		s = s.replace("Completion_Threshold=","");
		if(s != ""){
			s = chg_str1(s);
			return t_AddText(dom,"/cmi","completion_threshold",s);
		}
	}else if(s.indexOf("Progress_Measure=")==0){
		s = s.replace("Progress_Measure=","");
		if(s != ""){
			s = chg_str1(s);
			return t_AddText(dom,"/cmi","progress_measure",s);
		}
	}else{
		return true;
	}
}

function ReBTime(s){
	var buf = s.split(":");
	if(buf[0].length == 2){
		buf[0] = "00" + buf[0];
	}else if(buf[0].length == 3){
		buf[0] = "0" + buf[0];
	}
	return buf.join(":");
}

function makeAdapter(){
	this.DM = new ActiveXObject("Microsoft.XMLDOM");
	this.mrt;
	this.ADPInit = ADPInit;
	this.SCOInit = SCOInit;
	this.SCOFin = SCOFin;
	this.GetLimitTime = GetLimitTime;
	this.sco_GetValue = sco_GetValue;
	this.sco_GetValueM = sco_GetValueM;
	this.sco_GetCount = sco_GetCount;
	this.sco_Double = sco_Double;
	this.sco_SetValue = sco_SetValue;
	this.sco_GetNode = sco_GetNode;
	this.sco_Commit = sco_Commit;
	this.sco_SetObjID = sco_SetObjID;
	this.SCO = null;
	this.stime = 0;
	this.flgWrite = 0;

	
	this.dm_CheckModel = dm_CheckModel;
	this.dm_CheckChildren = dm_CheckChildren;
	this.dm_CheckVersion = dm_CheckVersion;
	this.dm_CheckCount = dm_CheckCount;
	this.dm_RetDefValue = dm_RetDefValue;
	this.dm_CheckData = dm_CheckData;
	this.dm_CheckValue = dm_CheckValue;
}

var ver;
function ADPInit(){
	this.DM.async = false;
	var xmlStr = '<?xml version="1.0"?><cmi><comments_from_learner><n><comment st="rw" dt="CMIString4096C"/><location st="rw" dt="CMIString256"/><timestamp st="rw" dt="CMITime"/>'
	xmlStr += '</n></comments_from_learner><comments_from_lms><n><comment st="r" dt="CMIString4096C"/><location st="r" dt="CMIString256"/><timestamp st="r" dt="CMITime"/></n>'
	xmlStr += '</comments_from_lms><completion_status st="rw" dt="CMIVocabulary"><kw>completed</kw><kw>incomplete</kw><kw>not attempted</kw><kw def="t">unknown</kw></completion_status>'
	xmlStr += '<completion_threshold st="r" dt="CMIPReal7_1"/><credit st="r" dt="CMIVocabulary"><kw def="t">credit</kw><kw>no-credit</kw></credit><entry st="r" dt="CMIVocabulary">'
	xmlStr += '<kw def="t">ab-initio</kw><kw>resume</kw><kw/></entry><exit st="w" dt="CMIVocabulary"><kw>time-out</kw><kw>suspend</kw><kw>logout</kw><kw>normal</kw><kw def="t"/>'
	xmlStr += '</exit><interactions><n><id st="rw" dt="CMIString4096I"/><type st="rw" dt="CMIVocabulary"><kw def="t">true-false</kw><kw>choice</kw><kw>fill-in</kw><kw>long-fill-in</kw>'
	xmlStr += '<kw>likert</kw><kw>matching</kw><kw>performance</kw><kw>sequencing</kw><kw>numeric</kw><kw>other</kw></type><objectives><n><id st="rw" dt="CMIString4096I"/></n></objectives>'
	xmlStr += '<timestamp st="rw" dt="CMITime"/><correct_responses><n><pattern st="rw" dt="CMIString4096R"/></n></correct_responses><weighting st="rw" dt="CMIReal7"/><learner_response st="rw" dt="CMIString4096R"/>'
	xmlStr += '<result st="rw" dt="SCERESULT"><kw>correct</kw><kw>incorrect</kw><kw>unanticipated</kw><kw>neutral</kw></result><latency st="rw" dt="CMITimespan"/><description st="rw" dt="CMIString256"/></n></interactions>'
	xmlStr += '<launch_data st="r" dt="CMIString4096"/><learner_id st="r" dt="CMIString4096I"/><learner_name st="r" dt="CMIString256"/><learner_preference><audio_level st="rw" dt="CMIPReal7"/>'
	xmlStr += '<language st="rw" dt="CMILang"/><delivery_speed st="rw" dt="CMIPReal7"/><audio_captioning st="rw" dt="CMIVocabulary"><kw>-1</kw><kw def="t">0</kw><kw>1</kw></audio_captioning>'
	xmlStr += '</learner_preference><location st="rw" dt="CMIString1000"/><max_time_allowed st="r" dt="CMITimespan"/><mode st="r" dt="CMIVocabulary"><kw>browse</kw><kw def="t">normal</kw><kw>review</kw>'
	xmlStr += '</mode><objectives><n><id st="rw" dt="CMIString4096I"/><score><scaled st="rw" dt="CMIReal7_1"/><raw st="rw" dt="CMIReal7"/><max st="rw" dt="CMIReal7"/><min st="rw" dt="CMIReal7"/></score>'
	xmlStr += '<success_status st="rw" dt="CMIVocabulary"><kw>passed</kw><kw>failed</kw><kw def="t">unknown</kw></success_status><completion_status st="rw" dt="CMIVocabulary"><kw>completed</kw><kw>incomplete</kw>'
	xmlStr += '<kw>not attempted</kw><kw def="t">unknown</kw></completion_status><progress_measure st="rw" dt="CMIPReal7_1"/><description st="rw" dt="CMIString256"/></n></objectives><progress_measure st="rw" dt="CMIPReal7_1"/>'
	xmlStr += '<scaled_passing_score st="r" dt="CMIReal7_1"/><score><scaled st="rw" dt="CMIReal7_1"/><raw st="rw" dt="CMIReal7"/><max st="rw" dt="CMIReal7"/><min st="rw" dt="CMIReal7"/></score><session_time st="w" dt="CMITimespan"/>'
	xmlStr += '<success_status st="rw" dt="CMIVocabulary"><kw>passed</kw><kw>failed</kw><kw def="t">unknown</kw></success_status><suspend_data st="rw" dt="CMIString4096"/><time_limit_action st="r" dt="CMIVocabulary">'
	xmlStr += '<kw>exit,message</kw><kw>exit,no message</kw><kw>continue,message</kw><kw def="t">continue,no message</kw></time_limit_action><total_time st="r" dt="CMITimespan"/></cmi>'
	this.DM.loadXML(xmlStr);
	return (this.DM.xml=="")?true:false;
}

function SCOInit(sid,trg){
	Ajax.setAICC(sid,trg);
	gStr = Ajax.cmiPost("GetParam", "");
	var mp,buf;
	mp = gStr.indexOf("aicc_data=");
	if(mp == -1) return null;
	var eStr = gStr.substring(0,mp);
	var aStr = gStr.substring(mp + 10,gStr.length);
	var AiccErr = new RetErr(eStr);
	if(AiccErr.error != 0){
		alert("aicc response error!");
		return false;
	}

	this.SCO = new ActiveXObject("Microsoft.XMLDOM");
	if(!RetSco(this.SCO,aStr)){
		alert("Error SCO Init");
		return 0;
	}
	var cStr = Ajax.cmiPost("GetLMSComments", "");

	mp = cStr.indexOf("aicc_data=");
	if(mp == -1) return null;
	var ceStr = cStr.substring(0,mp);

	var caStr = cStr.substring(mp + 10,cStr.length);
	var cAiccErr = new RetErr(ceStr);
	if(cAiccErr.error != 0){
		alert("aicc commnets response error!");
		return false;
	}

	if(!RetCFL(this.SCO,caStr)){
		alert("Error SCO Init");
		return 0;
	}
	

	this.stime = t_GetDT("m");
	this.flgWrite = 1;
	return 1;
}

function SCOFin(){
	if(this.stime){
		var etime = t_GetDT("m");
		var ttime = etime - this.stime;
	}
	ADP.sco_Commit(1);
	return 1;
}

function sco_Commit(num){
	var sData = "";
	var eStr,tmp,i,j,buf,raw,max,min,n;

	if(this.flgWrite){
		sData = "[Core]" + "\r\n";
		sData += "Lesson_Location=" + chg_str2(this.sco_GetValue("cmi.location")) + "\r\n";

		tmp = this.sco_GetValue("cmi.exit");
		if(tmp==null){
			tmp = "";
		}

		var bss = this.sco_GetValue("cmi.success_status");
		var bcs = this.sco_GetValue("cmi.completion_status");

		var tmps1,tmps2,tmps3,tmps4;
		tmps1 = this.sco_GetValue("cmi.score.scaled");
		tmps2 = this.sco_GetValue("cmi.score.raw");
		tmps3 = this.sco_GetValue("cmi.score.max");
		tmps4 = this.sco_GetValue("cmi.score.min");

		var mscore = this.sco_GetValue("cmi.scaled_passing_score");
		if((mscore != null)&&(tmps1 != null)){
			if(eval(tmps1) >= eval(mscore)){
				bss = "passed";
			}
		}

		var mmj = this.sco_GetValue("cmi.completion_threshold");
		var tmpc1 = this.sco_GetValue("cmi.progress_measure");
		if((mscore != null)&&(tmpc1 != null)){
			if(eval(tmpc1) >= eval(mmj)){
				bcs = "completed";
			}
		}

		sData += "Lesson_Status=" + chg_str2(bss + "," + bcs + "," + tmp) + "\r\n";
		if(tmps4 != null){
			sData += "Score=" + chg_str2(nullToEmp(tmps1) + "," + nullToEmp(tmps2) + "," + nullToEmp(tmps3) + "," + nullToEmp(tmps4)) + "\r\n";
		}else if(tmps3 != null){
			sData += "Score=" + chg_str2(nullToEmp(tmps1) + "," + nullToEmp(tmps2) + "," + nullToEmp(tmps3)) + "\r\n";
		}else if(tmps2 != null){
			sData += "Score=" + chg_str2(nullToEmp(tmps1) + "," + nullToEmp(tmps2)) + "\r\n";
		}else if(tmps1 != null){
			sData += "Score=" + chg_str2(nullToEmp(tmps1) + ",") + "\r\n";
		}else{
			sData += "Score=" + chg_str2(",") + "\r\n";
		}
		tmp = this.sco_GetValue("cmi.session_time");

		if(tmp==null){
			;
		}else{
			sData += "Time=" + chg_str2(tmp) + "\r\n";
		}
		sData += "[Core_Lesson]" + "\r\n";
		sData += chg_str2(this.sco_GetValue("cmi.suspend_data")) + "\r\n";
		sData += "[Comments]" + "\r\n";

		sData += "[Objectives_Status]" + "\r\n";

		m = dm_RepS("cmi.objectives");
		pn = this.SCO.selectSingleNode(m);
		if(pn != null){
			cnl = pn.childNodes;

			for(i=0;i<cnl.length;i++){
				tagname = cnl.item(i).tagName;
				if(tagname.match(/^i{1}\d+/) != null){
					if(cnl.item(i).getAttribute("f_chg") == "1"){
						tagname = tagname.replace("i","");
						ptagname = parseInt(tagname) + 1;
						pathName = "cmi.objectives.i";
						if(this.sco_GetValue(pathName + tagname + ".id") != null){
							sData += "J_ID." + ptagname + "=" + chg_str2(this.sco_GetValue(pathName + tagname + ".id")) + "\r\n";
						}
						var os0,os1,os2,os3;
						os0 = this.sco_GetValue(pathName + tagname + ".score.scaled");
						os1 = this.sco_GetValue(pathName + tagname + ".score.raw");
						os2 = this.sco_GetValue(pathName + tagname + ".score.max");
						os3 = this.sco_GetValue(pathName + tagname + ".score.min");
						if(os0 == null)os0 = "";
						if(os1 == null)os1 = "";
						if(os2 == null)os2 = "";
						if(os3 == null)os3 = "";
						if(os3 != ""){
							sData += "J_Score." + ptagname + "=" + chg_str2(os0 + "," + os1 + "," + os2 + "," + os3) + "\r\n";
						}else if(os2 != ""){
							sData += "J_Score." + ptagname + "=" + chg_str2(os0 + "," + os1 + "," + os2) + "\r\n";
						}else if(os1 != ""){
							sData += "J_Score." + ptagname + "=" + chg_str2(os0 + "," + os1) + "\r\n";
						}else if(os0 != ""){
							sData += "J_Score." + ptagname + "=" + chg_str2(os0 + ",") + "\r\n";
						}
						var ss0,ss1;
						ss0 = this.sco_GetValue(pathName + tagname + ".success_status");
						ss1 = this.sco_GetValue(pathName + tagname + ".completion_status");
						if(ss0 == null)ss0 = "unknown";
						if(ss1 == null)ss1 = "unknown";

						if((ss0 != "")||(ss1 !="")){
							sData += "J_Status." + ptagname + "=" + chg_str2(ss0 + "," + ss1) + "\r\n";
						}
						post_ResetFlag("cmi.objectives.i" + tagname);
					}
				}
			}
		}

		sData += "[Student_Data]" + "\r\n";
		sData += "[Student_Preferences]" + "\r\n";
		sData += "Audio=" + chg_str2(this.sco_GetValue("cmi.learner_preference.audio_level")) + "\r\n";
		sData += "Language=" + chg_str2(this.sco_GetValue("cmi.learner_preference.language")) + "\r\n";
		sData += "Speed=" + chg_str2(this.sco_GetValue("cmi.learner_preference.delivery_speed")) + "\r\n";
		sData += "Text=" + chg_str2(this.sco_GetValue("cmi.learner_preference.audio_captioning")) + "\r\n";

		eStr = Ajax.cmiPost("PutParam",sData);
		var AiccErr = new RetErr(eStr);
		if(AiccErr.error != 0){
			alert("PurParam error!");
			return false;
		}


		sData = '"Date","Interaction_ID","Objective_ID","Type_Interaction","Correct_Response","Student_Response","Result","Weighting","Latency","Description"' + "\r\n";

		m = dm_RepS("cmi.interactions");
		pn = this.SCO.selectSingleNode(m);
		if(pn != null){
			var iwflg = false;
			cnl = pn.childNodes;
			pathName = "cmi.interactions.i";
			for(i=0;i<cnl.length;i++){
				tagname = cnl.item(i).tagName;
				if(tagname.match(/^i{1}\d+/) != null){
					iwflg = true;
					if(cnl.item(i).getAttribute("f_chg") == "1"){
						tagname = tagname.replace("i","");
						sData += '"' + chg_str2(post_GetValue(pathName + tagname + ".timestamp")) + '","';
						sData += chg_str2(post_GetValue(pathName + tagname + ".id")) + '","';

						var temp = post_GetMultiValue(pathName + tagname + ".objectives","id");
						if(temp != null){
							sData += chg_str2(temp) + '","';
						}else{
							sData += '","';
						}

						sData += chg_str2(post_GetValue(pathName + tagname + ".type")) + '","';

						temp = post_GetMultiValue(pathName + tagname + ".correct_responses","pattern");
						if(temp != null){
							sData += chg_str2(temp) + '","';
						}else{
							sData += '","';
						}

						sData += chg_str2(post_GetValue(pathName + tagname + ".learner_response")) + '","';
						sData += chg_str2(post_GetValue(pathName + tagname + ".result")) + '","';
						sData += chg_str2(post_GetValue(pathName + tagname + ".weighting")) + '","';
						sData += chg_str2(post_GetValue(pathName + tagname + ".latency")) + '","';
						sData += chg_str2(post_GetValue(pathName + tagname + ".discription")) + '"\r\n';

						post_ResetFlag("cmi.interactions.i" + tagname);
					}
				}
			}

			if(iwflg){
				eStr = Ajax.cmiPost("PutInteractions",sData);
				var AiccErr = new RetErr(eStr);
				if(AiccErr.error != 0){
					alert("PutInteractions error!");
					return false;
				}
			}

		}

		sData = '"Date","Location","Comment"\r\n';
		var owflg = false;
		m = dm_RepS("cmi.comments_from_learner");

		pn = this.SCO.selectSingleNode(m);
		if(pn != null){
			cnl = pn.childNodes;
			pathName = "cmi.comments_from_learner.i";
			for(i=0;i<cnl.length;i++){
				tagname = cnl.item(i).tagName;
				if(tagname.match(/^i{1}\d+/) != null){
					owflg = true;
					tagname = tagname.replace("i","");
					sData += '"' + chg_str2(post_GetValue(pathName + tagname + ".date_time")) + '","';
					sData += chg_str2(post_GetValue(pathName + tagname + ".location")) + '","';
					sData += chg_str2(post_GetValue(pathName + tagname + ".comment")) + '"\r\n';
				}
			}

			if(owflg){
				eStr = Ajax.cmiPost("PutComments",sData);
				var AiccErr = new RetErr(eStr);
				if(AiccErr.error != 0){
					alert("PutComments error!");
					return false;
				}
			}

		}
		this.flgWrite = 0;
	}

	if(num){
		eStr = Ajax.cmiPost("ExitAU","");
		var AiccErr = new RetErr(eStr);
		if(AiccErr.error != 0){
			alert("ExitAU error!");
			return false;
		}
	}
	return true;
}

function GetLimitTime(){
	var lt,tt;
	lt = this.sco_GetValue("cmi.max_time_allowed");
	if (lt == null)
		return 0;
	lt = t_GetMS(lt);
	tt = this.sco_GetValue("cmi.total_time");
	tt = (tt == null)?0:t_GetMS(tt);
	lt -= tt;
	if(lt <= 0)
		lt = 1;
	return lt;
}

function sco_GetValue(m){
	m = dm_RepS(m);
	var n = this.SCO.selectSingleNode(m);
	return (n==null)?null:n.text;
}

function sco_GetValueM(m){
	var n = this.SCO.selectSingleNode(m);
	return (n==null)?null:n.text;
}

function sco_GetCount(m){
	m = dm_RepS(m);
	m = m.replace("/_count","");
	var n = this.SCO.selectSingleNode(m);
	if(n==null){
		return 0;
	}else{
		var cn = n.childNodes;
		return cn.length;
	}
}

function sco_SetValue(m,s,f){
	if(!f){
		if(m=="cmi.session_time"){
			this.stime = 0;
		}
	}
	m = dm_RepS(m);

	var i,tn,nn,cn;
	var ncnt = 0;
	var buf = m.split("/");
	cn = this.SCO;
	for(i=0;i<buf.length;i++){
		tn = cn.selectSingleNode(buf[i]);
		if(tn==null){
			nn = this.SCO.createElement(buf[i]);
			cn.appendChild(nn);
			cn = nn;
		}else{
			cn = tn;
		}

		if(buf[i].match(/^i{1}\d+/) != null){
			ncnt++;
			if(ncnt == 1)
				cn.setAttribute("f_chg", "1");
		}
	}
	cn.text = s;
	this.flgWrite = 1;
}

function dm_RepG(m){
	var i;
	var buf = m.split(".");
	for(i in buf)
		if(!isNaN(buf[i]))
			buf[i] = "n";
	return "/" + buf.join("/");
}

function dm_RepS(m){
	var i;
	var buf = m.split(".");
	for(i in buf)
		if(!isNaN(buf[i]))
			buf[i] = "i" + buf[i];

	return buf.join("/");
}

function dm_CheckModel(m){return  ADP.mrt.selectSingleNode(m);}

function dm_CheckData(m,f){
	m = dm_RepG(m);
	var ret;
	var n = this.dm_CheckModel(m);
	if(n==null){
		return null;
	}else{
		ret = n.getAttribute("st");
		if(ret==null)
			return null;
		else if((ret=="w")&&(!f))
			return 0;
		else if((ret=="r")&&(f))
			return 0;
		else
			return n.getAttribute("dt");
	}
}

function dm_CheckChildren(mm){
	var m = dm_RepG(mm);
	m = m.replace("/_children","");

	var i;
	var ret = "";
	var n = this.dm_CheckModel(m);
	if(n==null){
		return null;
	}else{
		n = n.childNodes;
		for(i=0;i<n.length;i++)
			ret += n.item(i).nodeName + ",";
		ret =  t_DelS(ret,1);
		if(ret == "n"){
			return dm_CheckChildren(mm+ ".n");
		}else{
			return ret;
		}
	}
}

function dm_CheckVersion(m){
	m = dm_RepG(m);
	m = m.replace("/_version","");
	var n = this.dm_CheckModel(m);
	return (n==null)?null:1;
}

function dm_CheckCount(m){
	m = dm_RepG(m);
	m = m.replace("/_count","");
	var n = this.dm_CheckModel(m);
	if(n==null){
		return null;
	}else{
		n = n.selectSingleNode("n");
		return (n==null)?0:1;
	}
}

function dm_RetDefValue(v,m){
	if((v=="CMIString255")||(v=="CMIString256")||(v=="CMIString1000")||(v=="CMIString4096")||(v=="CMIString4096C")||(v=="CMIString4096I")||(v=="CMIString4096R")||(v=="CMIBlank")||(v=="SCESCORE0")){
		ret = "";
	}else if((v=="CMIDecimal")||(v=="CMIInteger")||(v.indexOf("CMISInteger")!=-1)){
		ret = 0;
	}else if(v=="CMITimespan"){
		ret = "0000:00:00.00";
	}else if(v=="CMIVocabulary"){
		m = dm_RepG(m)
		ret = this.mrt.selectSingleNode(m + '/kw[@def="t"]').text;
	}else{
		ret = null;
	}
	return ret;
}

function dm_CheckValue(t,s,m){
	var f = false;
	if(t=="CMIIdentifier"){
		f = Check_CMIIdentifier(s);
	}else if(t=="CMILongIdentifier"){
		f = Check_CMILongIdentifier(s);
	}else if(t=="CMIReal7"){
		if(!isNaN(s)){
			if(0 <= eval(s)){
				f = true
			}else{
				_setLastError("407");
				f = false;
			}
		}else{
			f = false;
		}
	}else if(t=="CMIReal7_1"){
		if(!isNaN(s)){
			if(Math.abs(eval(s)) <= 1){
				f = true
			}else{
				_setLastError("407");
				f = false;
			}
		}else{
			f = false;
		}
	}else if(t=="CMIPReal7"){
		if(!isNaN(s)){
			if(0 <= eval(s)){
				f = true
			}else{
				_setLastError("407");
				f = false;
			}
		}else{
			f = false;
		}
	}else if(t=="CMIPReal7_1"){
		if(!isNaN(s)){
			if((0 <= eval(s))&&(eval(s) <= 1)){
				f = true
			}else{
				_setLastError("407");
				f = false;
			}
		}
	}else if(t=="CMILang"){
		if(s == ""){
			f = true;
		}else{
			f = chk_localLang("{lang=" + s + "}",0);
		}
	}else if(t=="CMIString255"){
		f = Check_CMIString255(s);
	}else if(t=="CMIString256"){
		f = Check_CMIString256(s);
	}else if(t=="CMIString1000"){
		f = Check_CMIString1000(s);
	}else if(t=="CMIString4096"){
		f = Check_CMIString4096(s);
	}else if(t=="CMIString4096C"){
		f = Check_CMIString4096C(s);
	}else if(t=="CMIString4096I"){
		f = Check_CMIString4096I(s);
	}else if(t=="CMIString4096R"){
		f = true;
	}else if(t=="CMIVocabulary"){
		f = Check_CMIVocabulary(s,m);
	}else if(t=="CMITimespan"){
		f = Check_CMITimespan(s);
	}else if(t=="CMITime"){
		f = Check_CMITime(s);
	}else if(t=="SCERESULT"){
		f = (Check_CMIVocabulary(s,m) || Check_CMIDecimal(s));
	}
	return f;
}

function Check_CMIVocabulary(s,m){
	var i;
	m = dm_RepG(m) + "/kw";
	var n  = ADP.mrt.selectNodes(m);
	for(i=0;i<n.length;i++){
		if(n.item(i).text == s){
			return true;
		}
	}
	return false;
}

// check_CMIBlank
function Check_CMIBlank(s){return (s=="")?true:false;}

// check_CMIBoolean
function Check_CMIBoolean(s){return ((s == "true") || (s == "false"))?true:false;}

// check_CMIDecimal
function Check_CMIDecimal(s){
	if((s=="")||(s.match(/[^-?\d\.]/) != null))return false;
	return (isNaN(s))?false:true;
}

// check_CMIIdentifier
function Check_CMIIdentifier(s){
	return ((s.match(/\s/) == null) && (s.length < 256) && (s != ""))?true:false;
}

function Check_CMILongIdentifier(s){
	if(s.length > 4000){
		return false;
	}
	var exp = /^urn:[\w]+:[\w]+$/;
	return exp.test(s);
}

function Check_Real7(s){
	if(s == ""){
		return false;
	}

	if(s.indexOf("E") != -1){
		return false;
	}

	if(s.length > 2){
		if((s.charAt(0)=="0")&&(s.charAt(1)!=".")){
			return false;
		}
	}

	if(isNaN(s)){
		return false;
	}
	return true;
}

function Check_PReal7(s){
	if(s == ""){
		return false;
	}

	if(s.charAt(0)=="-"){
		return false;
	}

	if(s.indexOf("E") != -1){
		return false;
	}

	if(s.length > 2){
		if((s.charAt(0)=="0")&&(s.charAt(1)!=".")){
			return false;
		}
	}

	if(isNaN(s)){
		return false;
	}

	return true;
}

// check_CMIString255
function Check_CMIString255(s){return (s.length < 201)?true:false;}

// check_CMIString256
function Check_CMIString256(s){return (s.length < 251)?true:false;}

// check_CMIString4096
function Check_CMIString4096(s){return (s.length < 4001)?true:false;}

// check_CMIString4096
function Check_CMIString1000(s){return (s.length < 1001)?true:false;}

// Check_CMITimespan
function Check_CMITimespan(s){
	var DTFlg = true;
	var DDFlg = false;
	var tmpStr,bufStr,tmpNum,pos;
	var retAry = new Array("","","","","","");
	if(s.charAt(0)!="P"){
		return false;
	}

	if(s.charAt(s.length - 1) == "T"){
		return false;
	}

	tmpStr = s.substring(1,s.length);

	bufStr = "";
	for(i=0;i<tmpStr.length;i++){

		tmpNum = tmpStr.charCodeAt(i);
		if((47<tmpNum)&&(tmpNum<58)){
			bufStr += tmpStr.charAt(i);
		}else if(tmpNum == 46){//.
			if(DDFlg){
				return false;
			}
			DDFlg = true;
			bufStr += tmpStr.charAt(i);
		}else{
			if(tmpNum == 89){
				pos = 0;
			}else if(tmpNum==77){
				if(DTFlg){
					pos = 1;
				}else{
					pos = 4;
				}
			}else if(tmpNum==68){
				pos = 2;
			}else if(tmpNum==84){
				DTFlg = false;
			}else if(tmpNum==72){

				if(DTFlg){return false;}
				pos = 3;
			}else if(tmpNum==83){
				if(DTFlg){return false;}
				pos = 5;
			}else{
				return false;
			}
			if(tmpNum!=84){
				retAry[pos] = bufStr;
				bufStr = "";
			}
		}
	}

	for(i=0;i<6;i++){
		if(retAry[i] != ""){
			if(i != 5){
				if(/\D/.test(retAry[i])){
					return false;
				}
			}
			if(isNaN(retAry[i])){
				return false;
			}

			if(eval(retAry[i])<0){
				return false;
			}

			if(i == 5){
				if(DTFlg){
					dbuf = retAry[i].split(".");
					if(dbuf.length != 2){
						return false;
					}
					if((dbuf[1].length == 0)||(dbuf[1].length > 2)){
						return false;
					}
				}
			}
		}
	}
	return true;
}

// check_CMITime
function Check_CMITime(s){
	var retAry = new Array("","","","","","","");
	var mBuf = s.split("T");

	var sBus = mBuf[0].split("-");

	for(i=0;i<sBus.length;i++){
		if(i==0){
			if(sBus[i].length != 4){
				return false;
			}
		}else{
			if(sBus[i].length != 2){
				return false;
			}
		}
		retAry[i] = eval(sBus[i]);
	}


	if(mBuf.length == 2){
		pus = false;
		var tzn = "";
		// まずマイナスから
		if(mBuf[1].indexOf("-") != -1){
			pus = true;
			qbuf = mBuf[1].split("-");
			if(qbuf.length != 2){
				return false;
			}
			mBuf[1] = qbuf[0];
			tzn = qbuf[1];
			if(tzn == ""){
				return false;
			}
		}else if(mBuf[1].indexOf("+") != -1){
			pus = true;
			qbuf = mBuf[1].split("+");
			if(qbuf.length != 2){
				return false;
			}
			mBuf[1] = qbuf[0];
			tzn = qbuf[1];
			if(tzn == ""){
				return false;
			}
		}else{// 最後の文字がZなら削除
			if(mBuf[1].charAt(mBuf[1].length - 1) == "Z"){
				pus = true;
				mBuf[1] = mBuf[1].slice(0,-1);
			}
		}

		// tznのちぇっく
		if(tzn != ""){
			if((/^[012]\d$/.test(tzn))||(/^[012]\d:[0-5]\d$/.test(tzn))){
				// 24以下であることを確認
				if(tzn.charAt(0) == "2"){
					if(eval(tzn.charAt(1)) > 3){
						return false;
					}
				}
			}else{
				return false;
			}
		}

		sBus = mBuf[1].split(":");

		if(pus){
			if(sBus.length != 3){
				return false;
			}
			// さらに小数点以下が入っていることが条件
			if(/\.\d{1,2}$/.test(sBus[2])){
			}else{
				return false;
			}
		}
		for(i=0;i<sBus.length;i++){
			if(i==2){
				if((sBus[2].length < 6)&&(sBus[2].length != 3)){
					tmpBuf = sBus[i].split(".");
					if(tmpBuf[0].length != 2){
						return false;
					}else{
						if(sBus[i].charAt(0) == "0"){
							sBus[i] = sBus[i].slice(1);
						}
					}
				}else{
					return false;
				}
			}else{
				if(sBus[i].length != 2){
					return false;
				}
			}
			retAry[i+3] = eval(sBus[i]);
		}
	}

	if((retAry[0]<1970)||(2038<retAry[0])){return false;}

	if(retAry[1]===""){
		if((retAry[2]!="")||(retAry[3]!="")||(retAry[4]!="")||(retAry[5]!="")){
			return false;
		}
	}else{
		if((retAry[1] < 1)||(12 < retAry[1])){
			return false;
		}
	}

	if(retAry[2]===""){
		if((retAry[3]!="")||(retAry[4]!="")||(retAry[5]!="")){
			return false;
		}

	}else{
		if((retAry[2]<1)||(31<retAry[2])){
			return false;
		}else{
			if(retAry[1] == 2){
				if(retAry[0] % 4 == 0){
					if(retAry[2]>29){
						return false;
					}
				}else{
					if(retAry[2]>28){
						return false;
					}
				}
			}
			if((retAry[1]==4)||(retAry[1]==6)||(retAry[1]==9)||(retAry[1]==11)){
				if(retAry[2]>30){
					return false;
				}
			}
		}
	}

	if(retAry[3]===""){
		if((retAry[4]!="")||(retAry[5]!="")){
			return false;
		}
	}else{
		if((retAry[3]<0)||(23<retAry[3])){
			return false;
		}
	}

	if(retAry[4]===""){
		if(retAry[5]!=""){
			return false;
		}
	}else{
		if((0<=retAry[4])&&(retAry[4]<60)){
		}else{
			return false;
		}
	}

	if(retAry[5]!=""){
		if((0<=retAry[5])&&(retAry[5]<60)){
		}else{
			return false;
		}
	}
	return true;
}

//------------------------------------------------------------------------------
// SCORE
// ADD
//------------------------------------------------------------------------------
function SCE_Check_Score(s){
	s = eval(s);
	return ((0 <= s) && (s <= 100))?true:false;
}

//------------------------------------------------------------------------------
// SCORE
// ADD
//------------------------------------------------------------------------------
function SCE_Check_Audio(s){
	s = eval(s);
	return ((-2 < s) && (s < 101))?true:false;
}

//------------------------------------------------------------------------------
// SPEED
// ADD
//------------------------------------------------------------------------------
function SCE_Check_Speed(s){
	s = eval(s);
	return ((-101 < s) && (s < 101))?true:false;
}

//------------------------------------------------------------------------------
// SPEED
// ADD
//------------------------------------------------------------------------------
function SCE_Check_Text(s){
	s = eval(s);
	return ((-2 < s) && (s < 2))?true:false;
}

function post_GetChangedNumber(m){
	var pn, cnl, tagname, n;
	var str = "";

	m = dm_RepS(m);
	pn = ADP.SCO.selectSingleNode(m);
	if(pn != null){
		cnl = pn.childNodes;

		for(i=0;i<cnl.length;i++){
			tagname = cnl.item(i).tagName;
			if(tagname.match(/^i{1}\d+/) != null){
				if(cnl.item(i).getAttribute("f_chg") == "1"){
					n = t_DelS(tagname, -1);
					str = str + n + ",";
				}
			}
		}
	}
	return t_DelS(str, 1);
}

function post_ResetFlag(m){
	m = dm_RepS(m);
	var n = ADP.SCO.selectSingleNode(m);
	if(n==null) return false;
	n.setAttribute("f_chg","0");
	return true;
}

function post_GetMultiValue(m,member){
	var pn, cnl, ntag, tname, str, cn, i, buf;

	m = dm_RepS(m);
	pn = ADP.SCO.selectSingleNode(m);
	if(pn != null){
		cnl = pn.childNodes;

		ntag = "";

		for(i=0;i<cnl.length;i++){
			tname = cnl.item(i).tagName;
			if(tname.match(/^i{1}\d+/) != null){
				ntag += tname + ",";
			}
		}

		if(ntag != ""){
			ntag = t_DelS(ntag, 1);
			buf = ntag.split(",");
			buf = buf.sort();
			str = "";
			for(i=0;i<buf.length;i++){
				if(member == "")
					cn = pn.selectSingleNode(buf[i]);
				else
					cn = pn.selectSingleNode(buf[i] + "/" + member);
				if(cn == null)
					str = str + ";";
				else
					str = str + cn.text + ";";
			}
			return t_DelS(str, 1);
		}else{
			return null;
		}
	}else{
		return null;
	}
}

function post_GetValue(m){
	m = dm_RepS(m);
	var ret = ADP.SCO.selectSingleNode(m);
	return (ret==null)?"":ret.text;
}

function post_GetMaxN(m){
	var pn,cnl,ntag,i,buf,n;

	m = dm_RepS(m);
	pn = ADP.SCO.selectSingleNode(m);
	if(pn != null){
		cnl = pn.childNodes;
		ntag = "";

		for(i=0;i<cnl.length;i++){
			tname = cnl.item(i).tagName;
			if(tname.match(/^i{1}\d+/) != null){
				ntag += tname + ",";
			}
		}

		if(ntag != ""){
			ntag = ntag.substr(0, ntag.length-1);
			buf = ntag.split(",");
			buf = buf.sort();
			n = buf[buf.length-1]
			return t_DelS(n, -1);
		}else{
			return null;
		}
	}else{
		return null;
	}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////

var ADP = null;
function myInit(uri){

	ADP = new makeAdapter()
	if(ADP.ADPInit()){
		alert("データモデルのロードに失敗しました。");
		return false;
	}
	ADP.mrt = ADP.DM.documentElement;
}

function Initialize(s){
	_setLastError("0");

	var status = _getStatus();

	if(status == "Running"){
		_setLastError("103");
		return "false";
	}

	if(s != ""){
		_setLastError("201");
		return "false";
	}

	var sp,ep,loc,tmp,sid,trg;

	loc = _getSCOLocationObject().search;
	tmp = loc.toUpperCase();

	sp = tmp.indexOf("AICC_SID=");
	if (sp == -1) return "false";

	ep = tmp.indexOf("&",sp);
	sid = loc.substring(sp + 9, ep);
	sid = unescape(sid)

	sp = tmp.indexOf("AICC_URL=")
	if(sp == -1) return "false";

	ep = tmp.indexOf("&",sp);
	if(ep == -1) ep = tmp.length;

	trg = loc.substring(sp + 9, ep);
	trg = unescape(trg.replace("http://",""));

	if(sid == "" || trg == "" ) return "false";

	if(ADP.SCOInit(sid,trg)==null){
		_setLastError("101");
		return "false";
	}

	if(NavInitialize(s) == "false"){
		return "false";
	}
	_setStatus("Running");
	navSusFlag = false;

	if(parent.main.loadBTN == "function"){
		parent.main.loadBTN();
	}
	
	return "true";
}


function Terminate(s){
	_setLastError("0");
	var status = _getStatus();

	if(status == "Not Initialized"){
		_setLastError("112");
		return "false";
	}

	if(status == "Terminated"){
		_setLastError("113");
		return "false";
	}

	if(s != ""){
		_setLastError("201");
		return "false";
	}

	if(navSusFlag){
		SetValue("cmi.exit","suspend");
	}

	if(ADP.SCOFin()==null){
		return "false";
	}

	if(NavTerminate(s) == "false"){
		return "false";
	}
	_setStatus("Terminated");
	if(navSusFlag){
		parent.main.Button.LMSUI_NavSuspendAll();
	}
	return "true";
}


function GetValue(m){
	_setLastError("0");
	if(m == "cmi.learner_preference.audio")
		m = "cmi.learner_preference.audio_level";

	if(m == "cmi.learner_preference.speed")
		m = "cmi.learner_preference.delivery_speed";

	if(m == "cmi.learner_preference.text")
		m = "cmi.learner_preference.audio_captioning";

	var status = _getStatus();

	if(status == "Not Initialized"){
		_setLastError("122");
		return "";
	}

	if(status == "Terminated"){
		_setLastError("123");
		return "";
	}

	if(typeof(m) == "undefined"){
		_setLastError("301");
		return "";
	}

	if(m == ""){
		_setLastError("301");
		return "";
	}

	if(m == "cmi._version"){
		return "1.0";
	}

	var buf,i,kw,str;
	buf = m.split(".");
	if(buf.length==1){
		_setLastError("401");
		return "";
	}else{

		if(buf[0]!="cmi"){
			if((buf[0] == "adl")&&(buf[1] == "nav")){
				return NavGetValue(m);
			}else{
				_setLastError("401");
				return "";
			}
		}
		kw = buf[buf.length-1];

		if(kw=="_children"){
			if((buf.length>1)&&(buf[buf.length-2]=="n")){
				_setLastError("401");
				return "";
			}
			ret = ADP.dm_CheckChildren(m);
			if(ret==null)
				_setLastError("301");
			else if(ret=="")
				_setLastError("301");
			else
				return ret;
			return "";
		}else if(kw=="_version"){
			if(m=="cmi._version")
				_setLastError("201");
			else
				return "";
			return "false";
		}else if(kw=="_count"){
			ret = ADP.dm_CheckCount(m);
			if(ret==null)
				_setLastError("301");
			else if(ret)
				return String(ADP.sco_GetCount(m));
			else
				_setLastError("301");

			return "";
		}else{
			ret = ADP.dm_CheckData(m,0);
			if(ret==null){
				_setLastError("401");
				return "";
			}else if(ret){
				str = ADP.sco_GetValue(m);
				// 初期値ありか？

				if(str==null){
					// 配列型かどうかを見る
					var aryStr = dm_RepG(m);
					if(aryStr.indexOf("/n/") != -1){
						mmm = dm_RepS(m);
						var nnn = null;
						if(aryStr.indexOf("cmi/objectives/n/score") != -1){
							wbuf = mmm.split("/");
							wbuf[wbuf.length - 1] = "";
							wbuf[wbuf.length - 2] = "";
							mmm = wbuf.join("/");
							mmm = mmm.slice(0,-2);
							nnn = ADP.sco_GetValueM(mmm);
						}else{
							wbuf = mmm.split("/");
							wbuf[wbuf.length - 1] = "";
							mmm = wbuf.join("/");
							mmm = mmm.slice(0,-1);
							nnn = ADP.sco_GetValueM(mmm);
						}

						if(nnn == null){
							_setLastError("301");
						}else{
// 配列型が存在する
							if((aryStr == "/cmi/objectives/n/success_status")||((aryStr == "/cmi/objectives/n/completion_status"))){
								return "unknown";
							}else{
								_setLastError("403");
							}
						}
					}else{
						_setLastError("403");
					}
					return "";
				}else{
					str = str.replace(/&nbsp;/g," ")
					return str;
				}

			}else{
				_setLastError("405");
				return "";
			}
		}
	}
}

var navSusFlag = false;
//
function SetValue(m,s){
	_setLastError("0");
	s = String(s);
	if(m == "cmi.learner_preference.audio")
		m = "cmi.learner_preference.audio_level";

	if(m == "cmi.learner_preference.speed")
		m = "cmi.learner_preference.delivery_speed";

	if(m == "cmi.learner_preference.text")
		m = "cmi.learner_preference.audio_captioning";

	var status = _getStatus();

	if(status == "Not Initialized"){
		_setLastError("132");
		return "false";
	}

	if(status == "Terminated"){
		_setLastError("133");
		return "false";
	}

	if(typeof(m) == "undefined"){
		_setLastError("351");
		return "false";
	}

	if(m === ""){
		_setLastError("351");
		return "false";
	}


	var buf,i,kw,str,cw;
	buf = m.split(".");

	if(buf.length==1){
		_setLastError("401");
	}else{
		if(buf[0]!="cmi"){
			if((buf[0] == "adl")&&(buf[1] == "nav")){
				if((m == "adl.nav.request")&&(s == "suspendAll")){
					navSusFlag = true;
					return true;
				}else{
					return String(NavSetValue(m,s));
				}
			}else{
				_setLastError("401");
				return "false";
			}
		}

		kw = buf[buf.length-1];
		if((kw=="_children")||(kw=="_version")||(kw=="_count")){
			_setLastError("404");
			return "false";
		}else{

			ret = ADP.dm_CheckData(m,1);
			if(ret==null){
				_setLastError("401");
				return "false";
			}else if(ret){


					var tStr = dm_RepG(m);
					if(tStr.indexOf("/n/") != -1){

						if((tStr == "/cmi/interactions/n/objectives/n/id")||(tStr == "/cmi/interactions/n/correct_responses/n/pattern")){
							t1 = dm_RepS2(m);
							if(t1 == ""){
							}else{
								if(ADP.sco_GetNode(t1)){
									_setLastError("351");
									return "false";
								}
							}

							t1 = dm_RepS3(m);
							if(t1 == ""){
								;
							}else{
								if(ADP.sco_GetNode(t1)){
									_setLastError("351");
									return "false";
								}
							}
						}else{

							t1 = dm_RepS2(m);

							if(t1 == ""){
							}else{
								if(ADP.sco_GetNode(t1)){
									_setLastError("351");
									return "false";
								}
							}
						}
					}

					if(tStr == "/cmi/objectives/n/id"){
						if(ADP.sco_SetObjID(m,s)){
							_setLastError("351");
							return "false";
						}
					}

					if(tStr.indexOf("/cmi/objectives/") != -1){
						// IDじゃない

						if(tStr != "/cmi/objectives/n/id"){
							tt1 = dm_RepS6(m);
							if(ADP.sco_GetNode(tt1)){
								_setLastError("408");
								return "false";
							}
						}
					}

// Interactionの場合はIDがセットされているか？
// cmi.interactions.0.id

					if(tStr.indexOf("/cmi/interactions/") != -1){
						// IDじゃない

						if(tStr != "/cmi/interactions/n/id"){
							tt1 = dm_RepS5(m);
							if(ADP.sco_GetNode(tt1)){
								_setLastError("408");
								return "false";
							}
						}
					}

					if(tStr == "/cmi/interactions/n/objectives/n/id"){
						if(ADP.sco_SetObjID(m,s)){
							_setLastError("351");
							return "false";
						}
					}

					if((tStr == "/cmi/interactions/n/correct_responses/n/pattern")||(tStr == "/cmi/interactions/n/learner_response")){

						var cfg = false;
						if(tStr == "/cmi/interactions/n/correct_responses/n/pattern"){
							cfg = true;
						}

						t1 = dm_RepS4(m);
						if(ADP.sco_GetNode(t1)){
							_setLastError("408");
							return "false";
						}

						cary = false;
						if(tStr == "/cmi/interactions/n/correct_responses/n/pattern"){
							cary = true;
						}

						mct = 0;
						if(cary){
							mdbuf = m.split(".");
							mct = parseInt(mdbuf[4]);
						}

						qtp = ADP.sco_GetValueM(t1);

						if(qtp == "true-false"){
							if((cary)&&(0 < mct)){_setLastError("351");return "false";}
							if(!chk_truefalse(s)){_setLastError("406");return "false";}


						}else if(qtp == "choice"){
							if(!chk_multiple(s)){_setLastError("406");return "false";}

							if(cary){
								if(9 < mct){
									_setLastError("351");return "false";
								}
								if(ADP.sco_Double(m,mct,s)){
									_setLastError("351");return "false";
								}
							}
						}else if(qtp == "fill-in"){
							if(!chk_fillin(s)){_setLastError("406");return "false";}
//							if((cary)&&(4 < mct)){_setLastError("351");return "false";}

						}else if(qtp == "long-fill-in"){
							if(!chk_longfillin(s)){_setLastError("406");return "false";}
//							if((cary)&&(4 < mct)){_setLastError("351");return "false";}

						}else if(qtp == "likert"){
							if(!chk_likert(s)){_setLastError("406");return "false";}
//							if((cary)&&(0 < mct)){_setLastError("351");return "false";}

						}else if(qtp == "matching"){
							if(!chk_matching(s)){_setLastError("406");return "false";}
							if(cary){
								if(4 < mct){
									_setLastError("351");return "false";
								}
							}
						}else if(qtp == "performance"){
							if(!chk_performance(s)){_setLastError("406");return "false";}
//							if((cary)&&(4 < mct)){_setLastError("351");return "false";}

						}else if(qtp == "sequencing"){
							if(!chk_sequencing(s)){_setLastError("406");return "false";}
							if(cary){
//								if(4 < mct){
//									_setLastError("351");return "false";
//								}
								if(ADP.sco_Double(m,mct,s)){
									_setLastError("406");return "false";
								}
							}

						}else if(qtp == "numeric"){
							if(cary){
								if(0 < mct){
									_setLastError("351");return "false";
								}

								if(!chk_numeric(s)){

									if(_getLastError() == "0"){
										_setLastError("406");
									}
									return "false";
								}
							}else{
								if(!chk_numeric2(s)){
									_setLastError("406");return "false";
								}
							}
						}else if(qtp == "other"){
							if(!chk_other(s)){_setLastError("406");return "false";}
//							if((cary)&&(0 < mct)){_setLastError("351");return "false";}

						}else{
							_setLastError("406");
							return "false";
						}
					}else if(!ADP.dm_CheckValue(ret,s,m)){
						if(_getLastError() == "0"){
							_setLastError("406");
						}
						return "false";
					}

					s = s.replace(/\s/g,"&nbsp;")
					ADP.sco_SetValue(m,s,0);

					if(m == "cmi.exit"){
						if(s == "suspend"){
							navSusFlag = true;
						}
					}

					ADP.flgWrite = 1;
					return "true";
/*
				}else{
					if(_getLastError() == "0"){
						_setLastError("406");
					}
					return "false";
				}
*/
			}else{
				_setLastError("404");
				return "false";
			}
		}
	}
	return "false";
}


function dm_RepS2(m){
	var i;
	var retstr = "";
	var buf = m.split(".");
	for(i in buf){
		if(!isNaN(buf[i])){
			if(parseInt(buf[i]) == 0){
				return "";
			}else{
				buf[i] = "i" + (parseInt(buf[i]) - 1);
			}
			retstr += buf[i];
			return retstr;
		}else{
			retstr += buf[i] + "/";
		}
	}
	return "";
}


function dm_RepS3(m){
	var flg = false;
	var i;
	var retstr = "";
	var buf = m.split(".");
	for(i in buf){
		if(!isNaN(buf[i])){
			if(flg){
				if(parseInt(buf[i]) == 0){
					return "";
				}else{
					buf[i] = "i" + (parseInt(buf[i]) - 1);
				}
				retstr += buf[i];
				return retstr;
			}else{
				buf[i] = "i" + buf[i];
				retstr += buf[i] + "/";
				flg = true;
			}
		}else{
			retstr += buf[i] + "/";
		}
	}
	return "";
}

function dm_RepS4(m){
	var buf = m.split(".");
	if(buf.length < 3){
		alert("model error")
	}
	return "cmi/interactions/i" + buf[2] + "/type";
}

function dm_RepS5(m){
	var buf = m.split(".");
	if(buf.length < 3){
		alert("model error")
	}
	return "cmi/interactions/i" + buf[2] + "/id";
}


function dm_RepS6(m){
	var buf = m.split(".");
	if(buf.length < 3){
		alert("model error")
	}
	return "cmi/objectives/i" + buf[2] + "/id";
}

function sco_SetObjID(m,s){

	var zbuf = m.split(".");
	if(zbuf[1] == "objectives"){
		var cNum = parseInt(zbuf[2]);
		var tmpNode2;

		var tmpNode = this.SCO.selectSingleNode("/cmi/objectives");

		if(tmpNode != null){
			var iList = tmpNode.childNodes;

			for(i=0;i<iList.length;i++){
				if(i != cNum){
					tmpNode2 = iList.item(i).selectSingleNode("id");
					if(tmpNode2 != null){
						if(tmpNode2.text == s){
							return true;
						}
					}
				}
			}
		}
	}else if(zbuf[1] == "interactions"){
		var cNum = parseInt(zbuf[4]);
		var tmpNode = this.SCO.selectSingleNode("/cmi/interactions/i"+ zbuf[2] +"/objectives");

		if(tmpNode != null){
			var iList = tmpNode.childNodes;

			for(i=0;i<iList.length;i++){
				if(i != cNum){
					tmpNode2 = iList.item(i).selectSingleNode("id");
					if(tmpNode2 != null){
						if(tmpNode2.text == s){
							return true;
						}
					}
				}
			}
		}
	}else{
		return true;
	}

	return false;
}

function sco_Double(m,mct,s){
	xbuf = m.split(".");
	var mdam = "/cmi/interactions/i" + xbuf[2] + "/correct_responses";
	var tmpNode = this.SCO.selectSingleNode(mdam);
	if(tmpNode != null){
		var nn = tmpNode.childNodes;
		var nnn = null;
		for(i=0;i<nn.length;i++){
			if(i != mct){
				nnn = nn.item(i).selectSingleNode("pattern");
				if(nnn != null){
					if(s == nnn.text){
						return true;
					}
				}
			}
		}
	}
	return false;
}


function sco_GetNode(m){
	var n = this.SCO.selectSingleNode(m);
	return (n==null)?1:0;
}


function Commit(s){
	_setLastError("0");
	var status = _getStatus();

	if(status == "Not Initialized"){
		_setLastError("142");
		return "false";
	}

	if(status == "Terminated"){
		_setLastError("143");
		return "false";
	}

	var ret = ADP.sco_Commit(0);
	var ret2 = NavCommit(s);

	return ((ret==null)||(ret2=="false"))?"false":"true";

}

function GetLastError(){
	return _getLastError();
}

function GetErrorString(s){
	return NEM[_getLastError()];
}

function GetDiagnostic(){
	return "error";
}

NEM = new Array();
NEM["0"]   = "No error";
NEM["101"] = "General exception";
NEM["102"] = "General Initialization Failure";
NEM["103"] = "Already Initialized ";
NEM["104"] = "Content Instance Terminated ";
NEM["111"] = "General Termination Failure ";
NEM["112"] = "Termination Before Initialization ";
NEM["113"] = "Termination After Termination ";
NEM["122"] = "Retrieve Data Before Initialization ";
NEM["123"] = "Retrieve Data After Termination ";
NEM["132"] = "Store Data Before Initialization ";
NEM["133"] = "Store Data After Termination ";
NEM["142"] = "Commit Before Initialization ";
NEM["143"] = "Commit After Termination ";
NEM["201"] = "General Argument Error ";
NEM["301"] = "General Get Failure ";
NEM["351"] = "General Set Failure ";
NEM["391"] = "General Commit Failure ";

NEM["401"] = "Undefined Data Model Element ";
NEM["402"] = "Unimplemented Data Model Element ";
NEM["403"] = "Data Model Element Value Not Initialized ";
NEM["404"] = "Data Model Element Is Read Only ";
NEM["405"] = "Data Model Element Is Write Only ";
NEM["406"] = "Data Model Element Type Mismatch ";
NEM["407"] = "Data Model Element Value Out Of Range  ";
NEM["408"] = "Data Model Dependency Not Established  ";


var lang639 = "aa-ab-af-am-ar-as-ay-az-ba-be-bg-bh-bi-bn-bo-br-ca-co-cs-cy-da-de-dz-el-en-eo-es-et-eu-fa-fi-fj-fo-fr-fy-";
lang639 += "ga-gd-gl-gn-gu-ha-he-hi-hr-hu-hy-ia-id-ie-ik-is-it-iu-ja-jw-ka-kk-kl-km-kn-ko-ks-ku-ky-la-ln-lo-lt-lv-";
lang639 += "mg-mi-mk-ml-mn-mo-mr-ms-mt-my-na-ne-nl-no-oc-om-or-pa-pl-ps-pt-qu-rm-rn-ro-ru-rw-sa-sd-sg-sh-si-sk-sl-sm-sn-so-sq-sr-ss-st-su-sv-sw-";
lang639 += "ta-te-tg-th-ti-tk-tl-tn-to-tr-ts-tt-tw-ug-uk-ur-uz-vi-vo-wo-xh-yi-yo-za-zh-zu";

var lang639_2 = "aar-abk-ace-ach-ada-ady-afa-afh-afr-aka-akk-alb-alb-ale-alg-amh-ang-apa-ara-arc-arg-arm-arn-arp-art-arw-asm-ast-ath-aus-ava-ave-awa-aym-aze-";
lang639_2 += "bad-bai-bak-bal-bam-ban-baq-bas-bat-bej-bel-bem-ben-ber-bho-bih-bik-bin-bis-bla-bnt-bod-bos-bra-bre-btk-bua-bug-bul-bur-byn-"
lang639_2 += "cad-cai-car-cat-cau-ceb-cel-cha-chb-che-chg-chi-chk-chm-chn-cho-chp-chr-chu-chv-chy-cmc-cop-cor-cos-cpe-cpf-cpp-cre-crh-crp-csb-cus-cym-cze-"
lang639_2 += "dak-dan-dar-day-del-den-deu-dgr-din-div-doi-dra-dua-dum-dut-dyu-dzo-";
lang639_2 += "efi-egy-eka-ell-elx-eng-enm-epo-est-eus-ewe-ewo-fan-fao-fas-fat-fij-fil-fin-fiu-fon-fra-fre-frm-fro-fry-ful-fur-"
lang639_2 += "gaa-gay-gba-gem-geo-ger-gez-gil-gla-gle-glg-glv-gmh-goh-gon-gor-got-grb-grc-gre-grn-guj-gwi-hai-hat-hau-haw-heb-her-hil-him-hin-hit-hmn-hmo-hrv-hun-hup-hye-"
lang639_2 += "iba-ibo-ice-ido-iii-ijo-iku-ile-ilo-ina-inc-ind-ine-inh-ipk-ira-iro-isl-ita-jav-jpn-jpr-jrb-"
lang639_2 += "kaa-kab-kac-kal-kam-kan-kar-kas-kat-kau-kaw-kaz-kbd-kha-khi-khm-kho-kik-kin-kir-kmb-kok-kom-kon-kor-kos-kpe-krc-kro-kru-kua-kum-kur-kut-"
lang639_2 += "lad-lah-lam-lao-lat-lav-lez-lim-lin-lit-lol-loz-ltz-lua-lub-lug-lui-lun-luo-lus-"
lang639_2 += "mac-mad-mag-mah-mai-mak-mal-man-mao-map-mar-mas-may-mdf-mdr-men-mga-mic-min-mis-mkd-mkh-mlg-mlt-mnc-mni-mno-moh-mol-mon-mos-mri-msa-mwl-mul-mun-mus-mwr-mya-myn-myv-"
lang639_2 += "nah-nai-nap-nau-nav-nbl-nde-ndo-nds-nep-new-nia-nic-niu-nld-nno-nob-nog-non-nor-nso-nub-nwc-nya-nym-nyn-nyo-nzi-oci-oji-ori-orm-osa-oss-ota-oto-"
lang639_2 += "paa-pag-pal-pam-pan-pap-pau-peo-per-phi-phn-pli-pol-pon-por-pra-pro-pus-que-raj-rap-rar-roa-roh-rom-ron-run-rus-"
lang639_2 += "sad-sag-sah-sai-sal-sam-san-sas-sat-scc-scn-sco-scr-sel-sem-sga-sgn-shn-sid-sin-sio-sit-sla-slk-slo-slv-sma-sme-smi-smj-smn-smo-sms-sna-snd-snk-sog-som-son-sot-spa-sqi-srd-srp-srr-ssa-ssw-suk-sun-sus-sux-swa-swe-syr-"
lang639_2 += "tah-tai-tam-tat-tel-tem-ter-tet-tgk-tgl-tha-tib-tig-tir-tiv-tkl-tlh-tli-tmh-tog-ton-tpi-tsi-tsn-tso-tuk-tum-tup-tur-tut-tvl-twi-tyv-"
lang639_2 += "udm-uga-uig-ukr-umb-und-urd-uzb-vai-ven-vie-vol-vot-wak-wal-war-was-wel-wen-wln-wol-xal-xho-yao-yap-yid-yor-ypk-zap-zen-zha-zho-znd-zul-zun";

//,,,qaa-qtz

lang3166 = "AF-AL-DZ-AS-AD-AO-AI-AQ-AG-AR-AM-AW-AU-AT-AZ-BS-BH-BD-BB-BY-BE-BZ-BJ-BM-BT-BO-BA-BW-BV-BR-IO-BN-BG-BF-BI-KH-CM-CA-CV-KY-CF-TD-CL-CN-CX-CC-CO-KM-"
lang3166 += "CD-CG-CK-CR-CI-HR-CU-CY-CZ-DK-DJ-DM-DO-TL-EC-EG-SV-GQ-ER-EE-ET-FK-FO-FJ-FI-FR-FX-GF-PF-TF-GA-GM-GE-DE-GH-GI-GR-GL-GD-GP-GU-GT-GN-GW-GY-HT-HM-HN-"
lang3166 += "HK-HU-IS-IN-ID-IR-IQ-IE-IL-IT-JM-JP-JO-KZ-KE-KI-KP-KR-KW-KG-LA-LV-LB-LS-LR-LY-LI-LT-LU-MO-MK-MG-MW-MY-MV-ML-MT-MH-MQ-MR-MU-YT-MX-FM-MD-MC-MN-MS-"
lang3166 += "MA-MZ-MM-NA-NR-NP-NL-AN-NC-NZ-NI-NE-NG-NU-NF-MP-NO-OM-PK-PW-PS-PA-PG-PY-PE-PH-PN-PL-PT-PR-QA-RE-RO-RU-RW-KN-LC-VC-WS-SM-ST-SA-SN-SC-SL-SG-SK-SI-"
lang3166 += "SB-SO-ZA-GS-ES-LK-SH-PM-SD-SR-SJ-SZ-SE-CH-SY-TW-TJ-TZ-TH-TG-TK-TO-TT-TN-TR-TM-TC-TV-UG-UA-AE-GB-US-UM-UY-UZ-VU-VA-VE-VN-VG-VI-WF-EH-YE-YU-ZM-ZW"

IANA = "art-lojban,az-Arab,az-Cyrl,az-Latn,cel-gaulish,de-1901,de-1996,de-AT-1901,de-AT-1996,de-CH-1901,de-CH-1996,de-DE-1901,de-DE-1996,en-boont,en-GB-oed,en-scouse,i-ami,i-bnn,i-default,i-enochian,i-hak,i-klingon,i-lux,i-mingo,i-navajo,i-pwn,i-tao,i-tay,i-tsu,no-bok,no-nyn,sgn-BE-fr,sgn-BE-nl,sgn-BR,sgn-CH-de,sgn-CO,sgn-DE,sgn-DK,sgn-ES,sgn-FR,sgn-GB,sgn-GR,sgn-IE,sgn-IT,sgn-JP,sgn-MX,sgn-NL,sgn-NO,sgn-PT,sgn-SE,sgn-US,sgn-ZA,sl-rozaj,sr-Cyrl,sr-Latn,uz-Cyrl,uz-Latn,yi-Latn,zh-gan,zh-guoyu,zh-hakka,zh-Hans,zh-Hant,zh-min,zh-min-nan,zh-wuu,zh-xiang";

// check_CMIString4096

function Check_CMIString4096C(s){
	return chk_localLang(s,4000);
}
function Check_CMIString4096I(s){
//	if(s.length > 4000){
//		return false;
//	}

	// :を探す。あればURNなければShort
	if(s.indexOf(":") == -1){
		return chk_shortID(s);
	}else{
		var ubuf = s.split(":");
		if(ubuf.length == 3){
			if(ubuf[0] != "urn"){
				return false;
			}
			if(!chk_shortID(ubuf[1])){
				return false;
			}

			if(!chk_shortID(ubuf[2])){
				return false;
			}
			return true;
		}else{
			return false;
		}
	}
}

function chk_localLang(s,n){

	var chkexp = /^\{lang=[^\}]*\}/g;
	if(chkexp.test(s)){
		chkexp.lastIndex = 0;
		rlt = String(chkexp.exec(s));
//		if(rlt.length > 250){
//			return false;
//		}

		alStr = s.replace(chkexp,"");
		if(n != 0){
//			if(alStr.length > n){
//				return false;
//			}
		}

		str = rlt.slice(6,-1);
		if((str != "")&&(str.length>1)){
			// IANAの文字列チェック
			if(IANA.indexOf(str) != -1){
				return true;
			}

			// x- でスタート
			if((str.charAt(0)=="x")&&(str.charAt(0)=="-")){
				return true;
			}
			// i- でスタート
			if((str.charAt(0)=="i")&&(str.charAt(0)=="-")){
				return true;
			}

			// それ以外
			buf = str.split("-");
			if((buf.length == 0)||(buf.length > 2)){
				return false;
			}
			if(buf.length == 1){
				if(buf[0].length == 2){
					if(/[^[a-z][A-Z]]/.test(buf[0])){
						return false;
					}else{
						if(buf[0] == "sp"){
							return false;
						}
						return true;
					}
/*
					if(lang639.indexOf(buf[0]) == -1){
						return false;
					}else{
						return true;
					}
*/
				}else if(buf[0].length == 3){
					if(/[^[a-z][A-Z]]/.test(buf[0])){
						return false;
					}else{
						if((buf[0] == "frl")||(buf[0] == "exg")||(buf[0] == "ruq")){
							return false;
						}
						return true;
					}

/*
					if(lang639_2.indexOf(buf[0]) == -1){
						if((buf[0].charAt(0) == "q")&&(96 <buf[0].charCodeAt(1))&&(buf[0].charCodeAt(1) < 117)){
							if((96 <buf[0].charCodeAt(2))&&(buf[0].charCodeAt(2) < 123)){
								return true;
							}else{
								return false;
							}
						}
						return false;
					}else{
						return true;
					}
*/
				}else{
					return false;
				}
			}else if(buf.length == 2){

				if(buf[0].length == 2){
					if(/[^[a-z][A-Z]]/.test(buf[0])){
						return false;
					}
						if(buf[0] == "sp"){
							return false;
						}

/*
					if(lang639.indexOf(buf[0]) == -1){
						return false;
					}
*/
				}else if(buf[0].length == 3){
					if(/[^[a-z][A-Z]]/.test(buf[0])){
						return false;
					}
						if((buf[0] == "scn")||(buf[0] == "frl")||(buf[0] == "exg")||(buf[0] == "ruq")){
							return false;
						}


/*
					if(lang639_2.indexOf(buf[0]) == -1){
						if((buf[0].charAt(0) == "q")&&(96 <buf[0].charCodeAt(1))&&(buf[0].charCodeAt(1) < 117)){
							if((96 < buf[0].charCodeAt(2))&&(buf[0].charCodeAt(2) < 123)){

							}else{
								return false;
							}

						}else{
							return false;
						}
					}
*/
				}
				// 後半戦
				if(buf[1].length == 2){
					if(/[^[a-z][A-Z]]/.test(buf[0])){
						return false;
					}else{
						return true;
					}
/*
					if(lang3166.indexOf(buf[1]) == -1){
						return false;
					}else{
						return true;
					}
*/
				}else if((2 < buf[1].length)&&(buf[1].length < 9)){
					// 英語の国名と一致すればOKだが不明なんで3文字から8文字のアルファベットならOK
					for(j=0;j<buf[1].length;j++){
						tcc = buf[1].charCodeAt(j);
						if(((64<tcc)&&(tcc<91))||((96<tcc)&&(tcc<123))){
						}else{
							return false;
						}
					}
					return true;
				}else{
					return false;
				}
			}
		}
		return false;
	}else{

//		if(n != 0){
//			if(s.length > n){
//				return false;
//			}
//		}


		return true;// デフォルト英語
	}
}

var str2396 = "!&'()*+,-./:;=?_~";
var str16 = "0123456789AaBbCcDdEeFf";

function chk_shortID(s){
	if(s == ""){
		return false;
	}

	mlen = s.length;
	for(i=0;i<mlen;i++){
		tgc = s.charCodeAt(i);
		if(((32 < tgc)&&(tgc < 91))&&(tgc != 60)&&(tgc != 62)){
			// OK
		}else if(((94 < tgc)&&(tgc < 123))&&(tgc != 96)){
			// OK
		}else if(tgc == 126){
			// OK
		}else if(tgc == 32){
			if((i+2) < mlen){
				tgc1 = s.charCodeAt(i + 1);
				tgc2 = s.charCodeAt(i + 2);
				if((str16.indexOf(tgc1) == -1)||(str16.indexOf(tgc2) == -1)){
					return false;
				}
				i = i + 2;
			}else{
				return false;
			}
		}else{
			return false;
		}
	}
	return true;
}

function chk_truefalse(s){
	if((s == "true")||(s == "false")){
		return true;
	}else{
		return false;
	}
}

function chk_multiple(s){
	if(s == ""){
		return true;
	}
	var buf = s.split("[,]");
	var i,j;
	clen = buf.length;
//	if(clen > 36){
//		return false;
//	}else{

		for(i=0;i<clen;i++){

//			if(buf[i].length > 250){
//				return false;
//			}

			if(!chk_shortID(buf[i])){
				return false;
			}

			for(j=(i+1);j<clen;j++){
				if(buf[i] == buf[j]){
					return false;
				}
			}
		}

		return true;
//	}
}

pst_ptn11 = "{case_matters=true}";
pst_ptn12 = "{case_matters=false}";
pst_ptn21 = "{order_matters=true}";
pst_ptn22 = "{order_matters=false}";
pst_ptn13 = "{case_";
pst_ptn23 = "{order_";


function chk_fillin(s){
	if(s.indexOf(pst_ptn11) == 0){
		s = s.replace(pst_ptn11,"");
	}else if(s.indexOf(pst_ptn12) == 0){
		s = s.replace(pst_ptn12,"");
	}
	if(s.indexOf(pst_ptn21) == 0){
		s = s.replace(pst_ptn21,"");
	}else if(s.indexOf(pst_ptn22) == 0){
		s = s.replace(pst_ptn22,"");
	}

	if(s.indexOf(pst_ptn13) == 0){
		return false;
	}

	if(s.indexOf(pst_ptn23) == 0){
		return false;
	}

	var buf = s.split("[,]");
//	if(buf.length < 11){
		for(i in buf){
			if(!chk_localLang(buf[i],250)){
				return false;
			}
		}
//	}else{
//		return false;
//	}
	return true;
}

function chk_longfillin(s){
	if(s.indexOf(pst_ptn11) == 0){
		s = s.replace(pst_ptn11,"");
	}else if(s.indexOf(pst_ptn12) == 0){
		s = s.replace(pst_ptn12,"");
	}

	if(s.indexOf(pst_ptn13) == 0){
		return false;
	}

	if(chk_localLang(s,4000)){
		return true;
	}
	return false;
}

function chk_likert(s){
	if(chk_shortID(s)){
		return true;
	}else{
		return false;
	}
}

function chk_matching(s){
	var buf = s.split("[,]");
//	if(buf.length > 36){
//		return false;
//	}

	for(i in buf){
		tbuf = buf[i].split("[.]");
		if(tbuf.length != 2){
			return false;
		}
		if((!chk_shortID(tbuf[0]))||(!chk_shortID(tbuf[1]))){
			return false;
		}
	}
	return true;
}

function chk_performance(s){
	if(s.indexOf(pst_ptn21) == 0){
		s = s.replace(pst_ptn21,"");
	}else if(s.indexOf(pst_ptn22) == 0){
		s = s.replace(pst_ptn22,"");
	}

	var buf = s.split("[,]");
//	if(buf.length > 36){
//		return false;
//	}

	for(i in buf){
		tbuf = buf[i].split("[.]");
		if(tbuf.length != 2){
			return false;
		}

		if((tbuf[0] == "")&&(tbuf[1] == "")){
				return true;
		}else if(tbuf[0] == ""){
			if(!chk_shortID(tbuf[1])){
				return false;
			}
		}else if(tbuf[1] == ""){
			if(!chk_shortID(tbuf[0])){
				return false;
			}
		}else{
			if((!chk_shortID(tbuf[0]))||(!chk_shortID(tbuf[1]))){
				return false;
			}
		}
	}
	return true;
}

function chk_performance2(s){
	if(s.indexOf(pst_ptn21) == 0){
		s = s.replace(pst_ptn21,"");
	}else if(s.indexOf(pst_ptn22) == 0){
		s = s.replace(pst_ptn22,"");
	}

	var buf = s.split("[,]");
//	if(buf.length > 36){
//		return false;
//	}

	for(i in buf){
		tbuf = buf[i].split("[.]");
		if(tbuf.length != 2){
			return false;
		}
		if(tbuf[0] == ""){
			if(!chk_shortID(tbuf[1])){
				return false;
			}
		}else{
			if((!chk_shortID(tbuf[0]))||(!chk_shortID(tbuf[1]))){
				return false;
			}
		}
	}
	return true;
}


function chk_sequencing(s){
	if(s == ""){
		return false;
	}
	var buf = s.split("[,]");
//	if(buf.length < 37){
		for(i in buf){
			if(!chk_shortID(buf[i])){
				return false;
			}
		}
		return true;
//	}
//	return false;
}

function chk_numeric(s){
	var buf = s.split("[:]");
	if(buf.length == 2){
		if((buf[0]!="")&&(isNaN(buf[0]))){
			return false;
		}
		if((buf[1]!="")&&(isNaN(buf[1]))){
			return false;
		}
		if((buf[0]!="")&&(buf[1]!="")){
			if(eval(buf[0]) > eval(buf[1])){
				_setLastError("406");
				return false;
			}
		}
		return true;
	}
	return false;
}

function chk_numeric2(s){
	if(isNaN(s)){
		return false;
	}else{
		return true;
	}
}

function chk_other(s){
	if(s.length < 4001){
		return true;
	}else{
		return false;
	}
}

