//
function formatBulletinCaption() {
  var bullCaption = document.getElementsByName("bullCaption");
  if (bullCaption != null) {
    for (var i=0; i<bullCaption.length; i++) {
      tmp = bullCaption[i].innerText;
      if (tmp.length > 16) {
        tmp = tmp.substring(0, 15);
        bullCaption[i].innerText = tmp + '...';
      }
    }
  }
}

function clearElementValue(nameElement, idElement) {
  if (nameElement.value == "") {
    idElement.value = "";
  }
}

/******************************************

******************************************/
function selectDept() {
  var sUrl = "/gd/common/selectDept.jsp";
  windowOpenWithScrollbars(300, 350, sUrl);
}

/******************************************

******************************************/
function typeNumeric()
{
	if ((window.event.keyCode<48) || (window.event.keyCode>57))
		window.event.returnValue = false;
}

/******************************************

******************************************/
function empty2zero(o){
   return o.value==""?0:parseFloat(o.value);
}

/******************************************
******************************************/
function typeFloat(obj)
{
	if ((obj.value.indexOf(".") > 0) && (window.event.keyCode == 46)||(obj.value != "" && (window.event.keyCode == 45)))
	{
		window.event.returnValue = false;
		return;
	}
	if (((window.event.keyCode<48) || (window.event.keyCode>57)) && (window.event.keyCode != 46) && (window.event.keyCode != 45)) //keyCode = 46 ±íê?D?êy??
		window.event.returnValue = false;
}

/******************************************
******************************************/
function tabNext(obj){
if(window.event.keyCode=="13"){
  for(i=0;i<theForm.length-1;i++){
	if(theForm.item(i)==obj) {
	theForm.item(i+1).focus();
	return;
      }
  }
}
}

/******************************************

******************************************/
 function checkDate(oStartDate,oEndDate){
      if(oStartDate.value==""&&oEndDate.value!=""){
		alert("????????????????");
		oStartDate.focus();
		return false;
      }
       if(oStartDate.value!=""&&oEndDate.value==""){
		alert("????????????????");
		oEndDate.focus();
		return false;
      }
      if(oStartDate.value>oEndDate.value){
		alert("???????????????");
		oEndDate.focus();
		return false;
      }
      return true;
    }

/******************************************

******************************************/
 function checkInt(iStart,iEnd){
      if(iStart.value==""&&iEnd.value!=""){
		alert("??????????????");
		iStart.focus();
		return false;
      }
       if(iStart.value!=""&&iEnd.value==""){
		alert("??????????????");
		iEnd.focus();
		return false;
      }
      if(iStart.value>iEnd.value){
		alert("????????????");
		iEnd.focus();
		return false;
      }
      return true;
    }

/******************************************

******************************************/
function roundNum(number,digit){
     if(digit<0) return number;
     var iNum;
     iNum = Math.round(number*Math.pow(10,digit))/Math.pow(10,digit);
     sNum = new String(iNum);
     //?????number????,????????0
     if(sNum.indexOf(".")<0&&digit>0){
         sNum = sNum + ".";
         for(var i=0;i<digit;i++){
           sNum = sNum +"0";
        }
     }
	 //?????number????????????,????0
	if(sNum.indexOf(".")>=0 && digit>(sNum.length-1-sNum.indexOf("."))){
		for(var i=0;i<digit-(sNum.length-1-sNum.indexOf("."));i++){
           sNum = sNum +"0";
        }
    }
     return sNum;
}

/******************************************

******************************************/
function jsLTrim(str){
		if (str==null){
			return null;
		}
		var rtnStr;
		rtnStr="";
		for (var i=0;i<str.length;i++){
			if (str.charAt(i)!=" "){
				rtnStr=str.substr(i);
				break;
			}
		}
		return rtnStr;
    }


    function jsRTrim(str){
		if (str==null){
			return null;
		}
		var rtnStr;
		rtnStr="";
		for (var i=str.length-1;i>=0;i--){
			if (str.charAt(i)!=" "){
				rtnStr=str.substring(0,i+1);
				break;
			}
		}
		return rtnStr;
    }


function jsTrim(str){
  return(jsLTrim(jsRTrim(str)));
}


function trim(s) {
  return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
}


