// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

      function showHideForm(form) {
         new Effect[Element.visible(form) ? 
           'BlindUp' : 'BlindDown'](form, {duration: 0.25});
      }

      function showEditableTags(hide, show) {
				Element.hide(hide);
				Element.show(show);
      }

      function showTags(hide, show1, show2) {
				Element.hide(hide);
				Element.show(show1);
				Element.show(show2);
      }

			function loading(hide) {
				Element.hide(hide);
			}

		  function quickRedReference(page) {
		    window.open( 
		      page,
		      "redRef",
		      "height=600,width=550,channelmode=0,dependent=0," +
		      "directories=0,fullscreen=0,location=0,menubar=0," +
		      "resizable=0,scrollbars=1,status=1,toolbar=0" 
		    );
		  }

			function toggle_all(tableId, CheckBoxId, CheckBoxesName)
			{
			    listTable = $(tableId);
			    listTable.SelectAllRows = $(CheckBoxId);
			    var aCheckBoxes = document.getElementsByName(CheckBoxesName);
			    var bChecked = listTable.SelectAllRows.checked;
				
			    var nRows = aCheckBoxes.length;
					
			    if(bChecked)
			    {
				  	for(var i=0;i<nRows;i++)
				    {
							aCheckBoxes[i].checked = bChecked;
				    }
			    }
			    else
			    {
				  	for(var i=0;i<nRows;i++)
				    {
							aCheckBoxes[i].checked = bChecked;
				    }
			    }
			    
			}


  	function delete_selected(chkbxesName, formName) {

			var aCheckboxes = document.getElementsByName(chkbxesName);
			var count = aCheckboxes.length;
			bChecked = false;
			
			var strChecked = '';
			var countChecked = 0;
			
			for(var i=0;i<count; i++)
			{
				if(aCheckboxes[i].checked)
				{
					countChecked += 1;
					bChecked = true;
					if (countChecked > 1)
						{
							strChecked += ", ";
						}
						strChecked += aCheckboxes[i].value;
					}
				}
				
				var strMessage = (countChecked > 1) ? 'messages' : 'message';
				
				if(!bChecked)
				{
					alert("Please select at least 1 message to delete");
					return false;
				}
				else
				{
					 if (confirm("Are you sure you want to delete selected " + strMessage))
					 {
						 document.forms[formName].strChkBoxes.value = strChecked;
						 document.forms[formName].submit();
					 }
					 else
					 	return false;
			}
						
    }
    
		function limitText(limitField, limitCount, limitNum, bAlert) {
			if ($(limitField).value.length > limitNum) {
				$(limitField).value = $(limitField).value.substring(0, limitNum);
				if(bAlert) {
					alert("Sorry, this field accepts up to " + limitNum + " characters.")
				}
			} else {
				$(limitCount).value = limitNum - $(limitField).value.length;
			}
		}

		function limitTextWithoutCount(limitField, limitNum, bAlert) {
			if ($(limitField).value.length > limitNum) {
				$(limitField).value = $(limitField).value.substring(0, limitNum);
				if(bAlert) {
					alert("Sorry, this field accepts up to " + limitNum + " characters.")
				}
			}
		}
		
		function validateMultipleEmails(textField) {
			var strInput = $(textField).value;
			//alert(strInput);
			var errorString = "Please enter one or more email addresses in \'To\' field.";
			if(strInput.length > 0) {
				var string = trim(strInput);
				if(string.length > 0) {
					var strArray = (string).split(',');
					count = strArray.length;
					index = 0;
					if(count > 0) {
						for(var i=0; i<count; i++) {
							index += 1;
							if(!isValidEmail(trim(strArray[i]))) {
								alert(getString(index) + " email you entered is not a valid email address.")
								$(textField).focus();
								return false;
							}	
						}
					}
					else {
						alert(errorString);
						$(textField).focus();
						return false;
					}
				}
				else {
					alert(errorString);
					$(textField).focus();
					return false;
				}
			}
			else {
				alert(errorString);
				$(textField).focus();
				return false;
			}
			return true;
		}
		
		function getString(index) {
			switch(index) {
				case 1:
					return index + 'st';
					break;
				case 2:
					return index + 'nd';
					break;
				case 3:
					return index + 'rd';
					break;
				default:
					return index + 'th'; 
					break;
			}
		}

		function validateMessageForm(fieldTo, fieldBody) {
		
			if(!isNotEmptyText($(fieldTo))) { 
				alert("Please enter a user id in \'To\' field.");
				$(fieldTo).focus();
				return false;
			}

		/*
			if(!isNotEmptyText($(fieldBody))) { 
				alert("Message can't be empty.");
				$(fieldBody).focus();
				return false;
			}
		*/
			return true;
		}
		
		function fixURL(fieldName) {
			if(isNotEmptyText($(fieldName))) {
				var url = trim($(fieldName).value);
				//alert(url)
				if(url.indexOf('http://') != 0) {
					$(fieldName).value = 'http://' + url;
					//alert($(fieldName).value)
				}
			}
			return true;
		}
		    