$(document).ready(function() {
	
	//alert($("form#validatedform").attr("action"));
	
	var v_no; // as global
	
	if ($("form#validatedform").attr("action") != null && ($("form#validatedform").attr("action").search('/emailfunction.php') || $("form#validatedform").attr("action") =='/emailfunction.php')) {
	//if ($("form#validatedform").attr("action") != null && $("form#validatedform").attr("action") =='/emailfunction.php') {
		v_no = Math.random();
		v_no = v_no * 9999;
		v_no = Math.ceil(v_no);
		
		if (v_no < 1000) v_no = v_no +1000;
		
		//alert("form_validatedform = " + v_no);
		
		var $verify = '<div style="padding-top:10px;padding-bottom:8px;">Type the code shown in the image <span class="verifyNumber">'+ v_no +'</span></div> <input id="jqverify" type="text" name="jqverfy"><br /><br />';
		$verify += '<input type="hidden" type="text" name="verify_vcode" id="verify_vcode" value="'+ v_no +'" />';
		
		//$("form#validatedform input[@type=submit]").before($verify);
		$("form#validatedform input:submit").before($verify);
	}
	
	$("form#validatedform").submit(function() {
		//alert($("#jqverify").val() + " &" + v_no);
		
		$(".warnvcode").remove();
		if ($("#jqverify").val()!= v_no) {
			$("#jqverify").css("background-color","red");
			$("#jqverify").val("");
			//alert("Wrong V.code or you did not type V.code");
			$("form#validatedform input:submit").before('<b class="warnvcode" style="color:red;">Verification code field is required or you did not type correct number<br /></b>');
			return false;
		}
	});
	
	
	
	if ($("form#form_newsletter").attr("action")!= null ) {
		
		v_no = Math.random();
		v_no = v_no * 9999;
		v_no = Math.ceil(v_no);
		
		if (v_no < 1000) v_no = v_no +1000;
		//alert("form_newsletter = " + v_no);
		
		var $verify = '<div style="padding-top:10px;padding-bottom:8px;">Type the code shown in the image <span class="verifyNumber">'+ v_no +'</span></div> <input id="jqverify" type="text" name="jqverfy"><br /><br />';
		
		$("form#form_newsletter input:submit").before($verify);
		
	}
	
	$("form#form_newsletter").submit(function() {
		//alert($("#jqverify").val() + " &" + v_no);
		$(".warnvcode").remove();
		
		
		
		if ($("#jqverify").val()!= v_no) {
			$("#jqverify").css("background-color","red");
			$("#jqverify").val("");
			//alert("Wrong V.code or you did not type V.code");
			$("form#form_newsletter input:submit").before('<b class="warnvcode" style="color:red;">Verification code field is required or you did not type correct number<br /></b>');
			return false;
		}
		
	});
	
});
