
var imgPath='/engine/images_1/';
var True=true;
var False=false;

var UA=navigator.userAgent.toLowerCase();

function isNS4() {return (navigator.appName=="Netscape" && navigator.appVersion.charAt(0)=='4');}
function isIE() {return (navigator.appName=="Microsoft Internet Explorer");}
function isMac() {return (navigator.platform.indexOf('Mac') != -1);}
function isSfri() {return (UA.indexOf('safari') != -1);}
function isGko() {return (!isSfri() && UA.indexOf('gecko') != -1);}
function isIE50() {return isIE() && (UA.indexOf('msie 5.0') !=-1);}

var FMwin=null;
var LMwin=null;
var winDoc=window.document
function dw(txt) {
	winDoc.write(txt)
}

function dwln(txt) {
	winDoc.writeln(txt)
}	

//singular dw : EX: input-assignments; output-assignment
function sngdw(txt) {
	winDoc.write(sng(txt))
}

function Squish(strIn, nMaxChars) {
	if(!strIn.length || strIn.length < nMaxChars) return strIn;
	return strIn.substring(0, (nMaxChars/2)-3) + '...' + strIn.substring(strIn.length-nMaxChars/2)
}

function Shim(x,y) {
	dw(ShimStr(x,y));
}	

function ShimStr(x,y) {
	return ('<img src="' + imgPath + 'shim.gif" width=' + x + ' height=' + y + ' border=0>')
}
function vShimStr(x,y) {
	return ('<img src="' + imgPath + 'vShim.gif" width=' + x + ' height=' + y + ' border=0>')
}

function fixHtm(str) {
	return String(str).replace(/\"/g,"&#34;").replace(/\'/g,"&#39;").replace(/>/g,'&gt;').replace(/</g,'&lt;').replace(/\|/g,'&brvbar;').replace(/\n/g,'<br>');
}

function getSelVal(o) {
	return o.options[o.selectedIndex].value;
}

//singular : EX: input-assignments; output-assignment
function sng(txt) {
	var ret_value
	
	if (txt=="Quizzes") 
		ret_value="Quiz"
	else 
		ret_value=txt.substr(0,(txt.length-1))
		
	return ret_value
}

// Retrieve the value of the cookie with the specified name.
function GetCookie(sName) {
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++) {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) 
      return aCrumb[1];
  }
  return null;
}
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function AddSessStr(str) {

    var fststr, laststr, i, n
	if (str.indexOf("?")==-1) 
	{
		if (str.indexOf("#") >= 0) 
		  {
		    i = str.indexOf("#")
		    n = str.length
			  fststr =  str.substr(0,i)
			  laststr = str.substr(i+1, n-(i+1))
			  return(fststr + "?" + sessStr + "#" + laststr) 
		   }
		else{    	
			  return (str +"?"+sessStr)
			}
		
	 }		
	else {
		   return (str +"&"+sessStr)
		 }  
}

function extpopup(str) {
	window.open(str,"ext");
}

var bigWin
function bigpopup(str)  {
	if (bigWin!=null)
		if (!bigWin.closed)
			bigWin.close()
	bigWin=window.open(AddSessStr(str),"big","directories=no,hotkeys=no,location=no,menubar=no,personalbar=no,scrollbars=yes,toolbar=no,width=750,height=500,resizable=yes,screenx=10,screeny=10,status=yes")
}


function EnterGE(tp) {
    popupWHS("/engine/intranets/course/EnterGE.asp?tp=" +tp, 900, 700)
}

function DLpopup(str){
	window.open(str,'_blank',"scrollbars=no,width=400,height=250,resizable=no,status=no,toolbar=no,menubar=no,location=no")
}

//popup for  portal pages
var portalpop
function portalpopup(str)  {
	if (portalpop!=null)
		if (!portalpop.closed)
			portalpop.close()
	portalpop=window.open(AddSessStr(str),"portal","directories=no,hotkeys=no,location=no,menubar=no,personalbar=no,scrollbars=yes,toolbar=no,width=750,height=500,resizable=yes,screenx=10,screeny=10,status=yes")
}


