var nRestoreMode = 0;
var strRootDir = "";
var browser=getBrowserInfo();

function getBrowserInfo() {
	if(window.navigator.appVersion.indexOf("MSIE 6") >= 0){return "IE6";}
	else if(window.navigator.appVersion.indexOf("MSIE 5") >= 0){return "IE5";}
	else if(window.navigator.appVersion.indexOf("MSIE 4") >= 0){return "IE4";}
	else if(window.navigator.appVersion.indexOf("Netscape") >= 0){return "NC";}
	else if(window.navigator.appName.indexOf("Netscape") >= 0 && window.navigator.appVersion.indexOf("Netscape") < 0){return "NN";}
	return "other"
}


// Finds the selected rows in the data tables displayed
// as part of the Administrator and Professor interfaces
// Returns and array of ID's that correspond the the objects
// in the selected rows
function getSelected()
{
	var cForm = document.forms.dataTable;

	var aSelected = new Array();

	if(cForm!=null)	
		for(var i=0; i<cForm.elements.length; i++)
		{
			if(cForm.elements[i].type=="checkbox" && cForm.elements[i].checked && !isNaN(cForm.elements[i].value))
				aSelected[aSelected.length] = cForm.elements[i].value;
		}
	
	return aSelected;
} 

function getSelectedRadio()
{
	var cForm = document.forms.dataTable;

	var aSelected = new Array();

	if(cForm!=null)	
		for(var i=0; i<cForm.elements.length; i++)
		{
			if(cForm.elements[i].type=="radio" && cForm.elements[i].checked)
				aSelected[aSelected.length] = cForm.elements[i].value;
		}
	
	return aSelected;
} 
xavailWidth=1024;
xavailHeight=768;
// var MSIE = (document.all && !window.opera)?true:false;
// var iebody = document.compatMode && document.compatMode != 'BackCompat' ? document.documentElement : document.body,
// xavailWidth = MSIE ? iebody.clientWidth : (document.documentElement.clientWidth || window.innerWidth),
// xavailHeight = MSIE ? iebody.clientHeight : window.innerHeight;
//return { xavailWidth: xavailWidth, xavailHeight: xavailHeight, scrollLeft: MSIE ? iebody.scrollLeft : window.pageXOffset, scrollTop: MSIE? iebody.scrollTop : window.pageYOffset }
	xavailWidth=screen.availWidth;
	xavailHeight=screen.availHeight;
	if(xavailWidth<600)
		xavailWidth = 1024;
	if(xavailHeight<400)
		xavailHeight = 768;	
function doPopup(strLocation, nWidth, nHeight, strOptions)
{
	//doPopupN(strLocation, nWidth, nHeight, strOptions);
	//return null;
	if(strOptions==null||strOptions=="undefined")
		strOptions = "";
	if(nWidth==-1)
		nWidth = xavailWidth;
	if(nHeight==-1)
		nHeight = xavailHeight;		
	//var cWin = window.open(strLocation, "", "WIDTH="+nWidth+",HEIGHT="+nHeight+","+strOptions);
	
	//cWin.moveTo(0,0);	
	if(nWidth<300)
		nWidth = xavailWidth-20;
	if(nHeight<300)
		nHeight = xavailHeight-20;	
		
	
	if (window.showModalDialog) {
		var strFeatures = "status:no; scroll:off; dialogHeight:"+nHeight+"px; dialogWidth:"+nWidth+"px;" + strOptions;
		var cRet = window.showModalDialog(strLocation, "", strFeatures);			
		return cRet;
	} else {
		var strFeatures = "modal=yes,stausbar=no, scrollbars=yes, height="+nHeight+", width="+nWidth+"," + strOptions;
		var cRet = window.open(strLocation,'',strFeatures);
		return cRet;
	}

	
	
}


