function popupSmallWindow(targetName, url)
{
	var browserAgent = navigator.userAgent;
	if(!url)
		url="";

	if(browserAgent.indexOf("MSIE") != -1) {

		var windowProp = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,alwaysRaised=yes,width=420,height=350,top=0,left=0';
		var mhlWindow = window.open(url, targetName, windowProp);
		if(mhlWindow)
			mhlWindow.focus();
		else
			alert("Popup is blocked in this browser. Please allow popup.");

	}
	else if(browserAgent.indexOf("Netscape/7") != -1) {

		var windowProp = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,alwaysRaised=yes,width=420,height=350,top=0,left=0';
		var mhlWindow = window.open(url, targetName, windowProp);
		if(mhlWindow)
			mhlWindow.focus();
		else
			alert("Popup is blocked in this browser. Please allow popup.");

	}
	else if(browserAgent.indexOf("Netscape6/6.1") != -1) {

		var windowProp = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,alwaysRaised=yes,width=420,height=350,top=0,left=0';
		var mhlWindow = window.open(url, targetName, windowProp);
		if(mhlWindow)
			mhlWindow.focus();
		else
			alert("Popup is blocked in this browser. Please allow popup.");

	}
	else if(browserAgent.indexOf("Netscape6") != -1) {

		var screenWidth = window.screen.width-6;
		var screenHeight = window.screen.height-100;
		var windowProp = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,alwaysRaised=yes,width=420,height=350,top=0,left=0';
		var mhlWindow = window.open(url, targetName, windowProp);
		if(mhlWindow)
			mhlWindow.focus();
		else
			alert("Popup is blocked in this browser. Please allow popup.");

	}
	else if(browserAgent.indexOf("Mozilla") != -1) {

		var screenWidth = window.screen.width-6;
		var screenHeight = window.screen.height-100;
		var windowProp = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,alwaysRaised=yes,width=420,height=350,top=0,left=0';
		var mhlWindow = window.open(url, targetName, windowProp);
		if(mhlWindow)
			mhlWindow.focus();
		else
			alert("Popup is blocked in this browser. Please allow popup.");

	}
	else {

		var screenWidth = window.screen.width-10;
		var screenHeight = window.screen.height-100;
		var windowProp = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,alwaysRaised=yes,width=420,height=350,top=0,left=0';
		var mhlWindow = window.open(url, targetName, windowProp);
		if(mhlWindow)
			mhlWindow.focus();
		else
			alert("Popup is blocked in this browser. Please allow popup.");
	}
}

function initQuickEnquiry()
{
	var qPos = window.location.href.indexOf('?');
	var len = window.location.href.length;
	var qryStr = window.location.href.substr(qPos+1, len);
	var paramArr = qryStr.split('&');
	for(i=0; i<paramArr.length; i++)
	{
		var elemNameValue = paramArr[i];
		var indx = elemNameValue.indexOf('=');
		var elemName = elemNameValue.substring(0, indx);
		var elemValue = elemNameValue.substring(indx+1);
		elemValue = elemValue.replace("+", " ");
		if(document.getElementById(elemName))
			document.getElementById(elemName).value=elemValue;
	}
}

function initCalculator()
{
	var qPos = window.location.href.indexOf('?');
	var len = window.location.href.length;
	var qryStr = window.location.href.substr(qPos+1, len);
	var paramArr = qryStr.split('&');
	for(i=0; i<paramArr.length; i++)
	{
		var elemNameValue = paramArr[i];
		var indx = elemNameValue.indexOf('=');
		var elemName = elemNameValue.substring(0, indx);
		var elemValue = elemNameValue.substring(indx+1);
		elemValue = elemValue.replace("+", " ");
		if(document.mortcalc.elements[elemName])
			document.mortcalc.elements[elemName].value=elemValue;
	}
}

