// Prevents event bubble up or any usage after this is called.
// pE - event object
function StopEvent(pE)
{
	if (!pE) {
		if (window.event) pE = window.event;
		else return;
	}
	if (pE.cancelBubble != null) pE.cancelBubble = true;
	if (pE.stopPropagation) pE.stopPropagation();
	if (pE.preventDefault) pE.preventDefault();
	if (window.event) pE.returnValue = false;
	if (pE.cancel != null) pE.cancel = true;
}

function Pg(pageNum, evt)
{	    
    StopEvent(evt);
	var href="?" + Add2Query("pg",pageNum);	
	Transfer(href);
}
function ItemNav(itemCode)
{
	var href="?" + Add2Query("_item",itemCode);
	Transfer(href);
}
function GoBack(lnk)
{
	//Construct back functionality
	if(GetTransferEl("_displayMode")=="item")
	{//Inner Item View State
		SetTransferEl("_back",(GetTransferEl("_back2main")));
		SetTransferEl("_back2main",(GetTransferEl("_back2main")));
	}
	Transfer(lnk);
}
function ItemNew(uLnk,cWidth,cHeight)
{
	var dWidth=Math.min(parseInt(window.screen.availWidth*0.9), 900);  
	var dHeight=Math.min(parseInt(window.screen.availHeight*0.9), 600); 
	if(cWidth) dWidth=cWidth;
	if(cHeight) dHeight=cHeight;
	
	 
	var msg_mnew="new";
	var msg_iLoading="loading";
	if(typeof(mNew)=="string")
		msg_mnew=mNew;
	if(typeof(iLoading)=="string")
		msg_iLoading=iLoading;
	// CHANGE ERROR (Tonya 04.11.2007)
	// for editor light (not work with showModalDialog!)	
	if(typeof(typeEditor)=="string" && typeEditor=="full")
	    ModalDialog_Show(uLnk,dWidth,dHeight,msg_mnew,msg_iLoading)
	else
	    ModalDialog_Show_Debug(uLnk,dWidth,dHeight,msg_mnew,msg_iLoading)
}/**/
        function Url(str, noBack)
        {
	        if(str!="")
	        {
		        var query=document.location.search;
		        var coll=str.split("&");
		        for(var i=0;i<coll.length;i++)
		        {
			        var elStr=coll[i].split("=");
			        if(elStr.length>1)
				        query=Add2Query(elStr[0],elStr[1],query);
		        }
        		
        		MakeButtonsUrl(noBack);
        		
		        Transfer("?" + query)
	        }
        }
        
function MakeButtonsUrl(noBack)
{
        var query=document.location.search;
        //Construct back functionality
        if(GetTransferEl("_displayMode")=="" && !noBack)
        {//Main State
	        SetTransferEl("_back",query); //document.location.search
	        SetTransferEl("_back2main",query);//document.location.search
        }
        if(GetTransferEl("_displayMode")!="item" && !noBack)
        {//Inner Items List State
	        SetTransferEl("_back",query); //document.location.search
        }
		
        //Construct Item Navigation functionality
        if(GetTransferEl("_displayMode")!="item")
        {//from middle mode (list or archive)
	        SetTransferEl("_prevMode",GetTransferEl("_displayMode"));
        }
}
function GetTransferEl(el)
{
	var el=document.frmTransfer[el];
	return (el)?el.value:"";
}
function SetTransferEl(el,val)
{
	var el=document.frmTransfer[el];
	if(el)el.value=val;
}
function Transfer(query)
{
	var f=document.frmTransfer;
	if(f)
	{
		f.action=query;
		f.submit();
	}
}
function Add2Query(element,val,query)
{
	var ret="";
	
	query=(typeof(query)=="string")?query:document.location.search;
	query=query.replace("?","")

	if(element!="")
	{
		if(query=="") //query is empty
			ret=element + "=" + val;
		else 
		{
			var newQuery="";
			var coll=query.split("&");
			for(var i=0;i<coll.length;i++)
			{//construct new query without given element
				var elStr=coll[i].split("=");
				if(elStr[0]!=element)
				{//add if other then given element
					if(newQuery!="") newQuery+="&";
					newQuery+=coll[i];
				}
			}
			//finaly add given element
			if(newQuery!="") newQuery+="&";
			newQuery+=element + "=" + val;
			
			ret=newQuery;
		}
	}
	else
		ret=query;
		
	return ret;
}
function GetFromQuery(el,query)
{
	var val="";
	var q;
	if(query)
		q=query;
	else
		q=document.location.search;
	var qArr=q.split(el + "=");
	if(qArr.length>1)
	{
		val=qArr[1];
		if(val.indexOf("&")>-1) val=val.slice(0,val.indexOf("&"));
	}
	return val;
}
////////

		function OpenLMS(TaskCode)
		{
			var width=640;
			var height=480;
			var uLnk="../LMS/StuTaskForm.aspx?ItemCode=" + TaskCode;
			
			var left = (window.screen.availWidth-width) / 2;
			var top =  (window.screen.availHeight-height) / 2;
			var features = "directories=no,scrollbars=yes,resizable=yes,left=" + left + ",top=" + top + ",width=" + width + ",height=" + height + ",status=no,toolbar=no";
			window.open(uLnk, "mwin", features, true);
		}
		
		function OpenNewLMS(TaskCode,courseCode)
		{
			var width=640;
			var height=480;
			var uLnk="../LMS/TaskSubmit.aspx?courseCode=" + courseCode + "&TaskCode="+ TaskCode;
			
			var left = (window.screen.availWidth-width) / 2;
			var top =  (window.screen.availHeight-height) / 2;
			var features = "directories=no,scrollbars=yes,resizable=yes,left=" + left + ",top=" + top + ",width=" + width + ",height=" + height + ",status=no,toolbar=no";
			window.open(uLnk, "mwin", features, true);
		}
		function Send2Friend(itemCode,wsCode)
		{
			var url=escape(document.location.href);
			
			var width=450;
			var height=300;
			var left = (window.screen.availWidth-width) / 2;
			var top =  (window.screen.availHeight-height) / 2;
			var features = "directories=no,scrollbars=yes,resizable=yes,left=" + left + ",top=" + top + ",width=" + width + ",height=" + height + ",status=no,toolbar=no";
			
			var uLnk="Send2Friend.aspx?ws=" + wsCode + "&item=" + itemCode + "&url=" + url;
			window.open(uLnk, "send2friend", features, true);
		}
		function Print(wsCode,pageCode,partCode,itemCode)
		{
			
			var width=600;
			var height=650;
			var left = (window.screen.availWidth-width) / 2;
			var top =  (window.screen.availHeight-height) / 2;
			var features = "directories=no,scrollbars=yes,resizable=yes,left=" + left + ",top=" + top + ",width=" + width + ",height=" + height + ",status=no,toolbar=no";
			
			var uLnk="Print.aspx?ws=" + wsCode + "&page=" + pageCode + "&box=" + partCode + "&_pstate=item&_item=" + itemCode;
			window.open(uLnk, "print", features, true);
		}