function doPopupN(strLocation, nWidth, nHeight, strOptions, strWinName)
{
	if(strOptions==null||strOptions=="undefined")
		strOptions = "";
		
	if(strWinName==null||strWinName=="undefined")
		strWinName = "";	
		
	if(nWidth==-1)
		nWidth = xavailWidth;
	if(nHeight==-1)
		nHeight = xavailHeight;		
	//var cWin = window.open(strLocation, strWinName, "resizable=yes,scrollbars=yes,status=yes,menubar=yes,WIDTH="+nWidth+",HEIGHT="+nHeight+","+strOptions);
	var cWin = window.open(strLocation, strWinName, "resizable=yes,WIDTH="+nWidth+",HEIGHT="+nHeight+","+strOptions);
	
	var x = parseInt((xavailWidth / 2) - (nWidth / 2));
	var y = parseInt((xavailHeight / 2) - (nHeight / 2));
	if(x<20)
		x = 0;
	if(y<20)
		y = 0;
	if (cWin != null)
	{
		cWin.moveTo(x,y);
		cWin.focus();	
	}
	return cWin;
}


var strKAID = "";
function saveState(strAttrName)
{
	strAttrName = strAttrName+strKAID;
		
	if(document.forms.dataTable!=null)
	{
		var aID = getSelected();
		//cachetag.setAttribute("ids",aID);
	   	//cachetag.save(strAttrName);
	}
}

function restoreState(strAttrName)
{
	strAttrName = strAttrName+strKAID;
	
	if(document.forms.dataTable==null)
		return false;
   	//cachetag.load(strAttrName);
   	//var aID = cachetag.getAttribute("ids");
	var aID=null;
	if(aID!=null && aID!="")
	{
		aID = aID.split(",");

		if(nRestoreMode == 0)
		{
			var cCB = null;
			for(var i=0; i<aID.length; i++)
			{	
				cCB = document.all["cb"+aID[i]];
				if(cCB!=null)
					cCB.checked = true;
				var cb = document.all["tr"+aID[i]];
				if(cb)
					cb.className = "dataTableRowSelected"
				
			}
		} else {
			var e = document.forms.dataTable.elements;
			var bCheck = false;
			for(var i=0; i<e.length; i++)
			{
				bCheck = false;
				if(e[i].type=="checkbox")
				{
					for(var j=0; j<aID.length; j++)
					{
						if(e[i].value == aID[j])
							bCheck = true;
					}
					e[i].checked = bCheck;
				}
			}			
		}
	}
	
	if(top.nCutAndCopyState == null)
		return;
	
	if(strContentType && top.clipboard)
	{
		if(strContentType == top.clipboard.contentType && top.clipboard.action == "cut")
		{
			for(var i = 0; i < top.clipboard.items.length; i++)
			{
				var e = document.all["tr" + top.clipboard.items[i]];
				if(e)
					e.disabled = true;				
			}
		}	
	}	
	
	if(getSelected().length > 0)
		top.nCutAndCopyState = 1;		
	else
		top.nCutAndCopyState = 0;	
	
	if(isCutCopyPasteDisabled())
		top.nCutAndCopyDisabled = true;
	else
		top.nCutAndCopyDisabled = false;
		
	updateButtons();
}

function changeDateState(nIndex, bState)
{
	document.forms.dataTable["nDate" + nIndex].disabled = bState;
	document.forms.dataTable["nMonth" + nIndex].disabled = bState;
	document.forms.dataTable["nYear" + nIndex].disabled = bState;
	document.forms.dataTable["nHours" + nIndex].disabled = bState;
	document.forms.dataTable["nMinutes" + nIndex].disabled = bState;
	document.forms.dataTable["strAmPm" + nIndex].disabled = bState;	
	
	if(bState)
		document.styleSheets(0).rules(0).style.color = "#808080";
	else
		document.styleSheets(0).rules(0).style.color = "#000000";	
}

function switchImage(name, num)
{
	var strState = "";
	if(name.toUpperCase() == "CUT" || name.toUpperCase() == "COPY"  || name.toUpperCase() == "PASTE" || name.toUpperCase() == "DELETE" || name.toUpperCase() == "PUBLISH")
	{
		if(!top.nCutAndCopyDisabled)
		{
			strState= "_" + top.nCutAndCopyState;	
			if(name.toUpperCase() == "PASTE")
			{
				strState = "_" + ((top.clipboard.items.length == 0)? 0 : 1);					
			}					
		}
		else
		{
			strState = "_" + ((name.toUpperCase() == "DELETE")? top.nCutAndCopyState : 0);
		}	
	}
	if(top.nCutAndCopyState == null)
		strState = "";	
	document.images[name].src = "../images/" + name + strState+ "_" + num + ".gif";	
}

