//This script library copyright Alan Hearnshaw of Savannah Software 
//http://www.savannahsoftware.com.
//No portion of this may be used or distributed
//without the express consent of the intellectual property owner.

function ValidateTextBox(rtxtTextBox, nMinLength)
	{
		if(rtxtTextBox.value=='')
			{
				alert("Invalid data - you will be returned to the form where the invalid data will be highlighted...")
				rtxtTextBox.select()
				rtxtTextBox.focus()
				return false
			}
		if(rtxtTextBox.value.length<nMinLength)
			{
				alert("Invalid data - the field requires a minimum of " + nMinLength + " characters. You will be returned to the form where the invalid data will be highlighted...")
				rtxtTextBox.select()
				rtxtTextBox.focus()
				return false
			}
		return true
	}
	
function ValidateTextBoxEmail(rtxtTextBox)
	{
		if(!isEmail(rtxtTextBox.value))
			{
				alert("Invalid data - this does not appear to be a valid Email address. You will be returned to the form where the invalid data will be highlighted...")
				rtxtTextBox.select()
				rtxtTextBox.focus()
				return false
			}
		return true
	}
	
function ValidateTextBoxNumeric(rtxtTextBox, bAllowNulls, sExtraValidChars, nMinLength)
	{
		//This function will validate that the contents of the referenced text 
		//is composed of valid numeric characters.
		//You can also pass a string containing any extra characters you would
		//like to be considered valid, otherwise pass an empty string.
		
		if(rtxtTextBox.value=='' && !bAllowNulls)
			{
				alert("Invalid data - you have not filled in a required field. You will be returned to the form where the invalid data will be highlighted.")
				rtxtTextBox.select()
				rtxtTextBox.focus()
				return false
			}
			
		if(rtxtTextBox.value.length<nMinLength && !bAllowNulls)
			{
				alert("Invalid data - the field requires a minimum of " + nMinLength + " characters. You will be returned to the form where the invalid data will be highlighted...")
				rtxtTextBox.select()
				rtxtTextBox.focus()
				return false
			}

		var sValidString="-0123456789."
		sValidString=sValidString.concat(sExtraValidChars)
		for(var n=0;n<rtxtTextBox.value.length;n++)
			{
				if(sValidString.indexOf(rtxtTextBox.value.charAt(n))==-1)
					{
						alert("Invalid data - this must contain only numeric characters. You will be returned to the form where the invalid data will be highlighted.")
						rtxtTextBox.select()
						rtxtTextBox.focus()
						return false
					}
			}
		return true
	}
	
function ValidateTextBoxTrueNumber(rtxtTextBox, bAllowNulls, lMinValue, lMaxValue)
	{
		//This function will check that the referenced textbox contains a true number (not just numeric characters with any extras)
		if(rtxtTextBox.value=='' && !bAllowNulls)
			{
				alert("Invalid data - you will be returned to the form where the invalid data will be highlighted...")
				rtxtTextBox.select()
				rtxtTextBox.focus()
				return false
			}
			
		if(isNaN(rtxtTextBox.value))
			{
				alert("Invalid data - this field requires a number. You will be returned to the form where the invalid data will be highlighted...")
				rtxtTextBox.select()
				rtxtTextBox.focus()
				return false
			}
			
		//Check for Min Value
		if(!isNaN(lMinValue)&&rtxtTextBox.value<lMinValue&&rtxtTextBox.value!='')
			{
				alert("Invalid data - the number must be at least " + lMinValue + ". You will be returned to the form where the invalid data will be highlighted...")
				rtxtTextBox.focus()
				rtxtTextBox.select()
				return false
			}
					
		if(!isNaN(lMaxValue)&&rtxtTextBox.value>lMaxValue&&rtxtTextBox.value!='')
			{
				alert("Invalid data - the number must be a maximum of " + lMaxValue + ". You will be returned to the form where the invalid data will be highlighted...")
				rtxtTextBox.focus()
				rtxtTextBox.select()
				return false
			}	
		return true	
	}
			
