

function generateform() {

var formdiv,content,nameU,emailU,sname,fname;
sname=""; fname="";
var theForm = document.form1;
formdiv=document.getElementById("multipleform");

var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);



content='<div id="Warning_mess"  style="display:none;"><table cellSpacing=0 cellPadding=0 align=center bgColor=#ffffff  border=0><tr><td  borderColor=#ffffff class="stylewarn">Please correct the highlighted items to continue</td></tr></table></div>';
				
content+='<form id="form1" name="form1"  method="post" action="files/processPFL_plat.php5">';

// -------Step1 Case Details--------
content+='<div id="step1" style="display:block">';

	content+='<table cellSpacing="0" cellPadding="5" align="center" bgColor="#ffffff"  border="0"><tr><td  borderColor="#ffffff">';
	content+='<table align="center" bgColor="#ffffff" collspanning="0" cellspaning="0">';
	content+='<tr><td  align="center" colspan="6" height="25px" background="Images/bggrey.gif" class="fHeadM">Tell us how you want to grow your business</td></tr>';

    content+='<tr><td height="5px" colspan="3">&nbsp;</td></tr>';

if (browser=="Microsoft Internet Explorer"){
	content+='<tr><td height="20px" class="text" colspan="3">&nbsp;Where are you looking for new clients?</td></tr><tr><td class="text"><input id="radio1" type="radio" value="National" name="clientLocation" onClick="ClientLocation()" onChange=this.style.background="#ffffff"> National</td><td align="left" class="text"><input id="radio2" type="radio" value="Local" name="clientLocation" onClick="ClientLocation()" onChange=radio1.style.background="#ffffff"> Local</td></tr>';
	content+='<tr><td style="display:none" id="LocalDetailsbox" class="text" colspan="2">Please specify locality&nbsp;<input type="text" name="LocalDetails" id="LocalDetails" size="40" onChange=this.style.background="#ffffff"></td></tr>';
}

if (browser=="Netscape"){
	content+='<tr><td height="20px" class="text" colspan="3">&nbsp;Where are you looking for new clients?</td></tr><tr><td class="text"><input id="radio1" type="radio" value="National" name="clientLocation" onChange=radio1.style.background="#ffffff"> National</td><td align="left" class="text"><input id="radio2" type="radio" value="Local" name="clientLocation"> Local</td></tr>';
	content+='<tr><td id="LocalDetailsbox" class="text" colspan="2">If Local please specify locality&nbsp;<input type="text" name="LocalDetails" id="LocalDetails" size="33" onChange=this.style.background="#ffffff"></td></tr>';
}



	content+='<tr><td height=30px class="text"colspan="3">How many new client leads do you need per day? &nbsp;<select name="numLeads" id="numLeads" onChange=this.style.background="#ffffff"><option value="Not Set">Please Select</option><option value="up to 5">1 to 5 </option><option value="up to 10">5 to 10 </option><option value="10 to 25">10 to 25</option><option value="25 to 50">25 to 50</option><option value="50+">50+</option></select></td></tr>';
    content+='<tr><td height="5px"> </td></tr>';
	content+='<tr><td height="20px" colspan="3" class="fHead2">&nbsp;In which of the following would you like to find more clients </td></tr>';

	content+='<tr><td colspan="3"><table width="100%" border="0">';

	content+='<tr><td width="20" rowspan="2"><input type="checkbox" name="Adversemortgage" id="Adversemortgage" /></td><td width="115" class="stext">Adverse Credit</td><td width="20" rowspan="2"><input type="checkbox" name="FirstTimemortgage" id="FirstTimemortgage" /></td><td width="115" class="stext">First Time Buyer</td><td width="20" rowspan="2"><input type="checkbox" name="BTLmortgage" id="BTLmortgage" /></td><td width="115" class="stext">Buy to Let </td></tr><tr><td width="115" class="stext">Mortgage</td><td width="115" class="stext">Mortgage</td><td width="115" class="stext">Mortgage</td></tr>';
	content+='<tr><td width="20"><input type="checkbox" name="Remortgage" id="Remortgage" /></td><td width="115" class="stext">Remortgages</td><td width="20"><input type="checkbox" name="HomeOwnerloan" id="HomeOwnerloan" /></td><td width="115" class="stext">Home Owner Loan</td><td width="20"><input type="checkbox" name="Debtconsolidation" id="Debtconsolidation" /></td><td width="115" class="stext">Debt Consolidation</td></tr>';