function taskBarButton(strName, nState)
{
	if(document.all['tb'+strName].className != "taskBarButton2")
		document.all['tb'+strName].className = "taskBarButton"+nState;
}

function chooseTaskBarButton(nID)
{
	document.all["windowTitle"].innerHTML = aTaskBarButtons[nID*2];
	if (document.frames) {
		document.frames["app"].location = aTaskBarButtons[nID*2+1];
	}
	else {
		document.all.app.src=aTaskBarButtons[nID*2+1];
		//document.getElementById('app').location.href = aTaskBarButtons[nID*2+1];
	}
	//alert ("location changed="+aTaskBarButtons[nID*2+1]);
	document.all["tb"+(nSelectedButton+1)].className = "taskBarButton0";
	document.all["tb"+(nID+1)].className = "taskBarButton2";
	
	var d = document;
	if(parent!=null)
		d = parent.document;
		
	//d.images["view"+(nSelectedButton+1)].src = "../images/clpx.gif";
	//d.images["view"+(nID+1)].src = "../images/check.gif";
	
	nSelectedButton = nID;
	nSelectedTab = 0;
	drawTabs(0);
}


function findSizes()
{
	var nWidth = document.body.clientWidth;
	alert(nWidth);
}

function doScroll()
{
	var boo = document.all["boo"];
	boo.style.top = document.body.scrollTop;
}

function disableFormButtons()
{
	for(var i=0; i<document.forms.length; i++)
	{
		var e = document.forms[i].elements;
		for(var j=0; j<e.length; j++)
		{
			e[j].disabled = true;
		}
	}
}

function CButton(strLable, strHref, strJS, strName, nState, bDisabled)
{
	if(strHref=="" || strHref=="undefined")
		strHref = "#";
	this.strLable = strLable;	
	this.strName = strName;
	this.strHref = strHref;
	this.strOnClick = strJS;
	this.nType = 0;
	this.nState = nState;
	this.isDisabled = (bDisabled == null)? false : bDisabled;
	this.setState = setState;
}

function CDropButton(strLable, strName, strImage, nState)
{
	this.strLable = strLable;
	this.strName = strName;
	this.nType = 1;
	if(strImage!=null)
	{
		this.strImage = strImage;
	} else {
		this.strImage = "";
	}
	this.nState = nState;
	this.aChildren = new Array();
	this.setState = setState;
}

function updateButtons()
{
	if(aButtons == null || top.nCutAndCopyState == null)
		return;

	if(getSelected().length == 0 || strContentType == "users")
		top.document.all["itemPROPERTIES"].disabled = true;
	else
		top.document.all["itemPROPERTIES"].disabled = false;	
	
	for(var i = 0; i < aButtons.length; i++)
	{
		if(aButtons[i].strName.toUpperCase() == "CUT" || aButtons[i].strName.toUpperCase() == "COPY" || aButtons[i].strName.toUpperCase() == "DELETE" || aButtons[i].strName.toUpperCase() == "PUBLISH")
		{
			if(top.nCutAndCopyDisabled && aButtons[i].strName.toUpperCase() != "DELETE")
				aButtons[i].setState(0);						
			else
				aButtons[i].setState(top.nCutAndCopyState);	
		
			if(top.document.all["item" + aButtons[i].strName.toUpperCase()])
			{
				if(aButtons[i].nState == 1)
					top.document.all["item" + aButtons[i].strName.toUpperCase()].disabled = false;
				else
					top.document.all["item" + aButtons[i].strName.toUpperCase()].disabled = true;
			}
		}	
		if(aButtons[i].strName.toUpperCase() == "PASTE")
		{
			var nState = (top.clipboard.items.length == 0)? 0 : 1;
			
			if(top.nCutAndCopyDisabled)
				nState = 0;
				
			aButtons[i].setState(nState);	
			if(top.document.all["item" + aButtons[i].strName.toUpperCase()])
			{
				if(nState == 1)
					top.document.all["item" + aButtons[i].strName.toUpperCase()].disabled = false;
				else
					top.document.all["item" + aButtons[i].strName.toUpperCase()].disabled = true;
			}
			
		}
	}	
}

