function moveModule(o_col, d_col) 
{
  o_sl = o_col.selectedIndex;
  d_sl = d_col.length;
  if (o_sl != -1 && o_col.options[o_sl].value > "") {
    oText = o_col.options[o_sl].text;
    oValue = o_col.options[o_sl].value;
    o_col.options[o_sl] = null;
    d_col.options[d_sl] = new Option (oText, oValue, false, true);
  } else {
    alert("Please select a topic first");
  }
}  

function orderModule(down, col) 
{
  sl = col.selectedIndex;
  if (sl != -1 && col[sl].value > "") {
    oText = col[sl].text;
    oValue = col[sl].value;
    if (col.options[sl].value > "" && sl > 0 && down == 0) {
      col.options[sl].text = col.options[sl-1].text;
      col.options[sl].value = col.options[sl-1].value;
      col.options[sl-1].text = oText;
      col.options[sl-1].value = oValue;
      col.selectedIndex--;
    } else if (sl < col.length-1 && col[sl+1].value > "" && down == 1) {
      col.options[sl].text = col.options[sl+1].text;
      col.options[sl].value = col.options[sl+1].value;
      col.options[sl+1].text = oText;
      col.options[sl+1].value = oValue;
      col.selectedIndex++;
    }
  } else {
    alert("Please select a topic first");
  }
}

function xMod(col) 
{
  req = "";
  sl = col.selectedIndex;
  if (sl != -1 && col.options[sl].value > "") {
    if (req.indexOf(col.options[sl].value) > -1) {
      alert ("You may not delete a required corporate module.");
    } else {
      if (confirm("This will delete the selected module.")) {
        if (col.options[sl].value!=".none") {
          if (col.length==1) {
            col.options[0].text="";
            col.options[0].value=".none";
          } else {
            col.options[sl]=null; 
          } 
        } else {
          alert("Please select a topic first");
        }
      }
    }
  }
}

function makeList(fm,col) 
{
  val = "";
  for (j=0; j<fm[col+"Value"].length; j++) {
    if (val > "") { val += ","; }
    if (fm[col+"Value"].options[j].value > "") val += fm[col+"Value"].options[j].value;
  } 
  fm[col+"ListValue"].value=val;
}

function openpopup(popurl,width,height) {
	winpops=window.open(popurl.replace(/\$!/g,"%").replace(/&amp;/g,"&"),"","width="+width+",height="+height+",resizable=yes,toolbar=yes,location=yes,status=yes,scrollbars=yes,alwaysRaised=yes");
	if (winpops.opener == null) winpops.opener = self;
}

function openpopupdomain(popurl,width,height) {
	popurlEsc=escape(popurl);
	winpops=window.open("open.do?url="+popurlEsc,"","width="+width+",height="+height+",resizable=yes,toolbar=yes,location=yes,status=yes,scrollbars=yes,alwaysRaised=yes");
}

function closepopup() {
	winhref=opener.location.href;
	anchorIndex=winhref.lastIndexOf('#');
	if (anchorIndex>-1) {
		withoutanchor=winhref.substring(0,anchorIndex);
		self.close();
		opener.location.href=withoutanchor;
		opener.location.href=opener.location.href;
	} else {
		self.close();
		opener.location.href=opener.location.href;
	}
}

function reportSelectionAndClose(theForm,theField,theValue) { 
  opener.document.getElementById(theForm).elements[theField+'Value'].value=theValue;
  self.close(); 
}

function reportSelection(theForm,theField,theValue) { 
  opener.document.getElementById(theForm).elements[theField+'Value'].value=theValue;
  if (opener.ICBBranding) {
  	opener.ICBBranding.enableButtons();
  }
}

function followLink(selectBox,selectedIndex) {
  if (selectBox.options[selectedIndex].value != '') window.open(selectBox.options[selectedIndex].value);
}

function followLinkSame(selectBox,selectedIndex) {
  var linkValue=selectBox.options[selectedIndex].value;
  if (linkValue && linkValue.indexOf("popup.do?href=")==0) {
	openpopup(unescape(linkValue.substring(14)),'800','600');
  } else
 	if (linkValue != '') window.location.href=linkValue;
}

