// JavaScript source code

// GlobalJs.inc must already be included
// Transheader.inc must be included 


var sVisParam = '&visible=';	
// PURPOSE: OVERRIDES DEFAULT VISIBILITY VALUES OF GIVEN ELEMENTS.
// EXAMPLE: 'visible=div1;div2;...'

function isVisible(id) {
	return document.getElementById(id).style.display != 'none' &&
		document.getElementById(id).style.display != '' ;
}//isVisible()

function setVisible(id)	{
document.getElementById(id).style.display =	'';
	if(sVisParam.indexOf(id) == -1) {
		sVisParam += id + ';';
	}//if
}//setVisible()

function setInvisible(id) {
	document.getElementById(id).style.display =	'none';
// DELETE IT FROM sVisParam:
	while(sVisParam.indexOf(id) != -1) {
		sVisParam = sVisParam.replace(id+';' , '');
	}//while
}//setInvisible()


function toggleVisibility(id) {
	if(!isVisible(id)) {
		setVisible(id);
	} else {
		setInvisible(id);
	}
}//toggleVisibility()




function setIdsVisible(sVisible)
// sVisible IS A LIST OF STRINGS SEPARATED BY A ';'
// EXAMPLE: 'div1;div2;div3;table1;form38;'
{
	var sVisibleIds = sVisible.split(';');
	for(var i in sVisibleIds) {
		var s = sVisibleIds[i];
		if(sVisibleIds[i] != '') {	
			if(document.getElementById(s) != null) {
				setVisible(sVisibleIds[i]);
			} else {
// IF SHOULD BE VISIBLE, BUT CURRENTLY NOT ON PAGE (BECAUSE THE ASP
// ENGINE DIDN'T GENERATE THIS ELEMENT) THEN INDICATE THAT IT STILL SHOULD
// BE VISIBLE IN THE FUTURE BUT DON'T TRY TO MAKE IT VISIBLE ON THIS PAGE:
				sVisParam += s+';';
			}//if-else
		}//if
	}//for
}

function formatName(sName)
// sName is in 'LastName, FirstName' format
// result is in 'LastName, FirstName' format
{
//	var sNames = sName.split(',');
//	return sNames[1].substr(1) + ' ' + sNames[0];
	return sName
}//formatName()

function getCurrentFile() {

	var sUrl = location.pathname;
	var sSections = sUrl.split('/');
	return sSections[sSections.length-1];
}//getCurrentFile()


function isNumeric(c) 
	// c: a character, i.e. a string that has a length of 1
	//		if it is shorter or longer, the result may (possibly) 
	//		be incorrect.
{	
	var sNumericChars = '01234567890';
	var result = (sNumericChars.indexOf(c) != -1);
	return result;
}//isNumeric(c) 


function removeAlpha(s, bPlusMinus, bDecimalPoint)
	// returns a string that contains only the numeric values
	// that were in s (keeping the order of them).
	// removes all non-numeric characters
	
	// parameters:
	
	// s: the string from which the non-numeric characters should be removed.
	
	// bPlusMinus (optional): if true then the number may begin with
	// a '+' or a '-'.
	
	// bDecimalPoint (optional): if true then the number may contain a . 
{
	var sResult = '';
	var i=0;
	if (bPlusMinus && s.length > 0 && 
		(s.charAt(0)=='+' || s.charAt(0)=='-')) 
	{
		sResult += s.charAt(i);
		i=1;
	}//if
	var wasDecimalPoint = false;
	for(;i<s.length;++i) {
		if(isNumeric(s.charAt(i))) { 
			sResult += s.charAt(i); 
		} else {
			if(bDecimalPoint) {
				if((!wasDecimalPoint) && (s.charAt(i) == '.')) {
					sResult += s.charAt(i);
					wasDecimalPoint = true;
				}//if '.'
			}//if(bDecimal)
		}//if-else
	}//for
	return sResult;
}//removeAlpha(s)

function setTvFrame(frame_id) 
// frame_id : id of the frame in which the current document is
// included.

// when putting a tableview in an iframe, call this function
// and it sets the size of the frame to the appropriate value.
// if you call this function from a non-frame tableview, it
// does nothing.
{
//alert('setTvFrame('+frame_id+')');
	var tv_frame = null;
	if( parent != null) {
		if( parent.document != null ) {
			tv_frame = parent.document.getElementById(frame_id);
		}//if
	}//if
	if(tv_frame != null) {
		tv_frame.style.height = document.body.scrollHeight;
		document.body.style.backgroundColor = '#CDCE95';
	}//if
	
}//setTvFrame() 



function startsWith(str1, str2)
{
	return str1.substring(0, str2.length) == str2;
}



