// общие скрипты

function OpenWindow( sUri, iWidth, iHeight, connectionError )
{
	var errorCode = parseInt(connectionError);
	if ( isNaN(errorCode) ) {errorCode = 0}
	if( errorCode != 0 || isNaN(errorCode) )
	{
		alert('ОШИБКА!\nВ настоящий момент нет связи с базой данных АНКОР.\nПопробуйте повторить попытку позже.')
		return null
	}
	else
	{
		var sWindowName = 'win' + Math.floor( Math.random()*1000 )
		var iRealWidth = iWidth ? iWidth : 600
		var iRealHeight = iHeight ? iHeight : screen.height - 300
	
		var iLeft = Math.round( (screen.width-iRealWidth)/2 )
		var iTop =  Math.round( (screen.height-iRealHeight)/2 ) - 35
	
		var sWindowOptions = 'status=yes,menubar=no,toolbar=no'
		sWindowOptions += ',resizable=yes,scrollbars=yes,location=no'
		sWindowOptions += ',width='  + iRealWidth
		sWindowOptions += ',height=' + iRealHeight
		sWindowOptions += ',left='   + iLeft
		sWindowOptions += ',top='    + iTop
	
		var win = window.open( sUri, sWindowName, sWindowOptions )
		win.focus()
	
		return win
	}
}


function CloseWindow()
{
	if( window.opener )
	{
		window.opener.top.location.href = window.opener.top.location.href + '?%20'
		window.opener.focus()
	}
	window.close()
	return false
}


function ChangeImg( ImgID, ImgUrl )
{
	var oImg = document.getElementById(ImgID)
	if( oImg )
	{
		oImg.src = ImgUrl
	}
}

function ChangeStateDisable( oStateController, oIdStateToChange )
{ 
	var oStateToChange = document.getElementById(oIdStateToChange);
	if( oStateToChange )
	{
		oStateToChange.disabled = oStateController.checked
	}
}

function SetStateChecked(sFormName, sFormElementName)
{
	var aCheeckBoxes = document.forms[sFormName].elements[sFormElementName]
	for( var i=0; i < aCheeckBoxes.length; i++ )
	{
		aCheeckBoxes[i].checked = true
	}
}
function SetStateUnChecked(sFormName, sFormElementName)
{
	var aCheeckBoxes = document.forms[sFormName].elements[sFormElementName]
	for( var i=0; i < aCheeckBoxes.length; i++ )
	{
		aCheeckBoxes[i].checked = false
	}
}

function LoadXml( sUrl )
{
	var oXMLHttpRequest

	// MSIE?
	try { oXMLHttpRequest = new ActiveXObject('Msxml2.XMLHTTP') }
	catch ( oError )
	{
		// Mozilla?
		try { oXMLHttpRequest = new XMLHttpRequest() }
		catch ( oError ) { return null }
	}

	oXMLHttpRequest.open('GET', sUrl, false)
	oXMLHttpRequest.setRequestHeader('If-Modified-Since', 'Thu, 22 Nov 2001 00:00:01 GMT')
	oXMLHttpRequest.send(null)
	return oXMLHttpRequest.responseXML
}

function getVote()
{
	var voteIFrame = document.getElementById ('voteSrc')
	if (voteIFrame)
	{
		var voteSrc = voteIFrame.contentWindow ? voteIFrame.contentWindow.document : voteIFrame.contentDocument
		if (voteSrc)
		{
			var innerHTMLContent = voteSrc.getElementsByTagName('body')[0].innerHTML		
			var votePanel = document.getElementById ('votePanel')
			if (innerHTMLContent && votePanel) votePanel.innerHTML = innerHTMLContent
		}
	}
}