function setState(nState)
{
	this.nState = nState;	
	
	if(top.document.all["taskBar"] && top.document.all["taskBar"].document.images[this.strName.toLowerCase()] != null)
	{
		top.document.all["taskBar"].document.images[this.strName.toLowerCase()].src = '../images/' + this.strName+ "_" + this.nState +'_0.gif';		
	}	
}

function CTab(strName, strHref)
{
	this.strName = strName;
	this.strHref = strHref;
}

function drawButtons()
{
	var strButtons = "";
	for(var i=0; i<aButtons.length; i++)
	{
		var strState = "";
		
		if(aButtons[i].nState != null)
			strState = "_" + aButtons[i].nState;
			
		if(aButtons[i].nType==0)
		{
			strButtons += '&nbsp;<a href="'+aButtons[i].strHref+'"';
			strButtons += ' onmouseup="document.frames.panel.document.frames.app.'+aButtons[i].strOnClick+'; return false;" onmouseout="switchImage(\''+aButtons[i].strName + '\',0)"'; 	
			strButtons += ' onmouseover="switchImage(\''+aButtons[i].strName+'\',1)"'; 	
			strButtons += ' onmousedown="switchImage(\''+aButtons[i].strName+'\',2)">';
			strButtons += '<img name="'+aButtons[i].strName+'" border="0" src="../images/'+aButtons[i].strName+ strState +'_0.gif" alt="'+aButtons[i].strLable+'" name="'+ aButtons[i].strName + '"></a>';
		}
		
		if(aButtons[i].nType==1)
		{
			strButtons += '&nbsp;<a href=""';
			strButtons += " onclick=\"return buttonClick(event, 'dropdown"+i+"');\" ";
			strButtons += ' onmouseout="switchImage(\''+aButtons[i].strName+'\',0)"'; 	
			strButtons += ' onmouseover="buttonClick(event, \'dropdown'+i+'\'); switchImage(\''+aButtons[i].strName+ strState +'\',1)"'; 	
			strButtons += ' onmousedown="switchImage(\''+aButtons[i].strName+'\',2)">';
			strButtons += '<img name="'+aButtons[i].strName+'" border="0" src="../images/'+aButtons[i].strName+ strState +'_0.gif" alt="'+aButtons[i].strLable+'" name="'+ aButtons[i].strName + '"></a>';
			var buttons = aButtons[i].aChildren;
			strButtons += '<div id="dropdown'+i+'" class="menu" onmouseover="menuMouseover(event)">';
			for(var j=0; j<buttons.length; j++)
			{
				strButtons += '<a class="menuItem" href="#" onClick="'+buttons[j].strOnClick+'; return false;" target="_top">'+buttons[j].strLable+'</a>';
			}
			strButtons += "</div>";
		}
		
	}
	if(top.document.all["taskBar"]!=null)
		top.document.all["taskBar"].innerHTML = strButtons;
}

function openChatRoom(nRoomID)
{
	var w = window.open("../aspchat/chatroom.asp?nRoomID="+nRoomID, "CHAT", "WIDTH=800,HEIGHT=600,SCROLLBARS=NO,LOCATION=NO,TOOLBARS=NO, STATUSBAR=NO");
	w.moveTo(0,0);
}

function LogEntry(nID, nObjectID, strObjectTable, nActionID, nUserID, strActionDate, strUsersName)
{
	this.nID = nID;
	this.nObjectID = nObjectID;
	this.nActionID = nActionID;
	this.strObjectTable = strObjectTable;
	this.nUserID = nUserID;
	this.cActionDate = new Date(strActionDate);
	this.strUsersName = strUsersName;
}

