/* Copyright � 2000-2006 Dennis Bekkering 
 * Comeniusstraat 61 
 * 1065 BH Amsterdam 
 * The Netherlands. 
 * All rights reserved 
 */
window.ax = eval( 'window.Act'+'iveX'+'Object' );
var textArr = null;
var lastTansferTime;
function transfer(contentHolder){

	
	get('buttonBorder').client='';
	get('buttonBorder').style.display='none';
	
 
	
	lastTansferTime = new Date();
	try{
	
		
		
		callInFrame( 'hiddenSubmitter' , 'showMessages' );	
		callInFrame( 'hiddenSubmitter' , 'showAlerts' );	
		
	 
		var hiddenSubmitter = get('hiddenSubmitter'); 
	 
		
		if(!contentHolder){
			alert('ajax error , targets not found');
			location = 'gui.do;jsessionid=' + getTop().jsessionId;
		}	
		var k;
		
		
		
		for(k=0;k<contentHolder.childNodes.length;k++) 
		{
					
			var contentObject = contentHolder.childNodes[k];	
			
			
		
		
			if(contentObject.getAttribute && (contentObject.getAttribute('componentId') 
					|| contentObject.getAttribute('tdWrapper') 
					|| contentObject.getAttribute('trWrapper') ) ){
				
				if(contentObject.getAttribute('tdWrapper')){
					contentObject = contentObject.getElementsByTagName('TD')[0]; 
				}
				else if(contentObject.getAttribute('trWrapper')){
					
					contentObject = contentObject.getElementsByTagName('TR')[0];
					
				}
				
				var d = new Date();
				var component = searchComponent(  contentObject.getAttribute('componentId') );
				
				var holder;
				if(!component){
					alert('receiver=null , should not happen , will refresh window');
					getTop().location=getTop().location;
					return;
				}
				else{
					holder = component;
				}
				
	 
				//alert(contentObject.outerHTML);
				//alert(holder.outerHTML);
				swapContent(contentObject,holder);
				
				swapAttributes(contentObject,holder);
				
				
				
			}
		}
		contentHolder.innerHTML='';
		
		if(window.hideInlineEditor) {
			hideInlineEditor();
		}
	}
	catch(e){
		alert( 'transfer error : ' + e.message );
	}
}

function swapContent(contentObject,holder) {
	
	if(holder.tagName == 'TR') {
		
		var n;
		var arrHolder = holder.getElementsByTagName('TD');
		var arrContentObject = contentObject.getElementsByTagName('TD');
		for(n=0;n<arrHolder.length;n++) {
			swapContent(arrContentObject[n],arrHolder[n]);
			swapAttributes(arrContentObject[n],arrHolder[n])			
		}
	}
	else if (holder.tagName == 'TABLE' && window.ax) {
		holder.outerHTML=contentObject.outerHTML;
	}else {
		holder.innerHTML='';
		holder.innerHTML=contentObject.innerHTML;
	}
}
function swapAttributes(contentObject,holder) {
	
	holder.className = contentObject.className;
	
	var cssString;
	cssString = contentObject.style.cssText;
	if( typeof(cssString) != 'string' ) {
	  cssString = contentObject.getAttribute('style');
	}
	holder.style.cssText = cssString;
	holder.setAttribute('style',cssString);

	holder.style.zIndex = contentObject.style.zIndex;
	holder.style.color = contentObject.style.color;
	
	holder.style.paddingLeft = contentObject.style.paddingLeft;
	holder.style.paddingRight = contentObject.style.paddingRight;
	holder.style.paddingTop = contentObject.style.paddingTop;
	holder.style.paddingBottom = contentObject.style.paddingBottom;
	
	
	holder.style.display = contentObject.style.display;
	holder.style.backgroundImage = contentObject.style.backgroundImage;
	if(contentObject.style.border){
		holder.style.border = contentObject.style.border;
	}

	holder.style.left = contentObject.style.left;
	holder.style.top = contentObject.style.top;

	var p;
	for(p=0;p<holder.attributes.length;p++) {
		if(contentObject.getAttribute(holder.attributes[p].name) != holder.getAttribute(holder.attributes[p].name)
				&& holder.attributes[p].name != 'style' 
				&& holder.attributes[p].name != 'onclick' 
				&& holder.attributes[p].name != 'onmouseover' 
				&& holder.attributes[p].name != 'onmouseout' 
				&& holder.attributes[p].name != 'onmousedown' 
				&& holder.attributes[p].name != 'onkeyup' 
				&& holder.attributes[p].name != 'onkeydown' 
		) 
		{
			holder.setAttribute( holder.attributes[p].name , contentObject.getAttribute(holder.attributes[p].name) );
		}
	}
}

function inPageMessageBoxClick(e,xevent){
	e.style.display='none';
	inPageMessageBox.innerHTML ='<b>[ Click anywhere on this messagebox to close it. ]</b><br><br>';
	inPageMessageBox.scrolled='';
	inPageMessageBox.style.height='';
} 
function message(mes){

	var inPageMessageBox = get('inPageMessageBox');
	if(!inPageMessageBox) {
		return;
	}
	if(mes){
		addMessage(mes);
		//inPageMessageBox.focus();
	}
	else{
		inPageMessageBox.style.display='none';
		inPageMessageBox.innerHTML ='<b>[ Click anywhere on this messagebox to close it. ]</b><br><br>';
		inPageMessageBox.scrolled='';
		inPageMessageBox.style.height='';
	}
}

