///------------------------------------------------------------------------------------------------

function printWebPage()
				{
				if (window.print) window.print();
				}
///------------------------------------------------------------------------------------------------

function validatePage()
{
//alert("page has been validated");
document.TForm.submit();
}
///------------------------------------------------------------------------------------------------

function checkDisabled(sel) 
{

    var opt = sel.options[sel.selectedIndex];
    if (opt.className == "grey") 
    {
            //sel.selectedIndex = -1;
            alert('This Law Firm cannot accept any more cases');
            return false;
    }
    document.TFormPanel.submit();
    return true;

}
///------------------------------------------------------------------------------------------------
function resubmitTFormCOToSearch()
{
	document.TForm1.BranchCode.value='';
	document.TForm1.action='RecommenderSearchQuote.asp';
	document.TForm1.submit();
}
///------------------------------------------------------------------------------------------------
function resubmitTFormBR()
{
	
	document.TForm1.action='RecommenderSearchQuote.asp';
	document.TForm1.submit();
}
///------------------------------------------------------------------------------------------------
function setFocus()
{
	document.TForm._Title.focus();
}
///------------------------------------------------------------------------------------------------
function CheckMandatoryAcceptFields()
{
	var sMsg = '';
	var sMsg2 = '';
	var sMsg3 = '';
	
	if (document.TForm.AlreadySubmitted.value=='false')
	{
		
			if ((document.TForm._FirstName.value=='') && (document.TForm._LastName.value==''))
				{
					sMsg = 'your first name and last name \n';
				}
			if ((document.TForm._HomeTelephoneNo.value=='') && (document.TForm._WorkTelephoneNo.value=='') && (document.TForm._MobileTelephoneNo.value==''))
				{
					sMsg = sMsg + 'contact number \n';
				}

			if ((document.TForm._EmailAddress.value=='') && (document.TForm._NoEmailAddress_1.checked!=true))
				{
					sMsg = sMsg + 'either your email address or check the No Email box \n';
				}

			//Validation for second client - if the firstname and last names are filled out
			if ((document.TForm._FirstName_2.value!='') || (document.TForm._LastName_2.value!=''))
			{
				if (document.TForm._Title_2.value=='')
				{
					sMsg2 = sMsg2 + 'title \n';
				}
				if ((document.TForm._HomeTelephoneNo_2.value=='') && (document.TForm._WorkTelephoneNo_2.value=='') && (document.TForm._MobileTelephoneNo_2.value==''))
				{
					sMsg2 = sMsg2 + 'contact number \n';
				}
				if ((document.TForm._EmailAddress_2.value=='') && (document.TForm._NoEmailAddress_2.checked!=true))
				{
					sMsg2 = sMsg2 + 'either your email address or check the No Email box \n';
				}
			}
			if ((document.TForm._BuyingSelling.value=='2') || (document.TForm._BuyingSelling.value=='3'))
			{
				if ((document.TForm._BuyerFound[0].checked==false)&&(document.TForm._BuyerFound[1].checked==false))
					{
						sMsg3 = '\nHas a buyer been found?\n';
					} 
			}
			
			var semailreturn ='';    
             
			if (document.TForm._EmailAddress.value!='')
            {
                semailreturn = (isvalidemail(document.TForm._EmailAddress.value))
             
                if (semailreturn !='valid')
                   {
                        sMsg = sMsg +  semailreturn + '\n';
                   }
            }  
            
            semailreturn = '';
            if (document.TForm._EmailAddress_2.value!='')
            {
                semailreturn = (isvalidemail(document.TForm._EmailAddress_2.value))
              
                if (semailreturn !='valid')
                   {
                        sMsg2 = sMsg2 +  semailreturn + '\n';
                   }
            }  
	
			//****** Show message if not completed form	
			
			if (sMsg != '')
				{
					sMsg = 'Please complete the following for Client 1 ...\n' + sMsg + ' \n';
				}
			if (sMsg2 != '')
				{
					sMsg2 = 'Please complete the following for Client 2 ...\n' + sMsg2;
				}
				
			sMsg = sMsg + sMsg2 +sMsg3;
			if (sMsg != '')
				{
					alert(sMsg);		
					return false;
				} 
			else 
				{
					document.TForm.AlreadySubmitted.value='true';
					return true;
				}
	}
	else
	{
		document.TForm.AlreadySubmitted.value='true';
		//alert("The calculation of your quotation is in progress.");
		return false;
	}
}
///------------------------------------------------------------------------------------------------
function LimitTextAreaSize()
{
if (document.TForm._Comments.value.length > 501)
	alert("You have reached the limit of the amount of text you can enter");
if (document.TForm._Comments.value.length > 500)
	document.TForm._Comments.value = document.TForm._Comments.value.substring(0,500);
}
///------------------------------------------------------------------------------------------------
function TextAreaSizeLimit(sfieldname,ilimit)
{
	var formfield = document.getElementById(sfieldname);
	if (formfield.value.length > ilimit+1)
		alert("You have reached the limit of the amount of text you can enter");
	if (formfield.value.length > ilimit)
		formfield.value = formfield.value.substring(0,ilimit);
		
}