function performLockEntryFormOnLoad()
{
	// If Global Variable NLOCK is -1, the lock was not obtained
	if(nLock == -1)
	{
		// Disables any buttons or submit buttons found in the form
		disableFormButtons();
	}
}

function performLockToolbarOnLoad()
{
	// If Global Variable NLOCK is -1, the lock was not obtained
	if(nLock == -1)
	{
		// Disable any links with the buttonBarButton class by changing class to buttonBarButtonDisabled
		for(var i=0; i<document.links.length; i++)
		{
			if(document.links(i).className == "buttonBarButton")
			{
				document.links(i).className = "buttonBarButtonDisabled";
				document.links(i).href = "#";
				document.links(i).onclick = null;
			}
		}
	}
}

function getPathToRemoteASP()
{
	var strPath = document.location+"";
	strPath = strPath.toUpperCase();
	aDirs = strPath.split("/");
	var j = 0;
	for(var i=aDirs.length - 1; i>0; i--)
	{
		if(aDirs[i] == "APPLICATION")
			break;
		j++;
	}
	j = j - 1;
	var strDelim = "";
	var strRet = "";
	for(var i=1; i<=j; i++)
	{
		strRet = ".." + strDelim + strRet
		strDelim = "/";
	}
	return strRet;
}

function releaseLock()
{
	// If the user own's the lock execute this function to release the lock
	// when the editor closes
	if(nLock == 1 && cLock != null)
	{
		var s = 'Release Lock\n';
		s += 'Object ID: '+cLock.nObjectID+'\n';
		s += 'Object Table: '+cLock.strObjectTable+'\n';
		s += 'Action Time: '+cLock.cActionDate+'\n';
		s += 'User ID: '+cLock.nUserID+'\n';
		//alert(s);
		getPathToRemoteASP();
		
		var objHTTP=null
		//if (browser != "other" && browser!="NN" && browser!="NC") {
		if (window.ActiveXObject) {
			objHTTP = new ActiveXObject("Microsoft.XMLHTTP")
		}
		else {
			objHTTP=new XMLHttpRequest()
		}
		
		if (objHTTP!=null)
		{
			objHTTP.Open('GET',getPathToRemoteASP()+'/lib/remotecalls.asp?strRequest=releaselock&nID='+cLock.nID+'&nUserID='+cLock.nUserID,false)
			objHTTP.Send()
		}
		else {
			alert("Uyarı:İnternet tarayıcınız bu sitenin tam olarak çalışması için gerekli bazı özellikleri içermiyor.")
		}
			
	}
}

function transferLock(nUserID)
{
	var s = 'Transfer Lock\n';
	s += 'Object ID: '+cLock.nObjectID+'\n';
	s += 'Object Table: '+cLock.strObjectTable+'\n';
	s += 'Action Time: '+cLock.cActionDate+'\n';
	s += 'User ID: '+cLock.nUserID+'\n';
	s += '\n\n';
	s += 'To user '+nUserID;
	//alert(s);
	if(cLock != null)
	{
		var objHTTP = new ActiveXObject("Microsoft.XMLHTTP")
		objHTTP.Open('GET',getPathToRemoteASP()+'/lib/remotecalls.asp?strRequest=transferlock&nID='+cLock.nID+'&nOldUserID='+cLock.nUserID+'&nNewUserID='+nUserID,false)
		objHTTP.Send()
	}
	
	return 1;
}

