function changeCheckbox(pelemid, chelemid) {
	chelid = document.getElementById(chelemid);
	pelid = document.getElementById(pelemid);
	var selindex = pelid.selectedIndex;
	if (selindex != "1") {
    	chelid.disabled = true;
    	chelid.checked = true;
	} else {
		chelid.disabled = false;
	}
}

function advWindow( url ) {
   var width = 850;
   var height = 640;
   var name = url;
   var rand = Math.floor( Math.random()*13254648);
   name = 'aa'+rand;
   var left = Math.floor( ( screen.width / 2 ) - ( width / 2 ) );
   var top = Math.floor( ( screen.height / 2 ) - ( height / 2 ) );
   var winParms = "top=" + top + ",left=" + left + ",height=" + height + ",width=" + width;
   winParms += ",status=no,toolbar=no,menubar=no,location=no,scrollbars=yes";
   var win = window.open(url, name, winParms);
   if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
   return false;
}

function CW(url, height, width, name, parms) {
	var left = Math.floor( (screen.width / 2) - (width / 2) );
	var top = Math.floor((screen.height / 2) - (height / 2) );
	var winParms = "top=" + top + ",left=" + left + ",height=" + height + ",width=" + width;
	if (parms) { winParms += "," + parms; }
	var win = window.open(url, name, winParms);
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
	return win;
}

function resizeWindow(){
	var winWidth = $(window).width() + $(window).scrollLeft();
	if ( winWidth >= 1255 ) {
		if ( $("#container").width() != 1240 ) {
			$("#container").css( 'width', '1240px' );
			$("#lefthalf").css( 'width', '900px' );
		}
	} else {
		$("#container").css( 'width', '980px' );
		$("#lefthalf").css( 'width', '660px' );
	}
}


function openParent( href ) {
	if ( window.opener && window.opener.open && !window.opener.closed ) {
		window.opener.location.href = href;
		window.close();
		return false;
	}
}

function changeContent(changeId, rootDiv) {
	if (document.getElementById) {
		x = document.getElementById(rootDiv).getElementsByTagName('div');
		for (i=0; i<x.length; i++)
			x[i].style.display = (x[i].getAttribute('id') == changeId) ? 'block' : 'none';
	}
	return false;
}

function ConfirmationDialog(value) {
	result = true;
    if (document.getElementById) {
		if (document.getElementById('agreewithrules').checked == false) {
			alert(value);
			result = false;
		}
	}
	return result;
}

var W3CDOM = (document.createElement && document.getElementsByTagName);

function initFileUploads( p1, p2, p3) {
	if (!W3CDOM) return;

	var fakeFileUpload = document.createElement('div');

	fakeFileUpload.className = 'fakefile';

	var image = document.createElement('img');
	
//	image.src='images/rinktis-nuotraukas-' + slang + '.gif';
//	fakeFileUpload.appendChild(image);

	var x = document.getElementsByTagName('input');
	for (var i=0;i<x.length;i++) {

		if (x[i].type != 'file') continue;
		
		if (x[i].parentNode.className != 'fileinputs') continue;
		
		x[i].className = 'file hidden';

//		var clone = fakeFileUpload.cloneNode(true);
		
//		x[i].parentNode.appendChild(clone);
		
//		x[i].relatedElement = clone.getElementsByTagName('img')[0];
		
		x[i].onchange = function () {
//			this.relatedElement.value = this.value;

			if ( p1 != undefined ) {
				formUpload.uploadF( p1, p2, p3);
			} else {
				formUpload.uploadF();
			}
		}
		
	}
}

function wh100()  {
	if (!W3CDOM) return;

	if (jQuery.browser.msie && parseInt(jQuery.browser.version) == 6) {
		$("body").append('<iframe id="ifrsfilter" src="#" scrolling="no" frameborder="0"></iframe>');
	}
	
	$("body").append('<div id="wh100" style="display: none;"></div>');
	$("body").append(isfilt);
	
	$('#wh100').show();

	centerThis('sfilter');
	$('#sfilter').show();
	$('#sfilter').focus();
}

function centerThis( div ) {
    var winH = $(window).height();
    var winW = $(window).width();
    var centerDiv = $('#' + div);
	
    centerDiv.css('top', (winH/2- (centerDiv.height()/2) )+getScrollY() );
	centerDiv.css('left', ( winW / 2 ) - ( centerDiv.width() / 2 ) );
	
}

function wh100close()  {
	if (!W3CDOM) return;
	document.body.removeChild( document.getElementById('sfilter') );
	if (jQuery.browser.msie && parseInt(jQuery.browser.version) == 6) {
		document.body.removeChild( document.getElementById('ifrsfilter') );
	}
	document.body.removeChild( document.getElementById('wh100') );
}