// form validation function //
var substitueFlag = false;
// Regular Expressions //
	var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
	var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);
	var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
	var regPhone = "^([0-9]{3})(-)?([0-9]{3})(-)?([0-9]{4}|[0-9]{4})$";
	var regDate = /(0[1-9]|1[012])\/(0[1-9]|[12][0-9]|3[01])\/([0-9]{2,4})/i;
	var regPrice = "/(^$)|(^[0-9]+$)|(^[0-9]+\.[0-9][0-9]$)/";

function emptyFields()
{
	return false;	
}
function numbersonly(myfield, e, dec)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// numbers
else if ((("0123456789").indexOf(keychar) > -1))
   return true;

// decimal point jump
else if (dec && (keychar == "."))
   {
   myfield.form.elements[dec].focus();
   return false;
   }
else
   return false;
}

function validateDineAroundForm()
{
	var Contact0FirstName = document.getElementById('Contact0FirstName').value;
	var Contact0LastName = document.getElementById('Contact0LastName').value;
	var Contact0Email = document.getElementById('Contact0Email').value;
	var Contact0_Mobile = document.getElementById('Contact0_Mobile').value;	
	var address = document.getElementById('address').value;
	var city = document.getElementById('city').value;
	var state = document.getElementById('state').value;
	var zip = document.getElementById('zip').value;
	var question = document.getElementById('question').value;
	
	if(Contact0FirstName == "") {

	inlineMsg('Contact0FirstName','You must enter your first name.',5);		
		return false;
	}
	if(Contact0LastName == "") {

	inlineMsg('Contact0LastName','You must enter your last name.',5);		
		return false;
	}
	
	if(Contact0Email == "") {

		inlineMsg('Contact0Email','You must enter your email.',5);
		return false;
	}

	if(!Contact0Email.match(emailRegex)) {
		inlineMsg('Contact0Email','You have entered an invalid email address.',5);
		return false;
	}
	
	if(Contact0_Mobile == "") {

	inlineMsg('Contact0_Mobile','You must enter your cell phone.',5);		
		return false;
	}
	if(!Contact0_Mobile.match(regPhone)) {

	inlineMsg('Contact0_Mobile','You must enter a valid phone number (e.g 123-123-1234)',5);		
		return false;
	}
	if(address == "") {

	inlineMsg('address','You must enter your address.',5);		
		return false;
	}
	if(city == "") {

	inlineMsg('city','You must enter your city.',5);		
		return false;
	}
	if(state == "") {

	inlineMsg('state','You must enter your state.',5);		
		return false;
	}
	if(zip == "") {

	inlineMsg('zip','You must enter your zip.',5);		
		return false;
	}
	if(question == "") {

	inlineMsg('question','You must enter your question.',5);		
		return false;
	}
	
	
}
function validateDHMForm1()
{
	var Contact0FirstName = document.getElementById('Contact0FirstName').value;
	var Contact0LastName = document.getElementById('Contact0LastName').value;
	var Contact0_Mobile = document.getElementById('Contact0_Mobile').value;
	var Contact0Email = document.getElementById('Contact0Email').value;
	var Contact0_PropertyAddress = document.getElementById('Contact0_PropertyAddress').value;
	var Contact0_PropertCity = document.getElementById('Contact0_PropertCity').value;
	var state = document.getElementById('state').value;
	var Contact0_Zip = document.getElementById('Contact0_Zip').value;
	var Contact0_EstimatedAfterRepairValue = document.getElementById('Contact0_EstimatedAfterRepairValue').value;
	var Contact0_EstimatedRehabCost = document.getElementById('Contact0_EstimatedRehabCost').value;

	
	var county = "";
	
	
	if(Contact0FirstName == "") {

	inlineMsg('Contact0FirstName','You must enter borrower first name.',5);		
		return false;
	}
	if(Contact0LastName == "") {

	inlineMsg('Contact0LastName','You must enter borrower last name.',5);		
		return false;
	}
	if(Contact0_Mobile == "") {

	inlineMsg('Contact0_Mobile','You must enter borrower cell phone.',5);		
		return false;
	}
	if(!Contact0_Mobile.match(regPhone)) {

	inlineMsg('Contact0_Mobile','You must enter a valid phone number (e.g 123-123-1234)',5);		
		return false;
	}
	if(Contact0Email == "") {

		inlineMsg('Contact0Email','You must enter borrower email.',5);
		return false;
	}

	if(!Contact0Email.match(emailRegex)) {
		inlineMsg('Contact0Email','You have entered an invalid email address.',5);
		return false;
	}
	if(Contact0_PropertyAddress == "") {

		inlineMsg('Contact0_PropertyAddress','You must enter property address.',5);
		return false;
	}
	if(Contact0_PropertCity == "") {

		inlineMsg('Contact0_PropertCity','You must enter property city.',5);
		return false;
	}
	if(state == "" || state == "0") {
		inlineMsg('state','You must select property state.',5);
		return false;
	}
	if(state == "Arizona (AZ)")
	{
		countyId = 	"countyAZ";
	}else if(state == "Colorado (CO)")
	{
		countyId = 	"countyCO";
	}else if(state == "Georgia (GA)")
	{
		countyId = 	"countyGA";
	}else if(state == "Maryland (MD)")
	{
		countyId = 	"countyMD";
	}else if(state == "Massachusetts (MA)")
	{
		countyId = 	"countyMA";
	}else if(state == "Mississippi (MS)")
	{
		countyId = 	"countyMS";
	}else if(state == "Nebraska (NE)")
	{
		countyId = 	"countyNE";
	}else if(state == "Nevada (NV)")
	{
		countyId = 	"countyNV";
	}else if(state == "New Hampshire (NH)")
	{
		countyId = 	"countyNH";
	}else if(state == "New Mexico (NM)")
	{
		countyId = 	"countyNM";
	}else if(state == "North Carolina (NC)")
	{
		countyId = 	"countyNC";
	}else if(state == "Oregon (OR)")
	{
		countyId = 	"countyOR";
	}else if(state == "Rhode Island (RI)")
	{
		countyId = 	"countyRI";
	}else if(state == "Texas (TX)")
	{
		countyId = 	"countyTX";
	}else if(state == "Utah(UT)")
	{
		countyId = 	"countyUT";
	}else if(state == "Virginia(VA)")
	{
		countyId = 	"countyVA";
	}else if(state == "Washington(WA)")
	{
		countyId = 	"countyWA";
	}else if(state == "West Virginia(WV)")
	{
		countyId = 	"countyWV";
	}
	
	var county = document.getElementById(countyId).value;
	if(county == "" || county == "0") {
		inlineMsg(countyId,'You must select property county.',5);
		return false;
	}
	
	if(Contact0_Zip == "") {
		inlineMsg('Contact0_Zip','You must enter property zip.',5);
		return false;
	}
	if(Contact0_EstimatedAfterRepairValue == "") {
		inlineMsg('Contact0_EstimatedAfterRepairValue','You must enter Estimated After Repaired Value.',5);
		return false;
	}
	if(Contact0_EstimatedRehabCost == "") {
		inlineMsg('Contact0_EstimatedRehabCost','You must enter Estimated Rehab Costs.',5);
		return false;
	}
	if(document.getElementById('selectNo').checked == false && document.getElementById('selectYes').checked == "" && document.getElementById('selectRe').checked == false)
	 {
		inlineMsg('selectRe','You must select one option.',5);
		return false;
	}
	
	return true;
	
}