function ValidateTextBoxAlpha(rtxtTextBox, bAllowNulls, sExtraValidChars, nMinLength)
	{
		//This function will validate that the contents of the referenced text 
		//box contains a valid Alpha value.
		//You can also pass a string containing any extra characters you would
		//like to be considered valid, otherwise pass an empty string.
		
		if(rtxtTextBox.value.length<nMinLength && !bAllowNulls)
			{
				alert("Invalid data - the field requires a minimum of " + nMinLength + " characters. You will be returned to the form where the invalid data will be highlighted...")
				rtxtTextBox.select()
				rtxtTextBox.focus()
				return false
			}
		if(rtxtTextBox.value=='' && !bAllowNulls)
			{
				alert("Invalid data - you have not filled in a required field. You will be returned to the form where the invalid data will be highlighted.")
				rtxtTextBox.select()
				rtxtTextBox.focus()
				
			}
		var sValidString="QWERTYUIOPASDFGHJKLZXCVBNM"
		sValidString=sValidString.concat(sExtraValidChars)

		for(var n=0;n<rtxtTextBox.value.length;n++)
			{
				if(sValidString.indexOf(rtxtTextBox.value.charAt(n).toUpperCase())==-1)
					{
						alert("Invalid data - this value needs to be characters only (not numbers). You will be returned to the form where the invalid data will be highlighted.")
						rtxtTextBox.select()
						rtxtTextBox.focus()
						return false
					}
			}
		return true
	}
	
function ValidateComboBox(rcboComboBox)
	{
		if(rcboComboBox.options[rcboComboBox.selectedIndex].value=='...')
			{
				alert("Invalid data - you will be returned to the form where the invalid data will be highlighted.")
				rcboComboBox.focus()
				return false
			}
		return true	
	}
function ValidateRadioButton(roptRadioButton, sHint)
	{
		//The hint is supplied so that the message can inform the user which option
		//button needs to be filled in
		for(var n=0;n<roptRadioButton.length;n++)
			{
				if(roptRadioButton[n].checked)
					{
						return true
					}
			}
		alert("Invalid data - you must select one from the radio buttons denoting " + sHint + ".")
		roptRadioButton[0].focus();
		return false
	}
	
