function dispmess(){
	
	var agree=confirm("Click 'OK' to confirm you wish to proceed with the discounted loan offer and send us the required documents and cheques.");

if (agree){
	return true;
}
else{
return false;
}
}

function print_text(){

            text = document.Form.fldTextbox.value;

var text = text.replace(

new RegExp( "\\n", "g" ), "<br>");


            winId = window.open('','newwin');
            with(winId.document){
                write('<body onLoad="window.focus();window.print()"><table width="600" border="0" cellpadding="0"><tr><td><p><a href="javascript:window.close()">When printing has finished, click here to close his window.</a></p><p>'+text+'</p></td></tr></table><\/body>');
                close();
        }
}

function checkScrolled() {	
	
	myTextArea = document.Form.fldTextbox
	tc = document.Form.Tc_agree.value
		
	maxScroll = myTextArea.scrollHeight	
	currentScroll = myTextArea.scrollTop + myTextArea.clientHeight
	
		if (currentScroll == maxScroll) {	
			
			document.Form.Tc_agree.disabled = false;	
			
			} else {	
				
				document.Form.Tc_agree.disabled = true;	
				
				}	
			if (tc=="Yes") {	
			
			document.Form.Tc_agree.disabled = false;	
			
			}
				
				window.setTimeout("checkScrolled()",500); 
				
				}

function show_button(){

tc = document.Form.Tc_agree.value;

if(tc=="Yes"){

document.getElementById('but').style.display = 'block';

}else{

document.getElementById('but').style.display = 'none';

}

}



function chkemailcon(){

email = document.Form.email.value;

email1 = document.Form.email1.value;

if(email!="" && email1!=""){

if(email!=email1){

alert("Both email address fields must match. Please check and amend. Thank you.");

}
}

}

function showadd(){
	
Main_address1 = document.Form.Main_address1.value;

	document.Form.Main_address1.disabled=false;
	document.Form.Main_address2.disabled=false;
	document.Form.Main_address3.disabled=false;
	document.Form.Main_address4.disabled=false;
	
}


function newWin() { var w_who = window.open("","1","location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=518,height=400"); w_who.focus() }

function chk()
	{
var agree=confirm("Click 'OK' to submit the application or 'Cancel' to return without submitting it.");

if (agree){
	return true;
}
else{
return false;
}
	}

function open_pcode(box)
	{
var box = "pcode.php?" + box;
new_window=window.open(box,"pcode","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width=350,height=200");
	}

function button(){
var agree=confirm("Are you sure you want to leave this page?\n\nClick 'OK' to continue.\n\nClick 'Cancel' to stay on this page.");

if (agree){
	return true;
}
else{
return false;
}
	}


function checkPostCode (toCheck) {

  // Permitted letters depend upon their position in the postcode.
  var alpha1 = "[abcdefghijklmnoprstuwyz]";                       // Character 1
  var alpha2 = "[abcdefghklmnopqrstuvwxy]";                       // Character 2
  var alpha3 = "[abcdefghjkstuw]";                                // Character 3
  var alpha4 = "[abehmnprvwxy]";                                  // Character 4
  var alpha5 = "[abdefghjlnpqrstuwxyz]";                          // Character 5
  

  // Array holds the regular expressions for the valid postcodes
  var pcexp = new Array ();

  // Expression for postcodes: AN NAA, ANN NAA, AAN NAA, and AANN NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1,2})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Expression for postcodes: ANA NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}[0-9]{1}" + alpha3 + "{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));

  // Expression for postcodes: AANA  NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1}" + alpha4 +"{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Exception for the special postcode GIR 0AA
  pcexp.push (/^(GIR)(\s*)(0AA)$/i);
  
  // Standard BFPO numbers
  pcexp.push (/^(bfpo)(\s*)([0-9]{1,4})$/i);
  
  // c/o BFPO numbers
  pcexp.push (/^(bfpo)(\s*)(c\/o\s*[0-9]{1,3})$/i);

  // Load up the string to check
  var postCode = toCheck;

  // Assume we're not going to find a valid postcode
  var valid = false;
  
  // Check the string against the types of post codes
  for ( var i=0; i<pcexp.length; i++) {
    if (pcexp[i].test(postCode)) {
    
      // The post code is valid - split the post code into component parts
      pcexp[i].exec(postCode);
      
      // Copy it back into the original string, converting it to uppercase and
      // inserting a space between the inward and outward codes
      postCode = RegExp.$1.toUpperCase() + " " + RegExp.$3.toUpperCase();
      
      // If it is a BFPO c/o type postcode, tidy up the "c/o" part
      postCode = postCode.replace (/C\/O\s*/,"c/o ");
      
      // Load new postcode back into the form element
      valid = true;
      
      // Remember that we have found that the code is valid and break from loop
      break;
    }
  }
  
  // Return with either the reformatted valid postcode or the original invalid 
  // postcode
  if (valid) {return postCode;} else return false;
}

