var MSIE, VERSION, TWOBYE;
var all='1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ _+-'

MSIE = navigator.userAgent.indexOf('MSIE') != -1;
VERSION = navigator.userAgent.substring(8,12);

USABLE = (MSIE) && (VERSION >= '3.01')
TWOBYTE = (((!MSIE) && (VERSION >= '4.51')) || MSIE)

function bkOpenWin(name, url, left, top, width, height, toolbar, menubar, statusbar, scrollbar, resizable)
{
	var w;
  toolbar_str = toolbar ? 'yes' : 'no';
  menubar_str = menubar ? 'yes' : 'no';
  statusbar_str = statusbar ? 'yes' : 'no';
  scrollbar_str = scrollbar ? 'yes' : 'no';
  resizable_str = resizable ? 'yes' : 'no';
  w = window.open(url, name, 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);
  return w;
}

// ------------------------------------------------------------------
// IS NUMBER STRING?
	function isNumberStr(str)
	{
		var i
		for( i = 0 ; i < str.length; i++ )
		{
			ch = str.charAt(i)
			if (!isNumber(ch)) {
				return false;
			}
		}
		return true;
	}

// ------------------------------------------------------------------
// IS ALPHABET STRING?
	function isAlphaStr(str)
	{
		var i
		for( i = 0 ; i < str.length; i++ )
		{
			ch = str.charAt(i)
			if (!isAlpha(ch)) {
				return false;
			}
		}
		return true;
	}

// ------------------------------------------------------------------
// IS ALPHANUMBER STRING?
	function isAlphaNumberStr(str)
	{
		var i
		for (i = 0; i < str.length; i++) {
			ch = str.charAt(i)
			if ((!isAlpha(ch)) && (!isNumber(ch)) ) {
				return false;
			}
		}
		return true;
	}
	
// ------------------------------------------------------------------
// IS ALPHA CHARACTER?
	function isAlpha(ch)
	{
		var i, alpha
		alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
		for(i = 0; i < alpha.length; i++) {
			if (alpha.charAt(i) == ch) {
				return true;			
			}
		}
		return false;
	}

// ------------------------------------------------------------------
// IS SPECIAL CHARACTER?
	function isSpecial(ch)
	{
		var i, special
		special = "~!@#$%^&*()_+|`-=\<>,./?'\"\32"
		for(i = 0; i < special.length; i++) {
			if (special.charAt(i) == ch) {
				return true;			
			}
		}
		return false;
	}

// ------------------------------------------------------------------
// IS NUMBER CHARACTER?
	function isNumber(ch)
	{
		var i, number
		number = "1234567890"
		for(i = 0; i < number.length; i++) {
			if (number.charAt(i) == ch) {
				return true;			
			}
		}
		return false;
	}

// ------------------------------------------------------------------
// IS SOME CHARACTER?
	function isChar(ch, str) {
		var i
		for(i = 0; i < str.length;i++){
			if (str.charAt(i) == ch){
				return true;			
			}
		}
		return false;
	}
// ------------------------------------------------------------------
// STRING LENGTH
	function strLength(str)
	{
		var i, StringLength
		StringLength = 0;
		for(i = 0 ; i < str.length; i++) {
			if (isNumber(str.charAt(i))) {
				StringLength++;
			} else if (isAlpha(str.charAt(i))) {
				StringLength++;
			} else if (isSpecial(str.charAt(i))) {
				StringLength++;
			} else {
				if (TWOBYTE) {
					StringLength += 2;
				} else {
					StringLength++;
				}

			}
		}
		
		return StringLength;
	}
// ------------------------------------------------------------------
function checkField(target, constr, lbound, ubound, must, tString, eString)
{
        var i
        var t = target.value

        if (strLength(t) == 0 && must ) {
			alert(tString + "は必ず入力してください。");
            target.focus()
            return true
        }

        if (strLength(t) != 0) {

	        if (strLength(t) < lbound || strLength(t) > ubound) {
					alert(eString);
        	        target.focus()
            	    return true
	        }
    	    if (strLength(constr) > 1) {
        	        for (i=0; i<strLength(t); i++)
            	            if(constr.indexOf(t.substring(i,i+1))<0) {
                	                alert(tString + 'に正しくない文字が含まれています。');
                    	            target.focus()
                        	        return true
	                        }
    	    }

		}
       	return false
        
}

