// JavaScript Document
	function validPhoneNumbers(phne)
	{
		notAllowed = "()-. ";
		var i;
   	    var returnString = "";
    	
		for (i = 0; i < phne.length; i++)
    	{   
        	var c = phne.charAt(i);
        	if (notAllowed.indexOf(c) == -1) returnString += c;
    	}
		
		if(returnString.length == 7 || returnString.length == 10)
		{
			for (j = 0; j < returnString.length; j++)
    		{   
        		var d = returnString.charAt(j);
        		if ((d < "0") || (d > "9")) return false;
    		}
			
			return true;
		}
		else
		{
			return false;
		}
	}
	function validEmailAddress(email)
	{
		invalidChars = " /:,;"
		
		if(email == "")
		{
			return false
		}
		for(i=0; i<invalidChars.length; i++)
		{
			badChar = invalidChars.charAt(i)
			if(email.indexOf(badChar,0) > -1)
			{
				return false
			}
		}
		atPos = email.indexOf("@",1)
		if(atPos == -1)
		{
			return false
		}
		if(email.indexOf("@",atPos+1) > -1)
		{
			return false
		}
		periodPos = email.indexOf(".",atPos)
		if(periodPos == -1)
		{
			return false
		}
		if(periodPos+3 > email.length)
		{
			return false
		}
		
		return true
	}
	function validNumbers(Numbers)
	{
		notAllowed = ",$ ";
		var i;
   	    var returnString = "";
    	
		for (i = 0; i < Numbers.length; i++)
    	{   
        	var c = Numbers.charAt(i);
        	if (notAllowed.indexOf(c) == -1) returnString += c;
    	}
		
		for (j = 0; j < returnString.length; j++)
    	{   
        	var d = returnString.charAt(j);
        	if ((d < "0") || (d > "9")) return false;
    	}
		
		return true;
	}
	function wrongMakeRed()
	{
		document.getElementById("wrong").innerHTML = "<center><font color='#FF0000'><b>Please fill in/check everything that is in red</b></font></center>";	
		if(myTitle.FirstName.value == '')
		{
			document.getElementById("First").innerHTML = "<font color='#FF0000'>*First Name:</font>";
		}
		
		if(myTitle.LastName.value == '')
		{
			document.getElementById("Last").innerHTML = "<font color='#FF0000'>*Last Name:</font>";
		}
		if(myTitle.Email.value == '')
		{
			document.getElementById("Email").innerHTML = "<font color='#FF0000'>*Email Address:</font>";
		}
		if(!validEmailAddress(myTitle.Email.value))
		{
			document.getElementById("Email").innerHTML = "<font color='#FF0000'>*Email Address:</font>";
		}
		if(myTitle.EmailC.value == '')
		{
			document.getElementById("EmailC").innerHTML = "<font color='#FF0000'>*Confirm Email:</font>";
		}
		if((myTitle.Email.value).toLowerCase() != (myTitle.EmailC.value).toLowerCase())
		{
			document.getElementById("Email").innerHTML = "<font color='#FF0000'>*Email Address:</font>";
			document.getElementById("EmailC").innerHTML = "<font color='#FF0000'>*Confirm Email:</font>";
		}
		if(myTitle.PPhone.value == '' && myTitle.SecPhone.value == '' && myTitle.FaxPhone.value == '')
		{
			document.getElementById("PSF").innerHTML = "<font color='#FF0000'>*Please Fill In At Least One:</font>";
			document.getElementById("Primary").innerHTML = "Primary Phone#:";
			document.getElementById("Secondary").innerHTML = "Secondary Phone#:";
			document.getElementById("Fax").innerHTML = "Fax Phone#:";
		}
		else
		{
			if(myTitle.PPhone.value != '')
			{
				if(!validPhoneNumbers(myTitle.PPhone.value))
				{
					document.getElementById("Primary").innerHTML = "<font color='#FF0000'>Primary Phone#:</font>";
				}
			}
			if(myTitle.SecPhone.value != '')
			{
				if(!validPhoneNumbers(myTitle.SecPhone.value))
				{
					document.getElementById("Secondary").innerHTML = "<font color='#FF0000'>Secondary Phone#:</font>";
				}
			}
			if(myTitle.FaxPhone.value != '')
			{
				if(!validPhoneNumbers(myTitle.FaxPhone.value))
				{
					document.getElementById("Fax").innerHTML = "<font color='#FF0000'>Fax Phone#:</font>";
				}
			}
			document.getElementById("PSF").innerHTML = "<font color='#FF0000'>*</font>Please Fill In At Least One:";

		}
		if(myTitle.month.value == '')
		{
			document.getElementById("ClosingD").innerHTML = "<font color='#FF0000'>*Closing Date:</font>";
		}
		if(myTitle.month.value.length < 2)
		{
			document.getElementById("ClosingD").innerHTML = "<font color='#FF0000'>*Closing Date:</font>";
		}
		if(myTitle.month.value < 1 || myTitle.month.value > 12)
		{
			document.getElementById("ClosingD").innerHTML = "<font color='#FF0000'>*Closing Date:</font>";
		}
		if(myTitle.day.value == '')
		{
			document.getElementById("ClosingD").innerHTML = "<font color='#FF0000'>*Closing Date:</font>";
		}
		if(myTitle.day.value.length < 2)
		{
			document.getElementById("ClosingD").innerHTML = "<font color='#FF0000'>*Closing Date:</font>";
		}
		if(myTitle.month.value == 1 || myTitle.month.value == 3 || myTitle.month.value == 5 || myTitle.month.value == 7 || myTitle.month.value == 8 ||   	
		    myTitle.month.value == 10 || myTitle.month.value == 12)
		{
			if(myTitle.day.value < 1 || myTitle.day.value > 31)
			{
				document.getElementById("ClosingD").innerHTML = "<font color='#FF0000'>*Closing Date:</font>";
			}
		}
		if(myTitle.month.value == 4 || myTitle.month.value == 6 || myTitle.month.value == 9 || myTitle.month.value == 11)
		{
			if(myTitle.day.value < 1 || myTitle.day.value > 30)
			{
				document.getElementById("ClosingD").innerHTML = "<font color='#FF0000'>*Closing Date:</font>";
			}
		}
		if(myTitle.month.value == 2)
		{
			if(myTitle.day.value < 1 || myTitle.day.value > 29)
			{
				document.getElementById("ClosingD").innerHTML = "<font color='#FF0000'>*Closing Date:</font>";
			}
		}
		if(myTitle.year.value == '')
		{
			document.getElementById("ClosingD").innerHTML = "<font color='#FF0000'>*Closing Date:</font>";
		}
		if(myTitle.year.value.length < 2)
		{
			document.getElementById("ClosingD").innerHTML = "<font color='#FF0000'>*Closing Date:</font>";
		}
		if(myTitle.year.value < 7)
		{
			document.getElementById("ClosingD").innerHTML = "<font color='#FF0000'>*Closing Date:</font>";
		}
		
		if(myTitle.Seller.value == '' && myTitle.Buyer.value == '')
		{
			document.getElementById("SB").innerHTML = "<font color='#FF0000'>*Please Fill In At Least One:</font>";
		}
		else
		{
			document.getElementById("SB").innerHTML = "<font color='#FF0000'>*</font>Please Fill In At Least One:";
		}
		if(myTitle.Price.value == 0 && myTitle.Loan.value == 0 && myTitle.Loan2.value == 0 )
		{
			document.getElementById("PLL2").innerHTML = "<font color='#FF0000'>*Please Fill In At Least One:</font>";
		}
		else
		{
			if(	myTitle.Price.value != 0)
			{
				if(!validNumbers(myTitle.Price.value))
				{
					document.getElementById("Purchase").innerHTML = "<font color='#FF0000'>Purchase Price:</font>";
				}
				else
				{
					document.getElementById("PLL2").innerHTML = "<font color='#FF0000'>*</font>Please Fill In At Least One:";
					document.getElementById("Purchase").innerHTML = "Purchase Price:";
				}
			}
			if(myTitle.cents1.value != 0)
			{
				if(!validNumbers(myTitle.cents1.value))
				{
					document.getElementById("Purchase").innerHTML = "<font color='#FF0000'>Purchase Price:</font>";
				}
			}
			if(myTitle.cents1.value.length < 2)
			{
				document.getElementById("Purchase").innerHTML = "<font color='#FF0000'>Purchase Price:</font>";
			}
			
			
			if(	myTitle.Loan.value != 0)
			{
				if(!validNumbers(myTitle.Loan.value))
				{
					document.getElementById("Loan").innerHTML = "<font color='#FF0000'>Loan Amount:</font>";
				}
				else
				{
					document.getElementById("PLL2").innerHTML = "<font color='#FF0000'>*</font>Please Fill In At Least One:";
					document.getElementById("Loan").innerHTML = "Loan Amount:";
				}
			}
			if(myTitle.cents2.value != 0)
			{
				if(!validNumbers(myTitle.cents2.value))
				{
					document.getElementById("Loan").innerHTML = "<font color='#FF0000'>Loan Amount:</font>";
				}
			}
			if(myTitle.cents2.value.length < 2)
			{
				document.getElementById("Loan").innerHTML = "<font color='#FF0000'>Loan Amount:</font>";
			}
			
			if(	myTitle.Loan2.value != 0)
			{
				if(!validNumbers(myTitle.Loan2.value))
				{
					document.getElementById("SLoan").innerHTML = "<font color='#FF0000'>Secondary Loan Amount:</font>";
				}
				else
				{
					document.getElementById("PLL2").innerHTML = "<font color='#FF0000'>*</font>Please Fill In At Least One:";
					document.getElementById("SLoan").innerHTML = "Secondary Loan Amount:";
				}
			}
			if(myTitle.cents3.value != 0)
			{
				if(!validNumbers(myTitle.cents3.value))
				{
					document.getElementById("SLoan").innerHTML = "<font color='#FF0000'>Secondary Loan Amount:</font>";
				}
			}
			if(myTitle.cents3.value.length < 2)
			{
				document.getElementById("SLoan").innerHTML = "<font color='#FF0000'>Secondary Loan Amount:</font>";
			}
			document.getElementById("PLL2").innerHTML = "<font color='#FF0000'>*</font>Please Fill In At Least One:";
		}
		if(myTitle.street.value == '')
		{
			document.getElementById("Property").innerHTML = "<font color='#FF0000'>*Property Address:</font>";
		}
		if(myTitle.city.value == '-1')
		{
			document.getElementById("Property").innerHTML = "<font color='#FF0000'>*Property Address:</font>";
		}
		if(myTitle.zip.value == '')
		{
			document.getElementById("Property").innerHTML = "<font color='#FF0000'>*Property Address:</font>";	
		}
		else
		{
			if(	myTitle.zip.value.length < 5)
			{
				document.getElementById("Property").innerHTML = "<font color='#FF0000'>*Property Address:</font>";
			}
		}
		if(myTitle.phoneAgent.value != '')
		{
			if(!validPhoneNumbers(myTitle.phoneAgent.value))
			{
				document.getElementById("LPhone").innerHTML = "<font color='#FF0000'>Listing Agent Phone#:</font>";
			}
			else
			{
				document.getElementById("LPhone").innerHTML = "Listing Agent Phone#:";
			}
		}
	}
	function TitleOK()
	{
		var error = false;
		if(myTitle.FirstName.value == '')
		{
			
			wrongMakeRed();
			document.forms.myTitle.FirstName.focus();
			return false;
		}
		else
		{
			document.getElementById("First").innerHTML = "<font color='#FF0000'>*</font>First Name:";
		}
		if(myTitle.LastName.value == '')
		{
			wrongMakeRed();
			document.forms.myTitle.LastName.focus();
			return false;
		}
		else
		{
			document.getElementById("Last").innerHTML = "<font color='#FF0000'>*</font>Last Name:";
		}
		if(myTitle.Email.value == '')
		{
			wrongMakeRed();
			document.forms.myTitle.Email.focus();
			return false;
		}
		else
		{
			document.getElementById("Email").innerHTML = "<font color='#FF0000'>*</font>Email Address:";	
		}
		if(!validEmailAddress(myTitle.Email.value))
		{
			wrongMakeRed();			
			document.forms.myTitle.Email.focus();
			return false;
		}
		else
		{
			document.getElementById("Email").innerHTML = "<font color='#FF0000'>*</font>Email Address:";	
		}
		if(myTitle.EmailC.value == '')
		{
			wrongMakeRed();
			document.forms.myTitle.EmailC.focus();
			return false;
		}
		else
		{
			document.getElementById("EmailC").innerHTML = "<font color='#FF0000'>*</font>Confirm Email:";	
		}
		if((myTitle.Email.value).toLowerCase() != (myTitle.EmailC.value).toLowerCase())
		{
			wrongMakeRed();
			document.forms.myTitle.Email.focus();
			return false;
		}
		else
		{
			document.getElementById("Email").innerHTML = "<font color='#FF0000'>*</font>Email Address:";
			document.getElementById("EmailC").innerHTML = "<font color='#FF0000'>*</font>Confirm Email:";
		}
		if(myTitle.PPhone.value == '' && myTitle.SecPhone.value == '' && myTitle.FaxPhone.value == '')
		{
			wrongMakeRed();
			document.forms.myTitle.PPhone.focus();
			return false;
		}
		else
		{
			document.getElementById("PSF").innerHTML = "<font color='#FF0000'>*</font>Please Fill In At Least One:";
			if(myTitle.PPhone.value != '')
			{
				if(!validPhoneNumbers(myTitle.PPhone.value))
				{
					wrongMakeRed();
					document.forms.myTitle.PPhone.focus();
					return false;
				}
				else
				{
					document.getElementById("Primary").innerHTML = "Primary Phone#:";
				}
			}
			if(myTitle.SecPhone.value != '')
			{
				if(!validPhoneNumbers(myTitle.SecPhone.value))
				{
					wrongMakeRed();	
					document.forms.myTitle.SecPhone.focus();
					return false;
				}
				else
				{
					document.getElementById("Secondary").innerHTML = "Secondary Phone#:";
					
				}
			}
			if(myTitle.FaxPhone.value != '')
			{
				if(!validPhoneNumbers(myTitle.FaxPhone.value))
				{
					wrongMakeRed();	
					document.forms.myTitle.FaxPhone.focus();
					return false;
				}
				else
				{
					document.getElementById("Fax").innerHTML = "Fax Phone#:";
				}
			}
		}
		if(myTitle.month.value == '')
		{
			wrongMakeRed();
			document.forms.myTitle.month.focus();
			return false;
		}
		if(myTitle.month.value.length < 2)
		{
			wrongMakeRed();
			document.forms.myTitle.month.focus();
			return false;
		}
		if(myTitle.month.value < 1 || myTitle.month.value > 12)
		{
			wrongMakeRed();
			document.forms.myTitle.month.focus();
			return false;
		}
		if(myTitle.day.value == '')
		{
			wrongMakeRed();
			document.forms.myTitle.day.focus();
			return false;
		}
		if(myTitle.day.value.length < 2)
		{
			wrongMakeRed();
			document.forms.myTitle.day.focus();
			return false;
		}
		if(myTitle.month.value == 1 || myTitle.month.value == 3 || myTitle.month.value == 5 || myTitle.month.value == 7 || myTitle.month.value == 8 ||   	
		    myTitle.month.value == 10 || myTitle.month.value == 12)
		{
			if(myTitle.day.value < 1 || myTitle.day.value > 31)
			{
				wrongMakeRed();
				document.forms.myTitle.day.focus();
				return false;
			}
		}
		if(myTitle.month.value == 4 || myTitle.month.value == 6 || myTitle.month.value == 9 || myTitle.month.value == 11)
		{
			if(myTitle.day.value < 1 || myTitle.day.value > 30)
			{
				wrongMakeRed();
				document.forms.myTitle.day.focus();
				return false;
			}
		}
		if(myTitle.month.value == 2)
		{
			if(myTitle.day.value < 1 || myTitle.day.value > 29)
			{
				wrongMakeRed();
				document.forms.myTitle.day.focus();
				return false;
			}
		}
		if(myTitle.year.value == '')
		{
			wrongMakeRed();
			document.forms.myTitle.year.focus();
			return false;
		}
		if(myTitle.year.value.length < 2)
		{
			wrongMakeRed();
			document.forms.myTitle.year.focus();
			return false;
		}
		if(myTitle.year.value < 7)
		{
			wrongMakeRed();
			document.forms.myTitle.year.focus();
			return false;
		}
		else
		{
			document.getElementById("ClosingD").innerHTML = "<font color='#FF0000'>*</font>Closing Date:";
		}
		if(myTitle.Seller.value == '' && myTitle.Buyer.value == '')
		{
			wrongMakeRed();
			document.forms.myTitle.Seller.focus();
			return false;
		}
		else
		{
			document.getElementById("SB").innerHTML = "<font color='#FF0000'>*</font>Please Fill In At Least One:";
		}
		if(myTitle.Price.value == 0 && myTitle.Loan.value == 0 && myTitle.Loan2.value == 0 )
		{
			wrongMakeRed();
			document.forms.myTitle.Price.focus();
			return false;
		}
		else
		{
			if(	myTitle.Price.value != 0)
			{
				if(!validNumbers(myTitle.Price.value))
				{
					wrongMakeRed();
					document.forms.myTitle.Price.focus();
					return false;
				}
			}
			if(myTitle.cents1.value != 0)
			{
				if(!validNumbers(myTitle.cents1.value))
				{
					wrongMakeRed();
					document.forms.myTitle.cents1.focus();
					return false;
				}
			}
			if(myTitle.cents1.value.length < 2)
			{
				wrongMakeRed();
				document.forms.myTitle.cents1.focus();
				return false;
			}
			
			
			if(	myTitle.Loan.value != 0)
			{
				if(!validNumbers(myTitle.Loan.value))
				{
					wrongMakeRed();
					document.forms.myTitle.Price.focus();
					return false;
				}
			}
			if(myTitle.cents2.value != 0)
			{
				if(!validNumbers(myTitle.cents2.value))
				{
					wrongMakeRed();
					document.forms.myTitle.cents2.focus();
					return false;
				}
			}
			if(myTitle.cents2.value.length < 2)
			{
				wrongMakeRed();
				document.forms.myTitle.cents2.focus();
				return false;
			}
			
			if(	myTitle.Loan2.value != 0)
			{
				if(!validNumbers(myTitle.Loan2.value))
				{
					wrongMakeRed();
					document.forms.myTitle.Loan2.focus();
					return false;
				}
			}
			if(myTitle.cents3.value != 0)
			{
				if(!validNumbers(myTitle.cents3.value))
				{
					wrongMakeRed();
					document.forms.myTitle.cents3.focus();
					return false;
				}
			}
			if(myTitle.cents3.value.length < 2)
			{
				wrongMakeRed();
				document.forms.myTitle.cents3.focus();
				return false;
			}
		}
		if(myTitle.street.value == '')
		{
			wrongMakeRed();
			document.forms.myTitle.street.focus();
			return false;	
		}
		if(myTitle.city.value == '-1')
		{
			wrongMakeRed();
			document.forms.myTitle.city.focus();
			return false;	
		}
		if(myTitle.zip.value == '')
		{
			wrongMakeRed();
			document.forms.myTitle.zip.focus();
			return false;	
		}
		else
		{
			if(	myTitle.zip.value.length < 5)
			{
				wrongMakeRed();
				document.forms.myTitle.zip.focus();
				return false;	
			}
		}
		document.getElementById("Property").innerHTML = "<font color='#FF0000'>*</font>Property Address:";
		if(myTitle.phoneAgent.value != '')
		{
			if(!validPhoneNumbers(myTitle.phoneAgent.value))
			{
				wrongMakeRed();	
				document.forms.myTitle.phoneAgent.focus();
				return false;
			}	
		}

		var req; 
			
    	if (window.XMLHttpRequest) 
		{ 
        	req = new XMLHttpRequest; 
		} 
		else if (window.ActiveXObject) 
		{ 
			req = new ActiveXObject("Microsoft.XMLHTTP");
        } 
		else
		{
			return true	
		}
			
		if (req) 
		{  
       		req.open("POST", 'http://www.caplanlegal.com/OrderTAs.law', true); 
			req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			var rad1;
			var rad2;
			
			for (var i=0; i < document.myTitle.radio1.length; i++)
   			{
   				if (document.myTitle.radio1[i].checked)
    			{
      				var rad1 = document.myTitle.radio1[i].value;
      			}
   			}
			for (var i=0; i < document.myTitle.radio2.length; i++)
   			{
   				if (document.myTitle.radio2[i].checked)
    			{
      				var rad2 = document.myTitle.radio2[i].value;
      			}
   			}
			
			
			var Parms = 'FirstName='+myTitle.FirstName.value+'&LastName='+myTitle.LastName.value+'&Email='+myTitle.Email.value+'&EmailC='+myTitle.EmailC.value+'&PPhone='+myTitle.PPhone.value+'&SecPhone='+myTitle.SecPhone.value+'&FaxPhone='+myTitle.FaxPhone.value+'&radio1='+rad1+'&month='+myTitle.month.value+'&day='+myTitle.day.value+'&year='+myTitle.year.value+'&Seller='+myTitle.Seller.value+'&Buyer='+myTitle.Buyer.value+'&Price='+myTitle.Price.value+'&cents1='+myTitle.cents1.value+'&Loan='+myTitle.Loan.value+'&cents2='+myTitle.cents2.value+'&Loan2='+myTitle.Loan2.value+'&cents3='+myTitle.cents3.value+'&radio2='+rad2+'&street='+myTitle.street.value+'&city='+myTitle.city.value+'&zip='+myTitle.zip.value+'&taxid='+myTitle.taxid.value+'&LenderN='+myTitle.LenderN.value+'&Listing='+myTitle.Listing.value+'&phoneAgent='+myTitle.phoneAgent.value;
       		
			//alert(Parms);
			req.send(Parms); 
    	} 
		else 
		{ 
       		return true;
    	} 
			
				
		alert("Thank You for ordering a title from this law firm.  Please call us at (757) 523-0023, if you do not hear from us within forty-eight hour");
		
		document.forms.myTitle.FirstName.value  = "";
		document.forms.myTitle.LastName.value = "";
		document.forms.myTitle.Email.value = "";
		document.forms.myTitle.EmailC.value  = "";
		document.forms.myTitle.PPhone.value  = "";
		document.forms.myTitle.SecPhone.value  = "";
		document.forms.myTitle.FaxPhone.value  = "";
		document.forms.myTitle.radio1[0].checked = true;
		document.forms.myTitle.month.value  = "";
		document.forms.myTitle.day.value  = "";
		document.forms.myTitle.year.value  = "";
		document.forms.myTitle.Seller.value  = "";
		document.forms.myTitle.Buyer.value  = "";
		document.forms.myTitle.Price.value  = "0";
		document.forms.myTitle.Loan.value  = "0";
		document.forms.myTitle.Loan2.value  = "0";
		document.forms.myTitle.cents1.value  = "00";
		document.forms.myTitle.cents2.value  = "00";
		document.forms.myTitle.cents3.value  = "00";
		document.forms.myTitle.radio2[0].checked = true;
		loadAddress(1);
		document.forms.myTitle.street.value  = "";
		document.forms.myTitle.city.options[0].selected = true;
		document.forms.myTitle.zip.value  = "";
		document.forms.myTitle.taxid.value  = "";
		document.forms.myTitle.LenderN.value  = "";
		document.forms.myTitle.Listing.value  = "";
		document.forms.myTitle.phoneAgent.value  = "";
		
		return false;
	}