//content+='<tr><td></td><td></td><td colspan="2" align="center" valign="center" style="border-top: 1px solid #8c99a1"><img src="images/spacer.gif" /></td><td></td><td></td></tr>';
//content+='<tr><td width="20"><input type="checkbox" name="HomeOwnerloan" id="HomeOwnerloan" /></td><td width="115" class="stext">Home Owner Loan</td><td width="20"><input type="checkbox" name="Debtconsolidation" id="Debtconsolidation" /></td><td width="115" class="stext">Debt Consolidation</td></tr>';
//content+='<tr><td></td><td></td><td colspan="2" align="center" valign="center" style="border-top: 1px solid #8c99a1"><img src="images/spacer.gif" /></td><td></td><td></td></tr>';
	content+='<tr><td width="20"><input type="checkbox" name="Lifeinsurance" id="Lifeinsurance" /></td><td width="115" class="stext">Life Insurance</td><td width="20"><input type="checkbox" name="Medicalinsurance" id="Medicalinsurance" /></td><td width="115" class="stext">Medical Insurance</td><td width="20"><input type="checkbox" name="Equityrelease" id="Equityrelease" /></td><td width="115" class="stext">Equity Release</td></tr>';

	content+='</table></td></tr>';
	
	
	
	content+='<tr><td height="40px" class="text">Any other areas where you’d like more clients?</td><td  valign="middle"  align="left"><textarea name="OtherClients" id="OtherClients" cols="22" rows="2" onChange=this.style.background="#ffffff" ></textarea></td></tr>';
	content+='<tr><td height="20px">&nbsp; </td></tr>';
	content+='<tr><td height="30px"><div style="font-size:12px;text-align:left;font-weight:normal;padding-left:10px;" valign="middle" class="text"> </td><td align="left"><input type="button" value="Click to Analyse Client Demand" style="margin-right:20px;" class="button" onclick="step1()"></td></tr>';
	content+='</table>';
	content+='</td></tr></table>';
content+='</div>';




//-- Step 2 Personal Details --------
content+='<div id="step2"  style="display:none">';
	content+='<table cellSpacing="0" cellPadding="0" align="center" bgColor="#ffffff"  border="0"><tr><td  borderColor="#ffffff">';
	content+='<table align=center bgColor=#ffffff>';
	content+='<tr><td  align="center" colspan="2" height="25px" background="Images/bggrey.gif" class="fHeadM">There is significant client demand in your area of business.<br> <br>Fill in your details below for a FREE consultation </td></tr>';
    content+='<tr><td height="5px" width="180"></td></tr>';
	content+='<tr><td height="30px" class="text" width="180">&nbsp;&nbsp;&nbsp;&nbsp;Name &nbsp;<span class="required">*</span></td><td valign="top" align=left><input type="text" maxLength="255" name="clientName" id="clientName" class="text" onChange=this.style.background="#ffffff" size="30"></td></tr>';
	content+='<tr><td height="30px" class="text" width="180"> &nbsp;&nbsp;&nbsp;&nbsp;Company Name &nbsp;<span class="required">*</span></td><td valign="top" align=left><input type="text" maxLength="255" name="companyName" id="companyName" class="text" onChange=this.style.background="#ffffff" size="30"></td></tr>';
	content+='<tr><td height="30px" class="text"  width="180">&nbsp;&nbsp;&nbsp;&nbsp;Job title&nbsp;</td><td valign="top" align=left><input type="text" maxLength="255" name="jobTitle" id="jobTitle" class="text" onChange=this.style.background="#ffffff" size="30"></td></tr>';
	content+='<tr><td height="30px" class="text"  width="180">&nbsp;&nbsp;&nbsp;&nbsp;Network/Parent Company&nbsp;<span class="required">*</span></td><td valign="top" align=left><input type="text" maxLength="255" name="netWork" id="netWork" class="text" onChange=this.style.background="#ffffff" size="30"></td></tr>';
	content+='<tr><td height="30px" class="text" width="180">&nbsp;&nbsp;&nbsp;&nbsp;Direct telephone&nbsp;<span class="required">*</span></td><td valign="top" align=left><input type="text" maxLength="255" name="dirTelephone" id="dirTelephone" class="text" onChange=this.style.background="#ffffff" size="30"></td></tr>';
	content+='<tr><td height="30px" class="text" width="180">&nbsp;&nbsp;&nbsp;&nbsp;Email&nbsp;<span class="required">*</span></td><td valign="top" align=left><input type="text" maxLength="255" name="emailAddress" id="emailAddress" class="text" onChange=this.style.background="#ffffff" size="30"></td></tr>';
	content+='<tr><td height="30px" class="text" width="180">&nbsp;&nbsp;&nbsp;&nbsp;Address line 1&nbsp;</td><td valign="top" align=left><input type="text" maxLength="255" name="address1" id="address1" class="text" onChange=this.style.background="#ffffff" size="30"></td></tr>';
	content+='<tr><td height="30px" class="text" width="180">&nbsp;&nbsp;&nbsp;&nbsp;Postcode&nbsp;</td><td valign="top" align=left><input type="text" maxLength="255" name="Postcode" id="Postcode" class="text" onChange=this.style.background="#ffffff" size="30"></td></tr>';
	
    content+='<tr><td height=20px>&nbsp; </td></tr>';
	content+='<tr><td  valign=middle align=left style="padding-left:10px;" height=30px><input type="button" value="Back" class="button" onclick="step2back()"> </td><td align="right"><input type="button" value="Request FREE consultation " style="margin-right:20px;" class="button" onclick="submit_form()"></td></tr>';

