	
	var is = new Is();
	var eventTarget=null
	var mX=0
	var mY=0
	var sX=0
	var sY=0
	var xy=[0,0]
	var offX=20 
	var offY=10 
	var button=0
	var mainpanel='mainPanel'
	var appPath='/'
	
	var tMsg = ['You have insufficient rights. Contact an Administrator.',
				'No row was selected.',
				'Item not found.',
				'Saving error!',
				'Delete this row?']

	var tMode =	[["chPanMR","chPanHR","chPanTR","chPanIR","/images/close.gif","chPanIR","/images/help.gif"],
				 ["chPanME","chPanHE","chPanTE","chPanIE","/images/closesep.gif","chPanIE","/images/helpsep.gif"]]
				
	var tWnd = new Array(100)
	var cWnd = 0
	var idWnd = 0
	var dWnd = 0
	
	document.onmousedown = jClick
	document.onmousemove = jMove

	function Is (){ 
		try{
			var agt=navigator.userAgent.toLowerCase()
			this.major = parseInt(navigator.appVersion)
			this.nav = ((agt.indexOf('mozilla')!=-1) && ((agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1)))
			this.nav4 = (this.nav && (this.major == 4))
			this.nav4up = this.nav && (this.major >= 4)
			this.ie = (agt.indexOf("msie") != -1)
			this.ie6 = (this.ie && (agt.indexOf("6.") != -1))
			this.ie5 = (this.ie && !this.ie6)
		}catch(e){}
	}
	
	function getEventTarget(e){
		eventTarget=is.nav?e.target:window.event.srcElement
	}

	function getObj(id){
		ret=null;
		try{
			ret=document.getElementById(id);
		}catch(e){}
		return ret;
	}
	
	function getHeight(val){
		return parseInt(getObj(val).offsetHeight)
	}
	
	function getWidth(val){
		return parseInt(getObj(val).offsetWidth)
	}
	
	function getTop(val){
		return parseInt(getObj(val).offsetTop)
	}
	
	function getLeft(val){
		return parseInt(getObj(val).offsetLeft)
	}
	
	function getObjHeight(val){
		return parseInt(val.offsetHeight)
	}

	function getObjParent(val){
		return is.nav?val.parentNode:val.parentElement
	}

	function getObjWidth(val){
		return parseInt(val.offsetWidth)
	}
	
	function getObjTop(val){
		return parseInt(val.offsetTop)
	}
	
	function getObjLeft(val){
		return parseInt(val.offsetLeft)
	}
	
	function getDate(){
		var today = new Date()
		var day   = today.getDate()
		var	month = today.getMonth()
		var	year  = y2k(today.getYear())
		var date='' + padout(day) + '/' + padout(month - 0 + 1) + '/' + year
		return date
	}
	
	function frLength(){
		return is.ie?document.frames.length:(window.frames!=null?window.frames.length:0)
	}
	
	function frGet(){
		return (is.ie)?document.frames:window.frames
	}
	
	function jClick(e){
		xy=getTTPos(window)
		xy[0]=xy[0]+(is.nav?e.pageX:event.clientX)-(window==window.top?getLeft(mainpanel)-getObj('body').scrollLeft:window.top.getLeft(mainpanel))								//+getObjWidth(eventTarget)-event.offsetX
		xy[1]=xy[1]+(is.nav?e.pageY:event.clientY)-(window==window.top?(is.ie?getTop(mainpanel)/2:getTop(mainpanel))-getObj('body').scrollTop:window.top.getTop(mainpanel))		//-getObjHeight(eventTarget)+event.offsetY
		try{
			//window.top.getObj('stat').innerHTML=eventTarget.id+' ' +getObjHeight(eventTarget)+' '+event.offsetY
			//window.top.getObj('stat').style.top=xy[1]+10
		}
		catch(e){}
	}

	function jMove(e){
		//try{
			mX=sX-((is.nav)? e.screenX:event.screenX)
			mY=sY-((is.nav)? e.screenY:event.screenY)
			sX=(is.nav)? e.screenX:event.screenX
			sY=(is.nav)? e.screenX:event.screenY
			button = (is.nav)?e.which:event.button
			if(dWnd){
				if(button!=1)
					wndMove(dWnd,0)
				else
					wndMove(dWnd)
			}
			eventTarget=(is.nav)?e.target:window.event.srcElement
		//}catch(e){}
	}
	
	function jKey(e){
		try{
			if(getObj('bSearch')){
				k=is.ie?event.keyCode:e.keyCode
				if(k == 13)
					getObj('bSearch').focus()
			}
		}catch(e){}
	}
	
	function getTTPos(w){
		var ret = [0,0]
		for(i=0;w!=window.top && i<50;i++){
			txy = getTPos(w.frameElement,w)
			ret[0]+=txy[0]
			ret[1]+=txy[1]
			w=w.parent
		}
		return ret
	}
	
	function getTPos(obj){
		var ret = [0,0]
		for(i=0;(obj) && (obj.offsetParent) && i<50;i++){
			try{
				ret[0]+=obj.offsetLeft
				ret[1]+=obj.offsetTop
				obj=obj.offsetParent
			}catch(e){}
		}
		return ret
	}
	
	function padout(number){ 
		return (number < 10) ? '0' + number : number; 
	}

	function y2k(number){ 
		return (number < 1000) ? number + 1900 : number; 
	}
	
	function ddopen(obj){
		if(is.ie){
				ddwidth=obj.style.width
				obj.style.width=null				
				obj.focus();
		}
	}

	function ddclose(obj){
		if(is.ie){
			obj.style.width=ddwidth
		}
	}
	
	function log(val){
		var ca=log.caller.toString().substring(0,log.caller.toString().indexOf('('))
		logg(val,ca,true)
	}
	
	function logg(val,ca,show){
		if(show){
			alert('Error!'+'\nName: '+ca+'\nMessage: '+val.message+'\nDescription: '+val.description)
		}
	}
	
	function blockForm(){
		disableDDL()
		for(i=0;i<frLength();i++){
			try{
				frGet()[i].window.blockForm()
			}catch(e){}
		}
	}
		
	function freeForm(){
		enableDDL()
		for(i=0;i<frLength();i++){
			try{
				frGet()[i].window.freeForm()
			}catch(e){}
		}
	}
		
	function disableDDL(){
		var ddl
		for(i=0;i<getObj(mainpanel).getElementsByTagName("select").length;i++){
			try{
				ddl=getObj(mainpanel).getElementsByTagName("select")[i]
				if(ddl.style.visibility!='hidden'){
					try{
						getObj(ddl.id+"Cover").style.display='block'
						getObj(ddl.id+"Cover").value=ddl.options[ddl.selectedIndex].text
					}catch(e){}
					ddl.style.display='none'
				}
			}catch(e){}
		}
	}
		
	function enableDDL(){
		var ddl
		for(i=0;i<getObj(mainpanel).getElementsByTagName("select").length;i++){
			try{
				ddl=getObj(mainpanel).getElementsByTagName("select")[i]
				if(ddl.style.visibility!='hidden'){
					try{
						getObj(ddl.id+"Cover").style.display='none'
					}
					catch(e){}
					ddl.style.display='block'
				}
			}catch(e){log(e)}
		}
	}
	
	function getTicks(){
		var d = new Date();
		var s= 'a'
		try{
			s += padout(d.getMonth())
			s += padout(d.getDate())
			s += padout(d.getYear())
			s += padout(d.getHours())
			s += padout(d.getMinutes())
			s += padout(d.getSeconds())
		}catch(e){}
		return s
	}
		
	function isEditMode(){
		var stat=true
		try{
			if(window.parent!=window)
				stat=window.parent.isEditMode()
			if(window.top.pageMode.toLowerCase()=='edit')
				stat=true
			else
				stat=false
		}catch(e){}
		return stat
	}
		
	function calOpen(field,sh){
		_calOpen(field,sh,this)
	}
	
	function _calOpen(field,sh,par){
		if(field.getAttribute('disabled')=='disabled')
			return false
		var fd=field.id.substring(0,field.id.length-3)
		var page = urlParamAdd(urlParamAdd(urlParamAdd(appPath+'comm/cal.aspx','val='+par.getObj(fd).value),'fd='+fd),(sh)?'short=1':'')
		wndOpen(page,176,202,par,1)		
	}
	
	function phOpen(field,mob){
		_phOpen(field,mob,this)
	}
	
	function _phOpen(field,mob,par){
		if(field.getAttribute('disabled')=='disabled')
			return false
		var fd=field.id.substring(0,field.id.length-2)
		var page = urlParamAdd(urlParamAdd(urlParamAdd(appPath+'comm/ph.aspx','val='+replace(par.getObj(fd).value,'+','plus')),'fd='+fd),(mob)?'mob=1':'')
		wndOpen(page,176,202,par,1)		
	}
		
	function getParentTable(val){
		var par=null
		if(val!=null){
			if(val.tagName=='TABLE')
				par=val
			else{
				for(i=0;i<10;i++){
					if(val.parentElement!=null){
						if((val=val.parentElement).tagName=='TABLE'){
							par=val
							break
						}
					}
					else
						break
				}
			}
		}
		return par
	}
	
	function popUp(u, w, h, tit){ 
		if(!tit)
			tit='Zoom'
		tit+=' (Click on Image to Close the Window)'
		var l=0
		var t=0
		try{
			l=(window.screen.availWidth-w)/2; 
			t=(window.screen.availHeight-h)/2;
		}catch(e){}
		page="<html><head><title>"+tit+"</title></head><body onclick=\"window.close();\" style=\"cursor:hand;margin: 0; padding: 0;\">"+
			"<img src=\""+u+"\" width=100% height=100% style=\"display: block;\" onclick=\"window.close();\" alt=\"\" /></body></html>"; 
		p = window.open("","","width="+w+",height="+h+",left="+l+",top="+t+",resizable=yes"); void(0); 
		p.document.open(); 
		p.document.write(page); 
		p.document.close(); 
		p.focus(); 
		return p;
	} 
			
	function popup(mylink, windowname){
		if (!window.focus)
			return true
		var href
		if (typeof(mylink) == 'string')
			href=mylink
		else
			href=mylink.href
		var l=(window.screen.Width-800)/2
		var t=(window.screen.Height-600)/2
		var p=",left="+l+",top="+t+",screenX="+l+",screenY="+t
		win=window.open(href, windowname, 'width=800,height=600,scrollbars=yes'+p)
		return win
	}

	function trim(str){
		return str.replace(/^\s*|\s*$/g,"");
	}
	
	function winSrc(val,popup){
		return urlParamAdd(urlParamAdd(urlParamAdd(urlParamAdd(val,'p='+getTicks()),getObj('isO')!=null?'IO='+getObj('isO').value:''),getObj('sect')!=null?'sec='+getObj('sect').value:''),popup!=null?'popup='+popup:'')
	}
	
	function urlParamAdd(page,param){
		if(param){
			if(page.indexOf('?')>=0)
				return page+'&'+param
			else
				return page+'?'+param
		}
		return page
	}
	
	function ft(val){
		if(val.title=='Open'){
			val.src=appPath+'images/rftop.gif'
			val.title='Close'
			if(getObj('filter')!=null)
				getObj('filter').style.display=''
		}
		else{
			val.src=appPath+'images/rfend.gif'
			val.title='Open'
			if(getObj('filter')!=null)
				getObj('filter').style.display='none'
		}
	}
	
	function replace(str,src,dest){
		var m = new RegExp(_replace(src),'gi')
		return str.replace(m,dest)
	}
	
	function search(str,src){
		var m = new RegExp(_replace(src),'i')
		return str.search(m)
	}
	
	function _replace(str){
		str = str.replace(new RegExp('\\+','gi'),'\\+')
		str = str.replace(new RegExp('\\(','gi'),'\\(')
		str = str.replace(new RegExp('\\)','gi'),'\\)')
		str = str.replace(new RegExp('\\?','gi'),'\\?')
		str = str.replace(new RegExp('\\|','gi'),'\\|')
		return str
	}
	
	function pSave(){
		try{
			getObj('bAccept').click();
		}catch(e){}
	}
	
	function pCancel(){
		try{
			getObj('bCancel').click();
		}catch(e){}
	}
	
	function pLoad(){
		try{
			getObj('bLoad').click();
		}catch(e){}
	}
	
	function pInit(mode,w,h){
		if((mode!=null) && (getObj('wndID'))){
			win = window.top
			win.wndUpdate(getObj('wndID').value,document.title,mode,w,h)
		}
		try{
			setTimeout('pageLoad()',100)
		}catch(e){}
	}
	
	function pageLoad(){
	}
	
	function saveData(){
	}
	
	function loadData(){
	}
	
	function openLinks(){
		wndOpen('/comm/links.aspx',144,264,this,2)
	}
	
	function jWnd(childpage,callW,id,x,y,w,h,pos){
		this.childpage = childpage
		this.callW = callW
		this.id = id
		this.pos=pos
		this.x = x
		this.y = y
		this.w = w
		this.h = h
		this.childW
	}
	
	function wndGet(id){
		for(i=1;i<=cWnd;i++){
			if((tWnd[i]) && (tWnd[i].id==id))
				return tWnd[i]
		}
		return null
	}
	
	function wndCreate(jwnd){
		var id=jwnd.id
		var obj = document.createElement("div")
		obj.setAttribute("id", "chBl_" + id)
		obj.className = "chBl"
		obj.style.zIndex = 500 + (cWnd*10)
		regEvent(obj,"wndClose("+id+",1)")
		if(!is.ie || is.ie5)
			obj.style.backgroundColor='transparent'
		getObj('body').appendChild(obj)
		obj = document.createElement("table")
		obj.setAttribute("id", "table_" + id)
		obj.className = "cTable"
		obj.style.position="absolute"
		obj.style.top=0
		obj.style.left=0
		obj.style.zIndex = 500 + (cWnd*10)+2
		getObj('body').appendChild(obj)
		obj=trCreate(obj,"tr_" + id)
		obj=tcCreate(obj,"td_" + id)
		obj.className = "cTd"
		obj.setAttribute("align", "center")
		regEvent(obj,"wndClose("+id+",1)")
		obj = document.createElement("div")
		obj.setAttribute("id", "mPan_" + id)
		obj.style.width=getWidth(mainpanel)
		obj.style.height=getHeight(mainpanel)	
		obj.style.backgroundColor='transparent'
		obj.style.position="relative"
		getObj("td_" + id).appendChild(obj)
		obj = document.createElement("div");
		obj.setAttribute("id", "chPan_" + id);
		obj.className = "chPan";
		wndSetPos(obj,jwnd)
		obj.style.width=jwnd.w
		obj.style.height=jwnd.h
		getObj("mPan_" + id).appendChild(obj)
		obj = document.createElement("iframe");
		obj.className = "chFr";
		obj.setAttribute("allowTransparency", "true");
		obj.setAttribute("frameBorder","no");
		obj.setAttribute("scrolling", "no");
		obj.setAttribute("id", "chFr_" + id);
		obj.setAttribute("name", "chFr_" + id);
		obj.style.width="0px"
		obj.style.height="0px"
		obj.setAttribute("src", jwnd.childpage);
		getObj("chPan_" + id).appendChild(obj)
	}
	
	function wndSetPos(obj,jwnd){
		switch(jwnd.pos){
			case 1:
				obj.style.left=jwnd.x
				obj.style.top=jwnd.y
			break;
			case 2:
				obj.style.left=jwnd.x
				obj.style.top=jwnd.y-jwnd.h
			break;
			default:
				obj.style.left=getWidth(mainpanel)/2-jwnd.w/2
				obj.style.top=getHeight(mainpanel)/2-jwnd.h/2
			break;
		}
	}
	
	function wndDestroy(jwnd){
		var id=jwnd.id
		getObj("body").removeChild(getObj("table_" + id));
		getObj("body").removeChild(getObj("chBl_" + id));
	}
	
	function wndMove(id,mode){
		if(mode!=null){
			if(mode)
				dWnd=id
			else{
				getObj('chFr_' + id).style.display='block'
				dWnd=0
			}	
		}
		else{
			if(wndGet(id)){
				getObj('chFr_' + id).style.display='none'
				var chPan = getObj("chPan_" + id)
				chPan.style.left=(getObjLeft(chPan)+window.top.getLeft(mainpanel)-mX)<0?getObjLeft(chPan):getObjLeft(chPan)-mX
				chPan.style.top=(getObjTop(chPan)+(window.top.getTop(mainpanel)/2)-mY)<0?getObjTop(chPan):getObjTop(chPan)-mY
			}
		}
	}
	
	function wndUpdate(id,tit,mode,w,h){
		var jwnd=wndGet(id)
		if(jwnd == null)
			return
		jwnd.w=parseInt(w)					
		jwnd.h=parseInt(h)+22
		var obj=getObj('chPan_'+id)
		wndSetPos(obj,jwnd)
		obj.className=tMode[mode][0]
		obj.style.width=jwnd.w+2
		obj.style.height=jwnd.h+2
		obj=getObj('chFr_'+id)
		obj.style.top=23
		obj.style.width=jwnd.w
		obj.style.height=jwnd.h-23
		obj=getObj("titPan_" + id)
		if(!obj){
			obj = document.createElement("div")
			obj.setAttribute("id", "titPan_" + id)
			obj.onmousedown=new Function("wndMove("+id+","+id+")")
			obj.onselectstart=new Function("return false;")
			getObj('chPan_'+id).appendChild(obj)
		}
		obj.style.width=jwnd.w
		obj.className=tMode[mode][1]
		obj=getObj("lTitle_" + id)			
		if(!obj){
			obj = document.createElement("label")
			obj.setAttribute("id", "lTitle_" + id)
			getObj("titPan_" + id).appendChild(obj)
		}
		obj.innerHTML=tit
		obj.className=tMode[mode][2]
		obj = getObj("imClose_" + id)
		if(!obj){
			obj = document.createElement("img")
			obj.setAttribute("id", "imClose_" + id)
			obj.setAttribute("title", "Close")
			obj.onclick=new Function("wndClose("+id+")")
			getObj("titPan_" + id).appendChild(obj)
		}
		obj.style.left=jwnd.w-20
		obj.className=tMode[mode][3]
		obj.setAttribute("src", tMode[mode][4])
		obj = getObj("imHelp_" + id)
		if(!obj){
			obj = document.createElement("img")
			obj.setAttribute("id", "imHelp_" + id)
			obj.setAttribute("title", "Help")
			getObj("titPan_" + id).appendChild(obj)
		}
		obj.style.left=jwnd.w-40
		obj.className=tMode[mode][5]
		obj.setAttribute("src", tMode[mode][6])
	}
	
	function wndClose(id,q){
		try{
			if((!q) || (confirm('Close this Window?')))
				if(frGet()["chFr_" + id].window){
					try{
						frGet()["chFr_" + id].window.wndQuit()
					}catch(e){
						wndQuit(null,idWnd)
					}
				}
				else
					wndQuit(null,idWnd)
		}
		catch(e){}
	}
	
	function wndOpen(page,w,h,par,pos){
		win=window.top
		win.cWnd++
		win.idWnd++
		win._wndOpen(winSrc(page,win.idWnd),xy[0],xy[1],w,h,par,pos)
	}
		
	function _wndOpen(page,x,y,w,h,par,pos){
		var id=idWnd
		tWnd[cWnd]=new jWnd(page,par,id,x,y,w,h,pos)
		blockForm()
		wndCreate(wndGet(id))
	}

	function _wndQuit(val,id){
		win=window.top
		if(!id)
			id=getObj('wndID').value
		win.wndEnd(id,val)
	}
	
	function wndQuit(val,id){
		_wndQuit(val,id)
	}
	
	function wndEnd(id,val){
		var jwnd=wndGet(id)
		wndDestroy(jwnd)
		if(cWnd>1)
			jwnd.callW.freeForm()
		else
			freeForm()
		if(val){
			jwnd.callW.getObj('pagePostState').value=val
			jwnd.callW.getObj('Form1').submit()
		}
		tWnd[i]=null
		cWnd--
		dWnd=0
		try{
		var obj = document.createElement("input")
		obj.setAttribute("width", "0")
		getObj('mainPanel').appendChild(obj)
		obj.focus();
		getObj('mainPanel').removeChild(obj)
		}catch(e){}
	}
	
	function wndExec(fun){
		win=window.top
		if(win.wndGet(getObj('wndID').value))
			win.wndGet(getObj('wndID').value).callW.eval(fun)
	}
	
	function regEvent(obj,ev){
		if(obj){
			if(is.ie)
				obj.setAttribute("ondblclick",new Function(ev))
			else
				obj.setAttribute("ondblclick",ev)
		}
	}
	
	function trCreate(table,id){
		var obj=null
		if(is.ie)
			obj = table.insertRow()
		else{
			obj = document.createElement("tr")
			table.appendChild(obj)
		}
		if(id!=null)
			obj.setAttribute("id", id)
		return obj
	}
	
	function tcCreate(tr,id){
		var obj=null
		if(is.ie)
			obj = tr.insertCell()
		else{
			obj = document.createElement("td")
			tr.appendChild(obj)
		}
		if(id!=null)
			obj.setAttribute("id", id)
		return obj
	}

	/**CM**********************************/
	var appImagePath=appPath+'images/'
	
	var tImg = [['cal','calendar.gif','calendardwn.gif'],
				['add','addrecord.gif','addrecorddwn.gif'],
				['plane','plane.gif','planedwn.gif'],
				['edit','memo.gif','memodwn.gif'],
				['delete','delete.gif','deletedwn.gif'],
				['showall','refresh.gif','refreshdwn.gif'],
				['ph','phone.gif','phone.gif']]
	
	function setHovImg(obj,val){
		var tabs=tImg 
		for(i=0;i<tabs.length;i++){
			if(tabs[i][0]==val){
				obj.src=appImagePath+tabs[i][2]
				break;
			}
		}
	}
	
	function setImg(obj,val){
		var tabs=tImg 
		for(i=0;i<tabs.length;i++){
			if(tabs[i][0]==val){
				obj.src=appImagePath+tabs[i][1]
				break;
			}
		}
	}
