/* (c)2007 Lavans, Inc. */
/**
 * formクリア
 */
function clearForm(){
//	alert(document.forms.length);
	with(document.forms[0]){
		for(i=0; i<elements.length; i++){
			if((elements[i].type != "button")
			 &&(elements[i].type != "reset")
			 &&(elements[i].type != "submit")
			 &&(elements[i].type != "radio")
			 &&(elements[i].type != "select-one")
			 &&(elements[i].type != "hidden")
			){
				elements[i].value = "";
			}
//		document.write(elements[i].type.value+"<br>");
		}
	}
}

/**
 * formクリア
 */
function clearFormByName(formName){
	with(document.forms[formName]){
		for(i=0; i<elements.length; i++){
			if((elements[i].type != "button")
			 &&(elements[i].type != "reset")
			 &&(elements[i].type != "submit")
			 &&(elements[i].type != "radio")
			 &&(elements[i].type != "select-one")
			 &&(elements[i].type != "hidden")
			){
				elements[i].value = "";
			}
//		alert(elements[i].name +"/"+ elements[i].type);
		}
	}
}
/**
 * チェックボックス全選択・全解除
 */
function checkAll(formName, value){
	with(document.forms[formName]){
		for(i=0; i<elements.length; i++){
			if(elements[i].type == "checkbox"){
				elements[i].checked = value;
			}
		}
	}
}

/**
 * 削除確認ダイアログ
 */
function deleteConfirm(target, url){
	if(window.confirm(target + 'を削除します')){
//		w = window.open(url, "_self");
		location.href = url; // sample_confirm.html へジャンプ
		return true;
	}
}

/**
 * 削除確認ダイアログ
 * 追加メッセージ付き
 */
function deleteConfirmMsg(target, url, msg){
	if(window.confirm(target + 'を削除します。\n' + msg)){
		window.open(url, "_new");
//		location.href = url; // sample_confirm.html へジャンプ
	}
}

/**
 * ランダムパスワード生成
 * 0-9,a-z,A-Zの62文字といきたいところだけど、
 * 数字の0と大文字のO、数字の1と小文字のlは見間違え安いので避ける。
 * 4文字引いて58文字。
 * @TODO 生成文字列が6文字以上なら数字が入っているかどうかのチェック。
 */
function makePass(length, target){
	var s="";
	for(i=0; i<length; i++){
		var code = shiftMark(parseInt(Math.random()*58)); // 58文字
		codeTest+=code+",";
		s += String.fromCharCode(code+0x32);	// 0,1を避けるので0x32からスタート
	}
	target.value=s;
}

/**
 * 記号を避けるようにshiftする。
 * ((i>9)  && (i<17))  :;<=>?@
 * ((i>42) && (i<49))  [\]^_`
 */
function shiftMark(i){
	if(i>7) i+=7;	// :
	if(i>28) i+=1;	// O
	if(i>40) i+=6;	// [
	if(i>57) i+=1;	// l
	return i;
}

/** テスト用コード
//素の0x30からどの文字になるかチェック
	for(i=0; i<75; i++){
	document.write(i+":"+String.fromCharCode(i+0x30)+"<br>");
	}
// 0から57までで全文字網羅のチェック
	for(i=0; i<58; i++){
		j=shiftMark(i);
		document.write(i+":"+j+":"+String.fromCharCode(j+0x32)+"<br>");
	}
*/


/**
 * 表示切替
 */
function changeDisp(target){
  if(document.getElementById(target).style.display == 'none'){
    document.getElementById(target).style.display = '';
  }else{
    document.getElementById(target).style.display = 'none';
  }
}

/**
 * 文字列カウント
 * 全角は2文字でカウントする。
 */
function countStr(str) {
    var len = str.length, n=0, i;
        
    for(i = 0; i < len; i++){
    	// escapeしたときにunicodeになったら全角
		if(escape(str.charAt(i)).charAt(1) == "u"){
			n += 2;
		}else{
			n +=1;
		}
    }
    return n;
}

/**
 * form submit後にwindowをクローズする。メモsubmit用
 */
function submitClose(){
	document.forms[0].submit();
	window.close();
}

