
/* this will replace a string with something else */
function ReplaceAll(Source,stringToFind,stringToReplace){
  var temp = Source;
  var index = temp.indexOf(stringToFind);
	while(index != -1) {
		temp = temp.replace(stringToFind,stringToReplace);
		index = temp.indexOf(stringToFind);
	}

     return temp;
}

function Strip(orig) {

		var newStr = orig;

		newStr = ReplaceAll(newStr,"<", "&#60;");
		newStr = ReplaceAll(newStr,">", "&#62;");
		newStr = ReplaceAll(newStr,"'", "&#39;");
		newStr = ReplaceAll(newStr,"­", "&#45;");
		newStr = ReplaceAll(newStr,"!", "&#33;");
		newStr = ReplaceAll(newStr,"@", "&#64;");
		newStr = ReplaceAll(newStr,"`", "&#96;"); 
		newStr = ReplaceAll(newStr,'"', "&#34;");
		newStr = ReplaceAll(newStr,"%", "&#37;");
		newStr = ReplaceAll(newStr,"^", "&#94;");
		newStr = ReplaceAll(newStr,"*", "&#42;");
		newStr = ReplaceAll(newStr,"(", "&#40;");
		newStr = ReplaceAll(newStr,")", "&#41;");
		newStr = ReplaceAll(newStr,"+", "&#43;");
		newStr = ReplaceAll(newStr,"=", "&#61;");
		newStr = ReplaceAll(newStr,"?", "&#63;"); 

		return newStr;

	}


function detectScrollbar()
{
    if (navigator.appName == "Microsoft Internet Explorer")
    {
        window.name=document.body.scrollTop;
    }
    else
   {
        window.name=window.pageYOffset;
    }
}

function doScroll()
{
  if (window.name)  window.scrollTo(0, window.name);

}
/* This will allow for a box to pop up and tell the user
	That they cannot use certain characters. MySql does
	not allow them so I cannot allow them to use.
*/


function wrongChar(site) {
	var s = new String(site);
	var g = new String(site.value.length);
	var v = new String(site.value);
	var iChars = "!@#$%^&*()+=[]\\\';/{}|\":<>?";
        for (var i = 0; i < g; i++) {
                if (iChars.indexOf(v.charAt(i)) != -1) {
					alert ("The box has one of the following special characters. \n Quote, Apostrophie, Ampersand, Asterick etc \nThese are not allowed \n ");
					return false;
				}
		}
}


/* Open a window
*/
function openWin(sUrl) {
		var sWin = sUrl;
		window.open(sWin, '','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=1000,height=650,top=0,left=0');
}


/* Now close the dumb thing
*/
function getClose()
{
	window.close();
}


/*=================================================================
Function: checkEnter
Purpose:  check if the enter key is clicked in a text box
Input:    e the event object, n the button name used for postback
Returns:  undefined
==================================================================*/

function checkEnter(e, n)
{ //e is event object passed from function invocation
						//n is the button name

	var characterCode;  //literal character code will be stored in this variable;

	if(e && e.which)
	{ //if which property of event object is supported (NN4)
		e = e;
		characterCode = e.which; //character code is contained in NN4's which property
	}
	else
	{							
		e = event;						
		characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}	 	 
	if(characterCode == 13)
	{ //if generated character code is equal to ascii 13 (if enter key)
		e.keyCode = 0;
		e.returnValue = false;
		e.cancelBubble = true;  
		__doPostBack(n,'');
	}
}
<!-- Used in CalEventEdit.jsp -->
function hideTables(t) {
		document.all['RecurDaily'].style.display = "none";
		document.all['RecurWeekly'].style.display = "none";
		document.all['RecurMonthly'].style.display = "none";
		document.all['RecurYearly'].style.display = "none";
		if(t == 'Daily') {
			document.all['RecurDaily'].style.display = "inline";
		}
		if(t == 'Weekly') {
			document.all['RecurWeekly'].style.display = "inline";
		}
		if(t == 'Monthly') {
			document.all['RecurMonthly'].style.display = "inline";
		}
		if(t == 'Yearly') {
			document.all['RecurYearly'].style.display = "inline";
		}
		
}
function displayTables(t)
{
			document.all['RecurDaily'].style.display = "none";
			document.all['RecurWeekly'].style.display = "none";
			document.all['RecurMonthly'].style.display = "none";
			document.all['RecurYearly'].style.display = "none";
			
		if(t.value == 'Daily')
		{
			document.all['RecurDaily'].style.display = "inline";
		}
		if(t.value == 'Weekly')
		{
			document.all['RecurWeekly'].style.display = "inline";
		}
		if(t.value == 'Monthly')
		{
			document.all['RecurMonthly'].style.display = "inline";
		}
		if(t.value == 'Yearly')
		{
			document.all['RecurYearly'].style.display = "inline";
		}
}