function addMessage(mes){
	var inPageMessageBox = get('inPageMessageBox');
	inPageMessageBox.style.display='';
	
	
	inPageMessageBox.innerHTML +=  mes + '<br>';
	if(inPageMessageBox.innerHTML.length>500) {
		//inPageMessageBox.innerHTML ='<b>[ Click anywhere on this messagebox to close it. ]</b><br><br>';
	}

	if(inPageMessageBox.clientHeight>document.body.clientHeight && !inPageMessageBox.scrolled ){
		inPageMessageBox.style.height = document.body.clientHeight -20;
		inPageMessageBox.scrolled=1;
		
	}
	inPageMessageBox.scrollTop=inPageMessageBox.scrollHeight;

}

window.onresize = function(event){
	
}


window.writer='';
window.debugStick='';
window.debugStart='';


function submitClick(componentId){
	var submitter = frames['stateSubmitter'];
	if(!submitter){
		//alert('not loaded yet');
		return;
	}
	var loc = 'set.state;jsessionid=' + getTop().jsessionId+
		'?componentId=' + componentId; 
	submitter.location = loc;
}

function showTab(e,content,xevent)
{

	submitClick( e.getAttribute('componentId') );
	var tab = content;
	e.tabContent = tab;
	if (e.getAttribute('isActive') == 'true' && tab.tagName == 'IFRAME') 
	{
		tab.contentWindow.location = tab.src;
		return;
	}
	else if (e.getAttribute('isActive') == 'true' ) 
	{
		return;
	}
  	if(!e.parentNode.parentNode.currentTab){
  		var children = e.parentNode.parentNode.parentNode.getElementsByTagName('span');
  		//just to be sure
  		for(i=0;i<children.length;i++){
  			if( children[i].innerHTML &&  children[i].getAttribute('isActive') == 'true' ){
	  			children[i].setAttribute('isActive' ,  'false');
	 			children[i].style.backgroundColor 	=  children[i].getAttribute('inActiveBackgroundColor');
	 			children[i].style.color 			=  children[i].getAttribute('inActiveColor');
	 			children[i].getElementsByTagName('span')[0].style.backgroundImage 	=  
	 				children[i].getAttribute('inActiveBackgroundImageCorner');
	 				
	 			children[i].style.backgroundImage 	=  
	 				children[i].getAttribute('inActiveBackgroundImage');
	 				
	 			hide(searchComponent(children[i].getAttribute('tabContentId')));	
  			}
  		}
  	}
  	else 
	{
		var currentTab = e.parentNode.parentNode.currentTab;
		currentTab.setAttribute('isActive' ,  'false');
		currentTab.style.backgroundColor 	=  currentTab.getAttribute('inActiveBackgroundColor');
		currentTab.style.color 				=  currentTab.getAttribute('inActiveColor');
		currentTab.getElementsByTagName('span')[0].style.backgroundImage 	=  
			currentTab.getAttribute('inActiveBackgroundImageCorner');
		
		currentTab.style.backgroundImage 	=  
			currentTab.getAttribute('inActiveBackgroundImage');
		
		hide(currentTab.tab);
  	}
 // 	alert( e.innerHTML );
	e.setAttribute('isActive' ,  'true');
	e.style.backgroundColor 	=  e.getAttribute('activeBackgroundColor');
	e.style.color 				=  e.getAttribute('activeColor');
	e.getElementsByTagName('span')[0].style.backgroundImage 	= 
		e.getAttribute('activeBackgroundImageCorner');
    
	e.style.backgroundImage 	= 
		e.getAttribute('activeBackgroundImage');
    
	show(tab);
	e.parentNode.parentNode.currentTab = e;
	e.parentNode.parentNode.currentTab.tab = tab;
}

function showLazyTab(e,content,xevent){

	xevent.cancelBubble = true;

	if(!e.getAttribute('contentLoaded')){
		var currentTab = e.parentNode.parentNode.currentTab;
		if(!currentTab){
			currentTab = e.parentNode.parentNode.parentNode.getElementsByTagName('span')[0];
		}

		var tabId = currentTab.getAttribute('componentId');
		var tabContentId = currentTab.getAttribute('tabContentId');
		contentId = content.getAttribute('componentId');
//		setTimeout(	"searchComponent('"+ tabContentId +"').style.display='none'" , 1 );
//		setTimeout(	"searchComponent('"+ contentId +"').innerHTML = '<center style=\"font-weight:900;margin-top:40px\" >loading ... </center>'" , 1 );
		content.innerHTML = '<center style="font-weight:900;margin-top:40px" >loading ... </center>';
		e.setAttribute('contentLoaded' , 'true');
		dynamicSubmitCall(e,xevent);
	}
	showTab(e,content,xevent);
}


function hide(e){
  e.style.display = 'none';
}
function show(e){
  e.style.display = 'block';
}
function isShown(e){
  return e.style.display == 'block';
}


