//
//-------------------------------------------------------------------------------------------------------------

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';
            }          
           

            newwindow=window.open(sURL + '?_Postcode=' + postcode 
                        + '&_AddressLine1=' + addressline1 + '&_AddressLine2=' + addressline2
                        + '&_AddressLine3=' + addressline3+ '&_Town=' + town,winname,
                        'left=50,top=50,width=600,scrollbars,height=400;');
			if (window.focus) {newwindow.focus()}

}


function checkPage()

{
	xxx;
	alert(Page_IsValid);
	
	//if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate();
	

}

function validatePage()
{
//alert("page has been validated");
document.TForm.submit();
}
//-------------------------------------------------------------------------------------------------------------

function returnhome(home)
{
document.AcceptQuoteForm.QuoteMode.value='';
document.AcceptQuoteForm.action=home;
document.AcceptQuoteForm.submit();
}

//-------------------------------------------------------------------------------------------------------------

function formValidator()

{
		alert('hello');
		document.all.divError.style.display='inline';
		//Page_ClientValidate();
}

function SubmitQuote()
{
		
	if (document.TForm._QuotationStatus.value==5)
	{
		alert("This Quote has been Declined and the status will remain as Declined");
	}
	
	
	if(checkMandatoryFields()){
	
		document.TForm.submit();
		return true;
		}else{
		return false;
	}
}
//-------------------------------------------------------------------------------------------------------------

// make sure header looks good in IE5
function showHeadingTH()
{
//document.all.titleTH.style.visibility='visible';
//document.all.titleTH.innerHTML = document.all.titleTH.innerHTML; 
}
//-------------------------------------------------------------------------------------------------------------

function showhide(sItem,sStatus)
{ 
	eval("document.all." + sItem + ".style.display=" + "'" + sStatus + "';");
	//eval("document.all." + 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 LimitTextAreaSize()
{

if (document.TForm)
	{
	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);
	}
if (document.AcceptQuoteForm)
	{
	if (document.AcceptQuoteForm._Comments.value.length > 501)
		alert("You have reached the limit of the amount of text you can enter");
	if (document.AcceptQuoteForm._Comments.value.length > 500)
		document.AcceptQuoteForm._Comments.value = document.AcceptQuoteForm._Comments.value.substring(0,500);
	}

}


//-------------------------------------------------------------------------------------------------------------

function checkMandatoryFields()
{
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 Leasehold 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';
		}
	
	if (document.TForm._EmailAddress.value=='')
		{
			sMsg = sMsg + 'an email address \n';
		}
		
	//****** Show message if not completed form	
	
	if((sMsg != '') && (sMsg != '\n') && (sMsg != '\n\n'))
	{
		alert('You have not filled out ...\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;
		}
}