function chknum(str)
{
 var i;
 var back
 i=0;
 back=0;
 for (i=0;i<str.length;i++)
  {
   if((str.charAt(i)<='9')&&(str.charAt(i)>='0'))
    {
     back=1
    }
    else
     {
      back=0;
      break;
     }
  }
 //alert ("back="+back);
 return back;
}


function copySelectOptions(sltFrom, sltTo) {
  if (sltFrom.options.length==0) return;
  var fromOpt;
  var toOpt;
  for (i=0; i<sltFrom.options.length; i++) {
    fromOpt = sltFrom.options[i];
    toOpt= new Option(fromOpt.text,fromOpt.value);
    sltTo.add(toOpt);
  }
}


function clearSelectOptions(slt){
	while(slt.options.length>0){
		slt.remove(0);
	}
}


function removeOpt(slt){
  if (slt.selectedIndex<0) return;
  slt.remove(slt.selectedIndex);
}


function secBoard(n) {
  for (i=0; i<secTable.cells.length; i++)
    secTable.cells[i].className="sec1";
    secTable.cells[n].className="sec2";
  for (i=0; i<mainTable.tBodies.length; i++)
    mainTable.tBodies[i].style.display="none";
    mainTable.tBodies[n].style.display="block";
}

function setToolBarDisplay() {
  if (document.forms['toolBarForm'].btnDisplay.value == "??") {
    document.forms['toolBarForm'].btnDisplay.value="??";
    toolBar.tBodies[0].style.display="none";
    toolBar.tBodies[1].style.display="block";
  } else {
    document.forms['toolBarForm'].btnDisplay.value="??";
    toolBar.tBodies[0].style.display="block";
    toolBar.tBodies[1].style.display="none";
  }
}


/******************************************
******************************************/
function copyToList(from, to) {
  fromList = eval('document.forms[0].' + from);
  toList = eval('document.forms[0].' + to);
  if (toList.options.length > 0 && toList.options[0].value == 'temp') {
    toList.options.length = 0;
  }
  var sel = false;
  for (i=0; i<fromList.options.length; i++) {
    var current = fromList.options[i];
    if (current.selected) {
      sel = true;
      if (current.value == 'temp') {
       // alert ('!');
        return;
      }
      txt = current.text;
      val = current.value;
      var isExist = false;
      for(var j=0;j<toList.options.length;j++){
        if(toList.options[j].value==current.value) {
          isExist = true;
        }
      }
      if(!isExist){
    	 toList.options[toList.length] = new Option(current.text,current.value);
      }
      fromList.options[i] = null;
      i--;
    }
  }
  //if (!sel) alert ();
}

/******************************************
******************************************/
function allSelect(selCourse, selDept, selUser, selDuty) {
  List = eval('document.forms[0].' + selCourse);
//  if (List.length && List.options[0].value == 'temp')
//    return;
  for (i=0; i<List.length; i++) {
    List.options[i].selected = true;
  }
  List = eval('document.forms[0].' + selDept);
  for (i=0; i<List.length; i++) {
    List.options[i].selected = true;
  }
  List = eval('document.forms[0].' + selUser);
  for (i=0; i<List.length; i++) {
    List.options[i].selected = true;
  }
  List = eval('document.forms[0].' + selDuty);
  for (i=0; i<List.length; i++) {
    List.options[i].selected = true;
  }
}

function allSelectBox(selectBox) {
  List = eval('document.forms[0].' + selectBox);
  for (i=0; i<List.length; i++) {
    List.options[i].selected = true;
  }
}

//???checkBox???
function selectAll(selectBox) {
  if (selectBox.length > 1)
    for (i=0; i<selectBox.length; i++)
      selectBox[i].checked = true;
  else
    selectBox.checked = true;
}

//???checkBox????
function selectReverse(selectBox) {
  if (selectBox.length > 1) {
    for (i=0; i<selectBox.length; i++) {
      if (selectBox[i].checked)
        selectBox[i].checked = false;
      else
        selectBox[i].checked = true;
    }
  } else {
    if (selectBox.checked)
      selectBox.checked = false;
    else
      selectBox.checked = true;
  }
}