function setPropertyEditors(xevent){
		var mouseFocus = get('MouseFocus');
		var dX = xevent.clientX - window.originalEventX;
		var dY = xevent.clientY - window.originalEventY;
		
		mouseFocus.innerHTML='';
		
	
		mouseFocus.style.width = '';
		
		if (window.capturePropertyEditorX){
			mouseFocus.style.left=xevent.pageX - 30;
			window.currentDebug.style[window.capturePropertyEditorX.getAttribute('property')] =  window.originalElementXVal + dX ;
			window.capturePropertyEditorX.innerHTML = 
			window.capturePropertyEditorX.getAttribute('property') + "="+
				window.currentDebug.style[window.capturePropertyEditorX.getAttribute('property')];
			mouseFocus.innerHTML+= window.capturePropertyEditorX.getAttribute('property')
				+ '=' + window.currentDebug.style[
			window.capturePropertyEditorX.getAttribute('property')];
		//	window.capturePropertyEditorX.style.height=32;
				
		}
		if (window.capturePropertyEditorY){
		
			if(window.capturePropertyEditorX){
				mouseFocus.innerHTML+='<br>';
				mouseFocus.style.height=32;
			}
			mouseFocus.style.top=xevent.pageY - 50;		
			window.currentDebug.style[window.capturePropertyEditorY.getAttribute('property')] =  window.originalElementYVal + dY;			
			window.capturePropertyEditorY.innerHTML = 
			window.capturePropertyEditorY.getAttribute('property') + "="+			
				window.currentDebug.style[window.capturePropertyEditorY.getAttribute('property')];
			mouseFocus.innerHTML+= window.capturePropertyEditorY.getAttribute('property')
				+ '=' + window.currentDebug.style[
			window.capturePropertyEditorY.getAttribute('property')];		
			//window.capturePropertyEditorX.style.height=32;			
		}
}
function setPropertyEditorsOnCapture(){
		var mouseFocus = get('MouseFocus');
		
		mouseFocus.innerHTML='';
		
	
		mouseFocus.style.width = 90;
		
		if (window.capturePropertyEditorX){
			mouseFocus.style.left= extractNumber(mouseFocus.style.left) - 40;
			
			mouseFocus.innerHTML+= window.capturePropertyEditorX.getAttribute('property')
				+ '=' + window.currentDebug.style[
			window.capturePropertyEditorX.getAttribute('property')];
		}
		if (window.capturePropertyEditorY){
			if(window.capturePropertyEditorX){
				mouseFocus.innerHTML+='<br>';
				mouseFocus.style.height=32;
			}
			mouseFocus.style.top = extractNumber(mouseFocus.style.top) - 65;
			mouseFocus.innerHTML+= window.capturePropertyEditorY.getAttribute('property')
				+ '=' + window.currentDebug.style[
			window.capturePropertyEditorY.getAttribute('property')];		
		}
}





function info(a)
{
	var infWin = open();
	for ( p in a){
		try{
			if( p!='outerHTML' && p!='innerHTML' && p!='innerText' && p!='outerText'){
				infWin.document.writeln(p + " = " +  a[p] + '<br>');
			}
		}
		catch(e){
			infWin.document.writeln(p + " = " +  e.message + '<br>');		
		}
	}
}




function callInFrame(frame , func){
	
	
	if(getTop().get(frame)[func]){
		getTop().get(frame)[func]();
	}
	else{
		getTop().get(frame).contentWindow[func]();
	}
}

var myvisionComponents = new Array();
var found;
function searchComponent(componentId ){
	var foundComponent;

	if( componentId ==  '-167d1935:10b06fcef96:-6c93'  ){
		alert( "sc caller" + searchComponent.callee);
	}

	if ( myvisionComponents[componentId ]){
		foundComponent = get( myvisionComponents[componentId ]);
	}
	if(!foundComponent){
	
		found=false;
		scan(componentId );
		if (found){
			foundComponent = found;
		}
	}
	
	
	return foundComponent;
}

function scan(componentId , element){
	if(element && !element.getAttribute){
		return;
	}
	if(!element){
		element=document.body;
	}

	if (element.getAttribute('componentId')  ){
		var id = element.id;
		if (!id)
		{
			element.id = element.getAttribute('componentId') ;
		}
		myvisionComponents[element.getAttribute('componentId')] = element.id;
		
	}
	if (element.getAttribute('componentId') == componentId ){
		found = element;
		return;
	}
	var i=0;
	if (element.childNodes) for(i=0;i<element.childNodes.length;i++){
		var child = element.childNodes[i];
		 scan(componentId , child );
	}
}




		
function newElement(name){
	return document.createElement(name);
}					

var fileCount=0;
function doOnFile(file){
	
	if(	window._onsubmit){
		if(!window._onsubmit()){
			return;
		}
	}
	open('','xxx'+fileCount,'width=200,height=200');
	file.form.componentId.value=file.name;
	file.form.method='post';
//	alert( file.form.encoding );
	file.form.encoding='multipart/form-data';
	file.form.target='xxx' +  fileCount;
	file.form.action='do.file;jsessionid=' + getTop().jsessionId;
	file.form.submit();
	fileCount++;

	file.form.encoding='application/x-www-form-urlencoded';
//	file.form.method='get';
	file.form.action='gui.do;jsessionid=' + getTop().jsessionId;
	file.form.target='main';
	file.form.submit();
	
}