function validateCallMeFrm()
{
	var frm = document.frmCallMeBack;
	var nameElm = frm.elements['name'];
	var contactNoElm = frm.elements['contactNo'];
	var timeToCallElm = frm.elements['timeToCall'];
	if(Trim(nameElm.value)=='' || Trim(nameElm.value).toUpperCase()=='NAME'){
		alert("Please enter name");
		nameElm.select();
	}
	else if(Trim(contactNoElm.value)=='' || Trim(contactNoElm.value).toUpperCase()=='CONTACT NO.'){
		alert("Please enter contact no.");
		contactNoElm.select();
	}
	else if(Trim(timeToCallElm.value)=='' || Trim(timeToCallElm.value).toUpperCase()=='TIME TO CALL'){
		alert("Please enter time to call");
		timeToCallElm.select();
	}
	else{
		frm.submit();
	}
}

function ResetForm()
{
myRef = document.frmMain;

myRef.txtBonus1.value = "";
myRef.txtIncome1.value = "";
myRef.txtBonus2.value = "";
myRef.txtIncome2.value = "";
myRef.txtResultLow.value = "";
myRef.txtResultHigh.value = "";
myRef.txtIncome1.focus();
}

function checkValues()
{
myRef = document.frmMain;

//Check 1st Applicant
if(myRef.txtIncome1.value > 0) 
{
 if(myRef.txtBonus1.value >= 0)
 {

 //Check 2nd Applicant
if(myRef.txtIncome2.value == "") 
{
if(myRef.txtBonus2.value == "")
{
 
return true;
}
}

 if(myRef.txtIncome2.value > 0) 
 {
 if(myRef.txtBonus2.value >= 0)
 {
   return true;
 }
 else
 {
 alert('Please enter a valid bonus or commission');
  myRef.txtBonus2.focus();
  return false;
 } 
}
else
{
alert('Please enter a valid income');
myRef.txtIncome2.focus();
return false;
}

 }
 else
 {
 alert('Please enter a valid bonus or commission');
  myRef.txtBonus1.focus();
  return false;
 } 
}
else
{
alert('Please enter a valid income');
myRef.txtIncome1.focus();
return false;
}


}



function Calculate()
{


if(checkValues())
{
//Result types have been validated
//check for minimum income type???
myRef = document.frmMain;

if(myRef.txtIncome2.value == "") 
 {
 if(myRef.txtBonus2.value == "")
 {
  //Individual calculation
  
  myRef.txtResultLow.value = (parseInt(myRef.txtIncome1.value)) * 3;
  myRef.txtResultHigh.value = (parseInt(myRef.txtIncome1.value)) * 5;
  return 0;
 }
} // end individ block


 //Joint calculation
  if(myRef.txtBonus1.value == "")
  {
  myRef.txtBonus1.value = 0;
  } 
 
 if(myRef.txtBonus2.value == "")
  {
  myRef.txtBonus2.value = 0;
  } 
 
  myRef.txtResultLow.value = (parseInt(myRef.txtIncome1.value) +  parseInt(myRef.txtIncome2.value) + parseInt(myRef.txtBonus1.value) + parseInt(myRef.txtBonus2.value)) * 2.5;
  myRef.txtResultHigh.value = (parseInt(myRef.txtIncome1.value) +  parseInt(myRef.txtIncome2.value) + parseInt(myRef.txtBonus1.value) + parseInt(myRef.txtBonus2.value)) * 3.9;
  
  return 0;

 } //end checkvalues 
 else
 {
 return false;
 }
 
} // end calculate

 function nextClick()
 {
 
 Calculate();
 if(document.frmMain.txtResultLow.value != "")
 {
 //Ok submit the form
 document.frmMain.submit();
 }
 }