function ValidateDate(rtxtTextBox, bAllowEmpty, vnMinYear, vnMaxYear, bConvertToAmerican)
	{
		//This function will check that the value contained in the referenced
		//box is a valid date. Must be passed in English format dd/mm/yyyy.
		//If bConvertToAmerican is true then the output will be in American format.
		var sDate=rtxtTextBox.value
		var bValid=true
		var nDay, nMonth, nYear, nStep1Pos, nStep2Pos, bStep1Found, bStep2Found
		var bLeapYear
		
		//Check if empty
		if(bAllowEmpty && rtxtTextBox.value=='')
			{
				return true
			}
			
		//Get position of Seperators
		for(var n=0;n<sDate.length;n++)
			{
				if(sDate.charAt(n)=="/")
					{
						if(!bStep1Found && !bStep2Found)
							{
								nStep1Pos=n
								bStep1Found=true
							}
						else
							{
								nStep2Pos=n
								bStep2Found=true
							}
					}
			}
		if(!(nStep1Pos>=1 && nStep1Pos<=2 && nStep2Pos>=3 && nStep2Pos<=5))
			{
				bValid=false
			}
			
		//Check that a 4 digit year has been passed
		if(sDate.substring(nStep2Pos+1).length<4)
			{
				bValid=false
			}
			
		//Get the date values
		var sTemp=sDate.substring(0, nStep1Pos)
		if(sTemp.charAt(0)=="0"){sTemp=sDate.substring(1, nStep1Pos)}
		nDay=parseInt(sTemp)
		sTemp=sDate.substring(nStep1Pos+1, nStep2Pos)
		if(sTemp.charAt(0)=="0"){sTemp=sDate.substring(nStep1Pos+2, nStep2Pos)}
		nMonth=parseInt(sTemp)
		nYear=parseInt(sDate.substring(nStep2Pos+1))
		
		if(isNaN(nDay)||isNaN(nMonth)||isNaN(nYear)){bValid=false}
			
		//Check that the date values are valid
		if(nDay>31||nDay<1){bValid=false}
		if(nMonth>12||nMonth<1){bValid=false}
		if(nYear>9999||nYear<1000){bValid=false}
		
		//Check day amount valid for month
		if((nMonth==9||nMonth==4||nMonth==6||nMonth==11||nMonth==2) && nDay>30){bValid=false}
		
		//Check for leap year
		if(parseFloat(nYear/4)>parseInt(nYear/4))
			{
				bLeapYear=false
			}
		else
			{
				bLeapYear=true
				if(parseFloat(nYear/100)==parseInt(nYear/100))
					{
						if(parseFloat(nYear/400)==parseInt(nYear/400))
							{
								bLeapYear=true
							}
						else
							{
								bLeapYear=false
							}
					}
			}
		//Check for valid day in February in leap year
		if(nMonth==2 && bLeapYear && nDay >29){bValid=false}
		if(nMonth==2 && !bLeapYear && nDay >28){bValid=false}

		if (bValid==false)
			{
				alert("Invalid data - the date must be a valid date in the format 'dd/mm/yyyy'.")
				rtxtTextBox.select()
				rtxtTextBox.focus()
				return false
			}
		else
			{
				//Check that the year is within the bounds passed
				if(!isNaN(vnMinYear)&&nYear<vnMinYear)
					{
						alert("Invalid data - the year must be greater than " + vnMinYear + ". You will be returned to the form where the invalid data will be highlighted...")
						rtxtTextBox.select()
						rtxtTextBox.focus()
						return false
					}
				if(!isNaN(vnMaxYear)&&nYear>vnMaxYear)
					{
						alert("Invalid data - the year must be less than " + vnMaxYear + ". You will be returned to the form where the invalid data will be highlighted...")
						rtxtTextBox.focus()
						rtxtTextBox.select()
						return false
					}
				if(bConvertToAmerican)
					{	
						rtxtTextBox.value=nMonth + "/" + nDay + "/" + nYear
					}
				else
					{
						rtxtTextBox.value=nDay+"/"+nMonth+"/"+nYear
					}
				return true
			}
	}