function checkCombo(target, svalue, tString, eString)
{
	var i
	var t = target[target.selectedIndex].value
	
	if ( t == svalue ) {
		alert(eString);
		target.focus()
		return true
	}
	
	return false;
}

function IDCheck(target, lbound, ubound, tString)
{
		var Alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    	var Digit = '1234567890'
        var i
        var t = target.value
		var cString = Alpha + Digit + '_'
		
        if (strLength(t) < lbound || strLength(t) > ubound) {
                if (lbound == ubound) alert(tString + 'は' + lbound + ' Byteのアルファベットか数字にしてください。');
                         else alert(tString +'は' + lbound + ' ~ ' + ubound + ' Byte以内のアルファベットか数字を入力してください。');
                target.focus();
                return true;
        }
        if (strLength(cString) > 1) {
                for (i=0; i<strLength(t); i++)
						if ( i == 0 ) {
    	                    if(Alpha.indexOf(t.substring(i,i+1))<0) {
	                                alert(tString + 'の頭文字は必ずアルファベットで始めます。');
        	                        target.focus()
            	                    return true
							}
						}
						else {
                	        if(cString.indexOf(t.substring(i,i+1))<0) {
            	                    alert(tString + 'に正しくない文字が含まれています。');
        	                        target.focus()
    	                            return true
	                        }
						}
        }
        return false
        
}

function getListValue(listfield) { return listfield.options[listfield.selectedIndex].value }

function checkList(target, tString)
{
        if (getListValue(target) == '-') {
                alert(tString + 'を選択してください。')
                target.focus()
                return true
        }
        return false
}

function checkListJP(target, tString)
{
        if (getListValue(target) == '-') {
                alert(tString + 'を選択してください。')
                target.focus()
                return true
        }
        return false
}

function jumin_check(jumin) {
	var IDtot, IDAdd
	
	if (jumin.length == 13) {
		IDtot = 0;
		IDAdd="234567892345";
		if ( (parseInt(jumin.substring(6,7)) != 1) && (parseInt(jumin.substring(6,7)) != 2) )
			return false;
		for(i=0;i<12;i++) {
			IDtot=IDtot+parseInt(jumin.substring(i,i+1))*parseInt(IDAdd.substring(i,i+1));
		}
		
		IDtot=11-(IDtot%11);
		if(IDtot==10) {
			IDtot=0;
		}
		else if(IDtot==11){
			IDtot=1;
		}

		if(parseInt(jumin.substring(12,13)) == IDtot) return true;
	}
	
	return false;
} 

//==================================================================================
// check size
//==================================================================================
function check_size( t_obj, t_size ) {
	var t_t = strLength(t_obj.value) ; 
	
	if ( t_t > t_size ) {
		return false ;
	} else {
		return true ;
	}
}
function check_obj( t_obj, t_size, str ) {
	var t_t ;
	var t_str = "規定のサイズを超えています。" ;
	
	t_t = check_size( t_obj, t_size ) ;
	
	if ( t_t  != true ) {
		alert( str + t_str ) ;
		return false ;
	}
	return true ;
}
//==================================================================================

function setCookie(name, value, expire) {
   document.cookie = name + "=" + escape(value)
      + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
}

function SetCookie (name, value) 
{
        var argv = SetCookie.arguments;
        var argc = SetCookie.arguments.length;
        var expires = (argc > 2) ? argv[2] : null;
        var path = (argc > 3) ? argv[3] : null;
        var domain = (argc > 4) ? argv[4] : null;
        var secure = (argc > 5) ? argv[5] : false;
        document.cookie = name + "=" + escape (value) +
        ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
        ((path == null) ? "" : ("; path=" + path)) +
        ((domain == null) ? "" : ("; domain=" + domain)) +
        ((secure == true) ? "; secure" : "");
}

function getCookie(Name) {
   var search = Name + "="
   if (document.cookie.length > 0) { // if there are any cookies      
       offset = document.cookie.indexOf(search)
       if (offset != -1) { // if cookie exists
          offset += search.length
          // set index of beginning of value
         end = document.cookie.indexOf(";", offset)
         // set index of end of cookie value
         if (end == -1)
             end = document.cookie.length
         return unescape(document.cookie.substring(offset, end))
      }
    }
}

function GetCookie(name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}