<!--
function MortgageForm(id1,id2,id3)
{
window.location = 'mortgageform.html?txtHowMuch=' + id1 + '&txtIncome1=' + id2 + '&txtIncome2=' + id3; 
}
function Cost(id1,id2,id3)
{
window.location = 'cost.html?txtHowMuch=' + id1 + '&txtIncome1=' + id2 + '&txtIncome2=' + id3;
}
//-->
<!--
function stripChar (input) {
s = input.value;
filteredValues = ",";     // Characters to strip out
var i;
var returnString = "";
for (i = 0; i < s.length; i++) { 
var c = s.charAt(i);
if (filteredValues.indexOf(c) == -1) returnString += c;
}
input.value = returnString;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
//-->
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
    function CheckZero(field) {
        if (field.value == 0 || field.value.length == 0) {
            alert ("This field cannot be 0.");
            field.focus(); }
        //else
	    //calculate Re-Payment
    }

    function cmdCalc_Click(form) {
        if (form.txtHowMuch.value == 0 || form.txtHowMuch.value.length == 0) {
            alert ("Please enter your mortgage amount.");
            form.txtHowMuch.focus(); }
        else if (form.oldrate.value == 0 || form.oldrate.value.length == 0) {
            alert ("Please enter your current interest rate.");
            form.oldrate.focus(); }
	    else if (form.newrate.value == 0 || form.newrate.value.length == 0) {
            alert ("Please enter the new interest rate.");
            form.newrate.focus(); }
        else if (form.txtPaymentPeriod.value == 0 || form.txtPaymentPeriod.value.length == 0) {
            alert ("Please enter your mortgage term.");
            form.txtPaymentPeriod.focus(); }
        else
            calculatePayment(form);
    }

    function calculatePayment(form) {
     
      //get values from the input form
		var princ = form.txtHowMuch.value;
		var rate = (form.oldrate.value);
		var newrate = (form.newrate.value);
		var intRate = (form.oldrate.value/100) /12;
		var txtPaymentPeriod = form.txtPaymentPeriod.value
		var newintrate = (form.newrate.value/100) /12;
        var months = form.txtPaymentPeriod.value * 12;
        
		//calculate the repayments on repayment motgage
		var repayment = Math.floor((princ*intRate)/(1-Math.pow(1+intRate,(-1*months)))*100)/100;
		var newrepayment = Math.floor((princ*newintrate)/(1-Math.pow(1+newintrate, (-1*months)))*100)/100;
 	
		//calculate the repayments on an interest only mortgage
		var I = rate / 12;
		var X = 1/(1+I/100);
		var I2 = newrate / 12
		var X2 = 1/(1+I2/100);
		var N = txtPaymentPeriod * 12;
		var L = princ;
		var P1 = 0;
		var P2 = princ;
		//var A1 = (L - P1 * Math.pow(X,N)) * (X - 1)/(Math.pow(X,N+1)-X) - REPAYMENT CALC
		var A1 = round((L - P2 * Math.pow(X,N)) * (X - 1)/(Math.pow(X,N+1)-X),2);
		var A2 = round((L - P2 * Math.pow(X2,N)) * (X2 - 1)/(Math.pow(X2,N+1)-X2),2);
	
		//populate the fields for a repayment mortgage
		form.repaysaving.value = round((repayment-newrepayment),2)
		
		//populate the fields for an interest only mortgage
		form.intsaving.value = round((A1-A2),2)
		}
		
function round(number,X) {
// rounds number to X decimal places, defaults to 2
X = (!X ? 2 : X);
return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}
<!--
function floor(number)
{
  return Math.floor(number*Math.pow(10,2))/Math.pow(10,2);
}
capitalarray = new Array(50);

function dosum()
{
  if(!isNaN(document.mortcalc.interest.value)
   &&!isNaN(document.mortcalc.year.value)
   &&(parseFloat(document.mortcalc.interest.value)!=0)
   &&(parseFloat(document.mortcalc.year.value)!=0)
   &&!isNaN(document.mortcalc.capital.value)
   &&(document.mortcalc.mortgagetype.selectedIndex)>0
   &&(document.mortcalc.intcalc.selectedIndex)>0
   )
   {
   	  var monthlyinterest = document.mortcalc.interest.value / 12 / 100;   
	  var annualinterest = document.mortcalc.interest.value / 100;   
	  var mortgageterm = document.mortcalc.year.value / 100;    
	  var type = document.mortcalc.mortgagetype.selectedIndex ;  
	  var originalcapital = document.mortcalc.capital.value ;  
	  var base = 1;
	  var base2 = 1;
	  var mbase = 1 + monthlyinterest;
	  var ybase = 1 + monthlyinterest*12;
	  
	  for (i=0; i<document.mortcalc.year.value; i++)
	  {base2 = base2 * ybase;}
	    
	  for (i=0; i<document.mortcalc.year.value * 12; i++)
	  {base = base * mbase;}
	
	  	if (type == 1)
	  	{    //Repayment type mortgage
	   
	  		if (document.mortcalc.intcalc.selectedIndex == 1) 
	  		{           // Annual interest calculations
	  		var monthlypayment = ((originalcapital * monthlyinterest*12 / ( 1 - (1/base2))/12));
	  		document.mortcalc.monthlypayment.value = floor((originalcapital * monthlyinterest*12 / ( 1 - (1/base2))/12));
	  
	  		}else if (document.mortcalc.intcalc.selectedIndex == 2){      // Monthly or daily interest calculations
	  		var monthlypayment = (originalcapital * monthlyinterest / ( 1 - (1/base)));
	  		document.mortcalc.monthlypayment.value = floor(originalcapital * monthlyinterest / ( 1 - (1/base)));
	  		}
	
	
	
	  	}else if (type == 2){  //Interest only type mortgage
	  	var monthlypayment = (originalcapital * monthlyinterest);
	  	document.mortcalc.monthlypayment.value = floor(originalcapital * monthlyinterest);
	  	}
	  
	  
	  	//For calculating arrays
	  
	  	if (document.mortcalc.intcalc.selectedIndex == 1) // Annual interest calculations
	  	{
	  	// Annual calculations for amortization table
	  	var capital = originalcapital;
	  		for (i=0; i<document.mortcalc.year.value; i++)
	  		{
	  		capital = capital - (12 * monthlypayment) + (capital*annualinterest);
	  		capitalarray[i] = capital;
	  		}
	  	}else if (document.mortcalc.intcalc.selectedIndex == 2){
	  	// Monthly/Daily calculations for amortization table
	  
	  	var capital = originalcapital;
	
	  		for (i=0; i<document.mortcalc.year.value; i++);
	  		{
	
	  			for (j=0; j < 12; j++) {
	  			capital = capital - (monthlypayment) + (capital * monthlyinterest);
	  			}
	  		capitalarray[1] = capital;
	  		}
	  	}
	}
	else
	{
		document.mortcalc.monthlypayment.value = "";
	}
}
function setDefaultValue(inputObj){
	inputObj.value="";
	document.mortcalc.monthlypayment.value = "";
}
function setDefaultBlankValue(inputObj){
	inputObj.value="";
	document.mortcalc.monthlypayment.value = "";
}

function validateCallMeBackForm(){
	if(document.frmCallMeBack.name.value == "Name")
	{
		alert("Please enter your name.");
		document.frmCallMeBack.name.focus();
		return false;
	}
	if(document.frmCallMeBack.contactNo.value == "Contact No.")
	{
		alert("Please enter your contact no.");
		document.frmCallMeBack.contactNo.focus();
		return false;
	}
	if(document.frmCallMeBack.timeToCall.value == "Time to call")
	{
		alert("Please enter time to call.");
		document.frmCallMeBack.timeToCall.focus();
		return false;
	}
	return true;
}

function validateCompareRatesForm(){
	if(document.frmCompareRates.email.value == "E-mail")
	{
		alert("Please enter your email id.");
		document.frmCompareRates.email.focus();
		return false;
	}
	if(document.frmCallMeBack.Telephone.value == "Telephone")
	{
		alert("Please enter your telephone no.");
		document.frmCompareRates.Telephone.focus();
		return false;
	}
	if(document.frmCompareRates.Name.value == "Name")
	{
		alert("Please enter Name.");
		document.frmCompareRates.Name.focus();
		return false;
	}
	return true;
}
// -->
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->
<!--
function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->
<!-- FORM VALIDATION -->
function validateForm() {
with (document.LifeForm) {
var alertMsg = "The following required fields have been left empty:\n";
if (CoverType_Quote_1.options[CoverType_Quote_1.selectedIndex].value == "") alertMsg += "\n  -  Type of cover";
if (singlejoint_1.options[singlejoint_1.selectedIndex].value == "") alertMsg += "\n  -  Who this quote is for (myself or myself & partner)";
if (Quote_1_CoverAmount.value.length < 4) alertMsg += "\n  -  How much cover? (total £)  For example, 150000.";
if (Quote_1_CoverAmount.value < 1000) alertMsg += "\n\n  -  The amount you have entered is below the minimum value.\n      Please enter the exact cover you require, eg, 100000.\n";
if (Quote_1_YearsOfCover.value == "") alertMsg += "\n  -  How many years?";
if (Title.options[Title.selectedIndex].value == "") alertMsg += "\n  -  Your Title";
if (ForeName.value.length < 3) alertMsg += "\n  -  Your forename";
if (SurName.value.length < 3) alertMsg += "\n  -  Your surname";
if (day.options[day.selectedIndex].value == "") alertMsg += "\n  -  The day you were born";
if (month.options[month.selectedIndex].value == "") alertMsg += "\n  -  The month you were born";
if (year.options[year.selectedIndex].value == "") alertMsg += "\n  -  The year you were born";
if (Gender.options[Gender.selectedIndex].value == "") alertMsg += "\n  -  Your gender";
if (Smoker.options[Smoker.selectedIndex].value == "") alertMsg += "\n  -  Whether or not you smoke";
if (Email.value.length < 3) alertMsg += "\n  -  Your email address";
if (Phone.value.length < 10) alertMsg += "\n  -  Your daytime telephone number";
if (Phone2.value.length < 10) alertMsg += "\n  -  Your evening telephone number";
if (singlejoint_1.options[singlejoint_1.selectedIndex].value == "Joint" && PartnerForeName.value == "")  alertMsg += "\n  -  Your partners forename";
if (singlejoint_1.options[singlejoint_1.selectedIndex].value == "Joint" && PartnerSurName.value == "")  alertMsg += "\n  -  Your partners surname";
if (singlejoint_1.options[singlejoint_1.selectedIndex].value == "Joint" && day2.options[day2.selectedIndex].value == "00")  alertMsg += "\n  -  The day your partner was born";
if (singlejoint_1.options[singlejoint_1.selectedIndex].value == "Joint" && month2.options[month2.selectedIndex].value == "00")  alertMsg += "\n  -  The month your partner was born";
if (singlejoint_1.options[singlejoint_1.selectedIndex].value == "Joint" && year2.options[year2.selectedIndex].value == "0000")  alertMsg += "\n  -  The year your partner was born";
if (singlejoint_1.options[singlejoint_1.selectedIndex].value == "Joint" && PartnerGender.options[PartnerGender.selectedIndex].value == "")  alertMsg += "\n  -  Your partners gender";
if (singlejoint_1.options[singlejoint_1.selectedIndex].value == "Joint" && PartnerSmoker.options[PartnerSmoker.selectedIndex].value == "")  alertMsg += "\n  -  Whether or not your partner smokes";
if (HouseNumber.value.length < 5) alertMsg += "\n  -  Your number street and town";
if (PostCode.value.length < 3) alertMsg += "\n  -  Your post code";
if (alertMsg != "The following required fields have been left empty:\n") {
alert(alertMsg);
return false;
} else {
return true;
} } }
//-->
<!-- SHOW PARTNER 2 -->
function PartnerShow()
{
var Partner2=document.getElementById("Partner2")
if (document.LifeForm.singlejoint_1.value!="Single")
{
Partner2.style.display = "block"
}
else
{
Partner2.style.display = "none"
} 
}
//-->
<!-- Begin
function checkEmail(myForm) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(LifeForm.Email.value)){
return (true)
}
alert("Invalid E-mail Address, Please enter a valid email address.")
document.LifeForm.Email.focus()
return (false)
}
//  End -->
<!--
function numbersonly(myfield, e, dec)
{
var key;
var keychar;
if (window.event)
key = window.event.keyCode;
else if (e)
key = e.which;
else
return true;
keychar = String.fromCharCode(key);
// control keys
if ((key==null) || (key==0) || (key==8) ||
(key==9) || (key==13) || (key==27) )
return true;
// numbers
else if ((("0123456789").indexOf(keychar) > -1))
return true;
// decimal point jump
else if (dec && (keychar == "."))
{
PPriceVal.form1.elements[dec].focus();
LoanRequired.form1.elements[dec].focus();
return false;
}
else
return false;
}
//-->
// Title: Tigra Form Validator
// URL: http://www.softcomplex.com/products/tigra_form_validator/
// Version: 1.2
// Date: 02/17/2005 (mm/dd/yyyy)
// Notes: Registration needed to use this script legally. Visit official site for details.

