
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 ValidateSearch()
{
	// Detect browser
	browser ();
	
	if ((bMSIE5 == true) || (bMSIE55 == true) || (bMSIE6 == true) || (bNetscape_6 == true) || (bNetscape_7 == true))
	{
		if( (document.getElementById("search_lost").checked == true ) || (document.getElementById("search_found").checked == true ) )
			return true;
	}
	else if (bNetscape_4 == true)
	{
		if( document.forms[0][0].checked == true || document.forms[0][1].checked == true )
			return true;
	}
	
	return false;	
}	

function ValidateDate()
{ 
	if( (bMSIE5 == true) || (bMSIE55 == true) || (bMSIE6 == true) || (bNetscape_6 == true) || (bNetscape_7 == true) )
	{
		if( CheckDate(document.getElementById("txtDate").value) )
		{
			document.getElementById("date").className = "form_bk";
			return true;
		}
		else
		{
			document.getElementById("date").className = "missing";
			return false;
		}
	}
	else if (bNetscape_4 == true)
	{
		for( x = 0; x < document.forms[1].length; x++ )
		{
			var element = document.forms[1][x];
			if( element )
			{
				if ( element.name == "txtDate" )
				{
					if( CheckDate(element.value) )
					{
						element.className = "form_bk";
						return true;
					}
					else
					{
						element.className = "missing";
						return false;
					}	
					
				}
			} // end if element
		} // end for
	}

	return false;
}

function CheckDate(strDate)
{
	var arDate = strDate.split("/");
	
	if( arDate.length != 3 )
		return false;
	
	if( arDate[2].length > 4 )
		return false;

	var mon = Number(arDate[0]);	
	var day = Number(arDate[1]);	
	var year = Number(arDate[2]);	
	var now = new Date();
		
	// Make sure the date is in a valid range
	if( (mon > 0 && mon <= 12) &&
		(day > 0 && day <= 31) &&
		(year > 0 && year <= now.getYear()) )
	{
		// and not in the future
		if( mon-1 > now.getMonth() && year == now.getYear())
		{
			return false;
		}
		else
		{
			if( mon-1 == now.getMonth() && day > now.getDate() &&  year == now.getYear())
				return false;
			else
				return true;
		}
	} // end if
	return false;	
} // end CheckDate

function Validate()
{ 
	// Detect browser
	browser();
	if( (bMSIE5 == true) || (bMSIE55 == true) || (bMSIE6 == true) || (bNetscape_6 == true) || (bNetscape_7 == true) )
	{
		// Start with everything in the normal state
		document.getElementById("name").className = "drop";
		document.getElementById("contact").className = "drop";
		document.getElementById("type").className = "drop";
		document.getElementById("gender").className = "drop";
		document.getElementById("color1").className = "drop";
		document.getElementById("size").className = "drop";
		document.getElementById("area").className = "drop";
		document.getElementById("breed").className = "drop";

		// Validate required person info
		if (animal_info.all["txtPersonName"].value == "Required" || animal_info.all["txtPersonName"].value == "")
		{
			animal_info.all["name"].className = "missing";
		}
		if (animal_info.all["txtContact"].value == "Required" || animal_info.all["txtContact"].value == "")
		{
			animal_info.all["contact"].className = "missing";
		}
		
		// Validate animal info
		if( animal_info.all["cboType"].value == -1 )
		{
			animal_info.all["type"].className = "missing";
		}
		if( !ValidateBreed() )
		{
			animal_info.all["breed"].className = "missing";
		}
		if( animal_info.all["cboGender"].value == -1 )
		{
			animal_info.all["gender"].className = "missing";
		}
		if( animal_info.all["cboColor1"].value == -1 )
		{
			animal_info.all["color1"].className = "missing";
		}
		if( animal_info.all["cboSize"].value == -1)
		{
			animal_info.all["size"].className = "missing";
		}
		if( animal_info.all["cboArea"].value == -1 )
		{
			animal_info.all["area"].className = "missing";
		}
		
		if( ValidateDate() == true )
		{
			if( (animal_info.all["txtPersonName"].value != "Required" || animal_info.all["txtPersonName"].value != "") &&
					(animal_info.all["txtContact"].value != "Required" || animal_info.all["txtContact"].value != "") &&
					animal_info.all["cboType"].value != -1 &&
					animal_info.all["cboGender"].value != -1 &&
					animal_info.all["cboColor1"].value != -1 && 
					animal_info.all["cboSize"].value != -1 &&
					animal_info.all["cboArea"].value != -1 && ValidateBreed() )
			{
				return true;
			}	
		}	
	}
	else if (bNetscape_4 == true)
	{
		var bReturn = true;
		if( ValidateDate() )
		{
			alert("Valid");
			for( x = 0; x < document.forms[1].length; x++ )
			{
				var element = document.forms[1][x];
				if( element )
				{
					if ( element.name == "txtPersonName" || element.name == "txtContact" )
					{
						if( element.value == "Required" || element.value == "" )
						{
							element.className = "missing";
							bReturn = false;
						}
						else
							element.className = "form_bk";
					}
					// Check combo boxes
					if ( element.name == "cboType" || element.name == "cboGender" || element.name == "cboColor1" ||
						element.name == "cboSize" || element.name == "cboArea" )
					{
						if( element.options[element.selectedIndex].value == -1 )
						{
							element.className = "missing";
							bReturn = false;
						}
						else
							element.className = "form_bk";
					}
				} // end if element
			} // end for
			return bReturn;
		} // end if ValidateDate
	} // end if Netscape

	return false;
}