function LTrim(p_strValue)
{
	for(i=0; i<p_strValue.length; i++)
	{
		if(p_strValue.charCodeAt(i)!=32)
			return p_strValue.substr(i);
	}
	return '';	
}


function adjustDialogSize(wnd)
	// sets the size of the dialog so that all of its contents fit into
	// the window
	
	// wnd is a window object. If null then the size of the current window's
	// content will be taken
{
  
	dialogHeight = '1px';
	dialogWidth = '1px';
	var doc;
	
	if(wnd) { doc = wnd.document; } else { doc = document; }
//alert(doc);
var clientHeight = 0, clientWidth = 0, width = 0, height = 0 ;
    if (navigator.appName == "Microsoft Internet Explorer") {  
    //IE 6+ in 'standards compliant mode'  
      clientWidth = doc.body.clientWidth;
      clientHeight = doc.body.clientHeight; 
      width = doc.body.scrollWidth; 
      height = doc.body.scrollHeight;
   } else { 
   //Non-IE  
     clientWidth = window.innerWidth;  
     clientHeight = window.innerHeight; 
     width = clientWidth + window.scrollMaxX;  
     height = clientHeight + window.scrollMaxY;

     }
 
	//var clientHeight = doc.body.outerHeight;
	//var clientWidth = doc.body.clientWidth;
	
//	var xDiff = dialogWidth.replace('px','') - clientWidth;
//	var yDiff = dialogHeight.replace('px','')  - clientHeight;
	

//	width += xDiff;
//	height += yDiff;
	//alert(width+' '+height);
	dialogWidth = width + 'px';
	dialogHeight = height + 'px';
	dialogLeft = ((screen.availWidth - width) / 2) + 'px';
	dialogTop = ((screen.availHeight - height) / 2) + 'px';

    window.innerWidth = width;
    window.innerHeight = height;
    
}//adjustDialogSize()


function adjustWindowSize(wnd) {
//alert('adjustWindowSize()');

	var doc;
	if(wnd) { doc = wnd.document; } else { doc = document; }
	window.resizeTo(doc.body.scrollWidth, doc.body.scrollHeight + 140);
		// there's no way to obtain the whole window's size in IE.
	window.moveTo(40, 30);
}

function getDateString(year, month, day, nLanguage)
	// nLanguage: if 0 then general format (YYYY.MM.DD) is returned.
{
//alert('getDateString '+year+' '+month+' '+day);
	if(isNaN(nLanguage)) { nLanguage = 0; } 
	nLanguage = parseInt(nLanguage);
	if (year=='') return '';
	switch(nLanguage) {
		case 0:
		case Language_Hungarian:
			return stringWide(year, 4, '0') + '.' + 
					stringWide(month, 2, '0') + '.' + 
					stringWide(day, 2, '0');
			break;
		case Language_English:		// English
			return stringWide(day, 2, '0') + '.' + 
					stringWide(month, 2, '0') + '.' + 
					stringWide(year, 4, '0');
			break;
	}//switch(nLanguage) 

}//getDateString()

function isValidEmail(str)
{
	if (str == '') { return true; }
	var pos = str.indexOf('@');
	if(pos == -1) { return false; }
	if(pos == 0) { return false; }
	if(pos == str.length-1) { return false; }
	if(pos != str.lastIndexOf('@')) { return false; }
	return true;
}//isValidEmail(str)


function disableAllInputs(oRoot) {
	if(oRoot == null) { oRoot = document; }
	var sDebug = '';
	for(var i in oRoot.childNodes) {
		var o = oRoot.childNodes[i];
		var s = o.tagName;
		if(s != null) {
sDebug += s + ' ';		
			switch(s.toUpperCase()) {
				case 'INPUT':
				case 'BUTTON':
				case 'TEXTAREA':
					o.disabled = true;
					break;
				case 'SELECT':
					if(!o.multiple) {
						o.disabled = true;
					}//if
					break;
				default:
					disableAllInputs(o);
			}//switch
		}
if(o.name != null) { sDebug += o.name + '\n'; }
	}//for
//alert(sDebug);
}//disableAllInputs()


function enableAllInputs(oRoot) {
	if(oRoot == null) { oRoot = document; }
	var sDebug = '';
//alert(oRoot.tagName);
	for(var i in oRoot.childNodes) {
		var o = oRoot.childNodes[i];
		var s = o.tagName;
		if(s != null) {
			switch(s.toUpperCase()) {
				case 'INPUT':
				case 'BUTTON':
				case 'TEXTAREA':
					o.disabled = false;
//sDebug += s + ' ';
					break;
				case 'SELECT':
					o.disabled = false;
					break;
				default:
					enableAllInputs(o);
			}//switch
		}
	}//for
//alert(sDebug);
}//enableAllInputs(oRoot)


