// defines the color of the boxes for the app
var lookRed = "red";
var lookBlue = "b";
var lookOrange = "orange";
var lookPurple = "purple";
var lookDkBlue = "dkblue";
var lookGreen = "g";
var lookGrey = "grey";
var lookLtTan = "lttan";
var lookMaroon = "maroon";

var cc = lookBlue;


function dlog1Start(theID,theTitle,colorCode,theWidth,theHeight,helpCode,closeCode) {
	var tCols = colorCode.split("-");
	var shadowCol = "";
	if (tCols.length == 0) {
		colorCode = "b";
		textCol = "";
	} else if (tCols.length>1) {
		colorCode = tCols[0];
		textCol = tCols[1];
	} else {
		colorCode = tCols[0];
		textCol = "";
	}
	
	if (colorCode=="") {
		colorCode='b';
		var textCol='';
	}
	
	if (tCols.length == 3) {
		// we want a shadow or outline color
		shadowCol = tCols[2];
	}
	
	
	document.write("<table border=0 cellspacing=0 cellpadding=0>");
	document.write("<tr height='27'><td width=8 class='topleft "+colorCode+"-topleft' style='padding-top: 0pt; ");
	document.write("padding-left: 0pt; padding-right: 0pt;' >");

	document.write("<div style='position: relative; top: 10pt; left: 10pt;'>");
	if ((helpCode!='')&(helpCode != null)) {
		document.write("<a id='"+theID+"help' href='"+helpCode+"'><img src='"+baseURL+"images/question.gif'></a>");
	} else {
		document.write("&nbsp;");
	}
	document.write("</div></td>");

	document.write("<td class='dtop "+colorCode+"-top'><table width='100%'><tr><td width=40 class='innertop col"+colorCode+"'>")
	document.write("");
	document.write("</td>");
	document.write("<td NOWRAP align=center height='26' class='innertop col"+colorCode+"'><div id='"+theID+"title' ");
	if (textCol != "") {
		document.write("style='color:"+textCol+";");
		//document.write("outline-style: inherit;");
		if (shadowCol != "") {
			document.write("text-outline: 1px 1px "+shadowCol+";");
			document.write("text-shadow: "+shadowCol+" 0px 0px 2px;");
			//document.write("outline-width: 2px;");
		}
		document.write("'");
	}
	document.write(">"+theTitle+"</div></td>");
	document.write("<td align=right width=40></td></tr></table></td>");

	document.write("<td align=left class='dtopright "+colorCode+"-topright' style='padding-top:0; padding-bottom:0;'>");
	document.write("<div style='position: relative; top: 10pt; left: -16pt;'>");
	if ((closeCode!='')&(closeCode != null)) {
		document.write("<a id='"+theID+"close' href='"+closeCode+"'><img src='"+baseURL+"images/closebox.jpg'></a>");
	} else {
		document.write("&#160;");
	}
	document.write("</div>");

	document.write("</td></tr><tr>");
	document.write("<td class='dleft' width=8></td><td class='dbody'");
	if (theHeight!="") document.write(" height="+theHeight);
	if (theWidth!="") document.write(" width="+theWidth);
	document.write(">");
}

function dlog1End() {
	document.write("</td><td class='dright'></td></tr><tr><td class='dbottomleft'></td>");
	document.write("<td class='dbottom'>&nbsp;</td><td class='dbottomright'></td></tr></table>");
}

function dlog2Start(theID,theTitle,colorCode,theWidth,theHeight) {
	if (colorCode=="") colorCode='b';
	document.write("<table border=0 cellspacing=0 cellpadding=0>");
	document.write("<tr height='27'><td width=8 class='topleft2 "+colorCode+"-topleft2'>&nbsp;</td>");
	document.write("<td class='dtop2 "+colorCode+"-top2'><div id='"+theID+"title'>"+theTitle+"</div></td>");
	document.write("<td class='dtopright2 "+colorCode+"-topright2'></td></tr><tr>");
	document.write("<td class='dleft2' width=8>&nbsp;</td><td class='dbody'");
	if (theHeight!="") document.write(" height="+theHeight);
	if (theWidth!="") document.write(" width="+theWidth);
	document.write(">");
}

function dlog2End() {
	document.write("</td><td class='dright2'>&nbsp;</td></tr><tr><td class='dbottomleft2'></td>");
	document.write("<td class='dbottom2'>&nbsp;</td><td class='dbottomright2'></td></tr></table>");
}


function dlogHide(dlogID) {
	var iFrameItem = document.getElementById(dlogID+'iFrame');
	if (iFrameItem != null) iFrameItem.style.display = "none";
	toggleLayer(dlogID+"frame");
	//toggleLayer("bkgndDlog");
	$('bkgndDlog').style.display = "none";
}