/******************************************
******************************************/
function copyAll(from, to) {
  var fromList = eval('document.forms[0].' + from);
  var toList = eval('document.forms[0].' + to);
  if (toList.options.length > 0 && toList.options[0].value == 'temp') {
    toList.options.length = 0;
  }
  for (i=0; i<fromList.options.length; i++) {
     var current = fromList.options[i];
     var isExist = false;
     for(var j=0;j<toList.options.length;j++){
        if(toList.options[j].value==current.value) {
          isExist = true;
        }
     }
     if(!isExist){
    	toList.options[toList.length] = new Option(current.text,current.value);
     }
     fromList.options[i] = null;
     i--;
  }
}

/******************************************
******************************************/
function transferSequence(sequence){
	switch (sequence) {
			   case "1" :
				  sequence = "?";
				  break;
			   case "2" :
				  sequence = "?";
			      break;
			   case "3" :
				  sequence = "?";
			      break;
			   case "4" :
				  sequence = "?";
			      break;
			   case "5" :
				  sequence = "?";
			      break;
			   case "6" :
				  sequence = "?";
			      break;
			   case "7" :
				  sequence = "?";
			      break;
			   case "8" :
				  sequence = "?";
			      break;
			   case "9" :
				  sequence = "?";
			      break;
			   case "10" :
				  sequence = "?";
			      break;
			   default :
	}
    return sequence;
}


/******************************************
******************************************/
function disableBackRefreshKeyAndRightMouseMenu() {
   
	if ((event.altKey) ||
		((event.keyCode == 8) && (event.srcElement.type != "text" && event.srcElement.type != "textarea" && event.srcElement.type != "password")) ||
	    ((event.ctrlKey) && ((event.keyCode == 78) || (event.keyCode == 82))) ||
		((event.altKey) && (event.keyCode == 115)) ||
	    (event.keyCode == 116)) {
 		event.keyCode = 0;
		event.returnValue = false;
		return;
 	}
	if(event.keyCode == 0 && event.button!=1) alert("?????????????");
	event.returnValue = false;
}

/******************************************
******************************************/
function s2hhmmss(s){
	var hh,mm,ss;
	ss = parseInt(s%60);
	hh = parseInt(s/3600);
	mm = parseInt((s/60)%60);

	ss = ss<10?"0"+ss:ss;
	hh = hh<10?"0"+hh:hh;
	mm = mm<10?"0"+mm:mm;
	return hh+" ? "+mm+" ? "+ss+" ?";
}

/******************************************
******************************************/
function subString(str){
        var str1;
        str1 = str.substr(0,str.length<20?str.length:20);
        return str1;
}


function GetRandomNum(Min,Max){
        var Range = Max - Min;
        var Rand = Math.random();
        return(Min + Math.round(Rand * Range));
}