function xinit(){

}

var funcArr = new Array();

function addOnload(func){

	funcArr[funcArr.length]=func;

}




function showAlerts(){
	//focusWindow();
	if(document.alertArray && document.alertArray.length){
		alert(document.alertArray.join('\n'));
	}
}
function showMessages(){
	
	var i; 
	if(document.messageArray.length){
		getTop().message( '' );
		for(i=0;i<document.messageArray.length;i++){
			getTop().addMessage( document.messageArray[i] );
		} 
	}
}




window._onsubmit;
function submitCall(e,event){
	

	if(window.formsubmitted){
		return;
	}
	
	//info(event);
	
	if(window._onsubmit) { 
		if(!window._onsubmit() ){
			return false;
		}
	}

	document.forms[0].target='main';

	ret = callSubmit(e,event);
	window.formsubmitted=1;
	return ret;
}
function xmlhttpChange(){
//	return alert('xmlhttpChange' + window.xmlhttp.readyState);
}

function dynamicSubmitCall(e,event){

	
	
	if(window._onsubmit) { 
		var ret = window._onsubmit();
		if(!ret){
			return false;
		}
	}
	var hiddenSubmitterExists = 1;
	if( !get('hiddenSubmitter') )
	{
		hiddenSubmitterExists=0;
		document.body.innerHTML+='<iframe name=hiddenSubmitter ></iframe>';
	}
	else{
//		document.forms[0].target='';
	}	
	document.forms[0].target='hiddenSubmitter';	
	showStatusIndicator();
	
	if(hiddenSubmitterExists==0){
		callSubmit(e,event);
		location=location;	
		return ;
	}

	return callSubmit(e,event);
}
window.formsubmitted;
var callsubmitCount=0;
function callSubmit(e,event){

	if(!document.forms[0].componentId){
		alert( '[callSubmit] : document.forms[0].componentId==null' );
	}
	if(!e){
		message( 'no component to submit' );
		return;
	}
	
	document.forms[0].componentId.value=e.getAttribute('componentId');


	document.forms[0].submit();

	message('');
	return true;      
}
function onFormSubmit(e){
	//alert('onFormSubmit trigger');
	return false;
}



function getEvent(xevent,debug){
	
	try{
		if(!xevent){
			xevent= event;
		}
		if(xevent.patched){
			return xevent;
		}
		if(!xevent.srcElement)
		{
			xevent.srcElement = xevent.target;	
			xevent.offsetY=xevent.layerY;
			xevent.offsetX=xevent.layerX;

		}
		else{
			xevent.target = xevent.srcElement;	
			xevent.pageX=xevent.clientX;
			xevent.pageY=xevent.clientY;
			
		}
		xevent.patched=1;
		if(debug)	alert('in event:' + xevent);
		
		return xevent;
	}
	catch(e){
//	if(debug)	alert('in event:' + e);
	
		return null;
	}
}


function getChildIndex(parent,child){
	var j=0;
	for(i=0;i<parent.childNodes.length;i++){
		if(parent.childNodes[i].tagName ){
			if(parent.childNodes[i]==child){
				return j;
			}	
			j++;			
		}
	}
}


function err(func,err,m){
//	info(func);
	if(!m){
		message('<pre>[SCRIPT-ERROR] : ' +  err.message + ' in ' + func 
		+ ' , called by : ' + (func ? func.caller : func )+'</pre>');
	}
	else{
		message('<pre>[SCRIPT-ERROR] : ' + m + ' , ' +  err.message + ' in ' + func
		+ ' , called by : ' + (func ? func.caller : func ) +'</pre>' );
	}
}



function openPdf(e,event,cid){
	var win = open('gui.itext;jsessionid=' + getTop().jsessionId+
			'?componentId=' +  cid + '&stamp=' + new Date() , 'pdfSubmitter' );
			return false;
}





function stretchWidth(){
	var stretchBottomI = 0;
	for(stretchBottomI=0;stretchBottomI<arguments.length;stretchBottomI++){
		var e = arguments[stretchBottomI];
		var stretchWidthTune = e.getAttribute('stretchWidthTune');
		var w = document.body.clientWidth+parseInt(stretchWidthTune);
		e.style.width= w < 0 ? 0 : w;
	}
}
function stretchHeight(){
	
	var stretchBottomI = 0;
	for(stretchBottomI=0;stretchBottomI<arguments.length;stretchBottomI++){
		var e = arguments[stretchBottomI];
		var stretchHeightTune = e.getAttribute('stretchHeightTune');
		if(window.ax){
//			stretchHeightTune = parseInt(stretchHeightTune) * 0.74;
		}
		e.style.height=document.body.clientHeight+parseInt(stretchHeightTune);
	}
}



function baseContextMenuClick(e,event){
	if(event.srcElement.tagName=='TD')
	{
		var inf = get('infoBox');
		var baseContextMenuHolder = get('baseContextMenuHolder');
		if(inf.offsetLeft==0)
		{
			inf.style.left= document.body.clientWidth - inf.clientWidth;
			baseContextMenuHolder.style.left  = inf.offsetLeft
				- ( baseContextMenuHolder.clientWidth - inf.clientWidth   );
		}
		else
		{
			inf.style.left=0;
			baseContextMenuHolder.style.left=0;
		}
	}
}





