// iStudy Enterprise Server common utilitys for opencms version
// copyroght System technology-i Co.,Ltd.

function numbersonly(myfield, e, dec){
   var key;
   var keychar;

   if (window.event)
	key = window.event.keyCode;
   else if (e)
	key = e.which;
   else
	return true;
   keychar = String.fromCharCode(key);

// control keys
   if ((key==null) || (key==0) || (key==8) ||
       (key==9) || (key==13) || (key==27) )
	return true;

// numbers
   else if ((("0123456789").indexOf(keychar) > -1))
	return true;

// decimal point jump
   else if (dec && (keychar == "."))
	{
	myfield.form.elements[dec].focus();
	return false;
	}
   else
	return false;
}

function numbersonly2(myfield, e, dec){
   var key;
   var keychar;

   if (window.event)
	key = window.event.keyCode;
   else if (e)
	key = e.which;
   else
	return true;
   keychar = String.fromCharCode(key);

// control keys
   if ((key==null) || (key==0) || (key==8) ||
       (key==9) || (key==13) || (key==27) )
	return true;

// numbers
   else if ((("0123456789.").indexOf(keychar) > -1))
	return true;

// decimal point jump
   else if (dec && (keychar == "."))
	{
	myfield.form.elements[dec].focus();
	return false;
	}
   else
	return false;
}

function help(sURL) {
   xhelp = window.open(sURL,"helpwindow","top=5,left=5,toolbars=no,maximize=yes,resize=yes,width=600,height=530,location=no,directories=no,scrollbars=yes")
   xhelp.focus();
}

function openWindow(sURL,sName) {
   var sArg = "toolbar=no,scrollbars=no,resizable=yes,width=500,height=500";
   xwin = window.open(sURL, sName, sArg);
   xwin.focus();
}