function PopRes(fePK,fc)  {
	if (fc)
		window.open(AddSessStr("/engine/res.asp?fc=" + fc + "&fePK=" + fePK),"_blank",'scrollbars=yes,width=750,height=650,resizable=yes,status=yes,toolbar=yes,menubar=yes').focus();
	else
		window.open(AddSessStr("/engine/res.asp?fePK=" + fePK),"_blank",'scrollbars=yes,width=750,height=650,resizable=yes,status=yes,toolbar=yes,menubar=yes').focus();

}
function PopCmpRes(objPK,objTp)  {
    //alert("ok")
    //alert(AddSessStr("/engine/res/CmpViewer.asp?objPK=" + objPK + "&objTp=" + objTp))
	win=window.open(AddSessStr("../../res/CmpViewer.asp?objPK=" + objPK + "&objTp=" + objTp),"cmpRes","scrollbars=yes,width=700,height=520,resizable=yes,status=yes,toolbar=yes,menubar=yes");
}

///////////////////////////
//Moved from std.asp 9-8-00
var win
function popup(str){
	var win
	if (win!=null)
		if (!win.closed)
			win.close()
	win=window.open(AddSessStr(str),'_blank','width=500,height=500,resizable=yes,scrollbars=yes,status=yes')
	
}

function popupWH(str,W,H){
	window.open("/engine/ru.asp?ru=" + escape(str),'_blank','width='+W+',height='+H+',resizable=yes,scrollbars=yes,status=yes')
}

function popupWHS(str,W,H){
	window.open(AddSessStr(str),'_blank','width='+W+',height='+H+',resizable=yes,scrollbars=yes,status=yes')
}

function popupLinks(str){
	var win
	if (win!=null)
		if (!win.closed)
			win.close()
	win=window.open(AddSessStr(str),'_blank','width=750,height=500,resizable=yes,scrollbars=yes,status=yes')
	
}


function popup2(str){
	var win
	if (win!=null)
		if (!win.closed)
			win.close()
	win=window.open(AddSessStr(str),'_blank','width=301,height=251,resizable=no,scrollbars=yes')
	}

function popuplesson(str){
	LMwin=window.open(AddSessStr(str),'Lesn','width=810,height=700,resizable=yes,scrollbars=yes')
	setTimeout("LMwin.focus()",10);
	}

function popupsoln(str){
	
	win=window.open(AddSessStr(str),'soln','width=750,height=600,resizable=yes,scrollbars=yes')
	setTimeout("win.focus()",10);
	}
		
function popupCert(id,sid){
	if (id[0]=='{')
		id.substr(1,36)
		
	if (sid)
		window.open('/Certificate/'+id+'/'+sid,'CertPop')
	else
		window.open('/Certificate/' + id,'CertPop')
}


	
function popup4(str){
	var win
	if (win!=null)
		if (!win.closed)
			win.close()
		win=window.open(AddSessStr(str),'_blank','width=650,height=400,resizable=yes,scrollbars=yes')
	}

function popupM(str){
	var win
	if (win!=null)
		if (!win.closed)
			win.close()
	win=window.open(AddSessStr(str),'M','width=770,height=560,resizable=yes,scrollbars=yes,status=yes,menubar=yes,toolbar=yes')
}

/*

// a new poup function for lecture notes for stds in iframes sreeni 8/23/02
function popuplecnote(str) {
	var win
	if (win!=null)
		if (!win.closed)
			win.close()
	win=window.open(AddSessStr(str),'Lecn','width=800,height=650,resizable=yes,scrollbars=yes')
}
	
function popupHome(str){
	window.open("/files/02/pk/" +jsInstpk +"/" +str,'h','width=770,height=560,resizable=yes,scrollbars=yes,status=yes,menubar=yes,toolbar=yes')
}
	

function popupFM(str){
	var win
	if (win!=null)
		if (!win.closed)
			win.close()
	win=window.open(AddSessStr(str),'FM','width=750,height=560,resizable=yes,scrollbars=yes,status=yes')
}


var LMWin;
function PopupVisLesnMkr(LesnPK){

	var ua=window.navigator.userAgent
	var i=ua.indexOf("MSIE");

	if (i!=-1 && (Number(ua.substr(i+5,3))>=5.5)) {
		LMwin = window.open('','VisLesn','width=1000,height=700,resizable=yes,scrollbars=yes,status=yes');
		
		if(typeof LMwin.alreadyOpen != 'undefined' &&
			(LMwin.coursesPK && fmiPK && fmiPK[0] && fmiPK[0]==LMwin.coursesPK) &&
			(LMwin.sessKey && sessKey && sessKey==LMwin.sessKey)) {
			LMwin.focus();
		} else
			LMwin.location.href=AddSessStr("../../Vis2/LesnSeq/LesnSeq.asp?crsPK=" + fmiPK[0]);
		
	}else
		alert("This feature requires Internet Explorer 5.5 or greater")		
}
*/

