/**********************************************************************************/
/** © 1998 - 2009 Ultratec, Inc.                                                 **/
/**                                                                              **/
/** Disclaimer:                                                                  **/
/**   Ultratec, Inc. is providing this code as an example of how to access their **/
/**   Externally Hosted CapTel Application Programming Interface. All example    **/
/**   source code obtained from Ultratec, Inc is delivered "AS IS." Ultratec,    **/
/**   Inc specifically disclaims any and all warranties, expressed or implied,   **/
/**   including but not limited to any implied warranties of merchantability or  **/
/**   fitness for a particular purpose. Ultratec, Inc. does not represent or     **/
/**   warrant that any program is error free or that its use will be             **/
/**   uninterrupted. Ultratec, Inc. shall not be liable for any loss of profit,  **/
/**   loss of business or goodwill, loss of data, interruption in business, nor  **/
/**   for indirect, special, incidental, or consequential damages of any kind    **/
/**   under or arising out of the use or implementation of the example source    **/
/**   code, however caused, whether for breach or warranty, breach or            **/
/**   repudiation of contract, tort, negligence, or otherwise, even if Ultratec, **/
/**   Inc has been advised of the possibility of such a loss. Also Ultratec,     **/
/**   Inc. shall not have any obligation to provide techincal support or         **/
/**   development assistance for the example source code obtained from Ultratec, **/
/**   Inc.                                                                       **/
/**********************************************************************************/
function SimpleMessageBox(strElement, strScreen){
	var elObject, elScreen, bInvalid=false;
	
	if(strElement==null || strElement==undefined || strElement=="" || strScreen==null || strScreen==undefined || strScreen==""){
		bInvalid = true;
	}else{
		elObject = document.getElementById(strElement);
		elScreen = document.getElementById(strScreen);
	}
	
	//this will set the object to null if an invalid element is passed in for either the screen or the actual messagebox
	if(elObject==null || elObject==undefined || elObject=="" || elScreen==null || elScreen==undefined || elScreen==""){
		bInvalid = true;
	}
	
	var elTitle = document.getElementById(strElement + "title");
	if(elTitle==null || elTitle==undefined){
		elTitle = document.createElement("h3");
		elTitle.setAttribute("id",strElement + "title");
		elTitle.setAttribute("class","messageboxtitle");
		elTitle.setAttribute("className","messageboxtitle");
	}
	
	var elError = document.getElementById(strElement + "error");
	if(elError==null || elError==undefined){
		elError = document.createElement("div");
		elError.setAttribute("id",strElement + "error");
		elError.setAttribute("class","messageboxerror");
		elError.setAttribute("className","messageboxerror");
	}else{
		elError.style.display = "none";
	}
	
	var elContent = document.getElementById(strElement + "content");
	if(elContent==null || elContent==undefined){
		elContent = document.createElement("div");
		elContent.setAttribute("id",strElement + "content");
		elContent.setAttribute("class","messageboxcontent");
		elContent.setAttribute("className","messageboxcontent");
	}
	
	var elFooter = document.getElementById(strElement + "footer");
	if(elFooter==null || elFooter==undefined){
		elFooter = document.createElement("div");
		elFooter.setAttribute("id",strElement + "footer");
		elFooter.setAttribute("class","messageboxfooter");
		elFooter.setAttribute("className","messageboxfooter");
	}
	
	//This array will match the validation type to the element that is being validated
	var aCheckKey = new Array();  //This should hold an array with the following array: strFilter, strError, bDisallow -- strFilter is the type of element the textinput field is: email, phone, or intlphone; strError is the id of the element that will display the error message; bDisallow is a flag that determines on whether or not the filter string is an allow string or a disallow string... meaning that if it is false the filter will only allow the characters in the filter string, and vice versa (false will only allow characters that are not in the filter string).
	
	/**********************************************************************************/
	//This function will display the messagebox (lightbox style)
	//	strTitle: the title of the messagebox
	//	strContent: the message in the messagebox
	//	strType: the type of messagebox that gets displayed
	//		supported types: OKOnly, OKCancel, YesNoCancel, YesNo, TextInput, Phone, IntlPhone, Email, TextInputCancel, PhoneCancel, IntlPhoneCancel, EmailCancel
	//	aHandler: this is an array of functions that will handle the button clicks...
	//		NOTE: If there is one button, there should be on function in the array. if
	//			  there are two buttons, there should be two handlers in the array.
	//			  etc... It also assigns the functions to the buttons from left to
	//			  right... ie: for "YesNo", Yes will get the first handler and No will
	//			  get the second handler.
	/**********************************************************************************/
	this.showMessage = (bInvalid)?null:function(strTitle,strContent,strType,aHandler){
				var bTitle = (strTitle!="" && strTitle!=null && strTitle!=undefined)?true:false; //this checks to ensure that a message title was passed in
				var bContent = (strContent!="" && strContent!=null && strContent!=undefined)?true:false;
				var bFooter = false;
				switch(strType.toLowerCase()){//if a valid Type is passed into the function, then the footer will be valid
					case "none":
					case "okonly":
					case "okcancel":
					case "submitcancel":
					case "addcancel":
					case "yesnocancel":
					case "yesno":
					case "textinput":
					case "phone":
					case "intlphone":
					case "email":
					case "textinputcancel":
					case "phonecancel":
					case "intlphonecancel":
					case "emailcancel":
						bFooter = true
						break;
				}
				
				//if there is a title, some content, and a footer to the messagebox, then display the message box...
				if(bTitle && bContent && bFooter){
					elScreen.style.display = 'block'; //display the pagescreen
					elObject.style.display = 'block'; //display the messagebox
					
					//this checks the type to display the textfield if necessary and the proper buttons for the MessageBox.
					var strFooter = "";
					switch(strType.toLowerCase()){
						case "none":
							strFooter = "";
							break;
						
						case "okonly":
							strFooter = "<input class='messageboxbutton' name='btn" + strElement + "1' id='btn" + strElement + "1' type='button' value='OK' onclick='var messagebox = new SimpleMessageBox(\"" + strElement + "\",\"" + strScreen + "\");messagebox.closeMessage();" + ((aHandler)?((aHandler[0])?aHandler[0]+";":""):"") + "' />";
							break;
							
						case "okcancel":
							strFooter = "<input class='messageboxbutton' name='btn" + strElement + "2' id='btn" + strElement + "2' type='button' value='Cancel' onclick='var messagebox = new SimpleMessageBox(\"" + strElement + "\",\"" + strScreen + "\");messagebox.closeMessage();" + ((aHandler)?((aHandler[1])?aHandler[1]+";":""):"") + "' />";
							strFooter += "<input class='messageboxbutton' name='btn" + strElement + "1' id='btn" + strElement + "1' type='button' value='OK' onclick='var messagebox = new SimpleMessageBox(\"" + strElement + "\",\"" + strScreen + "\");messagebox.closeMessage();" + ((aHandler)?((aHandler[0])?aHandler[0]+";":""):"") + "' />";
							break;

						case "addcancel":
							strFooter = "<input class='messageboxbutton' name='btn" + strElement + "2' id='btn" + strElement + "2' type='button' value='Cancel' onclick='var messagebox = new SimpleMessageBox(\"" + strElement + "\",\"" + strScreen + "\");messagebox.closeMessage();" + ((aHandler)?((aHandler[1])?aHandler[1]+";":""):"") + "' />";
							strFooter += "<input class='messageboxbutton' name='btn" + strElement + "1' id='btn" + strElement + "1' type='button' value='Add' onclick='var messagebox = new SimpleMessageBox(\"" + strElement + "\",\"" + strScreen + "\");messagebox.closeMessage();" + ((aHandler)?((aHandler[0])?aHandler[0]+";":""):"") + "' />";
							break;
							
						case "submitcancel":
							strFooter = "<input class='messageboxbutton' name='btn" + strElement + "2' id='btn" + strElement + "2' type='button' value='Cancel' onclick='var messagebox = new SimpleMessageBox(\"" + strElement + "\",\"" + strScreen + "\");messagebox.closeMessage();" + ((aHandler)?((aHandler[1])?aHandler[1]+";":""):"") + "' />";
							strFooter += "<input class='messageboxbutton' name='btn" + strElement + "1' id='btn" + strElement + "1' type='button' value='Submit' onclick='var messagebox = new SimpleMessageBox(\"" + strElement + "\",\"" + strScreen + "\");messagebox.closeMessage();" + ((aHandler)?((aHandler[0])?aHandler[0]+";":""):"") + "' />";
							break;

						case "yesnocancel":
							strFooter = "<input class='messageboxbutton' name='btn" + strElement + "3' id='btn" + strElement + "3' type='button' value='Cancel' onclick='var messagebox = new SimpleMessageBox(\"" + strElement + "\",\"" + strScreen + "\");messagebox.closeMessage();" + ((aHandler)?((aHandler[2])?aHandler[2]+";":""):"") + "' />";
							strFooter += "<input class='messageboxbutton' name='btn" + strElement + "2' id='btn" + strElement + "2' type='button' value='No' onclick='var messagebox = new SimpleMessageBox(\"" + strElement + "\",\"" + strScreen + "\");messagebox.closeMessage();" + ((aHandler)?((aHandler[1])?aHandler[1]+";":""):"") + "' />";
							strFooter += "<input class='messageboxbutton' name='btn" + strElement + "1' id='btn" + strElement + "1' type='button' value='Yes' onclick='var messagebox = new SimpleMessageBox(\"" + strElement + "\",\"" + strScreen + "\");messagebox.closeMessage();" + ((aHandler)?((aHandler[0])?aHandler[0]+";":""):"") + "' />";
							break;
							
						case "yesno":
							strFooter = "<input class='messageboxbutton' name='btn" + strElement + "2' id='btn" + strElement + "2' type='button' value='No' onclick='var messagebox = new SimpleMessageBox(\"" + strElement + "\",\"" + strScreen + "\");messagebox.closeMessage();" + ((aHandler)?((aHandler[1])?aHandler[1]+";":""):"") + "' />";
							strFooter += "<input class='messageboxbutton' name='btn" + strElement + "1' id='btn" + strElement + "1' type='button' value='Yes' onclick='var messagebox = new SimpleMessageBox(\"" + strElement + "\",\"" + strScreen + "\");messagebox.closeMessage();" + ((aHandler)?((aHandler[0])?aHandler[0]+";":""):"") + "' />";
							break;
							
						case "phone": //this provides phone validation on the text input
						case "intlphone": //this provides international phone validation on the text input
							strContent = strContent + "<br/><img src=\"images/contacts.gif\" class=\"messageboxcontacts\" border=\"0\" vspace=\"0\" align=\"right\" onClick=\"showContacts('txtmessagebox1')\" style=\"cursor:pointer; cursor:hand; padding-top: .5em; padding-right: 3.5em; \" /><input class='messageboxphoneinput' name='txt" + strElement + "1' id='txt" + strElement+ "1' type='text' value='' style=\"width: 20em;\" /><br/><br/>";
							strFooter = "<div><input class='messageboxbutton' name='btn" + strElement + "1' id='btn" + strElement + "1' type='button' value='Submit' onclick='var messagebox = new SimpleMessageBox(\"" + strElement + "\",\"" + strScreen + "\");messagebox.closeMessage();" + ((aHandler)?((aHandler[0])?aHandler[0]+";":""):"") + "' /></div>";
							break;

						case "textinput": //this provides no validation on the text input
						case "email": //this provides email validation on the text input
							strContent = strContent + "<br/><input class='messageboxtextinput' name='txt" + strElement + "1' id='txt" + strElement+ "1' type='text' value='' />";
							strFooter = "<input class='messageboxbutton' name='btn" + strElement + "1' id='btn" + strElement + "1' type='button' value='Submit' onclick='var messagebox = new SimpleMessageBox(\"" + strElement + "\",\"" + strScreen + "\");messagebox.closeMessage();" + ((aHandler)?((aHandler[0])?aHandler[0]+";":""):"") + "' />";
							break;
							
						case "phonecancel": //this provides phone validation on the text input and also displays a cancel button
						case "intlphonecancel": //this provides international phone validation on the text input and also displays a cancel button
							strContent = strContent + "<br/><img src=\"images/contacts.gif\" class=\"messageboxcontacts\" border=\"0\" vspace=\"0\" align=\"right\" onClick=\"showContacts('txtmessagebox1')\" style=\"cursor:pointer; cursor:hand; padding-top: .5em; padding-right: 3.5em; \" /><input class='messageboxphoneinput' name='txt" + strElement + "1' id='txt" + strElement+ "1' type='text' value='' style=\"width: 20em;\" /><br/><br/>";
							strFooter = "<input class='messageboxbutton' name='btn" + strElement + "2' id='btn" + strElement + "2' type='button' value='Cancel' onclick='var messagebox = new SimpleMessageBox(\"" + strElement + "\",\"" + strScreen + "\");messagebox.closeMessage();" + ((aHandler)?((aHandler[1])?aHandler[1]+";":""):"") + "' />";
							strFooter += "<input class='messageboxbutton' name='btn" + strElement + "1' id='btn" + strElement + "1' type='button' value='Submit' onclick='var messagebox = new SimpleMessageBox(\"" + strElement + "\",\"" + strScreen + "\");messagebox.closeMessage();" + ((aHandler)?((aHandler[0])?aHandler[0]+";":""):"") + "' />";
							break;						

						case "textinputcancel": //this provides no validation on the text input and also displays a cancel button
						case "emailcancel": //this provides email validation on the text input and also displays a cancel button
							strContent = strContent + "<br/><div style='width:90%; float:left;'><input class='messageboxphoneinput' name='txt" + strElement + "1' id='txt" + strElement+ "1' type='text' value='' /></div><div style='width:10%; float:right; text-align: left;'><img src=\"images/contacts.gif\" border=\"0\" vspace=\"0\" align=\"left\" onClick=\"showContacts('txtmessagebox1')\" style=\"cursor:pointer; cursor:hand; padding-top: 5px; padding-right: 15px;\" /></div><br/><br/>";
							strFooter = "<input class='messageboxbutton' name='btn" + strElement + "2' id='btn" + strElement + "2' type='button' value='Cancel' onclick='var messagebox = new SimpleMessageBox(\"" + strElement + "\",\"" + strScreen + "\");messagebox.closeMessage();" + ((aHandler)?((aHandler[1])?aHandler[1]+";":""):"") + "' />";
							strFooter += "<input class='messageboxbutton' name='btn" + strElement + "1' id='btn" + strElement + "1' type='button' value='Submit' onclick='var messagebox = new SimpleMessageBox(\"" + strElement + "\",\"" + strScreen + "\");messagebox.closeMessage();" + ((aHandler)?((aHandler[0])?aHandler[0]+";":""):"") + "' />";
							break;						
						
						default: //does nothing for now...
							break;
					}
														
					elTitle.innerHTML = strTitle; //display title
					elContent.innerHTML = strContent; //display content
					elFooter.innerHTML = strFooter; //display footer
					
					if(!elObject.hasChildNodes()){
						elObject.appendChild(elTitle);
						elObject.appendChild(elError);
						elObject.appendChild(elContent);
						elObject.appendChild(elFooter);
					}
					
					var iWidth, iHeight;
					if(document.layers || (document.getElementById && !document.all)){
						iWidth = window.outerWidth;
						iHeight = window.outerHeight;
					}else if(document.all){
						iWidth = document.body.clientWidth;
						iHeight = document.body.clientHeight;
					}
					document.body.style.overflow = "hidden";
					
					window.scrollTo(0,0);
					document["bScroll"] = true;
					window.onscroll = function(){if(document["bScroll"]){window.scrollTo(0,0);}};
					window.onresize = function(){setContent();}; //This tells the browser to center the messagebox to the middle of the screen when the browser gets resized
					
					setContent();
					document.body.focus();  //Clear focus
					
					switch(strType.toLowerCase()){
						case "phone": //adds phone validation to the text input field
						case "intlphone": //adds phone validation to the text input field
						case "phonecancel": //adds phone validation to the text input field
						case "intlphonecancel": //adds phone validation to the text input field
						case "email": //adds email validation to the text input field
						case "emailcancel": //adds email validation to the text input field
							var elTextInput = document.getElementById('txt' + strElement + '1'); //this is the input field
							
							if(strType.toLowerCase()=="phone" || strType.toLowerCase()=="phonecancel"){ //validate with phone
								aCheckKey["txt" + strElement + "1"] = new Array("phone", strElement + "error"); //This defines the validation for the messageboxtextinput as phone
							}else if(strType.toLowerCase()=="intlphone" || strType.toLowerCase()=="intlphonecancel"){ //validate with international phone
								aCheckKey["txt" + strElement + "1"] = new Array("intlphone", strElement + "error"); //This defines the validation for the messageboxtextinput as phone
							}else{ //validate with for email address
								aCheckKey["txt" + strElement + "1"] = new Array("email", strElement + "error"); //This defines the validation for the messageboxtextinput as phone
							}
							
							//This statement adds the keyup event to the elements
							if(elTextInput.addEventListener){
								elTextInput.addEventListener('keyup', checkKey, false);
							}else if (elTextInput.attachEvent){
								elTextInput.attachEvent('onkeyup', checkKey);
							}
							
							//The following statement will set the page focus to the messagebox text field
							if(document.getElementById("txt" + strElement + "1")){
								document.getElementById("txt" + strElement + "1").focus();
							}
							break;
																							
						default: //does nothing
							break;
					}
					
				}else{
					alert("Please pass in the proper values to display the messagebox. object.showMessage(strTitle, strContent, strType:OKOnly;OKCancel;YesNoCancel;YesNo, aHandler:1 handler if OKOnly;2 handlers for OKCancel and YesNo;3 handlers for YesNoCancel)");
				}
			};
	
	this.closeMessage = function() {
				document.getElementById(strElement).style.display = "none";
				document.getElementById(strScreen).style.display = "none";
				window.onscroll = function(){
							document["bScroll"] = false;
						};
				document.body.style.overflow = "auto";
				window.onresize = function(){};
			};
	
	//This function determines the window height
	function getWindowHeight() {
		var windowHeight = 0;
		if(typeof(window.innerHeight) == 'number'){
			windowHeight = window.innerHeight;
		}else{
			if(document.documentElement && document.documentElement.clientHeight){
				windowHeight = document.documentElement.clientHeight;
			}else{
				if(document.body && document.body.clientHeight){
					windowHeight = document.body.clientHeight;
				}
			}
		}
		return windowHeight;
	}
	
	//This function places the specified element in the middle of the screen...
	function setContent(){
		var iWidth, iHeight;
		if(self.innerHeight){// all except Explorer
			iWidth = self.innerWidth + window.scrollMaxX;
			iHeight = self.innerHeight + window.scrollMaxY;
		}else if(document.documentElement && document.documentElement.clientHeight){// Internet Explorer 6 Strict Mode
		iWidth = document.documentElement.clientWidth;
			iHeight = document.documentElement.clientHeight;
		}else if (document.body){// other Explorers
			iWidth = document.body.clientWidth;
			iHeight = document.body.clientHeight;
		}
		
		
        if (window.innerHeight && window.scrollMaxY) {
            iWidth = document.body.scrollWidth;
            iHeight = window.innerHeight + window.scrollMaxY;
        } else if (document.body.scrollHeight > document.body.offsetHeight) {
            // all but explorer mac
            iWidth = document.body.scrollWidth;
            iHeight = document.body.scrollHeight;
        } else {
            // explorer mac...would also work in explorer 6 strict, mozilla and safari
            iWidth = document.body.offsetWidth;
            iHeight = document.body.offsetHeight;
        }
		
		//set the element screen to fill the entire window...
		elScreen.style.width = iWidth;
		elScreen.style.height = iHeight;
		
		centerObject();
		
		if(parseInt(elObject.style.top) > 100){
			elObject.style.top = '10em'; //this will force the application to position the element 100px from the top margin. if the base font is 10px
			elObject.style.marginTop = '0px';
		}else if(parseInt(elObject.style.top) < 10){
			elObject.style.top = '1em'; //this will force the application to always give the element a 10px top margin. if the base font is 10px
		}
		
	}
	
	//This centers an object in the browser window.
	function centerObject(){
	
		var iWidth, iHeight;
		if(self.innerHeight){// all except Explorer
			iWidth = self.innerWidth;
			iHeight = self.innerHeight;
		}else if(document.documentElement && document.documentElement.clientHeight){// Explorer 6 Strict Mode
			iWidth = document.documentElement.clientWidth;
			iHeight = document.documentElement.clientHeight;
		}else if (document.body){// other Explorers
			iWidth = document.body.clientWidth;
			iHeight = document.body.clientHeight;
		}
		
		if(iHeight > 0){
			//This moves the messagebox to the center of the screen
			var iConHeight = elObject.offsetHeight;
			var iConTop = (iHeight - iConHeight) / 2;
			if(iConTop<0){
				iConTop = 0;
			}
			elObject.style.top = iConTop + 'px';
	
			var iConWidth = elObject.offsetWidth;
			var iConLeft = iConWidth / 2 * -1;
			elObject.style.marginLeft = iConLeft + 'px';
			}
	}
	
	/**********************************************************************************/
	/** Key Press Functions                                                          **/
	/**********************************************************************************/
	//this function shows which key was pressed
	function checkKey(event){
		event = (!event)?window.event:event;
		var iChar = (event.which)?event.which:event.keyCode;
		if(iChar==13 && document.getElementById("btn" + strElement + "1")){//if the enter key is pressed (character 13) and a message box is displayed that has an input field, then do the following...
			document.getElementById("btn" + strElement + "1").click(); //click the first button...
		}else if(iChar==16 || iChar==17 || iChar==18 || iChar==20 || iChar==144 || iChar==27 || iChar==37 || iChar==38 || iChar==39 || iChar==40 || iChar==45 || iChar==46 || iChar==36 || iChar==35 || iChar==33 || iChar==34 || iChar==112 || iChar==113 || iChar==114 || iChar==115 || iChar==116 || iChar==117 || iChar==118 || iChar==119 || iChar==120 || iChar==121 || iChar==122 || iChar==123 || iChar==224){
			//this ensures that the only characters that will trigger the function are the standard characters... IE: 1-0, a-z, and symbols
		}else{ //process the validation for the element...
			var element = (event.srcElement)?event.srcElement:event.target; //this returns the element that heard the event that triggered this function
			
			var strNew = "";
			var strFilter = aCheckKey[element.name.toLowerCase()][0];
			var strError = aCheckKey[element.name.toLowerCase()][1];
			var bDisallow = aCheckKey[element.name.toLowerCase()][2];
			
			switch(strFilter.toLowerCase()){
				case "email":
					strNew = emailOnly(element.value, strError);
					break;
					
				case "phone":
					//the if statement below is used to strip the '-' that is automatically placed into the string in the event that the backspace button was selected and that is the last character in the string
					if(element.value.charAt(element.value.length-1) == '-'){
						element.value = element.value.substr(0,element.value.length-1);
					}
					strNew = formatPhone(element.value, strError);
					break;
					
				case "intlphone":
					//the if statement below is used to strip the '-' that is automatically placed into the string in the event that the backspace button was selected and that is the last character in the string
					if(element.value.charAt(element.value.length-1) == '-'){
						element.value = element.value.substr(0,element.value.length-1);
					}
					strNew = formatIntlPhone(element.value, strError);
					break;
					
				default:
					strNew = nonSQLSpecialCharacters(element.value, strError);
					break;
			}
			element.value = strNew;
		}
	}
	
	//This function strips all sql special characters
	function nonSQLSpecialCharacters(strCheck,strError){
		var strFilter = "!@#$%^&*()_";
		return filterString(strCheck, strFilter, true, strError);
	}
	
	//This function returns all numbers from a string and strips everything else out...
	function numbersOnly(strCheck,strError){
		var strFilter = "0123456789";
		return filterString(strCheck, strFilter, false, strError);
	}
	
	//This function returns valid email characters from a string and strips everything else out...
	function emailOnly(strCheck, strError){
		var strFilter = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-.@";
		return filterString(strCheck, strFilter, false, strError);
	}
	
	//This function returns valid SQL Special characters from a string and strips everything else out...
	function SQLSpecialCharactersOnly(strCheck, strError){
		var strFilter = "!%^[]";
		return filterString(strCheck, strFilter, false, strError);
	}
	
	//This function returns a string that filters out all characters except the characters in the filter...
	// If bDisallow is set to "true", then the function will allow all characters except for the characters in strFilter
	// strError is the element that will display any error for the given filterString call
	function filterString(strCheck, strFilter, bDisallow, strError){
		var strReturn = "";
		var bError = false;
		
		for(var i=0; i<strCheck.length && !bError; i++){
			if(strError!=undefined && strError!=null && strError!=""){
				document.getElementById(strError).innerHTML = "";
				document.getElementById(strError).style.display = "none";
			}
			if(strFilter.indexOf(strCheck.charAt(i))>=0 && !bDisallow){
				strReturn += strCheck.charAt(i);
			}else if(strFilter.indexOf(strCheck.charAt(i))<0 && bDisallow){
				strReturn += strCheck.charAt(i);
			}else{
				if(strError!=null && strError!=undefined && strError!=""){
					document.getElementById(strError).style.display = "block";
					document.getElementById(strError).innerHTML = "The character entered, '" + strCheck.charAt(i) + "', is not allowed, so it was removed.";
				}
			}
		}
		return strReturn;
	}
	
	//This function formats a string into XXX-XXX-XXXX
	function formatPhone(strPhone, strError){
		var strCurrent = numbersOnly(strPhone, strError), strNew = "", strStart = "", strMiddle = "", strEnd = "";
		if(strCurrent.length>10){ //NOTE: This forces the phone number to be only 10 digits long...
			strCurrent = strCurrent.substr(0,10);
		}
		
		if(strError!=null && strError!=undefined && strError!=""){ //only try to display an error message if there is a place to display the error
			if(strCurrent.charAt(0)=="0" || strCurrent.charAt(0)=="1"){ //us phone numbers can't start with a 0 or 1
				document.getElementById(strError).style.display = "block";
				document.getElementById(strError).innerHTML = "US phone numbers do not start with 0 or 1. Please enter a valid US phone number.";
			}else{
				document.getElementById(strError).innerHTML = "";
				document.getElementById(strError).style.display = "none";
			}
		}
		
		var iCurrentLength = strCurrent.length;
		if(iCurrentLength<=3){
			strNew = strCurrent;
		}else if(iCurrentLength>3 && iCurrentLength<=7){
			strStart = strCurrent.substr(0,3);
			if(iCurrentLength>3){
				strEnd = strCurrent.substr(3);
			}
			strNew = strStart + "-" + strEnd
		}else if(iCurrentLength>7 && iCurrentLength<=10){
			strStart = strCurrent.substr(0,3);
			strMiddle = strCurrent.substr(3,3);
			strEnd = strCurrent.substr(6);
			strNew = strStart + "-" + strMiddle + "-" + strEnd;
		}
		
		return strNew;
	}
	
	//This function formats a string into XXX-XXX-XXXX if it is 10 digits or less, otherwise it doesn't format the string
	function formatIntlPhone(strPhone, strError){
		var strCurrent = numbersOnly(strPhone, strError), strNew = "", strStart = "", strMiddle = "", strEnd = "";
		if(strCurrent.length>20){ //NOTE: This forces the phone number to be only 10 digits long...
			strCurrent = strCurrent.substr(0,20);
		}
		
		var iCurrentLength = strCurrent.length;
		if(iCurrentLength<=3){
			strNew = strCurrent;
		}else if(iCurrentLength>3 && iCurrentLength<=7){
			strStart = strCurrent.substr(0,3);
			if(iCurrentLength>3){
				strEnd = strCurrent.substr(3);
			}
			strNew = strStart + "-" + strEnd
		}else if(iCurrentLength>7 && iCurrentLength<=10){
			strStart = strCurrent.substr(0,3);
			strMiddle = strCurrent.substr(3,3);
			strEnd = strCurrent.substr(6);
			strNew = strStart + "-" + strMiddle + "-" + strEnd;
		}else{
			strNew = strCurrent;
		}
		
		return strNew;
	}
}