// regular expressions or function to validate the format
var re_dt = /^(\d{1,2})\-(\d{1,2})\-(\d{4})$/,
re_tm = /^(\d{1,2})\:(\d{1,2})\:(\d{1,2})$/,
a_formats = {
	'alpha'   : /^[a-zA-Z\.\-]*$/,
	'alphanum': /^\w+$/,
	'unsigned': /^\d+$/,
	'integer' : /^[\+\-]?\d*$/,
	'real'    : /^[\+\-]?\d*\.?\d*$/,
	'email'   : /^[\w-\.]+\@[\w\.-]+\.[a-z]{2,4}$/,
	'phone'   : /^[\d\.\s\-]+$/,
	'date'    : function (s_date) {
		// check format
		if (!re_dt.test(s_date))
			return false;
		// check allowed ranges	
		if (RegExp.$1 > 31 || RegExp.$2 > 12)
			return false;
		// check number of day in month
		var dt_test = new Date(RegExp.$3, Number(RegExp.$2-1), RegExp.$1);
		if (dt_test.getMonth() != Number(RegExp.$2-1))
			return false;
		return true;
	},
	'time'    : function validate_time(s_time) {
		// check format
		if (!re_tm.test(s_time))
			return false;
		// check allowed ranges	
		if (RegExp.$1 > 23 || RegExp.$2 > 59 || RegExp.$3 > 59)
			return false;
		return true;
	}
},
a_messages = [
	'No form name passed to validator construction routine',
	'No array of "%form%" form fields passed to validator construction routine',
	'Form "%form%" can not be found in this document',
	'Incomplete "%n%" form field descriptor entry. "l" attribute is missing',
	'Can not find form field "%n%" in the form "%form%"',
	'Can not find label tag (id="%t%")',
	'Can not verify match. Field "%m%" was not found',
	'"%l%" is a required field',
	'Value for "%l%" must be %mn% characters or more',
	'Value for "%l%" must be no longer than %mx% characters',
	'"%v%" is not valid value for "%l%"',
	'"%l%" must match "%ml%"'
]