function validateDHMForm2()
{
	
	var txtMailingAddress = document.getElementById('txtMailingAddress').value;
	var txtCity = document.getElementById('txtCity').value;
	var txtState = document.getElementById('txtState').value;
	var txtZip = document.getElementById('txtZip').value;

	if(txtMailingAddress == "") {
		inlineMsg('txtMailingAddress','You must enter Borrower Mailing Address.',5);
		return false;
	}
	
	if(txtCity == "") {
		inlineMsg('txtCity','You must enter City.',5);
		return false;
	}
	if(txtState == "") {
		inlineMsg('txtState','You must enter State.',5);
		return false;
	}
	if(txtZip == "") {
		inlineMsg('txtZip','You must enter Zip.',5);
		return false;
	}
	
	return true;
}

function validateDHMForm3()
{
	if(document.getElementById('rdLivingN').checked == false && document.getElementById('rdLivingY').checked == "") {
		inlineMsg('rdLivingN','You must select an option.',5);
		return false;
	}		
	
	return true;
}
function validateDHMForm4()
{
	var txtSSN = document.getElementById('txtSSN').value;
	var txtDOB = document.getElementById('txtDOB').value;
	var txtHomePhone = document.getElementById('txtHomePhone').value;
	var txtCellPhone = document.getElementById('txtCellPhone').value;
	var txtWorkPhone = document.getElementById('txtWorkPhone').value;
	var txtEmail = document.getElementById('txtEmail').value;
	var txtHomeAddress = document.getElementById('txtHomeAddress').value;
	var txtPropertyCity = document.getElementById('txtPropertyCity').value;
	var txtPropertyState = document.getElementById('txtPropertyState').value;
	var txtPropertyZip = document.getElementById('txtPropertyZip').value;
	var txtRentOwn = document.getElementById('txtRentOwn').value;
	var txtEmployer  = document.getElementById('txtEmployer').value;
	var txtEmployerPhone = document.getElementById('txtEmployerPhone').value;
	var txtPrimaryBankName = document.getElementById('txtPrimaryBankName').value;
	var txtBankAccountNumber = document.getElementById('txtBankAccountNumber').value;
	var txtCheck = document.getElementById('txtCheck').value;
	var txtBalance = document.getElementById('txtBalance').value;
	if(txtSSN == "") 
	{
		inlineMsg('txtSSN','You must enter SSN#.',5);
		return false;
	}
	if(txtDOB == "") 
	{
		inlineMsg('txtDOB','You must enter DOB.',5);
		return false;
	}
	if(txtHomePhone == "") 
	{
		inlineMsg('txtHomePhone','You must enter Home Phone.',5);
		return false;
	}
	if(txtCellPhone == "") 
	{
		inlineMsg('txtCellPhone','You must enter Cell Phone.',5);
		return false;
	}
	if(txtWorkPhone == "") 
	{
		inlineMsg('txtWorkPhone','You must enter Work Phone.',5);
		return false;
	}
	if(txtEmail == "") {

		inlineMsg('txtEmail','You must enter email.',5);
		return false;
	}

	if(!txtEmail.match(emailRegex)) {
		inlineMsg('txtEmail','You have entered an invalid email address.',5);
		return false;
	}
	if(txtHomeAddress == "") 
	{
		inlineMsg('txtHomeAddress','You must enter home address.',5);
		return false;
	}
	if(txtPropertyCity == "") 
	{
		inlineMsg('txtPropertyCity','You must enter City.',5);
		return false;
	}
	if(txtPropertyState == "") 
	{
		inlineMsg('txtPropertyState','You must enter State.',5);
		return false;
	}
	if(txtPropertyZip == "") 
	{
		inlineMsg('txtPropertyZip','You must enter Zip.',5);
		return false;
	}
	if(txtRentOwn == "") 
	{
		inlineMsg('txtRentOwn','You must enter Do You Rent or Own?.',5);
		return false;
	}
	if(txtEmployer == "") 
	{
		inlineMsg('txtEmployer','You must enter Name of Employe.',5);
		return false;
	}
	if(txtEmployerPhone == "") 
	{
		inlineMsg('txtEmployerPhone','You must enter Employer Phone.',5);
		return false;
	}
	if(txtPrimaryBankName == "") 
	{
		inlineMsg('txtPrimaryBankName','You must enter Primary Bank Name.',5);
		return false;
	}
	if(txtBankAccountNumber == "") 
	{
		inlineMsg('txtBankAccountNumber','You must enter Bank Account #.',5);
		return false;
	}
	if(txtCheck == "") 
	{
		inlineMsg('txtCheck','You must enter Checking or Savings.',5);
		return false;
	}
	if(txtBalance == "") 
	{
		inlineMsg('txtBalance','You must enter Balance.',5);
		return false;
	}
	
	return true;
}


