/** HELP BOX */
var HELPiframe;
var HELPtimer;
function getiframeReady(){
	try{
		if( HELPiframe && HELPiframe.contentWindow && HELPiframe.contentWindow.document && HELPiframe.contentWindow.document.readyState ){
			clearInterval( HELPtimer );
			HelpBox( HELPiframe );
		}
	} catch( e ){
	}
}

function HelpBox( el, type ){
	if( typeof el == 'string' ){
		HELPiframe = document.createElement('iframe');
		HELPiframe.style.border = 'none';
		HELPiframe.style.display = 'none';
		//iframe.style.overflow = 'x';
		HELPiframe.setAttribute( 'scrolling', 'vertical' );
		HELPiframe.setAttribute( 'onload', 'HelpBox(this)' );
		HELPiframe.onload = HelpBox;
		this.lang = document.documentElement.getAttribute( 'lang' );
		this.type = document.documentElement.getAttribute( 'manualType' );
		if( type )
			this.type = type;
		var src = '../../projekt/web/help/'+this.lang+'/';
		if( this.type ){
			src += this.type+'/';
		}
		src += 'manual.htm'+( ( el != '#' ) ? '#'+el : '' );
		HELPiframe.src = src;
		HELPiframe.savedTarget = el;
		questioner.iframe = HELPiframe;
		document.body.appendChild( HELPiframe );
		HELPiframe.onreadystatechange = function( e, el ){
			if( HELPiframe.readyState == 'complete' ){
				HelpBox( HELPiframe );
			}
		}
		return false;
	}
	else{ 
		var buttons = Array();
		var button;
		button = {
			sButtonName : 'close', 
			sButtonString : 'Bezár', 
			fnCallBack : questioner.fnClose, 
			elLink: null
		};
		buttons.push( button );
		questioner.create( 9999, buttons, HELPiframe.contentWindow.document.body );
		var textBoxLinks = questioner.textBox.getElementsByTagName( 'a' );
		
		for( var i = 0, len = textBoxLinks.length; i < len; i++ ){
			if( RegExp( HELPiframe.savedTarget ).test( textBoxLinks[i].name ) ){
				var realOffsetParent = questioner.containerDiv
				questioner.textBox.scrollTop = 0;
				var offset;
				do{
					if( offset == null ){
						offset = textBoxLinks[i];
					}else{
						offset = offset.offsetParent;
					}
					questioner.textBox.scrollTop += offset.offsetTop;
				}while( offset.offsetParent != questioner.containerDiv )
				
				questioner.textBox.scrollTop -= 25
				
				break;
			}
		}
	}
}
var questioner = {
	backgroundDiv: null,
	pageSize:null,
	scrollSize:null,
	pgFrame:null,
	containerDiv:null,
	questionDiv:null
};
questioner.createOverlay = function ( zIndex ){
	questioner.backgroundDiv = document.createElement( 'div' );
	/* Beállítjuk az elemeket */
	questioner.backgroundDiv.className="proform confirm background"
	questioner.backgroundDiv.align='center';
	questioner.pageSize=getPageSize();
	questioner.scrollSize=getPageScroll();
	questioner.pgFrame=document.getElementById('pg');
	//questioner.pgFrame=document.getElementById('pg-frame');
	questioner.backgroundDiv.style.height=questioner.pageSize[1]+"px";  
	pgFrame = questioner.pgFrame.offsetWidth;
	if( zIndex !== null ){
		questioner.backgroundDiv.style.zIndex = zIndex;
	}
	questioner.backgroundDiv.style.width=((pgFrame > questioner.pageSize[0])? pgFrame : questioner.pageSize[0])+"px";  
	if(is.ie){
		questioner.backgroundDiv.style.filter='alpha(opacity=80)';
	}
	addClass( questioner.backgroundDiv, 'overlay' );
	document.body.backgroundDiv=questioner.backgroundDiv;
	return questioner.backgroundDiv;
}
questioner.createConfirmBox = function( zIndex ){
	if( questioner.pageSize == null )
		questioner.pageSize=getPageSize();
	if( questioner.scrollSize == null )
		questioner.scrollSize=getPageScroll();
	questioner.containerDiv = document.createElement( 'div' );
	questioner.containerDiv.className="proform confirm question"
	questioner.containerDiv.id="containerDiv";
	questioner.containerDiv.style.top=((questioner.pageSize[3]/2)-50)+'px';
	questioner.containerDiv.align='center';
	questioner.containerDiv.style.zIndex = zIndex;
	document.body.containerDiv=questioner.containerDiv;
	return questioner.containerDiv;
}
questioner.createQuestionDiv = function(){
	questioner.questionDiv = document.createElement('div');
	questioner.questionDiv.id = 'questionDiv';
}
questioner.createQuestionForm = function(){
	questioner.questionForm = document.createElement('form');
	questioner.questionForm.id = 'questionForm';
}
questioner.createTextBox = function( element ){
	if( element == null )
		element = 'p';
	questioner.textBox = document.createElement( element );
	questioner.textBox.id = 'textBox';
	if( element == 'p' ){
		questioner.textBox.style.fontWeight='bold';
	}
	questioner.textBox.style.paddingBottom='10px';
}
questioner.createTextEl = function( textEl ){
	if (typeof textEl == 'string') {
		questioner.createTextBox();
		questioner.textBox.appendChild(document.createTextNode(textEl).cloneNode(true));
	}else{
		questioner.createTextBox( 'div' );
		questioner.textBox.innerHTML = textEl.innerHTML;
		questioner.textBox.style.overflow = 'auto';
		//questioner.textBox.style.maxHeight = '200px';
		questioner.textBox.style.marginBottom = '10px';
		questioner.textBox.style.border = 'none';
		questioner.textBox.align='left';
		//questioner.questionDiv.style.paddingRight='31px';
	}
}
  