function ValidateDateAmerican(rtxtTextBox, bAllowEmpty, vnMinYear, vnMaxYear, bConvertToEnglish)
	{
		//This function will check that the value contained in the referenced
		//box is a valid date. Must be passed in American format mm/dd/yyyy.
		//If bConvertToEnglish is true then the output will be in the proper format.
		var sDate=rtxtTextBox.value
		var bValid=true
		var nDay, nMonth, nYear, nStep1Pos, nStep2Pos, bStep1Found, bStep2Found
		var bLeapYear
		
		//Check if empty
		if(bAllowEmpty && rtxtTextBox.value=='')
			{
				return true
			}
			
		//Get position of Seperators
		for(var n=0;n<sDate.length;n++)
			{
				if(sDate.charAt(n)=="/")
					{
						if(!bStep1Found && !bStep2Found)
							{
								nStep1Pos=n
								bStep1Found=true
							}
						else
							{
								nStep2Pos=n
								bStep2Found=true
							}
					}
			}
		if(!(nStep1Pos>=1 && nStep1Pos<=2 && nStep2Pos>=3 && nStep2Pos<=5))
			{
				bValid=false
			}
			
		//Check that a 4 digit year has been passed
		if(sDate.substring(nStep2Pos+1).length<4)
			{
				bValid=false
			}
			
		//Get the date values
		var sTemp=sDate.substring(0, nStep1Pos)
		if(sTemp.charAt(0)=="0"){sTemp=sDate.substring(1, nStep1Pos)}
		nMonth=parseInt(sTemp)
		sTemp=sDate.substring(nStep1Pos+1, nStep2Pos)
		if(sTemp.charAt(0)=="0"){sTemp=sDate.substring(nStep1Pos+2, nStep2Pos)}
		nDay=parseInt(sTemp)
		nYear=parseInt(sDate.substring(nStep2Pos+1))
		
		if(isNaN(nDay)||isNaN(nMonth)||isNaN(nYear)){bValid=false}
			
		//Check that the date values are valid
		if(nDay>31||nDay<1){bValid=false}
		if(nMonth>12||nMonth<1){bValid=false}
		if(nYear>9999||nYear<1000){bValid=false}
		
		//Check day amount valid for month
		if((nMonth==9||nMonth==4||nMonth==6||nMonth==11||nMonth==2) && nDay>30){bValid=false}
		
		//Check for leap year
		if(parseFloat(nYear/4)>parseInt(nYear/4))
			{
				bLeapYear=false
			}
		else
			{
				bLeapYear=true
				if(parseFloat(nYear/100)==parseInt(nYear/100))
					{
						if(parseFloat(nYear/400)==parseInt(nYear/400))
							{
								bLeapYear=true
							}
						else
							{
								bLeapYear=false
							}
					}
			}
		//Check for valid day in February in leap year
		if(nMonth==2 && bLeapYear && nDay >29){bValid=false}
		if(nMonth==2 && !bLeapYear && nDay >28){bValid=false}

		if (bValid==false)
			{
				alert("Invalid data - the date must be a valid date in the format 'mm/dd/yyyy'.")
				rtxtTextBox.select()
				rtxtTextBox.focus()
				return false
			}
		else
			{
				//Check that the year is within the bounds passed
				if(!isNaN(vnMinYear)&&nYear<vnMinYear)
					{
						alert("Invalid data - the year must be greater than " + vnMinYear + ". You will be returned to the form where the invalid data will be highlighted...")
						rtxtTextBox.select()
						rtxtTextBox.focus()
						return false
					}
				if(!isNaN(vnMaxYear)&&nYear>vnMaxYear)
					{
						alert("Invalid data - the year must be less than " + vnMaxYear + ". You will be returned to the form where the invalid data will be highlighted...")
						rtxtTextBox.focus()
						rtxtTextBox.select()
						return false
					}
				if(bConvertToEnglish)
					{	
						rtxtTextBox.value=nDay+"/"+nMonth+"/"+nYear
					}
				else
					{
						rtxtTextBox.value=nMonth + "/" + nDay + "/" + nYear
					}
				return true
			}
	}

function ConvertSingleQuotes(sText)
	{
		//This function will convert all instances of single quotes in the passed string
		//to double quotes for database update.
		return sText.replace(/'/g, "''")
	}
function ConvertAllSingleQuotesInForm(frmForm)
	{
		//This function is passed a reference to the form and it iterates
		//through all controls on that form that are textbox or textarea
		//and replaces single quotes with double (for database update).
		for(var n=0;n<frmForm.length;n++)
			{
				if(frmForm[n].type=="text"||frmForm[n].type=="textarea")
					{
						frmForm[n].value=ConvertSingleQuotes(frmForm[n].value)
					}
			}
	}

function isEmail(sEmail) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
	 var tempStr = "a";
	 var tempReg = new RegExp(tempStr);
	 if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
	 return (sEmail.indexOf(".") > 2) && (sEmail.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(sEmail) && r2.test(sEmail));
}

//Array for validating area codes against states
var StatesArray=new Array();

