
function fnStartup() {
	window.setInterval( fnSetDateTime, 60000 );
}

function fnItemOver( intE, objI, intType ) {

	var strBColor = '';
	if ( intE == 0 ) {
		switch( intType ) {
			case 1: strBColor = '#DCBA5E'; break;
			case 2: strBColor = '#F3E9C7'; break;
			case 3: strBColor = '#4C1201'; break;
		}
	}
	else {
		switch( intType ) {
			case 1: strBColor = '#B0954B'; break;
			case 2: strBColor = '#DCBA5E'; break;
			case 3: strBColor = '#9C4829'; break;
		}
	}
	if ( strBColor == '' )
		return;

	objI.style.backgroundColor = strBColor;
}

function fnItemClick( intID, intType  ) {
	document.location = gstrServer + '/view.asp?' + ((intType == 1) ? 'tree' : 'doc') + '=' + intID + '&ts=' + (100 * Math.random());
}

function fnSetDateTime() {

	intDateTimeCR += 60000;
	getObj('idDTCR').innerHTML = fnPrepareDateTime( intDateTimeCR );

	intDateTimeNZ += 60000;
	getObj('idDTNZ').innerHTML = fnPrepareDateTime( intDateTimeNZ );
}

function fnPrepareDateTime( intMS ) {

	var dat = new Date( intMS );
	var strDT = fnRight('0' + dat.getDate(), 2) + '.' + fnRight('0' + (dat.getMonth() + 1), 2) + '.' + dat.getYear() + ' ' + fnRight('0' + dat.getHours(), 2) + ':' + fnRight('0' + dat.getMinutes(), 2);

	return strDT;
}

function fnDiscussionAdd( intD, intP ) {
	document.location = gstrServer + '/reaction.asp?docid=' + intD + '&reaid=' + intP + '&state=1&ts=' + (100 * Math.random());
}

function fnDiscussionShow( intD, intR ) {

	var strDList = '';
	if ( intR == 1 ) {
		strDList = fnGetDiscussionList( false );
		
		if ( strDList == '' ) {
			fnGetDiscussionList( true );
			intR = -1;
		}
	}

	document.location = gstrServer + '/discussion.asp?docid=' + intD + '&range=' + intR + '&dlist=' + strDList + '&ts=' + (100 * Math.random());
}

function fnGetDiscussionList( blnCheck ) {

	var colDItems = getObj('idDiscussionStore').getElementsByTagName('input');
	var strReturn = '';
	
	for ( var i = 0; i < colDItems.length; i++ ) {
	
		if ( colDItems[i].name == 'thisonly' ) {
			var objI = colDItems[i];
			
			if ( blnCheck )
				objI.checked = true;
				
			if ( objI.checked )
				strReturn += objI.value + ',';
		}
	}

	if ( strReturn != '' )
		strReturn = strReturn.substr(0, strReturn.length - 1);

	return strReturn;
}


function getObj( strID ) {
	var obj = document.getElementById(strID);
	return obj;
}

function isEmptyInputMSG( objI, strMSG, strMSG2 ) {

	if ( objI.value == '' ) {
		alert( 'Vyplòte prosím pole - ' + strMSG + ' - !' )
		objI.focus();
		return false;
	}
	return true;	
}


function fnRight( strExpr, intCount ) {
	return strExpr.substr( strExpr.length - intCount );
}

function fnImageDetail( strIPath ) {
	window.open( gstrServer + '/lib/image.asp?ipath=' + strIPath + '&ts=' + (100 * Math.random()), '_blank', 'width=200, height=200, status=yes' )
}

function fnSearch() {
	
	var strSearch = getObj('xSearch').value;
	if ( strSearch == '' )
		return;
		
	document.location = gstrServer + '/search.asp?search=' + escape(strSearch) + '&ts=' + (100 * Math.random());
}

function isEmail( strExpr ) {

	var intLen = strExpr.length;
	if ( intLen < 7 )
		return false;
	var strD3 = strExpr.substr( intLen - 3, 1 ), strD4 = strExpr.substr( intLen - 4, 1 ), strD5 = strExpr.substr( intLen - 5, 1 )
	if ( (strD3 != '.') && (strD4 != '.') && (strD5 != '.') ) 
		return false;
	var strValid = '0123456789_-.@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
	var intCount = 0;
	var blnNoValid = false;
	for ( var i=0; i < strExpr.length; i++) {
		var str1 = strExpr.substr( i,1 )
		if ( strValid.indexOf( str1 ) == -1 ) {
			var blnNoValid = true;
			break;
		}
		if ( str1 == '@' )
			intCount += 1;
	}
	if ( blnNoValid )
		return false;
	if ( intCount != 1 )
		return false;
	return true;
}

function fnShowSection(intS) {
	getObj('idSection1').style.display = 'none';
	getObj('idSection2').style.display = 'none';
	getObj('idSection' + intS).style.display = '';
}