// JavaScript Document
function CallMe()
{
	var booErr=false;
	var focusObj;
	var span;
	
	span = document.getElementById('sp1Title');
	if (span)
	{
		span.className = '';
	}
	span = document.getElementById('sp1Fname');
	if (span)
	{
		span.className = '';
	}
	span = document.getElementById('sp1Sname');
	if (span)
	{
		span.className = '';
	}
	span = document.getElementById('sp1Phone');
	if (span)
	{
		span.className = '';
	}
	span = document.getElementById('sp1Best');
	if (span)
	{
		span.className = '';
	}
	span = document.getElementById('sp1Heard');
	if (span)
	{
		span.className = '';
	}
	
	with (document.aspnetForm)
	{
		if( title1.value.length == 0 )
		{
			booErr = true;
			span = document.getElementById('sp1Title');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = title1;
		}
		if( firstname1.value.length == 0 )
		{
			booErr = true;
			span = document.getElementById('sp1Fname');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = firstname1;
		}
		else if( !isName(firstname1.value) )
		{
			booErr = true;
			span = document.getElementById('sp1Fname');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = firstname1;
		}	
		if( surname1.value.length == 0 )
		{
			booErr = true;
			span = document.getElementById('sp1Sname');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = surname1;
		}
		else if( !isName(surname1.value) )
		{
			booErr = true;
			span = document.getElementById('sp1Sname');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = surname1;
		}
		if( phone1.value.length == 0)
		{
			booErr = true;
			span = document.getElementById('sp1Phone');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = phone1;
		}
		else if( !isTelephoneNum(phone1.value))
		{
			booErr = true;
			span = document.getElementById('sp1Phone');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = phone1;
		}
	
		if( best_time1.value.length == 0 )
		{
			booErr = true;
			span = document.getElementById('sp1Best');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = best_time1;
		}
		if( how_heard1.value.length == 0 )
		{
			booErr = true;
			span = document.getElementById('sp1Heard');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = how_heard1;
		}
		if (booErr)
		{
			focusObj.focus();
			var divY = document.getElementById('divMessage');
			if (divY)
			{
				divY.innerHTML = 'Please correct the fields highlighted in red below';
			}
		}
		else
		{				
			xn.value='callme';
			submit();
		}	
	}

}

function DoIQualify()
{
	var booErr=false;
	var focusObj;
	var span;
	
	span = document.getElementById('sp1Debt');
	if (span)
	{
		span.className = '';
	}
	span = document.getElementById('sp1Creditors');
	if (span)
	{
		span.className = '';
	}
	span = document.getElementById('sp1Employed');
	if (span)
	{
		span.className = '';
	}
	span = document.getElementById('sp1Title');
	if (span)
	{
		span.className = '';
	}
	span = document.getElementById('sp1Fname');
	if (span)
	{
		span.className = '';
	}
	span = document.getElementById('sp1Sname');
	if (span)
	{
		span.className = '';
	}
	span = document.getElementById('sp1Phone');
	if (span)
	{
		span.className = '';
	}
	span = document.getElementById('sp1Email');
	if (span)
	{
		span.className = '';
	}
	span = document.getElementById('sp1Heard');
	if (span)
	{
		span.className = '';
	}
	
	with (document.aspnetForm)
	{
		if( unsecured_debt1.value.length == 0 )
		{
			booErr = true;
			span = document.getElementById('sp1Debt');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = unsecured_debt1;
		}
		if( creditors1.value.length == 0 )
		{
			booErr = true;
			span = document.getElementById('sp1Creditors');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = creditors1;
		}
		if( employment1.value.length == 0 )
		{
			booErr = true;
			span = document.getElementById('sp1Employed');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = employment1;
		}
		if( title1.value.length == 0 )
		{
			booErr = true;
			span = document.getElementById('sp1Title');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = title1;
		}
		if( firstname1.value.length == 0 )
		{
			booErr = true;
			span = document.getElementById('sp1Fname');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = firstname1;
		}
		else if( !isName(firstname1.value) )
		{
			booErr = true;
			span = document.getElementById('sp1Fname');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = firstname1;
		}	
		if( surname1.value.length == 0 )
		{
			booErr = true;
			span = document.getElementById('sp1Sname');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = surname1;
		}
		else if( !isName(surname1.value) )
		{
			booErr = true;
			span = document.getElementById('sp1Sname');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = surname1;
		}
		if( phone1.value.length == 0)
		{
			booErr = true;
			span = document.getElementById('sp1Phone');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = phone1;
		}
		else if( !isTelephoneNum(phone1.value))
		{
			booErr = true;
			span = document.getElementById('sp1Phone');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = phone1;
		}
		if( email1.value.length == 0 )
		{
			booErr = true;
			span = document.getElementById('sp1Email');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = email1;
		}
		else if( !isEmail(email1.value) )
		{
			booErr = true;
			span = document.getElementById('sp1Email');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = email1;
		}
		if( how_heard1.value.length == 0 )
		{
			booErr = true;
			span = document.getElementById('sp1Heard');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = how_heard1;
		}
		if (booErr)
		{
			focusObj.focus();
			var divY = document.getElementById('divMessage');
			if (divY)
			{
				divY.innerHTML = 'Please correct the fields highlighted in red below';
			}
		}
		else
		{				
			xn.value='qualify';
			submit();
		}	
	}

}