function validateForm()
{ 
	var regexp = document.getElementById('Contact1Email').value;
	var name = document.getElementById('Contact1FirstName').value;
	var lname = document.getElementById('Contact1LastName').value;
	
	if(name == "" || name == "First Name") {

		inlineMsg('Contact1FirstName','You must enter your first name.',5);
		return false;
	}
	
	if(lname == "" || lname == "Last Name") {

		inlineMsg('Contact1LastName','You must enter your last name.',5);
		return false;
	}
	
	if(regexp == "" || regexp == "Email") {

		inlineMsg('Contact1Email','You must enter your email.',5);
		return false;
	}

	if(!regexp.match(emailRegex)) {
		inlineMsg('Contact1Email','You have entered an invalid email address.',5);
		return false;
	}
	
	return true;
}

function validateForm1()
{ 
	var regexp = document.getElementById('Contact0Email').value;
	var name = document.getElementById('Contact0FirstName').value;
	var lname = document.getElementById('Contact0LastName').value;
	
	if(name == "" || name == "First Name") {

		inlineMsg('Contact0FirstName','You must enter your first name.',5);
		return false;
	}
	
	if(lname == "" || lname == "Last Name") {

		inlineMsg('Contact0LastName','You must enter your last name.',5);
		return false;
	}
	
	if(regexp == "" || regexp == "Email") {

		inlineMsg('Contact0Email','You must enter your email.',5);
		return false;
	}

	if(!regexp.match(emailRegex)) {
		inlineMsg('Contact0Email','You have entered an invalid email address.',5);
		return false;
	}
	
	return true;
}