var nLastClicked = 0;
var aLastClicked = new Array();
function doClickDataRow(nID)
{
	var cb = document.dataTable.elements["cb"+nID];
	if(cb && cb.type == "checkbox")
	{
		if(event.srcElement == cb)
		{
			// clicked on the checkbox
			if(cb.checked)
			{
				document.all["tr"+nID].className = "dataTableRowSelected";
				aLastClicked["tr"+nID] = 1;
			} else {
				document.all["tr"+nID].className = "dataTableRow";
				aLastClicked["tr"+nID] = 0;
			}
		} else {
			// clicked on the row or a radio

			/* 
			Code commented out by Glen - May 26 - when you select a new item in Windows Explorer, that item is selected
			regardless of its current state.  The other items that are selected then lose selection */
			/*
			if(cb.checked)
			{
				cb.checked = false;
				document.all["tr"+nID].className = "dataTableRow";
				aLastClicked["tr"+nID] = 0;
			} else {
				cb.checked = true;
				document.all["tr"+nID].className = "dataTableRowSelected";
				aLastClicked["tr"+nID] = 1;
			}*/

			// Clear currently checked items
			var a = getSelected();
			for(var i=0; i<a.length; i++)
			{
				document.all["tr"+a[i]].className = "dataTableRow";
				var cTempCB = document.dataTable.elements["cb"+a[i]];
				if(cTempCB && (cTempCB.type == "checkbox" || cTempCB.type == "radio") )
				{
					cTempCB.checked = false;
				}
			}
			
			// Item is not checked so check it
			if(!cb.checked)
			{
				cb.checked = true;
				document.all["tr"+nID].className = "dataTableRowSelected";
				aLastClicked["tr"+nID] = 1;
			}
		}
	} else {
		document.all["tr"+nID].className = "dataTableRowSelected";
		if(document.all["tr"+nLastClicked] != null)
			document.all["tr"+nLastClicked].className = "dataTableRow";
		nLastClicked = nID;	
	}
	
	if(document.all["removeBTN"])
	{
		if(getSelected().length == 0)
			document.all["removeBTN"].disabled = true;
		else
			document.all["removeBTN"].disabled = false;	
	}

	if(top.nCutAndCopyState == null)
		return;
		
	if(getSelected().length > 0)
	{
		top.nCutAndCopyState = 1;		
	}
	else
	{
		top.nCutAndCopyState = 0;			
	}	
	if(isCutCopyPasteDisabled())
		top.nCutAndCopyDisabled = true;
	else
		top.nCutAndCopyDisabled = false;	
	updateButtons();
}

function isCutCopyPasteDisabled()
{
	for(var i = 0; i < aButtons.length; i++)
	{
		if(aButtons[i].strName.toUpperCase() == "CUT" || aButtons[i].strName.toUpperCase() == "COPY" || aButtons[i].strName.toUpperCase() == "PASTE")
		{
			return aButtons[i].isDisabled;
		}
	}	
	return false;
}

function checkAll()
{
	var f = document.forms.dataTable;
	if(f)
	{
		for(var i=0; i<f.elements.length; i++)
			if(f.elements[i].type == "checkbox")
				f.elements[i].click();
		
	}
}

//select Knowledge Area
function getKAID(nMode, nIndex)
{
	var f = document.forms[0];
	var nKAID = -1;
	var strTree = "";
	
	if(f.nKAID.length)
	{
		nKAID = f.nKAID[nIndex].value;
		strTree = f.strTree[nIndex].value;
	}
	else
	{
		nKAID = f.nKAID.value;
		strTree = f.strTree.value;
	}
	var win = doPopupN(getPathToRemoteASP() + "/question-builder/getKA.asp?nClickedID=" + nKAID + "&strTree=" + strTree + "&nMode=" + nMode + "&nIndex=" + nIndex, 500, 450, "scrollbars=1,resizable=1", 'KABrowser');
	win.focus();
	
	changeApplyState();
}

//select Knowledge Area
function getKAID2(nParentID,nMode, nIndex)
{
	var f = document.forms[0];
	var nKAID = -1;
	var strTree = "";
	
	if(f.nKAID.length)
	{
		nKAID = f.nKAID[nIndex].value;
		strTree = f.strTree[nIndex].value;
	}
	else
	{
		nKAID = f.nKAID.value;
		strTree = f.strTree.value;
	}
	var win = doPopupN(getPathToRemoteASP() + "/question-builder/getKA.asp?nParentID="+nParentID+"&nClickedID=" + nKAID + "&strTree=" + strTree + "&nMode=" + nMode + "&nIndex=" + nIndex, 500, 450, "scrollbars=1,resizable=1", 'KABrowser');
	win.focus();
	
	changeApplyState();
}


