//受講者定義関数




//XMLHttpRequestオブジェクト生成
function createHttpRequest(){

	//Win ie用
	if(window.ActiveXObject){
		try {
			//MSXML2以降用
			return new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				//旧MSXML用
				return new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				return null;
			}
		}
	} else if(window.XMLHttpRequest){
		//Win ie以外のXMLHttpRequestオブジェクト実装ブラウザ用
		return new XMLHttpRequest();
	} else {
		return null;
	}
}



//ファイルにアクセスし受信内容を確認します
function callback(div,val,id)
{
	var re = "";
	var url = "./call.php?p_div="+div+"&p_val="+val+"&p_id="+id;
	//XMLHttpRequestオブジェクト生成
	var httpoj = createHttpRequest();
	//open メソッド
	httpoj.open("GET", url,"false");
	//受信時に起動するイベント
	httpoj.onreadystatechange = function(){ 
		//readyState値は4で受信完了
		if(httpoj.readyState==4 && httpoj.status == 200){
			if(document.fm_call.call.value==""){
				document.fm_call.call.value = httpoj.responseText;
			}
		}
	}
	//send メソッド
	httpoj.send(null);
}

//必ず呼び出すページ内に右記フォームを設置するして使用する→<form name="fm_call"><input type="hidden" name="call" value=""></form>
function call_str(div,val,id){
	document.fm_call.call.value = "";
	for(i=0;i<10;i++){
		if(document.fm_call.call.value==""){
			callback(div,val,id);
		}
	}
	return document.fm_call.call.value;
}


//必ず呼び出すページ内に右記フォームを設置するして使用する→<form name="fm_call"><input type="hidden" name="call" value=""></form>
function call(div,val,id){
	document.fm_call.call.value = "";
	for(i=0;i<10;i++){
		if(document.fm_call.call.value==""){
			callback(div,val,id);
		}
	}
	if(document.fm_call.call.value>0){
		return true;
	}else{
		return false;
	}
}

function strtoarray(str){
	var a=str.split("`");
	var c = new Array();
	for(var i=0;i<a.length;i++){
		c[i]=new Array();
		var b=a[i].split(",");
		c[i][0] =b[0]; 
		c[i][1] =b[1]; 
	}
	return c;
}


//背景色の変更（初期）
function chdef(obj)
{
	obj.style.backgroundColor="#FFFFFF";
}
//背景色の変更（エラー）
function ch(obj)
{
	obj.style.backgroundColor="#FFB6C1";
}
//日付の入力チェック
function ckDate(datestr) 
{ 
    // 正規表現による書式チェック 
    if(!datestr.match(/(\d{4})\/(\d{1,2})\/(\d{1,2})/)){ 
        return false; 
    } 
    if(datestr.match(/(\d{4})\/(\d{1})\/(\d{1,2})/)){ 
        datestr=datestr.replace(datestr.substr(0, 5),datestr.substr(0,5)+"0"); 
    } 
    if(datestr.match(/(\d{4})\/(\d{2})\/(\d{1})/) && datestr.length==9){ 
        datestr=datestr.replace(datestr.substr(0, 8),datestr.substr(0,8)+"0"); 
    } 
    var vYear = datestr.substr(0, 4) - 0; 
    var vMonth = datestr.substr(5, 2) - 1; // Javascriptは、0-11で表現 
    var vDay = datestr.substr(8, 2) - 0; 
    // 月,日の妥当性チェック 

    if(vMonth >= 0 && vMonth <= 11 && vDay >= 1 && vDay <= 31 && datestr.length == 10){ 
        var vDt = new Date(vYear, vMonth, vDay); 
        if(isNaN(vDt)){ 
            return false; 
        }else if(vDt.getFullYear() == vYear && vDt.getMonth() == vMonth && vDt.getDate() == vDay){ 
            return true; 
        }else{ 
            return false; 
        } 
    }else{ 
        return false; 
    } 
} 

//メールアドレスチェック
function ckmail(address){
	data = address.match(/[^A-Za-z0-9\s.\-@\_]+/);
	if(!data){
		return true;
	}
	return false;
}

//桁数を合わせた数値を文字列をして返す
function keta(str,col){
	atai=""+str;
	while(atai.length<col){
		atai="0"+atai;
	}
	return atai;
}

//「00000101」形式を「0000/01/01」へ変換
function Ymd_Y_m_d(ymd){
	s=""+ymd;
	t=keta(s.substring(0,4),4)+"/"+keta(s.substring(4,6),2)+"/"+keta(s.substring(6,8),2);
	return t;
}

//「00000101」形式を「0000/1/1」へ変換
function Ymd_Y_n_j(ymd){
	s=""+ymd;
	t=keta(s.substring(0,4),4)+"/"+parseInt(s.substring(4,6),10)+"/"+parseInt(s.substring(6,8),10);
	return t;
}