function dlogShow(dlogID, action) {

	switch (action) {
		case "XXXX":
					// Put some thing like this code (just the switch) on your own
					// page, then call this function to actually show the dlog
					
					// This sets the width
					var item2 = document.getElementById(dlogID+'frame');
					item2.style.width="800px";
					// What is the content iFrame ?
					var item = document.getElementById(dlogID+'iFrame');
					item.src = "../../tutortrac/entry/lPostFile.4sp";
					
					// Any instructions?
					item = document.getElementById(dlogID+'Instr');
					item.innerHTML = "Post a document to the listed students:"
					// Title of the Dialog box
					item = document.getElementById(dlogID+'title');
					item.innerHTML = "Post Document"
					// What does help do?
					item = document.getElementById(dlogID+'help');
					item.href = "help?topic=postdoc"
					//What does the close do?
					item = document.getElementById(dlogID+'close');
					item.href = "javascript:dlogHide('"+theID+"')"
					break;

	}
	// Now show it
	toggleLayer(dlogID+"frame");
	
	var iFrameItem = document.getElementById(dlogID+'iFrame');
	if (iFrameItem != null) iFrameItem.style.display = "block";

	// Make sure the background layer covers everything
	item2 = document.getElementById("bkgndDlog");
	item2.style.width="99%";
	item2.style.height="99%";

	toggleLayer("bkgndDlog");
}


function dlogNewStart(theID,theTitle,colorCode,theWidth,theHeight,helpCode,closeCode) {
	var tCols = colorCode.split("-");
	var shadowCol = "";
	if (tCols.length == 0) {
		colorCode = "b";
		textCol = "";
	} else if (tCols.length>1) {
		colorCode = tCols[0];
		textCol = tCols[1];
	} else {
		colorCode = tCols[0];
		textCol = "";
	}
	
	if (colorCode=="") {
		colorCode='b';
		var textCol='';
	}
	
	if (tCols.length == 3) {
		// we want a shadow or outline color
		shadowCol = tCols[2];
	}
	
	prodCode = ""
	if (tCols.length == 4) {
		prodCode = tCols[3];
	}
	
	document.write("<table ")
	if (theHeight!="") document.write(" height="+theHeight);
	if (theWidth!="") document.write(" width="+theWidth);
	document.write("><tr><td style='padding-top:0; padding-bottom:0; padding-left: 0; padding-right: 0;'>");
	
	document.write("<div class='dlogframe "+prodCode+"' >");
	
	document.write("<table border=0 cellspacing=0 cellpadding=0 class='dlogtable' width='100%' >");
	document.write("<tr height='20'><td width=8 class='dlogtopleft "+prodCode+"' style='padding-top:0; padding-bottom:0; padding-left: 0; padding-right: 0;' >");
	document.write("<div style='position: relative; top: 2pt; left: 5pt;'>");
	if ((helpCode!='')&(helpCode != null)) {
		document.write("<a id='"+theID+"help' href='"+helpCode+"'><img src='"+baseURL+"images/question.gif'></a>");
	} else {
		document.write("&#160;&#160;&#160;");
	}
	document.write("</div></td>");

	document.write("<td class='dlogtop "+prodCode+"' style='padding-top:0; padding-bottom:0; padding-left: 0; padding-right: 0;' ><table width='100%'><tr><td width=40 class='dloginnertop' style='padding-top:0; padding-bottom:0; padding-left: 0; padding-right: 0;'>")
	document.write("");
	document.write("</td>");
	document.write("<td NOWRAP align=center height='20' class='dloginnertop2' style='padding-top:0; padding-bottom:0; padding-left: 0; padding-right: 0;'><div id='"+theID+"title' ");
	if (textCol != "") {
		document.write("style='color:"+textCol+";");
		document.write("font-weight: bold;");
		document.write("font-size:14pt;");
		//document.write("outline-style: inherit;");
		if (shadowCol != "") {
			document.write("text-outline: 1px 1px "+shadowCol+";");
			document.write("text-shadow: "+shadowCol+" 0px 0px 2px;");
			//document.write("outline-width: 2px;");
		}
		document.write("'");
	}
	document.write(">"+theTitle+"</div></td>");
	//<td class='dlogtopright' style='padding-top:0; padding-bottom:0; padding-left: 0; padding-right: 0;' align=right width=40></td>
	document.write("</tr></table></td>");

	document.write("<td style='padding-top:0; padding-bottom:0; padding-left: 0; padding-right: 0;' align=left class='dlogtopright "+prodCode+"' >");
	document.write("<div style='position: relative; top: 2pt; left: -3pt;'>");
	if ((closeCode!='')&(closeCode != null)) {
		document.write("<a id='"+theID+"close' href='"+closeCode+"'><img src='"+baseURL+"images/closebox.jpg'></a>");
	} else {
		document.write("&#160;&#160;&#160;");
	}
	
	document.write("</div>");

	document.write("</td></tr><tr>");
	
	document.write("<td style='padding-top:0; padding-bottom:0; padding-left: 0; padding-right: 0;' class='dlogleft' width=8></td><td style='padding-top:0; padding-bottom:0; padding-left: 0; padding-right: 0;' class='dlogbody'");
	if (theHeight!="") document.write(" height="+theHeight);
	if (theWidth!="") document.write(" width="+theWidth);
	document.write(">");

}