function doProperties()
{
	if(getSelected().length == 0)
		return false;
		
	var nContentType = 0;
	
	switch(strContentType)
	{
		case "courses": nContentType = 0;
						break;
		case "templates": nContentType = 2;
						break;						
		case "certificates": nContentType = 3;
						break;
		case "hp": nContentType = 4;
						break;
		case "tests": nContentType = 5;
						break;
		case "questions": nContentType = 6;
						break;
		case "pages": nContentType = 7;
						break;
		case "lu": nContentType = 8;
						break;
		case "exercises": nContentType = 9;
						break;
		case "announcements": nContentType = 10;
						break;
		case "surveys": nContentType = 11;
						break;
		case "chat": nContentType = 12;
						break;																																																		

		default: return false;
	}
	var ret = doPopup('../lib/properties-outer.asp?nID=' + getSelected() + '&nContentType=' + nContentType + "&nKAID=" + strKAID, 500, 565, '');
	document.location.reload();
}

function doOKSubmit()
{
	if(document.forms.dataForm == null)
	{
		self.close()
		return;
	}	
	document.forms.dataForm.nMode.value = 1;
	
	if(this.doUpdate)
	{
		if(!doUpdate())	
			return false;
	}
	this.flushMemory();
	document.forms.dataForm.submit();	
}

function doApply()
{
	document.forms.dataForm.nMode.value = 0;
	if(this.doUpdate)
	{
		if(!doUpdate())	
			return false;
	}
	memorizeSettings(true);
	document.forms.dataForm.submit();	
}

function changeApplyState()
{
	if(top.document.all.applyBTN)
		top.document.all.applyBTN.disabled = false;
}

function doOnClose()
{
	var f = document.forms[0];
	if(f.nMode.value == 1)
		this.flushMemory();
}

function doCancelSave()
{
	this.flushMemory();
	top.close();
}
/************************************************************************************/
/* Cut, Copy, and Paste functions                                                   */
/************************************************************************************/

function doCut()
{
	if(strContentType == "users")
		return;
		
	if(top.nCutAndCopyState == 1)
	{
		top.clipboard.action = "cut";
		top.clipboard.contentType = strContentType;
		top.clipboard.items = getSelected();
		top.clipboard.KAID = strKAID;
		updateButtons();
		for(var i = 0; i < top.clipboard.items.length; i++)
		{
			document.all["tr" + top.clipboard.items[i]].disabled = true;
		}	
	}		
}

function doCopy()
{
	if(strContentType == "users")
		return;
		
	if(top.nCutAndCopyState == 1)
	{
		top.clipboard.action = "copy";
		top.clipboard.contentType = strContentType;
		top.clipboard.items = getSelected();
		top.clipboard.KAID = strKAID;
		updateButtons();
		for(var i = 0; i < top.clipboard.items.length; i++)
		{
			document.all["tr" + top.clipboard.items[i]].disabled = false;
		}	
	}	
}

function doPaste()
{
	if(strContentType == "users")
		return;
	
	if(strContentType != top.clipboard.contentType)
	{
		var strTemp = arrStrings["cannotpaste"];
		strTemp = strTemp.replace("%strContentType%",  top.clipboard.contentType);
		strTemp = strTemp.replace("%strContentType2%",  strContentType);
		alert(strTemp);
		return;
	}
		
	if(top.clipboard.items.length > 0)
	{
		var strAction = top.clipboard.action;
		//<%=Application("BaseURL")%>/<%=Application("BaseDir")%>
		var strRedir = "/application/lib/paste.asp?aID=" + top.clipboard.items + "&strContent=" + strContentType + "&strAction=" + strAction + "&nKAID=" + strKAID;
		top.clipboard.action = "";
		top.clipboard.items = new Array();
		top.clipboard.KAID = -1;
		updateButtons();
		//top.document.frames.panel.document.frames.app.location = strRedir;
		
		getXMLRequest(strRedir);
	}
	else
	{
		//alert("Cannot paste: the source has been deleted.");
	}	
}