function validate(theForm) { 
	var pass=true; 
	var required=theForm.elements; 
	var missing='';
	var trimReg = /^\s*$/;
	for (i=0;i<required.length;i++) { 
		if (required[i].name=='inputRequired') { 
			if (trimReg.test(eval("document.getElementById('" + theForm.id + "')." + required[i].value + "Value.value"))) { 
			  pass=false; 
			  if (trimReg.test(eval("document.getElementById('" + theForm.id + "')." + required[i].value + "Label.value"))) {
			  	missing=missing+required[i].value+"\n";
			  }	else {
			    missing=missing+eval("document.getElementById('"+theForm.id+"')."+required[i].value+"Label.value")+"\n";
			  }
			} 
		} 
	} 
	if (!pass) alert("One or more of the required elements are not completed. Please fill in the following elements and try again: \n"+missing); 
	return pass; 
}
	
function toggleVisability(checkbox,element){
	if(checkbox.checked){
    	element.style.visibility="visible"
	}else{
    	element.style.visibility="hidden"
	}
} 

function showHide(checkbox,elementId) {
     var block = document.getElementById(elementId);
     if (checkbox.checked) {
         block.style.display = "block";
     } else {
         block.style.display = "none";
     }
}
  
function resetValue(theForm,theField, theValue) { 
		var complete = eval("document.getElementById('" + theForm + "')." + theField + "Value");
		complete.value = theValue;
		//document.getElementById(theField + "Value").setAttribute("value", theValue);
}
 
// Browser Detection
// browser identification

agt = navigator.userAgent.toLowerCase();
is_ie	   = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_major = parseInt(navigator.appVersion);
var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie3    = (is_ie && (is_major < 4));
var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
var is_ie4up  = (is_ie && (is_major >= 4));
var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);

is_opera  = (agt.indexOf("opera") != -1);
is_mac	   = (agt.indexOf("mac") != -1);
is_mac_ie = (is_ie && is_mac);
is_win_ie = (is_ie && !is_mac);
is_gecko  = ((navigator.product == "Gecko") && (agt.indexOf("rv:") != -1));
isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
NS4 = (document.layers) ? true : false;
IEmac = ((document.all)&&(isMac)) ? true : false;
IE4plus = (document.all) ? true : false;
IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
ver4 = (NS4 || IE4plus) ? true : false;
NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;

// Body onload utility (supports multiple onload functions)
var gSafeOnload = new Array();
function SafeAddOnload(f)
{
	if (IEmac && IE4)  // IE 4.5 blows out on testing window.onload
	{
		window.onload = SafeOnload;
		gSafeOnload[gSafeOnload.length] = f;
	}
	else if  (window.onload)
	{
		if (window.onload != SafeOnload)
		{
			gSafeOnload[0] = window.onload;
			window.onload = SafeOnload;
		}		
		gSafeOnload[gSafeOnload.length] = f;
	}
	else
		window.onload = f;
}
function SafeOnload()
{
	for (var i=0;i<gSafeOnload.length;i++)
		gSafeOnload[i]();
}

function loadScript2(scriptSrc) {
	var els=document.getElementsByTagName("head");
	var head=els.item(0);
	var el       = document.createElement("SCRIPT");
    el.type  = "text/javascript";
    el.defer = true;
    el.src   = scriptSrc;
    head.appendChild(el);
}

function loadScript(scriptSrc) {
	document.write("<script type='text/javascript' src='" +scriptSrc + "'></script>");
}

function checkSupportedEditorBrowser() {
	if (is_gecko) {
		if (navigator.productSub < 20030210) {
			// You need at least Mozilla-1.3 B. Sorry, your Gecko is not supported.
			return false;
		}
	}
	return is_gecko || is_ie5_5up;
};

