//////////////////////////  CLOROX GLOBAL
		function clorox_show_confirmation(targ_window, visible) {
			var obj = targ_window.document.getElementById("clorox_spare");
			if (visible) {
				obj.style.top = ((window.innerHeight / 2) - 50).toString() + "px";
				obj.style.left = ((window.innerWidth / 2) - 150).toString() + "px";
				obj.style.display = "block";
				
				obj.innerHTML = 	'<table width="300" height="100" cellpadding="0" cellspacing="6" border="0" bgcolor="#000000"><tr><td bgcolor="#FFFFFF" align="center" style="font-weight:bold; font-size:14px; color:#FF0000;">Please Wait...</td></tr></table>';
			} else {
				obj.style.display = "none";
			}
		}
//////////////////////////  END


//////////////////////////  CLOROX VIEW MANUSCRIPTS
		function clorox_addToSaved(UserID, WorkID) {
			document.getElementById("options_frame").src = "/desktop/clorox_options_frame.php?UserID=" + UserID + "&WorkID=" + WorkID + "&mode=add";
			document.getElementById("addToSave").style.display = "none";
			document.getElementById("showSaveControls").style.display = "block";
		}
		
		function clorox_removeFromSaved(UserID, WorkID) {
			document.getElementById("options_frame").src = "/desktop/clorox_options_frame.php?UserID=" + UserID + "&WorkID=" + WorkID + "&mode=remove";
			document.getElementById("addToSave").style.display = "block";
			document.getElementById("showSaveControls").style.display = "none";
		}
//////////////////////////  END