function validateCommercialForm()
{
	var bName = document.getElementById('Contact0FirstName').value;
	var bLastName = document.getElementById('Contact0LastName').value;
	var address = document.getElementById('Contact0StreetAddress1').value;
	var city = document.getElementById('Contact0City').value;
	var state = document.getElementById('Contact0State').value;
	var zip = document.getElementById('Contact0PostalCode').value;
	var bCell = document.getElementById('Contact0_Mobile').value;
	var bEmail = document.getElementById('Contact0Email').value;
	var sAddress = document.getElementById('Contact0_SubjectPropertyAddress0').value;
	var sCity = document.getElementById('Contact0_CommercialCity').value;
	var sState = document.getElementById('Contact0_CommercialState').value;
	var sZip = document.getElementById('Contact0_CommercialZip').value;
	var sPurchasePrice = document.getElementById('Contact0_PurchasePrice').value;
	var sEstCurrentValue = document.getElementById('Contact0_EstimatedCurrentValue').value;
	var downPayment = document.getElementById('Contact0_DownPaymentAmountBorrowercanputasdownpayment').value;
	var requestedAmount = document.getElementById('Contact0_RequestedLoanAmount').value;

	if(bName == "") {

	inlineMsg('Contact0FirstName','You must enter borrower First name.',5);		
		return false;
	}
	if(bLastName == "") {

	inlineMsg('Contact0LastName','You must enter borrower Last name.',5);		
		return false;
	}
	
	if(address == "") {

	inlineMsg('Contact0StreetAddress1','You must enter borrower address.',5);		
		return false;
	}
	
	if(city == "") {

	inlineMsg('Contact0City','You must enter borrower City.',5);		
		return false;
	}
	
	if(state == "") {

	inlineMsg('Contact0State','You must enter borrower State.',5);		
		return false;
	}
	
	if(zip == "") {

	inlineMsg('Contact0PostalCode','You must enter borrower ZIP.',5);		
		return false;
	}
	
	if(bCell == "") {

	inlineMsg('Contact0_Mobile','You must enter borrower cell number.',5);		
		return false;
	}
	
	if(!bCell.match(regPhone)) {

	inlineMsg('Contact0_Mobile','You must enter a valid phone number (e.g 123-123-1234)',5);		
		return false;
	}
	
	if(bEmail == "") {

		inlineMsg('Contact0Email','You must enter borrower email.',5);
		return false;
	}

	if(!bEmail.match(emailRegex)) {
		inlineMsg('Contact0Email','You have entered an invalid email address.',5);
		return false;
	}
	
	if(sAddress == "") {

	inlineMsg('Contact0_SubjectPropertyAddress0','You must enter property address.',5);		
		return false;
	}
	
	if(sCity == "") {

	inlineMsg('Contact0_CommercialCity','You must enter property City.',5);		
		return false;
	}
	
	if(sState == "") {

	inlineMsg('Contact0_CommercialState','You must enter property State.',5);		
		return false;
	}
	
	if(sZip == "") {

	inlineMsg('Contact0_CommercialZip','You must enter property ZIP.',5);		
		return false;
	}
	
	if(sPurchasePrice == "") {

	inlineMsg('Contact0_PurchasePrice','You must enter purchase price.',5);		
		return false;
	}
	
	if(!sPurchasePrice.match(regPrice)) {

	inlineMsg('Contact0_PurchasePrice','You must enter a valid price(only numbers)',5);		
		return false;
	}
	
	if(sEstCurrentValue == "") {

	inlineMsg('Contact0_EstimatedCurrentValue','You must enter estimated current value.',5);		
		return false;
	}
	
	if(!sEstCurrentValue.match(regPrice)) {

	inlineMsg('Contact0_EstimatedCurrentValue','You must enter a valid estimated current value(only numbers)',5);		
		return false;
	}
	
	if(downPayment == "") {

	inlineMsg('Contact0_DownPaymentAmountBorrowercanputasdownpayment','You must enter down payment.',5);		
		return false;
	}
	
	if(!downPayment.match(regPrice)) {

	inlineMsg('Contact0_DownPaymentAmountBorrowercanputasdownpayment','You must enter a valid down payment(only numbers)',5);		
		return false;
	}
	
	if(requestedAmount == "") {

	inlineMsg('Contact0_RequestedLoanAmount','You must enter requested amount.',5);		
		return false;
	}
	
	if(!requestedAmount.match(regPrice)) {

	inlineMsg('Contact0_RequestedLoanAmount','You must enter a valid requested amount(only numbers)',5);		
		return false;
	}
	
}

