function advOpen(openUrl, openWidth, openHeight, openSwitch) {
    var srw = screen ? (screen.width-50)    : 750;
    var srh = screen ? (screen.height-36)   : 564;
    var openScroll  	= "0";
	var documentWrite	= "";
	var	openParameters	= "";
    if ((openWidth>srw) || (openHeight>srh)) {
        openScroll  = "1";
        if (openHeight>srh) { openWidth  = openWidth+16; openHeight = srh-50; }
        if (openWidth>srw)  { openHeight = openHeight+16; openWidth = srw-50; }
    }
    
    srw     = (srw - openWidth)/2;
    srh     = (srh - openHeight)/5;
    
  	var UTCstring;
  	Today = new Date();
  	UTCstring = Today.getUTCHours()*Today.getUTCMinutes()*Today.getUTCSeconds();
	
	var openName;
	openName        = "openPopup"+UTCstring;
    openParameters  = "left="+srw+",top="+srh+",outerHeight=0,innerWidth,width="+openWidth+",innerHeight,height="+openHeight+",scrollbars="+openScroll+",titlebar=1,resizable=0";
    switch(openSwitch) {
        case "print":   openParameters  = "left="+srw+",top="+srh+",outerHeight=0,innerWidth,width="+openWidth+",innerHeight,height="+openHeight+",scrollbars=1,titlebar=1,resizable=0,menubar=1"; break;
        case "scroll":  openParameters  = "left="+srw+",top="+srh+",outerHeight=0,innerWidth,width="+openWidth+",innerHeight,height="+openHeight+",scrollbars=1,titlebar=1,resizable=0"; break;
		case "printNow": 
			documentWrite	= '<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">function startPrint() { var pr=(window.print)?1: 0; if (pr) { window.print(); } else { alert("Can\'t Print"); } }</SCRIPT>'
			openParameters  = "left="+srw+",top="+srh+",outerHeight=0,innerWidth,width="+openWidth+",innerHeight,height="+openHeight+",scrollbars=1,titlebar=1,resizable=0"; break;
		case "pic":
			openParameters  = "scrollbars=0,titlebar=0,resizable=0"; break;
    }
    var openPopup   = open(openUrl, openName, openParameters);
	if (documentWrite.length>0) {
		$window	= openPopup;
		self.setTimeout('printPageDistant()', 2000);
	}
	
    return false;
}

function printPage() {
    var pr = (window.print) ? 1 : 0;
    if (pr) // NS4, IE5
        window.print()
    else if (da && !mac) // IE4 (Windows)
        vbPrintPage()
    else // muut
        alert("Can't Print");
}

function XHTMLRequest() {
	var $http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		$http_request = new XMLHttpRequest();
	} else if ( window.ActiveXObject ) { // IE
    	try {
    		$http_request = new ActiveXObject("Microsoft.XMLHTTP");
        	
        } catch (e) {
        	try {
            	$http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {}
        }
	}
	return $http_request;
}

function loadCalendar( $timestamp ) {
    
	var $http_request = XHTMLRequest();
	if ( !$http_request ) {
		return false;
    }
    $http_request.onreadystatechange = function() { alertContents($http_request); };
    $http_request.open( 'GET', '/tools/main_page_calendar.php?timestamp=' + $timestamp + '&lang=' + $clang + '&date=' + document.getElementById( 'date' ).value, true);
    $http_request.send(null);
    resizeTopImage();
}

function alertContents($http_request) {
	if ($http_request.readyState == 4) {
    	if ($http_request.status == 200) {
        	document.getElementById('frame').innerHTML = $http_request.responseText;
        } else {
        	document.getElementById('frame').innerHTML = '';
		}
	}
}

// RF_FOTO_OPEN
scrolltimer = null;
function scroll(speed) {
	var page = document.getElementById("scroller");
	page.scrollLeft += speed;
	if (!scrolltimer){
		scrolltimer = window.setInterval("scroll("+speed+")", 5);
	}
}
	
function stopScroll(){
	window.clearInterval(scrolltimer);
	scrolltimer = null
}
	
function higlightSmallPicture( number, show ) {
	pic = document.getElementById('pic'+number);
	//pic.src = 'images/content/foto-open-small-' + ( show == true ? 'active' : 'inactive' ) + '.jpg';
	if( show == true ) {
		pic.className = 'active';
	} else {
		pic.className = 'inactive';
	}
}

var $active = 1;

function showPicture( $src, $author, $title, $id ) {
	$season = document.getElementById('sez').value;
	$authorcap = document.getElementById('aut').value;
	document.getElementById( 'big-picture' ).src = '/images/galleries/big/' + $src;
	document.getElementById( 'foto-name' ).innerHTML = ( $title != '' ? $title : '&nbsp;' );
	document.getElementById( 'foto-name-icon' ).innerHTML = ( $title != '' ? '<img src="/images/'+$season+'/rf-foto-open-icon.gif" alt="" />' : '&nbsp;' );
	document.getElementById( 'foto-author' ).innerHTML = ( $author != '' ? $author : '&nbsp;' );
	document.getElementById( 'foto-name-icon' ).innerHTML = ( $title != '' ? '<img src="/images/'+$season+'/rf-foto-open-icon.gif" alt="" />' : '&nbsp;' );
	document.getElementById( 'foto-author-cap' ).innerHTML = ( $author != '' ? $authorcap : '&nbsp;' );
	$active = $id;
}

function showNext( $next ) {
	$season = document.getElementById('sez').value;
	$authorcap = document.getElementById('aut').value;
	if( $active == 1 && $next == -1 ) {
		return;
	}
	if ( $active == $picturesSrc.length - 1 && $next == 1 ) {
		return;
	}
	$active += $next;
	document.getElementById( 'big-picture' ).src = '/images/galleries/big/' + $picturesSrc[$active];
	document.getElementById( 'foto-name' ).innerHTML = $picturesTitle[$active];
	document.getElementById( 'foto-name-icon' ).innerHTML = ( $picturesTitle[$active] != '' ? '<img src="/images/'+$season+'/rf-foto-open-icon.gif" alt="" />' : '&nbsp;' );
	document.getElementById( 'foto-author' ).innerHTML = $picturesAuthor[$active];
	document.getElementById( 'foto-author-cap' ).innerHTML = ( $picturesAuthor[$active] != '' ? $authorcap : '&nbsp;' );
}

function showBigPicture() {
	window.Popup = window.open( '/lat/full_image/?src=' + $picturesFullSrc[$active],'','width=' + $picturesX[$active] + ',height=' + $picturesY[$active] + ',scrollbars=0,titlebar=0,resizable=1,menubar=0,top=100' );
	window.Popup.focus();
}

// END RF_FOTO_OPEN

// RF_FORUM_ADDCOMMENT
function count( obj ) {
	if( obj.value.length > 1000 ) {
		obj.value = obj.value.substring(0,1000);
		alert( 'Maksimālais komentāra garums ir 1000 simboli!' );
	}
	document.getElementById( 'lenght' ).innerHTML = 1000 - obj.value.length;
}
// END RF_FORUM_ADDCOMMENT

function showElement( id ) {
	var c = document.getElementById( id );
	c.style.display = ( c.style.display == 'none' ? '' : 'none' );
}

function resizeTopImage() {
    var img = document.getElementById('topimage');
    if(img) {
        if(img.width>400) {
            img.style.width = '400px';
        }
    }
}
