// Show hide
function showdiv(name){
var obj = (document.getElementById)? document.getElementById(name) : eval("document.all[name]");
if (obj.style.display=="none"){
obj.style.display="";
}else{
obj.style.display="none";
}
}

function showdiv2(name){
document.getElementById('infobox-debt').style.display="none"
document.getElementById('infobox-residential').style.display="none"

document.getElementById(name).style.display="block"
}

function hidediv(name){
var obj = (document.getElementById)? document.getElementById(name) : eval("document.all[name]");
obj.style.display="none";
}




//Font Resizer
var xmlhttp;
var DivStyle
function fontresize(divID) {
   
    DivStyle = divID 
	xmlhttp = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest && !(window.ActiveXObject)) {
    	try {
			xmlhttp = new XMLHttpRequest();
        } catch(e) {
			xmlhttp = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		xmlhttp = false;
        	}
		}
    }
    
	if(xmlhttp) {
		var url = '/containercookie.aspx?ClassName=' + divID
		xmlhttp.onreadystatechange = changeClass
		xmlhttp.open("GET", url , true)
		xmlhttp.send(null)
		
	}
}
 
function changeClass() {
    if (xmlhttp.readyState==4){
       if (xmlhttp.status==200) {
        document.getElementById("main-container").className = DivStyle
       }
    }
}

function validate() {

	var txtForenames = document.getElementById("txtForenames"); resetError(txtForenames)
	var txtSurname = document.getElementById("txtSurname"); resetError(txtSurname);
	var txtHometelno = document.getElementById("txtHometelno"); resetError(txtHometelno);
	var txtMobiletelno = document.getElementById("txtMobiletelno"); resetError(txtMobiletelno);
	var txtEmail = document.getElementById("txtEmail"); resetError(txtEmail);
	var chkPrivacyPolicy = document.getElementById("chkPrivacyPolicy"); resetError(chkPrivacyPolicy);
	var txtLoanAmount = document.getElementById("txtLoanAmount");resetError(txtLoanAmount);
	var txtResidential = document.getElementById("txtResidential");resetError(txtResidential);
	var txtEmployment = document.getElementById("Employment");resetError(txtEmployment);
	var cboWhenCall = document.getElementById("cboWhenCall");resetError(cboWhenCall);

	var msg = "";

	
	if (txtLoanAmount.value != "0" && txtResidential.value != "0" && txtEmployment.value != "0" && vrule_name(txtForenames.value) && vrule_name(txtSurname.value) && (vrule_telephone(txtHometelno.value) || vrule_telephone(txtMobiletelno.value)) && vrule_email(txtEmail.value) && chkPrivacyPolicy.checked==true) {
		// tidy up the field content before submitting
		document.getElementById("txtHometelno").value = vtidy_telephone( txtHometelno.value );
		document.getElementById("txtMobiletelno").value = vtidy_telephone( txtMobiletelno.value );
		return true;	
		} else {
		if (txtLoanAmount.value == "0"){highlightErrorCallBack(txtLoanAmount);msg = msg + " - Your approximate total debt\n"} 
		if (txtEmployment.value == "0"){highlightErrorCallBack(txtEmployment);msg = msg + " - Your employment status\n"} 
		if (txtResidential.value == "0"){highlightErrorCallBack(txtResidential);msg = msg + " - Where you live\n"} 
		if (!vrule_name(txtForenames.value)){highlightErrorCallBack(txtForenames);msg = msg + " - First name\n"} 
		if (!vrule_name(txtSurname.value)){highlightErrorCallBack(txtSurname);msg = msg + " - Surname\n"} 
		if(!vrule_telephone(txtHometelno.value) && !vrule_telephone(txtMobiletelno.value)){highlightErrorCallBack(txtHometelno); msg = msg + " - A valid home or mobile number\n"} ; 
		if(!chkPrivacyPolicy.checked==true){msg = msg + " - Tick the box to agree to our privacy policy\n"}  
		alert ("Please check that the following fields have been filled correctly:\n\n" + msg)
		return false;
	}
}

function vrule_telephone( value ) {	
	value = vtidy_telephone( value );
	telNoPattern = /^\d{11}$/;
	return telNoPattern.test(value);
}

function vtidy_telephone( value ) {
	// strip out any spaces and other junk
	return value.replace( /[^0-9]/g, "");
}

function vrule_name( value ) {	
	if (value.length == 0 || value == "First name" || value == "Surname") return false; // name is required	
	telNoPattern = /^[a-zA-Z\-\' ]*$/;	
	return telNoPattern.test(value);
}

function vrule_text( value ) {	
	if (value.length == 0){return false; }
	else
	{return true}
}


function vrule_email( value ) {
	
	if (value.length == 0) return true; // email address is optional	
	telNoPattern = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
	return telNoPattern.test(value);
}

// Tooltip show hide
// Tooltip show hide
function showdiv(name){

if (document.getElementById(name)){
var obj = document.getElementById(name)
}

if (obj.style.display=="none"){
obj.style.display="";

document.getElementById("faq-" + name).style.backgroundImage = "url(img/faq-minus.png)"

}else{
obj.style.display="none";

document.getElementById("faq-" + name).style.backgroundImage = "url(img/faq-plus.png)"
}
}

function hidediv(name){
var obj = (document.getElementById)? document.getElementById(name) : eval("document.all[name]");
obj.style.display="none";
}

// Show details and errors

function showDetails() {
	changeDisplay( "details", "block" );
}

function hideDetails() {
	changeDisplay( "details", "none" );
}

function changeDisplay( id, type ) {
	var sel = document.getElementById( id );
	sel.style.display = type;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// Pop up window

function openpopup(popurl){
var winpops=window.open(popurl,"","width=550,height=500,scrollbars,resizable")
}

function displayError( msg ){
	document.getElementById('warning').innerHTML = msg
	document.getElementById('warning').style.display= 'block'}

function highlightError( id ){
	id.style.borderColor='#FF8100';

}

function highlightErrorCallBack( id ){
	id.style.borderColor='#FF8100';
	id.style.backgroundImage = "url(../images/app-asterisk.png)";

}

function highlightErrorCB( id ){
	id.style.borderColor='#FF8100';
	id.style.backgroundColor='#FF8100';
}

function resetError( id ){
	id.style.borderColor='#A5A9AB';
	id.style.backgroundImage  = 'none'
}
function resetErrorMain( id ){
	id.style.borderColor='#A5A9AB';
	id.style.backgroundImage.src  = 'none'
}