function validateInvest()
{
	var Contact0FirstName = document.getElementById('Contact0FirstName').value;
	var Contact0LastName = document.getElementById('Contact0LastName').value;	
	var Contact0Email = document.getElementById('Contact0Email').value;	
	var Contact0_AmountofFundsforHardMoneyLending = document.getElementById('Contact0_AmountofFundsforHardMoneyLending').value;
	var Contact0Phone1 = document.getElementById('Contact0Phone1').value;
	
	if(Contact0FirstName == "") {

	inlineMsg('Contact0FirstName','You must enter your first name.',5);		
		return false;
	}
	if(Contact0LastName == "") {

	inlineMsg('Contact0LastName','You must enter your last name.',5);		
		return false;
	}
	if(Contact0Phone1 == "") {

	inlineMsg('Contact0Phone1','You must enter borrower cell number.',5);		
		return false;
	}
	
	if(!Contact0Phone1.match(regPhone)) {

	inlineMsg('Contact0Phone1','You must enter a valid phone number (e.g 123-123-1234)',5);		
		return false;
	}
	if(Contact0Email == "") {

		inlineMsg('Contact0Email','You must enter your email.',5);
		return false;
	}

	if(!Contact0Email.match(emailRegex)) {
		inlineMsg('Contact0Email','You have entered an invalid email address.',5);
		return false;
	}	
	if(Contact0_AmountofFundsforHardMoneyLending == "") {

	inlineMsg('Contact0_AmountofFundsforHardMoneyLending','You must enter Amount of Funds for Hard Money Lending.',5);		
		return false;
	}
	
	return true;
}

function validateContactUsForm()
{
	
	var first_name = document.getElementById('Contact0FirstName').value;
	var last_name = document.getElementById('Contact0LastName').value;	
	var email_val = document.getElementById('Contact0Email').value;
	/*var subject = document.getElementById('subject').value;*/
	
	if(first_name == "") {

	inlineMsg('Contact0FirstName','You must enter your first name.',5);		
		return false;
	}
	if(last_name == "") {

	inlineMsg('Contact0LastName','You must enter your last name.',5);		
		return false;
	}
	if(email_val == "") {

		inlineMsg('Contact0Email','You must enter your email.',5);
		return false;
	}

	if(!email_val.match(emailRegex)) {
		inlineMsg('Contact0Email','You have entered an invalid email address.',5);
		return false;
	}
	/*if(subject == "") {

	inlineMsg('subject','You must enter a subject.',5);		
		return false;
	}*/

	
	return true;
}

function validateProofForm()
{
	
	var first_name = document.getElementById('Contact2FirstName').value;
	var last_name = document.getElementById('Contact2LastName').value;	
	var email_val = document.getElementById('Contact2Email').value;
	/*var subject = document.getElementById('subject').value;*/
	var yes = document.getElementById('termsYes');
	var no = document.getElementById('termsNo');
	
	
	if(first_name == "") {

	inlineMsg('Contact2FirstName','You must enter your first name.',5);		
		return false;
	}
	if(last_name == "") {

	inlineMsg('Contact2LastName','You must enter your last name.',5);		
		return false;
	}
	if(email_val == "") {

		inlineMsg('Contact2Email','You must enter your email.',5);
		return false;
	}

	if(!email_val.match(emailRegex)) {
		inlineMsg('Contact2Email','You have entered an invalid email address.',5);
		return false;
	}
	if(yes.checked || no.yes)
	{
		
	}else
	{
		inlineMsg('termsYes','You must agree to Proof of Funds Disclosure.',5);		
		return false;	
	}
	
	return true;
} 