var editorLoaded=false;
/*function loadEditor() {
	if ((!editorLoaded) && (checkSupportedEditorBrowser())) {
		// load the main HTMLArea files 
		loadScript("htmlarea/htmlarea.js");
		loadScript("htmlarea/lang/en.js");
		loadScript("htmlarea/dialog.js");
		loadScript("htmlarea/popupwin.js");
		
		// load the TableOperations plugin files
		loadScript("htmlarea/plugins/TableOperations/table-operations.js");
		loadScript("htmlarea/plugins/TableOperations/lang/en.js");
		
		
		document.write("<style type='text/css'>		@import url(htmlarea/htmlarea.css);	</style>");
		editorLoaded=true;
	}
}


addLoadEvent(initEditors);


*/
// Closures! Great! For! Onload! Events!
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}
/*
var gEditors = new Array();
var gEditorNames = new Array();
var gImageBases = new Array();
var gAreasToShow = new Array();
var gAreasToHide = new Array();
var gCSS='editor_styles.css';
function initEditors()
{
	if (editorLoaded) {
		 _editor_url = "/icb/htmlarea/";
		for (var i=0;i<gEditorNames.length;i++) {
			var editor = new HTMLArea(gEditorNames[i],gAreasToShow[i],gAreasToHide[i]);
			editor.registerPlugin("TableOperations");
			editor.generate();
			editor.config.pageStyle=gCSS;
			editor.imageBase=gImageBases[i];
			gEditors[gEditors.length]=editor;
		}
	}
}*/

function initDomain()
{
	document.domain='harvard.edu';
}

var checkedDefault=false;

function doDefault(theForm) 
{
	if (!checkedDefault) {
		checkedDefault=true;
		var defaultLink=document.getElementById(theForm.id+'_default');
		if (defaultLink) {
			eval(defaultLink.href.substring(11));
			checkedDefault=false;
			return false;
		}
	}
	return true;
}


function noMatch(theForm,nomatchfield,nomatchpattern) { 

	if (nomatchfield!=null) {
		var value="";
		if (nomatchfield.type.indexOf("select") != -1) {
			value = nomatchfield.options[nomatchfield.selectedIndex].value;
		} else {
			value = nomatchfield.value;
		}
		return (value.indexOf(nomatchpattern)==-1);
	}
	
	return true;
}

function match(theForm,matchfield,matchpattern) { 

	if (matchfield!=null) {
		var value="";
		if (matchfield.type.indexOf("select") != -1) {
			value = matchfield.options[matchfield.selectedIndex].value;
		} else {
			value = matchfield.value;
		}
		return (value.indexOf(matchpattern)!=-1);
	}
	
	return false;
}

function launch(theForm,linkField,variableFields) { 

	var launchUrl="";
	var linkFieldObject=eval("document.getElementById('"+theForm.id+"')."+linkField+"Value");
	if (linkFieldObject.type.indexOf("select") != -1) {
		launchUrl = linkFieldObject.options[linkFieldObject.selectedIndex].value;
	} else {
		launchUrl = linkFieldObject.value;
	}
	
	launchRaw(theForm,launchUrl,variableFields);
}

function getFieldValue(field)
{
   switch(field.type)
   {
      case "text" :
      case "textarea" :
      case "password" :
      case "hidden" :
         return field.value;

      case "select-one" :
         var i = field.selectedIndex;
         if (i == -1)   return "";
         else   return (field.options[i].value == "") ? field.options[i].text : field.options[i].value;

      case "select-multiple" :
         var allChecked = new Array();
         for(i = 0; i < field.options.length; i++)
            if(field.options[i].selected)
               allChecked[allChecked.length] = (field.options[i].value == "") ? field.options[i].text : field.options[i].value;
         return allChecked;

      case "button" :
      case "reset" :
      case "submit" :
         return "";

      case "radio" :
      case "checkbox" :
         if (field.checked) { return field.value; } else { return ""; }
      default :
         if(field[0].type == "radio")
         {
            for (i = 0; i < field.length; i++)
               if (field[i].checked)
                  return field[i].value;

            return "";
         }
         else if(field[0].type == "checkbox")
         {
            var allChecked = new Array();
            for(i = 0; i < field.length; i++)
               if(field[i].checked)
                  allChecked[allChecked.length] = field[i].value;

            return allChecked;
         }
         else
            var str = "";
            for (x in field) { str += x + "\n"; }
            alert("I couldn't figure out what type this field is...\n\n" + field.name + ": ???\n\n\n" + str + "\n\nlength = " + field.length);
         break;
   }
   
   return "";
}

