//
//-------------------------------------------------------------------------------------------------------------
function returnhome(home)
{
document.AcceptQuoteForm.action=home;
document.AcceptQuoteForm.submit();
}

//-------------------------------------------------------------------------------------------------------------

function SubmitQuote()
{
	
	if (document.TForm.AlreadySubmitted.value=='false')
	{
		if(checkMandatoryPublicFields())
		{
			document.TForm.AlreadySubmitted.value='true';

			TForm._submit = TForm.submit;
			TForm.submit = function() { if ( validator.validate( this ) ) { this._submit() } };

			//document.TForm.submit();
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		document.TForm.AlreadySubmitted.value='true';
		//alert("The calculation of your quotation is in progress.");
		return false;
	}
	
}

//-------------------------------------------------------------------------------------------------------------

function checkMandatoryPublicFields()
{
var sMsg = '';
var sExtraMsg = '';

// Now Check that the Company fields have been filled in - Company Name, Branch Name 
//
	

	if (document.TForm._CompanyName.value=='')
	{
		sMsg = sMsg + 'Company Name \n';
	}

	if (document.TForm._BranchName.value=='')
	{
		sMsg = sMsg + 'Branch Name \n';
	}

	if (document.TForm._IntroducerUserID.value=='')
	{
		sMsg = sMsg + 'Negotiator \n';
	}
	
	//sMsg = sMsg + '\n';
	
	
	if((document.TForm._BuyingSellingHidden.value == 2) || (document.TForm._BuyingSellingHidden.value == 3))
	{
		document.TForm._SellHouseValue.value = document.TForm._SellHouseValue.value.replace(/,/g, '');
		
		if (document.TForm._BuyingSellingHidden.value == 2)
		{
			document.TForm._BuyHouseValue.value='';	
		}
		document.TForm._NewMortgageAmount.value='';		
		
		//**** checking BUY mandatory fields ****
		if(isNaN(document.TForm._SellHouseValue.value)==true)
		{
			sMsg = sMsg + 'property you are selling must have a valid price \n';
		}
		

		if(document.TForm._SellHouseValue.value == '')
		{
			sMsg = sMsg + 'price of house you are selling \n';
		}

		if(document.TForm._SellFreehold.value == '')
		{
			sMsg = sMsg + 'freehold or leasehold of house you are selling \n';
		}

	}	

	if((document.TForm._BuyingSellingHidden.value == 1) || (document.TForm._BuyingSellingHidden.value == 3))
	{
		sMsg = sMsg + '\n';
		//**** checking BUY mandatory fields ****

		if (document.TForm._BuyingSellingHidden.value == 1)
		{
			document.TForm._SellHouseValue.value='';		
		}
		document.TForm._NewMortgageAmount.value='';		
		
		document.TForm._BuyHouseValue.value = document.TForm._BuyHouseValue.value.replace(/,/g, '');
		if(isNaN(document.TForm._BuyHouseValue.value)==true)
		{
			sMsg = sMsg + 'property you are buying must have a valid price \n';
		}
		

		if(document.TForm._BuyHouseValue.value == '')
		{
			sMsg = sMsg + 'price of house you are buying \n';
		}

		if(document.TForm._BuyFreehold.value == '')
		{
			sMsg = sMsg + 'freehold or feasehold of house you are buying \n';
		}

	}
	
	//**** checking Re-mortgage mandatory fields ****
	if(document.TForm._BuyingSellingHidden.value == 4)
	{	
		document.TForm._BuyHouseValue.value='';	
		document.TForm._SellHouseValue.value='';		
		
		document.TForm._NewMortgageAmount.value = document.TForm._NewMortgageAmount.value.replace(/,/g, '');
		sMsg = sMsg + '\n';
		//**** checking Re-mortgage mandatory fields ****
		if(isNaN(document.TForm._NewMortgageAmount.value)==true)
		{
			sMsg = sMsg + 'a valid amount for your new mortgage \n';
		}
		if(document.TForm._NewMortgageAmount.value == '')
		{
			sMsg = sMsg + 'a re-mortgage amount \n';
		}
			
		if(document.TForm._RemortgageFHLH.value == '')
		{
			sMsg = sMsg + 'freehold or leasehold of House you are re-mortgaging \n';
		}
		
	}

	
	if ((document.TForm._FirstName.value=='')&&(document.TForm._LastName.value==''))
		{
			sMsg = sMsg + 'your first name or last name \n';
		}
	
	
	 var emailaddress = document.getElementById("_EmailAddress").value;
	 if (emailaddress != '')
		{
			var semailreturn = (isvalidemail(emailaddress));
            if (semailreturn != 'valid' )
			{
				sMsg = sMsg + semailreturn + '\n';
			}
		}
	else
	 
		{
			sMsg = sMsg + 'an email address \n';
		}
		
		
	//****** Show message if not completed form	
	
	if((sMsg != '') && (sMsg != '\n') && (sMsg != '\n\n'))
	{
		alert('Please fill in  ...\n' + sMsg);
		return false;
	} 
	else 
	{
		if(sExtraMsg != '')
		{
			alert(sExtraMsg);
			return false;
		} 
		else 
		{
			return true;
		}
	}
}
//-------------------------------------------------------------------------------------------------------------

function CheckMandatoryAcceptInstruct()
{
	var sMsg = '';
	
	if ((document.AcceptQuoteForm._FirstName.value=='')&&(document.AcceptQuoteForm._LastName.value==''))
		{
			sMsg = 'your first name or last name \n';
		}
	
	if ((document.AcceptQuoteForm._HomeTelephoneNo.value=='') && (document.AcceptQuoteForm._WorkTelephoneNo.value=='') && (document.AcceptQuoteForm._MobileTelephoneNo.value==''))
		{
			sMsg = sMsg + 'a contact number \n';
		}
		
	//****** Show message if not completed form	
	if (sMsg != '')
		{
			alert('Please enter ...\n' + sMsg);
			return false;
		} 
	else 
		{
		
			return true;
		}
}


//-------------------------------------------------------------------------------------------------------------

function CheckMandatoryAcceptContact()
{
	var sMsg = '';
	
	if ((document.AcceptQuoteForm._FirstName.value=='')&&(document.AcceptQuoteForm._LastName.value==''))
		{
			sMsg = 'your first name or last name \n';
		}
	//if (document.AcceptQuoteForm._EmailAddress.value=='')
	//	{
	//		sMsg = sMsg + 'your email address \n';
	//	}
	if ((document.AcceptQuoteForm._HomeTelephoneNo.value=='') && (document.AcceptQuoteForm._WorkTelephoneNo.value=='') && (document.AcceptQuoteForm._MobileTelephoneNo.value==''))
		{
			sMsg = sMsg + 'a contact number \n';
		}
		
	//****** Show message if not completed form	
	if (sMsg != '')
		{
			alert('Please enter ...\n' + sMsg);
			return false;
		} 
	else 
		{
			document.AcceptQuoteForm._Comments.value = 'Please contact client';
			return true;
		}
}