function validatePayoffForm()
{
	var first_name = document.getElementById('Contact0FirstName').value;
	var last_name = document.getElementById('Contact0LastName').value;
	var email_val = document.getElementById('Contact0Email').value;
	var phone = document.getElementById('Contact0_BusinessPhone1').value;
	
	
	if(first_name == "") {

	inlineMsg('Contact0FirstName','You must enter your first name.',5);		
		return false;
	}	
	if(last_name == "") {

	inlineMsg('Contact0LastName','You must enter your last name.',5);		
		return false;
	}	
	if(email_val == "") {

		inlineMsg('Contact0Email','You must enter your email.',5);
		return false;
	}

	if(!email_val.match(emailRegex)) {
		inlineMsg('Contact0Email','You have entered an invalid email address.',5);
		return false;
	}
	if(phone == "") {

	inlineMsg('Contact0_BusinessPhone1','You must enter your phone.',5);		
		return false;
	}
	
	if(!phone.match(regPhone)) {

	inlineMsg('Contact0_BusinessPhone1','You must enter a valid phone number (e.g 123-123-1234)',5);		
		return false;
	}
	
	return true;
}

 function validateRegistrationForm() {
	
	var first_name = document.getElementById('fName').value;
	var last_name = document.getElementById('lName').value;
	var email_val = document.getElementById('email').value;
	var password = document.getElementById('password').value;
	var phone = document.getElementById('phone').value;
	
	if(first_name == "") {

	inlineMsg('fName','You must enter your first name.',5);		
		return false;
	}
	
	if(last_name == "") {

	inlineMsg('lName','You must enter your last name.',5);		
		return false;
	}
	if(email_val == "") {

		inlineMsg('email','You must enter your email.',5);
		return false;
	}

	if(!email_val.match(emailRegex)) {
		inlineMsg('email','You have entered an invalid email address.',5);
		return false;
	}
	if(password == "") {

	inlineMsg('password','You must enter password.',5);		
		return false;
	}
	if(phone == "") {

	inlineMsg('phone','You must enter your phone.',5);		
		return false;
	}
	if(!phone.match(regPhone)) {

	inlineMsg('phone','You must enter a valid phone number (e.g 123-123-1234)',5);		
		return false;
	}

	if(document.getElementById('agree').checked == "")
	{		
		inlineMsg('agree','You must approve the Terms of Use.',5);		
		return false
	}

			
	return true;
	
} 


function validateServices(form)
{
	var name = 	document.getElementById('name').value;
	var lName = 	document.getElementById('lName').value;
	var phone = document.getElementById('phone').value;
	var email_val = document.getElementById('email').value;
	var price = document.getElementById('price').value;
	
	if(name == "") {

	inlineMsg('name','You must enter your First name.',5);		
		return false;
	}
	if(lName == "") {

	inlineMsg('lName','You must enter your Last name.',5);		
		return false;
	}
	if(phone == "") {

	inlineMsg('phone','You must enter your phone number.',5);		
		return false;
	}
	if(!phone.match(regPhone)) {

	inlineMsg('phone','You must enter a valid phone number (e.g 123-123-1234)',5);		
		return false;
	}
	if(email_val == "") {

		inlineMsg('email','You must enter your email.',5);
		return false;
	}

	if(!email_val.match(emailRegex)) {
		inlineMsg('email','You have entered an invalid email address.',5);
		return false;
	}
			
	if(price == "") {

	inlineMsg('price','You must enter the price.',5);		
		return false;
	}
	if(!price.match(regPrice)) {

	inlineMsg('price','Please enter a valid Price.',5);		
		return false;
	}
	
	
	return true;
}