////////////////////////////////////
//Helper funcs for DataGrid	3-13-01
function AssertOneChecked() {
	if (GetNumChecked()<1) {
		alert('Please select at least one.');
		return false;
	}
	return true
}

function AssertOneChecked_ass() {
	if (GetNumChecked()<1) {
		alert('Please select at least one.');
		return false;
	}
	if (GetNumChecked()>1) {
		alert('You cannot select more than one.');
		return false;
	}
	return true
}
        
function GetNumChecked() {
	var objlength, i
	var obj=document.frm.ChkBox
	if (obj != null) {
		objlength = obj.length
		if ((objlength==null) && (obj.checked))
			return 1
		var ns=0;
		for (i=0; i<=objlength-1; i++) {
			if (obj[i].checked)
				ns++;
		}
		return ns
	}
	return 0
}




////////////////////////////////////
//Moved from inc/FileMan.asp  9-8-00
var FMhwnd
var FMintv

////ONLY use the following funcs to open the FileMan

function FileManGrp(crsPK) {
	var url="/groups/Registration/Checker.asp?toolNbr=22&tp=Faculty&crspk=" + crsPK
	window.open(AddSessStr(url), 'FileMan','width=750,height=550,resizable=yes,scrollbars=yes,status=yes').focus();
}

//Opens FileMan to foldPK; normally what you want. Optional: pass true for goUL to go directly to the Upload page.
function FileManOpen(pk,it,goUL) {
	FileManPopup(null,pk,it,"&Mode=open",goUL)
}

//Opens a folder of the given type in the current intr. Optional: pass true for goUL to go directly to the Upload page.
function FileManFoldType(foldType,intrType,goUL) {
	FileManPopup(null,foldType,intrType,"&Mode=FoldTP",goUL)
}

//If there are any files in foldPK, they are opened directly
function FileManDisp(foldPK,intrType) {
	FileManPopup(null,foldPK,intrType,"&Mode=disp")
}


////The following funcs should NOT be used for new code!
function FileManSpecial(tbl, pk, it, fld) {
	FileManPopup(tbl,pk,it,"&fld=fld" + fld)
}
function FileManView(tbl,pk,it) {
	FileManPopup(tbl,pk,it,"&Mode=view")
}
function FileManPopup(tbl,pk,it,addl,ul) {
	var url
	url="/engine/FileManager/FileMan.asp?pop=1&iTp=" + it + "&pk=" + pk + addl
	
	if (ul)
		url+="&UL=true&breakFrames=activex";
	
//	if (isDebugFM)
//		window.open(AddSessStr(url), 'FileMan','width=750,height=550,resizable=yes,scrollbars=yes,status=yes,menubar=yes').focus();
//	else
		window.open(AddSessStr(url), 'FileMan','width=750,height=550,resizable=yes,scrollbars=yes,status=yes').focus();
	//FMwin=window.open(AddSessStr(url), 'FileMan', 'width=750,height=550,resizable=yes,scrollbars=yes,status=yes,menubar=yes,toolbar=yes');
//	setTimeout("FMwin.focus()",10);

//	return FMwin
}

