$(document).ready(function(){
	$.ajax({ url: "captcha_res.php", success: function(data){
        $("#res_value").val(data);
      }});					   
});
function reloadCaptcha(){
	document.getElementById('captcha').src = document.getElementById('captcha').src+ '?' +new Date();
	$.ajax({ url: "captcha_res.php", success: function(data){
		$("#res_value").val(data);
	  }});		
}

function validate_email(myEmail) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(reg.test(myEmail) == false) {
		return false;
	}
}

function validate(){
	var name = $("#name").val();//document.forms.OnlineAdvice.name.value;
	var email = $("#email").val();//document.forms.OnlineAdvice.email.value;
	var captcha = $('#captcha_code').val();
	var agree = $("input[name='confirmCheckbox']:checked").val();
	var res = true; 
	var msg = "Please check the following errors:- \n";
	if(name.length < 1){
		res = false;
		msg += " - Please provide your Name. \n";
	}
	if(!email.match(/^\w+([\.\-]\w+)*@\w+([\.\-]\w+)*\.[a-z]{2,4}$/i)){
		res = false;	
		msg += " - Please provide a valid email address. \n";			
	}
	if(captcha != $("#res_value").val()){
		res = false;
		msg += " - Please check the Math Result, feel free to use your system calculator we won't tell anyone. :)\n";
	}
	if(agree == undefined){
		res = false;
		msg += " - Please confirm that you agree with our Terms & Conditions.\n";
	}
	if(res == false){
		alert(msg);				
		return false;				
	}
	else {
	$("#frm_Acc_Signup").submit();	
	return true;
	}
}



function validate_form2()
{
	var name = document.forms.OnlineAdvice.name.value;
	var email = document.forms.OnlineAdvice.email.value;
	var captcha = $('#captcha_code').val();
	var res = true; 
	var msg = "Please check the following errors:- \n";
		if(name.length == 0)	
		{
			res = false;
			msg += " - Please provide your Name. \n";
		}
		if(!email.match(/^\w+([\.\-]\w+)*@\w+([\.\-]\w+)*\.[a-z]{2,4}$/i))
		{
			res = false;	
			msg += " - Please provide a valid email address. \n";			
		}
		if(captcha != $("#res_value").val()){
			res = false;
			msg += " - Please check the Math Result, feel free to use your system calculator we won't tell anyone. :)\n";
		}
	
	if(res == false)				
	{
		alert(msg);				
		return false;				
	}
	else return true;		
}