function launchRaw(theForm,launchUrl,variableFields) { 
	var fieldArray=variableFields.split(",");
	if (fieldArray) {
		for (i=0;i<fieldArray.length;i++) { 
		    var valueField=eval("document.getElementById('"+theForm.id+"')."+fieldArray[i]+"Value");
			var fieldValue=getFieldValue(valueField);
			launchUrl=launchUrl.replace(new RegExp("\\$"+i,"g"),escape(fieldValue));
		} 
	} else {
		var valueField=eval("document.getElementById('"+theForm.id+"')."+variableFields+"Value");
		var fieldValue=getFieldValue(valueField);
		launchUrl=launchUrl.replace(/\$0/g,escape(fieldValue));
	}
	winpops=window.open(launchUrl,"","width=800,height=600,resizable=yes,toolbar=yes,location=yes,status=yes,scrollbars=yes,alwaysRaised=yes");
}

//SafeAddOnload(initDomain);
//SafeAddOnload(initEditors);


function checkAll(field)
{
for (i = 0; i < field.length; i++)
	field[i].checked = true ;
}

function uncheckAll(field)
{
for (i = 0; i < field.length; i++)
	field[i].checked = false ;
}

/*
function webeditor_custom_encode(content) {
	content = content.replace(new RegExp("<!--((.|[\\s])*?)-->","gi"), "");
	content = content.replace(new RegExp("<script((.|[\\s])*?)\\/script>","gi"), "");
	// all namespace tags
	content = content.replace(new RegExp("<\\/?[a-z]+:[^>]*>","gi"), "");
	return content; 
} 

function webeditor_custom_decode(content) { 
	return content; 
} 
		
		
function webeditor_custom_formatclass_option(name) { 
	switch (name) { 
		case "textHeader1": return "Text Header 1"; break; 
		case "textHeader2": return "Text Header 2"; break; 
		case "textParagraph1": return "Text Paragraph 1"; break; 
		case "textParagraph2": return "Text Paragraph 2"; break; 
		case "tableHeader": return "Table Header"; break; 
		case "columnLabel": return "Column Label"; break; 
		case "elementLabel": return "Element Label"; break; 
		case "highlight": return "Highlight"; break; 
		default: return ""; break; 
	} 
}
*/
function initOnSubmit(theForm) {

	if (typeof theForm.onsubmit == "function") {
		var funcref = theForm.onsubmit;
		if (typeof theForm.__msh_prevOnSubmit == "undefined") {
			theForm.__msh_prevOnSubmit = [];
		}
		theForm.__msh_prevOnSubmit.push(funcref);
	}
	theForm.onsubmit = function() {
		HardCoreWebEditorSubmit();
		var a = theForm.__msh_prevOnSubmit;
		// call previous submit methods if they were there.
		if (typeof a != "undefined") {
			for (var i = 0; i < a.length; i++) {
				if (!a[i]()) return false;
			}
		}
		return true;
	};
	
}
/*
function loadHtmlEditorIncludes() { 
	document.write("<script src='/js/webeditor/webeditor.js'></script>");
}

function loadHtmlEditor(theEditor,theDiv,formname,valueName,imagebase,originalName,icburlroot,toolbarlevel) {
	WebEditorSkin('blue2007');
	if (((webeditor.type == "msie") || (webeditor.type == "mozilla") || (webeditor.type == "safari")) && document.designMode) {
		var height=eval("document.getElementById('"+formname+"')."+valueName+".clientHeight;");
		var htmlSnippet="<table cellpadding='0' cellspacing='0' border='0' width='100%'>";
		height = (height == 0) ? 200 : height;
		theDiv.innerHTML='&nbsp;';
		htmlSnippet+="<tr><td>Current: <b>HTML with Editor</b> Switch to <a href=\"javascript:switchToPlain('"+valueName+"')\">[Plain Text]</a> <a href=\"javascript:switchToHTMLwoEditor('"+valueName+"')\">[HTML]</a></td></tr>";
		htmlSnippet+="<tr><td>";
		document.write(htmlSnippet);

		if (toolbarlevel=="advanced") {
			HardCoreWebEditorToolbar({toolbar1:'formatclass formatblock bold italic underline superscript subscript strikethrough viewdetails viewsource help',toolbar2:'cut copy paste clean removeformat delete selectall undo redo specialcharacter insertmedia createlink mailto unlink inserthorizontalrule insertorderedlist insertunorderedlist outdent indent justifyleft justifycenter justifyright justifyfull nobr',toolbar3:'createtable tableproperties insertcaption insertrowhead insertrowfoot rowproperties insertrowabove insertrowbelow deleterow splitcellrows columnproperties insertcolumnleft insertcolumnright deletecolumn splitcellcolumns cellproperties insertcellleft insertcellright deletecell splitcell mergecells import find printbreak'});
		} else if (toolbarlevel=="medium") {
			HardCoreWebEditorToolbar({toolbar1:'formatclass formatblock bold italic underline superscript subscript strikethrough viewdetails viewsource help',toolbar2:'cut copy paste clean removeformat delete selectall undo redo specialcharacter insertmedia createlink mailto unlink inserthorizontalrule insertorderedlist insertunorderedlist outdent indent justifyleft justifycenter justifyright justifyfull nobr'});
		} else {
			HardCoreWebEditorToolbar({toolbar1:'formatblock bold italic underline superscript subscript strikethrough insertmedia createlink insertorderedlist insertunorderedlist outdent indent justifyleft justifycenter justifyright justifyfull'});
		}
		
		
		htmlSnippet="</td></tr><tr><td>";
		document.write(htmlSnippet);
	
		eval("document.__icb_imagebase_"+valueName+"='"+imagebase+"';");
		theEditor = new HardCoreWebEditor('/js/webeditor/', '', valueName, document.getElementById(originalName).value, '', 'http://'+icburlroot+'wysiwyg_styles.css', true, '', '', '', '','','', '100%', height, '', '');
		initOnSubmit(eval("document.getElementById('"+formname+"')"));
	
		htmlSnippet="</td></tr></table>";
		htmlSnippet+="";
		htmlSnippet+="";
		htmlSnippet+="";
		htmlSnippet+="";
		htmlSnippet+="";
		document.write(htmlSnippet);
	 } else {
		theDiv.getElementsByTagName("div")[0].innerHTML="Current: <b>HTML</b> Switch to <a href=\"javascript:switchToPlain('"+valueName+"')\">[Plain Text]</a>";	 
	 }
}

function loadEditorBySwitch(texttype,theEditor,theDiv,typeField,formname,valueName,imagebase,originalName,icburlroot,toolbarlevel) { 
	var de = GetCookie('htmlarea_setting');
	var had = GetCookie('htmlarea_default');
	DeleteCookie('htmlarea_setting');
	if (de == null) {
		if (texttype=="markup") {
			if ((had !=null) && (had=="1")) {
				loadHtmlEditor(theEditor,theDiv,formname,valueName,imagebase,originalName,icburlroot,toolbarlevel);
				typeField.value="markup";
			} else {
				typeField.value="markup";
				if (((webeditor.type == "msie") || (webeditor.type == "mozilla") || (webeditor.type == "safari")) && document.designMode) {
					theDiv.getElementsByTagName("div")[0].innerHTML="Current: <b>HTML</b> Switch to <a href=\"javascript:switchToPlain('"+valueName+"')\">[Plain Text]</a> <a href=\"javascript:switchToHTML('"+valueName+"')\">[HTML with Editor]</a>";
				} else {
					theDiv.getElementsByTagName("div")[0].innerHTML="Current: <b>HTML</b> Switch to <a href=\"javascript:switchToPlain('"+valueName+"')\">[Plain Text]</a>";
				}
			}
		} else if (texttype=="default") {
			if ((had !=null) && (had=="1")) {
				loadHtmlEditor(theEditor,theDiv,formname,valueName,imagebase,originalName,icburlroot,toolbarlevel);
				typeField.value="markup";
			} else if ((had !=null) && (had=="3")) {
				typeField.value="plain";
				if (((webeditor.type == "msie") || (webeditor.type == "mozilla") || (webeditor.type == "safari")) && document.designMode) {
					theDiv.getElementsByTagName("div")[0].innerHTML="Current: <b>Plain Text</b> Switch to <a href=\"javascript:switchToHTML('"+valueName+"')\">[HTML with Editor]</a> <a href=\"javascript:switchToHTMLwoEditor('"+valueName+"')\">[HTML]</a>";
				}
			} else {
				typeField.value="markup";
				if (((webeditor.type == "msie") || (webeditor.type == "mozilla") || (webeditor.type == "safari")) && document.designMode) {
					theDiv.getElementsByTagName("div")[0].innerHTML="Current: <b>HTML</b> Switch to <a href=\"javascript:switchToPlain('"+valueName+"')\">[Plain Text]</a> <a href=\"javascript:switchToHTML('"+valueName+"')\">[HTML with Editor]</a>";
				} else {
					theDiv.getElementsByTagName("div")[0].innerHTML="Current: <b>HTML</b> Switch to <a href=\"javascript:switchToPlain('"+valueName+"')\">[Plain Text]</a>";
				}
			}
		} else {
			typeField.value="plain";
			if (((webeditor.type == "msie") || (webeditor.type == "mozilla") || (webeditor.type == "safari")) && document.designMode) {
				theDiv.getElementsByTagName("div")[0].innerHTML="Current: <b>Plain Text</b> Switch to <a href=\"javascript:switchToHTML('"+valueName+"')\">[HTML with Editor]</a> <a href=\"javascript:switchToHTMLwoEditor('"+valueName+"')\">[HTML]</a>";
			}
		}
	} else if (de=="1") {
		loadHtmlEditor(theEditor,theDiv,formname,valueName,imagebase,originalName,icburlroot,toolbarlevel);
		typeField.value="markup";
	} else if (de=="2") {
		typeField.value="markup";
		if (((webeditor.type == "msie") || (webeditor.type == "mozilla") || (webeditor.type == "safari")) && document.designMode) {
			theDiv.getElementsByTagName("div")[0].innerHTML="Current: <b>HTML</b> Switch to <a href=\"javascript:switchToPlain('"+valueName+"')\">[Plain Text]</a> <a href=\"javascript:switchToHTML('"+valueName+"')\">[HTML with Editor]</a>";
		} else {
			theDiv.getElementsByTagName("div")[0].innerHTML="Current: <b>HTML</b> Switch to <a href=\"javascript:switchToPlain('"+valueName+"')\">[Plain Text]</a>";
		}
	} else {
		typeField.value="plain";
		if (((webeditor.type == "msie") || (webeditor.type == "mozilla") || (webeditor.type == "safari")) && document.designMode) {
			theDiv.getElementsByTagName("div")[0].innerHTML="Current: <b>Plain Text</b> Switch to <a href=\"javascript:switchToHTML('"+valueName+"')\">[HTML with Editor]</a> <a href=\"javascript:switchToHTMLwoEditor('"+valueName+"')\">[HTML]</a>";
		}
	}
}*/