////////////////////////////////////////
///Func for handling embedded ppt submission in NS4x
function DoPptSubmitNS() {
   if (document.layers && document.layers.elems && window.qnFrmArr) {
		var frmLyr=document.layers.elems;
		for(var i=1;i<=qnFrmArr[1];i++) {
//			alert(i + ": " + frmLyr.document.layers["MFTL_qn1_ch" + i].document.f.elements["ans1"].checked + ", " + frmLyr.document.layers["MFTL_qn1_ch" + i].document.f.elements["ans1"].value);
			if (frmLyr.document.layers["MFTL_qn1_ch" + i].document.f.elements["ans1"].checked)
				document.thisForm.ans1.value=frmLyr.document.layers["MFTL_qn1_ch" + i].document.f.elements["ans1"].value;
		}
	}

//		for(var k in document.layers.elems.document.frm.ans1)
//			if (document.layers.elems.document.frm.ans1[k].checked)
//				document.thisForm.ans1.value=document.layers.elems.document.frm.ans1[k].value;
}


//Function to easily get the value of a selection box. To use, pass in the selection object.
//For example, with a form name thisForm and a selection name mySel, call: SelVal(document.thisForm.mySel)
function SelVal(sel) {
	return sel.options[sel.selectedIndex].value;
}

///////////////////////////////////
function WordWrap(txtIn,nChars) {
//	var bgn=(new Date()).getTime();	
	if (!nChars)
		nChars=60;
		
	var i,j,br,tl;
	i=0;
	var txt=String(txtIn).replace(/\t/gi,'        ');	//Use 8 spaces in place of tabs
	tl=txt.length;
	
	var zz=10000;
	
	while((--zz)>0) {
		j=i+nChars;		//Get our char window
		if (j>=tl)
			break;
			
		br=txt.lastIndexOf('\n',j);
		if (br>=i && br>-1) {		//There is a \n in our window. Move i up and try again
			i=br+1;
			continue;
		}
		
		br=txt.lastIndexOf(' ',j)
		
		if (br<i) 		//No breaks in our window, force a break
			br=j;
			
		document.write(txt.substring(i,br) + '\n');
		i=br+1;
		
	}
	
//	var nd=(new Date()).getTime();
	
//	document.write(zz + '\n' + ((nd-bgn)/1000) + '\n');
}


var imBx2;
var IMCnt=10;		//upto 10 are reserved for help boxes which get written out in html
var noIMs=false;
var ShowIMCnt=0;

// Displays the im box.
//sets the right position, width, height and show the box
function ShowIMBox(n, tp, w, h) {
	if (noIMs) return false;
	var imBx;		
	var x=10;
	var y0=0
	var y;
	var ofs=3
	
	if (!h) {
		if (isGko())
			h=60;
		else
			h=50;
	}
	
	if (n==0) HideHelpIcon()
		
	if (n>10)	{//err msg boxes stack up if there are more than one
		y= y0 + /*(IMCnt-11)*h*/ +ofs;
		//HideIMBoxes(1)
	}
	else		{//help boxes show at the top always
		y= y0 + ofs;
		//HideIMBoxes(2)
	}
	
	var brdClr = '#FCD972';
	var bgClr = '#FFFFE0';
	
	switch  (tp) {
	case 1:		//help - yellowish
		brdClr = '#FCD972';
		bgClr = '#FFFFE0';		
		break;
	case 2:		//error - red
		brdClr = '#FF0000';
		bgClr = '#ffdddd';		
		break;
	case 3:		//no error - green
		brdClr = '#FF0000';
		bgClr = '#ffdddd';		
		break;
	}
	
	
		if (window.document.body.clientWidth) {
			if (isIE())
				w=window.document.body.clientWidth-x-10;
			else
				w=window.document.body.clientWidth-x-30;
			if (w<1000) w=1000
		}else
			w=1000;
	
	if (isGko())
		w='98%'
	else
		w='98%'
	
	
	imBx = document.getElementById('IMBox' + n)
	
	if (imBx) {
		var hs
		ShowIMCnt++;
		hs = imBx.style
		hs.display ='block';			
		hs.zIndex =30000+ShowIMCnt;
		hs.align = 'left';
		hs.position = 'relative';
		hs.top = y;
		hs.width= w;
		hs.height=h;
		hs.left = x;
		hs.border='1px solid ' +brdClr;
		hs.marginBottom=(2*ofs) + 'px';
		hs.backgroundColor = bgClr;
		hs.color ='black';
		hs.overflow = 'auto';
		hs.padding =2
	}							
}