questioner.hideSelect = function(){
  var hide = 'hidden';
  /* össze szedjük az összes SELECT elemet és eltüntetjük */
  questioner.objsSelect=document.getElementsByTagName('select');
  objsSelectL=questioner.objsSelect.length;
  objsSelectL--;
  if (is.ie)
	hide = 'hidden';
	
  for ( var i=objsSelectL; i>=0 ; i-- ){
	questioner.objsSelect[i].style.visibility=hide;
  }
}

questioner.create = function( zIndex, buttons, textEl ){
	questioner.hideSelect();
	questioner.createOverlay( zIndex++ );
	questioner.createConfirmBox( zIndex++ );
	questioner.createQuestionDiv( zIndex++ );
	questioner.createQuestionForm( zIndex++ );
	questioner.createTextEl( textEl );
	questioner.questionForm.appendChild(questioner.textBox);
	var button;
	for (i = 0; i < buttons.length; i++) {
		button = questioner.createButton( buttons[i].sButtonName, buttons[i].sButtonString, buttons[i].fnCallBack, buttons[i].elLink );
		questioner.questionForm.appendChild( button );
	}
	
	questioner.questionDiv.appendChild( questioner.questionForm );
	questioner.containerDiv.appendChild( questioner.questionDiv );
	document.body.appendChild(questioner.backgroundDiv);
	document.body.appendChild(questioner.containerDiv);
	questioner.containerDiv.style.top =((questioner.pageSize[3]/2)- ( questioner.questionDiv.offsetHeight / 2 ) )+'px';
	return questioner.textBox;
}

questioner.fnCancel = function(){
  questioner.close();
  return true;  
};


questioner.fnClose = function(){
	document.body.removeChild( questioner.backgroundDiv );
	document.body.removeChild( questioner.containerDiv );
	if( isset( questioner.iframe ) ){
		questioner.iframe.parentNode.removeChild( questioner.iframe );
	}
	for ( var i=questioner.objsSelect.length-1; i>=0 ; i-- ){
		questioner.objsSelect[i].style.visibility='visible';
	}
//	document.body.style.overflow="auto";
	
	return true;  
};

questioner.createButton = function( sButtonName, sButtonString, fnCallBack, elLink ){
	questioner[ sButtonName ] = document.createElement( 'input' );
	questioner[ sButtonName ].type = "button";
	questioner[ sButtonName ].value = sButtonString;
	questioner[ sButtonName ].className = "proform-primary confirm";
	questioner[ sButtonName ].onclick = fnCallBack;
	questioner[ sButtonName ].elLink = elLink;
	return questioner[ sButtonName ];
}  

