/* jQuery code for contact us form    It uses the .ajax function to asynchronously send the quicknote message   and the blockUI.js to disable the form while sending the message.   It first checks the form for errors and puts up the appropriate message   using the *//*** general purpose functions used in the script ***//* Captcha function to reload image */function reloadCaptcha() {	now = new Date();	var capObj = document.getElementById('phoca-captcha');		if (capObj) {		capObj.src = capObj.src + (capObj.src.indexOf('?') > -1 ? '&' : '?') + Math.ceil(Math.random()*(now.getTime()));	 }}/* This function checks if the input string is empty. */function isEmpty(inputStr){  if(inputStr == null || inputStr == "")     return true;  return false;}/* This function checks for valid email addresses. */function isEmailAddr(inputStr) {  var hasAtSign = false;  var hasDotRightOfAt = false;    for(var i = 0; i < inputStr.length; i++) {     if(i > 0 && inputStr.charAt(i) == "@") {	    hasAtSign = true;		continue;	 }	 if(inputStr.charAt(i) == "." && hasAtSign) 	    hasDotRightOfAt = true;  }  if(hasAtSign && hasDotRightOfAt)     return true;	   return false;}/* first check that JavaScript is enabled */if(document.getElementById && document.createTextNode) { 	/* run jQuery if JavaScript is enabled */	$(document).ready(function()  {			/* setup .ajax */		$.ajaxSetup({			type: "POST",			dataType: "html"		});		/* hide email addresses */		var spt = $('span.mailaddr');		var at = / at /;		var dot = / dot /g;		$(spt).each(function(){			var addr = $(this).text().replace(at,"@").replace(dot,".");			$(this).after('<a href="mailto:'+addr+'" title="Send an email">'+ addr +'</a>')				  .hover(function(){window.status="Send an email!";}, function(){window.status="";});			$(this).remove();		});		/* hide the errMsg <p> tag */		$("#errMsg").hide();		/* setup the form click action */		$("#btnSubmit").click(function() {			/* reset colour and background for labels and message */			$("#quicknote label").each(function() {				$(this).css("color","#666666");			});			$("#errMsg").addClass("errMsgQN");			$("#errMsg").css("color","#f00");						/* setup variables for form inputs */			var fname = $("#FName").val();			var lname = $("#LName").val();			var email = $("#Email").val();			var msg = $("#Note").val();			var captcha = $("#Captcha").val();			var frmErrors = false;  //flag to indicate if there are errors on the form						/* validate the form inputs */			if(isEmpty(fname)) {				$("#lblFname").css("color","#f00");    //change the text colour				//$("#FName").css("background","#f3f5f6");     //change the background colour				frmErrors = true;			}			if(isEmpty(lname)) {				$("#lblLname").css("color","#f00");    //change the text colour				//$("#LName").css("background","#f3f5f6");     //change the background colour				frmErrors = true;			}			if(isEmpty(email)) {				$("#lblEmail").css("color","#f00");    //change the text colour				//$("#Email").css("background","#f3f5f6");     //change the background colour				frmErrors = true;			}			else {   //field not empty so check email address				if(!isEmailAddr(email)) {					$("#lblEmail").css("color","#f00");    //change the text colour					//$("#Email").css("background","#f3f5f6");     //change the background colour					frmErrors = true;				}			}			if(isEmpty(msg)) {				$("#lblNote").css("color","#f00");    //change the text colour				//$("#Note").css("background","#f3f5f6");     //change the background colour				frmErrors = true;			}			if(isEmpty(captcha)) {				$("#lblCaptcha").css("color","#f00");    //change the text colour				//$("#Note").css("background","#f3f5f6");     //change the background colour				frmErrors = true;			}			/* inform user of form errors if any */			if(frmErrors) {				$("#errMsg").text("There are errors on the form! Please correct them.");				$("#errMsg").slideDown("slow");				$("#errMsg").vkfade();			}			else {  /* no errors so  block the form, put up message,and post data using .ajax */				$("#myqn").block();				$("#errMsg").css("color","#666666");				$("#errMsg").text("Sending your QuickNote... Please wait...");				$("#errMsg").slideDown("slow");				$("#errMsg").vkfade();				$.ajax({					url: "quicknote_a.php",					data: "FName=" + fname + "&LName=" + lname + "&Email=" + email + "&Note=" + msg + "&Captcha=" + captcha,					success: function(responseText) {						if(responseText == "Incorrect Captcha. Please correct and retry.") {							$("#errMsg").css("color","#f00");						}						else {						/* clear the text boxes */						$("#FName").val("");						$("#LName").val("");						$("#Email").val("");						$("#Note").val("");						}						/* unblock then put up message */						$("#myqn").unblock();						$("#Captcha").val("");  //reset captcha						reloadCaptcha();        //reset captcha						$("#errMsg").html(responseText);											},					error: function() {						$("#myqn").unblock();						$("#errMsg").css("color","#f00");						$("#errMsg").text("Error sending your QuickNote. Please retry.");					}				});			}						return false; // cancel the default form click action		});		/* setup the form reset action */		$("#btnReset").click(function() {			$("#errMsg").slideUp("slow");  //hide the error message			/* reset colour and background for labels */			$("#quicknote label").each(function() {				$(this).css("color","#666666");			});			reloadCaptcha();  //reset captcha 		});	 });}