/*function setDefaultEditor(valueName) {
	var de = GetCookie('htmlarea_setting');
	if (de == null) {
		SetCookie ('htmlarea_setting', "1");
	} else {
	}
}

function switchToPlain(valueName) {
	var x=window.confirm("All changes since the last submission will be lost if you switch the content editing mode?");
    if (x) {
		SetCookie ('htmlarea_setting', "3");
		SetCookie ('htmlarea_default', "3");
		window.location.reload( false );
	}
}

function switchToHTML(valueName) {
	var x=window.confirm("All changes since the last submission will be lost if you switch the content editing mode?");
    if (x) {
		SetCookie ('htmlarea_setting', "1");
		SetCookie ('htmlarea_default', "1");
		window.location.reload( false );
		}
}

function switchToHTMLwoEditor(valueName) {
	var x=window.confirm("All changes since the last submission will be lost if you switch the content editing mode?");
    if (x) {
		SetCookie ('htmlarea_setting', "2");
		SetCookie ('htmlarea_default', "2");
		window.location.reload( false );
	}
}
*/

var expDays = 30;
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
function color(){
var favColor = GetCookie('color');
if (favColor == null) {
favColor = prompt("What is your favorite background color?");
SetCookie('color', favColor, exp);
}
document.bgColor=favColor;
return favColor;
}
function set(){
favColor = prompt("What is your favorite background color?");
SetCookie ('color', favColor, exp);
}