function dlogNewEnd() {
	document.write("</td><td style='padding-top:0; padding-bottom:0; padding-left: 0; padding-right: 0;' class='dlogright'></td></tr><tr><td style='padding-top:0; padding-bottom:0; padding-left: 0; padding-right: 0;' class='dlogbottomleft'></td>");
	document.write("<td style='padding-top:0; padding-bottom:0; padding-left: 0; padding-right: 0;' class='dlogbottom'>&nbsp;</td><td style='padding-top:0; padding-bottom:0; padding-left: 0; padding-right: 0;' class='dlogbottomright'></td></tr></table></div></td></tr></table>");
}

function dlogStart(style,id,title,cols,width,height,help,closeCode) {
	switch (style) {
		case "":
		case "Round-Shadow1":
			dlog1Start(id,title,cols,width,height,help,closeCode);
			break;
		
		case "CSS Defined":
			dlogNewStart(id,title,cols,width,height,help,closeCode);
			break;
			
		default:
			dlog1Start(id,title,cols,width,height,help,closeCode);
			break;
	}
}

function dlogEnd(style) {
	switch (style) {
		case "":
		case "Round-Shadow1":
			dlog1End();
			break;
		
		case "CSS Defined":
			dlogNewEnd();
			break;
			
		default:
			dlog1End();
			break;
	}
}

function oldtoggleLayer(whichLayer) {

	if (document.getElementById) {
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display? "":"block";
	} else if (document.all) {
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"block";
	} else if (document.layers) {
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"block";
	}

}

function toggleTree(szDivID, iState) {
    if(document.layers)	   //NN4+
    {
    	if (iState == null) {
    		if (document.layers[szDivID].display != "none") {
    			iState = 0;
    		} else {
    			iState = 1;
    		}
    	}
		document.layers[szDivID].display = iState ? "block" : "none";
		if (iState==1) {
			document.layers[szDivID].height = "100%"
		} else {
			document.layers[szDivID].height = "0px"
		}
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
	{
		var obj = document.getElementById(szDivID);

    	if (iState == null) {
    		if (obj.style.display == "block") {
    			iState = 0;
    		} else {
    			iState = 1;
    		}
    	}
		obj.style.display = iState ? "block" : "none";

		if (iState==1) {
			obj.style.height = "100%"
		} else {
			obj.style.height = "0px"
		}

	}
	else if(document.all)	// IE 4
	{

    	if (iState == null) {
    		if (document.all[szDivID].style.display == "block") {
    			iState = 0;
    		} else {
    			iState = 1;
    		}
    	}

		document.all[szDivID].style.display = iState ? "block" : "none";

		if (iState==1) {
			document.all[szDivID].style.height = "100%"
		} else {
			document.all[szDivID].style.height = "0px"
		}

	}
	var item = document.getElementById(szDivID+'exp');
	if (iState==1) {
		item.innerHTML = "<img src='../images/min.jpg'>";
	} else {
		item.innerHTML = "<img src='../images/max.jpg'>";
		// All contained divs of class tree, should be hidden as well and
		// set the height to 0px;
		obj = document.getElementById(szDivID);
		//how to determin "sub" objects
		var numChild = obj.childNodes.length;
		for (var count=0;count<numChild;count++) {
			if (obj.childNodes[count].className == "tree") {
				toggleTree(obj.childNodes[count].id,iState);
			}
		}
	
	}
	
}


function toggleLayer(szDivID, iState) // 1 visible, 0 hidden
{
    if(document.layers)	   //NN4+
    {
    	if (iState == null) {
    		if (document.layers[szDivID].style.display != "none") {
    			iState = 0;
    		} else {
    			iState = 1;
    		}
    	}
		document.layers[szDivID].style.display = iState ? "block" : "none";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
	{
		var obj = document.getElementById(szDivID);

    	if (iState == null) {
    		if (obj.style.display != "none") {
    			iState = 0;
    		} else {
    			iState = 1;
    		}
    	}


		obj.style.display = iState ? "block" : "none";
	}
	else if(document.all)	// IE 4
	{

    	if (iState == null) {
    		if (document.all[szDivID].style.display != "none") {
    			iState = 0;
    		} else {
    			iState = 1;
    		}
    	}

		document.all[szDivID].style.display = iState ? "block" : "none";


	}
}

function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

 function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }
  