function ApplyMain()
{
	var booErr=false;
	var focusObj;
	var span;
	
	span = document.getElementById('sp1Debt');
	if (span)
	{
		span.className = '';
	}
	span = document.getElementById('sp1Creditors');
	if (span)
	{
		span.className = '';
	}
	span = document.getElementById('sp1Disposable');
	if (span)
	{
		span.className = '';
	}
	span = document.getElementById('sp1Title');
	if (span)
	{
		span.className = '';
	}
	span = document.getElementById('sp1Fname');
	if (span)
	{
		span.className = '';
	}
	span = document.getElementById('sp1Sname');
	if (span)
	{
		span.className = '';
	}
	span = document.getElementById('sp1Phone');
	if (span)
	{
		span.className = '';
	}
	span = document.getElementById('sp1Email');
	if (span)
	{
		span.className = '';
	}
	span = document.getElementById('sp1Heard');
	if (span)
	{
		span.className = '';
	}
	
	with (document.aspnetForm)
	{
		if( unsecured_debt1.value.length == 0 )
		{
			booErr = true;
			span = document.getElementById('sp1Debt');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = unsecured_debt1;
		}
		if( creditors1.value.length == 0 )
		{
			booErr = true;
			span = document.getElementById('sp1Creditors');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = creditors1;
		}
		if( monthly_disposable_income1.value.length == 0 )
		{
			booErr = true;
			span = document.getElementById('sp1Disposable');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = monthly_disposable_income1;
		}
		if( title1.value.length == 0 )
		{
			booErr = true;
			span = document.getElementById('sp1Title');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = title1;
		}
		if( firstname1.value.length == 0 )
		{
			booErr = true;
			span = document.getElementById('sp1Fname');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = firstname1;
		}
		else if( !isName(firstname1.value) )
		{
			booErr = true;
			span = document.getElementById('sp1Fname');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = firstname1;
		}	
		if( surname1.value.length == 0 )
		{
			booErr = true;
			span = document.getElementById('sp1Sname');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = surname1;
		}
		else if( !isName(surname1.value) )
		{
			booErr = true;
			span = document.getElementById('sp1Sname');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = surname1;
		}
		if( phone1.value.length == 0)
		{
			booErr = true;
			span = document.getElementById('sp1Phone');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = phone1;
		}
		else if( !isTelephoneNum(phone1.value))
		{
			booErr = true;
			span = document.getElementById('sp1Phone');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = phone1;
		}
		if( email1.value.length == 0 )
		{
			booErr = true;
			span = document.getElementById('sp1Email');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = email1;
		}
		else if( !isEmail(email1.value) )
		{
			booErr = true;
			span = document.getElementById('sp1Email');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = email1;
		}
		if( how_heard1.value.length == 0 )
		{
			booErr = true;
			span = document.getElementById('sp1Heard');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = how_heard1;
		}
		if (booErr)
		{
			focusObj.focus();
			var divY = document.getElementById('divMessage');
			if (divY)
			{
				divY.innerHTML = 'Please correct the fields highlighted in red below';
			}
		}
		else
		{				
			xn.value='applymain';
			submit();
		}	
	}

}


