
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])
function fixPNG(myImage) {
if ((version >= 5.5) && (version < 7) && (document.body.filters)) {
var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
var imgTitle = (myImage.title) ? "title='" + myImage.title + "' " : "title='" + myImage.alt + "' "
var imgStyle = "display:inline-block;" + myImage.style.cssText
var strNewHTML = "<span " + imgID + imgClass + imgTitle
+ " style=\"" + "width:" + myImage.width + "px; height:" + myImage.height + "px;" + imgStyle + ";"
+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
+ "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
myImage.outerHTML = strNewHTML	}
}

var cmn_aPopup_defaults = [
	["width", 720],
	["height", 650],
	["location", "no"],
	["menubar", "no"],
	["toolbar", "no"],
	["resizable", "yes"],
	["scrollbars", "yes"],
	["status", "yes"]
]
var cmn_aPopup = new Array();
function cmnPopup( sURL, sName, sFeatures, bReplace ){
	var sTarget = sName;
	if( !sURL.length ){
		if( sURL && sURL.tagName.toLowerCase() == "a" ){
			if( !sName ){ sName = ( sURL.id ) ? sURL.id : "_blank"; }
			sURL = sURL.href;
		}else{
			return false;
		}
	}else if( !sName ){
		sName = "_blank";
	}
	for( var i = 0 ; i < cmn_aPopup_defaults.length ; i++ ){
		if( !cmnPairs_string_get_value( sFeatures, cmn_aPopup_defaults[i][0], "=", "," ) ){
			sFeatures = cmnPairs_string_set_value( sFeatures, cmn_aPopup_defaults[i][0], cmn_aPopup_defaults[i][1], "=", "," );
		}
	}

	var iWidth = cmnPairs_string_get_value( sFeatures, "width", "=", "," );
	var iHeight = cmnPairs_string_get_value( sFeatures, "height", "=", "," );
	if( screen ){
		var iScreen_height = screen.height ? screen.height - 150 : 0;
		var iScreen_width = screen.width ? screen.width - 100 : 0;
		var bScroll = false;
		if( iScreen_height < iHeight ){ bScroll = true; iHeight = iScreen_height; sFeatures = cmnPairs_string_set_value( sFeatures, "height", iHeight, "=", "," ); }
		if( iScreen_width < iWidth ){ bScroll = true; iWidth = iScreen_width; sFeatures = cmnPairs_string_set_value( sFeatures, "width", iWidth, "=", "," ); }
		if( bScroll ) {
			sFeatures = cmnPairs_string_set_value( sFeatures, "scrollbars", "yes", "=", "," );
		}
		sFeatures = cmnPairs_string_set_value( sFeatures, "top", Math.round( ( iScreen_height - iHeight ) / 2 ), "=", "," );
		sFeatures = cmnPairs_string_set_value( sFeatures, "left", Math.round( ( iScreen_width - iWidth ) / 2 ), "=", "," );
	}

	if( sURL.match(/\.(gif|jpe?g|png)$/i) ){
		cmn_aPopup[sName] = window.open( "", sName, sFeatures );
		if( cmn_aPopup[sName] ){
			var sTitle = unescape( cmnPairs_string_get_value( sFeatures, "title", "=", "," ) );
			sTitle = sTitle.replace( /<\/?\w[^>]*>/g, " " ).replace( /</g, "&lt;" ).replace( /</g, "&lt;" ).replace( /"/g, "&quot;" );
			cmn_aPopup[sName].document.open();
			cmn_aPopup[sName].document.write('<html><head><title>'
				+ sTitle
				+ '</title></head><body bgcolor="white" style="margin: 0px; padding: 0px;"><table cellpadding="0" cellspacing="0" border="0" width="100%" height="100%"><tr><td align="center"><img src="'
				+ sURL + '" alt="'
				+ sTitle + '" /></td></tr></table></body></html>');
			cmn_aPopup[sName].document.close();
		}
	}else{
		var bWas_open = false;
		try{ bWas_open = ( cmn_aPopup[sName] && cmn_aPopup[sName].location.href != sURL ) }catch(e){}
		if( !cmn_aPopup[sName] || cmn_aPopup[sName].closed || !bWas_open ){
			if( sTarget && sTarget.match( /^_/ ) ){
				cmn_aPopup[sName] = window.open( sURL, sTarget );
			}else{
				cmn_aPopup[sName] = window.open( sURL, sName, sFeatures, bReplace );
			}
		}
	}
	if( sName != "_blank" ){
		cmn_aPopup[sName].focus();
	}

	return false;
}


function cmnPairs_string_get_value( sText, sName, sFrom, sBefore ){
	var sValue = "";
	if( sText ){
		if( !sFrom ) sFrom = "=";
		if( !sBefore ) sBefore = ";";
		sText = sText.replace( new RegExp( "(" + sBefore + ")\\s+", "g" ), "$1" );
		var iStart = sText.indexOf( sBefore + sName + sFrom );
		if( iStart >= 0 ){
			iStart += ( sBefore.length + sName.length + sFrom.length );
		}else{
			iStart = sText.indexOf( sName + sFrom );
			if( iStart == 0 ){
				iStart += ( sName.length + sFrom.length );
			}else{
				iStart = -1;
			}
		}
		if( iStart >= 0 ){
			var iEnd = sText.indexOf( sBefore, iStart );
			if( iEnd < 0 ){
				iEnd = sText.length;
			}
			sValue = sText.substring( iStart, iEnd );
		}
	}
	return sValue;
}

function cmnPairs_string_set_value( sText, sName, sValue, sFrom, sBefore ){
	if( !sFrom ) sFrom = "=";
	if( !sBefore ) sBefore = ";";
	var iStart = -1;
	if( sText ){
		sText = sText.replace( new RegExp( "\\s+(" + sBefore + "|" + sFrom + ")\\s+", "g" ), "$1" );
		iStart = sText.indexOf( sBefore + sName + sFrom );
		if( iStart >= 0 ){
			iStart += ( sBefore.length + sName.length + sFrom.length );
		}else{
			iStart = sText.indexOf( sName + sFrom );
			if( iStart == 0 ){
				iStart += ( sName.length + sFrom.length );
			}else{
				iStart = -1;
			}
		}
		if( iStart >= 0 ){
			var iEnd = sText.indexOf( sBefore, iStart );
			if( iEnd < 0 ){
				iEnd = sText.length;
			}
			sText = sText.substring( 0, iStart ) + sValue + sText.substr( iEnd );
		}
	}
	if( iStart < 0 ){
		if( sText && sText.lastIndexOf( sBefore ) != ( sText.length - sBefore.length ) ){
			sText += sBefore;
		}
		sText += sName + sFrom + sValue + sBefore;
	}
	return sText;
}


/* сворачивает-разворачивает списки */

function expandList(oTarget){
	var oElem=oTarget.parentNode.parentNode;
	var oDT, oDD, oSibling;
	switch(oElem.tagName){
		case 'DT':
			if( (oSibling=CL_SearchSibling(oElem, 'DD', 'next')) ){
				oDT=oElem;
				oDD=oSibling;
			}
			break;
		case 'DD':
			if( (oSibling=CL_SearchSibling(oElem, 'DT', 'previous')) ){
				oDT=oSibling;
				oDD=oElem;
			}
			break;
	}

	if(oDD && oDT){
		if(matchClass(oDD, 'Expanded')){
			removeClass(oDD, 'Expanded');
			removeClass(oDT, 'Expanded');
		}
		else{
			addClass(oDD, 'Expanded');
			addClass(oDT, 'Expanded');
		}
	}
}


/* ищет ближайший соседний элемент и проверяет его название */

function CL_SearchSibling(oElem, sSiblingName, sWay){
	var oSibling=oElem;
	switch(sWay){
		case 'next':
			while( (oSibling = oSibling.nextSibling) )
				if(oSibling.nodeType == 1)
					return (oSibling.tagName == sSiblingName) ? oSibling : null;
			break;
		case 'previous':
			while( (oSibling = oSibling.previousSibling) )
				if(oSibling.nodeType == 1)
					return (oSibling.tagName == sSiblingName) ? oSibling : null;
			break;
	}
	
	return null;
}


/* Размер документа по вертикали */
function getDocumentHeight(){
	return (document.body.scrollHeight > document.body.offsetHeight)?document.body.scrollHeight:document.body.offsetHeight;
}

/* Размер документа по горизонтали */
function getDocumentWidth(){
	return (document.body.scrollWidth > document.body.offsetWidth)?document.body.scrollWidth:document.body.offsetWidth;
}



/* полезности для работы с class */

function setClass( eOn, sClass_name, sInstead ){
	if( eOn ){
		sClass_name = ( sClass_name.length ) ? sClass_name.replace( /(^\s+|\s+$)/, "" ) : "";
		if( eOn.className.length ){
			var sOld = sClass_name;
			if( sInstead && sInstead.length ){
				sInstead = sInstead.replace( /\s+(\S)/g, "|$1" );
				if( sOld ){
					sOld += "|";
				}
				sOld += sInstead;
			}
			eOn.className = eOn.className.replace( new RegExp("(^|\\s+)(" + sOld +")($|\\s+)", "g"), "$1" );
		}
		eOn.className += ( eOn.className.length && sClass_name ? " " : "" ) + sClass_name;
	}
}

function switchClass( objNode, strCurrClass, strNewClass ) {
	if ( matchClass( objNode, strNewClass ) ) replaceClass( objNode, strCurrClass, strNewClass );
		else replaceClass( objNode, strNewClass, strCurrClass );
}

function removeClass( objNode, strCurrClass ) {
	replaceClass( objNode, '', strCurrClass );
}

function addClass( objNode, strNewClass ) {
	replaceClass( objNode, strNewClass, '' );
}

function replaceClass( objNode, strNewClass, strCurrClass ) {
	var strOldClass = strNewClass;
	if ( strCurrClass && strCurrClass.length ){
		strCurrClass = strCurrClass.replace( /\s+(\S)/g, '|$1' );
		if ( strOldClass.length ) strOldClass += '|';
		strOldClass += strCurrClass;
	}
	objNode.className = objNode.className.replace( new RegExp('(^|\\s+)(' + strOldClass + ')($|\\s+)', 'g'), '$1' );
	objNode.className += ( (objNode.className.length)? ' ' : '' ) + strNewClass;
}

function matchClass( objNode, strCurrClass ) {
	return ( objNode && objNode.className.length && objNode.className.match( new RegExp('(^|\\s+)(' + strCurrClass + ')($|\\s+)') ) );
}

function $(x) {
	return document.getElementById(x);
}
 