// validator counstruction routine
function validator(s_form, a_fields, o_cfg) {
	this.f_error = validator_error;
	this.f_alert = o_cfg && o_cfg.alert
		? function(s_msg) { alert(s_msg); return false }
		: function() { return false };
		
	// check required parameters
	if (!s_form)	
		return this.f_alert(this.f_error(0));
	this.s_form = s_form;
	
	if (!a_fields || typeof(a_fields) != 'object')
		return this.f_alert(this.f_error(1));
	this.a_fields = a_fields;

	this.a_2disable = o_cfg && o_cfg['to_disable'] && typeof(o_cfg['to_disable']) == 'object'
		? o_cfg['to_disable']
		: [];
		
	this.exec = validator_exec;
}

// validator execution method
function validator_exec() {
	var o_form = document.forms[this.s_form];
	if (!o_form)	
		return this.f_alert(this.f_error(2));
		
	b_dom = document.body && document.body.innerHTML;
	
	// check integrity of the form fields description structure
	for (var n_key in this.a_fields) {
		// check input description entry
		this.a_fields[n_key]['n'] = n_key;
		if (!this.a_fields[n_key]['l'])
			return this.f_alert(this.f_error(3, this.a_fields[n_key]));
		o_input = o_form.elements[n_key];
		if (!o_input)
			return this.f_alert(this.f_error(4, this.a_fields[n_key]));
		this.a_fields[n_key].o_input = o_input;
	}

	// reset labels highlight
	if (b_dom)
		for (var n_key in this.a_fields) 
			if (this.a_fields[n_key]['t']) {
				var s_labeltag = this.a_fields[n_key]['t'], e_labeltag = get_element(s_labeltag);
				if (!e_labeltag)
					return this.f_alert(this.f_error(5, this.a_fields[n_key]));
				this.a_fields[n_key].o_tag = e_labeltag;
				// normal state parameters assigned here
				e_labeltag.className = 'smalltxt';
			}

	// collect values depending on the type of the input
	for (var n_key in this.a_fields) {
		var s_value = '';
		o_input = this.a_fields[n_key].o_input;
		if (o_input.type == 'checkbox') // checkbox
			s_value = o_input.checked ? o_input.value : '';
		else if (o_input.value) // text, password, hidden
			s_value = o_input.value;
		else if (o_input.options) // select
			s_value = o_input.selectedIndex > -1
				? o_input.options[o_input.selectedIndex].value
				: null;
		else if (o_input.length > 0) // radiobuton
			for (var n_index = 0; n_index < o_input.length; n_index++)
				if (o_input[n_index].checked) {
					s_value = o_input[n_index].value;
					break;
				}
		this.a_fields[n_key]['v'] = s_value.replace(/(^\s+)|(\s+$)/g, '');
	}
	
	// check for errors
	var n_errors_count = 0,
		n_another, o_format_check;
	for (var n_key in this.a_fields) {
		o_format_check = this.a_fields[n_key]['f'] && a_formats[this.a_fields[n_key]['f']]
			? a_formats[this.a_fields[n_key]['f']]
			: null;

		// reset previous error if any
		this.a_fields[n_key].n_error = null;

		// check reqired fields
		if (this.a_fields[n_key]['r'] && !this.a_fields[n_key]['v']) {
			this.a_fields[n_key].n_error = 1;
			n_errors_count++;
		}
		// check length
		else if (this.a_fields[n_key]['mn'] && String(this.a_fields[n_key]['v']).length < this.a_fields[n_key]['mn']) {
			this.a_fields[n_key].n_error = 2;
			n_errors_count++;
		}
		else if (this.a_fields[n_key]['mx'] && String(this.a_fields[n_key]['v']).length > this.a_fields[n_key]['mx']) {
			this.a_fields[n_key].n_error = 3;
			n_errors_count++;
		}
		// check format
		else if (this.a_fields[n_key]['v'] && this.a_fields[n_key]['f'] && (
			(typeof(o_format_check) == 'function'
			&& !o_format_check(this.a_fields[n_key]['v']))
			|| (typeof(o_format_check) != 'function'
			&& !o_format_check.test(this.a_fields[n_key]['v'])))
			) {
			this.a_fields[n_key].n_error = 4;
			n_errors_count++;
		}
		// check match	
		else if (this.a_fields[n_key]['m']) {
			for (var n_key2 in this.a_fields)
				if (n_key2 == this.a_fields[n_key]['m']) {
					n_another = n_key2;
					break;
				}
			if (n_another == null)
				return this.f_alert(this.f_error(6, this.a_fields[n_key]));
			if (this.a_fields[n_another]['v'] != this.a_fields[n_key]['v']) {
				this.a_fields[n_key]['ml'] = this.a_fields[n_another]['l'];
				this.a_fields[n_key].n_error = 5;
				n_errors_count++;
			}
		}
	}

	// collect error messages and highlight captions for errorneous fields
	var s_alert_message = '',
		e_first_error;

	if (n_errors_count) {
		for (var n_key in this.a_fields) {
			var n_error_type = this.a_fields[n_key].n_error,
				s_message = '';
				
			if (n_error_type)
				s_message = this.f_error(n_error_type + 6, this.a_fields[n_key]);

			if (s_message) {
				if (!e_first_error)
					e_first_error = o_form.elements[n_key];
				s_alert_message += s_message + "\n";
				// highlighted state parameters assigned here
				if (b_dom && this.a_fields[n_key].o_tag){
					this.a_fields[n_key].o_tag.className = 'tfvHighlight';
					}
			}
		}
		alert(s_alert_message);
		// set focus to first errorneous field
		if (e_first_error.focus && e_first_error.type != 'hidden'  && !e_first_error.disabled)
			eval("e_first_error.focus()");
		// cancel form submission if errors detected
		return false;
	}
	
	for (n_key in this.a_2disable)
		if (o_form.elements[this.a_2disable[n_key]])
			o_form.elements[this.a_2disable[n_key]].disabled = true;

	return true;
}