//////////////////////////  CLOROX SEARCH MANUSCRIPTS
		var formatted_search_results 	= "";
		var formatted_search_bgcolors 	= ["#FFFFFF", "#ADCEFB"];
		var formatted_search_counter 	= 1;
		var results_per_page 		= 5;
		var current_results_layer 	= 1;
		var newLayer 			= true;
		var currentSearchString		= "";
        
        //these are used to give the user a valid back option
        //when paginating through results
        var previousLayers = new Array(); 
        var backEnabledText = "|&nbsp;<a href='javascript:clorox_layerBack();'>Back</a>&nbsp;|&nbsp;&nbsp;";
        var backDisabledText = "|&nbsp;Back&nbsp;|&nbsp;&nbsp;";
        var previousLayer = -1;  
        var backMsg = "Use this Back feature instead of your browser's Back button when viewing search results.\nIt tracks your last 25 selections.";
		
        function clorox_delete_saved_search(user_id, search_name)
        {            
            var answer = confirm("Delete Saved Search " + search_name + "?");
            if(answer)
            {
                window.location = "?view=history&delete=" + user_id + "&search_name=" + search_name;
            }
        
        }
        
		function clorox_search_all_new() {
			//document.getElementById("search_frame").src = "/desktop/clorox_search.php?saveFlag=false&mode=new";
			clorox_submit_search("saveFlag=false&mode=new");
		}
		
		function clorox_search_all() {
			//document.getElementById("search_frame").src = "/desktop/clorox_search.php?saveFlag=false&mode=all";
            
			clorox_submit_search("saveFlag=false&mode=all");
		}
		
		function clorox_search_premium() {
			clorox_submit_search("saveFlag=false&mode=premium");
		}
		
		function clorox_getMainCatId(obj) {
			if (document.getElementById(obj).selectedIndex != 0) {
				var jsCatID = sub_array[document.getElementById(obj).options[document.getElementById(obj).selectedIndex].value]['index'];
				return jsCatID;
			} else {
				return "";
			}
		}

		function clorox_getSecondaryCatId(obj2) {
			if (document.getElementById(obj2).selectedIndex > 0) {
				var jsCatID = document.getElementById(obj2).options[document.getElementById(obj2).selectedIndex].value;
				return jsCatID;
			} else {
				return "";
			}
		}

		function clorox_buildKeyWordList(keylist,key) {
			if ( trim(key) != "" ) {
				if ( trim(keylist) != "" ) { 
					keylist = keylist + ",'";
				} else {
					keylist = keylist + "'";
				}
				keylist = keylist + trim(key) + "'";
			}
			return keylist;
		}

		function clorox_getKeyWord(key) {
			if ( trim(key) != "" ) {
				return trim(key);
			}
			return "";
		}

		function clorox_setSessionState() {
			//some of the search pages do not have search criteria input controls.
			//if they do not have the controls, we dont need to set a series of session vars.
			if (document.getElementById("1_MainCat")) {
				var sessionList = "";
				sessionList = "topCat0=" + document.getElementById("1_MainCat").selectedIndex;
				sessionList += "&topCat1=" + document.getElementById("2_MainCat").selectedIndex;
				sessionList += "&topCat2=" + document.getElementById("3_MainCat").selectedIndex;
				sessionList += "&catSub0=" + clorox_getSecondaryCatId("1_SecondaryCat");
				sessionList += "&catSub1=" + clorox_getSecondaryCatId("2_SecondaryCat");
				sessionList += "&catSub2=" + clorox_getSecondaryCatId("3_SecondaryCat");
				sessionList += "&key0=" + document.getElementById("keyWord1").value;
				sessionList += "&key1=" + document.getElementById("keyWord2").value;
				sessionList += "&key2=" + document.getElementById("keyWord3").value;
				sessionList += "&key3=" + document.getElementById("keyWord4").value;
				sessionList += "&key4=" + document.getElementById("keyWord5").value;
				
				document.getElementById("setSessionVar_frame").src = "/includes/setSessionVar.php?" + sessionList;
			}
		}
		
		function buildSearchQuery() {
			var keylist = "";
			var src_string = "";
			current_results_layer = 1;

			if ( document.getElementById("1_SecondaryCat").selectedIndex > 0 ) {
				cat1 = clorox_getSecondaryCatId("1_SecondaryCat");
			} else {
				cat1 = clorox_getMainCatId("1_MainCat");
			}
            document.forms.search_manuscripts.cat1 = cat1;
            
			if ( document.getElementById("2_SecondaryCat").selectedIndex > 0 ) {
				cat2 = clorox_getSecondaryCatId("2_SecondaryCat");
			} else {
				cat2 = clorox_getMainCatId("2_MainCat");
			}
            document.forms.search_manuscripts.cat2 = cat2;
            
			if ( document.getElementById("3_SecondaryCat").selectedIndex > 0 ) {
				cat3 = clorox_getSecondaryCatId("3_SecondaryCat");
			} else {
				cat3 = clorox_getMainCatId("3_MainCat");
			}
            document.forms.search_manuscripts.cat3 = cat3;
            
			keylist = clorox_buildKeyWordList(keylist,document.getElementById("keyWord1").value);
			key1 = clorox_getKeyWord(document.getElementById("keyWord1").value);
			keylist = clorox_buildKeyWordList(keylist,document.getElementById("keyWord2").value);
			key2 = clorox_getKeyWord(document.getElementById("keyWord2").value);
			keylist = clorox_buildKeyWordList(keylist,document.getElementById("keyWord3").value);
			key3 = clorox_getKeyWord(document.getElementById("keyWord3").value);
			keylist = clorox_buildKeyWordList(keylist,document.getElementById("keyWord4").value);
			key4 = clorox_getKeyWord(document.getElementById("keyWord4").value);
			keylist = clorox_buildKeyWordList(keylist,document.getElementById("keyWord5").value);
			key5 = clorox_getKeyWord(document.getElementById("keyWord5").value);

			if ( trim(keylist) == "" && trim(cat1) == "" && trim(cat2) == "" && trim(cat3) == "" ) {
				alert("Please provide a category or at least one keyword to search against the database.");
				document.getElementById("keyWord1").focus();
			} else {
				src_string += "&cat1=" + cat1;
				src_string += "&cat2=" + cat2;
				src_string += "&cat3=" + cat3;
				src_string += "&key1=" + key1;
				src_string += "&key2=" + key2;
				src_string += "&key3=" + key3;
				src_string += "&key4=" + key4;
				src_string += "&key5=" + key5;
				src_string += "&keylist=" + keylist
			}			
			
			return src_string;
		}
		
		function clorox_saveSearch() {
			if (document.getElementById("saveSearchName").value == "") {
				document.getElementById("saveSearchName").focus();
				return null; 
			} else {
                var el_worktype = document.getElementById('lkup_worktype');
                
				searchString =  "/desktop/clorox_saveSearch.php?" + currentSearchString + "&saveName=" + document.getElementById("saveSearchName").value + "&lkup_worktype=" + el_worktype.value;
                var el_iframe = document.getElementById("search_frame");
                if( el_iframe )
                {
				    el_iframe.src = searchString;
                }
			}
		}
		
        function clorox_view_all()
        {
            window.location = "index.php?view=search&mode=all&searching=true";
        }
        
		//fired from search button click event
		function clorox_search(saveFlag) {
			var src_string = buildSearchQuery();
			if ( trim(src_string) != "" ) {
                //clorox_setSessionState();
                document.getElementById('initialize_new_search').value = "true";
                document.forms.search_manuscripts.submit();
                return;
                
				//clorox_submit_search(src_string);
				clorox_setSessionState();
			}
			
		}
		
		function clorox_search_fail(targ_window) {
			var obj = targ_window.document.getElementById("search_results");
			if (obj.innerHTML != "") {
				obj.innerHTML = "<br /><center><span class='pageHeader'>Your search returned 0 results.</span></center><br /><br /><br />";
				targ_window.document.getElementById("search_pages").innerHTML = "";
			}
		}
		
		//finds all records based on search criteria
		function clorox_find_records(searchString) {             
			searchString =  "/desktop/clorox_search.php?" + searchString;
			document.getElementById("search_frame").src = searchString;
		}
		//but first, we need to...
		
		//first we pull a record count
		function clorox_submit_search(searchString, saved_name) {
            //clear the 'back layer' array
            previousLayers = new Array();
            previousLayer = -1;
            
			//this var is an inter-operability variable so that search all new, etc. work
			currentSearchString = searchString;
		
			//clear page innerHTML for result pages
			parent.document.getElementById("search_results").innerHTML = "";
			
			//clear page innerHTML for result page links
			parent.document.getElementById("search_pages").innerHTML = "";
           
             
            if(saved_name) //we are in the history page (saved searches)
            {
		        var el_saved_name = document.getElementById('saved_search_selected');
                el_saved_name.innerHTML = saved_name;
            }
            
            
			searchString =  "/desktop/clorox_shallowSearch.php?" + searchString + "&saved_search_name=" + saved_name;
			document.getElementById("search_frame").src = searchString;
		}
		
		//then we build out the links
		function build_result_page_links(recordCount) {
			//build empty divs for each predicted block of results			
			var resultPageHTML = "";
			
            //clear the 'back layer' array
            previousLayers = new Array();
            previousLayer = -1;
            
			//build links to toggle visibility for result blocks
            var resultLinksHTML = "<a href='javascript:alert(backMsg);'><strong>|?|</strong></a>&nbsp;&nbsp;<div id='layerBack' style='display: inline;'>" + backDisabledText + "</div>";
			resultLinksHTML += "<strong>Results Pages:&nbsp;&nbsp;</strong>";
            
			for (var i = 0; i < Math.ceil(recordCount / results_per_page); i++) {
                //alert("Building results_layer_" + i);
				resultPageHTML +=  "<div id='results_layer_" + i + "' style='z-index:" + (5000 - i) + "; display:block;'></div>";
				resultLinksHTML += "&nbsp;&nbsp;<div id='paginate_" + i + "' style='display: inline;'><a href='javascript:clorox_loadLayer(" + i + ")'>" + (i + 1) + "</a></div>&nbsp;&nbsp;";
			}
			
			//update page count var
			count = Math.ceil(recordCount / results_per_page);
			
			//update page innerHTML for result pages
			parent.document.getElementById("search_results").innerHTML = resultPageHTML;
			
			//update page innerHTML for result page links
			parent.document.getElementById("search_pages").innerHTML = resultLinksHTML;
			
			//auto-search for either first page record, or last session page
			parent.document.getElementById("auto_search_form").submit();
			
			//re-enable save buttons
			clorox_reset_save_button(false);
		}
		
        function clorox_layerBack()
        {

            var val = previousLayers.pop();
            if( previousLayers.length == 0 )
            {
                document.getElementById('layerBack').innerHTML = backDisabledText;
                previousLayers = new Array();
                previousLayer = val;
            }
			for (var i = 0; i < 1000; i++) {
				if (document.getElementById("results_layer_" + i)) {
					document.getElementById("results_layer_" + i).style.display = (val == i) ? "block" : "none";
                    document.getElementById("paginate_" + i).innerHTML = (val == i) ? i + 1 : "<a href='javascript:clorox_loadLayer(" + i + ")'>" + (i + 1) + "</a>";
				} else {
					break;
				}
			} 

			if (document.getElementById("results_layer_" + val).innerHTML == "") {
				//basically a try...catch() implementation.  
				//the auto-page loader occasionally fails
				//on searches with one search results page.  think it has something to do
				//with the session value for the last search page being clicked not being reset
				if (document.getElementById("results_layer_" + val)) {
					loadSequentialPageResults(val);      
                    currentLayer = val;
				} else {
					loadSequentialPageResults(0);
                    currentLayer = 0;
				}
			}
        }
        
		function clorox_reset_save_button(enableFlag) {
			var resetTextField = false;
		
			if (document.getElementById("saveSearchButton")) {
				//evaluates if it is being card by the actual search page
				document.getElementById("saveSearchButton").disabled 	= enableFlag;
				document.getElementById("saveSearchName").disabled 	= enableFlag;
				resetTextField = true;
			} else {
				//evaluates if this method is invoked by the iframe search query page
				if (parent.document.getElementById("saveSearchButton")) {
					//redundant; makes sure that this isnt being called on a page like "search premium"
					parent.document.getElementById("saveSearchButton").disabled 	= enableFlag;
					parent.document.getElementById("saveSearchName").disabled 	= enableFlag;
					resetTextField = true;
				}
			}
			
			if (resetTextField && !enableFlag) {
				parent.document.getElementById("saveSearchName").value = "";
			}
		}
		
		function loadSequentialPageResults(val) {
			//check to make sure data hasnt already been loaded prior to executing query
            //alert("Doesn't results_layer_" + val + " exist?");
			if (document.getElementById("results_layer_" + val).innerHTML == "") {
				var src_string = "";
				src_string += currentSearchString;
				src_string += "&startRec=" + (val * results_per_page);
				src_string += "&requestCount=" + results_per_page;
				src_string += "&refPage=" + val;
                src_string += "&from=paginate";
				
				clorox_find_records(src_string);
				current_results_layer = val;
				clorox_setSessionState();
			}
		}
		
		function clorox_loadLayer(val) {
			//the page that is running this method on itself has no inherent
			//notion of how many result pages there are.  therefore we loop
			//until it cant find anymore, then break
            
            
			var val;
			for (var i = 0; i < 1000; i++) {
				if (document.getElementById("results_layer_" + i)) {
					document.getElementById("results_layer_" + i).style.display = (val == i) ? "block" : "none";
                    document.getElementById("paginate_" + i).innerHTML = (val == i) ? i + 1 : "<a href='javascript:clorox_loadLayer(" + i + ")'>" + (i + 1) + "</a>";
				} else {
					break;
				}
			} 
            //alert("I'm Here...");
            
            if( previousLayer != previousLayers[previousLayers.length - 1] && previousLayer != -1 )
            {
                previousLayers.push(previousLayer);
                //limit the back link to the last 25 elements
                if( previousLayers.length > 25 )
                {
                    previousLayers.shift();
                }
            }
            if( previousLayers.length == 1 )
            {
                document.getElementById('layerBack').innerHTML = backEnabledText;
            }
            previousLayer = val;
			if (document.getElementById("results_layer_" + val).innerHTML == "") {
				//basically a try...catch() implementation.  
				//the auto-page loader occasionally fails
				//on searches with one search results page.  think it has something to do
				//with the session value for the last search page being clicked not being reset
				if (document.getElementById("results_layer_" + val)) {
					loadSequentialPageResults(val);      
				} else {
					loadSequentialPageResults(0);
				}
			}
		}

		function clorox_add_search_result(targ_window, ref_page, mss_id, index, title, author, summary, post_date, cat1_main, cat1_sec, cat2_main, cat2_sec, cat3_main, cat3_sec, count) {
			var obj = targ_window.document.getElementById("results_layer_" + ref_page);
			
			if (title == "") {
				title = "Untitled Work";
			}
			
			formatted_search_counter = Math.abs(formatted_search_counter - 1);
			var insertString = "";

			if (obj.innerHTML == "") {
				insertString += "<table cellpadding='3' cellspacing='0' border='0'>";
				insertString += "<tr><td style='font-weight:bold;'>Posted</td><td width='1'></td><td style='font-weight:bold;'>Author</td><td width='1'></td><td style='font-weight:bold;' width='500'>Manuscript Title & Subcategories</td></tr>";
			} else {
				insertString = obj.innerHTML;
				if (insertString.toLowerCase().indexOf("</tbody>") > 0) {
					var tempNum  = insertString.toLowerCase().indexOf("</tbody>");
					insertString = insertString.substring(0, tempNum);
				} else if (insertString.toLowerCase().indexOf("</table>") > 0) {
					var tempNum  = insertString.toLowerCase().indexOf("</table>");
					insertString = insertString.substring(0, tempNum);
				} 
				
				//alert("insertString :: " + insertString);
			}

			insertString += 	"<tr style='background-color:" + formatted_search_bgcolors[formatted_search_counter] + ";'>";
			insertString += 	"<td valign='top' width='75'>" + post_date + "</td><td width='1'></td>";
			insertString += 	"<td valign='top' width='150'>" + author + "</td><td width='1'></td>";
			insertString += 	"<td><a target='_blank' href='/desktop/?view=view_manuscripts&id=" + mss_id + "'>" + title + "</a><br /><span style='font-weight:bold;'>";
			insertString += 	(cat1_main != "" ) ? (cat1_main + ": " + cat1_sec + ", ") : "";
			insertString += 	(cat2_main != "" ) ? (cat2_main + ": " + cat2_sec + ", ") : "";
			insertString += 	(cat3_main != "" ) ? (cat3_main + ": " + cat3_sec) : "";
			insertString += 	"</span><br />\"";
			insertString += 	(summary != "") ? summary.substr(0, 200) : "<i>No summary information available.</i>";
			insertString += 	"...\"</td>";
			insertString += 	"</tr>";
			
			if ((index == (count - 1)) || (count == 1)) {
				insertString += "</table></div>";
				if (targ_window.document.getElementById("temp_reset_form")) {
					targ_window.document.getElementById("temp_reset_form").submit();
				}
				//weaksauce hack...  temporary
				parent.document.getElementById("side_menu_panel").height = 1500; //600 + (count * 100);
				clorox_search_scroll();
				//clorox_show_confirmation(targ_window, false);
			}
			
			obj.innerHTML = insertString;
		}
		
		function clorox_search_scroll() {
			location.href = '#anchor_results';
		}
