	ns4 = (document.layers)? true:false
	ns6 = (document.getElementById)? true:false
	ie4 = (document.all)? true:false

	function layerWrite(id,nestref,text) {
		if( document.getElementById ) {
			document.getElementById(id).innerHTML = text;
		} 
		else {
		 	var lyr = (nestref)? eval('document.'+nestref+'.document.'+id+'.document') : document.layers[id].document;
		 		
			lyr.open();		
			lyr.write(text);
	 		lyr.close();
		}
	}
	
	var browser_supports_getElementById  = (document.getElementById)? true:false
	
	var selected_bg_colour = '#E8E8FF';
	var unselected_bg_colour = '#FFFFFF';
	
	var selected_folder_bg_colour = '#000084';
	var selected_folder_colour = '#FFFFFF';
	var unselected_folder_bg_colour = '#FFFFFF';
	var unselected_folder_colour = '#000000';
	
	function changeColour( id, colour ) {
		if( browser_supports_getElementById ) {
			document.getElementById(id).style.color = colour;
		}
	}
	
	function changeBGColour( id, colour ) {
		if( browser_supports_getElementById ) {
			document.getElementById(id).style.backgroundColor = colour;
		}
	}

	function getBGColour( id ) {
		if( browser_supports_getElementById ) {
			if( document.getElementById(id) ) {
				return document.getElementById(id).style.backgroundColor;
			}
		}
	}
	
	//call this function to get the default (un)highlighting
	// b = 1 to highlight, b = 0 to unhighlight
	function highlight( id, b, n ) {
		var colour = (b)? selected_bg_colour : unselected_bg_colour;
		if( isNaN(n) ) {
			changeBGColour( id, colour );
		} else {
			for( i=0; i<n; i++ ) {
				changeBGColour( id + String(i), colour );				
			}
		}
	}
	
	function selectNavFolder( id, b ) {
		if( b ) {
			changeBGColour( id, selected_folder_bg_colour );
			changeColour( id, selected_folder_colour );
		} else {
			changeBGColour( id, unselected_folder_bg_colour );
			changeColour( id, unselected_folder_colour );
		}
	}
	
	function dropdown(obj) {
		if( obj.selectedIndex >= 0 ) {
			return obj.options[obj.selectedIndex].value;
		}
		return null;
	}

	function verifyDate( month, day, year ) {
		var daysInMonth;
			
		switch( parseInt(month) )
		{
			case 1:
			case 3:
			case 5:
			case 7:
			case 8:
			case 10:
			case 12:
				daysInMonth = 31;
				break;
			case 4:
			case 6:
			case 9:
			case 11:
				daysInMonth = 30;
				break;
			case 2:
				daysInMonth = 28
				if( parseInt(year) % 4 == 0) {
					if( parseInt(year) % 100 != 0 ) {
						daysInMonth = 29
					}
					else {
						if( parseInt(year) % 400 == 0 ) {
							daysInMonth = 29
						}
					}
				}
				break;
			default:
				return 0;
		}

		if( parseInt(day) > daysInMonth ) {
			return 0;
		}
				
		return 1;
	}

	function PopupWindow( url, winName, features ) {
		var winHandle;
		winHandle = window.open( url, winName, features )
		return winHandle;
	}

	function d2lTrim ( inputStringTrim ) {
		var fixedTrim;
		var lastCh;
		
		fixedTrim = "";
		lastCh = " ";
		
		for (x=0; x < inputStringTrim.length; x++) {
			ch = inputStringTrim.charAt(x);
			if ((ch != " ") || (lastCh != " ")) {
				 fixedTrim += ch; 
			}
			lastCh = ch;
		}
		if (fixedTrim.charAt(fixedTrim.length - 1) == " ") {
			fixedTrim = fixedTrim.substring(0, fixedTrim.length - 1); 
		}
		return fixedTrim
	}
	
	function d2lPopup( ) {
		//this will be the D2L popup window function
	}
	
	function close_popup_window( win ) {
		if( win ) {
			if( !win.closed ) {
				win.close();
			}
		}
		return 0;
	}
	
	function previewText( ou, srcText, srcIsHTML, height, width ) {
		var preview_win = window.open("/d2l/tools/preview/preview_frame.asp?ou="+ ou +"&text="+ escape(srcText) +"&isHTML="+ escape(srcIsHTML), "preview_text_win", "height="+ height +",width="+ width +",resizable=yes");
		preview_win.focus();
	}
	
	function launchWysiwygEditor(ou, chkIsHTML, elementName) {
		if( eval(chkIsHTML) ) {
			eval(chkIsHTML).checked=true;
		}
		window.open('/d2l/tools/wysiwygEditor/editor.asp?ou='+ ou +'&elementName='+elementName+'&strip=true', 'wysiwygEditor','width=573,height=465,resizable=yes');
	
	}