function doDelete()
{
	switch(strContentType)
	{
		case "courses": doDeleteCourses();
						break;
		case "templates": doDeleteSkins();
						break;						
		case "certificates": doDeleteCertificates();
						break;
		case "hp": doDeleteHelpPages();
						break;
		case "tests": doDeleteTests();
						break;
		case "questions": doDeleteQuestions();
						break;
		case "pages": doDeleteFlatPages();
						break;
		case "lu": doDeleteLearningUnits();
						break;
		case "exercises": doDeleteExercises();
						break;
		case "announcements": doDeleteAnnouncements();
						break;
		case "surveys": doDeleteSurveys();
						break;
		case "chat": doDeleteChatrooms();
						break;
		case "users": doDeleteUsers();
			break;																																																						
	}
}


function getXMLHTTPHandle()
{
	if(document.all)
	{	
		//alert("getting Microsoft.XMLHTTP");
		return (new ActiveXObject("Microsoft.XMLHTTP"));
		
	 }	
	else
	{
		//alert("getting XMLHttpRequest");
		return (new XMLHttpRequest());	
	}	
}

function getXMLRequest(strURL)
{

	var xmlHTTP = getXMLHTTPHandle();
	xmlHTTP.open("GET",strURL, false);	
	xmlHTTP.send();
	if(xmlHTTP.status == 200)
	{
		var ParamProc = new ParamProcessor(xmlHTTP.responseXML);
		if(ParamProc.getParam("errorCode") != "0")
		{
			if(ParamProc.getParam("errorMessage") != "")
			{
				alert(ParamProc.getParam("errorMessage"));
			}	
		}	
		var strData = ParamProc.getParam("data");
		switch(ParamProc.getParam("doAction"))
		{
			case "refresh": document.location = strData;		
							//top.document.frames.panel.document.frames.app.location = strData;
							break;
									alert("4");

							
			case "returndata": xmlHTTP = null;
									alert("4");
								return strData;
								break;							
			//case "close": top.close();
			//				break;				
		}
		
	}
	else
	{
		var strMSG = arrStrings["connectionfailed"].replace("%nSTATUS%", xmlHTTP.status);
		alert(strMSG);
	}	
	xmlHTTP = null;	

}


/**************************************************************************************/
/* ParamProcessor - processes the XML Response										  */
/**************************************************************************************/
function ParamProcessor(xmlDoc)
{
	this.xmlDoc = xmlDoc;
	this.getParam = getParam;
}

function getParam(strParam)
{
	return this.xmlDoc.getElementsByTagName(strParam).item(0).text;	 
}

/*************************************************************************************/
/* COOKIE Management																 */
/*************************************************************************************/

function setCookie(key, value) 
{  
   //document.cookie = key + "=" + escape(value)  + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()));
   document.cookie = key + "=" + escape(value);
}

function getCookie(Name) 
{   
    var search = Name + "=";
    if (document.cookie.length > 0) 
    { // if there are any cookies      
	   offset = document.cookie.indexOf(search);      
	   if (offset != -1) 
	   { // if cookie exists          
	     offset += search.length;          // set index of beginning of value         
    	 end = document.cookie.indexOf(";", offset);          // set index of end of cookie value         
		 if (end == -1)             
		   end = document.cookie.length;
		 return unescape(document.cookie.substring(offset, end))      
       }   
    }
	return null;
}

function clearCookie(Name)
{
	var expire = new Date();
	expire.setYear(expire.getFullYear() - 1);
	document.cookie = Name + "=dummy; expires=" + expire.toGMTString();
}

function memorizeSettings(bForce)
{
	var f = document.forms.dataForm;
	//if(getCookie("aID") == f.aID.value && getCookie("nContentType") == f.nContentType.value && !bForce)
	//	return;
	
	var elem;
	for(var i = 0; elem = f.elements[i]; i++)
	{
		if(elem.type == "checkbox")
		{
			if(elem.checked)
				setCookie(elem.name, 1); 	
			else
				setCookie(elem.name, 0); 	
		}	
		else if(elem.type != "button")
			setCookie(elem.name, elem.value);
			
	}
}

function flushMemory()
{
	var f = document.forms.dataForm;
	var elem;
	for(var i = 0; elem = f.elements[i]; i++)
	{
		if(elem.type != "button")
			clearCookie(elem.name);
	}
}