///------------------------------------------------------------------------------------------------

function CreateQuoteLookup()
{
	document.TForm.action="../../asp/QuoteUser/CreateQuote.asp";
	document.TForm.submit();
}
///------------------------------------------------------------------------------------------------
function CreateQuoteViewMaster()
{
	
	if (document.TForm.AlreadySubmitted.value=='false')
	{
				
		if (document.TForm._QuotationStatus.value==5)
		{
			alert("This Quote has been Declined and the status will remain as Declined");
		}
		
	    if(checkMandatoryFields()){
	    
			if ((document.TForm._PanelQuote.value=='Y')&&(document.TForm._FeeScaleType.value=='D')&&(document.TForm._ExternalAdminInstruct.value!='Y'))
			{
			
				if (document.TForm._LawFirmsAvailable)
				{
					if (document.TForm._LawFirmsAvailable.value=='Y')
					{

						if ((document.TForm._PanelQuoteType[0].checked==false)&&(document.TForm._PanelQuoteType[1].checked==false)&&(document.TForm._PanelQuoteType[2].checked==false))
						{
							alert("Please select the type of quotation");
							return false;
						}
					}
				}
			}

			if ((document.TForm._UserType.value=='3'||document.TForm._UserType.value=='2')&&(document.TForm._IntroducerUserID.value=='0')&&(document.TForm._QuotationRefCode.value=='')&&(document.TForm._BuyingSelling.value!='5'))
			{
				if (document.TForm._RegisteredForRewards.value=='Y')
				{
					var msg = "Have you registered for MHM Rewards? If so click 'Cancel', select your name and request your quote again."
				    	msg = msg + '\n'
					var r = confirm(msg);
					if (r==false)
						{ return false; }
				
				}
			
			}
			
			document.TForm.AlreadySubmitted.value='true';
			document.TForm.action="../../asp/QuoteUser/CreateQuote.asp";
			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 showBuySell(sItem,sStatus)
{ 
	eval("document.getElementById('" + sItem + "').style.visibility=" + "'" + sStatus + "';");
}
///------------------------------------------------------------------------------------------------
function setBuySellHidden(iNo)
{
	// sets hidden variable value for submitssion validation
	document.TForm._BuyingSellingHidden.value = iNo;
}
///------------------------------------------------------------------------------------------------
function flatFreeholdWarning()
{
	alert('Please Note that Flats are RARELY Freehold');
}
///------------------------------------------------------------------------------------------------

function setDisabledAddressOnLoad()
{
//**** First look at SELL.  If has postcode then do not disable.
if (document.TForm._Postcode)
	{
		if(document.TForm._Postcode.value!='')
		{
			disableAddresses("SELL", false);
		} else {
			disableAddresses("SELL", true);
		}
	}
//**** Second look at BUY.  If has postcode then do not disable.
if (document.TForm._BuyPostcode)
	{
		if(document.TForm._BuyPostcode.value!='')
		{
			disableAddresses("BUY", false);
		} else {
			disableAddresses("BUY", true);
		}
	}

}
///------------------------------------------------------------------------------------------------

function disableAddresses(sType, bDisable)
{
if(sType=="SELL")
{
	document.TForm._AddressLine1.disabled=bDisable;
	document.TForm._AddressLine1.style.bgColor = "grey";

	document.TForm._AddressLine2.disabled=bDisable;
	document.TForm._AddressLine3.disabled=bDisable;
	document.TForm._Town.disabled=bDisable;
	document.TForm._Postcode.disabled=bDisable;
}
if(sType=="BUY")
{
	document.TForm._BuyAddressLine1.disabled=bDisable;
	document.TForm._BuyAddressLine2.disabled=bDisable;
	document.TForm._BuyAddressLine3.disabled=bDisable;
	document.TForm._BuyTown.disabled=bDisable;
	document.TForm._BuyPostcode.disabled=bDisable;
}
if(sType=="REMO")
{
	document.TForm._AddressLine1.disabled=bDisable;
	document.TForm._AddressLine1.style.bgColor = "grey";

	document.TForm._AddressLine2.disabled=bDisable;
	document.TForm._AddressLine3.disabled=bDisable;
	document.TForm._Town.disabled=bDisable;
	document.TForm._Postcode.disabled=bDisable;
}
}
///------------------------------------------------------------------------------------------------

//**** LOOK FOR DISTRICT
function openDistrictcodeSearch(buysell)
{

if(buysell=="BUY")
{
	window.open('../../asp/PostalLookUp/PostalDistrictLookup.asp?Place=' + document.TForm._BuyTown.value,'BUY',
			'left=50,top=50,width=500,scrollbars,height=250;');
} 
else 
{
	window.open('../../asp/PostalLookUp/PostalDistrictLookup.asp?Place=' + document.TForm._Town.value,'SELL',
				'left=50,top=50,width=500,scrollbars,height=250;');
}
}	

///------------------------------------------------------------------------------------------------
function openPostcodeSearch(lookuptype,postcode,addressline1,addressline2,addressline3,town,winname)
{
	var sURL;
	if(lookuptype=='POSTCODE')
	{
		sURL = '../../asp/PostalLookUp/PostcodeSearchLookup.asp';
 	} else {
 		sURL = '../../asp/PostalLookUp/PostcodeAddressLookup.asp';
 	}	
	
	window.open(sURL + '?_Postcode=' + postcode 
		+ '&_AddressLine1=' + addressline1 + '&_AddressLine2=' + addressline2
		+ '&_AddressLine3=' + addressline3+ '&_Town=' + town,winname,
		'left=50,top=50,width=500,scrollbars,height=300;');

}	
///------------------------------------------------------------------------------------------------
function openAFDSearch(lookuptype,postcode,addressline1,addressline2,addressline3,town,winname)
{
	var sURL;
	sURL = '../../asp/PostalLookUp/AFDAddressLookup.asp';

 	
	window.open(sURL + '?_Postcode=' + postcode 
		+ '&_AddressLine1=' + addressline1 + '&_AddressLine2=' + addressline2
		+ '&_AddressLine3=' + addressline3+ '&_Town=' + town+ '&_BuyingSelling=' + winname,winname,
		'left=50,top=50,width=500,scrollbars,height=550;');

}	
///------------------------------------------------------------------------------------------------
function Mandatoryfields()
{
	var sMsg = '';
	var sIntroCode;
	
		if ((document.TForm._cCompanyName.value=='')||(document.TForm._cBranchName.value==''))
		{
			sMsg = sMsg + '\n';
			sMsg = sMsg + 'Please ensure you select both a company and a branch. \n';
			sMsg = sMsg + '\n';
			alert(sMsg);
			return false;
		}
		else
		{
			document.TForm._cIntroducerCode.value = document.TForm._cIntroducerCode.value + '-' + document.TForm._cBranchCode.value;
			
			if (document.TForm._cBuyingSelling.value=='4')
			{
				document.TForm.action="../../asp/QuoteUser/makeRemortgageQuote.asp?QuotationRequestID=" + escape(document.TForm._cQuotationRequestID.value) + "&IntroducerCode=" + escape(document.TForm._cIntroducerCode.value) + "&QuotationRefCode=" + escape(document.TForm._cQuotationRefCode.value);				
			}
			else
			{
				document.TForm.action="../../asp/QuoteUser/MakeMasterQuote.asp?QuotationRequestID=" + escape(document.TForm._cQuotationRequestID.value) + "&IntroducerCode=" + escape(document.TForm._cIntroducerCode.value) + "&QuotationRefCode=" + escape(document.TForm._cQuotationRefCode.value) + "&BuyingSelling=" + escape(document.TForm._cBuyingSelling.value);				
			}
			document.TForm.submit();	
			return true;
		}
}
///------------------------------------------------------------------------------------------------///////////////////////////////////////////////////////////////////////////////////////////
function SearchMandatoryfields()
{
	var sMsg = '';
	var sIntroCode;
	
		
		if ((document.TForm._LoginCompanyType.value=='SO')||(document.TForm._UserType.value=='2'))
		{
			if (document.TForm._CompanyName.value=='')
				{
					sMsg = sMsg + '\n';
					sMsg = sMsg + 'Please ensure you select a company. \n';
					sMsg = sMsg + '\n';
					alert(sMsg);
					return false;
				}
		}
		else
		{
			if (document.TForm._UserType.value=='3')
			
			if ((document.TForm._CompanyName.value=='')||(document.TForm._BranchName.value==''))
			{
				sMsg = sMsg + '\n';
				sMsg = sMsg + 'Please ensure you select both a company and a branch. \n';
				sMsg = sMsg + '\n';
				alert(sMsg);
				return false;
			}
		}
			if (document.TForm._BranchName.value=='')
			{
				document.TForm._IntroducerCode.value = document.TForm._IntroducerCode.value.substring(0,4);
			}
			document.TForm.action="../../asp/" + escape(document.TForm._OriginReport.value) + "?CompanyName=" + escape(document.TForm._CompanyName.value) + "&BranchName=" + escape(document.TForm._BranchName.value) + "&IntroCode=" + escape(document.TForm._IntroducerCode.value) + "&LoginIntroCode=" + escape (document.TForm._LoginIntroCode.value) + "&SolicitorID=" + escape(document.TForm._SolicitorID.value) + "&IntroducerCode=" + escape(document.TForm._IntroducerCode.value) ;				
			document.TForm.submit();	
			return true;
		
		
}

///------------------------------------------------------------------------------------------------
function ClearLookupFields2()
{
	if ((document.TForm._LoginCompanyType.value=='SO')||(document.TForm._UserType.value=='5'))
	{
		document.TForm._CompanyName.value='';
		document.TForm._BranchName.value='';
	}
	else
	{
		document.TForm._BranchName.value='';
	}
}

///------------------------------------------------------------------------------------------------
function CallLookup()
{
	document.TForm1.action="../../asp/UserManagement/CompanyBranchLookup2.asp?IntroducerCode=" + escape(document.TForm1._IntroducerCode.value);
	document.TForm1.submit();	
}
///------------------------------------------------------------------------------------------------
function checkcompany()
{
	var sMsg = '';
	
	sMsg = sMsg + '\n';
	if(document.TForm._CompanyName.value=='' && document.TForm._BranchName.value!='')
		{
			sMsg = 'Please enter a Company name \n';
			alert(sMsg);
			return false;
				}
	else { return true;}
}
///------------------------------------------------------------------------------------------------
function checkregisterfields()
{
	var sMsg = '';
	
	sMsg = sMsg + '\n';
	if(document.TForm.EmailAddress.value=='' && document.TForm.Telephone.value=='' && document.TForm.Mobile.value=='')
		{
			sMsg = 'Please fill in an email address or a contact number. \n';
			alert(sMsg);
			return false;
				}
	else { 
			
			return true;}
}
///------------------------------------------------------------------------------------------------
function checksolicitor()
{
	var sMsg = '';
	
	sMsg = sMsg + '\n';

	if (document.getElementById("_PanelLawFirm")!=null)
	{
	

		if(document.TFormPanel._PanelLawFirm.value=='')
		{
			sMsg = 'Please select a Law Firm. \n';
			alert(sMsg);
			return false;
				}
		else { 
			
			return true;}
	}
	else
	{
		return true;
	}
}

///------------------------------------------------------------------------------------------------

function openquotePDFwindow(quotationrequestid,quotationrefcode,introducercode,brand,quotetypeselected)
{
	var sURL = '';

	sURL='http://v2.mhmservices.net/quoteservices/quotations/DisplayQuotationPDF.aspx';
	//sURL='http://www.mhmtest4.co.uk/quoteservices/quotations/DisplayQuotationPDF.aspx';

	
	window.open(sURL + '?Quotationrequestid=' + escape(quotationrequestid) + '&Introducercode=' + escape(introducercode) + '&brand=' + escape(brand) + '&quotetypeselected=' + escape(quotetypeselected));

	
}

///------------------------------------------------------------------------------------------------


function submitvalidatelogin()
{

	var sMsg = '';
		
	if  (document.TForm._LoginIntroducerUserID)
	{

		var userid = document.TForm._LoginIntroducerUserID.value
		
		if (userid == '')
		
		{
			sMsg = sMsg + '\n';
			sMsg = sMsg + 'Please select your user name. \n';
			sMsg = sMsg + '\n';
		}
	}
	
	if (sMsg != '')
		{
			alert(sMsg);		
			return false;
		} 
	else 
		{
			document.TForm.action="/asp/Login/ValidateLogin.asp";
			document.TForm.submit();
			return true;
		}
}

//------------------------------------------------------------------------------------------------

function setfocusonfield(fieldname)
{
    var focusfield = document.getElementByID('AccessPassword'); 
   
    if (focusfield != null) {
        focusfield.focus();
      }
 }
 
//------------------------------------------------------------------------------------------------
function validateemailaddress(emailaddress)
{
	 var semailreturn = '';
	 
     if (emailaddress!='')
            {
                semailreturn = (isvalidemail(emailaddress))
              
                if (semailreturn !='valid')
                   {
                        alert(semailreturn);
                        return false;
                   }
            }  
     return true;
}
 
 
//------------------------------------------------------------------------------------------------

function isvalidemail(emailaddress)
{

		var at="@"
		var dot="."
		var dotdot=".."
		var lat=emailaddress.indexOf(at)
		var lstr=emailaddress.length
		var ldot=emailaddress.indexOf(dot)
		var l2dot=emailaddress.indexOf(dotdot)
		
		if (emailaddress.indexOf(at)==-1){
		   return 'The email address must contain an @'
		}
		
		if (emailaddress.indexOf(at)==-1 || emailaddress.indexOf(at)==0 || emailaddress.indexOf(at)+1==lstr){
		   return 'The email address has an invalid format'
		  
		}

		if (emailaddress.indexOf(dot)==-1 )		{
		    return 'The email address must contain a .'
		    
		}
		
		if (emailaddress.indexOf(dotdot)!=-1 )		{
		    return 'The email address cannot contain ..'
		    
		}
		
		if(emailaddress.indexOf(dot)==0 || emailaddress.indexOf(dot)+1==lstr){
		    return 'The email address cannot start or end with .'
		    
		}

		 if (emailaddress.indexOf(at,(lat+1))!=-1){
		    return 'The email address is incomplete'
		 }

		 if (emailaddress.substring(lat-1,lat)==dot || emailaddress.substring(lat+1,lat+2)==dot){
		    return 'The email address is invalid'
		 
		 }
		
		 if (emailaddress.indexOf(" ")!=-1){
		    return 'The email address cannot have a space.'
		    
		 }
		 
		 return 'valid'
			
	}

//---------------------------------------------------------------------------

function validateepcfields()
{
	var sMsg = '';
	var sMsg2 = '';
	
		if ((document.TForm._AddressLine1.value=='')&&(document.TForm._AddressLine2.value=='')&&(document.TForm._AddressLine3.value=='')&&(document.TForm._Town.value=='')&&(document.TForm._Postcode.value==''))
		{
			sMsg = sMsg + 'Property address \n';
		
		}
			
		if (document.TForm._SellerFullName.value=='')
		{
			sMsg = sMsg + 'Sellers name \n';
		
		}
		if ((document.TForm._SellerWorkTelephone.value=='')&&(document.TForm._SellerTelephone.value=='')&&(document.TForm._SellerMobile.value==''))
		{
			
			sMsg = sMsg + 'At least one of the following: Seller telephone, work telephone or mobile \n';
		
		}
		
		var semailreturn ='';    
             
		if (document.TForm._SellerEmail.value!='')
        {
            semailreturn = (isvalidemail(document.TForm._SellerEmail.value));
            
            if (semailreturn !='valid')
                {
                    sMsg = sMsg +  semailreturn + '\n';
                }
        }  
		
		
		if (sMsg != '')
		{
			sMsg = 'Please fill in the following fields: \n\n' + sMsg;
			alert(sMsg);		
			return false;
		} 
		else 
		{
			
			return true;
		}
	
}