//////////////////////////  END

//////////////////////////  CLOROX UPDATE MANUSCRIPT
		var last_value = "";
		var last_id = "";
		var saved = false;
		var document_editMode = false;
		
		
		
		function clorox_edit(id, type, table, work_id, comp_month, comp_year) {
			//re-initialize last id
			last_id = "";
			
			document.getElementById(id + "_nav").innerHTML  = '<input type="button" class="editmss" value="Save" onclick="clorox_save(\'' + id + '\', \'' + type + '\', \'' + table + '\', \'' + work_id +'\');"><br>';
			document.getElementById(id + "_nav").innerHTML += '<input type="button" class="editmss" value="Cancel" onclick="clorox_reset(\'' + id + '\', \'' + type + '\', \'' + table + '\', \'' + work_id +'\');">';
			last_value = document.getElementById(id + "_content").innerHTML;
			
			if ((type == "category") || (type == "keyword")) {
				last_id = document.getElementById(id + "_lastID").value;
			}
			
			if (type == "statusDropdown") {
				document.getElementById(id + "_content").innerHTML = 	'<select id="' + (id + '_input') + '" name="' + (id + '_input') + '"><option value="0">Disable Manuscript</option><option value="1">Enable Manuscript</option></select>';
			}
			
			if (type == "category") {
				document.getElementById(id + "_content").innerHTML = document.getElementById("template_category").innerHTML;
				document.getElementById("template_category").innerHTML = "";
			}
			
			if (type == "workType") {
				document.getElementById(id + "_content").innerHTML = document.getElementById("template_workType").innerHTML;
				document.getElementById("template_workType").innerHTML = "";
			}
			
			if (type == "completionDate") {
				document_editMode = true;   
                var year_dd = build_year_dd(comp_year);
                var month_dd = build_month_dd(comp_month);   
				document.getElementById(id + "_content").innerHTML = "<span>" + month_dd + "&nbsp;&nbsp;&nbsp;" + year_dd;
			}
			
			if (type == "input" || type == "keyword") {
				document_editMode = true;
				document.getElementById(id + "_content").innerHTML = '<input id="' + (id + '_input') + '" name="' + (id + '_input') + '" size="35" value="' + document.getElementById(id + "_content").innerHTML + '">';
			}
			
			if (type == "textarea") {
				document.getElementById(id + "_content").innerHTML = '<textarea rows="20" cols="57" id="' + (id + '_input') + '" name="' + (id + '_input') + '" size="35">' + text_to_php(document.getElementById(id + "_content").innerHTML) + '</textarea>';
			}
			
			if (type == "upload") {
				document.getElementById(id + "_content").innerHTML = 	'<input type="text" 	id="frm' + document.getElementById(id + "_type").value + 'FileName" 		name="frm' + document.getElementById(id + "_type").value + 'FileName" value="" disabled="true">';
				document.getElementById(id + "_content").innerHTML += 	'<input type="hidden" 	id="frm' + document.getElementById(id + "_type").value + 'SearchTuple" 		name="frm' + document.getElementById(id + "_type").value + 'SearchTuple" value="">';
				document.getElementById(id + "_content").innerHTML += 	'<input type="hidden" 	id="frm' + document.getElementById(id + "_type").value + 'UploadFileName" 	name="frm' + document.getElementById(id + "_type").value + 'UploadFileName" value="">';
				document.getElementById(id + "_content").innerHTML += 	'<input type="hidden" 	id="frm' + document.getElementById(id + "_type").value + 'FileType" 		name="frm' + document.getElementById(id + "_type").value + 'FileType" value="">';
				document.getElementById(id + "_content").innerHTML += 	'<input type="hidden" 	id="frm' + document.getElementById(id + "_type").value + 'FileSize" 		name="frm' + document.getElementById(id + "_type").value + 'FileSize" value="">';
				document.getElementById(id + "_content").innerHTML += 	'<input type="button" name="frmBtnUpload' + document.getElementById(id + "_type").value + '" value=" Browse... " onClick="JavaScript:uploadTool(\'Upload File\',\'' + document.getElementById(id + "_type").value + '\');">';
			}
			
			set_edit_mode("disable");
		}
		 function build_year_dd(selected_year)
         {
           var yearDropDown = "<strong>Year:</strong>&nbsp;&nbsp;<select id='WorkCompletionDate_year' name='WorkCompletionDate_year' value='" + selected_year + "'>"
           for( var i = 1995; i < 2021; i++)
           {
                if( selected_year == i )
                {
                    yearDropDown +=	"<option value='" + i + "' selected>" + i + "</option>";
                }else{
                    yearDropDown +=	"<option value='" + i + "'>" + i + "</option>";
                }
           
           }
         
            yearDropDown += "</select>";
            return yearDropDown;
         
         }
         
         function build_month_dd(selected_month)
         {
            var monthDropDown = "<strong>Year:</strong>&nbsp;&nbsp;<select id='WorkCompletionDate_month' name='WorkCompletionDate_month' value='" + selected_month + "'>";
            if( selected_month == '01' )
            {
                monthDropDown += "<option value='01' selected>January</option>";
            }else{
                monthDropDown += "<option value='01'>January</option>";
            }
            if( selected_month == '02' )
            {
                monthDropDown += "<option value='02' selected>February</option>";
            }else{
                monthDropDown += "<option value='02'>February</option>";
            }
            if( selected_month == '03' )
            {
                monthDropDown += "<option value='03' selected>March</option>";
            }else{
                monthDropDown += "<option value='03'>March</option>";
            }
            if( selected_month == '04' )
            {
                monthDropDown += "<option value='04' selected>April</option>";
            }else{
                monthDropDown += "<option value='04'>April</option>";
            }
            if( selected_month == '05' )
            {
                monthDropDown += "<option value='05' selected>May</option>";
            }else{
                monthDropDown += "<option value='05'>May</option>";
            }
            if( selected_month == '06' )
            {
                monthDropDown += "<option value='06' selected>June</option>";
            }else{
                monthDropDown += "<option value='06'>June</option>";
            }
            if( selected_month == '07' )
            {
                monthDropDown += "<option value='07' selected>July</option>";
            }else{
                monthDropDown += "<option value='07'>July</option>";
            }
            if( selected_month == '08' )
            {
                monthDropDown += "<option value='08' selected>August</option>";
            }else{
                monthDropDown += "<option value='08'>August</option>";
            }
            if( selected_month == '09' )
            {
                monthDropDown += "<option value='09' selected>September</option>";
            }else{
                monthDropDown += "<option value='09'>September</option>";
            }
            if( selected_month == '10' )
            {
                monthDropDown += "<option value='10' selected>October</option>";
            }else{
                monthDropDown += "<option value='10'>October</option>";
            }
            if( selected_month == '11' )
            {
                monthDropDown += "<option value='11' selected>November</option>";
            }else{
                monthDropDown += "<option value='11'>November</option>";
            }
            if( selected_month == '12' )
            {
                monthDropDown += "<option value='12' selected>December</option>";
            }else{
                monthDropDown += "<option value='12'>December</option>";
            }
			monthDropDown +=	"</select>";
            
            return monthDropDown;
         
         }
		function clorox_save(id, type, table, work_id) {
			//populate clorox fields
			var target = frames["update_frame"].document;
			target.getElementById("update_eval").value = "true";
			target.getElementById("update_type").value = type;
			target.getElementById("update_id").value = work_id;
			target.getElementById("update_table").value = table;
			target.getElementById("update_field").value = id;
			
			
			if ((type == "category") || (type == "keyword")) {
				target.getElementById("update_last_id").value = last_id;
			}
			
			if (type == "completionDate") {
				target.getElementById("update_content").value = document.getElementById("WorkCompletionDate_month").value + "-" + document.getElementById("WorkCompletionDate_year").value;
			} else if (type == "workType") {
				target.getElementById("update_content").value = document.getElementById("lkup_worktype").value;
			} else if (type == "category") {
				target.getElementById("update_content").value = document.getElementById("1_SecondaryCat").value;
			} else if (type == "upload") {
				//for document uploads
				target.getElementById("update_file_field").value = document.getElementById(id + "_type").value;
				target.getElementById("update_file").value	= document.getElementById("frm" + document.getElementById(id + "_type").value + "UploadFileName").value;
				target.getElementById("update_file_name").value	= document.getElementById("frm" + document.getElementById(id + "_type").value + "FileName").value;
				target.getElementById("update_file_type").value	= document.getElementById("frm" + document.getElementById(id + "_type").value + "FileType").value;
				target.getElementById("update_file_size").value	= document.getElementById("frm" + document.getElementById(id + "_type").value + "FileSize").value;
			} else if (type == "statusDropdown") {
				target.getElementById("update_content").value = document.getElementById(id + "_input").value;
			} else {
				if (id == "WorkWordCount") { 
					document.getElementById('WorkWordCount_input').value=stripAlpha(document.getElementById('WorkWordCount_input').value); 
				}
				target.getElementById("update_content").value = text_to_php(document.getElementById(id + "_input").value);
			}
			//submit clorox form
			target.getElementById("update_form").submit();
			
			if (type == "category") {
				document.getElementById(id + "_lastID").value = document.getElementById("1_SecondaryCat").value;
			} else if (type == "keyword") {
				document.getElementById(id + "_lastID").value = last_value;
			}
			
			saved = true;
			clorox_reset(id, type, table, work_id);
		}
		
		function clorox_reset(id, type, table, work_id) {
			main_cat = "";
			secondary_cat = "";
			document_editMode = false;
		
			if (type == "category") {
				if (saved) {
					secondary_cat = document.getElementById("1_SecondaryCat").options[document.getElementById("1_SecondaryCat").selectedIndex].text;
					main_cat = document.getElementById("1_MainCat").options[document.getElementById("1_MainCat").selectedIndex].text;
				}
				
				document.getElementById("template_category").innerHTML = document.getElementById(id + "_content").innerHTML;		
			}
			document.getElementById(id + "_nav").innerHTML  = '<input type="button" class="editmss" value="Edit" id="' + id + '_edit" name="' + id + '_edit" onclick="clorox_edit(\'' + id + '\', \'' + type + '\', \'' + table + '\', \'' + work_id +'\');"><br>';	
			
			if (type == "completionDate") {
                var comp_month = document.getElementById("WorkCompletionDate_month").value;
                var comp_year = document.getElementById("WorkCompletionDate_year").value;
				document.getElementById(id + "_content").innerHTML = comp_month + " - " + comp_year;
                document.getElementById(id + "_nav").innerHTML  = '<input type="button" class="editmss" value="Edit" id="' + id + '_edit" name="' + id + '_edit" onclick="clorox_edit(\'' + id + '\', \'' + type + '\', \'' + table + '\', \'' + work_id +'\', \'' + comp_month +'\', \'' + comp_year +'\');"><br>';
			} else if (type == "workType") {
				var tempNum = document.getElementById("lkup_worktype").value;
				document.getElementById("template_workType").innerHTML = document.getElementById(id + "_content").innerHTML;
				document.getElementById(id + "_content").innerHTML = (saved) ? echoWorkTypeString(tempNum) : last_value;				
			} else if (type == "statusDropdown") {
				document.getElementById(id + "_content").innerHTML = (document.getElementById(id + "_input").value == 0) ? "Manuscript is disabled" : "Manuscript is enabled";
			} else if (type == "category" && saved) {
				document.getElementById(id + "_content").innerHTML = last_value;
				document.getElementById(id + "_primary").innerHTML = main_cat;
				document.getElementById(id + "_secondary").innerHTML = secondary_cat;
			} else if (type == "upload" && saved) {
				document.getElementById(id + "_content").innerHTML = '<a href="javascript:downloadTool(\'' + document.getElementById(id + "_type").value + '\', \'' + work_id + '\');">Download File:  ' + document.getElementById("frm" + document.getElementById(id + "_type").value + "FileName").value + '</a>';
			} else if (saved) {
				document.getElementById(id + "_content").innerHTML = text_to_html(document.getElementById(id + "_input").value);
			} else {
				document.getElementById(id + "_content").innerHTML = last_value;
			}
			
			saved = false;	
			set_edit_mode("enable");
		}
		
		function set_edit_mode(value) {
			for (i = 0; i <= document.getElementById("frmRegister").length - 1; i++) {
				var tempObj=document.getElementById("frmRegister").elements[i];
				if (tempObj.value == "Edit") {
					div_content = tempObj.name.substr(0, tempObj.name.length - 5);
					tempObj.style.backgroundColor = (value == "enable") ? "D4D0C8" : "FFFFFF";
					tempObj.disabled = (value == "enable") ? false : true;
					
					document.getElementById(div_content + "_content").style.color = (value == "enable") ? "000000" : "AAAAAA";
				}
			}		
		}
		
		function text_to_php(str) {
			str = text_replace(str, "<br>\n", "\n");
			str = text_replace(str, "<BR>\n", "\n");
			str = text_replace(str, "<br>", "\n");
			str = text_replace(str, "<BR>", "\n");
			
			return str;	
		}
		
		function text_to_html(str) {
			str = text_replace(str, "\n", "<br>");
			return str;
		}
		
		function text_replace(str, from, to) {
			var i = str.indexOf(from);
			if (!from || !str || i == -1) return str;
			
			var newstr = str.substring(0, i) + to;
			if (i+from.length < str.length) { newstr += text_replace(str.substring(i+from.length,str.length),from,to); }
			return newstr;
		}
		
		function onKeyPress (e) {
			if (document_editMode == true) {
				var keycode;
				if (window.event) {
					keycode = window.event.keyCode;
				} else if (e) {
					keycode = e.which;
				} else {
					return true;
				}
				if (keycode == 13) {
					//do nothing
					return false
				}
				return true
			} else {
				return true;
			}
		}
		document.onkeypress = onKeyPress;