function hideAttachment()
{
	document.all['Attachment'].style.display = "none";
}

function viewAttachment(t)
{
	if (document.all['Attachment'].style.display == "inline")
		document.all['Attachment'].style.display = "none";
	else
		document.all['Attachment'].style.display = "inline";
//	document.all['NoAttachBtn'].style.display = "none";
}


	function __doPostBack(eventTarget, eventArgument) {
		var theform;
		if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
			theform = document.forms["Form1"];
		}
		else {
			theform = document.Form1;
		}
		theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
		theform.__EVENTARGUMENT.value = eventArgument;
		theform.submit();
	}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImgRestore()
{ //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage()
{ //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null)
   {
	   document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];
	   }
}


/* This function will alternate the description (Long or Short) that is displayed.  
	Author:		Stephen Goldman, April 12, 2004
	Parameters:	description to be displayed 
*/			

function swrmc_HideLongShort(t)
{
		if(t == 'short')
		{
			document.all['short'].style.display = "inline";
			document.all['long'].style.display = "none";
		}
		if(t == 'long') 
		{
			document.all['long'].style.display = "inline";
			document.all['short'].style.display = "none";
		}
}

/* This function will open up a new window.  Used on the menus */
function swrmc_openWin(sUrl,target)
{
		var sWin;
		sWin = window.open(sUrl, target,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=800,height=600,top=0,left=0');
		sWin.focus();
}


/* This function will open up a new window - Preluded with a Loading Transaction message
	Author:		Stephen Goldman, March 29, 2004
	Parameters:	docForm - This is the document form
			height, width - size of the window to open
			action - action to take
			target - name of taget
*/			
function swrmc_NewTranWindow(docForm,height, width, action,target)
{
	var t = screen.availHeight/2-(height/2);
	var l = screen.availWidth/2-(width/2);
  	var sURL = '/ERM/common/TransLoading.html';
	tranWin = window.open(sURL, target,'titlebar=1,toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width='+width+',height='+height+',top='+t+',left='+l);
	docForm.target = target;
	docForm.action = action;
	docForm.submit();
	tranWin.focus(); 
}

function swrmc_NewTranWindowNoAct(docForm,height, width, target)
{
	var t = screen.availHeight/2-(height/2);
	var l = screen.availWidth/2-(width/2);
  	var sURL = '/ERM/common/TransLoading.html';
	tranWin = window.open(sURL, target,'titlebar=s,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width='+width+',height='+height+',top='+t+',left='+l);
	docForm.target = target;
	docForm.submit();
	tranWin.focus();
}

/* This function prompts the user if they want to delete a record
	Author:		Stephen Goldman, March 29, 2004
	Parameters:	docForm - This is the document form
			action - action to take (jsp program to call)
*/			
function swrmc_DeleteWindow(docForm, action)
{
	if (confirm("This action will delete the record and can not be undone. \nAre you sure you want to proceed (OK - yes   Cancel - no)?"))
	{
		swrmc_NewTranWindow(docForm,240,430,action,'DelWin');
	}	
}
	


/* This function prompts the user if they want to Update a given Record or not
	Author:		William Wood , 07 Oct 2008
	Parameters:	docForm - This is the document form
			action - action to take (jsp program to call)
*/			
function swrmc_WariningWindow(docForm, action)
{
	if (confirm("This action will Update this record and mark it as Paid. \nAre you sure you want to proceed (OK - yes   Cancel - no)?"))
	{
		swrmc_NewTranWindow(docForm,240,430,action,'WarWin');
	}	
}
	


/* refreshes a window (used in conjunciton with swrmc_DeleteWindow)
	Author:		Stephen Goldman, March 29, 2004
	Parameters:	loc - program to be refreshed
*/			
function swrmc_refreshWindow(loc)
{
	window.location=loc;
}
/* refreshes a opener window and closes existing window
	Author:		Stephen Goldman, March 29, 2004
	Parameters:	loc - program to be refreshed
*/			
function swrmc_refreshOpenerWindow(loc)
{
	window.opener.location=loc;
	window.close();
}
/* refreshes the parent opener window and closes existing window
	Author:		Stephen Goldman, March 29, 2004
	Parameters:	loc - program to be refreshed
*/			
function swrmc_refreshParentOpenerWindow(loc)
{
	window.opener.parent.location=loc;
	window.close();
}



/* Display warning to user that they are about to leave our website */
function swrmc_warningURL(url)
{
	if (confirm("Your are about to leave the Evansville Rescue Mission site. \n Click OK to proceed."))
	{
		window.open(url);
	}	
	

}
/* resizes a window 
	Author:		Stephen Goldman, March 29, 2004
	Parameters:	height, width - size of the window to be
			ScrollVisible - make scrollbar visble or invisable
*/			
function win_resize(width, height)
{
	window.resizeTo(width,height);
}

/* resizes a window 
	Author:		Stephen Goldman, March 29, 2004
	Parameters:	height, width - size of the window to be
			ScrollVisible - make scrollbar visble or invisable
*/			
function swrmc_win_resize(width, height)
{
	window.resizeTo(width,height);
}

function swrmc_PickList(loc, frm)
{
	frm.action=loc;
	frm.submit();
}

/*  This fucntion is used for the Alphabet listing 
		When the user selects a letter onclick will send the document.formname and the letter
		selected to this function which will set the onsubmit to nothing and then fire off the submit.
		The page needs to have two fields (employee and letter). 
*/
function swrmc_LetterList_LetterSelect(doc,selLetter)
{
		swrmc_LetterList_setLetter(doc, selLetter);
		doc.letter.value = selLetter;
		doc.employee.value = 0;
		doc.onSubmit="";
		doc.submit();
}
/*  This procedure is used for the Alphabet listing 
	This will change the class of the letter selected causing it to look different from the others
*/
function swrmc_LetterList_setLetter(doc, selLetter)
{
		doc.letter.value = selLetter;
		if(selLetter != null && selLetter != '') 
		{
				document.all(selLetter).className = "AlphabetClick";
		}
}

/* This function is used primarily when you have a dropdown list and it needs to do a submit after picking a item
off of the lise
*/
function swrmc_submit(doc)
{
	doc.onSubmit="";
	doc.submit();
}


			
function swrmc_NewWindow(docForm,height, width, action,target) {
	var t = screen.availHeight/2-(height/2);
	var l = screen.availWidth/2-(width/2);
	tranWin = window.open(action, target,'titlebar=s,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width='+width+',height='+height+',top='+t+',left='+l);
	tranWin.focus();
	
}

/* This function prompts the user if they want to delete a record
	Author:		Stephen Goldman, March 29, 2004
	Parameters:	docForm - This is the document form
			action - action to take (jsp program to call)
*/			
function swrmc_AreUSureWindow(docForm, action) {
	if (confirm("Are you sure you want to proceed (OK - yes   Cancel - no)?")){
		swrmc_NewTranWindow(docForm,1100,1150,action,'SureWin');
	}	

}	

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function