function sortSelectByText(oSelect)
	// gives correct result only if there is no duplication in 
	// either the values or the texts.
{
	var aOptionTexts = new Array();
	var aOptionValues = new Array();
	var aOptionSelected = new Array();
	var sText;
	for(var iOption=0; iOption < oSelect.length; ++iOption) {
		sText = oSelect[iOption].text;
		aOptionTexts[iOption] = sText;
		aOptionValues[sText] = oSelect[iOption].value;
		aOptionSelected[sText] = oSelect[iOption].selected;
	}//for
	aOptionTexts.sort();
	for(var iText in aOptionTexts) {
		sText = aOptionTexts[iText];
		oSelect[iText].text = sText;
		oSelect[iText].value = aOptionValues[sText];
		oSelect[iText].selected = aOptionSelected[sText];
	}//for
}//sortSelectByText(oSelect)


function forceTextAreaMaxLength(oTextArea, nLength) 
// call this function if you want to maximize the length of a
// TEXTAREA element. 
// Make it handle the ONKEYPRESS, ONPASTE and ONDROP events.
{
	var sInsertFailed = 'The text you are trying to insert ' +
		'would make the content of the field longer than ' +
		nLength + '!';
	switch(event.type) {
		case 'keypress':
			if(oTextArea.value.length >= nLength) {
				event.returnValue = false;
			}//if
			break;
		case 'paste':
			if(oTextArea.value.length > 
					nLength - 
						window.clipboardData.getData('Text').
							length	)
			{
				alert(sInsertFailed);
				event.returnValue = false;
			}//if
			break;
		case 'drop':
			if(oTextArea.value.length > 
				nLength - 
					event.dataTransfer.getData('Text').length	)
			{
				alert(sInsertFailed);
				event.returnValue = false;
			}//if
	}//switch(event.type) 
}//forceTextAreaMaxLength(oTextArea, nLength) 
		

function stringWide(str, nWidth, cPadding)	// returns String
// returns a string that is exactly nWidth characters long
// if str is longer than nWidth, then the end is chopped down.
// if it is shorter, then cPadding characters are appended to the front.
{
//alert('stringWide '+str+' '+nWidth+' '+cPadding);
	var result = str;
	if(('' + result).length < nWidth) {
		while(('' + result).length != nWidth) {
			result = cPadding + result;
//alert(result+' '+nWidth);
		}//while
	} else {
		result = ('' + result).substr(0, nWidth);
	}//if-else
	return result;
}


function selectAllOptions(oSelect)
// oSelect.multiple must be true.
{
	for(var i=0; i<oSelect.length; ++i) {
		oSelect[i].selected = true;
	}//for
}//selectAllOptions(oSelect)


function sinkButton(oElement){
	oElement.className = oElement.className + ' button_mousedown';
//alert(oElement.className);
//alert(oElement.style.paddingLeft);
//	var paddingLeft = oElement.style.paddingLeft.replace('px', '')
//	oElement.style.paddingLeft = (paddingLeft + 10) + 'px';
//	var paddingTop = oElement.style.paddingTop.replace('px', '')
//	oElement.style.paddingTop = (paddingTop + 5) + 'px';
//oElement.style.backgroundColor = 'Black';	
}

function raiseButton(oElement){
	oElement.className = oElement.className.replace('button_mousedown', '');
	
	
//alert(oElement.style.paddingLeft);
//	var paddingLeft = oElement.style.paddingLeft.replace('px', '')
//	oElement.style.paddingLeft = (paddingLeft - 10) + 'px';
//	var paddingTop = oElement.style.paddingTop.replace('px', '')
//	oElement.style.paddingTop = (paddingTop - 5) + 'px';
//oElement.style.backgroundColor = 'White';	
}



var bFunctionsJsIncluded = true;

function window.onbeforeprint()
{
    var IFrameColl = document.all.tags("iframe");
    var FrameDiv;
    
    if (IFrameColl != null)
    {
        for (i = 0; i < IFrameColl.length; i++)
        {                
            IFrameColl[i].style.display = "none";
            FrameDiv = document.createElement("DIV");
            FrameDiv.id = "FrameDiv"+i;
            FrameDiv.name = "FrameDiv"+i;                
            FrameDiv.innerHTML = IFrameColl[i].contentWindow.document.body.innerHTML;
            IFrameColl[i].parentNode.insertBefore(FrameDiv);
        }            
    }  
}

function window.onafterprint()
{
    var IFrameColl = document.all.tags("iframe");
           
    if (IFrameColl != null)
    {
        for (i = 0; i < IFrameColl.length; i++)
        {        
            document.getElementById("FrameDiv"+i).removeNode(true);                
            IFrameColl[i].style.display = "block";
        }
    }
}

