

/* ===============  Global Variables  =============== */

var nickname = '';
var myid = '';
var myface = '';
var member_array = new Array();    // nickname +',,'+ chatid +',,'+ chatface
var loaded = 0;

/* ===============  FLASH  =============== */

function insert() {

}


/* ===============  LOAD DATA  =============== */

function chat_DoFSCommand (command, args) {
	if (command == "B") {
		var msg_array = new Array();
		msg_array = args.split(',,');
		loadData(msg_array[0], msg_array[1], msg_array[2], msg_array[3], msg_array[4]);
	}
}

function loadData(chatname, chatid, chatname_loggedin, is_loggedin, hash) {  // chatname,chatid
	
	if(is_loggedin == 1){
		document.bbsform.nickname.value = chatname_loggedin;
	}
	else{
		document.bbsform.nickname.value = chatname;
	}
	document.bbsform.chatid.value = chatid;
	document.bbsform.hash.value = hash;
	document.bbsform.is_loggedin.value = is_loggedin;
	document.bbsform.rm.value = 'confirm';
	loaded = 1;
}

function sendData(a,b,c) {  // rm,id,res
	document.bbsform.rm.value = a;
	document.bbsform.id.value = b;
	document.bbsform.method = 'post';
	document.bbsform.submit();
}

var offset_x, offset_y;
var popup_x, popup_y;
var move_box_obj;
var move_offsetX;
var move_offsetY;
//var move_X;
//var move_Y;
// 動かしたいものはset_moveであらかじめ登録しておく
function move_box(e){
	move_box_obj = this;
	var evt = window.event? window.event : e;
	var src = (evt.srcElement) ? evt.srcElement : evt.target;
	if(src.tagName == 'INPUT' || src.tagName == 'SELECT' || src.tagName == 'TEXTAREA'){
		move_offsetX = 0;
		move_offsetY = 0;
		return true;
	}
	
	move_offsetX = parseInt(move_box_obj.style.left) - evt.clientX;
	move_offsetY = parseInt(move_box_obj.style.top) - evt.clientY;
	
	return false;
}
function onMouseMove(e) {
	if (!move_box_obj) {
		return true;
	}
	
	var evt = window.event? window.event : e;
	if(move_offsetX != 0 && move_offsetY != 0){
		move_box_obj.style.left = move_offsetX + evt.clientX + "px";
		move_box_obj.style.top = move_offsetY + evt.clientY + "px";
	}	
	return false;
}


function onMouseUp(e) {
	move_box_obj = null;
}


function set_move(id) {
	document.getElementById(id).style.position = "absolute";
	document.getElementById(id).onmousedown = move_box;
}

window.onload = function () {
	document.onmousemove = onMouseMove;
	document.onmouseup = onMouseUp;
}

function show_report_window(id, evt) {
	var id = document.getElementById('report_article_id').value = id;
	
	
	if ( evt ) {
		popup_x = evt.clientX + (document.body.scrollLeft || document.documentElement.scrollLeft);
		popup_y = evt.clientY + (document.body.scrollTop || document.documentElement.scrollTop);
	} else {
		popup_x = event.clientX + (document.body.scrollLeft || document.documentElement.scrollLeft);
		popup_y = event.clientY + (document.body.scrollTop || document.documentElement.scrollTop);
	}
	if( popup_x + 300 > document.body.clientWidth ){
		popup_x = document.body.clientWidth - 300;
	}
	
	document.getElementById('report_window').style.left = popup_x + "px";
	document.getElementById('report_window').style.top = popup_y + "px";
	document.getElementById('report_window').style.display = "block";
}
function close_report_window() {
	document.getElementById('report_window').style.display = "none";
}

function send_report() {
	var id = document.getElementById('report_article_id').value;
	
	var script = document.createElement("script");
	script.type = "text/javascript";
	script.charset = "utf-8";
	script.src = "/report.cgi?rm=bbs&id=" + id + "&chatid=" + document.bbsform.chatid.value + "&hash=" + document.bbsform.hash.value + "&reason=" + document.getElementById('report_reason').value + "&nick=" + document.bbsform.nickname.value;
	document.body.appendChild(script);
	
	document.getElementById('report_reason').value = "";
	
	
	close_report_window();
}


