
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 submitTheInfo() {
   // 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

   //Uncomment the next 2 line to enable the lawdepot US contracts page. Adds State initials to end of url (i.e ...?loc=USAK)
   if(getFormObject("promnote", 'governingLaw').value != 'sel')
   	getForm('hiddenform').action+=getFormObject("promnote", 'governingLaw').value;
   getForm("hiddenform").submit();
}

function hideAll(hidden_div) {
  setVisDisp("hidden_div",false);
}
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";
      //alert("Oops!  That does not appear to be a valid number.  Please try again."); 
      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);
      }
   }
}

// Ensure input is numeric and not less than 0
// Returns 0 if not
function ensureNonNegative( value ) {

	if( isNaN( value ) )
		return 0;
		
	if( value != Math.abs( value ) )
		return 0;
	
	return value;

}

// Ensure input is numeric and greater than 0
// Return the empty string if not
// Otherwise format the value into a proper currency string
function ensurePositiveCurrency( value ) {

	value = ensureNonNegative( value );
	
	// Deal with small values and 0
	if( value < 0.005 )
		return "";
		
	return formatCurrency( value );

}

function ensurePositiveInteger( value ) {

	value = Math.round( ensureNonNegative( value ) );
	
	if( value == 0 )
		return "";
	
	return value;

}

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.");
   }
}

// This function returns true if the event is a keypress of 0-9
function onlyNumeric(event) {
   var strUserAgent = navigator.userAgent.toLowerCase(); 
   var isIE = strUserAgent.indexOf("msie") > -1;
   if(isIE)
      iKeyCode = event.keyCode;
   else
      iKeyCode = event.which;
   if( (iKeyCode >= 32 && iKeyCode <= 47) || iKeyCode >= 58 )
      return false;
   return true;

}

// This function returns true if the event is a keypress of 0-9 or . (decimal) or , (comma)
function onlyNumericCurrency(event) {
 
   var strUserAgent = navigator.userAgent.toLowerCase(); 
   var isIE = strUserAgent.indexOf("msie") > -1;
   if(isIE)
      iKeyCode = event.keyCode;
   else
      iKeyCode = event.which;
   if(
         (iKeyCode >= 32 && iKeyCode <= 43) ||
         (iKeyCode == 47) || (iKeyCode == 45) ||
         iKeyCode >= 58
     )
     return false;
   return true;

}

// This function returns true if the event is a keypress of 0-9 or . (decimal)
function onlyNumericDecimal(event) {
 
   var strUserAgent = navigator.userAgent.toLowerCase(); 
   var isIE = strUserAgent.indexOf("msie") > -1;
   if(isIE)
      iKeyCode = event.keyCode;
   else
      iKeyCode = event.which;
   if(
         (iKeyCode >= 32 && iKeyCode <= 45) ||
         (iKeyCode == 47) ||
         (iKeyCode >= 58)
     )
     return false;
   return true;

}