//	content+='<tr><td  colspan=2 height='30px'><div style='background:#f5f5f5;height:30px;line-height:30px;letter-spacing: 0px;font-size:11px;color:#666666;text-align:center;font-weight:normal;'> Privacy Policy: Unless instructed to do so, we will not share your details with any other third parties.</div></td></tr>';
	content+='</table>';
	content+='</td></tr></table>';
content+='</div>';





content+="</form>";
formdiv.innerHTML=content;
//selectedOpt(document.getElementById('landpage').value);



}//end of generate form

var msg = 'Please correct the highlighted items before continuing ...\n';
var field;var alpha = /\w/;
var numeric = /[^0-9^\s]/;var invalid = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
var valid = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
var dateformat1=/^\d{4}\-\d{2}\-\d{2}$/; var dateformat2=/^\d{4}\ \d{2}\ \d{2}$/;
var alphanumeric = /^[a-zA-Z 0-9\-\/\,\n\r\&\.\']+$/;
var elem = document.getElementById(field);
var err1 = false;var err2=false;var errSubmit=false;
var theForm = document.form1;
var paaemail=/^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;


// -------step 1 verification--------
function step1(){
var theForm = document.form1;
err1=false;
var msg = 'Please correct the following to continue ...\n';var field;var alpha = /\w/;var numeric = /[^0-9^\s]/;var invalid = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;var valid = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;

if(!theForm.radio1.checked && !theForm.radio2.checked){
	msg += '\n\Please select a Location';
	err1 = true;
	field=theForm.radio1;
	highlite(field);}

if(theForm.radio2.checked && trimInput(theForm.LocalDetails.value)==0){
	msg += '\n\Please enter a Locality';
	err1 = true;
	field=theForm.LocalDetails;
	highlite(field);	
	}
if(theForm.numLeads.value=='Not Set'){
	msg += '\n\Please select number of client leads';
	err1 = true;
	field=theForm.numLeads;
	highlite(field);
	}
	
/*var hasError=elmLoop();alert (hasError);
if(hasError || trimInput(theForm.OtherClients.value)==0){
	msg += '\n\Please select at least one type of client lead or enter new type\n\   in the "Any other areas" box';
	err1 = true;
}*/

if(err1==true)  {
		show("Warning_mess");
		alert(msg);
		field.focus();
		
	}else {
	
	hide("step1");
	show("step2");		
	hide("Warning_mess");
	if(errSubmit==true) {show("Warning_mess");
	}else{
		hide("Warning_mess");}
	
	
	
	}


}


function submit_form(){
	errSubmit = false;
	var theForm = document.form1;
	var msg = 'Please correct the highlighted items before continuing ...\n';

//			for (var i=0; i< theForm.length; i+=1){
//			if (theForm[i].type=="text"){
//				//alert(i+"  "+theForm[i].name+" : "+ theForm[i].value);
//				theForm[i].value=trimInput(theForm[i].value);
//					if(!strPresent(theForm[i].value)){
//						field = theForm[i];
//						if(field.name!="EmailAddress" && field.name!="MobilePhone" && field.name!="CaseRef" && field.name!="Company" && field.name!="CaseRef" && field.name!="JobTitle"){
//							highlite(field);
//							msg += '\n\ '+ field.name;
//									errSubmit = true;}	   
//																   
//										   }
//								}
//			}

if (!checktelNo(theForm.dirTelephone.value)){
field = theForm.dirTelephone;
highlite(field);
	msg += '\n\Valid Telephone No.';
	errSubmit = true;
}

if ((!paaemail.test(theForm.emailAddress.value))){
	field = theForm.emailAddress;
	highlite(field);
	msg += '\n\Valid email address (name@domain.com/co.uk etc)';
	errSubmit = true;
		}	

if (!alphanumeric.test(theForm.clientName.value)){
field = theForm.clientName;
highlite(field);
	msg += '\n\Name - only letters and numbers valid';
	errSubmit = true;
}

if (!alphanumeric.test(theForm.companyName.value)){
field = theForm.companyName;
highlite(field);
	msg += '\n\Company Name - only letters and numbers valid';
	errSubmit = true;
}

if (!alphanumeric.test(theForm.netWork.value)){
field = theForm.netWork;
highlite(field);
	msg += '\n\Network/Parent Co.  - only letters and numbers valid';
	errSubmit = true;
}

if (strPresent(theForm.Postcode.value) && (checkPostCode(theForm.Postcode.value))){
theForm.Postcode.value=checkPostCode(theForm.Postcode.value);	
}else{
	if (strPresent(theForm.Postcode.value)){
	field = theForm.Postcode;
	highlite(field);
	msg += '\n\Valid UK Postcode';
	errSubmit = true;}
}



		if(errSubmit==true)  {
			show("Warning_mess");
			alert(msg);
			field.focus();
		}else {
		hide("Warning_mess");	
		//alert("Form would have been submitted OK");
		//Strip numbers
		//theForm.DirectPhone.value=stripInput(theForm.DirectPhone.value,"-");
		//theForm.DirectPhone.value=stripInput(theForm.DirectPhone.value," ");
		//theForm.MobilePhone.value=stripInput(theForm.MobilePhone.value,"-");
		//theForm.MobilePhone.value=stripInput(theForm.MobilePhone.value," ");
		//if (theForm.EmailAddress.value==""){theForm.EmailAddress.value="no@email.com";}
		//var elem=document.getElementById("merchID").value;
		//document.getElementById("merchID2").value=elem;
		//var elem2=document.getElementById("merchID2").value;
		//alert (elem2);
		theForm.submit();
		}
	
}//end of submit





function finalstepback(){
		hide("finalstep");
		show("step2");
		hide("Warning_mess");
}
function step2back(){
		hide("step2");
		show("step1");
		hide("Warning_mess");
}



//function showltv()
//{
//	var display_text = '';
//	var theForm = document.form1;
//
//	if (document.all || document.layers) {
//		MM_setTextOfLayer(window.ltvdesc,'',display_text);
//
//	} else {
//		MM_setTextOfLayer("ltvdesc",'',display_text);
//	}
//}

function KeyPress(iField,e,max,action) {
	if(document.layers){	if(e.target.value.length >= max) eval(action);}
		else if(document.all){ if(iField.value.length > (max-1)) eval(action);}
			else if(document.getElementById){if(iField.value.length >= max)	eval(action);}
}

function formatnum(amount,X) {
	// rounds number to X decimal places, defaults to 2
	//X = (!X ? 2 : X);
	//return Math.round(amount*Math.pow(10,X))/Math.pow(10,X);
	return Math.ceil(amount)
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	var ck = name+"="+value+expires+"; path=/";
	// if (days != -1) alert('Cookie\n' + ck + '\ncreated');
	document.cookie = ck;
}


function trimInput(sStr)
{
//return str.replace(/^\s*|\s*$/,"");

while (sStr.substring(0,1) == ' ')
{
sStr = sStr.substring(1, sStr.length);
}
while (sStr.substring(sStr.length-1, sStr.length) == ' ')
{
sStr = sStr.substring(0,sStr.length-1);
}
return sStr;
}

function stripInput(Str,sStr){
	sStr=eval("/"+sStr+"/gi");
	Str=Str.replace(sStr, "");
	//tmpStr=tmpStr.replace(/-/gi, "");
	return Str;
	}


function checkNumber(field){

var elem = document.getElementById(field);

if ((isNaN(elem.value)) || (!alpha.test(elem.value))){
	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 validPC = 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
      validPC = 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 (validPC) {return postCode;} else return false;
}

function strPresent(toCheck){
	var emptyString = /^\s*$/ ;
	
	if((toCheck!='') || (!emptyString.test(toCheck))){
	return true;
	}else{
	return false;
	}
}

function checktelNo(toCheck){
    var telnr = /^\+?[0-9 ()-]+[0-9]$/  ;
	var tmpStr;
	tmpStr=stripInput(toCheck," ");
	tmpStr=stripInput(tmpStr,"-");
	
	if (telnr.test(toCheck)&& tmpStr.length>3 && tmpStr.length<21) {
	return true;		
	}else{return false;}
}


function highlite(field){
field.style.background="#FFB3B3";
}

function hide(id){
	elem=document.getElementById(id);
    if(elem)
    	elem.style.display='none';
}
function show(id){
    elem=document.getElementById(id);
    if(elem)
    	elem.style.display='block';
}

function selectedOpt(id){
	elem=document.getElementById('CaseType');
	elem.selectedIndex=id;
	}

function ClientLocation(){
	elem=document.getElementById('radio2');
	if(elem.checked){show("LocalDetailsbox");}else{
				document.getElementById("LocalDetails").value="";
				hide("LocalDetailsbox");
				
				}

}


function selectedOpt(id,fCap){
	var add_mess=fCap+" added to your client demand analysis below";
	alert(add_mess);
	elem=document.getElementById(id);
	elem.checked=true;
	}
function focusOpt(id){
	var add_mess="Please enter any other business areas in the box selected below";
	alert(add_mess);
	elem=document.getElementById(id);
	elem.focus();
	elem.select();
	}


function elmLoop(){
var theForm = document.form1;
var err_val=true;
	for(i=0; i<theForm.elements.length; i++){
		if(theForm.elements[i].type == "checkbox" && theForm.elements[i].checked==true){
		err_val=false;
		}//end of chk
	}//end of for

return err_val;}


function newWindow(a_str_windowURL, a_str_windowName, a_int_windowWidth, a_int_windowHeight, a_bool_scrollbars, a_bool_resizable, a_bool_menubar, a_bool_toolbar, a_bool_addressbar, a_bool_statusbar, a_bool_fullscreen,a_position) {
	var int_windowLeft;
	if(a_position==0){int_windowLeft=0;}
	if(a_position==1){int_windowLeft = (screen.width - a_int_windowWidth) / 2;}
  var int_windowTop = (screen.height - a_int_windowHeight) / 4;
  var str_windowProperties = 'height=' + a_int_windowHeight + ',width=' + a_int_windowWidth + ',top=' + int_windowTop + ',left=' + int_windowLeft + ',scrollbars=' + a_bool_scrollbars + ',resizable=' + a_bool_resizable + ',menubar=' + a_bool_menubar + ',toolbar=' + a_bool_toolbar + ',location=' + a_bool_addressbar + ',statusbar=' + a_bool_statusbar + ',fullscreen=' + a_bool_fullscreen + '';
  var obj_window = window.open(a_str_windowURL, a_str_windowName, str_windowProperties)
    if (parseInt(navigator.appVersion) >= 4) {
      obj_window.window.focus();
    }
}

function Show_DIV(dispid,hide1,hide2,hide3,hide4,hide5) {
	var lth=dispid+"_link";
	document.getElementById(dispid).style.display='';
	document.getElementById(hide1).style.display='none';
	document.getElementById(hide2).style.display='none';
	document.getElementById(hide3).style.display='none';
	document.getElementById(hide4).style.display='none';
	document.getElementById(hide5).style.display='none';

	
	
/*		//var lts1=hide1+"_link";lts2=hide2+"_link";lts3=hide3+"_link";

	//document.getElementById(lth).style.display='none';
	//document.getElementById(lts1).style.display='block';
	//document.getElementById(lts2).style.display='block';
	//document.getElementById(lts3).style.display='block';*/
}