function SendQuery()
{
	var booErr=false;
	var focusObj;
	var span;
	
	
	span = document.getElementById('sp1Fullname');
	if (span)
	{
		span.className = '';
	}
	span = document.getElementById('sp1Phone');
	if (span)
	{
		span.className = '';
	}
	span = document.getElementById('sp1Email');
	if (span)
	{
		span.className = '';
	}
	span = document.getElementById('sp1Query');
	if (span)
	{
		span.className = '';
	}
	
	with (document.aspnetForm)
	{
		if( fullname1.value.length == 0 )
		{
			booErr = true;
			span = document.getElementById('sp1Fullname');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = fullname1;
		}
		if( phone1.value.length == 0)
		{
			booErr = true;
			span = document.getElementById('sp1Phone');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = phone1;
		}
		else if( !isTelephoneNum(phone1.value))
		{
			booErr = true;
			span = document.getElementById('sp1Phone');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = phone1;
		}
		if( email1.value.length == 0 )
		{
			booErr = true;
			span = document.getElementById('sp1Email');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = email1;
		}
		else if( !isEmail(email1.value) )
		{
			booErr = true;
			span = document.getElementById('sp1Email');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = email1;
		}
		if( query1.value.length == 0 )
		{
			booErr = true;
			span = document.getElementById('sp1Query');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = query1;
		}
		if (booErr)
		{
			focusObj.focus();
			var divY = document.getElementById('divMessage');
			if (divY)
			{
				divY.innerHTML = 'Please correct the fields highlighted in red below';
			}
		}
		else
		{				
			xn.value='query';
			submit();
		}	
	}

}


function Apply()
{
	var booErr=false;
	var focusObj;
	var span;
	
	span = document.getElementById('spTitle');
	if (span)
	{
		span.className = '';
	}
	span = document.getElementById('spFname');
	if (span)
	{
		span.className = '';
	}
	span = document.getElementById('spSname');
	if (span)
	{
		span.className = '';
	}
	span = document.getElementById('spPhone');
	if (span)
	{
		span.className = '';
	}
	span = document.getElementById('spDebt');
	if (span)
	{
		span.className = '';
	}
	span = document.getElementById('spCreditors');
	if (span)
	{
		span.className = '';
	}
	span = document.getElementById('spDisposable');
	if (span)
	{
		span.className = '';
	}
	span = document.getElementById('spEmail');
	if (span)
	{
		span.className = '';
	}
	span = document.getElementById('spPcode');
	if (span)
	{
		span.className = '';
	}
	span = document.getElementById('spAdd1');
	if (span)
	{
		span.className = '';
	}
	span = document.getElementById('spHeard');
	if (span)
	{
		span.className = '';
	}
	
	with (document.aspnetForm)
	{

		if( title.value.length == 0 )
		{
			booErr = true;
			span = document.getElementById('spTitle');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = title;
		}
		if( firstname.value.length == 0 )
		{
			booErr = true;
			span = document.getElementById('spFname');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = firstname;
		}
		else if( !isName(firstname.value) )
		{
			booErr = true;
			span = document.getElementById('spFname');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = firstname;
		}	
		if( surname.value.length == 0 )
		{
			booErr = true;
			span = document.getElementById('spSname');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = surname;
		}
		else if( !isName(surname.value) )
		{
			booErr = true;
			span = document.getElementById('spSname');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = surname;
		}
		if( phone.value.length == 0)
		{
			booErr = true;
			span = document.getElementById('spPhone');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = phone;
		}
		else if( !isTelephoneNum(phone.value))
		{
			booErr = true;
			span = document.getElementById('spPhone');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = phone;
		}
		if( unsecured_debt.value.length == 0 )
		{
			booErr = true;
			span = document.getElementById('spDebt');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = unsecured_debt;
		}
		if( creditors.value.length == 0 )
		{
			booErr = true;
			span = document.getElementById('spCreditors');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = creditors;
		}
		if( monthly_disposable_income.value.length == 0 )
		{
			booErr = true;
			span = document.getElementById('spDisposable');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = monthly_disposable_income;
		}
		if( email.value.length == 0 )
		{
			booErr = true;
			span = document.getElementById('spEmail');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = email;
		}
		else if( !isEmail(email.value) )
		{
			booErr = true;
			span = document.getElementById('spEmail');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = email;
		}
		if( postcode.value.length == 0 )
		{
			booErr = true;
			span = document.getElementById('spPcode');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = postcode;
		}
		else if( !isPostcode(postcode.value) )
		{
			booErr = true;
			span = document.getElementById('spPcode');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = postcode;
		}	
		if( address1.value.length == 0 )
		{
			booErr = true;
			span = document.getElementById('spAdd1');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = postcode;
		}
		if( how_heard.value.length == 0 )
		{
			booErr = true;
			span = document.getElementById('spHeard');
			if (span)
			{
				span.className = 'FldError';
			}
			if( !focusObj )
				focusObj = how_heard;
		}
		if (booErr)
		{
			focusObj.focus();
			return;
		}
		else
		{		
		    action.value = '../pages/page.aspx';		
			xn.value = 'apply';
			submit();
		}	
		

	}
}



