var xmlHttp = null;
var EMPTY = "";
function getXmlHttpObject() {
   try {                                          // Firefox, Opera 8.0+, Safari
      xmlHttp = new XMLHttpRequest();
   } catch (e) {                                            // Internet Explorer
      try {
         xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
         xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
   }
   return xmlHttp;
}

function AJAX(aUrl) {

   xmlHttp = getXmlHttpObject();
   if (xmlHttp == null) { alert (errMsg01);  return;  }
   var t = EMPTY;

   xmlHttp.onreadystatechange = function showRPT() {
     if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
        t = xmlHttp.responseText;
   }
   xmlHttp.open("GET", aUrl, false);
   xmlHttp.send(null);

   return t;
}


function checkCode(ext, place) {
   var a, b, c;
   b = document.getElementById("inp");
   c = document.getElementById(place);
   a = AJAX("http://www.cpco.on.ca/Report/VerificationCode.aspx?q=" + b.value + "&ext=" + ext);
   if (a == "NOK") c.innerHTML += "<span style='color:red;'><b>Error </b></span>";
   else {
      document.getElementById("mail" + ext).innerHTML = a;
      c.innerHTML = "";
   }
}

function showVCode(ext, place) {

   var b = document.getElementById(place);

   if (b.innerHTML == "") {

      b.innerHTML = 
      "<p><b>Please enter the verification code. (Not Case Sensitive)</b><br>" +
      "<img src='http://www.cpco.on.ca/Report/VerificationCode.aspx?q=CR&r=" + Math.random() + "'>&nbsp;&nbsp;&nbsp;" +
      "<input id='inp' type=text size=8 style='font-size:120%' onKeyDown='if(event.keyCode==13) checkCode(\"" + ext + "\",\"" + place + "\")'>&nbsp;&nbsp;&nbsp;" +
      "<span id='subId' onclick='checkCode(\"" + ext + "\",\"" + place + "\")' style='color:blue; text-align:center;width:50px;' onMouseOver=\"style.cursor='hand'; style.color='red'\" onMouseOut=\"style.cursor='default'; style.color='blue'\"> <u>Submit</u> </span>";
      document.getElementById("inp").focus();

   } else b.innerHTML = "";

}

function mv(obj)  { obj.style.cursor='hand';}
function mt(obj)  { obj.style.cursor='default';}