function validator_error(n_index) {
	var s_ = a_messages[n_index], n_i = 1, s_key;
	for (; n_i < arguments.length; n_i ++)
		for (s_key in arguments[n_i])
			s_ = s_.replace('%' + s_key + '%', arguments[n_i][s_key]);
	s_ = s_.replace('%form%', this.s_form);
	return s_
}

function get_element (s_id) {
	return (document.all ? document.all[s_id] : (document.getElementById ? document.getElementById(s_id) : null));
}
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->
<!--
function formValidator(f,NXT)
	{
		var errormsg = '';
	
		if (errormsg.length == 0 )
		{
			goPage(NXT);
			return true;
		}
		else 
		{
			alert(errormsg);
			return false;
		}
	} 


//STEP 2 - VALIDATE SECOND FORM
/*******************************************************************************/

function formValidator1(foo,NXT)
	{
		var errormsg1 = '';
	
				
		if (errormsg1.length == 0 )
		{
			goPage(NXT);
			return true;
		}
		else 
		{
			alert(errormsg1);
			return false;
		}
	} 
	
// -->
<!--
  function hideAll() {
    document.getElementById('page1').style.display = 'none';
    document.getElementById('page2').style.display = 'none';
    //document.getElementById('page3').style.display = 'none';
    //document.getElementById('page4').style.display = 'none';
  }
   function goPage(x) {
 		hideAll();
		document.getElementById('page' + x).style.display = '';
	//dynamicSection = document.getElementById('dynamic');
	//dynamicSection.innerHTML = document.dataentry.page1_text.value + " " + document.dataentry.page2_text.value;
	//refresh();
	}