StatesArray['201']='NJ'
StatesArray['202']='DC'
StatesArray['203']='CT'
StatesArray['204']='MB'
StatesArray['205']='AL'
StatesArray['206']='WA'
StatesArray['207']='ME'
StatesArray['208']='ID'
StatesArray['209']='CA'
StatesArray['210']='TX'
StatesArray['211']='--'
StatesArray['212']='NY'
StatesArray['213']='CA'
StatesArray['214']='TX'
StatesArray['215']='PA'
StatesArray['216']='OH'
StatesArray['217']='IL'
StatesArray['218']='MN'
StatesArray['219']='IN'
StatesArray['224']='IL'
StatesArray['225']='LA'
StatesArray['228']='MS'
StatesArray['229']='GA'
StatesArray['231']='MI'
StatesArray['234']='OH'
StatesArray['236']='VA'
StatesArray['239']='FL'
StatesArray['240']='MD'
StatesArray['242']='--'
StatesArray['246']='--'
StatesArray['248']='MI'
StatesArray['249']='MD'
StatesArray['250']='BC'
StatesArray['251']='AL'
StatesArray['252']='NC'
StatesArray['253']='WA'
StatesArray['254']='TX'
StatesArray['256']='AL'
StatesArray['260']='IN'
StatesArray['262']='WI'
StatesArray['264']='--'
StatesArray['267']='PA'
StatesArray['268']='--'
StatesArray['269']='MI'
StatesArray['270']='KY'
StatesArray['276']='VA'
StatesArray['278']='MI'
StatesArray['280']='MD'
StatesArray['281']='TX'
StatesArray['282']='IL'
StatesArray['283']='OH'
StatesArray['284']='--'
StatesArray['289']='ON'
StatesArray['301']='MD'
StatesArray['302']='DE'
StatesArray['303']='CO'
StatesArray['304']='WV'
StatesArray['305']='FL'
StatesArray['306']='SK'
StatesArray['307']='WY'
StatesArray['308']='NE'
StatesArray['309']='IL'
StatesArray['310']='CA'
StatesArray['311']='--'
StatesArray['312']='IL'
StatesArray['313']='MI'
StatesArray['314']='MO'
StatesArray['315']='NY'
StatesArray['316']='KS'
StatesArray['317']='IN'
StatesArray['318']='LA'
StatesArray['319']='IA'
StatesArray['320']='MN'
StatesArray['321']='FL'
StatesArray['323']='CA'
StatesArray['325']='TX'
StatesArray['327']='KY'
StatesArray['330']='OH'
StatesArray['331']='IL'
StatesArray['334']='AL'
StatesArray['336']='NC'
StatesArray['337']='LA'
StatesArray['339']='MA'
StatesArray['340']='--'
StatesArray['341']='CA'
StatesArray['345']='--'
StatesArray['347']='NY'
StatesArray['351']='MA'
StatesArray['352']='FL'
StatesArray['353']='WI'
StatesArray['354']='--'
StatesArray['358']='PA'
StatesArray['360']='WA'
StatesArray['361']='TX'
StatesArray['369']='CA'
StatesArray['380']='OH'
StatesArray['381']='VA'
StatesArray['383']='ME'
StatesArray['385']='UT'
StatesArray['386']='FL'
StatesArray['401']='RI'
StatesArray['402']='NE'
StatesArray['403']='AB'
StatesArray['404']='GA'
StatesArray['405']='OK'
StatesArray['406']='MT'
StatesArray['407']='FL'
StatesArray['408']='CA'
StatesArray['409']='TX'
StatesArray['410']='MD'
StatesArray['411']='--'
StatesArray['412']='PA'
StatesArray['413']='MA'
StatesArray['414']='WI'
StatesArray['415']='CA'
StatesArray['416']='ON'
StatesArray['417']='MO'
StatesArray['418']='QC'
StatesArray['419']='OH'
StatesArray['420']='WI'
StatesArray['423']='TN'
StatesArray['424']='CA'
StatesArray['425']='WA'
StatesArray['430']='TX'
StatesArray['432']='TX'
StatesArray['434']='VA'
StatesArray['435']='UT'
StatesArray['438']='QC'
StatesArray['440']='OH'
StatesArray['441']='--'
StatesArray['442']='CA'
StatesArray['443']='MD'
StatesArray['445']='PA'
StatesArray['450']='QC'
StatesArray['456']='--'
StatesArray['464']='IL'
StatesArray['469']='TX'
StatesArray['470']='GA'
StatesArray['473']='--'
StatesArray['475']='CT'
StatesArray['478']='GA'
StatesArray['479']='AR'
StatesArray['480']='AZ'
StatesArray['484']='PA'
StatesArray['500']='--'
StatesArray['501']='AR'
StatesArray['502']='KY'
StatesArray['503']='OR'
StatesArray['504']='LA'
StatesArray['505']='NM'
StatesArray['506']='NB'
StatesArray['507']='MN'
StatesArray['508']='MA'
StatesArray['509']='WA'
StatesArray['510']='CA'
StatesArray['511']='--'
StatesArray['512']='TX'
StatesArray['513']='OH'
StatesArray['514']='QC'
StatesArray['515']='IA'
StatesArray['516']='NY'
StatesArray['517']='MI'
StatesArray['518']='NY'
StatesArray['519']='ON'
StatesArray['520']='AZ'
StatesArray['530']='CA'
StatesArray['540']='VA'
StatesArray['541']='OR'
StatesArray['546']='MI'
StatesArray['551']='NJ'
StatesArray['555']='--'
StatesArray['557']='MO'
StatesArray['559']='CA'
StatesArray['561']='FL'
StatesArray['562']='CA'
StatesArray['563']='IA'
StatesArray['564']='WA'
StatesArray['567']='OH'
StatesArray['570']='PA'
StatesArray['571']='VA'
StatesArray['573']='MO'
StatesArray['574']='IN'
StatesArray['580']='OK'
StatesArray['585']='NY'
StatesArray['586']='MI'
StatesArray['590']='--'
StatesArray['600']='--'
StatesArray['601']='MS'
StatesArray['602']='AZ'
StatesArray['603']='NH'
StatesArray['604']='BC'
StatesArray['605']='SD'
StatesArray['606']='KY'
StatesArray['607']='NY'
StatesArray['608']='WI'
StatesArray['609']='NJ'
StatesArray['610']='PA'
StatesArray['611']='--'
StatesArray['612']='MN'
StatesArray['613']='ON'
StatesArray['614']='OH'
StatesArray['615']='TN'
StatesArray['616']='MI'
StatesArray['617']='MA'
StatesArray['618']='IL'
StatesArray['619']='CA'
StatesArray['620']='KS'
StatesArray['623']='AZ'
StatesArray['626']='CA'
StatesArray['627']='CA'
StatesArray['628']='CA'
StatesArray['630']='IL'
StatesArray['631']='NY'
StatesArray['636']='MO'
StatesArray['641']='IA'
StatesArray['646']='NY'
StatesArray['647']='ON'
StatesArray['649']='--'
StatesArray['650']='CA'
StatesArray['651']='MN'
StatesArray['657']='CA'
StatesArray['660']='MO'
StatesArray['661']='CA'
StatesArray['662']='MS'
StatesArray['664']='--'
StatesArray['669']='CA'
StatesArray['670']='MP'
StatesArray['671']='GU'
StatesArray['678']='GA'
StatesArray['679']='MI'
StatesArray['682']='TX'
StatesArray['684']='--'
StatesArray['689']='FL'
StatesArray['700']='--'
StatesArray['701']='ND'
StatesArray['702']='NV'
StatesArray['703']='VA'
StatesArray['704']='NC'
StatesArray['705']='ON'
StatesArray['706']='GA'
StatesArray['707']='CA'
StatesArray['708']='IL'
StatesArray['709']='NF'
StatesArray['710']='--'
StatesArray['711']='--'
StatesArray['712']='IA'
StatesArray['713']='TX'
StatesArray['714']='CA'
StatesArray['715']='WI'
StatesArray['716']='NY'
StatesArray['717']='PA'
StatesArray['718']='NY'
StatesArray['719']='CO'
StatesArray['720']='CO'
StatesArray['724']='PA'
StatesArray['727']='FL'
StatesArray['731']='TN'
StatesArray['732']='NJ'
StatesArray['734']='MI'
StatesArray['737']='TX'
StatesArray['740']='OH'
StatesArray['747']='CA'
StatesArray['752']='CA'
StatesArray['754']='FL'
StatesArray['757']='VA'
StatesArray['758']='--'
StatesArray['760']='CA'
StatesArray['763']='MN'
StatesArray['764']='CA'
StatesArray['765']='IN'
StatesArray['767']='--'
StatesArray['770']='GA'
StatesArray['772']='FL'
StatesArray['773']='IL'
StatesArray['774']='MA'
StatesArray['775']='NV'
StatesArray['778']='BC'
StatesArray['780']='AB'
StatesArray['781']='MA'
StatesArray['784']='--'
StatesArray['785']='KS'
StatesArray['786']='FL'
StatesArray['787']='PR'
StatesArray['800']='--'
StatesArray['801']='UT'
StatesArray['802']='VT'
StatesArray['803']='SC'
StatesArray['804']='VA'
StatesArray['805']='CA'
StatesArray['806']='TX'
StatesArray['807']='ON'
StatesArray['808']='HI'
StatesArray['809']='--'
StatesArray['810']='MI'
StatesArray['811']='--'
StatesArray['812']='IN'
StatesArray['813']='FL'
StatesArray['814']='PA'
StatesArray['815']='IL'
StatesArray['816']='MO'
StatesArray['817']='TX'
StatesArray['818']='CA'
StatesArray['819']='QC'
StatesArray['822']='--'
StatesArray['828']='NC'
StatesArray['830']='TX'
StatesArray['831']='CA'
StatesArray['832']='TX'
StatesArray['833']='--'
StatesArray['835']='PA'
StatesArray['836']='FL'
StatesArray['843']='SC'
StatesArray['844']='--'
StatesArray['845']='NY'
StatesArray['847']='IL'
StatesArray['848']='NJ'
StatesArray['850']='FL'
StatesArray['855']='--'
StatesArray['856']='NJ'
StatesArray['857']='MA'
StatesArray['858']='CA'
StatesArray['859']='KY'
StatesArray['860']='CT'
StatesArray['861']='FL'
StatesArray['862']='NJ'
StatesArray['863']='FL'
StatesArray['864']='SC'
StatesArray['865']='TN'
StatesArray['866']='--'
StatesArray['867']='YT'
StatesArray['868']='--'
StatesArray['869']='--'
StatesArray['870']='AR'
StatesArray['872']='IL'
StatesArray['876']='--'
StatesArray['877']='--'
StatesArray['878']='PA'
StatesArray['880']='--'
StatesArray['881']='--'
StatesArray['882']='--'
StatesArray['888']='--'
StatesArray['900']='--'
StatesArray['901']='TN'
StatesArray['902']='NS'
StatesArray['903']='TX'
StatesArray['904']='FL'
StatesArray['905']='ON'
StatesArray['906']='MI'
StatesArray['907']='AK'
StatesArray['908']='NJ'
StatesArray['909']='CA'
StatesArray['910']='NC'
StatesArray['911']='--'
StatesArray['912']='GA'
StatesArray['913']='KS'
StatesArray['914']='NY'
StatesArray['915']='TX'
StatesArray['916']='CA'
StatesArray['917']='NY'
StatesArray['918']='OK'
StatesArray['919']='NC'
StatesArray['920']='WI'
StatesArray['925']='CA'
StatesArray['928']='AZ'
StatesArray['931']='TN'
StatesArray['935']='CA'
StatesArray['936']='TX'
StatesArray['937']='OH'
StatesArray['939']='PR'
StatesArray['940']='TX'
StatesArray['941']='FL'
StatesArray['947']='MI'
StatesArray['949']='CA'
StatesArray['951']='CA'
StatesArray['952']='MN'
StatesArray['954']='FL'
StatesArray['956']='TX'
StatesArray['957']='NM'
StatesArray['959']='CT'
StatesArray['969']='MD'
StatesArray['970']='CO'
StatesArray['971']='OR'
StatesArray['972']='TX'
StatesArray['973']='NJ'
StatesArray['975']='MO'
StatesArray['976']='--'
StatesArray['978']='MA'
StatesArray['979']='TX'
StatesArray['980']='NC'
StatesArray['984']='NC'
StatesArray['985']='LA'
StatesArray['989']='MI'
StatesArray['999']='--'

function ValidateAreaCodeForState(txtAreaCode, cboStateID)
{
	if(StatesArray[txtAreaCode.value]!=cboStateID.options(cboStateID.selectedIndex).value)
	{
		alert("The telephone area code does not match the selected state. Please check...");
		txtAreaCode.focus();
		txtAreaCode.select();
		return false;
	}
	return true;
}