// Displays the msg box. Pass string to be displayed as s.
function WriteIMBox(s,w,h,rl) {
	if (noIMs) return false;

	IMCnt++;
	
	var cLnk='<table cellspacing=0 cellpadding=0 width=100%><td align=left><b>Message</b></td><td align=right><a style="text-decoration:none" href="javascript:void(0);" onclick="HideIMBox(' + IMCnt + ');"><img border=0 src="/groups/images_1/close.gif"></a></td></tr><tr><td colspan=2>' + s + '</td></tr></table>';
	
	var imBx = document.getElementById('IMBox11')
	
	if(IMCnt==11 && imBx) {
		
		imBx.innerHTML=cLnk
		ShowIMBox(IMCnt, 2, w, h);
	}
	else {
		document.write('<div align=left id=IMBox' + IMCnt + ' style="display:none;">' + cLnk  +'</div>');
		ShowIMBox(IMCnt, 2, w, h);
	}

							
}

function ShowHelpIcon(){
	var d = document.getElementById("dHlp")
	if (d) d.style.display="block"
}

function HideHelpIcon(){
	var d = document.getElementById("dHlp")
	if (d) d.style.display="none"
}

function HideIMBox(n) {
	if (n==0) ShowHelpIcon()
	if (isNS4())
		document.layers['IMBox' + n].visibility="hidden";
	else {
		var imBx2=document.getElementById('IMBox' + n);
		if (imBx2)
			imBx2.style.display="none";
	}
}

function HideIMBoxes(tp){
	if (tp==1) {	//help boxes
		for (var i=0; i<=10 ; i++) HideIMBox(i)
	}else {			//non-help boxes
		for (var i=11; i<=20 ; i++) HideIMBox(i)
	}
}

////////////////////

function AutoScrollIE(doc) {
	if (isIE() && !isMac()) {
		var bd=(doc) ? doc.document.body : window.document.body;
	
		if (bd && bd.clientHeight && bd.scrollHeight) {
			if (bd.scrollHeight>bd.clientHeight && bd.scroll=='no')
				bd.scroll='auto';
			else if (bd.scrollHeight<=bd.clientHeight && bd.scroll!='no')
				bd.scroll='no';
		}
	}
}

function impSetMsg(ttl,txt,x,y,pos,nm){
	var impMsg = document.getElementById('impMsg');
	var impMsgTxt = document.getElementById('impMsgTxt');
	var impMsgTtl = document.getElementById('impMsgTtl');

	impMsg.nm=nm;
	impMsgTtl.innerHTML=ttl+'&nbsp;';
	impMsgTxt.innerHTML=txt;

	if (pos) impMsg.style.position=pos;
	if (x) impMsg.style.left=x;
	if (y) impMsg.style.top=y;
	

	impMsg.style.display='block';
}

function impClose(){
	var impMsg=	document.getElementById('impMsg');
	impMsg.nm=0;
	impMsg.style.display='none';
}

// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function dbgProps(o){
	var w,d,i,v,t,r=new Array();
	w=window.open();
	d=w.document;
	d.open();
	function hE(s){
		return s.replace(/>/g,"&gt;").replace(/</g,"&lt;");
	}
	
	d.write("<table border=1>");
	for (i in o)
		r[r.length]=i;
		
	alert(r.length);
		
	r.sort();
	
	for (ai=0;ai<r.length;ai++) {
		i=r[ai];
		try {
			v=o[i];
		} catch(e) {
			v=e
		}
		
		d.write("<tr><td>"+hE(i)+"</td><td>"+hE(typeof(v))+"</td><td><pre>");
		try {
			d.write(hE(v.toString()))
		} catch(er) {
			d.write(hE(er.toString()))
		}
		d.write("</pre></td></tr>");
	}
	
	d.write("</table>");
	d.close();
	
	w.focus();
}