function _Numbers(iObj)
{
    var i, pStr;
	var strValidChars = "0123456789";
	pStr = iObj.value;
	
    for (i = 0; i < pStr.length; i++)
    {
        var c = pStr.charAt(i);
		
		if(strValidChars.indexOf(c) < 0)  
		{	
			window.alert("Please use numeric characters only");
			iObj.value = pStr.substring(0,i)
			iObj.focus();
			return;
		}
    }
}



function isTelephoneNum(pStr)
{
    var i;
	var j = pStr;
	var strValidChars = "0123456789 ";
	pStr = j.replace(/ +/g,'');	
	
    for (i = 0; i < pStr.length; i++)
    {
        var c = pStr.charAt(i);
		
		if(strValidChars.indexOf(c) < 0)  
		{	return false;
		}
    }

	var idxi = pStr.indexOf("01");
	var idxj = pStr.indexOf("02");
	var idxk = pStr.indexOf("03");
	var idxl = pStr.indexOf("07");
 	var len = pStr.length;

	return ( (len > 9 && len < 12) && ((idxi==0)||(idxj==0)||(idxk==0)||(idxl==0)) );
}

function isName(pStr)
{
	var nameexp = /^([a-z,']+\s*\-*)+$/i;
	
	return( nameexp.test(pStr) );
}

function isEmail(pStr)
{
	var objText=pStr;
	var reg01 = /(@.*@)|(\.\.)|(@\.)|\,|\;|\\|\!|\%|\$|\&|\*|\(|\)|\=|\s|\'|\"|(\.@)|(^\.)/;   // not valid
	var reg02 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/; // is valid
		
	return( (!reg01.test(objText) && reg02.test(objText)) );	
}

function isPostcode(pStr)
{
	var postcodeexp = /^[a-z]{1,2}[0-9]{1,2}\s*\D{0,2}[0-9]{1,1}[a-z]{1,2}$/i;
	var objText=pStr;
	
	return( objText.match(postcodeexp) );
}


function showHelp(what)
{
	var str;
	var divX = document.getElementById('divHelp');
	if (divX)
	{
		
		switch (what)
		{
			case 'debt':
				str = 'Total Unsecured Debt: <br /><br />Total owed on credit and store cards, hire purchases, ';
				str = str + 'unsecured loans, etc. Numerical characters only.';
				break;
			case 'creditors':
				str = 'Creditors: <br /><br />The companies you owe.';
				break;
			case 'telephone':
				str = 'Telephone: <br /><br />Please enter a valid UK telephone or mobile number. ';
				str = str + 'Numerical characters and spaces allowed.';
				break;
			case 'disposable':
				str = 'Monthly Disposable Income: <br /><br />The amount (in &pound;) you have left after essential bills.';
				break;
				
		}
		str = str + '<p><a href="javascript:hideHelp();"> Close </a></p>'
		divX.innerHTML = str;
//		alert(y);
		divX.style.top = (y-2)+'px';
		divX.style.left = (x-172)+'px';
		divX.style.display = 'block';
		
	}
}
function hideHelp()
{
	var divX = document.getElementById('divHelp');
	if (divX)
	{
		divX.innerHTML = '';
	}
	divX.style.left = 0;
	divX.style.top = 0;
	divX.style.display = 'none';
}

function Pay()
{
	with (document.aspnetForm)
	{
		action = '../pages/netbanx.aspx';
		target='_blank';
		submit();
	}
}

