//myField - object reference, myValue - string to add
function insertatcursor(myField, myValue) {

	//IE support (if document.selection exists, using ie, else netscape / moz (?) )
	if (document.selection) {
		myField.focus();
		
		//create a text range with zero length at cursor location, replace with myValue
		sel = document.selection.createRange();
		sel.text = myValue;
	}

	//Mozilla/Firefox/Netscape 7+ support
	else if (myField.selectionStart || myField.selectionStart == '0') {

		// get the start and end points of selection. then create substrings up to the
		//start point and from the end point of the selection to the end of the field value.
		//then we concatenate the first substring, myValue, and the second substring to get the new value.

		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring(0, startPos)+ myValue+ myField.value.substring(endPos, myField.value.length);
	} else {
		myField.value += myValue;	// if selection start is at the end position(?)
	}
}

// get local date from client's machine & convert to japanese date
function getJDate() {
	var today = new Date()
	var month = today.getMonth() + 1
	var day = today.getDate()
	var year = today.getFullYear()

//convert year
	year=year-1988
	var datestring = "平成" + year + "年" + month + "月" + day + "日"
	return (datestring)
}

//takes two parameters - the form element and a string referring to a tag id where an error message is displayed
//function returns true (1) if the element's value is null (an empty string)
function checkForNull (element,element_id) {
	var result=0
	if (element.value=='') {
		document.getElementById(element_id).style.visibility="visible"
		result=1
	} else {
		document.getElementById(element_id).style.visibility="hidden"
	}
	return (result)
}

function IsNumeric(element,element_id)
   //check for valid numeric strings, this funciton allows null values
   {
   var strValidChars = "0123456789";
   var strChar;
   var strString = element.value;
   var blnResult = true;

   if (strString.length == 0) return true; //change this to false to disallow nulls

   //test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
	if (blnResult) {
		document.getElementById(element_id).style.visibility="hidden"
	} else {
		document.getElementById(element_id).style.visibility="visible"
	}
   return blnResult;
   }
