
document.onclick = hideQueryHintDiv;

var cListSeparator = '\n';

//
function resetPasswordOrSecretCode(resetWhat) {

   var sEmladrs = document.reset_form.emladrs.value.replace(/^\s+|\s+$/g,"");

   if (sEmladrs == "") {

      alert("Please enter an Email address.");
      document.reset_form.emladrs.focus();
      return 0;

   } else if (sEmladrs.search(/[^a-zA-Z0-9'._\-\+:#@,\*()%]/g) != -1) {
      
      alert("Valid characters for Email address are a to z, A to Z, 0 to 9 and any of the following '._-+:#@,*()%.");
      document.reset_form.emladrs.focus();
      return 0;

   }

   //
   document.getElementById("formAction").value = resetWhat;

   //
   document.reset_form.submit();

}

//
function submitLoginForm() {

   var sUsrId = document.login_form.userid.value.replace(/^\s+|\s+$/g,"");
   var sUserPwd = document.login_form.userpwd.value.replace(/^\s+|\s+$/g,"");

   //
   if (sUsrId == "") {

      alert("Please fill in the User Id.");
      document.login_form.userid.focus();
      return 0;

   } else if (sUserPwd == "") {

      alert("Please fill in the Password.");
      document.login_form.userpwd.focus();
      return 0;

   } else {

      if (sUsrId.search(/[^a-z0-9]/g) != -1) {

         alert("Valid characters for User Id are a to z and 0 to 9.");
         document.login_form.userid.focus();
         return 0;

      } else if (sUserPwd.search(/[^a-zA-Z0-9._\-\+:#@,\*()%]/g) != -1) {

         alert("Valid characters for Password are a to z, A to Z, 0 to 9 and any of the following ._-+:#@,*()%.");
         document.login_form.userpwd.focus();
         return 0;

      } else {

         document.login_form.submit();

      }

   }

}

//
function submitUsrRegForm() {

   var sUsrId = document.reg_form.userid.value.replace(/^\s+|\s+$/g,"");
   var sYouNum = document.reg_form.younum.value.replace(/^\s+|\s+$/g,"");
   var sYouNum1 = document.reg_form.younum1.value.replace(/^\s+|\s+$/g,"");
   var sUserPwd = document.reg_form.userpwd.value.replace(/^\s+|\s+$/g,"");
   var sUserPwd1 = document.reg_form.userpwd1.value.replace(/^\s+|\s+$/g,"");
   var sEmladrs = document.reg_form.email.value.replace(/^\s+|\s+$/g,"");
   var sCaptchachars = document.reg_form.captchachars.value.replace(/^\s+|\s+$/g,"");
   var sFname = document.reg_form.fname.value.replace(/^\s+|\s+$/g,"");
   var sMinitial = document.reg_form.minitial.value.replace(/^\s+|\s+$/g,"");
   var sLname = document.reg_form.lname.value.replace(/^\s+|\s+$/g,"");
   var sXpert = document.reg_form.xpert.value.replace(/^\s+|\s+$/g,"");
   var sPayeename = document.reg_form.payeename.value.replace(/^\s+|\s+$/g,"");
   var sStreetaddressline1 = document.reg_form.streetaddressline1.value.replace(/^\s+|\s+$/g,"");
   var sStreetaddressline2 = document.reg_form.streetaddressline2.value.replace(/^\s+|\s+$/g,"");
   var sCitytown = document.reg_form.citytown.value.replace(/^\s+|\s+$/g,"");
   var sState = document.reg_form.state.value.replace(/^\s+|\s+$/g,"");
   var sZip = document.reg_form.zip.value.replace(/^\s+|\s+$/g,"");
   var sCountry = document.reg_form.country.value.replace(/^\s+|\s+$/g,"");
   var sPhone1 = document.reg_form.phone1.value.replace(/^\s+|\s+$/g,"");
   var bAgreeTOSandPP = document.reg_form.agreetosandpp.checked;

   // user must agree to TOS and PP
   if (!bAgreeTOSandPP) {

      confirm("Please check the box against Terms of Use and Privacy Policy if you agree to them.")
      document.reg_form.agreetosandpp.focus();
      return 0;

   }

   //
   if (sUsrId == "") {

      alert("Please fill in the User Id.");
      document.reg_form.userid.focus();
      return 0;

   } else if (sYouNum == "") {

      alert("Please fill in the Secret code.");
      document.reg_form.younum.focus();
      return 0;

   } else if (sUserPwd == "") {

      alert("Please fill in the Password.");
      document.reg_form.userpwd.focus();
      return 0;

   } else if (sEmladrs == "") {

      alert("Please fill in the Email address.");
      document.reg_form.email.focus();
      return 0;

   } else if (sCaptchachars == "") {

      alert("Please fill in the letters you see in the image.");
      document.reg_form.captchachars.focus();
      return 0;

   } else {

      // data validation
      if (sUsrId.search(/[^a-z0-9]/g) != -1) {

         alert("Valid characters for User Id are a to z and 0 to 9.");
         document.reg_form.userid.focus();
         return 0;

      } else if (sYouNum.search(/[^a-zA-Z0-9._\-\+:#@,\*()%]/g) != -1) {

         alert("Valid characters for Secret code are a to z, A to Z, 0 to 9 and any of the following ._-+:#@,*()%.");
         document.reg_form.younum.focus();
         return 0;

      } else if (sUserPwd.search(/[^a-zA-Z0-9._\-\+:#@,\*()%]/g) != -1) {

         alert("Valid characters for Password are a to z, A to Z, 0 to 9 and any of the following ._-+:#@,*()%.");
         document.reg_form.userpwd.focus();
         return 0;

      } else if (sEmladrs.search(/[^a-zA-Z0-9'._\-\+:#@,\*()%]/g) != -1) {
      
         alert("Valid characters for Email address are a to z, A to Z, 0 to 9 and any of the following '._-+:#@,*()%.");
         document.reg_form.email.focus();
         return 0;

      } else if (sFname.search(/[^ a-zA-Z0-9'.]/g) != -1) {
      
         alert("Valid characters for First name are a space, a to z, A to Z, 0 to 9 and any of the following '..");
         document.reg_form.fname.focus();
         return 0;

      } else if (sMinitial.search(/[^a-zA-Z0-9]/g) != -1) {
      
         alert("Valid characters for Middle initial are a to z, A to Z and 0 to 9.");
         document.reg_form.minitial.focus();
         return 0;

      } else if (sLname.search(/[^ a-zA-Z0-9'.]/g) != -1) {
      
         alert("Valid characters for Last name are a space, a to z, A to Z, 0 to 9 and any of the following '..");
         document.reg_form.lname.focus();
         return 0;

      } else if (sXpert.search(/[^yYnN]/g) != -1) {
      
         alert("Valid characters for 'Will you be ranking content ?' are Y or N.");
         document.reg_form.xpert.focus();
         return 0;

      } else if (sPayeename.search(/[^ a-zA-Z0-9'.]/g) != -1) {
      
         alert("Valid characters for Payee name are a space, a to z, A to Z, 0 to 9 and any of the following '..");
         document.reg_form.payeename.focus();
         return 0;

      } else if (sStreetaddressline1.search(/[^ a-zA-Z0-9'._\-\+:#@,\*()%]/g) != -1) {
      
         alert("Valid characters for Street address are a space, a to z, A to Z, 0 to 9 and any of the following '._-+:#@,*()%.");
         document.reg_form.streetaddressline1.focus();
         return 0;

      } else if (sStreetaddressline2.search(/[^ a-zA-Z0-9'._\-\+:#@,\*()%]/g) != -1) {
      
         alert("Valid characters for Street address are a space, a to z, A to Z, 0 to 9 and any of the following '._-+:#@,*()%.");
         document.reg_form.streetaddressline2.focus();
         return 0;

      } else if (sCitytown.search(/[^ a-zA-Z0-9'.]/g) != -1) {
      
         alert("Valid characters for City/Town are a space, a to z, A to Z, 0 to 9 and any of the following '..");
         document.reg_form.citytown.focus();
         return 0;

      } else if (sState.search(/[^ a-zA-Z0-9'.]/g) != -1) {
      
         alert("Valid characters for State are a space, a to z, A to Z, 0 to 9 and any of the following '.");
         document.reg_form.state.focus();
         return 0;

      } else if (sZip.search(/[^0-9\-]/g) != -1) {
      
         alert("Valid characters for Zip are 0 to 9 and -.");
         document.reg_form.zip.focus();
         return 0;

      } else if (sCountry.search(/[^ a-zA-Z0-9'.]/g) != -1) {
      
         alert("Valid characters for Country are a space, a to z, A to Z, 0 to 9 and any of the following '..");
         document.reg_form.country.focus();
         return 0;

      } else if (sPhone1.search(/[^0-9.\-\+()]/g) != -1) {
      
         alert("Valid characters for Phone are 0 to 9 and any of the following .-+().");
         document.reg_form.phone1.focus();
         return 0;

      } else {

         // Anyone who rates the Search results should supply these details
         if (sXpert.toUpperCase() == "Y") {

            if (sPayeename == "") {
               alert("Please fill in the Payee name.");
               document.reg_form.payeename.focus();
               return 0;
            } else if (sStreetaddressline1 == "") {
               alert("Please fill in the Street address.");
               document.reg_form.streetaddressline1.focus();
               return 0;
            } else if (sCitytown == "") {
               alert("Please fill in the City/Town.");
               document.reg_form.citytown.focus();
               return 0;
            } else if (sState == "") {
               alert("Please fill in the State.");
               document.reg_form.state.focus();
               return 0;
            } else if (sZip == "") {
               alert("Please fill in the Zip.");
               document.reg_form.zip.focus();
               return 0;
            } else if (sCountry == "") {
               alert("Please fill in the Country.");
               document.reg_form.country.focus();
               return 0;
            } else if (sPhone1 == "") {
               alert("Please fill in the Phone.");
               document.reg_form.phone1.focus();
               return 0;
            }

         }

         // typo checks
         if (sYouNum != sYouNum1) {

            alert("Secret code doesn't match the re-typed secret code.");
            document.reg_form.younum.focus();
            return 0;

         } else if (sUserPwd != sUserPwd1) {
 
            alert("Password doesn't match the re-typed password.");
            document.reg_form.userpwd.focus();
            return 0;

         } else {

            document.reg_form.submit();

         }
      
      }

   }

}

//
function submitUsrUpdForm() {

   var sYouNum = document.updusr_form.younum.value.replace(/^\s+|\s+$/g,"");
   var sYouNum1 = document.updusr_form.younum1.value.replace(/^\s+|\s+$/g,"");
   var sYouNum2 = document.updusr_form.younum2.value.replace(/^\s+|\s+$/g,"");
   var sUserPwd = document.updusr_form.userpwd.value.replace(/^\s+|\s+$/g,"");
   var sUserPwd1 = document.updusr_form.userpwd1.value.replace(/^\s+|\s+$/g,"");
   var sEmladrs = document.updusr_form.email.value.replace(/^\s+|\s+$/g,"");
   var sFname = document.updusr_form.fname.value.replace(/^\s+|\s+$/g,"");
   var sMinitial = document.updusr_form.minitial.value.replace(/^\s+|\s+$/g,"");
   var sLname = document.updusr_form.lname.value.replace(/^\s+|\s+$/g,"");
   var sXpert = "N";
   if (document.updusr_form.xpert != undefined) {
      sXpert = document.updusr_form.xpert.value.replace(/^\s+|\s+$/g,"");
   }
   var sRankValue = "0";
   if (document.updusr_form.rankvalue != undefined) {
      sRankValue = document.updusr_form.rankvalue.value.replace(/^\s+|\s+$/g,"");
   }
   var sPayeename = document.updusr_form.payeename.value.replace(/^\s+|\s+$/g,"");
   var sStreetaddressline1 = document.updusr_form.streetaddressline1.value.replace(/^\s+|\s+$/g,"");
   var sStreetaddressline2 = document.updusr_form.streetaddressline2.value.replace(/^\s+|\s+$/g,"");
   var sCitytown = document.updusr_form.citytown.value.replace(/^\s+|\s+$/g,"");
   var sState = document.updusr_form.state.value.replace(/^\s+|\s+$/g,"");
   var sZip = document.updusr_form.zip.value.replace(/^\s+|\s+$/g,"");
   var sCountry = document.updusr_form.country.value.replace(/^\s+|\s+$/g,"");
   var sPhone1 = document.updusr_form.phone1.value.replace(/^\s+|\s+$/g,"");
   var bAgreeTOSandPP = document.updusr_form.agreetosandpp.checked;
   var bDelAccount = document.updusr_form.delaccount.checked;

   // user must agree to TOS and PP unless he/she is deleting the account
   if ((!bDelAccount) && (!bAgreeTOSandPP)) {

      confirm("Please check the box against Terms of Use and Privacy Policy if you agree to them.")
      document.updusr_form.agreetosandpp.focus();
      return 0;

   }

   //
   if (sYouNum == "") {
      alert("Please enter your Secret code.");
      document.updusr_form.younum.focus();
      return 0;
   }

   // don't validate data if request to delete account
   if (bDelAccount) {

      var bReply = confirm("Are you sure you want to delete your account ?")
      if (bReply) {
         document.updusr_form.submit();
         return 1;
      } else {
         return 0;
      }

   }

   //
   if (sEmladrs == "") {

      alert("Please fill in the Email address.");
      document.updusr_form.email.focus();
      return 0;

   } else {

      // data validation
      if (sYouNum1.search(/[^a-zA-Z0-9._\-\+:#@,\*()%]/g) != -1) {

         alert("Valid characters for Secret code are a to z, A to Z, 0 to 9 and any of the following ._-+:#@,*()%.");
         document.updusr_form.younum.focus();
         return 0;

      } else if (sUserPwd.search(/[^a-zA-Z0-9._\-\+:#@,\*()%]/g) != -1) {

         alert("Valid characters for Password are a to z, A to Z, 0 to 9 and any of the following ._-+:#@,*()%.");
         document.updusr_form.userpwd.focus();
         return 0;

      } else if (sEmladrs.search(/[^a-zA-Z0-9'._\-\+:#@,\*()%]/g) != -1) {
      
         alert("Valid characters for Email address are a to z, A to Z, 0 to 9 and any of the following '._-+:#@,*()%.");
         document.updusr_form.email.focus();
         return 0;

      } else if (sFname.search(/[^ a-zA-Z0-9'.]/g) != -1) {
      
         alert("Valid characters for First name are a space, a to z, A to Z, 0 to 9 and any of the following '..");
         document.updusr_form.fname.focus();
         return 0;

      } else if (sMinitial.search(/[^a-zA-Z0-9]/g) != -1) {
      
         alert("Valid characters for Middle initial are a to z, A to Z and 0 to 9.");
         document.updusr_form.minitial.focus();
         return 0;

      } else if (sLname.search(/[^ a-zA-Z0-9'.]/g) != -1) {
      
         alert("Valid characters for Last name are a space, a to z, A to Z, 0 to 9 and any of the following '..");
         document.updusr_form.lname.focus();
         return 0;

      } else if (sXpert.search(/[^yYnN]/g) != -1) {
      
         alert("Valid characters for 'Will you be ranking content ?' are Y or N.");
         document.updusr_form.xpert.focus();
         return 0;

      } else if (sPayeename.search(/[^ a-zA-Z0-9'.]/g) != -1) {
      
         alert("Valid characters for Payee name are a space, a to z, A to Z, 0 to 9 and any of the following '..");
         document.updusr_form.payeename.focus();
         return 0;

      } else if (sStreetaddressline1.search(/[^ a-zA-Z0-9'._\-\+:#@,\*()%]/g) != -1) {
      
         alert("Valid characters for Street address are a space, a to z, A to Z, 0 to 9 and any of the following '._-+:#@,*()%.");
         document.updusr_form.streetaddressline1.focus();
         return 0;

      } else if (sStreetaddressline2.search(/[^ a-zA-Z0-9'._\-\+:#@,\*()%]/g) != -1) {
      
         alert("Valid characters for Street address are a space, a to z, A to Z, 0 to 9 and any of the following '._-+:#@,*()%.");
         document.updusr_form.streetaddressline2.focus();
         return 0;

      } else if (sCitytown.search(/[^ a-zA-Z0-9'.]/g) != -1) {
      
         alert("Valid characters for City/Town are a space, a to z, A to Z, 0 to 9 and any of the following '..");
         document.updusr_form.citytown.focus();
         return 0;

      } else if (sState.search(/[^ a-zA-Z0-9'.]/g) != -1) {
      
         alert("Valid characters for State are a space, a to z, A to Z, 0 to 9 and any of the following '.");
         document.updusr_form.state.focus();
         return 0;

      } else if (sZip.search(/[^0-9\-]/g) != -1) {
      
         alert("Valid characters for Zip are 0 to 9 and -.");
         document.updusr_form.zip.focus();
         return 0;

      } else if (sCountry.search(/[^ a-zA-Z0-9'.]/g) != -1) {
      
         alert("Valid characters for Country are a space, a to z, A to Z, 0 to 9 and any of the following '..");
         document.updusr_form.country.focus();
         return 0;

      } else if (sPhone1.search(/[^0-9.\-\+()]/g) != -1) {
      
         alert("Valid characters for Phone are 0 to 9 and any of the following .-+().");
         document.updusr_form.phone1.focus();
         return 0;

      } else {

         // Anyone who rates the Search results should supply these details
         if ((sXpert.toUpperCase() == "Y") || (sRankValue != "0")) {

            if (sPayeename == "") {
               alert("Please fill in the Payee name.");
               document.reg_form.payeename.focus();
               return 0;
            } else if (sStreetaddressline1 == "") {
               alert("Please fill in the Street address.");
               document.reg_form.streetaddressline1.focus();
               return 0;
            } else if (sCitytown == "") {
               alert("Please fill in the City/Town.");
               document.reg_form.citytown.focus();
               return 0;
            } else if (sState == "") {
               alert("Please fill in the State.");
               document.reg_form.state.focus();
               return 0;
            } else if (sZip == "") {
               alert("Please fill in the Zip.");
               document.reg_form.zip.focus();
               return 0;
            } else if (sCountry == "") {
               alert("Please fill in the Country.");
               document.reg_form.country.focus();
               return 0;
            } else if (sPhone1 == "") {
               alert("Please fill in the Phone.");
               document.reg_form.phone1.focus();
               return 0;
            }

         }

         // typo checks
         if (sYouNum1 != sYouNum2) {

            alert("Secret code doesn't match the re-typed secret code.");
            document.updusr_form.younum1.focus();
            return 0;

         } else if (sUserPwd != sUserPwd1) {
 
            alert("Password doesn't match the re-typed password.");
            document.updusr_form.userpwd.focus();
            return 0;

         } else {

            document.updusr_form.submit();

         }
      
      }

   }

}

//
function keyupQueries(event, theForm) {

   var keyCode = 0;

   //
   if (window.event) {
      // IE

      keyCode = window.event.keyCode;

   } else {
      // Mozilla, Safari, ...

      if (event) {
         keyCode = event.which;
      }

   }

   //
   if (keyCode == 27) { // "Esc" key

      //
      hideQueryHintDiv();

   } else if ((keyCode != 37) && (keyCode != 38) && (keyCode != 39) && (keyCode != 40) && (keyCode != 13)) { // not an "Up/Down/Enter" Arrow key

      //
      var sQuery = document.getElementById("q").value;
      // this check prevents subsequent calls to "getQueries()" if the last call didn't yield any Query hints
      if ((sQuery.length == 1) || (keyCode == 8) || 
         ((sQuery.length > 0) && (document.getElementById("queryhint").innerHTML.length > 0))) {
      
         // get Query hints
         getQueries(sQuery);

      } else {
         //
         hideQueryHintDiv();
      }

   }

   //
   return true;

}

//
function keydownQueries(event, theForm) {

   //
   // navigate Up/Down in Query hints
   
   var keyCode = 0;
   
   //
   if (window.event) {
      // IE

      keyCode = window.event.keyCode;

   } else {
      // Mozilla, Safari, ...

      if (event) {
         keyCode = event.which;
      }

   }

   //
   if (keyCode == 13) { // "Enter" key

      //
      submitPage();

   } else if (keyCode == 9) { // "Tab" key

      //
      hideQueryHintDiv();

   } else if (keyCode == 38) {  // "Up" key

      // which Query hint are we at ?
      var qnum = parseInt(document.getElementById("querynum").value);

      // un-highlight the current Query hint
      var divHint = document.getElementById("queryhint" + (qnum-1));
      if (divHint != null) {
         divHint.style.background="#FFFFFF";
      }

      // get the Query hint immediately above the current Query hint
      divHint = document.getElementById("queryhint" + (qnum-2));
      if (divHint != null) {

         // highlight it
         divHint.style.background="#F0F8FF";
         // set the current Query hint number
         document.getElementById("querynum").value=qnum-1;
         // set the Query to this highlighted Query hint
         document.getElementById("q").value = divHint.innerHTML;

      } else {
         // user pressed an "Up" key while at the first Query hint

         // get maximum Query hints
         qnum = parseInt(document.getElementById("maxquerynum").value);
         // get the last Query hint
         divHint = document.getElementById("queryhint" + (qnum-1));
         if (divHint != null) {
            // highlight it
            divHint.style.background="#F0F8FF";
            // set the current Query hint number
            document.getElementById("querynum").value=qnum;
            // set the Query to this highlighted Query hint
            document.getElementById("q").value = divHint.innerHTML;
         }

      }

   } else if (keyCode == 40) { // "Down" key

      // which Query hint are we at ?
      var qnum = parseInt(document.getElementById("querynum").value);

      // un-highlight the current Query hint
      var divHint = document.getElementById("queryhint" + (qnum-1));
      if (divHint != null) {
         divHint.style.background="#FFFFFF";
      }

      // get the Query hint immediately below the current Query hint
      divHint = document.getElementById("queryhint" + qnum);
      if (divHint != null) {

         // highlight it
         divHint.style.background="#F0F8FF";
         // set the current Query hint number
         document.getElementById("querynum").value = qnum + 1;
         // set the Query to this highlighted Query hint
         document.getElementById("q").value = divHint.innerHTML;

      } else {
         // user pressed an "Down" key while at the last Query hint

         // get the first Query hint
         divHint = document.getElementById("queryhint0");
         if (divHint != null) {
            // highlight it
            divHint.style.background="#F0F8FF";
            // set the current Query hint number
            document.getElementById("querynum").value=1;
            // set the Query to this highlighted Query hint
            document.getElementById("q").value = divHint.innerHTML;
         }
      }

   }

}

//
function submitPage() {
   
   //
   hideQueryHintDiv();
   document.srch_form.submit();

}

//
function hideQueryHintDiv() {

   //
   divHint = document.getElementById("queryhint");
   if (divHint != null) {
      divHint.innerHTML = "";
      divHint.style.visibility='hidden';
      document.getElementById("querynum").value=0;
      document.getElementById("maxquerynum").value=0;
   }

}

//
function getQueries(str) {

   //
   xmlHttp=GetXmlHttpObject()
   if (xmlHttp==null) {
      alert ("Browser does not support HTTP Request");
      return;
   }
   
   //
   var url = "GetQueryList";
   url = url + "?q=" + str.toLowerCase();
   url = url + "&sid=" + Math.random();

   //
   xmlHttp.onreadystatechange=setQueries;
   xmlHttp.open("GET",url,true);
   xmlHttp.send(null);

}

//
function setQueries() {

   //
   if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {

      //
      if (xmlHttp.status == 200) {

         // get response text
         var sQueriesList = xmlHttp.responseText;
         if (sQueriesList.substring(0, 5) == "<xml>") {
            sQueriesList = sQueriesList.substring(5, sQueriesList.length-6);
         }
         // split the response text
         var sMainTokens = sQueriesList.split(cListSeparator);
         sQueriesList = "";
         var maxHints = 0;
         // prepare Query hints
         for (i = 0; i < sMainTokens.length; i++) {
            if (sMainTokens[i] != '') {
               sQueriesList += decodeURIComponent(sMainTokens[i]);
               maxHints = maxHints + 1;
            }
         }
         //
         document.getElementById("queryhint").innerHTML = sQueriesList;
         //
         if (sQueriesList.length == 0) {
            // no Query hints found

            hideQueryHintDiv();

         } else {

            //
            document.getElementById("queryhint").style.visibility='visible';
            // set current and maximum Query number
            document.getElementById("querynum").value=0;
            document.getElementById("maxquerynum").value=maxHints;

         }

      } else {

         // clear up Query
         document.getElementById("q").value = "";

      }

   }

} 

//
function submitQuery(queryStr) {

   //
   document.getElementById("q").value = queryStr;
   submitPage();

}

//
function highlightHint(queryNumber) {

   // which Query hint are we at ?
   var qnum = parseInt(document.getElementById("querynum").value) - 1;

   // if the mouse is not over the the current Query hint, un-highlight it
   var divHint = document.getElementById("queryhint" + qnum);
   if ((divHint != null) && (queryNumber != qnum)) {
      divHint.style.background="#FFFFFF";
   }

   // highlight the Query hint the mouse is over
   divHint = document.getElementById("queryhint" + queryNumber);
   if (divHint != null) {
      divHint.style.background="#F0F8FF";
   }

   // set the Query num so that we can un-highlight when we mouse away
   document.getElementById("querynum").value = queryNumber + 1;

   return true;

}

//
function updateUserRank(formName) {

   // error checks  
   if (parseInt(document.getElementById(formName).ndxnumber.value, 10) < 0) {
      alert("Invalid index number");
      return;
   } else if (parseInt(document.getElementById(formName).filenumber.value, 10) <= 0) {
      alert("Invalid File number");
      return;
   } else if ((parseInt(document.getElementById(formName).userrank.value, 10) < 0) ||
      (parseInt(document.getElementById(formName).userrank.value, 10) > 65535)) {
      alert("Rank number should be between 0 and 65535");
      return;
   }

   //
   xmlHttp=GetXmlHttpObject()
   if (xmlHttp==null) {
      alert ("Browser does not support HTTP Request")
      return
   }

   //   
   var url = "/LogUserRank"
   url = url + "?ndxnumber=" + encodeURIComponent(document.getElementById(formName).ndxnumber.value)
   url = url + "&filenumber=" + encodeURIComponent(document.getElementById(formName).filenumber.value)
   url = url + "&filename=" + encodeURIComponent(document.getElementById(formName).filename.value)
   url = url + "&rank="  +encodeURIComponent(document.getElementById(formName).userrank.value)
   url = url + "&nodeid=" + encodeURIComponent(document.getElementById(formName).nodeid.value)
   url = url + "&docsn=" + encodeURIComponent(document.getElementById(formName).docsn.value)
   url = url + "&sid=" + Math.random()
   xmlHttp.onreadystatechange=resUpdUserRank
   xmlHttp.open("GET",url,true)
   xmlHttp.send(null)

}

//
function resUpdUserRank() { 

   //
   if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {

      //
      if (xmlHttp.status == 200) {
         var msg = xmlHttp.responseText;
         if (msg.substring(0, 5) == "<xml>") {
            msg = msg.substring(5, msg.indexOf("<", 5));
         }
         alert(msg);
      } else {
         alert("Error updating user ranking.");
      }

   } 

} 

//
function updPublicPageRank(formName, theVote) {

   // error checks
   if (parseInt(document.getElementById(formName).ndxnumber.value, 10) < 0) {
      alert("Invalid index number");
      return;
   } else if (parseInt(document.getElementById(formName).filenumber.value, 10) <= 0) {
      alert("Invalid File number");
      return;
   }

   //
   xmlHttp=GetXmlHttpObject()
   if (xmlHttp==null) {
      alert ("Browser does not support HTTP Request")
      return
   }

   //
   var url = "/LogUserVote"
   url = url + "?ndxnumber=" + encodeURIComponent(document.getElementById(formName).ndxnumber.value)
   url = url + "&filenumber=" + encodeURIComponent(document.getElementById(formName).filenumber.value)
   url = url + "&filename=" + encodeURIComponent(document.getElementById(formName).filename.value)
   url = url + "&vote=" + encodeURIComponent(theVote)
   url = url + "&nodeid=" + encodeURIComponent(document.getElementById(formName).nodeid.value)
   url = url + "&id=" + encodeURIComponent(document.getElementById(formName).id.value)
   url = url + "&sid=" + Math.random()
   xmlHttp.onreadystatechange=resUpdPublicPageRank
   xmlHttp.open("GET",url,true)
   xmlHttp.send(null)

}

//
function resUpdPublicPageRank() { 

   //
   if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
      
      //
      if (xmlHttp.status == 200) {
         var msg = xmlHttp.responseText;
         if (msg.substring(0, 5) == "<xml>") {
            msg = msg.substring(5, msg.indexOf("<", 5));
         }
         alert(msg);
      } else {
         alert("Error updating popularity ranking.");
      }

   }

}

//
// AJAX functions
//

//
function GetXmlHttpObject(handler) { 

   var objXMLHttp=null;

   //
   if (window.XMLHttpRequest) { // Mozilla, Safari, ...

      objXMLHttp = new XMLHttpRequest();
      if (objXMLHttp.overrideMimeType) {
          objXMLHttp.overrideMimeType('text/xml');
      }

   } else if (window.ActiveXObject) { // IE

     try {
         objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {}

   }

   //
   if (!objXMLHttp) {
      alert('Giving up :( Cannot create an XMLHTTP instance');
      return false;
   }

   //
   return objXMLHttp
   
}


