
function AjaxCall(sURL, sParameters, LoadingElement, ResultElement, IsPost, CallbackFunction) {

  //alert(sURL) // the sURL to send data to/ fetch data from
  //alert(sParameters) // name value pairs for the ajax call, ie: name=value&name2=value2 
  //alert(LoadingElement); // element containing image or message to indicate ajax activity
  //alert(ResultElement) // where the result are dumped when ajax returns and where any error messages are posted
  //alert(IsPost) // 1=Post (querystring), 0=Get (form)
  //CallbackFunction // js function to run when ajax call is complete ie: function() { alert('all done.'); }

  if (!IsPost) {
    IsPost = 0; //default value
  }

  var xhr2;
  try { xhr2 = new XMLHttpRequest(); }
  catch (e) {
    xhr2 = new ActiveXObject("Microsoft.XMLHTTP");
  }

  xhr2.onreadystatechange = function() {
    if (xhr2.readyState == 4) {
      //Ajax call done

      // hide loading tag 
      if (LoadingElement) {
        document.getElementById(LoadingElement).style.display = 'none';
      }

      if (xhr2.status == 200) {
        // no errors, show results

        if (ResultElement) {
          document.getElementById(ResultElement).innerHTML = xhr2.responseText;
        }

        if (CallbackFunction) {
          CallbackFunction(xhr2.responseText);
        }

      }
      else {
        // busted, show errors
        if (ResultElement) {
          document.getElementById(ResultElement).innerHTML = xhr2.status;
        }

        if (CallbackFunction) {
          CallbackFunction(xhr2.status);
        }

      }

    }
  };

  // show loading tag 
  if (LoadingElement) {
    document.getElementById(LoadingElement).style.display = 'block';
  }

  //Make Ajax Call
  if (IsPost == 1) {
    sParameters = encodeURI('dummy=' + parseInt(Math.random() * 99999999) + '&' + sParameters);

    xhr2.open("POST", sURL, true);
    xhr2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xhr2.setRequestHeader("Content-length", sParameters.length);
    xhr2.setRequestHeader("Connection", "close");
    xhr2.send(sParameters);
  }
  else {
    xhr2.open("GET", sURL + '?dummy=' + parseInt(Math.random() * 99999999) + '&' + sParameters, true);
    xhr2.send(null);
  }

}



function IsEmailValid(checkThisEmail) {
  var myEMailIsValid = true;
  var myAtSymbolAt = checkThisEmail.indexOf('@');
  var myLastDotAt = checkThisEmail.lastIndexOf('.');
  var mySpaceAt = checkThisEmail.indexOf(' ');
  var myLength = checkThisEmail.length;


  // at least one @ must be present and not before position 2
  // @yellow.com : NOT valid
  // x@yellow.com : VALID

  if (myAtSymbolAt < 1)
  { myEMailIsValid = false }


  // at least one . (dot) afer the @ is required
  // x@yellow : NOT valid
  // x.y@yellow : NOT valid
  // x@yellow.org : VALID

  if (myLastDotAt < myAtSymbolAt)
  { myEMailIsValid = false }

  // at least two characters [com, uk, fr, ...] must occur after the last . (dot)
  // x.y@yellow. : NOT valid
  // x.y@yellow.a : NOT valid
  // x.y@yellow.ca : VALID

  if (myLength - myLastDotAt <= 2)
  { myEMailIsValid = false }


  // no empty space " " is permitted (one may trim the email)
  // x.y@yell ow.com : NOT valid

  if (mySpaceAt != -1)
  { myEMailIsValid = false }

  //DEBUG
  //if (myEMailIsValid == true)
  // {alert("email is VALID")}
  // else
  // {alert("email is NOT valid!")}

  return myEMailIsValid
}			