//////////////////////////  END

//Added by Rick Robinson <rrobinson@itpdx.com>


/**
 * Hides/Unhides the email form on button click
 */
function clorox_show_email_form()
{
    var el_form = document.getElementById('forward_to');
    var el_button = document.getElementById('forward_button');
    
    if( el_form )
    {
        if( el_form.style.display == 'block' )
        {
            el_form.style.display = 'none';
            el_button.innerHTML = "Forward to a Colleague";
            document.getElementById('email_to').value = "";
            document.getElementById('email_to').style.backgroundColor = "#ffffff";
            //document.getElementById('email_cc').value = "";
            //document.getElementById('email_bcc').value = "";
            document.getElementById('email_message').value = "";
            document.getElementById('email_attached').checked = true;
            var el_iframe = document.getElementById("email_frame");
            el_iframe.contentWindow.document.body.innerHTML = "";
            
        }else{
            el_form.style.display = 'block';
            el_button.innerHTML = "Cancel/Clear Forward";
            
            //document.getElementById("email_frame").style.display = "none";
        }
    }
}

/**
 * Verifies email input and sends the email if 
 * everything looks ok
 */
function clorox_send_manuscript(UserID, WorkID)
{
    //collect all our elements
    var el_iframe = document.getElementById("email_frame");
    var el_name = document.getElementById('email_from_name');
    var el_from = document.getElementById('email_from');
    var el_to = document.getElementById('email_to');
    //var el_cc = document.getElementById('email_cc');
    //var el_bcc = document.getElementById('email_bcc');
    var el_subject = document.getElementById('email_subject');
    var el_message = document.getElementById('email_message');
    var el_attach = document.getElementById('email_attached');
    
    // To: is required
    if( el_to.value == "" )
    {
        el_to.style.backgroundColor = "#ffb3b3";
        el_iframe.contentWindow.document.body.innerHTML = "<span style='font-size: 9pt; font-weight: bold;'>'To' field required</span>";
        return;
    }
    
    //check To: for valid emails
    var emails = Array();
    emails = el_to.value.split(",");
    for( var i = 0; i < emails.length; i++ )
    {
        if( check_email( emails[i] ) == false )
        {
            alert( emails[i] + " in the 'To' field seems to be invalid" );
            return;
        }
    }
    
    //check CC: for valid emails -- not implemented at this time
    /*if( el_cc.value != "" )
    {
        var emails = Array();
        emails = el_cc.value.split(",");
        for( var i = 0; i < emails.length; i++ )
        {
            if( check_email( emails[i] ) == false )
            {
                alert( emails[i] + " in the 'CC' field seems to be invalid" );
                return;
            }
        }
    }
    
    //check BCC: for valid emails -- not implemented at this time
    if( el_bcc.value != "" )
    {
        var emails = Array();
        emails = el_bcc.value.split(",");
        for( var i = 0; i < emails.length; i++ )
        {
            if( check_email( emails[i] ) == false )
            {
                alert( emails[i] + " in the 'BCC' field seems to be invalid" );
                return;
            }
        }
    }*/
    
    //see if we have a subject and verify with user if not
    if( el_subject.value == "" )
    {
        var ret = confirm( "Are you sure you want to send email without a subject?" );
        if( !ret )
        {
            with( document.all )
            {
                el_subject.focus();
            }
            return;
        }
        
    }
    var message_text = el_message.value;
    message_text =  message_text.split(/\n/).join("<br />");
    //put our GET request variables together
    var reqVariables = "user_id=" + UserID + "&work_id=" + WorkID + "&email_from_name=" + el_name.value + "&email_from=" + el_from.value;
    reqVariables += "&email_to=" + el_to.value; // + "&email_cc=" + el_cc.value + "&email_bcc=" + el_bcc.value;
    reqVariables += "&email_subject=" + el_subject.value + "&email_message=" + message_text + "&email_attachments=" + el_attach.checked;
    
    //doit
     el_iframe.contentWindow.document.body.innerHTML = "<span style='font-size: 9pt; font-weight: bold;'>Attempting to send email...Please Wait<br/></span>";
    el_iframe.src = "/desktop/clorox_send_manuscript.php?" + reqVariables;
    

}

