if (typeof console == "undefined" || typeof console.log == "undefined") var console = { log: function() {} }; 
function padd(pNum){
	if(pNum < 10)
		return "0"+pNum;
	else
		return pNum;
}
function getTimeStamp(){
	nowDate = new Date();
	return padd(nowDate.getHours())+":"+padd(nowDate.getMinutes())+":"+padd(nowDate.getSeconds());
}
function scormAPI() {
	this.scormVars = new Object();
	this.changes = 0;
	this.interactions = 0;
}
	scormAPI.prototype.Initialize = function(pStr){
		//document.getElementById("logOut").value+=getTimeStamp()+" Initialize("+pStr+")\r";
		isSCORM=true;
		playbuttonObj = $("#productListTable #row"+vidContentID+" #playButton");
		if(playbuttonObj.attr("class") != "completed")
			playbuttonObj.attr("class","opened");
		console.log("video initialized: "+vidContentID);
		return "true";
	}
	scormAPI.prototype.Terminate = function(pStr){
		//document.getElementById("logOut").value+=getTimeStamp()+" Terminate("+pStr+")\r";
		if(this.changes)
			this.Commit(pStr);
		console.log("video terminated: "+vidContentID);
		vidContentID='';
		isSCORM=false;
		return "true";
	}
	scormAPI.prototype.GetValue = function(pStr){
		//while(vidLoading == true){
		//	x=1;
		//}
		retStr = "unknown";
		if(typeof(this.scormVars[pStr]) != "undefined")
			retStr=this.scormVars[pStr];
		else if(pStr == "cmi.success_status")
			retStr="unknown";
		else if(pStr == "cmi.completion_status")
			retStr="not attempted";
		else if(pStr == "cmi.mode")
			retStr="normal";
		else if(pStr == "cmi.suspend_data")
			retStr="";
		else if(pStr == "cmi.interactions._count")
			retStr=this.interactions++;
		//document.getElementById("logOut").value+=getTimeStamp()+" GetValue("+pStr+")="+retStr+"\r";
		console.log(vidContentID+": GetValue("+pStr+")="+retStr);
		return retStr;
	}
	scormAPI.prototype.SetValue = function(pStr,vStr){
		//document.getElementById("logOut").value+=getTimeStamp()+" SetValue("+pStr+","+vStr+")\r";
		this.scormVars[pStr]=vStr;
		this.changes=1;
		if(pStr.toUpperCase() == "CMI.COMPLETION_STATUS" && vStr == "completed")
			$("#productListTable #row"+vidContentID+" #playButton").attr("class","completed");
		//this.DumpVars();
		console.log(vidContentID+": SetValue("+pStr+")="+vStr);
		return "true";
	}
	scormAPI.prototype.Commit = function(pStr){
		//document.getElementById("logOut").value+=getTimeStamp()+" Commit("+pStr+")\r";
		if(this.changes == 1){
			postData=this.scormVars;
			$.extend(postData,{contentid:vidContentID,userid:vidUserID,action:"save"});
			//$.post(SCORMProxyURL,{contentid:vidContentID,userid:vidUserID,action:"save",data:this.scormVars.toString()});
			if(vidUserID != '')
				$.post(SCORMProxyURL,postData);
			console.log(vidContentID+": Commit()");
			this.changes=0;
		}
		return "true"
	}
	scormAPI.prototype.GetLastError = function(pStr){
		//document.getElementById("logOut").value+=getTimeStamp()+" GetLastError("+pStr+")=0\r";
		return "0";
	}
	scormAPI.prototype.GetErrorString = function(pStr){
		//document.getElementById("logOut").value+=getTimeStamp()+" GetErrorString("+pStr+")=none\r";
		return "none";
	}
	scormAPI.prototype.GetDiagnostic = function(pStr){
		//document.getElementById("logOut").value+=getTimeStamp()+" GetDiagnostic("+pStr+")=none\r";
		return "none";
	}
	scormAPI.prototype.DumpVars = function(){
			retStr="";
			for(key in this.scormVars){
				if(this.scormVars[key].indexOf){
					if(this.scormVars[key].indexOf("|")!=-1){
						retStr+=key+"=\r";
						valList = this.scormVars[key].split("|");
						for(x=0;x<valList.length;x++){
							retStr+="     "+valList[x]+"\r";
						}
					}else{
						retStr+=key +"="+this.scormVars[key]+"\r";
					}
				}
			}
			document.getElementById("varOut").value=retStr;

	}
var API_1484_11 = new scormAPI();
var vidContentID = '';
var vidUserID = '';
var isSCORM = false;
//var vidLoading = false;

function launchSCORM_LM(scormurl,contentid){
	//alert("got here "+contentid);
	if(vidContentID != '' && isSCORM == true){
		alert('please close the active lesson before starting another one');
		return;
	}
	if(vidUserID == '')
		alert('if you are not logged in then your lesson progress will not be saved');
	if(vidContentID!=contentid){
		vidContentID=contentid;
		API_1484_11.scormVars=new Object();
	}
	console.log("video launched: "+vidContentID);

	//vidLoading=true;
	if(vidUserID != '')
		$.ajax({url:SCORMProxyURL,async:false,data:{contentid:vidContentID,userid:vidUserID,action:"get"},dataType:"json",type:"post",success:function(data){API_1484_11.scormVars=data}});
	//vidLoading=false;
	//window.open(scormurl,'_blank','');
	
	/* 2010-06-03 (dspeaker) added in place of above line */
	var winWidth = 1000;
	var winHeight = 740;
	modWin = window.open(scormurl, '_blank', 'width='+winWidth+',height='+winHeight+',resizable=1');
	modWin.moveTo(screen.width/2 - winWidth/2, screen.height/2 - winHeight/2); //attempt to center
}


//$(function(){
//	$("body").append("<textarea rows='20' cols='50' id='logOut' wrap='off'></textarea><textarea rows='20' cols='50' id='varOut' wrap='off'></textarea><button onClick=\"window.open('http://local.support.pearsonschool.com/coco_mura/tasks/sites/mtc/assets/Flash/SMXQuiznSurvey/index_lms.html','newWin','height=600,width=800');return false;\">Launch The Lesson 2</button>");
//});

