function dapi_watchResize(){
	if (document.layers) window.onresize = new Function("if ("+window.innnerWidth+"!=window.innnerWidth || "+window.innerHeight+"!=window.innerHeight){ location.reload() }")
}

function isObject(obj){
	if (typeof(obj) == "object"){
		return true
	} else return false
}

function isFloat(num){
	var numInt = parseInt(num) || 0
	var numFloat = parseFloat(num) || 0
	if (numFloat>numInt) return true
	else return false
}

Number.prototype.inverse = inverse
function inverse(){
	return -1*this
}
	
if (typeof(window.aGlobalEvents)=="undefined"){
	window.aGlobalEvents = new Array()
	window.aGlobalEventTypes = new Array()	
}	
window.GlobalEvent_Re1 = /\}$|\}\n$/
window.GlobalEvent_ReEOF = /\}\n*$/
window.GlobalEvent_ReFARGS = /\(.*\).*\{/
window.GlobalEvent_ReSOF_BODY = /\{/
window.GlobalEvent_ReEV_RET = /var bEventReturn;/
window.GlobalEvent_ReSPACE = /\s/g;
function GlobalEvent(sId,iState,sType,oFunc,bAddTop){
	if (!sType){
		sStoreType = aGlobalEvents[sId]
		if (!sStoreType){
			return false
		}
		if (aGlobalEvents[sStoreType][sId][0]!=-1) aGlobalEvents[sStoreType][sId][0] = iState
		return true
	} else if (sType && typeof(aGlobalEvents[sId])=="undefined"){
		if (sType.indexOf(".")!=-1) {
			sStoreType = "E"+sType.replace(/\./,"")
			oObj = eval(sType.split(".")[0])
			sType = sType.split(".")[1] 		
		} else {
			sStoreType = "E"+sType
			oObj = null
		}
		aGlobalEvents[sId] = sStoreType
	} else {
		alert("sId "+sId+" already exists...\nmust be unique.")
		return false
	}
	if (sType && typeof(aGlobalEvents[sStoreType])=="undefined"){
		aGlobalEvents[sStoreType] = new Array()
	}
	if (!sId || (typeof(iState)=="undefined") || !sType || !oFunc){
		alert("error, can't proceed\n"+sId+","+iState+","+sType+","+oFunc)
		return false
	}
	aGlobalEvents[sStoreType][sId] = [iState,null]
	if (typeof(oFunc)=="string"){
		aGlobalEvents[sStoreType][sId][1] = new Function("e",oFunc)
	}else{
		aGlobalEvents[sStoreType][sId][1] = oFunc
	}

	oCurrentEvent = GlobalEvent_Event(sType,oObj)
	if (typeof(oCurrentEvent)!="function"){
		sEvent = "function anonymous(e){\n/*DAPI HAS CREATED THIS EVENT*/var bEventReturn;\ne = e || event;\n}"
	} else {
		sEventArg = "e"
		sEvent = oCurrentEvent.toString()

		sFirstLine = sEvent.substring(sEvent.indexOf("(")+1,sEvent.indexOf(")")).replace(GlobalEvent_ReSPACE,"")
		sArgs = sFirstLine.split(",")
		bHasArgs = (sArgs[0]!="" && typeof(sArgs[0])!="undefined")
		if (bHasArgs){
			sEventArg = sArgs[0]
		} else {
			sEvent = sEvent.replace(GlobalEvent_ReFARGS,"(e){")
		}
		if (!GlobalEvent_ReEV_RET.test(sEvent)){
			sEvent = sEvent.replace(GlobalEvent_ReSOF_BODY,"{\ne = "+sEventArg+" || event;\nvar bEventReturn;\n")
			sEvent = sEvent.replace(GlobalEvent_ReEOF,"\n/*DAPI HAS MODIFIED THIS CODE*/\n}")			
		}
	}

	iReturnAt = sEvent.indexOf("return ")
	iEventReturn = sEvent.indexOf("return bEventReturn")
	if (iReturnAt!=-1 && iEventReturn==-1){
		sEvent = sEvent.replace("return ","bEventReturn = ")
	} else if (iEventReturn>-1){
		sEvent = sEvent.replace("return bEventReturn","")
	}
	if (bAddTop){
		sAddStr = "var bEventReturn;\nif (aGlobalEvents[\""+sStoreType+"\"][\""+sId+"\"][0]==1){\nbLocalReturn = aGlobalEvents[\""+sStoreType+"\"][\""+sId+"\"][1](e);\nif (bEventReturn!=false && typeof(bLocalReturn)==\"boolean\") bEventReturn=bLocalReturn;\n}\n"
		sEvent = sEvent.replace(GlobalEvent_ReEV_RET,sAddStr)
		sEvent = sEvent.replace(GlobalEvent_ReEOF,"\nreturn bEventReturn\n}")
	} else {
		sAddStr = "if (aGlobalEvents[\""+sStoreType+"\"][\""+sId+"\"][0]==1){\nbLocalReturn = aGlobalEvents[\""+sStoreType+"\"][\""+sId+"\"][1](e);\nif (bEventReturn!=false && typeof(bLocalReturn)==\"boolean\") bEventReturn=bLocalReturn;\n}\nreturn bEventReturn\n}"
		sEvent = sEvent.replace(GlobalEvent_ReEOF,sAddStr)
	}
	if (GlobalEvent_Event(sType,oObj,sEvent)) return true
	else return false
}

function GlobalEvent_Event(sEvent,oObj,sAssign){
	var oObj = oObj || document
	bIe4Mac = (oClient.ie4 && oClient.mac)
	if (!bIe4Mac){
		if (!sAssign) rObj = oObj[sEvent]
		else {
			eval("oObj['"+sEvent+"'] ="+ sAssign); 
			rObj = true
		}
	} else {

		sType = typeof(document[sEvent])
		if (!sAssign){
			if (sType=="function") rObj = oObj[sEvent]
			else rObj = oObj[sEvent] = new Function()
		} else {
			if (sType!="function") document[sEvent] = new Function()
			eval("oObj['"+sEvent+"'] ="+ sAssign); 
			rObj = true
		}	
	}
	return rObj
}