function ValidateBreed()
{
	for( x = 0; x < 15; x++)
	{
		if( animal_info.all["rBreed"][x].checked )
			return true;
	}
	
	return false;
}
	
function ValidateAgency()
{
	// Detect browser
	browser ();
	if ((bMSIE5 == true) || (bMSIE55 == true) || (bMSIE6 == true) || (bNetscape_6 == true) || (bNetscape_7 == true))
	{
		reZip = /\d{5}(-\d{4})?/i;  
		rePhone = /((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}/i;
		reEmail = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i;
		
		strZip = agency.all["txtZip"].value;
		strPhone = agency.all["txtPhone"].value;
		strEmail = agency.all["txtEmail"].value;
		
		if( false == reZip.test(strZip) )
			agency.all["zip"].className = "missing";
		else
			agency.all["zip"].className = "form_bk";
		
		if( false == rePhone.test(strPhone) )
			agency.all["phone"].className = "missing";
		else
			agency.all["phone"].className = "form_bk";

		if( false == reEmail.test(strEmail) )
			agency.all["email"].className = "missing";
		else
			agency.all["email"].className = "form_bk";
		
		if( agency.all["txtName"].value == "" )
			agency.all["name"].className = "missing";
		else
			agency.all["name"].className = "form_bk";

		if( agency.all["txtContact"].value == "" )
			agency.all["contact"].className = "missing";
		else
			agency.all["contact"].className = "form_bk";

		if( agency.all["txtAddress"].value == "" )
			agency.all["address"].className = "missing";
		else
			agency.all["address"].className = "form_bk";

		if( agency.all["txtCity"].value == "" )
			agency.all["city"].className = "missing";
		else
			agency.all["city"].className = "form_bk";
			
		if( agency.all["cboState"].value == -1 )
			agency.all["state"].className = "missing";
		else
			agency.all["state"].className = "form_bk";
			
		if( agency.all["txtLoginName"].value == "" )
			agency.all["login"].className = "missing";
		else
			agency.all["login"].className = "form_bk";
			
		if( agency.all["txtPwd"].value == "" )
			agency.all["pwd"].className = "missing";
		else
			agency.all["pwd"].className = "form_bk";
			
		if( agency.all["txtName"].value == "" ||
			agency.all["txtContact"].value == "" ||
			agency.all["txtAddress"].value == "" ||
			agency.all["txtCity"].value == "" ||
			agency.all["cboState"].value == -1 ||
			agency.all["txtZip"].value == "" ||
			agency.all["txtPhone"].value == "" ||
			agency.all["txtEmail"].value == "" ||
			agency.all["txtLoginName"].value == "" ||
			agency.all["txtPwd"].value == "" )
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	else if (bNetscape_4 == true)
	{ 
		var bReturn = true;
			for( x = 0; x < document.forms[1].length; x++ )
			{
				var element = document.forms[1][x];
				if( element )
				{
					if ( element.name == "txtName" || element.name == "txtContact" || element.name == "txtAddress" ||
						element.name == "txtCity" || element.name == "cboState" || element.name == "txtZip" || element.name == "txtPhone" ||
						element.name == "txtEmail" || element.name == "txtLoginName" || element.name == "txtPwd" )
					{
						if( element.value == "" )
						{
							//element.className = "missing";
							bReturn = false;
						}
						else
							element.className = "form_bk";
					}
				} // end if element
			} // end for
			return bReturn;
	} // end if Netscape
	return false;
}

function ChangeBreed(breed)
{
	// Detect browser
	browser();
	
	// Uncheck all just to be safe
	if ((bMSIE5 == true) || (bMSIE55 == true) || (bMSIE6 == true) || (bNetscape_6 == true) || (bNetscape_7 == true))
	{
		for( x = 0; x < 15; x++)
			animal_info.all["rBreed"][x].checked = false;

		if( 1 == breed )
		{
			document.getElementById('t1').style.display= 'block';
			document.getElementById('t2').style.display= 'none';
			document.getElementById('t3').style.display= 'none';
		}
		else if( 2 == breed )
		{
			document.getElementById('t1').style.display= 'none';
			document.getElementById('t2').style.display= 'block';
			document.getElementById('t3').style.display= 'none';
		}
		else if( 3 == breed )
		{
			document.getElementById('t1').style.display='none';
			document.getElementById('t2').style.display='none';
			document.getElementById('t3').style.display='block';
		}
		else
		{ 
			document.getElementById('t1').style.display='none';
			document.getElementById('t2').style.display='none';
			document.getElementById('t3').style.display='none';
		}
	}
	else if (bNetscape_4 == true)
	{
		for( x = 0; x < document.forms[1].length; x++)
		{
			if( document.forms[1][x].type == "radio" )
				document.forms[1][x].checked = false;
		}
			
	}
}