/**
 * Does it's best to validate email addresses
 *  I wish I knew who wrote this so I could credit them
 *  here. I didn't
 */
function check_email (emailStr) {

    /* Trim leading and trailing whitespace */
    emailStr = trim_whitespace( emailStr );
    
    /* The following variable tells the rest of the function whether or not
    to verify that the address ends in a two-letter country or well-known
    TLD.  1 means check it, 0 means don't. */

    var checkTLD=1;

    /* The following is the list of known TLDs that an e-mail address must end with. */

    var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

    /* The following pattern is used to check if the entered e-mail address
    fits the user@domain format.  It also is used to separate the username
    from the domain. */

    var emailPat=/^(.+)@(.+)$/;

    /* The following string represents the pattern for matching all special
    characters.  We don't want to allow special characters in the address. 
    These characters include ( ) < > @ , ; : \ " . [ ] */

    var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

    /* The following string represents the range of characters allowed in a 
    username or domainname.  It really states which chars aren't allowed.*/

    var validChars="\[^\\s" + specialChars + "\]";

    /* The following pattern applies if the "user" is a quoted string (in
    which case, there are no rules about which characters are allowed
    and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
    is a legal e-mail address. */

    var quotedUser="(\"[^\"]*\")";

    /* The following pattern applies for domains that are IP addresses,
    rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
    e-mail address. NOTE: The square brackets are required. */

    var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

    /* The following string represents an atom (basically a series of non-special characters.) */

    var atom=validChars + '+';

    /* The following string represents one word in the typical username.
    For example, in john.doe@somewhere.com, john and doe are words.
    Basically, a word is either an atom or quoted string. */

    var word="(" + atom + "|" + quotedUser + ")";

    // The following pattern describes the structure of the user

    var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

    /* The following pattern describes the structure of a normal symbolic
    domain, as opposed to ipDomainPat, shown above. */

    var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

    /* Finally, let's start trying to figure out if the supplied address is valid. */

    /* Begin with the coarse pattern to simply break up user@domain into
    different pieces that are easy to analyze. */

    var matchArray=emailStr.match(emailPat);

    if (matchArray==null) {

        /* Too many/few @'s or something; basically, this address doesn't
        even fit the general mould of a valid e-mail address. */

        //alert("Email address seems incorrect (check @ and .'s)");
        return false;
    }
    
    var user=matchArray[1];
    var domain=matchArray[2];

    // Start by checking that only basic ASCII characters are in the strings (0-127).

    for (i=0; i<user.length; i++) {
        if (user.charCodeAt(i)>127) {
        //alert("Ths username contains invalid characters.");
        return false;
       }
    }
    for (i=0; i<domain.length; i++) {
        if (domain.charCodeAt(i)>127) {
        //alert("Ths domain name contains invalid characters.");
        return false;
       }
    }

    // See if "user" is valid 

    if (user.match(userPat)==null) {

        // user is not valid

        //alert("The username doesn't seem to be valid.");
        return false;
    }

    /* if the e-mail address is at an IP address (as opposed to a symbolic
    host name) make sure the IP address is valid. */

    var IPArray=domain.match(ipDomainPat);
    if (IPArray!=null) {

        // this is an IP address

        for (var i=1;i<=4;i++) {
            if (IPArray[i]>255) {
            //alert("Destination IP address is invalid!");
            return false;
           }
        }
        return true;
    }

    // Domain is symbolic name.  Check if it's valid.
     
    var atomPat=new RegExp("^" + atom + "$");
    var domArr=domain.split(".");
    var len=domArr.length;
    for (i=0;i<len;i++) {
        if (domArr[i].search(atomPat)==-1) {
        //alert("The domain name does not seem to be valid.");
        return false;
       }
    }

    /* domain name seems valid, but now make sure that it ends in a
    known top-level domain (like com, edu, gov) or a two-letter word,
    representing country (uk, nl), and that there's a hostname preceding 
    the domain or country. */

    if (checkTLD && domArr[domArr.length-1].length!=2 && 
        domArr[domArr.length-1].search(knownDomsPat)==-1) {
        //alert("The address must end in a well-known domain or two letter " + "country.");
        return false;
    }

    // Make sure there's a host name preceding the domain.

    if (len<2) {
        //alert("This address is missing a hostname!");
        return false;
    }

    // If we've gotten this far, everything's valid!
    return true;
}

// Remove leading and trailing whitespace from a string
function trim_whitespace(string) 
{
   var newString  = '';
   var substring  = '';
   beginningFound = false;
   
   // copy characters over to a new string
   // retain whitespace characters if they are between other characters
   for (var i = 0; i < string.length; i++) {
      
      // copy non-whitespace characters
      if (string.charAt(i) != ' ' && string.charAt(i) != '\n' && string.charCodeAt(i) != 9) {
         
         // if the temporary string contains some whitespace characters, copy them first
         if (substring != '') {
            newString += substring;
            substring = '';
         }
         newString += string.charAt(i);
         if (beginningFound == false) beginningFound = true;
      }
      
      // hold whitespace characters in a temporary string if they follow a non-whitespace character
      else if (beginningFound == true) substring += string.charAt(i);
   }
   return newString;
}