function getCookieVal (offset) {  
	var endstr = document.cookie.indexOf (";", offset);  
	if (endstr == -1)    
		endstr = document.cookie.length;  
	return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg)      
			return getCookieVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}  
	return null;
}


function SetCookie (name, value) {  
	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + "=" + escape (value) + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	((path == null) ? "" : ("; path=" + path)) +  
	((domain == null) ? "" : ("; domain=" + domain)) +    
	((secure == true) ? "; secure" : "");
}

function DeleteCookie (name) {  
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);  
	var cval = GetCookie (name);  
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function prepareUpload(filenameInput) {
	var validfilename = false;
	validfilename = checkFilename(filenameInput, false);
	
	if(validfilename) {
		var buttons = document.getElementById("upload_form_buttons");
		if (buttons != null) {
			buttons.style.display = 'none';
			document.getElementById("progress_meter").style.display = '';
		}
		return true;
	} else {
		return false;
	}
}

/*
	Check for invalid characters in the file upload
	input for any forms before submitting invalid
	filenames.
*/

var illegalCharSetFileMsg = "\n( ) < > { } , ; : \" ' ? & # + [ ] %";
function checkFilename(filenameInput, rename) {
	/* Return true if there is no filename to validate */
	if (filenameInput == null || filenameInput.value == null || filenameInput.value == '') {
		return true;
	}
	
	var inputString = filenameInput.value;
	var error = "";
	var illegalChars = /[\(\)\<\>\{\}\,\;\:\"\'\?\&\#\+\[\]\%]/;
	var filename = "";
	
	/* Get just the file name of the upload and ditch the path */
	if(inputString.lastIndexOf('/') != -1) {
		filename = inputString.substring(inputString.lastIndexOf('/') + 1, inputString.length);
	} else if(inputString.lastIndexOf('\\') != -1) {
		filename = inputString.substring(inputString.lastIndexOf('\\') + 1, inputString.length);
	} else {
		filename = inputString;
	}
	
	if(illegalChars.test(filename)) {
		if (rename) {
			error = "The filename you have entered, " + filename + ", contains illegal characters.\nPlease modify the name of this file and be sure to exclude the following characters:"+illegalCharSetFileMsg;
		} else {
			error = "The file you are attempting to upload, " + filename + ", contains illegal characters in the filename.\nPlease modify the name of this file and be sure to exclude the following characters:"+illegalCharSetFileMsg;
		}
	}
	
	if(error != "") {
		alert( error );
		return false;
	} else {
		return true;
	}
}

var illegalCharSetDirMsg ="\n( ) < > { } , ; : \" \/ \\ ' ? & # + [ ] . %";
function validateDirName(filenameInput, rename) {
	/* Return true if there is no filename to validate */
	if (filenameInput == null || filenameInput.value == null || filenameInput.value == '') {
		return true;
	}
	
	var filename = filenameInput.value;
	var error = "";
	var illegalChars = /[\/\\\(\)\<\>\{\}\,\;\:\"\'\?\&\#\+\[\]\.\%]/;
	
	if(illegalChars.test(filename)) {
			error = "The name you have entered, " + filename + ", contains illegal characters.\nPlease modify the name and be sure to exclude the following characters:"+illegalCharSetDirMsg;
	}
	
	if(error != "") {
		alert( error );
		return false;
	} else {
		return true;
	}
}
function popupform(myform, windowname) {
    if (!window.focus) return true;
    window.open('', windowname, 'height=480,width=640,scrollbars=yes');
    myform.target = windowname;
    return true;
}