//(c)Alex Barnard 2000-2001
//--------------------------------------------------------------------------------
var g_Remove_=/_/g
var g_day,g_month,g_year

function checkFor(txt, sTest,flg)
{
	if(!txt.length) 
		return !flg
	
	for(var i = 0; i < txt.length; i++ )	
	{
		var	cChar=txt.charAt(i)
		cChar=cChar.toLowerCase()
		if (sTest.indexOf(cChar)<0)	
			return false
	}	
	return true
} 
//--------------------------------------------------------------------------------
function fnChkNumber(theField,flgReq)
{
	
	if(!checkFor(theField.value,".0123456789",flgReq))
	{
		alert(theField.name.substring(2,theField.name.length).replace(g_Remove_," ")+" requires Numerical entry")
		theField.focus()
		return false
	}
	return true
}		
//--------------------------------------------------------------------------------
//----------------------------------------------------------------------------
function fnChkPhone(theField,flgReq)
{
	if(!checkFor(theField.value,"() 0123456789",flgReq))
	{
		alert(theField.name.substring(2,theField.name.length).replace(g_Remove_," ")+" requires a Phone Number entry")
		theField.focus()
		return false
	}
	return true
}
//------------------------------------------------------------------------------
function fnChkEmail(sText,flgReq)
{
	
	var sTestChar = "abcdefghijklmnopqrstuvwxyz1234567890"
	var sTestSym="@.-&_"
	var sTest=sTestChar+sTestSym
	var c=0
	var d=0
	var flgErr=true

	if (sText.value.length == 0 &&!flgReq)
		return true;	
	
	sText.value=sText.value.toLowerCase()
	
	for( i = 0; i < sText.value.length; i++ )	
	{
		var	cChar=sText.value.charAt(i);
		if (sTest.indexOf(cChar)== -1)	
			flgErr=true
	
		if (sTestSym.indexOf(cChar)>=0)	
			if(i>0)
			{	
				if (cChar=="@")c++
				if (cChar==".")d++
				if(sTestChar.indexOf(sText.value.charAt(i-1))== -1)
					flgErr=true		
			
				if(i==sText.value.length-1)			
					flgErr=true
				else				
					if(sTestChar.indexOf(sText.value.charAt(i+1))== -1)	
						flgErr=true				
			}	

	}


		if(c==1)
			if(d>0)
				if(sText.value.indexOf(".")!= -1)
					if(sTestChar.indexOf(sText.value.charAt(0))!= -1)
						if(sTestChar.indexOf(sText.value.charAt(sText.value.length-1))!= -1)
							flgErr=false;
				
	if(flgErr)
	{
		alert("Invalid Email Address\nYou have entered an incorrect Email Address.");
		sText.focus();
		sText.select();
		return false;
	}
	
	return true;
}
	
//------------------------------------------------------------------------------------
function fnChkForm(theForm,flgForceReq)
{
	var flgErr=false
	var iPassPtr=-1
	var chk=0
	var sRadio	
	var sBox
	
	
    for(var i=0;i<theForm.elements.length;i++)
	{
		var fType=theForm.elements[i].name.substring(0,1)		
		var sName=theForm.elements[i].name.substring(2,theForm.elements[i].name.length)
		var sName=theForm.elements[i].name.substring(2,theForm.elements[i].name.length).replace(g_Remove_," ")
		var flgReq=flgForceReq

		if (!flgReq)
			flgReq=parseInt(theForm.elements[i].name.substring(1,2),10)
	
		if(fType!="X")
		{
			if(theForm.elements[i].type=="text" || theForm.elements[i].type=="file")
			{
				if(theForm.elements[i].value=="" && flgReq)
				{
					alert("You need to make an entry for "+sName)
					theForm.elements[i].focus()
					return false
				}

				if(fType=="D")
					if(!fnChkDate(theForm.elements[i],flgReq))
						return false

				if(fType=="N"||fType=="F")
					if(!fnChkNumber(theForm.elements[i],flgReq))
						return false
				
				if(sName.search("Email")>=0)	
					if(!fnChkEmail(theForm.elements[i]))
						return false
		
			}	

				
			if(theForm.elements[i].type=="textarea")
			{

				if(!theForm.elements[i].value) 
				{
					if(flgReq)
					{
						alert("You must make an entry for "+sName)
						theForm.elements[i].focus()
						return false				
					}	
				}	
			}			
		}
	
	}
	return true	
}
//------------------------------------------------------------------------------------
function msg(txt)
		{
			window.status=txt
			return true
		}	
//====================================================================================

function fnChkContact(theForm,flgFrmOk)
{
	if(!flgFrmOk)
		return false
	
	if(!theForm.T0Telephone.value && !theForm.T0Email.value)
	{
		alert("You must enter a Telephone number OR Email address")
		theForm.T0Telephone.focus()
		return false
	}		

	return true
}			

function fnSearch(theObj,params){
	var i,filter="",idx=theObj.options[theObj.selectedIndex].value
	for(i=0;i<=2;i++)
		filter+="&t="+escape(document.forms[0].elements[i].value)

	if(document.layers)//Netscape 4
		document.mshflexgrid.src="search_list.asp?o="+idx+filter+params
	else if(document.all)//IE	
		document.all.mshflexgrid.src="search_list.asp?o="+idx+filter+params
	else if(document.body.getAttributeNode)//Netscape 6
		document.mshflexgrid.src="search_list.asp?o="+idx+filter+params

	else
		alert("Browser Type Unknown")	

	return true
}


var hWnd
function fnPopUp(id) {
	var w=400;h=180;
	var fileName="search_popup.asp?i="+id
	if(!hWnd||hWnd.closed){
		hWnd=window.open(fileName, "popup", "width="+w+",height="+h+",scrollbars=1")
		if(!hWnd.opener)hWnd.opener=window
	}
	else{
		if(hWnd.location!=fileName)
			hWnd.location.replace(fileName)
		hWnd.focus()
	}
}