function getNumber(px){
	if(!px){
		return 0;
	}
	return parseInt(px.substring(0,px.length-2));
}





function getPreviousSibling(e)
{
	if(!e){
		return null;
	}
	var ret='';
	while(e.previousSibling)
	{
		e=e.previousSibling;
		if (e.tagName )
		{
			return e;
		}
	}

	return ret;
}
function getCid(e){
//	alert( e.outerHTML );
	return e.getAttribute('componentId');
}



function get(id)
{
	if(id == 'hiddenSubmitter' ){
		if(!document.getElementById(id)){
			if(!frames['hiddenSubmitter']){
				return;
			}
			frames['hiddenSubmitter'].contentWindow = new Object();
			
			frames['hiddenSubmitter'].contentWindow.document = 
				frames['hiddenSubmitter'].frameElement.contentDocument;
			if(!frames['hiddenSubmitter'].contentWindow.document){
				frames['hiddenSubmitter'].contentWindow = frames['hiddenSubmitter'];
			}
			return frames['hiddenSubmitter'];
		}
	}
	return document.getElementById(id);
}

function len(e)
{
	var len = e.childNodes.length;
	var j =0 ;
	for (i=0;i<len;i++)
	{
		if (e.childNodes[i].nodeName != '#text')
		{
			j++;
		}
	}
	return j;
}


function focusWindow(){
	window.focus();
	
}

function focusComponent(cid) {
	
	try{
		searchComponent(cid).focus();
		//alert( searchComponent(cid).value );
	}
	catch(e){}
} 





function restartApplication() {
	alert('The application is closed, the start up screen will show');
	getTop().location = getTop().location;
}


function buttonImageOver(e,xevent) {
	
	if(!get('buttonBorder')){
		return;
	}
	if(e.click) diff=3 ;
	else diff=1;
	if(get('buttonBorder').client==e)
	return;
	get('buttonBorder').client=e;
	get('buttonBorder').style.top=getRealTop(e)-diff; 
	get('buttonBorder').style.left=getRealLeft(e)-diff;
	get('buttonBorder').style.display='';

	if(e.specific){
		e.specific(e,xevent);
	}	
	if(e._onmousemove ){
		get('buttonBorder').onmousemove= e._onmousemove ;
	}	
	else{
		get('buttonBorder').onmousemove= '';
	}
	get('buttonBorder').title = get('buttonBorder').client.title;
}

function showStatusIndicator(){
//	get('statusIndicator').style.display='block';	
}
function hideStatusIndicator(){
	get('statusIndicator').style.display='none';	
}


function checkMaxLength(e,event,maxLength){

	if(!maxLength){
		return true;
	}
	
	if( event.keyCode != 13 
	&& event.keyCode != 8 
	&& event.keyCode != 9 
	&& event.keyCode != 16 
	&& event.keyCode != 17 
	&& event.keyCode != 18 
	&& event.keyCode != 27 
	&& event.keyCode != 35 
	&& event.keyCode != 36 
	&& event.keyCode != 37 
	&& event.keyCode != 38 
	&& event.keyCode != 39 
	&& event.keyCode != 40 
	&& event.keyCode != 46 
	&& event.keyCode != 116 
	&& e.value.length>=maxLength)
	{
		alert('max length = ' + maxLength );
		e.value = e.value.substring(0,maxLength);
		return false;
	}
	return true;
}


function checkIsNumber(e,event,message){
//alert(event.keyCode);
	if ((event.keyCode < 48 || event.keyCode > 57) 
			&& (event.keyCode < 96 || event.keyCode > 105) 
			&& ( event.keyCode != 13 
				&& event.keyCode != 8 
				&& event.keyCode != 9 
				&& event.keyCode != 16 
				&& event.keyCode != 17 
				&& event.keyCode != 18 
				&& event.keyCode != 27 
				&& event.keyCode != 35 
				&& event.keyCode != 36 
				&& event.keyCode != 37 
				&& event.keyCode != 38 
				&& event.keyCode != 39 
				&& event.keyCode != 40 
				&& event.keyCode != 46 
				&& event.keyCode != 109
				&& event.keyCode != 116 
				&& event.keyCode != 189 
				&& event.keyCode != 32 
				 ) ) 
	{
		if(message) {
			alert(message);
		}
		return false; 
	}
	return true;
}