function validateClassified()
{
	var address = document.getElementById('Contact0_PropertyClassifiedAddress').value;
	var price = document.getElementById('Contact0_PropertyClassifiedPrice').value;
	var phone = document.getElementById('Contact0_BusinessPhone1').value;
	var email_val = document.getElementById('Contact0Email').value;
/*	var pic_one = document.getElementById('pic_one').value;*/
	
	if(address == "") {

	inlineMsg('Contact0_PropertyClassifiedAddress','You must enter property address.',5);		
		return false;
	}
	if(price == "") {

	inlineMsg('Contact0_PropertyClassifiedPrice','You must enter the price.',5);		
		return false;
	}
	if(!price.match(regPrice)) {

	inlineMsg('Contact0_PropertyClassifiedPrice','Please enter a valid Price.',5);		
		return false;
	}
	if(phone == "") {

	inlineMsg('Contact0_BusinessPhone1','You must enter your phone number.',5);		
		return false;
	}
	if(!phone.match(regPhone)) {

	inlineMsg('Contact0_BusinessPhone1','You must enter a valid phone number (e.g 123-123-1234)',5);		
		return false;
	}
	if(email_val == "") {

		inlineMsg('Contact0Email','You must enter your email.',5);
		return false;
	}

	if(!email_val.match(emailRegex)) {
		inlineMsg('Contact0Email','You have entered an invalid email address.',5);
		return false;
	}
/*	if(pic_one == "") {

		inlineMsg('email','Please upload first image.',5);
		return false;
	}*/
	
	return true;
}


 function validateAdminPropertyForm(form) {

	var city_name = form.city_name.value;
	var purchase_price = form.purchase_price.value;
	var loan_amount = form.loan_amount.value;
	var estimated_value = form.estimated_value.value;
	var exit_startegy = form.exit_strategy.value;
	var mainImage = form.mainImage.value;


	if(city_name == "") {

	inlineMsg('city_name','You must enter city name.',5);		
		return false;
	}
	if(purchase_price == "") {

		inlineMsg('purchase_price','You must enter purchase price.',5);
		return false;
	}
	/*if(isNaN(purchase_price)) {

		inlineMsg('purchase_price','purchase price must be numeric.',5);
		return false;
	}*/
	
		
	if(loan_amount == "") {
		inlineMsg('loan_amount','Please provide loan amount.',5);
		return false;
	}

	/*if(isNaN(loan_amount)) {
		inlineMsg('loan_amount','loan amount must be numeric value.',5);
		return false;
	}
*/

	if(estimated_value == "") {
		inlineMsg('estimated_value','Please provide estimated value.',5);
		return false;
	}

	/*if(isNaN(estimated_value)) {
		inlineMsg('estimated_value','estimated value must be numeric value.',5);
		return false;
	}*/

	if(exit_startegy == "") {
		inlineMsg('exit_strategy','Please provide exit strategy.',5);
		return false;
	}

	if(mainImage == "") {
		inlineMsg('mainImage','Please provide property image.',5);
		return false;
	}
	
	


	return true;
	
} 



 function validateWinPrize(form)
 {
	var name_val = form.name.value;
	var email_val = form.email.value;
	var year_val = form.year.value;


	if(name_val == "") {

	inlineMsg('name','You must enter your full name.',5);		
		return false;
	}
	if(email_val == "") {

		inlineMsg('email','You must enter your email.',5);
		return false;
	}

	if(!email_val.match(emailRegex)) {
		inlineMsg('email','You have entered an invalid email address.',5);
		return false;
	}
	
	if(year_val == "") {
		inlineMsg('year','Please provide your Grad Year at University of Windsor.',5);
		return false;
	}
	
	return true;
}


function validateTellafriendForm(form) {
var fieldCounter = form.addmore_counter.value;

var userName = form.ref_name1.value;
var userEmail = form.ref_address1.value;

	/*if(userName == "") {
		inlineMsg('user_name','You must enter your name.',5);
		return false;
	}
	if(!userName.match(nameRegex)) {
		inlineMsg('user_name','You have entered an invalid name.',5);
		return false;
	}
	if(userEmail == "") {
		inlineMsg('user_email','Please provide your email address.',5);
		return false;
	}
	if(!userEmail.match(emailRegex)) {
		inlineMsg('user_email','You have entered an invalid email address.',5);
		return false;
	}*/

	for(var i = 1; i <= fieldCounter; i++) {
		if(document.getElementById('ref_name'+i)!=null)
		var name = document.getElementById('ref_name'+i).value;
		if(document.getElementById('ref_address'+i)!=null)
		var email = document.getElementById('ref_address'+i).value;
		
		if(name == "") {
			if(document.getElementById('ref_name'+i).name=="ref_name1")
				inlineMsg('ref_name'+i,'You must enter your name.',5);
			else
				inlineMsg('ref_name'+i,'You must enter your friend name.',5);
			return false;
		}
		if(!name.match(nameRegex)) {
			inlineMsg('ref_name'+i,'You have entered an invalid name.',5);
			return false;
		}
		if(email == "") {
			if(document.getElementById('ref_name'+i).name=="ref_name1")
				inlineMsg('ref_address'+i,'Please provide your email address.',5);
			else
				inlineMsg('ref_address'+i,'Please provide your friend\'s email address.',5);
			return false;
		}
		if(!email.match(emailRegex)) {
			inlineMsg('ref_address'+i,'You have entered an invalid email address.',5);
			return false;
		}
	}

var subject = form.subject.value;
var comments = form.comments.value;

	if(subject == "") {
		inlineMsg('subject','You must enter subject line.',5);
		return false;
	}
	
	if(comments == "") {
		inlineMsg('comments','You must enter your comments.',5);
		return false;
	}
	
	
	return true;
} 



 function validatePropertyForm2(form) {
	var first_name = form.txtName.value;
	var email_address = form.txtEmail.value;
	var phone = form.txtPhone.value;


	if(first_name == "") {

	inlineMsg('txtName','You must enter your first name.',5);		
		return false;
	}
	if(phone == "") {
		inlineMsg('txtPhone','Please provide your contact number.',5);
		return false;
	}
	if(email_address == "") {
		inlineMsg('txtEmail','Please provide your email address.',5);
		return false;
	}
	if(!email_address.match(emailRegex)) {
		inlineMsg('txtEmail','You have entered an invalid email address.',5);
		return false;
	}
	
	return true;
	
} 


 function validateApplicationForm(form) {
	var txtBorrowerName = form.txtBorrowerName.value;
	var email_address = form.txtEmail.value;
	var phone = form.txtCellPhone.value;


	if(txtBorrowerName == "") {

	inlineMsg('txtBorrowerName','You must enter your first name.',5);		
		return false;
	}
	if(phone == "") {
		inlineMsg('txtCellPhone','Please provide your contact number.',5);
		return false;
	}
	if(email_address == "") {
		inlineMsg('txtEmail','Please provide your email address.',5);
		return false;
	}
	if(!email_address.match(emailRegex)) {
		inlineMsg('txtEmail','You have entered an invalid email address.',5);
		return false;
	}


			
	return true;
	
} 


 function validatePropertyForm1(form) {
	var name = form.txtName.value;
	var phone = form.txtPhone.value;
	var state = form.state.value;


	if(name == "") {
		inlineMsg('txtName','Please provide your name.',5);
		return false;
	}
	
	if(phone == "") {
		inlineMsg('txtPhone','Please provide your contact number.',5);
		return false;
	}
	if(state == "Select") {
		
		inlineMsg('state','Please select property state.',5);
		return false;
	}

	return true;
	
} 



		
// START OF MESSAGE SCRIPT //