//「0000/1/1」形式を「00000101」へ変換。Y_m_d_Ymd()の効果もあり。
function Y_n_j_Ymd(ymd){
	str=""+ymd;
	a=str.split("/");
	result=keta(a[0],4)+keta(a[1],2)+keta(a[2],2);
	return ""+result;
}

//「0000/01/01」形式を「00000101」へ変換。Y_n_j_Ymd()の効果もあり。
function Y_m_d_Ymd(ymd){
	str=""+ymd;
	a=str.split("/");
	result=keta(a[0],4)+keta(a[1],2)+keta(a[2],2);
	return ""+result;
}


//サブウィンドウを開く
function open_sub_customer_list_select(){
	location.href = "#action_edit";
	str="width=620,height=300,location=no,status=no,resizable=yes,toolbar=no,menubar=no,scrollbars=yes";
	sub_customer_list_select = window.open("./p/sub_customer_list_select.php","sub",str); 
}

//サブウィンドウからの得意先選択
function select_customer(id,name){
	window.opener.document.fm.p_customer_id.value=id;
	window.opener.document.fm.p_customer_name.value=name;
	window.opener.document.fm.p_customer_name_sub.value=name;
	window.opener.document.getElementById("customer_select").innerHTML="ＩＤ："+id+" 「 "+name+" 」";
	window.close();
}

//サブウィンドウを開く
function open_sub_project_list_select(){
	location.href = "#action_edit";
	str="width=620,height=300,location=no,status=no,resizable=yes,toolbar=no,menubar=no,scrollbars=yes";
	sub_project_list_select = window.open("./p/sub_project_list_select.php","sub",str); 
}

//サブウィンドウからのプロジェクト選択
function select_project(id,name){
	window.opener.document.fm_action.p_project_id.value=id;
	window.opener.document.getElementById("project_select").innerHTML="ＩＤ："+id+" 「 "+name+" 」";
	window.close();
}


//講師サブウィンドウを開く（フォーム名の指定に対応）
function open_sub_lecturer_list_select_list(form_group_name,form_name){
//	location.href = "#action_edit";
	str="width=500,height=400,location=no,status=no,resizable=yes,toolbar=no,menubar=no,scrollbars=yes";
	sub_lecturer_list_select_list = window.open("./p/sub_lecturer_list_select_list.php?p_form_group_name="+form_group_name+"&p_form_name="+form_name,"sub",str); 
}

//講師サブウィンドウからのプロジェクト選択（フォーム名の指定に対応）
function select_lecturer_list(id,name,form_group_name,form_name){
	window.opener.document[form_group_name][form_name].value=id;
	window.opener.document.getElementById("lecturer_select").innerHTML="ＩＤ："+id+" 「 "+name+" 」";
	window.close();
}
//偉人サブウィンドウを開く（フォーム名の指定に対応）
function open_sub_history_person_list_select_list(form_group_name,form_name){
//	location.href = "#action_edit";
	str="width=500,height=400,location=no,status=no,resizable=yes,toolbar=no,menubar=no,scrollbars=yes";
	sub_lecturer_list_select_list = window.open("./p/sub_history_person_list_select_list.php?p_form_group_name="+form_group_name+"&p_form_name="+form_name,"sub",str); 
}

//偉人サブウィンドウからのプロジェクト選択（フォーム名の指定に対応）
function select_history_person_list(id,name,form_group_name,form_name){
	window.opener.document[form_group_name][form_name].value=id;
	window.opener.document.getElementById("history_person_select").innerHTML="ＩＤ："+id+" 「 "+name+" 」";
	window.close();
}

//会場サブウィンドウを開く（フォーム名の指定に対応）
function open_sub_place_list_select_list(form_group_name,form_name){
//	location.href = "#action_edit";
	str="width=500,height=400,location=no,status=no,resizable=yes,toolbar=no,menubar=no,scrollbars=yes";
	sub_place_list_select_list = window.open("./p/sub_place_list_select_list.php?p_form_group_name="+form_group_name+"&p_form_name="+form_name,"sub",str); 
}

//会場サブウィンドウからのプロジェクト選択（フォーム名の指定に対応）
function select_place_list(id,name,form_group_name,form_name){
	window.opener.document[form_group_name][form_name].value=id;
	window.opener.document.getElementById("place_select").innerHTML="ＩＤ："+id+" 「 "+name+" 」";
	window.close();
}

//メールアドレスの存在チェック
function lecturer_check_email(id,email){
	str="../iframe/lecturer_check_email.php?p_target_lid="+id+"&p_email="+email;
	frm.location.href=str;
}

//メールアドレスの存在チェック
function user_check_email(id,email){
	str="../iframe/user_check_email.php?p_target_uid="+id+"&p_email="+email;
	frm.location.href=str;
}