document.onfocus =  document_onfocus;
function document_onfocus(event)
{
	
	var xevent = getEvent(event);
	
	if(
		(window.ax && xevent.srcElement.onfocus && new String(xevent.srcElement.onfocus).substring(0,8) != 'function')
		||
		(window.ax && xevent.srcElement.parentNode.tagName == 'TR' &&  xevent.srcElement.parentNode.onfocus &&  new String(xevent.srcElement.parentNode.onfocus).substring(0,8) != 'function')
		)
	{
		var newEvent = '';
		var tr =(window.ax && xevent.srcElement.parentNode.tagName == 'TR' &&  xevent.srcElement.parentNode.onfocus &&  new String(xevent.srcElement.parentNode.onfocus).substring(0,8) != 'function');
		var oldEvent ;
		var cid ;
		if(tr){
			oldEvent = xevent.srcElement.parentNode.onfocus;
			cid=xevent.srcElement.parentNode.getAttribute("componentId");
		}
		else{
			oldEvent = xevent.srcElement.onfocus;
			cid=xevent.srcElement.getAttribute("componentId");
		}

		while(oldEvent.indexOf('this') != -1){
			var start = oldEvent.indexOf('this') ;
			var end = start + 4 ;
			var firstPart = oldEvent.substring(0,start);
			newEvent += firstPart;
			newEvent += 'searchComponent("'+ cid +'")';
			oldEvent = oldEvent.substring(end);
		}
		newEvent += oldEvent;
		var ret = eval( 'function x(){'+ newEvent +';};window.ret = x()' );
		if(ret == false){
			return false;
		}
	}
}


function dayTextInputClick(dayTextInput,event){
	var options = new Array();
	var i=0;
	for(i=0;i<31;i++){
		options[i]= i + 1;
	}	
 	fillOptionChooser( dayTextInput ,  options , 25 , 175 , event ,7);
}

function integerTextInputClick(input,event){
	var options = new Array();
	var i=-90;
 	for(i=-90;i<90;i++){
		options[i+90]= i ;
	}	
 	fillOptionChooser( input,  options , 25 , 250 , event ,10,true);
}

function monthTextInputClick(monthText,event){
	var options = new Array();
	for(i=0;i<12;i++){
		options[i]= i + 1;
	}	
	fillOptionChooser( monthText ,  options ,25 , 50,event, 2);
}

function yearTextInputClick(yearTextInput,event){
	var options = new Array();
	var d = new Date();
	var yr = d.getFullYear();

	for(i=0;i<20;i++){
		options[i]= (yr - 10 + i);
	}	
	fillOptionChooser( yearTextInput ,  options , 45 , 225 , event, 5);
}

function hourTextInputClick(hourTextInput,event){
	var options = new Array();
	for(i=0;i<24;i++){
		options[i]= i ;
	}	
	fillOptionChooser( hourTextInput  ,  options , 25 , 100,event, 4);
}
function minuteTextInputClick(minuteTextInput,event){
	var options = new Array();
	for(i=0;i<12;i++){
		options[i]= i * 5;
	}	
	fillOptionChooser( minuteTextInput ,  options , 25 , 100,event, 4);
}

function dateTextInputKey(e){
	hideOptionChooser();
}

function fillOtherDateInputs(dateInput,dateTextInput){
	if(!dateInput) {
		return;
	}
	var arr = dateInput.getElementsByTagName('input');
	var j;
	var found=false;
	for(j=0;j<arr.length;j++) {
		if(arr[j] != dateTextInput && arr[j].value) {
			found=true;
		}
	}
	
	
	if(!found) {
		var d = new Date();
		for(j=0;j<arr.length;j++) {
			if(arr[j] != dateTextInput ) {
				if (arr[j].getAttribute('javaClassName').indexOf('DayTextInput') != -1) {
					arr[j].value = d.getDate();
				}
				if (arr[j].getAttribute('javaClassName').indexOf('MonthTextInput') != -1) {
					arr[j].value = d.getMonth() + 1;
				}
				if (arr[j].getAttribute('javaClassName').indexOf('YearTextInput') != -1) {
					arr[j].value = d.getFullYear();
				}
				if (arr[j].getAttribute('javaClassName').indexOf('HourTextInput') != -1) {
					arr[j].value = d.getHours();
				}
				if (arr[j].getAttribute('javaClassName').indexOf('MinuteTextInput') != -1) {
					arr[j].value = d.getMinutes();
				}
			}
		}
	}
}

function hideOptionChooser(){
	if (optionChooser){
		
		optionChooser.style.top=0;
		optionChooser.style.left=0;
		
		optionChooserBack.style.top=0;
		optionChooserBack.style.left=0;
		
		optionChooserClientBorder.style.top=0;
		optionChooserClientBorder.style.left=0;
		
		optionChooser.style.visibility='hidden';
		optionChooserBack.style.visibility='hidden';
		optionChooserClientBorder.style.visibility='hidden';
		
	}
	if (window.currentOptionChooserClient){
		window.currentOptionChooserClient.style.background=window.currentOptionChooserClient.bg;
	}
	
}
function fillOptionChooser(client , options ,  optionWidth  , chooserWidth,event,cols,zeroEmpty){

	if (!optionChooser){
		createoptionChooser();	
	}
	else if ( optionChooser.style.visibility!='hidden' && optionChooser.client==client ){
		hideOptionChooser();
		return;
	}
	
	optionChooser.innerHTML='';
	optionChooser.client=client;
	optionChooser.style.fontSize=12;
	var len = options.length;
	var i =0;

	var rowCount=0;
	
	for(i=0;i<len;i++){
		var value = options[i];
		var chooseOption = document.createElement('div');
		
		
		chooseOption.innerHTML=value;
		if(client.value==value){
			chooseOption.style.fontWeight=900;
			//chooseOption.style.fontSize=14;
			//chooseOption.style.textDecoration='underline';
			chooseOption.style.color='yellow';
//			info(chooseOption.currentStyle);
		}
		if(i%cols==0&&i>0){
			optionChooser.appendChild( document.createElement('br') );
			rowCount++;
		}
		
		chooseOption.value=value;
		if(zeroEmpty && value ==0) {
			chooseOption.value='';
		}
		chooseOption.className='chooseOption';
		if (optionWidth ){
			chooseOption.style.width= optionWidth + "px";
			chooseOption.style.height=  '15px';			
			chooseOption.style.top= (rowCount * 15) + 'px';			
			chooseOption.style.left= (((i%cols)*optionWidth))+  'px';			
		}
	//	chooseOption.style.position='relative';
		chooseOption.overColor='#000044';
		chooseOption.overBg	='#ffffcc';
		chooseOption.onmouseover=invert;
		chooseOption.onmouseout=revert;
		chooseOption.onclick=selectOption;
		optionChooser.appendChild( chooseOption );
//		alert(width);

		
	}
	if(chooserWidth){
		optionChooser.style.width=chooserWidth + 2;
	}
	optionChooser.style.height=(rowCount*15) + 17;
	showOptionChooser(event);		
}

