
function $I(id){
Claim.isString(id,"$I.id");
var element=$(id);
Claim.isObject(element,"Required HTML element id: "+id);
return element;}
function $F(id){
Claim.isString(id,"$F.id")
Claim.isObject($(id),"Required form element id: "+id)
return Form.Element.getValue(id)}
function $T(tagName){
var element=document.getElementsByTagName(tagName).item(0)
Claim.isObject(element,"Required HTML element tag: "+tagName)
return element}
function $SO(id){
return $I(id).options[$I(id).selectedIndex]}
Number.prototype.toText=function(base,width){
Claim.isNumber(base,"Number.toText.base")
Claim.isTrue(base>0,"Number.toText.base")
Claim.isNumber(width,"Number.toText.width")
Claim.isTrue(width>=0,"Number.toText.width")
var text=this.toString(base||10)+""
while(text.length<width)
text="0"+text
return text}
Number.prototype.toDec=function(width){
Claim.isNumber(width,"Number.toText.width")
Claim.isTrue(width>=0,"Number.toText.width")
return this.toText(10,width)}
Number.prototype.toHex=function(width){
Claim.isNumber(width,"width","Number.toText.width")
Claim.isTrue(width>=0,"width","Number.toText.width")
return this.toText(16,width)}
Date.prototype.toText=function(){
var year=this.getUTCFullYear().toDec(4)
var month=this.getUTCMonth().toDec(2)
var day=this.getUTCDate().toDec(2)
var hours=this.getUTCHours().toDec(2)
var minutes=this.getUTCMinutes().toDec(2)
var seconds=this.getUTCSeconds().toDec(2)
var milliseconds=this.getUTCMilliseconds().toDec(3)
return year+"-"+month+"-"+day+" "+hours+":"+minutes+":"+seconds+"."+milliseconds}
var PreLoad={}
PreLoad.preLoad=function(){
PreLoad.log=new Log4Js.Logger("PreLoad")}
PreLoad.onLoad=function(){
PreLoad.log.debug("Done pre-load")}
PreLoad.actions=[]
PreLoad.actions.push(PreLoad.preLoad)
Event.observe(window,"load",PreLoad.onLoad)
var Url={}
Url.parse=function(url){
Claim.isString(url,"Url.parse.url")
var parsed={}
parsed.full=url
parsed.base=url.replace(/\?.*$/,'')
parsed.protocol=url.replace(/:.*$/,'')
parsed.domain=
parsed.base.replace(/^[^:]*:\/[\/]/,'').replace(/[:\/].*$/,'')
parsed.path=parsed.base.replace(/^[^\/]*\/\/[^\/]*[\/]/,'/')
parsed.query=url.replace(/^[^?]*\??/,'')
parsed.params=
parsed.query.split("&").inject({},function(params,paramValue){
pair=paramValue.split("=")
params[pair[0]]=unescape(pair[1])
return params})
return parsed}
Url.trimAnchor=function(url){
var i=url.lastIndexOf("#");
var isHasSharpMark=i>-1
var isHasQMark=url.lastIndexOf("?")>-1
if(isHasSharpMark&&((isHasQMark&&i>url.lastIndexOf("="))||!isHasQMark)){
url=url.substr(0,i);}
return url;}
Url.appendParams=function(url,params){
Claim.isString(url,"Url.appendParams.url")
if(!params||params=="")
return url
if(typeof(params)=="string")
return url+(url.match(/\?/)?"&":"?")+params
return $A($H(params).keys().sort()).inject(url,function(url,param){
return Url.appendParamValue(url,param,params[param])})}
Url.appendParamValue=function(url,param,value){
Claim.isString(url,"Url.appendParamValue.url")
Claim.isString(param,"Url.appendParamValue.param")
Claim.isScalar(value,"Url.appendParamValue.value")
return url+(url.match(/\?/)?"&":"?")+escape(param)+"="+escape(value)}
Url.relativeUrl=function(options){
Claim.isObject(options,"Url.relativeUrl.options")
var protocol=options.protocol||Url.here.protocol
Claim.isString(protocol,"Url.relativeUrl.options.protocol")
var domain=options.domain||Url.here.domain
Claim.isString(domain,"Url.relativeUrl.options.domain")
var path=options.path||Url.here.path
Claim.isString(path,"Url.relativeUrl.options.path")
if(!path.match(/^[\/]/)){
var base=Url.here.path
path="../"+path
while(path.match(/^\.\.[\/]/)){
path=path.replace(/^\.\.[\/]/,"")
base=base.replace(/\/[^\/]+$/,"")}
path=base+"/"+path}
var params={}
var withHereParams=options.withHereParams||false
Claim.isBoolean(withHereParams,
"Url.relativeUrl.options.withHereParams")
if(withHereParams)
Object.extend(params,Url.here.params)
var withClearanceParams=options.withClearanceParams
if(withClearanceParams==undefined)
withClearanceParams=domain!=Url.here.domain
Claim.isBoolean(withClearanceParams,
"Url.relativeUrl.options.withClearanceParams")
if(withClearanceParams)
Object.extend(params,Clearance.params)
var optionsParams=options.params||{}
Claim.isObject(optionsParams,"Url.relativeUrl.options.params")
Object.extend(params,options.params||{})
return Url.appendParams(protocol+":/"+"/"+domain+path,params)}
Url.here=undefined
Url.preLoad=function(){
Url.here=Url.parse(location.href)}
PreLoad.actions.push(Url.preLoad)
var Claim={}
Claim.check=function(condition,claim,comment){
if(!comment)
comment=claim
else
comment=claim+": "+comment
var log=Claim.log
Claim.log=undefined
try{
if(condition){
if(log)
log.debug(comment)}
else{
if(log)
log.error(comment)
else
alert(comment)
throw new Error(comment)}}
finally{
Claim.log=log}}
Claim.valueType=function(object){
if(object==undefined)
return "undefined"
if(object==null)
return "null"
return typeof(object)+"("+object+")"}
Claim.isTrue=function(condition,comment){
Claim.check(condition,
"isTrue("+Claim.valueType(condition)+")",
comment)}
Claim.isFalse=function(condition,comment){
Claim.check(!condition,
"isFalse("+Claim.valueType(condition)+")",
comment)}
Claim.isNull=function(object,comment){
Claim.check(typeof(object)==null,
"isNull("+Claim.valueType(object)+")",
comment)}
Claim.isNotNull=function(object,comment){
Claim.check(typeof(object)!=null,
"isNotNull("+Claim.valueType(object)+")",
comment)}
Claim.isUndefined=function(object,comment){
Claim.check(typeof(object)==undefined,
"isUndefined("+Claim.valueType(object)+")",
comment)}
Claim.isNotUndefined=function(object,comment){
Claim.check(typeof(object)!=undefined,
"isNotUndefined("+Claim.valueType(object)+")",
comment)}
Claim.isObject=function(object,comment){
Claim.check(!!object,
"isObject("+Claim.valueType(object)+")",
comment)}
Claim.isNumber=function(object,comment){
Claim.check(typeof(object)=="number",
"isNumber("+Claim.valueType(object)+")",
comment)}
Claim.isBoolean=function(object,comment){
Claim.check(typeof(object)=="boolean",
"isBoolean("+Claim.valueType(object)+")",
comment)}
Claim.isString=function(object,comment){
Claim.check(typeof(object)=="string",
"isString("+Claim.valueType(object)+")",
comment)}
Claim.isScalar=function(object,comment){
Claim.check(typeof(object)=="string"||typeof(object)=="number"||typeof(object)=="boolean",
"isScalar("+Claim.valueType(object)+")",
comment)}
Claim.isArray=function(object,comment){
Claim.check(object&&object.length!=undefined,
"isArray("+Claim.valueType(object)+")",
comment)}
Claim.areEqual=function(object1,object2,comment){
Claim.check(object1==object2,
"areEqual("+Claim.valueType(object1)+" ? "+Claim.valueType(object2)+")",
comment)}
Claim.isFunction=function(object,comment){
Claim.check(typeof(object)=='function',
"isFunction("+Claim.valueType(object)+")",
comment)}
Claim.preLoad=function(){
Claim.log=new Log4Js.Logger("Claim")}
PreLoad.actions.push(Claim.preLoad)
var Cookies={}
Cookies.defaultOptions={}
Cookies.rawByName={}
Cookies.valueByName={}
Cookies.set=function(name,value,options){
Claim.isString(name,"Cookies.set.name")
Claim.isObject(value,"Cookies.set.value")
var fullOptions=Cookies.fullOptions(name,options)
var raw=Cookies.toJson(value)
Cookies.valueByName[name]=value
Cookies.rawByName[name]=raw
var cookie=Cookies.fullCookie(name,raw,fullOptions)
Cookies.log.info("Set cookie: "+cookie)
document.cookie=cookie}
Cookies.get=function(name){
Claim.isString(name,"Cookies.get.name")
return Cookies.valueByName[name]}
Cookies.clear=function(name,options){
Claim.isString(name,"Cookies.clear.name")
var fullOptions=Cookies.fullOptions(name,options)
fullOptions.expires=Cookies.expiration(-1)
var cookie=Cookies.fullCookie(name,"",fullOptions)
delete(Cookies.rawByName[name])
delete(Cookies.valueByName[name])
Cookies.log.info("Clear cookie: "+cookie)
document.cookie=cookie}
Cookies.fullOptions=function(name,options){
Claim.isString(name,"Cookies.fullOptions.name")
var fullOptions=Object.extend({},Cookies.defaultOptions)
fullOptions=Object.extend(fullOptions,options||{})
if(!fullOptions.path){
var error="Set cookie name: "+name+" without a path"
Cookies.log.error(error)
throw error}
if(fullOptions.path.charAt(0)!="/"){
var error="Set cookie name: "+name+" invalid path: "+fullOptions.path
Cookies.log.error(error)
throw error}
if(!fullOptions.domain){
var error="Set cookie name: "+name+" without a domain"
Cookies.log.error(error)
throw error}
if(fullOptions.domain.charAt(0)!="."){
var error="Set cookie name: "+name+" invalid domain: "+fullOptions.domain
Cookies.log.error(error)
throw error}
return fullOptions}
Cookies.expiration=function(millis){
Claim.isNumber(millis,"Cookies.expiration.millis")
var today=new Date()
var now=Date.parse(today)
today.setTime(now+1*millis)
return today.toUTCString()}
Cookies.fullCookie=function(name,raw,options){
Claim.isString(name,"Cookies.fullCookie.name")
var cookie=name+"="+raw
$H(options).each(function(pair){
if(pair[1]!=undefined)
cookie+=";"+pair[0]+"="+pair[1]})
return cookie}
Cookies.toJson=function(object){
if(object==undefined)
return "undefined"
if(object==null)
return "null"
if(typeof(object)=="string")
return "\"" + Cookies.jsonEscape(object.toString()) + "\""
if(typeof(object)=="number"||typeof(object)=="boolean")
return object.toString()
if(object.toJson)
return object.toJson()
var json=""
var seperator=""
if(typeof object=='object'&&object.constructor.toString().match(/array/i)!=null){
$A(object).each(function(value){
json+=seperator+Cookies.toJson(value)
seperator=","})
return "["+json+"]"}
else{
var json=""
$H(object).each(function(pair){
json+=seperator+Cookies.toJson(pair[0])+":"+Cookies.toJson(pair[1])
seperator=","})
return "{"+json+"}"}}
Cookies.jsonEscape=function(text){
Claim.isString(text,"Claim.jsonEscape.text")
var escaped=""
for(var i=0;i<text.length;i++){
var code=text.charCodeAt(i)
if(code<32||code==59){
escaped+="\\u"+code.toHex(4)}
else{
var nextChar=text.charAt(i)
if(nextChar=="\"" || nextChar == "\\")
escaped+="\\"
escaped+=nextChar}}
return escaped}
Cookies.preLoad=function(){
Cookies.log=new Log4Js.Logger("Cookies")
Cookies.defaultOptions.path="/"
Cookies.defaultOptions.domain=
"."+Url.here.domain.replace(/^[a-zA-Z0-9\-]+./,'')
document.cookie.split(';').each(function(cookie){
if(!cookie){
if(Cookies.rawByName!=undefined){
Cookies.rawByName={};
Cookies.valueByName={};}
throw $break}
var name=cookie.replace(/^\s*([^=]+)=.*$/,'$1')
var raw=cookie.replace(/^[^=]*=/,'')
Cookies.rawByName[name]=raw
Cookies.log.info("Load cookie name: "+name+" value: "+raw)
try{
var value=undefined
eval("value="+raw)
Cookies.valueByName[name]=value}
catch(error){
Cookies.log.error("Invalid cookie name: "+name+" value: "+value+" error: "+error)
Cookies.valueByName[name]=null}})}
Cookies.pop=function(){
var each,s=[];
for(each in this.rawByName){
s[s.length]=each
s[s.length]=":"
s[s.length]=this.rawByName[each]
s[s.length]="\n"}
alert(unescape(s.join("")));}
PreLoad.actions.push(Cookies.preLoad)
var Log4Js={}
Log4Js.levelNames=["All","Debug","Info","Warn","Error","Fatal","None"]
Log4Js.ALL=0
Log4Js.DEBUG=1
Log4Js.INFO=2
Log4Js.WARN=3
Log4Js.ERROR=4
Log4Js.FATAL=5
Log4Js.NONE=6
Log4Js.configVersion=0
Log4Js.targetsByName={"*":[]}
Log4Js.setTargets=function(name,targets){
Claim.isString(name,"Log4Js.setTargets.name")
Claim.isArray(targets,"Log4Js.setTargets.targets")
Log4Js.targetsByName[name]=targets
Log4Js.configVersion++}
Log4Js.removeTargets=function(name){
Claim.isString(name,"Log4Js.removeTargets.name")
if(name=="*")
Log4Js.targetsByName[name]=[]
else
delete(Log4Js.targetsByName[name])
Log4Js.configVersion++}
Log4Js.getTargets=function(name){
Claim.isString(name,"Log4Js.getTargets.name")
return Log4Js.targetsByName[name]}
Log4Js.findPrefix=function(name){
Claim.isString(name,"Log4Js.findPrefix.name")
while(true){
if(name=="")
name="*"
var targets=Log4Js.targetsByName[name]
if(targets)
return name
var lastDot=name.lastIndexOf(".")
name=lastDot>0?name.substring(0,lastDot):""}}
Log4Js.findTargets=function(name){
Claim.isString(name,"Log4Js.findTargets.name")
return this.getTargets(this.findPrefix(name))}
Log4Js.toConfig=function(){
var anchorsByName={}
var targetAnchorByJson={}
var targetByAnchor={}
var nextAnchor=1
$H(Log4Js.targetsByName).each(function(pair){
var name=pair[0]
var targets=pair[1]
anchorsByName[name]=targets.inject([],function(anchors,target){
var json=target.toJson()
var anchor=targetAnchorByJson[json]
if(!anchor){
anchor=targetAnchorByJson[json]="t"+nextAnchor++
targetByAnchor[anchor]=target}
anchors.push(anchor)
return anchors})})
return{targetByAnchor:targetByAnchor,anchorsByName:anchorsByName}}
Log4Js.fromConfig=function(config){
Claim.isObject(config,"Log4Js.fromConfig.config")
Claim.isObject(config.anchorsByName,
"Log4Js.fromConfig.config.anchorsByName")
Claim.isObject(config.targetByAnchor,
"Log4Js.fromConfig.config.targetByAnchor")
var targetsByName=
$H(config.anchorsByName).inject({},function(targetsByName,pair){
var name=pair[0]
var anchors=pair[1]
targetsByName[name]=
$A(anchors).inject([],function(targets,anchor){
targets.push(config.targetByAnchor[anchor])
return targets})
return targetsByName})
Log4Js.targetsByName=targetsByName
Log4Js.configVersion++}
Log4Js.pop=function(conf){
if(!conf||typeof(conf)!='object'){
conf={anchorsByName:{"*":["t1"],Claim:["t2"]},targetByAnchor:{t1:new Log4Js.PopupTarget(Log4Js.ALL,"log4js-%U-%T",true),t2:new Log4Js.PopupTarget(Log4Js.FATAL,"log4js-%U-%T",true)}};}
Cookies.set("log4js.config",conf,{});
this.fromConfig(conf);}
Log4Js.add=function(sClassName,enLEVEL){
Claim.isString(sClassName,"Log4Js.add(sClassName, enLEVEL) - sClassName must be a string");
Claim.isString(enLEVEL,"Log4Js.add(sClassName, enLEVEL) - enLEVEL must Log Level ALL, DEBUG, WARN, ...");
var iLevel=this[enLEVEL.toUpperCase()];
Claim.isNumber(iLevel,"Log4Js.add(sClassName, enLEVEL) - Log4Js."+enLEVEL+" is not a valid warn-level");
Claim.check(iLevel>=0&&iLevel<=6,"0 <= iLevel <= 6","Log4Js.add(sClassName, enLEVEL) - Log4Js[enLEVEL must be between 0 to 6");
var conf=this.toConfig();
conf.targetByAnchor.newAnchor=new Log4Js.PopupTarget(iLevel,"log4js-%U-%T",true)
conf.anchorsByName[sClassName]=["newAnchor"];
this.pop(conf);}
Log4Js.clear=function(sClassName){
Claim.isString(sClassName,"Log4Js.clear(sClassName) - sClassName must be a string");
var conf=this.toConfig();
delete conf.anchorsByName[sClassName];
this.pop(conf);}
Log4Js.stop=function(){
var conf={anchorsByName:{"*":["t1"]},targetByAnchor:{t1:new Log4Js.PopupTarget(Log4Js.NONE,"log4js-%U-%T",true)}};
Cookies.set("log4js.config",conf,{});
this.fromConfig(conf);}
Log4Js.preLoad=function(){
var config=Cookies.get("log4js.config")
if(config)
Log4Js.fromConfig(config)
PreLoad.log.debug("Start pre-load")}
PreLoad.actions.push(Log4Js.preLoad)
Log4Js.Logger=Class.create()
Log4Js.Logger.prototype={}
Log4Js.Logger.prototype.initialize=function(name){
Claim.isString(name,"Log4Js.Logger.name")
this.name=name
this.configVersion=-1}
Log4Js.Logger.prototype.debug=function(text){
this.emit(Log4Js.DEBUG,text)}
Log4Js.Logger.prototype.info=function(text){
this.emit(Log4Js.INFO,text)}
Log4Js.Logger.prototype.warn=function(text){
this.emit(Log4Js.WARN,text)}
Log4Js.Logger.prototype.error=function(text){
this.emit(Log4Js.ERROR,text)}
Log4Js.Logger.prototype.fatal=function(text){
this.emit(Log4Js.FATAL,text)}
Log4Js.Logger.prototype.emit=function(level,text){
if(this.configVersion<Log4Js.configVersion){
this.targets=Log4Js.findTargets(this.name)
this.configVersion=Log4Js.configVersion}
if(this.targets.length>0){
Claim.isNumber(level,"Log4Js.Logger.emit.level")
Claim.isTrue(Log4Js.DEBUG<=level&&level<=Log4Js.FATAL)
Claim.isScalar(text,"text")
var event={
time:new Date().toText(),
level:level,
name:this.name,
text:text,
url:location.href}
this.targets.each(function(target){target.emit(event)})}}
Log4Js.AbstractTarget=function(){}
Log4Js.AbstractTarget.prototype={}
Log4Js.AbstractTarget.prototype.emit=function(event){
Claim.isObject(event,"Log4Js.AbstractTarget.emit.event")
Claim.isNumber(event.level,"Log4Js.AbstractTarget.emit.event.level")
if(event.level>=this.level)
this._emit(event)}
Log4Js.AlertTarget=Class.create()
Log4Js.AlertTarget.prototype=new Log4Js.AbstractTarget()
Log4Js.AlertTarget.prototype.initialize=function(level){
Claim.isNumber(level,"Log4Js.AlertTarget.level")
Claim.isTrue(Log4Js.ALL<=level&&level<=Log4Js.NONE,
"Log4Js.AlertTarget.level")
this.level=level}
Log4Js.AlertTarget.prototype._emit=function(event){
Claim.isObject(event,"Log4Js.AlertTarget._emit.event")
alert(event.time+" "+event.url+" "+Log4Js.levelNames[event.level]+" "+event.name+":\n"+event.text)}
Log4Js.AlertTarget.prototype.toJson=function(){
return "new Log4Js.AlertTarget(Log4Js."+Log4Js.levelNames[this.level].toUpperCase()+")"}
Log4Js.TableTarget=Class.create()
Log4Js.TableTarget.prototype=new Log4Js.AbstractTarget()
Log4Js.TableTarget.prototype.backLog=[]
Log4Js.TableTarget.prototype.initialize=function(level,table,isLastOnTop){
Claim.isNumber(level,"Log4Js.TableTarget.level")
Claim.isTrue(Log4Js.ALL<=level&&level<=Log4Js.NONE,
"Log4Js.TableTarget.level")
Claim.isObject(table,"Log4Js.TableTarget.table")
Claim.isBoolean(isLastOnTop,"Log4Js.TableTarget.isLastOnTop")
this.level=level
this.isLastOnTop=isLastOnTop
if(typeof(table)=="string"){
this.name=table
this.table=$(table)}
else{
this.name=table.id
this.table=table}}
Log4Js.TableTarget.prototype.initTable=function(event){
Claim.isObject(event,"Log4Js.TableTarget.initTable.event")
this.table=this.table||$(this.name)
if(!this.table)
return false
if(this.table.rows.length>0)
return true
var row=this.table.insertRow(-1)
row.insertCell(-1).innerHTML="Time"
row.insertCell(-1).innerHTML="Level"
row.insertCell(-1).innerHTML="Name"
row.insertCell(-1).innerHTML="Text"
row=this.table.insertRow(-1)
row.insertCell(-1).innerHTML=event.time
row.insertCell(-1).innerHTML="<hr />"
row.insertCell(-1).innerHTML="LOG4JS"
row.insertCell(-1).innerHTML=event.url
row=this.table.insertRow(-1)
row.insertCell(-1).innerHTML=event.time
row.insertCell(-1).innerHTML="<hr />"
row.insertCell(-1).innerHTML="LOG4JS"
row.insertCell(-1).innerHTML=event.url
row=this.table.insertRow(-1)
row.insertCell(-1).innerHTML="Time"
row.insertCell(-1).innerHTML="Level"
row.insertCell(-1).innerHTML="Name"
row.insertCell(-1).innerHTML="Text"
return true}
Log4Js.TableTarget.prototype._emit=function(event){
Claim.isObject(event,"Log4Js.TableTarget._emit.event")
this.backLog.push(event)
if(!this.initTable(event))
return
while(this.backLog.length>0){
var event=this.backLog.shift()
var row=this.table.insertRow(this.isLastOnTop?2:-1)
row.insertCell(-1).innerHTML=event.time
row.insertCell(-1).innerHTML=Log4Js.levelNames[event.level]
row.insertCell(-1).innerHTML=event.name
row.insertCell(-1).innerHTML=event.text}}
Log4Js.TableTarget.prototype.toJson=function(){
return "new Log4Js.TableTarget(Log4Js."+Log4Js.levelNames[this.level].toUpperCase()+","+Cookies.toJson(this.name)+","+Cookies.toJson(this.isLastOnTop)+")"}
Log4Js.PopupTarget=Class.create()
Log4Js.PopupTarget.prototype=new Log4Js.AbstractTarget()
Log4Js.PopupTarget.windows={}
Log4Js.PopupTarget.prototype.initialize=function(level,name,isLastOnTop){
Claim.isNumber(level,"Log4Js.Prototype.level")
Claim.isTrue(Log4Js.ALL<=level&&level<=Log4Js.NONE,
"Log4Js.Prototype.level")
Claim.isString(name,"Log4Js.Prototype.name")
Claim.isBoolean(isLastOnTop,"Log4Js.Prototype.isLastOnTop")
this.name=name
name=name.replace(/%T/,new Date().toText())
name=name.replace(/%U/,location.href)
name=name.replace(/\W+/g,'_')
name=name.replace(/[_]+/g,'_')
this.windowName=name
this.level=level
this.isLastOnTop=isLastOnTop}
Log4Js.PopupTarget.prototype._emit=function(event){
Claim.isObject(event,"Log4Js.Prototype._emit.event")
if(!this.window||!this.window.document){
this.window=Log4Js.PopupTarget.windows[name]
if(!this.window||!this.window.document){
this.window=Log4Js.PopupTarget.windows[name]=
window.open("",this.windowName,
'width=640,height=480,'+'scrollbars=1,status=0,toolbars=0,resizable=1')
if(!this.window||!this.window.document){
alert("A popup window manager is blocking the logger "+"popup display.\n"+"You need to allow popups to see the logged events.")
this.emit=function(event){}
return}
this.window.document.writeln("<table id='log-table'></table>")
this.window.document.close()}
this.table=this.window.document.getElementById("log-table")
this.target=
new Log4Js.TableTarget(this.level,this.table,this.isLastOnTop)}
this.target._emit(event)}
Log4Js.PopupTarget.prototype.toJson=function(){
return "new Log4Js.PopupTarget(Log4Js."+Log4Js.levelNames[this.level].toUpperCase()+","+Cookies.toJson(this.name)+","+Cookies.toJson(this.isLastOnTop)+")"}
var Clearance={}
Clearance.MEMBER=0;
Clearance.GUEST=1;
Clearance.levelNames=["Anonymnous","Unclassified","Restricted","Confidential"]
Clearance.ANONYMOUS=0
Clearance.UNCLASSIFIED=1
Clearance.RESTRICTED=2
Clearance.CONFIDENTIAL=3
Clearance.level=undefined
Clearance.userId=undefined
Clearance.isLevel=function(level){
return Clearance.level==level}
Clearance.hasLevel=function(level){
Claim.isNumber(level,"Clearance.hasLevel.level")
Claim.isTrue(0<=level&&level<=Clearance.CONFIDENTIAL,
"Clearance.hasLevel.level")
if(Clearance.hasLoginType()==true){
return Clearance.level>=level}return false;}
Clearance.requireLevel=function(requiredLevel,loginUrl,urlParam){
Claim.isNumber(requiredLevel,"Clearance.requireLevel.requiredLevel")
var minLevel=Clearance.ANONYMOUS
var maxLevel=Url.here.protocol=="https"?Clearance.CONFIDENTIAL:Clearance.UNCLASSIFIED
Claim.isTrue(minLevel<=requiredLevel&&requiredLevel<=maxLevel,
"Clearance.requireLevel.requiredLevel")
Claim.isString(loginUrl,"Clearance.requireLevel.loginUrl")
Claim.isString(urlParam,"Clearance.requireLevel.urlParam")
Clearance.log.debug("Required: "+requiredLevel+" level: "+Clearance.level)
if(Clearance.level<requiredLevel){
var url=Url.appendParamValue(loginUrl,urlParam,location.href)
Clearance.log.info("Redirect to "+url)
location=url}}
Clearance.isUnclassified=function(){
return Clearance.isLevel(Clearance.UNCLASSIFIED)}
Clearance.hasUnclassified=function(){
return Clearance.hasLevel(Clearance.UNCLASSIFIED)}
Clearance.isGuest=function(){
var currentLoginType=Clearance.loginType();
if(currentLoginType){
if(currentLoginType==Clearance.GUEST)
return true;
return false;}}
Clearance.isMember=function(){
var currentLoginType=Clearance.loginType();
if(currentLoginType){
if(currentLoginType==Clearance.MEMBER)
return true;
return false;}}
Clearance.hasLoginType=function(){
if(Clearance.loginType())
return true;
return false;}
Clearance.loginType=function(){
var unclCookie=
Cookies.get(Clearance.cookieName(Clearance.UNCLASSIFIED,true));
if(unclCookie){
var cookieParams=unclCookie.en.toQueryParams()
if(cookieParams["LT"])
return cookieParams["LT"];}
return null}
Clearance.refresh=function(){
Cookies.preLoad();
Clearance.preLoad();}
Clearance.requireUnclassified=function(loginUrl,param){
Clearance.requireLevel(Clearance.UNCLASSIFIED,loginUrl,param)}
Clearance.isRestricted=function(){
return Clearance.isLevel(Clearance.RESTRICTED)}
Clearance.hasRestricted=function(){
return Clearance.hasLevel(Clearance.RESTRICTED)},
Clearance.requireRestricted=function(loginUrl,param){
Clearance.requireLevel(Clearance.RESTRICTED,loginUrl,param)}
Clearance.isConfidential=function(){
return Clearance.isLevel(Clearance.CONFIDENTIAL)}
Clearance.hasConfidential=function(){
return Clearance.hasLevel(Clearance.CONFIDENTIAL)}
Clearance.requireConfidential=function(loginUrl,param){
Clearance.requireLevel(Clearance.CONFIDENTIAL,loginUrl,param)}
Clearance.getParams=function(level){
Claim.isNumber(level,"Clearance.getEncrypted.level")
Claim.isTrue(level>=Clearance.UNCLASSIFIED&&level<=Clearance.CONFIDENTIAL,
"Clearance.getEncrypted.level")
if(!Clearance.hasLevel(level))
return null
var params={}
params.ui=Clearance.params.ui
params.un=Clearance.params.un
params.ux=Clearance.params.ux
if(level>=Clearance.RESTRICTED){
params.rn=Clearance.params.rn
params.rx=Clearance.params.rx}
if(level>=Clearance.CONFIDENTIAL){
params.cn=Clearance.params.cn
params.cx=Clearance.params.cx}
return params}
Clearance.getMagic=function(level){
params=Clearance.getParams(level)
if(params)
return Url.appendParams("",params)
return null}
Clearance.prefix=["Oberon1.A.","Oberon1.U.","Oberon1.R.","Oberon1.C."],
Clearance.cookieName=function(level,isTimed){
Claim.isNumber(level,"Clearance.cookieName.level")
Claim.isTrue(level>=Clearance.ANONYMOUS&&level<=Clearance.CONFIDENTIAL,
"Clearance.cookieName.level")
Claim.isBoolean(isTimed,"Clearance.cookieName.isTimed")
if(level>Clearance.UNCLASSIFIED)
return Clearance.prefix[level]+(isTimed?"T":"S")
else
return Clearance.prefix[level]}
Clearance.setCookies=function(level,userId,encrypted,expires){
Claim.isNumber(level,"Clearance.setCookies.level")
Claim.isTrue(level>=Clearance.ANONYMOUS&&level<=Clearance.CONFIDENTIAL,
"Clearance.setCookies.level")
if(level!=Clearance.ANONYMOUS)
Claim.isString(userId,"Clearance.setCookies.userId")
Claim.isString(encrypted,"Clearance.setCookies.encrypted")
var value={ui:userId,en:encrypted}
if(expires){
value.ex=Math.round(expires/1000)
var date=new Date()
date.setSeconds(date.getSeconds()+value.ex)
Cookies.set(Clearance.cookieName(level,true),value,{expires:date.toUTCString()})
if(level>Clearance.UNCLASSIFIED){
Cookies.set(Clearance.cookieName(level,false),value,{expires:undefined})}}
else{
Claim.isTrue(level==Clearance.UNCLASSIFIED||level==Clearance.ANONYMOUS,
"Clearance.setCookies.level")
Cookies.set(Clearance.cookieName(level,true),value,{expires:undefined})}}
Clearance.clearCookies=function(level){
Claim.isNumber(level,"Clearance.clearCookies.level")
Claim.isTrue(level>=Clearance.UNCLASSIFIED&&level<=Clearance.CONFIDENTIAL,
"Clearance.clearCookies.level")
Cookies.clear(Clearance.cookieName(level,false),{})
Cookies.clear(Clearance.cookieName(level,true),{})}
Clearance.forget=function(url){
Clearance.log.debug("Forget user")
Clearance.clearCookies(Clearance.UNCLASSIFIED)
Clearance.clearCookies(Clearance.RESTRICTED)
Clearance.clearCookies(Clearance.CONFIDENTIAL)
var url=Url.appendParamValue(url,"ui","none")
Clearance.log.info("Redirect to "+url)
location=url}
Clearance.params={},
Clearance.preLoad=function(){
Clearance.urlParamsToCookies()
Clearance.level=Clearance.ANONYMOUS
Clearance.log.debug("Achieved Anonymnous")
if(Clearance.processCookies(Clearance.UNCLASSIFIED,"un","ux"))
if(Clearance.processCookies(Clearance.RESTRICTED,"rn","rx"))
Clearance.processCookies(Clearance.CONFIDENTIAL,"cn","cx")}
Clearance.urlParamsToCookies=function(){
Clearance.log=new Log4Js.Logger("Clearance")
Clearance.level=Clearance.ANONYMOUS
Clearance.log.debug("Try to access current URL clearance parameters")
if(Url.here.params.an){
Clearance.setCookies(Clearance.ANONYMOUS,
Url.here.params.ui,
Url.here.params.an);}
if(Url.here.params.ui){
if(Url.here.params.un&&Url.here.params.ux)
Clearance.setCookies(Clearance.UNCLASSIFIED,
Url.here.params.ui,
Url.here.params.un,((typeof(Url.here.params.ux)=="number")?(Url.here.params.ux*1000.0):Url.here.params.ux))
else if(Url.here.params.un)
Clearance.setCookies(Clearance.UNCLASSIFIED,
Url.here.params.ui,
Url.here.params.un,
null)
else
Clearance.clearCookies(Clearance.UNCLASSIFIED)

/*
if(Url.here.params.rn&&Url.here.params.rx)
Clearance.setCookies(Clearance.RESTRICTED,
Url.here.params.ui,
Url.here.params.rn,(typeof(Url.here.params.rx)=="number")?(Url.here.params.rx*1000.0):Url.here.params.rx)
else
Clearance.clearCookies(Clearance.RESTRICTED)
if(Url.here.params.cn&&Url.here.params.cx)
Clearance.setCookies(Clearance.CONFIDENTIAL,
Url.here.params.ui,
Url.here.params.cn,(typeof(Url.here.params.cx)=="number"?(Url.here.params.cx*1000.0):Url.here.params.cx))
else
Clearance.clearCookies(Clearance.CONFIDENTIAL)*/

}

Clearance.log.debug("Strip clearance params from URL")
delete(Url.here.params["ui"])
delete(Url.here.params["un"])
delete(Url.here.params["ux"])
delete(Url.here.params["rn"])
delete(Url.here.params["rx"])
delete(Url.here.params["cn"])
delete(Url.here.params["cx"])
delete(Url.here.params["an"])}
Clearance.processCookies=function(level,en,ex){
Claim.isNumber(level,"Clearance.processCookies.level")
Claim.isTrue(level>Clearance.level&&level<=Clearance.CONFIDENTIAL,
"Clearance.processCookies.level")
Clearance.log.debug("Process "+Clearance.prefix[level]+" cookies")
var sessionName=Clearance.cookieName(level,false)
var timedName=Clearance.cookieName(level,true)
var session=Cookies.get(sessionName)
var timed=Cookies.get(timedName)
if(!session){
Clearance.log.debug("No "+sessionName+" cookie => "+Clearance.levelNames[Clearance.level])
return false}
if(!timed){
Clearance.log.debug("No "+timedName+" cookie => "+Clearance.levelNames[Clearance.level])
return false}
if(!session.ui){
Clearance.log.debug("No "+sessionName+".ui => "+Clearance.levelNames[Clearance.level])
return false}
if(!timed.ui){
Clearance.log.debug("No "+timedName+".ui => "+Clearance.levelNames[Clearance.level])
return false}
if(session.ui!=timed.ui){
Clearance.log.debug("Mismatch {"+sessionName+","+timedName+"}.ui => "+Clearance.levelNames[Clearance.level])
return false}
if(!session.en){
Clearance.log.debug("No "+sessionName+".en => "+Clearance.levelNames[Clearance.level])
return false}
if(!timed.en){
Clearance.log.debug("No "+timedName+".en => "+Clearance.levelNames[Clearance.level])
return false}
if(session.en!=timed.en){
Clearance.log.debug("Mismatch {"+sessionName+","+timedName+"}.en => "+Clearance.levelNames[Clearance.level])
return false}
if(level>Clearance.UNCLASSIFIED){
if(session.ui!=Clearance.userId){
Clearance.log.debug("Mismatch "+sessionName+".ui => "+Clearance.levelNames[Clearance.level])
return false}}
else{
Clearance.params.ui=session.ui
Clearance.userId=session.ui}
Clearance.params[en]=session.en
Clearance.params[ex]=timed.ex?timed.ex:1
Clearance.level=level
Clearance.log.debug("Achieved "+Clearance.levelNames[Clearance.level])
return true}
PreLoad.actions.push(Clearance.preLoad)
var Jast={}
Jast.timeout=20000
Jast.pendingRequestByUrl={}
Jast.pendingRequestById={}
Jast.isPreLoad=true
Jast.nextRequestId=0
Jast.activeRequestCount=0
Jast.response=function(id,isOk,result,caching){
Claim.isNumber(id,"Jast.response.id")
Claim.isBoolean(isOk,"Jast.response.isOk")
request=Jast.pendingRequestById[id]
if(!request){
Jast.Request.log.warn("Unknown load request id: "+id+" isOk: "+isOk)
return}
request.loaded(isOk,result,caching)}
Jast.clearCache=function(){
$H(Cookies.valueByName).keys.each(function(name){
if(name.substr(0,5)=="Jast.")
Cookies.clear(name)})}
Jast.Request=Class.create()
Jast.Request.prototype={}
Jast.Request.stateNames=[
"Uninitialized","Loading","Loaded","Interactive","Complete"]
Jast.Request.UNINITIALIZED=0
Jast.Request.LOADING=1
Jast.Request.LOADED=2
Jast.Request.INTERACTIVE=3
Jast.Request.COMPLETE=4
Jast.Request.statusNames=[
"Create","Success","Failure","Timeout"]
Jast.Request.CREATE=0
Jast.Request.SUCCESS=1
Jast.Request.FAILURE=2
Jast.Request.TIMEOUT=3
Jast.Request.preLoad=function(){
Jast.Request.log=new Log4Js.Logger("Jast.Request")}
PreLoad.actions.push(Jast.Request.preLoad)
Jast.Request.onLoad=function(){
Jast.isPreLoad=false
var length=Jast.nextRequestId
Jast.Request.log.debug("Complete "+length+" pre-load request(s)")
length.times(function(id){
request=Jast.pendingRequestById[id]
if(request&&!request.uses)
if(request.result)
request.complete()
else{
if(request.options.timeout>0){
request.setTimeout=
setTimeout(request.timedOut.bind(request),request.options.timeout)
Jast.Request.log.debug("Reset timeout for Preloaded Request. Request id: "+request.id+" setTimeout: "+request.setTimeout)}}})}
Event.observe(window,"load",Jast.Request.onLoad)
Jast.Request.prototype.initialize=function(url,options){
Claim.isString(url,"Jast.Request.url")
this.url=url
this.options={
timeout:Jast.timeout,
toReuse:true,
unimportant:[]}
Object.extend(this.options,options||{})
var parsed=Url.parse(url)
$A(this.options.unimportant).each(function(param){
delete(parsed.params[param])})
$A(["un","ux","rn","rx","cn","cx"]).each(function(param){
delete(parsed.params[param])})
this.cacheId=Url.appendParams(parsed.base,parsed.params)
this.cacheId="Just."+this.cacheId.replace(/[=;]/g,'_')
this.usedBy=[]
this.id=Jast.nextRequestId++
this.state=-1
this.status=Jast.Request.CREATE
Jast.Request.log.debug("Create request id: "+this.id+" url: "+this.url+" unimportant: "+Cookies.toJson(this.options.unimportant)+" cacheId: "+this.cacheId+" toReuse: "+this.options.toReuse+" timeout: "+this.options.timeout)
this.advanceTo(Jast.Request.UNINITIALIZED)
this.dispatch("onCreate")
var name
var cached=Cookies.get(name=this.cacheId+".T")||Cookies.get(name=this.cacheId+".S")
if(cached){
Jast.Request.log.debug("Fetch request id: "+this.id+" from cookie name: "+name)
if(Jast.isPreLoad){
Jast.pendingRequestByUrl[this.cacheId]=this
Jast.pendingRequestById[this.id]=this}
this.loaded(cached.isOk,cached.result,undefined)
return}
var request=Jast.pendingRequestByUrl[this.cacheId]
if(request&&this.options.toReuse&&request.options.toReuse&&request.state<=Jast.Request.LOADED){
Jast.Request.log.debug("Merge request id: "+this.id+" with request id: "+request.id+" state: "+Jast.Request.stateNames[request.state]+" status: "+Jast.Request.statusNames[request.status])
this.uses=request
this.advanceTo(request.state)
this.result=request.result
this.status=request.status
request.usedBy.push(this)}
else{
this.makeRequest()}}
Jast.Request.prototype.makeRequest=function(){
this.fullUrl=Url.appendParamValue(this.url,"jastId",this.id)
Jast.Request.log.info("Make request id: "+this.id+" fullUrl: "+this.fullUrl)
this.scriptId="jast-script-"+this.id
Jast.pendingRequestByUrl[this.cacheId]=this
Jast.pendingRequestById[this.id]=this
var isHeadNotExists=(0==document.getElementsByTagName("HEAD").length);
if(Jast.isPreLoad&&isHeadNotExists){
Jast.Request.log.debug("Write script id: "+this.scriptId+" for request id: "+this.id)
document.write("<"+"script")
document.write(' id="'+this.scriptId+'"')
document.write(' type="text/javascript"')
document.write(' src="'+this.fullUrl+'"')
document.write("></"+"script"+">")}
else{
Jast.Request.log.debug("Create script id: "+this.scriptId+" for request id: "+this.id)
script=document.createElement("script")
script.setAttribute("id",this.scriptId)
script.setAttribute("type","text/javascript")
script.setAttribute("src",this.fullUrl)
$T("head").appendChild(script)
if(this.options.timeout>0){
this.setTimeout=
setTimeout(this.timedOut.bind(this),this.options.timeout)
Jast.Request.log.debug("Request id: "+this.id+" setTimeout: "+this.setTimeout)}}
this.advanceTo(Jast.Request.LOADING)}
Jast.Request.prototype.loaded=function(isOk,result,caching){
Claim.isBoolean(isOk,"Jast.Request.loaded.isOk")
if(this.state>=Jast.Request.LOADED){
Jast.Request.log.warn("Reloaded request id: "+this.id+" isOk: "+isOk)
return}
Jast.Request.log.info("Loaded request id: "+this.id+" isOk: "+isOk)
if(this.setTimeout){
clearTimeout(this.setTimeout)
Jast.Request.log.debug("Request id: "+this.id+" clearTimeout: "+this.setTimeout)
delete(this["setTimeout"])}
if(caching&&caching.expires||session){
var value={isOk:isOk,result:result}
var session=caching.session
delete(caching["session"])
if(caching.expires){
Jast.Request.log.debug("Cache in: "+this.cacheId+".T for "+caching.expires+"ms")
Cookies.set(this.cacheId+".T",value,caching)}
delete(caching["expires"])
if(session){
Jast.Request.log.debug("Cache in: "+this.cacheId+".S for rest of session")
Cookies.set(this.cacheId+".S",value,caching)}}
this.advanceTo(Jast.Request.LOADED)
this.result=result
this.status=isOk?Jast.Request.SUCCESS:Jast.Request.FAILURE
var status=this.status
this.usedBy.each(function(request){
request.result=result
request.status=status})
if(!Jast.isPreLoad)
this.complete()}
Jast.Request.prototype.timedOut=function(){
if(this.state>=Jast.Request.LOADED){
Jast.Request.log.warn("Retimedout request id: "+this.id)
return}
Jast.Request.log.info("Timedout request id: "+this.id)
this.advanceTo(Jast.Request.LOADED)
this.status=Jast.Request.TIMEOUT
this.usedBy.each(function(request){
request.status=Jast.Request.TIMEOUT})
this.complete()}
Jast.Request.prototype.complete=function(){
Jast.Request.log.debug("Complete request id: "+this.id)
this.advanceTo(Jast.Request.INTERACTIVE)
this.dispatchUsed("on"+Jast.Request.statusNames[this.status])
this.advanceTo(Jast.Request.COMPLETE)
delete(Jast.pendingRequestByUrl[this.cacheId])
delete(Jast.pendingRequestById[this.id])
this.usedBy.each(function(request){
delete(Jast.pendingRequestById[request.id])})
if(this.scriptId){
Jast.Request.log.debug("Remove script id: "+this.scriptId+" for request id: "+this.id)
var script=$I(this.scriptId)
script.parentNode.removeChild(script)}}
Jast.Request.prototype.advanceTo=function(state){
Claim.isNumber(state,"Jast.Remove.advanceTo.state")
Claim.isTrue(0<=state&&state<=Jast.Request.COMPLETE,
"Jast.Remove.advanceTo.state")
while(this.state<state){
var nextState=this.state++
this.dispatch("on"+Jast.Request.stateNames[this.state])
this.usedBy.each(function(request){
request.advanceTo(nextState)})}}
Jast.Request.prototype.dispatch=function(event){
Claim.isString(event,"Jast.Request.dispatch.event")
Jast.Request.log.debug("Dispatch event: "+event+" for request id: "+this.id)
if(this.options[event]){
try{
this.options[event](this)}
catch(e){
Jast.Request.log.warn("Exception in "+event+" for request id: "+request.id+" exception: "+e.message);}}
Jast.Responders.dispatch(event,this)}
Jast.Request.prototype.dispatchUsed=function(event){
Claim.isString(event,"Jast.Responders.dispatchUsed.event")
Jast.Request.log.debug("DispatchUsed event: "+event+" for request id: "+this.id)
this.dispatch(event)
this.usedBy.each(function(request){
request.dispatchUsed(event)})}
Jast.Responders={}
Jast.Responders.responders=[]
Jast.Responders._each=function(iterator){
Claim.isObject(iterator,"Jast.Responders._each.iterator")
this.responders._each(iterator)}
Jast.Responders.register=function(responderToAdd){
Claim.isObject(responderToAdd,"Jast.Request.register.responderToAdd")
if(!this.include(responderToAdd))
this.responders.push(responderToAdd)}
Jast.Responders.unregister=function(responderToRemove){
Claim.isObject(responderToRemove,
"Jast.Responders.unregister.responderToRemove")
this.responders=this.responders.without(responderToRemove)}
Jast.Responders.dispatch=function(event,request){
Claim.isString(event,"Jast.Responders.dispatch.event")
Claim.isObject(request,"Jast.Responders.dispatch.request")
Claim.isNumber(request.id,"Jast.Responders.dispatch.request.id")
this.log.debug("Dispatch event "+event+" for request id: "+request.id)
this.each(function(responder){
if(responder[event]){
try{
responder[event](request)}
catch(e){
this.log.warn(" Exception in "+event+" for request id: "+request.id+" exception: "+e.message);}}})}
Jast.Responders.preLoad=function(){
Jast.Responders.log=new Log4Js.Logger("Jast.Responders")}
Object.extend(Jast.Responders,Enumerable)
PreLoad.actions.push(Jast.Responders.preLoad)
Jast.Responders.register({
onCreate:function(){
Jast.activeRequestCount++
Jast.Responders.log.debug("Active requests up to "+Jast.activeRequestCount)
Claim.isTrue(Jast.activeRequestCount>=1,
"Jast.Responders.activeRequestCount")},
onComplete:function(){
Jast.activeRequestCount--
Jast.Responders.log.debug("Active requests down to "+Jast.activeRequestCount)
Claim.isTrue(Jast.activeRequestCount>=0,
"Jast.Responders.activeRequestCount")}})
$A(PreLoad.actions).each(function(action){action()})

