
var authenticate_url = "/dap/authenticate_captcha.php";
var dap_authenticate_url = "/dap/authenticate_captcha.php";

function validateDAPLoginFormWithCaptcha(form) {
	var badTextArray = new Array("\"","`","!","%","^","&","*","(",")","'",";");
	
	for(i=0; i<form.elements.length; i++){
   		if( (form.elements[i].name == "email") || (form.elements[i].name == "password")) {

			if(form.elements[i].value == "") {
				var missing_info_msg = unescape(MSG_MISSING_INFO);
				swal({
				      title: "",
				      text: missing_info_msg,
				      confirmButtonText: "OK"
				  },
				  function(isConfirm) {
				      if (isConfirm) {
				          setTimeout(function() {
				            form.elements[i].focus();
				          }, "slow");
				      }
				  });
				return false;
			}
		}
   	}
   
   	jQuery("#"+form.id+" .frontend_captcha_login").each(function(index, el){
		var response =grecaptcha.getResponse(jQuery(this).attr('data-id'));
		//var response = grecaptcha.getResponse();
		
		var missing_captcha_info_msg = jQuery(".captcha_msg").val();
		if(missing_captcha_info_msg !=""){
			var missing_captcha_info_msg = missing_captcha_info_msg;
		}else{
			var missing_captcha_info_msg = "Please Select Captcha.";
		}
		
		if(response.length == 0) { 
			swal({
			      title: "",
			      text: missing_captcha_info_msg,
			      confirmButtonText: "OK"
			},
			function(isConfirm) {
				if (isConfirm) {
				  setTimeout(function() {
				    jQuery(".recaptcha-checkbox-checkmark").focus();
				  }, "slow");
				}
			});
			return false;
		}else{
			/*jQuery(".submit_btn").text("Please Wait...") ;	*/
			form.action = authenticate_url;
			form.submit();
			return true;
		}
	});
} 
 

function validateWWithCaptcha(form) {
	for(i=0; i<form.elements.length; i++){
   		if( (form.elements[i].name == "email") || (form.elements[i].name == "password")) {
			if(form.elements[i].value == "") {
				var missing_info_msg = unescape(MSG_MISSING_INFO);
				swal({
				      title: "",
				      text: missing_info_msg,
				      confirmButtonText: "OK"
				  },
				  function(isConfirm) {
				      if (isConfirm) {
				          setTimeout(function() {
				            form.elements[i].focus();
				          }, "slow");
				      }
				  });
				return false;
			}
		}
   	}

	jQuery("#"+form.id+" .frontend_captcha_login").each(function(index, el){
	   	var response =grecaptcha.getResponse(jQuery(this).attr('data-id'));
		var missing_captcha_info_msg = jQuery(".captcha_msg").val();
		if(missing_captcha_info_msg !=""){
			var missing_captcha_info_msg = missing_captcha_info_msg;
		}else{
			var missing_captcha_info_msg = "Please Select Captcha.";
		}
		
		if(response.length == 0) { 
			swal({
			      title: "",
			      text: missing_captcha_info_msg,
			      confirmButtonText: "OK"
			},
			function(isConfirm) {
				if (isConfirm) {
				  setTimeout(function() {
				    jQuery(".recaptcha-checkbox-checkmark").focus();
				  }, "slow");
				}
			});
			return false;
		}else{
			form.action = dap_authenticate_url;
	    	form.submit();
			return true;
		}
	});

}