function selectOption(event){
	optionChooser.client.value =  this.value;
	if(optionChooser.client.value=='0') {
		//optionChooser.client.value='';
	}
	hideOptionChooser();
	if(optionChooser.client.onSelectDefault){
		optionChooser.client.onSelectDefault();
	}
	if(optionChooser.client.onSelectValue) {
		optionChooser.client.onSelectValue();
	}
	if(!window.ax || new String(optionChooser.client.onkeyup).substring(0,8) == 'function' ){
		optionChooser.client.onkeyup(event);
	}
	else {
		fireDeadFunction(optionChooser.client.onkeyup,optionChooser.client);
	}
	
	
}

var optionChooser;
var optionChooserBack;
var optionChooserClientBorder;
function createoptionChooser( ){

	optionChooserBack = document.createElement('div');
	optionChooser = document.createElement('div');
	optionChooserClientBorder = document.createElement('div');
	
	optionChooserBack.className='optionChooserBack';
	optionChooser.className='optionChooser';	
	optionChooserClientBorder.className='optionChooserClientBorder';
	
	document.body.appendChild( optionChooserBack );	
	document.body.appendChild( optionChooser );
	document.body.appendChild( optionChooserClientBorder);

}


function showOptionChooser(event)
{
//	info(event);
	
	if (window.currentOptionChooserClient){
		window.currentOptionChooserClient.style.background=window.currentOptionChooserClient.bg;
	}
	
	

	var ll ;
	var tt ;
	
	if (window.ax) {//ie
		ll = getRealLeft( optionChooser.client ) - 2;
		tt = getRealTop( optionChooser.client) - 2;
	}
	else {//firefox
		
		ll = getRealLeft( optionChooser.client ) - 1;
		tt = getRealTop( optionChooser.client ) - 2;
	}
	
	

	optionChooser.style.visibility='visible';
	optionChooser.style.top = tt + ( window.ax ? 0 : 2 );
	if(ll + optionChooser.offsetWidth > document.body.clientWidth ) {
		optionChooser.style.left = ll - optionChooser.offsetWidth  + ( window.ax ? 0 : 2 );	
	}
	else{
		optionChooser.style.left  = ll + optionChooser.client.offsetWidth + ( window.ax ? 0 : 1 );
	}

	if(tt + optionChooser.offsetHeight > document.body.clientHeight  ) {
		optionChooser.style.top = tt - optionChooser.clientHeight  + optionChooser.client.offsetHeight + ( window.ax ? 0 : 2 );	
	}
	else{
		optionChooser.style.top  = tt + ( window.ax ? 0 : 2 );
	}
	
 	
	optionChooser.style.position='absolute';
	
	//return //alert(ll);
	
	optionChooserBack.style.visibility='visible';
	optionChooserBack.style.position='absolute';
	optionChooserBack.style.top = tt ;
	
	if(ll + optionChooser.offsetWidth > document.body.clientWidth ) {
		optionChooserBack.style.left = ll - optionChooser.offsetWidth + ( window.ax ? 0 : 2 );	
	}
	else{
		optionChooserBack.style.left = ll + optionChooser.client.offsetWidth + ( window.ax ? 0 : 1 )  ;
	}
	
	if(tt + optionChooser.offsetHeight > document.body.clientHeight ) {
		optionChooserBack.style.top = tt - optionChooser.clientHeight + optionChooser.client.offsetHeight + ( window.ax ? 0 : 2 );	
	}
	else{
		optionChooserBack.style.top  = tt + ( window.ax ? 0 : 2 );
	}
	
	optionChooserBack.style.width=optionChooser.offsetWidth;
	optionChooserBack.style.height = optionChooser.offsetHeight;


	
	optionChooserClientBorder.style.position='absolute';
	optionChooserClientBorder.style.visibility='visible';
	if (window.ax) {//ie
		optionChooserClientBorder.style.left = ll ;
		optionChooserClientBorder.style.top = tt;
		
	}else {//ff
		optionChooserClientBorder.style.left = ll + 1;	
		optionChooserClientBorder.style.top = tt + 2;
		
	}
	
	optionChooserClientBorder.style.width= optionChooser.client.offsetWidth - ( window.ax ? 0 : 2 );
	optionChooserClientBorder.style.height = optionChooser.client.offsetHeight - ( window.ax ? 0 : 2 ) ;
	optionChooserClientBorder.style.overflow='hidden';
	
	if(ll - optionChooser.offsetWidth > 0 ) {
		//optionChooserClientBorder.style.borderLeft = '1px solid #ffffcc';
		//optionChooserClientBorder.style.borderRight = '1px solid #000000';
	}
	else {
		//optionChooserClientBorder.style.borderRight = '1px solid #ffffcc';
		//optionChooserClientBorder.style.borderLeft = '1px solid #000000';
	}
	
	bg(optionChooser.client);
	optionChooser.client.style.background='#ffffcc';
		
	window.currentOptionChooserClient =  optionChooser.client;
}