var MSGTIMER = 20;
var MSGSPEED = 5;
var MSGOFFSET = 3;
var MSGHIDE = 3;

// build out the divs, set attributes and call the fade function //
function inlineMsg(target,string,autohide) {

  var msg;
  var msgcontent;
  if(!document.getElementById('msg')) {
    msg = document.createElement('div');
    msg.id = 'msg';
  	msgcontent = document.createElement('div');
    msgcontent.id = 'msgcontent';
    document.body.appendChild(msg);
    msg.appendChild(msgcontent);
    msg.style.filter = 'alpha(opacity=0)';
    msg.style.opacity = 0;
    msg.alpha = 0;
  } else {
    msg = document.getElementById('msg');
    msgcontent = document.getElementById('msgcontent');
  }
  msgcontent.innerHTML = string;
  msg.style.display = 'block';
  var msgheight = msg.offsetHeight;
  var targetdiv = document.getElementById(target);
  targetdiv.focus();
  var targetheight = targetdiv.offsetHeight;
  var targetwidth = targetdiv.offsetWidth;
  var topposition = topPosition(targetdiv) - ((msgheight - targetheight) / 2);
  var leftposition = leftPosition(targetdiv) + targetwidth + MSGOFFSET;
  msg.style.top = topposition + 'px';
  msg.style.left = leftposition + 'px';
  clearInterval(msg.timer);
  msg.timer = setInterval("fadeMsg(1)", MSGTIMER);
  if(!autohide) {
    autohide = MSGHIDE;  
  }
  window.setTimeout("hideMsg()", (autohide * 1000));
}

// hide the form alert //
function hideMsg(msg) {
  var msg = document.getElementById('msg');
  if(!msg.timer) {
    msg.timer = setInterval("fadeMsg(0)", MSGTIMER);
  }
}
function isInteger(s)
{
      var i;
		s = s.toString();
      for (i = 0; i < s.length; i++)
      {
         var c = s.charAt(i);
         if (isNaN(c)) 
	   {
		//alert("Given value is not a number");
		return false;
	   }
      }
      return true;
}

// face the message box //
function fadeMsg(flag) {
  if(flag == null) {
    flag = 1;
  }
  var msg = document.getElementById('msg');
  var value;
  if(flag == 1) {
    value = msg.alpha + MSGSPEED;
  } else {
    value = msg.alpha - MSGSPEED;
  }
  msg.alpha = value;
  msg.style.opacity = (value / 100);
  msg.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 99) {
    clearInterval(msg.timer);
    msg.timer = null;
  } else if(value <= 1) {
    msg.style.display = "none";
    clearInterval(msg.timer);
  }
}

// calculate the position of the element in relation to the left of the browser //
function leftPosition(target) {
  var left = 0;
  if(target.offsetParent) {
    while(1) {
      left += target.offsetLeft;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.x) {
    left += target.x;
  }
  return left;
}

// calculate the position of the element in relation to the top of the browser window //
function topPosition(target) {
  var top = 0;
  if(target.offsetParent) {
    while(1) {
      top += target.offsetTop;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.y) {
    top += target.y;
  }
  return top;
}

// preload the arrow //
if(document.images) {
	
	arrow = new Image(7,80); 
  	arrow.src = "images/msg_arrow.gif"; 
	}