// -->

function LTrim(str)
{
	var whitespace = new String(" \t\n\r");
	var s = new String(str);
	if (whitespace.indexOf(s.charAt(0)) != -1) {
		// We have a string with leading blank(s)...
		var j=0, i = s.length;
	  	// Iterate from the far left of string until we
	  	// don't have any more whitespace...
	  	while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
			j++;
		// Get the substring from the first non-whitespace
		// character to the end of the string...
		s = s.substring(j, i);
	}
	return s;
}

/**
 * ==================================================================
 * RTrim(string) : Returns a copy of a string without trailing spaces.
 * ==================================================================
 * PURPOSE: Remove trailing blanks from our string.
 * IN: str - the string we want to RTrim
 */
function RTrim(str)

{
	// We don't want to trip JUST spaces, but also tabs,
	// line feeds, etc.  Add anything else you want to
	// "trim" here in Whitespace
	var whitespace = new String(" \t\n\r");
	var s = new String(str);
	if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
		// We have a string with trailing blank(s)...
		var i = s.length - 1;       // Get length of string
		// Iterate from the far right of string until we
		// don't have any more whitespace...
		while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
			i--;
		// Get the substring from the front of the string to
		// where the last non-whitespace character is...
		s = s.substring(0, i+1);
	}	
	return s;
}

/**
 * =============================================================
 * Trim(string) : Returns a copy of a string without leading or trailing spaces
 * =============================================================
 * PURPOSE: Remove trailing and leading blanks from our string.
 * IN: str - the string we want to Trim RETVAL: A Trimmed string!
 */
function Trim(str)
{
   return RTrim(LTrim(str));
}