function encodeURL(str){
    var s0, i, s, u;
    s0 = "";                

    for (i = 0; i < str.length; i++){  
        s = str.charAt(i);
        u = str.charCodeAt(i);         
        if (s == " "){
           s0 += "+";
        } else {
            if ( u == 0x2a || u == 0x2d || u == 0x2e || u == 0x5f || ((u >= 0x30) && (u <= 0x39)) || ((u >= 0x41) && (u <= 0x5a)) || ((u >= 0x61) && (u <= 0x7a))){ 
                s0 = s0 + s;           
            } else {            

                if ((u >= 0x0) && (u <= 0x7f)){    
                    s = "0"+u.toString(16);
                    s0 += "%"+ s.substr(s.length-2);
                } else if (u > 0x1fffff){    
                    s0 += "%" + (oxf0 + ((u & 0x1c0000) >> 18)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0x3f000) >> 12)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                } else if (u > 0x7ff){       
                    s0 += "%" + (0xe0 + ((u & 0xf000) >> 12)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                } else {                     
                    s0 += "%" + (0xc0 + ((u & 0x7c0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);

                }

            }

        }

    }

    return s0;
}


var helpType = "";

function helpOpen() {
   if (helpType.substring(0,1) == '/') {
      helpFile = helpType;
   }else{
      helpFile = "/ies/help.do?TYPE="+helpType;
   }
   var sArg = "toolbar=no,scrollbars=yes,resizable=yes,width=400,height=400";
   xwin = window.open(helpFile, "_blank", sArg);
   xwin.focus();
}

function selectRow(line,stat,class1,field_max) {
   if (stat == 1) {
      for (i = 1; i <= field_max; i++) {
         document.getElementById("field"+i+"_"+line).className ="TableSelect";
      }
   } else {
      for (i = 1; i <= field_max; i++) {
         document.getElementById("field"+i+"_"+line).className =class1;
      }
   }
}

function movePage(page) {
	document.searchForm.PAGE_COUNT.value = page;
	document.searchForm.submit();
}

function openDeptWindow(cust) {
   var sArg = "toolbar=no,scrollbars=yes,resizable=yes,width=500,height=500";
   xwin = window.open("/ies/deptTree.do?TYPE=2&CUST_CD=" + cust, "dept", sArg);
   xwin.focus();
}

function isNumeric(num){ 
	var numeric="0123456789"; 

	if(num.length == 0){ 
		return true; 
	} 

	for(i = 0;i < num.length;i++){ 
		if(numeric.indexOf(num.charAt(i)) < 0){ 
			return false; 
		} 
	}
	return true; 
} 
function isDate(obj, must, msg) {
	if(must && obj.value.length == 0) {
		alert(msg);
		obj.focus();
		return false;
	}
	if(obj.value.length > 0) {
	    if(obj.value.length != 7 && obj.value.length != 10) {
		   alert(msg);
		   obj.focus();
		   return false;
		}
	    if(obj.value.substring(4,5) != '/') {
		   alert(msg);
		   obj.focus();
		   return false;
	    }
	    if(obj.value.length == 10 && obj.value.substring(7,8) != '/') {
		   alert(msg);
		   obj.focus();
		   return false;
	    }
	    if(obj.value.length == 7 || obj.value.length == 10) {
	       sYYYY = obj.value.substring(0,4);
	       sMM = obj.value.substring(5,7);
	       if (isNumeric(sYYYY) != true) { 
		      alert(msg);
		      obj.focus();
		      return false;
		   }
	       if (isNumeric(sMM) != true) { 
		      alert(msg);
		      obj.focus();
		      return false;
		   }
	    }
	}
	return true;
}

// yyyy/mm/dd format Check
//  inputFlg: boolean must input ( true:must false: not must )
//  str:input String

function CheckCalendarFormat(inputFlg, str){
	if (str.length==0) {
		if (inputFlg == true) {
			return false;
		}
	} else {
		var s=str.split("/");
		if(s.length!=3){
			return false;
		}
		
		if (s[0].length != 4) {
			return false;
		}
		
		if (s[1].length != 2) {
			return false;
		}

		if (s[2].length != 2) {
			return false;
		}
	}
	
	return true;
}

// Date Exist Check
//  inputFlg: boolean must input ( true:must false: not must )
//  str:input String

function CheckCalendarDate(inputFlg, str){
	if (str.length==0) {
		if (inputFlg == true) {
			return false;
		}
	} else {
		var s=str.split("/");
		if(s.length!=3){
			return false;
		}
	
		var y=s[0];
		var m=s[1];
		var d=s[2];
	
		if(isNaN(y)||isNaN(m)||isNaN(d)){
			return false;
		}else{
			if(y.length!=4){
				return false;
			}else{
				if(m<1||m>12){
					return false;
				}else{
					if(d<=0 || d>30+((m==4||m==6||m==9||m==11)?0:1) || (m==2&&d>28+(((y%4==0&&y%100!=0)||y%400==0)?1:0)) ){
						return false;
					}
				}
			}
		}
	}
	
	return true;
}


function body_init(){
	var ie  = document.all;
	if (ie) {
		hh = document.body.clientHeight;
		document.getElementById("contents").style.height = (hh-85)+"px";
	}else{
		hh = window.innerHeight;
		document.getElementById("contents").style.minHeight = (hh-85)+"px";
	}
}

function openPrintVersion() {
	var params = "print=true";
	if (document.location.search != "") {
		params = document.location.search + "&" + params;		
	} else {
		params = "?" + params;
	}
	window.open(document.location.pathname + params, "print", "width=860,height=750,menubar=yes,dependent=yes,status=no,toolbar=no,location=no,scrollbars=yes");
}
function parseSearchQuery(theForm, message) {
	var queryValue = theForm.elements["query2"].value;
	var testValue = queryValue.replace(/ /g, "");
	if (testValue.length < 3) {
		alert(message);
		return (false);
	}
	theForm.elements["query"].value = queryValue;
	return (true);
}
function c1107Mail() {
//20110726 キャンペーン用
	var ua = navigator.userAgent.toUpperCase();
	if ((ua.indexOf("IPHONE") != -1) || 
		(ua.indexOf("IPAD") != -1)) {
	//iPhone or iPad の時 → UTF-8をURLエンコード
		location.href = "mailto:cp_jtck@istudy.ne.jp?subject=Java%e8%b3%87%e6%a0%bc%e5%8f%96%e5%be%97%e5%bf%9c%e6%8f%b4%e3%82%ad%e3%83%a3%e3%83%b3%e3%83%9a%e3%83%bc%e3%83%b3%e5%bf%9c%e5%8b%9f&body=%e7%94%bb%e9%9d%a2%e3%82%b7%e3%83%a7%e3%83%83%e3%83%88%e3%82%92%e6%b7%bb%e4%bb%98%e3%81%ae%e4%b8%8a%e3%80%81%e3%81%8a%e5%90%8d%e5%89%8d%e3%82%92%e6%98%8e%e8%a8%98%e3%81%97%e3%81%a6%e3%81%94%e5%bf%9c%e5%8b%9f%e3%81%8f%e3%81%a0%e3%81%95%e3%81%84%e3%80%82%0d%0a%e3%80%90%e3%81%8a%e5%90%8d%e5%89%8d%e3%80%91";
	} else {
	//それ以外 → ShiftJISをURLエンコード（Windows用）
		location.href = "mailto:cp_jtck@istudy.ne.jp?subject=Java%8e%91%8ai%8e%e6%93%be%89%9e%89%87%83L%83%83%83%93%83y%81%5b%83%93&body=%89%e6%96%ca%83V%83%87%83b%83g%82%f0%93Y%95t%82%cc%8f%e3%81A%82%a8%96%bc%91O%82%f0%96%be%8bL%82%b5%82%c4%82%b2%89%9e%95%e5%82%ad%82%be%82%b3%82%a2%81B%0d%0a%81y%82%a8%96%bc%91O%81z";
	}
}