function chkform(){

msg = "There appears to be a problem with: ";

Main_address1 = document.Form.Main_address1.value;

Main_postcode = document.Form.Main_postcode.value;

App1_lastname = document.Form.App1_lastname.value;

App2_lastname = document.Form.App2_lastname.value;

App1_dob_date = document.Form.App1_dob_date.value;

App1_dob_month = document.Form.App1_dob_month.value;

App1_dob_year = document.Form.App1_dob_year.value;

App2_dob_date = document.Form.App2_dob_date.value;

App2_dob_month = document.Form.App2_dob_month.value;

App2_dob_year = document.Form.App2_dob_year.value;

if(Main_address1=="" || Main_postcode==""){

msg = msg + "Blank Address; ";

}

  if (checkPostCode (Main_postcode)) {
    document.Form.Main_postcode.value = checkPostCode (Main_postcode);

  } else{
msg = msg + "Invalid Postcode; ";
};

if(App1_lastname==""){

msg = msg + "Blank Applicant 1 Name; ";

}


if(App1_dob_date=="None" || App1_dob_month=="None" || App1_dob_year=="None"){

msg = msg + "Blank Applicant 1 DOB; ";

}

if(App2_lastname!="" && (App2_dob_date=="None" || App2_dob_month=="None" || App2_dob_year=="None")){

msg = msg + "Blank Applicant 2 DOB; ";

}


if(msg!="There appears to be a problem with: "){

alert (msg);

return false;
}else{

if(App2_lastname==""){
var agree=confirm("Click 'OK' to submit the application as a SINGLE application or 'Cancel' to return and enter Applicant 2 details.");

if (agree){
	return true;
}
else{
return false;
}
}
return true;

}
}


function chkform2(){

msg = "There appears to be a problem with: ";
out = document.Form1.call_outcome.value;


if(out=="None Selected"){

msg = msg + "Blank Call Result; ";

}


if(msg!="There appears to be a problem with: "){

alert (msg);


document.Form1.call_outcome.focus();

return false;
}else{

return true;

}
}

function chkemail(){
chk=document.Form.email.checked;
if(chk=="FALSE" || chk==""){
msg = "You have chosen to not have this saved lead sent to you as an email link. Click 'OK' to continue or 'Cancel' to amend the checkbox.";
var agree=confirm(msg);

if (agree)
	return true ;
else
	return false ;
}

}

function select(){
chk=document.Form1.call_outcome.value;
if(chk=="DO NOT CALL AGAIN"){
document.getElementById('moreinfo').style.display = 'block';
}else{
document.getElementById('moreinfo').style.display = 'none';
}

}

function swap_panel(){
document.getElementById('telno').style.display = 'none';
document.getElementById('address').style.display = 'block';
}

function swap_panel_back(){
document.getElementById('telno').style.display = 'block';
document.getElementById('address').style.display = 'none';
}

function swap_button(){
document.getElementById('button2').style.display = 'none';
document.getElementById('button3').style.display = 'block';
document.getElementById('button4').style.display = 'block';
document.getElementById('button1').style.display = 'none';
document.getElementById('call_outcome').style.display = 'block';
}

function swap_button_back(){
document.getElementById('button2').style.display = 'block';
document.getElementById('button3').style.display = 'none';
document.getElementById('button4').style.display = 'none';
document.getElementById('button1').style.display = 'block';
document.getElementById('call_outcome').style.display = 'none';
}

function select_dnc(){
document.Form1.call_outcome.value="WARNING - Do Not Contact";
}

function HandlePostcode(cOrgName,
                        cDeptName,
                        cThoroughfareName,
                        cThoroughfareType,
                        cLevel1Suburb,
                        cLevel2Suburb,
                        cLocality,
                        cDPS,
                        cLine1,
                        cLine2,
                        cLine3,
                        cLine4,
                        cLine5,
                        lSmallUser,
                        nHouseholds,
                        cPostcode)
{
  
   document.Form.elements["Main_address1"].value=cLine1;
   document.Form.elements["Main_address2"].value=cLine2;
   document.Form.elements["Main_address3"].value=cLine3;
   document.Form.elements["Main_address4"].value=cLine4;
   document.Form.elements["Main_postcode"].value=cPostcode;

}

function HandlePostcode1(cOrgName,
                        cDeptName,
                        cThoroughfareName,
                        cThoroughfareType,
                        cLevel1Suburb,
                        cLevel2Suburb,
                        cLocality,
                        cDPS,
                        cLine1,
                        cLine2,
                        cLine3,
                        cLine4,
                        cLine5,
                        lSmallUser,
                        nHouseholds,
                        cPostcode)
{
  
   document.Form.elements["First_previous_address1"].value=cLine1;
   document.Form.elements["First_previous_address2"].value=cLine2;
   document.Form.elements["First_previous_address3"].value=cLine3;
   document.Form.elements["First_previous_address4"].value=cLine4;
   document.Form.elements["First_previous_postcode"].value=cPostcode;

}

function HandlePostcode2(cOrgName,
                        cDeptName,
                        cThoroughfareName,
                        cThoroughfareType,
                        cLevel1Suburb,
                        cLevel2Suburb,
                        cLocality,
                        cDPS,
                        cLine1,
                        cLine2,
                        cLine3,
                        cLine4,
                        cLine5,
                        lSmallUser,
                        nHouseholds,
                        cPostcode)
{
  
   document.Form.elements["Second_previous_address1"].value=cLine1;
   document.Form.elements["Second_previous_address2"].value=cLine2;
   document.Form.elements["Second_previous_address3"].value=cLine3;
   document.Form.elements["Second_previous_address4"].value=cLine4;
   document.Form.elements["Second_previous_postcode"].value=cPostcode;

}

function chkfrl900(){

msg = "";

dte = document.Form.date.value;

lead = document.Form.lead.value;

if(lead=="None"){

msg = "Please select a lead generator; ";

}

if(dte==""){

msg= msg+"Please select an application date; ";

}

if(msg!=""){

alert (msg);

return false;
}else{

return true;
}

}

