// $Id: gdm.js,v 1.7 2007/01/15 03:16:37 nishi Exp $ 
// gdm.js

function $(id) {
	return document.getElementById(id); 
}

var req = createXMLHttpRequest();

function sendMessage(event, arg) {
	var method = "GET";
	var obj = null;
	if (arg == null) {
		arg = "";
	}
	var url = "/?m=browser&e=" + event + "&arg=" + encodeURIComponent(arg);
	req.onreadystatechange = readyStateChangeHandler;
	req.open(method, url, true);
	req.send(obj);
}

function sendMessageSync(event, arg) {
	var method = "GET";
	var obj = null;
	if (arg == null) {
		arg = "";
	}
	var url = "/?m=browser&e=" + event + "&arg=" + encodeURIComponent(arg);
	req.open(method, url, false);
	req.send(obj);
}

function readyStateChangeHandler() {
	try {
		if (req.readyState == 4) {
			if (req.status == 200) {
				// alert("data received");
			} else {
				alert("data receive error\n" + req.status + " " + req.statusText);
			}
		}
	} catch(e) {
		if(typeof e == 'object') {
			alert(e.message);
		} else {
			alert(e);
		}
	}
}

function createXMLHttpRequest() {
	return this.XMLHttpRequest ?
	  new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
}

// http://jsgt.org/js/books/dhtml2/part3/cross/getkeycd.htm
function getKeyCode(e){
    var ua = navigator.userAgent
    if(ua.indexOf("Safari")!=-1 ||
       ua.search('opera(\ |\/)6')!=-1)  // s1,o6 : not available
      return null
    else if(document.layers)            // n4
      return e.which
    else if(document.all)               // e4,e5,e6,o7
      return event.keyCode
    else if(document.getElementById)    // n6,n7,moz
      return e.charCode
    else return null                    // others : not available
}

// end of file