function invert(){
	this.color=this.style.color;
	this.bg=this.style.background;

	if (this.overColor){
		this.style.color=this.overColor;
	}
	if(this.overBg){
		this.style.background=this.overBg;		
	}

}
function revert(){
	this.style.color=this.color;
	this.style.background=this.bg;
}



function bg(e){
	if(e.currentStyle){
		e.bg= e.currentStyle.backgroundColor;
		return e.currentStyle.backgroundColor;
	}
	e.bg= e.style.backgroundColor;
	return e.style.backgroundColor;
}
function initCodeAssist(e){
	
	e.pointer=-1;
	var i;
	var arr = e.getElementsByTagName('DIV');
	for(i=0;i<arr.length;i++) {
		arr[i].style.color='000000';
		arr[i].style.backgroundColor='ffffff';
	}
}
function assistedTextBoxKeyUp(assistedTextBox,hiddenInput,codeAssist,componentId,xevent) {
	 
	if(xevent.keyCode==13 || assistedTextBox.enterBlock){
		return;
	}
	var code = xevent.keyCode; 
	var client = codeAssist;
	
	var arr = client.getElementsByTagName('DIV');
	
	if( code == 40 ){ 

		if(arr.length==0) {
			return;
		}

		if(client.pointer>-1)arr[client.pointer].style.backgroundColor='ffffff';
		if(client.pointer>-1)arr[client.pointer].style.color='000000';
		client.pointer++ ;	
		if(client.pointer==arr.length){
			client.pointer = 0;
		}
		arr[client.pointer].style.backgroundColor='ff0000';
		arr[client.pointer].style.color='ffffff';
		return; 
	}
	else if( code == 38 ){ 

		if(arr.length==0) {
			return;
		}

		if(client.pointer>-1)arr[client.pointer].style.backgroundColor='ffffff';
		if(client.pointer>-1)arr[client.pointer].style.color='000000';
		client.pointer-- ;
		if(client.pointer<0){
			client.pointer = arr.length-1;
		}
		arr[client.pointer].style.backgroundColor='ff0000';
		arr[client.pointer].style.color='ffffff';
		return; 
	}
	if(window._to) clearTimeout(window._to);
	window._ref_key = function (){  assistedTextBoxFocus(assistedTextBox,hiddenInput,codeAssist,componentId,xevent)  };
	window._to = setTimeout('window._ref_key()',300);
}

function fireDelayedInputChange(e,code) {
	code= unescape( code );
	var newEvent = '';
	var cid=e.getAttribute("componentId");
	var start = code.indexOf('this');
	var end = start + 4 ;
	var firstPart = code.substring(0,start);
	newEvent += firstPart;
	newEvent += 'searchComponent("'+ cid +'")';
	code = code.substring(end);
	newEvent += code;
	if(window._to) clearTimeout(window._to);
	//window._ref_key = function (){  assistedTextBoxFocus(assistedTextBox,hiddenInput,codeAssist,componentId,xevent)  };
	window._to = setTimeout(newEvent,300);
}


function assistedTextBoxFocus(assistedTextBox,hiddenInput,codeAssist,componentId,xevent){
	
	if(assistedTextBox.getAttribute('currentValue') == assistedTextBox.value && !assistedTextBox.value) {
		codeAssist.style.display='none';
		return;
	}
	
	if(assistedTextBox.getAttribute('currentValue') != assistedTextBox.value 
			|| window._assistedTextBox != assistedTextBox.getAttribute('componentId')) 
	{ 
		assistedTextBox.setAttribute('currentValue',assistedTextBox.value); 
		hiddenInput.value = componentId;
		assistedTextBox.enterBlock=true;
		dynamicSubmitCall(  hiddenInput , xevent  );  
		hiddenInput.value=""; 
		window._assistedTextBox = assistedTextBox.getAttribute('componentId');
	} else if (assistedTextBox.value && codeAssist.getElementsByTagName('DIV').length>0
			|| assistedTextBox.value && codeAssist.getElementsByTagName('SPAN').length==1) 
	{  
		codeAssist.style.display='block';
	}
}

function positionAssistBox(assistClient , codeAssist) {
	
	if(assistClient) {
		codeAssist.style.left = getRealLeft( assistClient ); 
		codeAssist.style.top = getRealTop( assistClient) + assistClient.clientHeight;
	}
}