function encryptString(str){

   var strRet = "";
   for(var i=1;i<str.length;i++){
      var ttt = str.substr(i,1);
	  strRet +=  str.substr(i,1) + GetRandomNum(0,9) ;
   }
   return strRet + str.substr(0,1) + GetRandomNum(0,9);
}
/******************************************
******************************************/
String.prototype.trim = function()
{
    // ???????????
    // ????????
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

/*********************************
 * ??????????????????
 */
// store variables to control where the popup will appear relative to the cursor position

// positive numbers are below and to the right of the cursor, negative numbers are above and to the left

var xOffset = 10;

var yOffset = 0;



function showPopup (targetObjectId, eventObj) {

    if(eventObj) {

	// hide any currently-visible popups

	hideCurrentPopup();

	// stop event from bubbling up any farther

	eventObj.cancelBubble = true;

	// move popup div to current cursor position

	// (add scrollTop to account for scrolling for IE)

	yOffset = calYOffset(targetObjectId, eventObj);
	xOffset = calXOffset(targetObjectId, eventObj);

	var newXCoordinate = (eventObj.pageX)?eventObj.pageX + xOffset:eventObj.x + xOffset + ((document.body.scrollLeft)?document.body.scrollLeft:0);

	var newYCoordinate = (eventObj.pageY)?eventObj.pageY + yOffset:eventObj.y + yOffset + ((document.body.scrollTop)?document.body.scrollTop:0);

    //var newXCoordinate = eventObj.x + 10;
    //var newYCoordinate = eventObj.y - 60;

    //alert(newXCoordinate);
    //alert(newYCoordinate);
	moveObject(targetObjectId, newXCoordinate, newYCoordinate);

	// and make it visible

	if( changeObjectVisibility(targetObjectId, 'visible') ) {

	    // if we successfully showed the popup

	    // store its Id on a globally-accessible object

	    window.currentlyVisiblePopup = targetObjectId;

	    return true;

	} else {

	    // we couldn't show the popup, boo hoo!

	    return false;

	}

    } else {

	// there was no event object, so we won't be able to position anything, so give up

	return false;

    }

} // showPopup



function hideCurrentPopup() {

    // note: we've stored the currently-visible popup on the global object window.currentlyVisiblePopup

    if(window.currentlyVisiblePopup) {

	changeObjectVisibility(window.currentlyVisiblePopup, 'hidden');

	window.currentlyVisiblePopup = false;

    }

} // hideCurrentPopup







// ***********************

// hacks and workarounds *

// ***********************



// initialize hacks whenever the page loads

//window.onload = initializeHacks;



// setup an event handler to hide popups for generic clicks on the document

document.onclick = hideCurrentPopup;



function initializeHacks() {

    // this ugly little hack resizes a blank div to make sure you can click

    // anywhere in the window for Mac MSIE 5

    if ((navigator.appVersion.indexOf('MSIE 5') != -1)

	&& (navigator.platform.indexOf('Mac') != -1)

	&& getStyleObject('blankDiv')) {

	window.onresize = explorerMacResizeFix;

    }

    resizeBlankDiv();

    // this next function creates a placeholder object for older browsers

    createFakeEventObj();

    if (typeof(examineCheckbox) != 'undefined') examineCheckbox();

}



function createFakeEventObj() {

    // create a fake event object for older browsers to avoid errors in function call

    // when we need to pass the event object to functions

    if (!window.event) {

	window.event = false;

    }

} // createFakeEventObj



function resizeBlankDiv() {

    // resize blank placeholder div so IE 5 on mac will get all clicks in window

    if ((navigator.appVersion.indexOf('MSIE 5') != -1)

	&& (navigator.platform.indexOf('Mac') != -1)

	&& getStyleObject('blankDiv')) {

	getStyleObject('blankDiv').width = document.body.clientWidth - 20;

	getStyleObject('blankDiv').height = document.body.clientHeight - 20;

    }

}



function explorerMacResizeFix () {

    location.reload(false);

}

//calculate the tip div y-position
function calYOffset(targetObjectId,eventObj){
    var posY = 0;
    var delta = 20;

    //the tip div object
    var divObj = document.getElementById(targetObjectId);

    var offsetTop = (eventObj.pageY)?eventObj.pageY + delta :eventObj.y + delta;//mouse pointer's y position
    var offsetHeight = divObj.offsetHeight;//tip div height
    var win_height = document.body.offsetHeight;//window height

    if(((offsetTop + offsetHeight) - win_height) > 0){
        //the tip bottom is over the visible window area bottom
        posY = win_height - (offsetTop + offsetHeight);

        //the top of tip div can not over the window top
        if((0-posY) > offsetTop) {
            posY = 0-offsetTop;
        }
    }else {
        posY = 0;
    }

    return posY;
}

function calXOffset(targetObjectId,eventObj){
    var posX = 10;
    var delta = 20;

    //the tip div object
    var divObj = document.getElementById(targetObjectId);

    var offsetLeft = (eventObj.pageX)?eventObj.pageX + delta :eventObj.x + delta;//mouse pointer's x position
    var offsetWidth = divObj.offsetWidth;//tip div width
    var win_width = document.body.offsetWidth;//window width

    if(((offsetLeft + offsetWidth) - win_width) > 0){
        //the tip right is over the visible window area right
        posX = win_width - (offsetLeft + offsetWidth);

        //the right of tip div can not over the window right
        if((0-posX) > offsetLeft) {
            posX= 0-offsetLeft;
        }
    }else {
        posX = 10;
    }

    return posX;
}

function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getStyleObject

function changeObjectVisibility(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.visibility = newVisibility;
	return true;
    } else {
	// we couldn't find the object, so we can't change its visibility
	return false;
    }
} // changeObjectVisibility

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


/***************************************************/


