function IsIE() {
var isApp = navigator.appName.indexOf( "Microsoft" ) != -1;
var isVersion = ( arguments.length ) ? navigator.appVersion.substring(0, 1).valueOf() >= arguments[0] : true;
return isApp && isVersion;
}
function IsMozilla() {
var isApp = IsNetscape() && !document.all && document.getElementById;
var isVersion = ( arguments.length ) ? navigator.appVersion.substring(0, 1).valueOf() >= arguments[0] : true;
return isApp && isVersion;
}
function IsNetscape() {
var isApp = navigator.appName == "Netscape";
var isVersion = ( arguments.length ) ? navigator.appVersion.substring(0, 1).valueOf() >= arguments[0] : true;
return isApp && isVersion;
}
///////
function $View(_property_) {
return $("v:"+_property_);
}
function $Form(_module_) {
return $("f:"+_module_);
}
function $Grid(_module_) {
return $("g:"+_module_);
}
function $Table(_module_) {
return $("t:"+_module_);
}
function $Column(_property_) {
return $("td:"+_property_);
}
function $Action(_action_) {
return $(_action_+"-action");
}
function $Filter(_filter_) {
return $(_filter_+"-filter");
}
function $Core(_element_id_) {
return $("core:"+_element_id_);
}
function $TG(_element_id_) {
return $("tg:"+_element_id_);
}
function $TGContent(_element_id_) {
return $("tg:ct:"+_element_id_);
}
/////////// UTILITY FUNCTIONS /////////
function elem(name, attributes, style) {
var el = document.createElement(name);
Object.extend(el,attributes);
Object.extend(el.style,style);
Element.extend(el);
return el;
}
function elemNS(namespace, name, attributes, style) {
var el = document.createElementNS(namespace, name);
Object.extend(el,attributes);
Object.extend(el.style,style);
Element.extend(el);
return el;
}
function htmlTableRow(attributes, style) {
var el = elem("tr", attributes, style);
Object.extend(el,MVCTableRowElement.prototype);
return el;
}
function htmlTableCell(attributes, style) {
var el = elem("td", attributes, style);
Object.extend(el,MVCTableCellElement.prototype);
return el;
}
function htmlLink(attributes, style) {
var el = elem("a", attributes, style);
Object.extend(el,MVCLinkElement.prototype);
return el;
}
var emptyElements = {
HR: true, BR: true, IMG: true, INPUT: true
};
var specialElements = {
TEXTAREA: true
};
Element.prototype.toHTML = function() {
return getOuterHTML(this);
}
function getOuterHTML(node) {
var html = '';
switch (node.nodeType) {
case Node.ELEMENT_NODE:
html += '<';
html += node.nodeName;
if (!specialElements[node.nodeName]) {
for (var a = 0; a < node.attributes.length; a++)
html += ' ' + node.attributes[a].nodeName.toUpperCase() +
'="' + node.attributes[a].nodeValue + '"';
html += '>';
if (!emptyElements[node.nodeName]) {
html += node.innerHTML;
html += '<\/' + node.nodeName + '>';
}
}
else switch (node.nodeName) {
case 'TEXTAREA':
for (var a = 0; a < node.attributes.length; a++)
if (node.attributes[a].nodeName.toLowerCase() != 'value')
html += ' ' + node.attributes[a].nodeName.toUpperCase() +
'="' + node.attributes[a].nodeValue + '"';
else
var content = node.attributes[a].nodeValue;
html += '>';
html += content;
html += '<\/' + node.nodeName + '>';
break;
}
break;
case Node.TEXT_NODE:
html += node.nodeValue;
break;
case Node.COMMENT_NODE:
html += '<!' + '--' + node.nodeValue + '--' + '>';
break;
}
return html;
}
function parseDate(str, fmt) {
return str ? Date.parseDate(str, fmt) : null;
}
function onKeyCal(evt,popKeyCode,el,format,showsTime) {
evt = evt ? evt : event;
if(evt.keyCode==popKeyCode) {
evt.cancelBubble = true;
if(isIE()) evt.keyCode=0;
evt.returnValue = false;
while(el && el.nodeName!='IMG') el = el.nextSibling;
if(el) { showCalendar(el,format,showsTime); }
return false;
}
}
function onEmptyCal(el,format) {
if(el && el.value=='' && el.asked!=true) {
while(el && el.nodeName!='IMG') el = el.nextSibling;
if(el) { showCalendar(el,format); }
el.asked = true;
}
}
function onCalSelected(cal, date) {
cal.sel.value = date;
if (cal.dateClicked) {
cal.callCloseHandler();
}
}
function fireEvent(tgt, evtName) {
if (IsIE()) {
var evt = document.createEventObject();
tgt.fireEvent('on'+evtName,evt);
}
else {
var evt = document.createEvent("Events");
evt.initEvent(evtName, true, true);
tgt.dispatchEvent(evt);
}
}
function onCalClose(cal) {
if (cal != null) {
cal.hide();
fireEvent(cal.sel, "change");
}
PopupManager.deregisterAll();
}
function onCalBlur() {
PopupManager.deregisterAll();
}
function showCalendar(bel, format, showsTime, hideOtherMonths) {
try {
var el = $(bel).previous('input');
PopupManager.deregisterAll();
if(el) {
var cal = new Calendar(1, null, onCalSelected, onCalClose);
cal.weekNumbers = false;
cal.showsOtherMonths = true;
if (typeof showsTime == "string") { cal.showsTime = false; cal.time24 = (showsTime == "24"); }
if (hideOtherMonths) { cal.showsOtherMonths = false; }
cal.setRange(1900, 2070);
cal.create();
cal.setDateFormat(format);
cal.parseDate(el.value);
cal.sel = el;
cal.showAtElement(bel,"Br");
PopupManager.register(cal, true);
}
} catch (e) {
debugPrint(Object.toJSON(e));
}
}
function getBeanIdParam(params) {
if (Form) {
if (!params || params=='' || (params.indexOf(Form.module)==-1)) {
if (Form.view && Form.view.bean && Form.view.bean.id && Form.view.bean.id != 0) {
if (params && params!='') {
return '&'+Form.module+'Id=' +  Form.view.bean.id;
}
else {
return '?'+Form.module+'Id=' +  Form.view.bean.id;
}
}
}
}
return '';
}
/////////////// LOGGER /////////////////////
var logLines = [];
function debugPrint(msg) {
if (mvc.debug) {
if (mvc.logger!=null) {
mvc.logger.print(msg)
}
try {
if (IsIE()) {
var force = false;
if (msg == "COMMIT") {force = true;}
else {
logLines.push(msg);
}
if ((logLines.length == 10) || force) {
if (Form) {
Form.context.log(logLines);
}
else if (Grid) {
Grid.context.log(logLines);
}
else {
console.log(logLines.join("\n"));
}
logLines = [];
}
}
else if (console && console.log) {
console.log(msg);
}
}
catch(e) {}
}
else if (mvc.firebug) {
if (!IsIE()) {
try {
if (console && console.log) {
console.log(msg);
}
}
catch (e) {}
}
}
}
function useLoadingMessage(message) {
var loadingMessage;
if (message) loadingMessage = message;
else loadingMessage = "Loading";
dwr.engine.setPreHook(function() {
var disabledZone = $('disabledZone');
if (!disabledZone) {
disabledZone = document.createElement('div');
disabledZone.setAttribute('id', 'disabledZone');
disabledZone.style.position = "absolute";
disabledZone.style.zIndex = "1000";
disabledZone.style.left = "0px";
disabledZone.style.top = "0px";
disabledZone.style.width = "100%";
disabledZone.style.height = "100%";
document.body.appendChild(disabledZone);
var messageZone = document.createElement('div');
messageZone.setAttribute('id', 'messageZone');
messageZone.style.position = "absolute";
messageZone.style.top = "0px";
messageZone.style.right = "0px";
messageZone.style.background = "red";
messageZone.style.color = "white";
messageZone.style.fontFamily = "Arial,Helvetica,sans-serif";
messageZone.style.padding = "4px";
disabledZone.appendChild(messageZone);
var text = document.createTextNode(loadingMessage);
messageZone.appendChild(text);
}
else {
$('messageZone').innerHTML = loadingMessage;
disabledZone.style.visibility = 'visible';
}
});
dwr.engine.setPostHook(function() {
$('disabledZone').style.visibility = 'hidden';
});
}
function init(defaultPath, scriptSessionId, message) {
if (mvc.debug && IsIE()) {
try {
console.log("IE: initLogger");
}
catch(e) {
mvc.initLogger();
}
}
dwr.engine._scriptSessionId = scriptSessionId;
dwr.engine._defaultPath = defaultPath + "/dwr";
dwr.engine.setHeaders({
"Script-Session-Id": dwr.engine._scriptSessionId
});
mvc.initKPH();
useLoadingMessage(message);
dwr.engine.setActiveReverseAjax(false);
dwr.engine.setErrorHandler(defaultErrorHandler);
dwr.engine.setWarningHandler(defaultWarningHandler);
dwr.engine._execute(dwr.engine._pathToDwrServlet, '__System', 'pageLoaded', function() {
dwr.engine._ordered = false;
});
dwr.engine.setNotifyServerOnPageUnload(true);
window.ignoreNextOnBeforeUnload = false;
}
function suppressProcessingMsg() {
window.ignoreNextOnBeforeUnload = true;
return true;
}
function displayProcessingMsg() {
if(!window.ignoreNextOnBeforeUnload) {
ct = $("content");
if(ct) {ct.hide();}
showLoadingDiv();
}
window.ignoreNextOnBeforeUnload = false;
}
function showLoadingDiv() {
var loadDiv = $("loading");
if (loadDiv) {
if(IsIE()) {
loadDiv.style.width = "100%";
loadDiv.style.height= "100%";
loadDiv.style.top="0px";
}
loadDiv.show();
}
return true;
}
window.onbeforeunload = displayProcessingMsg;
function defaultErrorHandler(errorString, exception) {
if (exception && exception.error) {
debugPrint("exception: "+exception.error.text);
$("loading").hide();
Messages.showMessage(exception.error);
}
else {
debugPrint("error: "+errorString);
}
if (errorString.indexOf("No bean specified")!=-1 || errorString.indexOf("Cannot find previously created bean")!=-1) {
window.refresh();
}
}
function defaultWarningHandler(errorString, exception) {
debugPrint("warning: "+errorString);
if (exception) debugPrint("exception: "+exception.message);
}
function defaultExceptionHandler(errorString, exception) {
debugPrint(errorString + ", exception="+exception);
}
function length(o) { return (o) ? o.length : 0; }
function put(o,i,data) { if (o) {o[i] = data;} }
function get(o,i) { return o ? o[i] : null; }
function push(o,data) { if (o) {o.push(data);} }
function pop(o) { return o ? o.pop() : null; }
function splice(o,i,n) { if (o) {o.splice(i, n ? n : 1);} }
function insert(o,i,data) { if (o) {o.splice(i,0,data);} }
function isBean(o) { if (o) return (typeof o == "string") ? false : true; return false; }
function exists(o) { if (o) return true; else return false; }
function setNestedBeanProperty(target,property,value) {
if (target && property) {
var dotIdx = property.indexOf('.');
if (dotIdx != -1) {
var nested = getNestedBeanProperty(target,property.substr(0,dotIdx));
setNestedBeanProperty(nested,property.substr(dotIdx+1),value);
}
else {
var bracketIdx = property.indexOf('[');
if (bracketIdx != -1) {
var nested = target[property.substr(0,bracketIdx)];
var closeBracketIdx = property.indexOf(']');
nested[parseInt(property.substr(bracketIdx+1,closeBracketIdx))] = value;
}
else {
target[property] = value;
}
}
}
}
function getNestedBeanProperty(source,property) {
if (source && property) {
var dotIdx = property.indexOf('.');
if (dotIdx != -1) {
var nested = getNestedBeanProperty(source,property.substr(0,dotIdx));
return getNestedBeanProperty(nested,property.substr(dotIdx+1));
}
else {
var bracketIdx = property.indexOf('[');
if (bracketIdx != -1) {
var nested = source[property.substr(0,bracketIdx)];
var closeBracketIdx = property.indexOf(']');
return nested[parseInt(property.substr(bracketIdx+1,closeBracketIdx))];
}
else {
return source[property];
}
}
}
return null;
}
function printDate(d,f) { return d ? d.print(f) : ""; }
function getElementPosition(obj) {
var useWindow=false;
var coordinates=new Object();
var x=0,y=0;
var use_gebi=false, use_css=false, use_layers=false;
if (document.getElementById) { use_gebi=true; }
else if (document.all) { use_css=true; }
else if (document.layers) { use_layers=true; }
if (use_layers) {
x=el.x;
y=el.y;
}
else
{
var el = obj;
var ol=el.offsetLeft;
while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
x = ol
el = obj;
var ot=el.offsetTop;
while((el=el.offsetParent) != null) { ot += el.offsetTop; }
y = ot;
}
coordinates.x=x;
coordinates.y=y;
return coordinates;
}
function getElementWindowPosition(el) {
var coordinates=getElementPosition(el);
var x=0;
var y=0;
if (document.getElementById) {
if (isNaN(window.screenX)) {
x=coordinates.x-document.body.scrollLeft+window.screenLeft;
y=coordinates.y-document.body.scrollTop+window.screenTop;
}
else {
x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
}
}
else if (document.all) {
x=coordinates.x-document.body.scrollLeft+window.screenLeft;
y=coordinates.y-document.body.scrollTop+window.screenTop;
}
else if (document.layers) {
x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
}
coordinates.x=x;
coordinates.y=y;
return coordinates;
}
function hasModalWindow() {
if (typeof window.showModalDialog != 'undefined') { return true; }
return false;
}
var dFeatures = 'dialogHeight: 450px; dialogWidth: 1049px; dialogTop: 646px; dialogLeft: 4px; edge: Raised; center: Yes; help: Yes; resizable: Yes; status: Yes;';
var modalWin = null;
var prevOnFocus = null;
var dHandler = function() {};
function xShowModalDialog( sURL, vArguments, sFeatures, sHandler ) {
if (sURL==null || sURL=='') {
alert("Invalid URL input.");
return false;
}
if (vArguments==null||vArguments=='') {
vArguments = '';
}
if (sFeatures==null||sFeatures=='') {
sFeatures = dFeatures;
}
if (sHandler==null||sHandler=='') {
sHandler = dHandler;
}
if (hasModalWindow()) {
var ret = window.showModalDialog ( sURL, vArguments, sFeatures );
sHandler(ret);
return false;
}
sFeatures = sFeatures.replace(/ /gi,'');
var aFeatures = sFeatures.split(";");
var sWinFeat = "directories=0,menubar=0,titlebar=0,toolbar=0,";
for ( var i=0; i< aFeatures.length;i++ ) {
if (!aFeatures[i]) continue;
var aTmp = aFeatures[i].split(":");
var sKey = aTmp[0].toLowerCase();
var sVal = aTmp[1];
switch (sKey) {
case "dialogheight":
sWinFeat += "height="+sVal+",";
pHeight = sVal;
break;
case "dialogwidth":
sWinFeat += "width="+sVal+",";
pWidth = sVal;
break;
case "dialogtop":
sWinFeat += "screenY="+sVal+",";
break;
case "dialogleft":
sWinFeat += "screenX="+sVal+",";
break;
case "resizable":
sWinFeat += "resizable="+sVal+",";
break;
case "status":
sWinFeat += "status="+sVal+",";
break;
case "center":
if ( sVal.toLowerCase() == "yes" ) {
sWinFeat += "screenY="+((screen.availHeight-pHeight)/2)+",";
sWinFeat += "screenX="+((screen.availWidth-pWidth)/2)+",";
}
break;
}
}
modalWin=window.open(String(sURL),"",sWinFeat);
if (modalWin.opener == null) {
modalWin.opener = self;
}
if (vArguments!=null&&vArguments!='') {
modalWin.dialogArguments=vArguments;
}
prevOnFocus = window.onfocus;
window.onfocus=function() {
window.checkFocus(sHandler);
};
PopupManager.registerWin(modalWin);
modalWin.focus();
return true;
}
function checkFocus(handler) {
if (window.navigator.appVersion.indexOf("MSIE")==-1) {
if (modalWin!=null && !modalWin.closed) {
self.blur();
modalWin.focus();
}
else if (modalWin!=null && modalWin.closed) {
debugPrint("deregister modalWindow");
PopupManager.deregisterWin(modalWin);
debugPrint("restore onfocus");
modalWin = null;
window.onfocus = prevOnFocus;
prevOnFocus = null;
debugPrint("execute handler");
handler(self.returnValue);
}
}
}
function delayedWindowFocus(delay) {
debugPrint("delayedWindowFocus: "+delay);
window.setTimeout("self.focus();",delay);
}
var Iterator = Class.create();
Object.extend(Iterator.prototype,{
pos: -1,
data: [],
initialize: function() {
this.data = [];
},
hasNext: function() {
if ((this.pos+1)<this.data.length) {
return true;
}
return false;
},
next: function() {
if (this.hasNext()) {
this.pos++;
return this.data[this.pos];
}
return null;
}
});
function iterator(bean) {
var iter = new Iterator();
iter.data = $H(bean).keys();
return iter;
}
escapeJSONChar =
function escapeJSONChar(c)
{
if(c == "\"" || c == "\\") return "\\" + c;
else if (c == "\b") return "\\b";
else if (c == "\f") return "\\f";
else if (c == "\n") return "\\n";
else if (c == "\r") return "\\r";
else if (c == "\t") return "\\t";
var hex = c.charCodeAt(0).toString(16);
if(hex.length == 1) return "\\u000" + hex;
else if(hex.length == 2) return "\\u00" + hex;
else if(hex.length == 3) return "\\u0" + hex;
else return "\\u" + hex;
};
escapeJSONString =
function escapeJSONString(s)
{
var parts = s.split("");
for(var i=0; i < parts.length; i++) {
var c =parts[i];
if(c == '"' || c == '\\' ||
c.charCodeAt(0) < 32 ||
c.charCodeAt(0) >= 128)
parts[i] = escapeJSONChar(parts[i]);
}
return "\"" + parts.join("") + "\"";
};
/*
toJSON = function toJSON(o)
{
if(o == null) {
return "null";
} else if(o.constructor == String) {
return escapeJSONString(o);
} else if(o.constructor == Number) {
return o.toString();
} else if(o.constructor == Boolean) {
return o.toString();
} else if(o.constructor == Date) {
return '{javaClass: "java.util.Date", time: ' + o.valueOf() +'}';
} else if(o.constructor == Array) {
var v = [];
for(var i = 0; i < o.length; i++) v.push(toJSON(o[i]));
return "[" + v.join(", ") + "]";
} else {
var v = [];
for(attr in o) {
if(o[attr] == null) v.push("\"" + attr + "\": null");
else if(typeof o[attr] == "function");  /*
else v.push(escapeJSONString(attr) + ": " + toJSON(o[attr]));
}
return "{" + v.join(", ") + "}";
}
};
*/
toJSON = Object.toJSON;
var Logger = Class.create();
Object.extend(Logger.prototype,{
view: null,
initialize: function() {},
init: function() {
var log = elem('div',{},{
overflow: 'scroll', overflowX: 'hidden', position: 'absolute', bottom: '0px',height: '13.2em', width: '39.6em', right: '0px',
float: 'left', left: '0em',  padding: '.1em', top: '1.5em', border: '2px solid gray', backgroundColor: 'white'
});
this.view = log;
},
show: function() {
if(!this.view) this.init();
var logWin = elem('div',
{ id: '__debugLogWindow__', innerHTML: '<img src="images/iconInformation.gif"  style="padding-right: .5em"/>JavaScript console<img src="images/clean.gif"  style="position: absolute; top: 0px; right: 0px; padding: 2px; cursor: pointer;" onclick="mvc.logger.clear();"/>' },
{ position: 'absolute', width : '40em ', height: '15em', zIndex: '100', paddingTop: '2px', bottom: '0px', right: '0px', verticalAlign: 'top', border: '1px solid black', backgroundColor: '#D0D0D0' }
);
$("core").appendChild(logWin);
logWin.appendChild(this.view);
},
print: function(txt) {
if(this.view) {
dv = this.view;
var old = dv.innerHTML;
var maxLen = this.maxTextLength;
if(!maxLen) {maxLen = 10000;}
if(old.length>maxLen) {
old = old.substr(old.length-maxLen,old.length);
}
var oldD = dv.oldD;
var T = 0;
var D = new Date();
if(oldD) {T = D.getTime() - oldD.getTime();}
dv.oldD = D;
dv.innerHTML = old + T + ' '+txt + '<br/>';
dv.scrollTop = dv.scrollHeight - dv.clientHeight;
}
},
clear: function() {
this.view.innerHTML = '';
}
});
function hideOrClose(w) {
if (w.close) w.close();
else if (w.hide) w.hide();
}
var EventDelegation = {
delegate : function(eventName, options) {
var element = $(this);
element.observe(eventName, function (_delegatedEvent) {
if (typeof options == "function") {
return options(_delegatedEvent);
}
else {
if (options.selector) {
var origin = _delegatedEvent.element();
if ( origin.match(options.selector) ){ return options.handler(_delegatedEvent); }
}
else {
return options.handler(_delegatedEvent);
}
}
});
return element;
}
};
Element.addMethods({
delegate: EventDelegation.delegate
});
Object.extend(document, {
delegate: EventDelegation.delegate
});
var EventManager = {
events: [],
running: false,
reset: function() {
debugPrint("events: reset()");
this.events = [];
this.running = false;
},
handleEvent: function(m, o, a) {
debugPrint("events: handle: "+m.toString());
return this.invokeEvent.bind(this, m, o, a);
},
invokeEvent: function(m, o, a) {
if (this.running) {
debugPrint("events: push: "+m.toString());
this.events.push({_method: m, _object: o, _args: a});
}
else {
this.running = true;
debugPrint("events: invoke: "+m.toString());
this.events.push({_method: m, _object: o, _args: a});
setTimeout("EventManager.processEvents();", 50);
}
},
popEvent: function() {
if (this.events.length > 0) {
var e = this.events.pop();
debugPrint("events: pop: "+e._method.toString());
e._method.apply(e._object, e._args);
this.popEvent();
}
else {
this.reset();
}
},
processEvents: function() {
debugPrint("events: process()");
this.popEvent();
}
};
var mvc = {
debug: false,
firebug: false,
logger: null,
kph: null,
setDebug: function(val) {
mvc.debug = val;
},
enableFirebug: function() {
mvc.firebug = true;
},
disableFirebug: function() {
mvc.firebug = false;
},
initLogger: function() {
mvc.logger = new Logger();
try {
mvc.logger.show();
}
catch(e) {}
},
initKPH: function() {
mvc.kph = new KPH();
mvc.kph.enable();
}
};
//////////////////////// KPH ////////////////////////////////
var KPH = Class.create();
Object.extend(KPH,{
SHIFT_FLAG:           0x1000,
CTRL_FLAG:            0x2000,
ALT_FLAG:             0x4000,
BACKSPACE_KEYCODE:    0x08,
TAB_KEYCODE:          0x09,
ENTER_KEYCODE:        0x0D,
ESC_KEYCODE:          0x1B,
PAGE_UP_KEYCODE:      0x21,
PAGE_DOWN_KEYCODE:    0x22,
END_KEYCODE:          0x23,
HOME_KEYCODE:         0x24,
LEFT_ARROW_KEYCODE:   0x25,
UP_ARROW_KEYCODE:     0x26,
RIGHT_ARROW_KEYCODE:  0x27,
DOWN_ARROW_KEYCODE:   0x28,
INS_KEYCODE:          0x2D,
DEL_KEYCODE:          0x2E,
A_KEYCODE:            0x41,
B_KEYCODE:            0x42,
C_KEYCODE:            0x43,
D_KEYCODE:            0x44,
E_KEYCODE:            0x45,
F_KEYCODE:            0x46,
G_KEYCODE:            0x47,
H_KEYCODE:            0x48,
I_KEYCODE:            0x49,
J_KEYCODE:            0x4A,
K_KEYCODE:            0x4B,
L_KEYCODE:            0x4C,
M_KEYCODE:            0x4D,
N_KEYCODE:            0x4E,
O_KEYCODE:            0x4F,
P_KEYCODE:            0x50,
Q_KEYCODE:            0x51,
R_KEYCODE:            0x52,
S_KEYCODE:            0x53,
T_KEYCODE:            0x54,
U_KEYCODE:            0x55,
V_KEYCODE:            0x56,
W_KEYCODE:            0x57,
X_KEYCODE:            0x58,
Y_KEYCODE:            0x59,
Z_KEYCODE:            0x5A,
F1_KEYCODE:           0x70,
F2_KEYCODE:           0x71,
F3_KEYCODE:           0x72,
F4_KEYCODE:           0x73,
F5_KEYCODE:           0x74,
F6_KEYCODE:           0x75,
F7_KEYCODE:           0x76,
F8_KEYCODE:           0x77,
F9_KEYCODE:           0x78,
F10_KEYCODE:          0x79,
F11_KEYCODE:          0x7A,
F12_KEYCODE:          0x7B
});
Object.extend(KPH.prototype,{
keymap: [],
keydownmap: [],
keyState: [],
keyMapStack: [],
initialize: function() {},
processKeyDown: function(evt) {
evt = evt ? evt : event;
var code = getKeyCodeWithModifiers(evt);
this.keyState[evt.keyCode] = true;
var action = resolveAction(code,this.keydownmap);
if (action) {
this.processAction(action);
evt.cancelBubble = true;
if(IsIE()) { evt.keyCode=0; }
evt.returnValue = false;
return false;
}
if (resolveAction(code,this.keymap)!=null) {
evt.cancelBubble = true;
if(IsIE()) { evt.keyCode=0; }
evt.returnValue = false;
return false;
}
},
processKeyUp: function(evt) {
evt = evt ? evt : event;
var code = getKeyCodeWithModifiers(evt);
if(this.keyState[evt.keyCode]) {
this.keyState[evt.keyCode] = false;
var processed = false;
if (!processed) processed = this.processAscii(evt);
if (!processed) {
var action = resolveAction(code,this.keymap);
if(action) {
processed = this.processAction(action);
}
}
}
},
processKeyPress: function(evt) {
evt = evt ? evt : event;
var code = getKeyCodeWithModifiers(evt);
var action = resolveAction(code,this.keydownmap);
if (action) {
return true;
}
return true;
},
processAction: function(action) {
if (action) {
return action.execute();
}
return false;
},
enable: function () {
document.onkeydown = this.processKeyDown.bind(this);
document.onkeyup = this.processKeyUp.bind(this);
document.onkeypress = this.processKeyPress.bind(this);
},
disable: function () {
document.onkeydown = null;
document.onkeyup = null;
document.onkeypress = null;
},
onKey: function (keyCode,actionInfo,down) {
debugPrint("onKey: "+keyCode);
var action = typeof actionInfo == "object" ? actionInfo : new keyAction(actionInfo);
if (down) {
debugPrint("registerKeyDown: "+keyCode);
this.keydownmap[keyCode] = action;
this.keymap[keyCode] = new keyAction(function(){return false;});
}
else {
debugPrint("registerKey: "+keyCode);
this.keymap[keyCode] = action;
}
},
push: function() {
this.keyMapStack.push(this.keymap);
this.keyMapStack.push(this.keydownmap);
this.keymap = [];
this.keydownmap = [];
},
pop: function() {
this.keydownmap = this.keyMapStack.pop();
this.keymap = this.keyMapStack.pop();
},
processAscii: function() { return false; }
});
function getKeyCodeWithModifiers(evt)
{
var code = evt.keyCode;
if (evt.shiftKey) { code = code | KPH.SHIFT_FLAG; }
if (evt.ctrlKey) { code = code | KPH.CTRL_FLAG; }
if (evt.altKey) { code = code | KPH.ALT_FLAG; }
return code;
}
function resolveAction(code,actionmap) {
return actionmap[code];
}
function keyAction(actionInfo) {
this.info = actionInfo;
if (typeof actionInfo == "string") {
this.execute = function() {
executeLink(this.info);
}
}
else if (typeof actionInfo == "function") {
this.execute = actionInfo;
}
return this;
}
function executeLinkElement(link) {
if (link) {
debugPrint("executeLink: "+toJSON(link));
if (link.href == "#") { link.onclick(); }
else {
if (link.onclick) {
if (link.onclick()) {
window.location = link.href;
}
}
else {
window.location = link.href;
}
}
return true;
}
return false;
}
function executeLink(linkId) {
var link = document.getElementById(linkId);
return executeLinkElement(link)
}
function downloadLink(name,url) {
var iframe = $("download-iframe");
if (!iframe) {
iframe = elem("iframe", {id: "download-iframe", name: "download-iframe", src: "javascript:void(0)"});
iframe.hide();
$("content").appendChild(iframe);
}
var iframeDoc;
if (iframe.contentDocument) {
iframeDoc = iframe.contentDocument;
}
else if (iframe.contentWindow) {
iframeDoc = iframe.contentWindow.document;
}
else if (window.frames[iframe.name]) {
iframeDoc = window.frames[iframe.name].document;
}
if (iframeDoc) {
iframeDoc.open();
iframeDoc.write('<html><head>');
iframeDoc.write('<meta http-equiv="Cache-Control" content="no-store"\/>');
iframeDoc.write('<meta http-equiv="Pragma" content="no-cache"\/>');
iframeDoc.write('<meta http-equiv="Expires" content="0"\/>');
iframeDoc.write('<meta http-equiv="Content-Disposition" content="attachment: filename='+name+'"\/>');
iframeDoc.write('<\/head><body><\/body><\/html>');
iframeDoc.close();
}
}


