var agent=navigator.userAgent.toLowerCase();
function moveObject(objectId, newXCoordinate, newYCoordinate) {
   // get a reference to the cross-browser style object and make sure the object exists
   var styleObject = getStyleObject(objectId);
   if(styleObject) {
      styleObject.left = newXCoordinate;
      styleObject.top = newYCoordinate;
      return true;
   } else {
      // we couldn't find the object, so we can't very well move it
      return false;
   }
} // moveObject
function switchIfDone(the_form, this_div, next_div) {

   var complete = true;
   for (var loop=0; loop < the_form.elements.length; loop++) {
      if (the_form.elements[loop].value == "") {
         complete = false;
      }
   }
   if ((complete == true) && (next_div == "finished")) {
      submitTheInfo();
   } else if (complete == true) {
      switchDiv(this_div, next_div);
   } else {
      alert('please complete the form before moving on');
   }
}
function switchDiv(this_div, next_div) {
   if (getStyleObject(this_div) && getStyleObject(next_div)) {
      setVisDisp(this_div, false);
      setVisDisp(next_div, true);
   }
}
function escapeChars(theString) {
   var regexp = /&/g ;
   var regexp2 = /#/g ;
   var regexp3 = /\r\n/g ;
   var regexp4 = /\n/g ;
   var regexp5 = /\"/g ;
   theString = theString.replace(regexp, "%^");
   theString = theString.replace(regexp2, "%*");
   theString = theString.replace(regexp3, "<br>");
   theString = theString.replace(regexp4, "<br>");
   theString = theString.replace(regexp5, "%)");
   return theString;
}
function submitTheInfo() {
   if(!checkInput()) return;

   // httprequest saving is not necessary, so set this to false.
   //alert("setting saveReq to false");
   saveReq=false;

   // createVarString is in answers.js
   getFormObject("hiddenform","variablestring").value = createVarString();

   // the next two lines are written for debugging -
   // to put the script into action
   // comment out the setVisDisp() line
   // and uncomment the document.hidden.form.submit() line
   //

   getForm("hiddenform").submit();
   //setVisDisp("hiddenstuff",true);
}

function checkboxcheck(entry,HiddenDiv) {
   if(entry) {
      if (entry.checked) {
         setVisDisp(HiddenDiv,true);
      }
      else {
         setVisDisp(HiddenDiv,false);
      }
   }
}

function isNumber(inputVal) {
   oneDecimal = false;
   inputStr = inputVal.toString();
   for (var i=0; i<inputStr.length; i++) {
      var oneChar =inputStr.charAt(i);
      if (oneChar == "." && !oneDecimal) {
         oneDecimal = true;
         continue;
      }
      if (oneChar < "0" || oneChar > "9")  {
         if (oneChar != ",") {
            alert("Please make sure entries are numbers.");
            return false;
         }
      }
   }
   return true;
}
function checkIt(inputvar) {
   inputStr = inputvar.value;
   if (isNumber(inputStr)) {
   } else {
      inputvar.focus();
      inputvar.select();
   }
}
function funcChangeDiv(inputvar,selectedvalue,HiddenDiv) {
   if(inputvar) {
      if (inputvar.selectedIndex == selectedvalue) {
         setVisDisp(HiddenDiv,true);
      } else {
         setVisDisp(HiddenDiv,false);
      }
   }
}
function funcradChangeDiv(selectedvalue,HiddenDiv) {
   if (selectedvalue == "true") {
      setVisDisp(HiddenDiv,true);
   } else {
      setVisDisp(HiddenDiv,false);
   }
}
function funcNotChangeDiv(inputvar,selectedvalue,HiddenDiv) {
   if(inputvar) {
      if (inputvar.selectedIndex != selectedvalue) {
         setVisDisp(HiddenDiv,true);
      } else {
         setVisDisp(HiddenDiv,false);
      }
   }
}
function redisplay(db,openingornot,divname) {
   for (var i=1; i<db.length; i++) {
      setVisDisp(db[i].divname, false);
   }
   if (openingornot == 'true') {
      setVisDisp(db[1].divname, true);
   }
   setVisDisp(divname, true);
}
function formatCurrency(num,dollarSign) {
   num = num.toString().replace(/\$|\,/g,'');
   if(isNaN(num)){
      num="0";
      return (num);
   } else {
      sign = (num == (num = Math.abs(num)));
      num = Math.floor(num*100+0.50000000001);
      cents = num%100;
      num = Math.floor(num/100).toString();
      if(cents<10) cents = "0" + cents;
      for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) {
         num = num.substring(0,num.length-(4*i+3))+','+
               num.substring(num.length-(4*i+3));
      }
      if (dollarSign == true)	{
         return (((sign)?'':'-') + '$' + num + '.' + cents);
      } else {
         return (((sign)?'':'-') + num + '.' + cents);
      }
   }
}
function setStatus(msg) {
   status = msg;
}
function bookmark(){
   window.external.AddFavorite(window.location.href,window.document.title);
}
function printDocument() {
   if(window.print) {
      window.print();
   } else if(agent.indexOf("mac") != -1) {
      alert("Press Cmd-p to print your document.");
   } else {
      alert("Press Ctrl-p to print your document.");
   }
}

