function validContactForm(){
var errorcount = '';

var names = $('#name');
	if(! names.val().match(/([a-z])/i)){
	errorcount+="- "+names.attr('alt')+"\n";
	}
	var surname = $('#surname');
	if(! surname.val().match(/([a-z])/i)){
	errorcount+="- "+surname.attr('alt')+"\n";
	}
var term = $('#terms');
	if(! term.val().match(/([a-z])/i)){
	errorcount+="- "+term.attr('alt')+"\n";
	}

var phone = $('#Phone');
	if(! phone.val().match(/[0-9 ]{11,16}/i)){
	errorcount+="- "+phone.attr('alt')+"\n";
	}
	
var times = $('#BestTime');
	if(times.val() == ''){
	errorcount+= "- Best time to be contacted\n";
	}
	
if(errorcount == '' ){
$('#quick_contact_form').submit();
return true;
}
alert("please correct the below\n\n"+errorcount);
return false;
}

function populateDate(){
	
    var selstr;
	
	selstr = '<select name="BestTime" id="BestTime" width="170px" style="font-size:11px; font-family:Arial, Helvetica, sans-serif; color:#767676; width:160px;"><option value="Anytime">Anytime</option><option value="9am-12noon">9am-12noon</option><option value="12noon-3pm">12noon-3pm</option><option value="3pm-6pm">3pm-6pm</option><option value="6pm-9pm">6pm-9pm</option></select>';
	
	return selstr;
	
}

function form_set_effect(namespace, obj, message){

	if(!obj){
	$('.form_help_icon').remove();
	}else{
	
		if(message){ 
		//$('#'+namespace+'_'+obj.attr('name')+'_e').html(message);
		newId = obj.attr('id');
		$(obj).after('<div id="fhi-'+newId+'" title="'+message+'"  class="form_help_icon"></div>');
		
		}
	}

}
function forms_validate(namespace){
error_count = 0;

if(!namespace){
alert('namespace not set');
return false;
}

form_set_effect(namespace);

var msg = '';

fnx = $('#'+namespace+'_firstname');
lnx = $('#'+namespace+'_lastname');
hpx = $('#'+namespace+'_homephone');
mpx = $('#'+namespace+'_mobilephone');
pcx = $('#'+namespace+'_postcode');
emx = $('#'+namespace+'_email');
udx = $('#'+namespace+'_unsecured_debt');
eax = $('#'+namespace+'_equity_amount');
apx = $('#'+namespace+'_accept_policy');
//wiz
nsx = $('#'+namespace+'_names');
gpx = $('#'+namespace+'_phone');
tcx = $('#'+namespace+'_time_to_contact');
ncx = $('#'+namespace+'_creditors');
mix = $('#'+namespace+'_monthly_income');
	
	if(nsx.val() != undefined)
	if(!nsx.val().match(/[a-z]+ +[a-z]/i)){
	error_count++;
	msg += "Please insert your name and surname?\n";
	//form_set_effect(namespace, nsx, 'Required, min 2 characters');
	}
	
	if(gpx.val() != undefined)
	if(!gpx.val().match(/[0-9 ]{11,16}/i)){
	error_count++;	
	msg += "Please insert your 11 digit telephone number?\n";
	//form_set_effect(namespace, gpx, 'Required, min 11, numbers only');
	}
	
	if(tcx.val() != undefined)
	if(!tcx.val() != ''){
	error_count++;	
	msg += "Please select best time to contact?\n";
	//form_set_effect(namespace, tcx, 'Required, time we should call you');
	}
	
	if(ncx.val() != undefined)
	if(!ncx.val().match(/[0-9]/)){
	error_count++;
	msg += "Please insert numeric value for creditors?\n";
	//form_set_effect(namespace, ncx, 'Required, numbers only');
	}
	
	if(mix.val() != undefined)
	if(!mix.val().match(/[0-9]/)){
	error_count++;
	msg += "Please insert numeric value for monthly income?\n";
	//form_set_effect(namespace, mix, 'Required, numbers only');
	}
	
	if(fnx.val() != undefined)
	if(!fnx.val().match(/[a-z]+ +[a-z]/i)){
	error_count++;
	msg += "Please insert your name and surname?\n";
	//form_set_effect(namespace, fnx, 'Required, min 2 characters');
	}
	
	if(lnx.val() != undefined)
	if(!lnx.val().match(/[a-z]+ +[a-z]/i)){
	error_count++;
	msg += "Please insert your name and surname?\n";
	//form_set_effect(namespace, lnx, 'Required, min 2 characters');
	}
	
	if(hpx.val() != undefined)
	if(!hpx.val().match(/[0-9 ]{11,16}/i)){
	error_count++;
	msg += "Please insert your 11 digit telephone number?\n";
	//form_set_effect(namespace, hpx, 'Required, min 11, numbers only');
	}
	
	if(mpx.val() != undefined)
	if(!mpx.val().match(/[0-9 ]{11,16}/i)){
	error_count++;
	msg += "Please insert your 11 digit mobile number?\n";
	//form_set_effect(namespace, mpx, 'Required, min 11, numbers only');
	}
	
	if(pcx.val() != undefined)
	if(!pcx.val().match(/[a-z0-9 ?]{5,7}/i)){
	error_count++;
	msg += "Please insert your postcode, min 5 characters?\n";
	//form_set_effect(namespace, pcx, 'Required, min 5 characters');
	}
	
	if(emx.val() != '' && emx.val() != undefined){
		if(!emx.val().match(/\b[A-Z0-9._%-]+@[A-Z0-9_%-]+\.[A-Z]{2,4}\b/i)){
		error_count++;
		msg += "Please insert a valid email address?\n";
		//form_set_effect(namespace, emx, 'Required, valid email');
	  }
	}
	
	if(udx.val() != undefined)
	if(!udx.val().match(/[0-9]/i)){
	error_count++;
	msg += "Please choose unsecured debt option?\n";
	//form_set_effect(namespace, udx, 'Required, choose 1');
	}
	
	if(eax.val() != undefined)
	if($('#'+namespace+'_home_owner_on').attr('checked') && !eax.val().match(/[0-9]/i)){
	error_count++;
	msg += "Please choose equity amount option?\n";
	//form_set_effect(namespace, eax, 'Required, choose 1');
	}
	
	if(apx.val() != undefined)
	if(!apx.attr('checked')){
	error_count++;
	msg += "Please accept the privacy policy?\n";
	//form_set_effect(namespace, apx, 'Accept policy by ticking');
	}
	
	if(error_count == 0){
	$('#'+namespace+'_form').attr('action', $('#'+namespace+'_dest_url').val());
	$('#'+namespace+'_form').submit();
	}else{
	  alert(msg);
	  return false;
	}

}
$(document).ready(function(){

$('#wiz_home_owner_on').click(function(){ 
	if(this.checked == true){
	$('#wiz_equity_amount').attr('disabled', false);
	}
});
$('#wiz_home_owner_off').click(function(){ 
	if(this.checked == true){
	$('#wiz_equity_amount').attr('disabled', true);
	}
});

$('#quick_home_owner_on').click(function(){ 
	if(this.checked == true){
	$('#quick_equity_amount').attr('disabled', false);
	}
});
$('#quick_home_owner_off').click(function(){ 
	if(this.checked == true){
	$('#quick_equity_amount').attr('disabled', true);
	}
});

/*$("#wiz_form :input").each(bind('blur',
								function(){alert('f');}
								);*/

});
