var cmn_oInformation = new cmnInformation();

function cmnInformation(){
	var eHTML = document.getElementsByTagName( 'html' )[0];
	this.sUser_agent = navigator.userAgent.toLowerCase();
	if( window.opera ){
		this.bOpera = true; cmnSet_class( eHTML, 'Opera');
	}
	if( !this.bOpera && this.sUser_agent.indexOf( 'msie' ) != -1 ){
		this.bIE = true; cmnSet_class( eHTML, 'IE');
	}else if( navigator.product == 'Gecko' ){
		this.bGecko = true; this.bMozilla = true; cmnSet_class( eHTML, 'Mozilla');
	}
	this.bMAC = ( this.sUser_agent.indexOf( 'mac' ) != -1 );
	this.sLanguage = null;
	this.bHTTP = null;
	this.bHandheld = false;
	return this;
}

function popupNewWindow(link,width,height){
	window.open(link,null,"width="+width+",height="+height+",resizable=yes");
	return false;
}

function popupWindow(fileUrl, winW, winH, winN, scrollB) {
	var winWidth = (winW)? winW : 740;
	var winHeight = (winH)? winH : 520;
	var winName = (winN)? winN : 'popupWin'
	var scrollBars = (scrollB)? scrollB : 'auto'
	var nn4 = (document.layers) ? true : false;
	var ie4 = (document.all) ? true : false;
	var dom = (document.createTextNode)? true : false;
	if (nn4 || ie4 || dom) {
		if (screen.width < winWidth + 50) { winWidth = screen.width - 50; scrollbars = 'yes' }
		if (screen.height < winHeight + 100) { winHeight = screen.height - 100; scrollbars = 'yes' }
		posX = Math.round((screen.width - winWidth) / 2);
		posY = Math.round((screen.height - winHeight) / 2);
		posCode = (nn4)? "screenX="+posX+",screenY="+posY : "left="+posX+",top="+posY;
	} else {
		posCode = "";
	}
	var popupWin = window.open(fileUrl, winName,"menubar=no,toolbar=no,scrollbars=" + scrollBars + ",status=yes,resizable=yes,width=" + winWidth + ",height=" + winHeight + "," + posCode);
	if (popupWin) popupWin.focus();
}

var printer=document.getElementById("printer");
function print(value){
	if(printer) printer.innerHTML=printer.innerHTML+"<br>"+value; else if(document.getElementById("printer")){
		printer=document.getElementById("printer");
		print(value);
	} else alert('printer not found');
}

function drawPNG(element){
	if( element.runtimeStyle && element.src.match( /\.png$/ ) ){
		element.runtimeStyle.filter
			= 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src='
			+ element.src
			+ ', sizingMethod=scale)';
		element.src = '/i/i-blank.gif';
	}
}

function cmnPlaceholder( eThis, sText, sClass_on_empty ){
	eThis.onfocus = function(){ if( this.value.length && this.value == sText ){ this.value = ''; } cmnRemove_class( this, sClass_on_empty ); this.select(); }
	eThis.onblur = function(){ if( !this.value.length ){ cmnSet_class( this, sClass_on_empty ); this.value = sText; } }
	if( !eThis.value.length ){ eThis.onblur(); }
	if( !eThis.getAttribute( 'placeholder' ) ){ eThis.setAttribute( 'placeholder', sText ); }
}

function cmnRemove_class( eOn, sClass_name ){
	cmnSet_class( eOn, "", sClass_name );
}

function cmnSet_class( 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 cmnFlash(){
	var aeFlash = new Array();
	this.build = function( vEnabled, vDisabled, vNone, iVersion  ){
		var vVersion = this.get_version( iVersion );
		if( vVersion.toString() != "false" ){
			this.enable();
			vVersion = this.get_version( iVersion );
		}
		if( vVersion ){
			if( vEnabled.nodeType )	vEnabled.style.display = "block";
			else document.write( build_object(vEnabled) );
			if( vDisabled.nodeType ) vDisabled.style.display = "none";
			if( vNone.nodeType ) vNone.style.display = "none";
		}else{
			if( vEnabled.nodeType ) vEnabled.style.display = "none";
			if( vDisabled.nodeType ) vDisabled.style.display = "block";
			else if( vDisabled ) document.write( vDisabled );
			if( parseInt(vVersion) == 0 );
				if( vNone.nodeType ) vNone.style.display = "block";
				else if( vNone ) document.write( vNone );
		}
	}
	this.get_version = function( iVersion ){
		var vVersion = cmnGet_cookie( "flash" );
		if( !vVersion ){
			vVersion = check_flash_version( iVersion );
			set_flash_cookie( vVersion );
			return vVersion;
		}else if( iVersion && iVersion > vVersion ){
			vVersion = false;
		}
		return ( vVersion == "false" ) ?  false : vVersion;
	}
	this.disable = function(){
		set_flash_disabled( true );
	}
	this.enable = function(){
		set_flash_disabled( false );
	}
	this.set_disabled = function( bDisabled ){
		set_flash_disabled( bDisabled );
	}

	return this;

	function build_object( sOptions ){
		var asOptions = sOptions.split( "," );
		for( var i = 0 ; i < asOptions.length ; i++){
			asPair = asOptions[i].split( "=" );
			asOptions[asPair[0]] = unescape( asPair[1] );
		}
		var sHTML = '<object style="width:'+asOptions.width +';" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
		sHTML += 'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"' + 'width="' + asOptions.width + '" height="' + asOptions.height + '" align="middle">' + '<param name="allowScriptAccess" value="sameDomain">' + '<param name="movie" value="' + asOptions.source + '">' + '<param name="quality" value="high">';
		if( asOptions.base ){ sHTML += '<param name="base" value="' + asOptions.base + '">'; }
		if( asOptions.background ){ sHTML += '<param name="bgcolor" value="' + asOptions.background + '">'; }
		if( asOptions.transparent ){ sHTML += '<param name="wmode" value="transparent">' }
		if( asOptions.flashvars ){ sHTML += '<param name="flashvars" value="' + asOptions.flashvars + '">'; }
		sHTML += '<embed quality="high" allowScriptAccess="sameDomain" type="application/x-shockwave-flash"' + ' pluginspage="http://www.macromedia.com/go/getflashplayer"' + ' src="' + asOptions.source + '" width="' + asOptions.width + '" height="' + asOptions.height + '"';
		if( asOptions.base ){ sHTML += ' base="' + asOptions.base + '"'; }
		if( asOptions.background ){ sHTML += ' bgcolor="' + asOptions.background + '"'; }
		if( asOptions.transparent ){ sHTML += ' wmode="transparent"' }
		if( asOptions.flashvars ){ sHTML += ' flashvars="' + asOptions.flashvars + '"'; }
		sHTML += '></embed></object>';
		return sHTML;
	}
	function set_flash_disabled( bDisabled ){
		set_flash_cookie( ( bDisabled ) ?  "false" : "" );
	}
	function check_flash_version( iVersion ){
		if( navigator.plugins && navigator.plugins['Shockwave Flash'] ){
			var sVersion = ( !iVersion ) ? "\\d+" : "[" + iVersion + "-9]\\d*";
			sVersion = parseInt( navigator.plugins['Shockwave Flash'].description.replace( new RegExp( "^[^\\d]+(" + sVersion + ").*$"), "$1" ) );
			return ( isNaN( sVersion ) ) ? ( !iVersion ) ? false : 0 : sVersion;
		}else if( cmn_oInformation.bIE && !cmn_oInformation.bMAC ){
			var oTemp, iMax = 20;
			iVersion = ( !iVersion ) ? 3 : iVersion;
			for( var i = iVersion ; i < iMax ; i++ ){
				try{
					oTemp = new ActiveXObject( "ShockwaveFlash.ShockwaveFlash." + i );
					iVersion = i;
				}catch(e){
					return ( i > iVersion ) ? iVersion : 0;
				}
			}
			return iVersion;
		}else{
			return ( !iVersion ) ? false : 0;
		}
	}
	function set_flash_cookie( sCookie_value ){
		var dNow = new Date();
		var dExpires = new Date();
		dExpires.setTime( dNow.getTime() + 1000 * 60 * 60 * 24 * 365 );
		cmnSet_cookie( "flash", ( !sCookie_value ) ? "" : sCookie_value, dExpires );
	}
}

function cmnSet_cookie( sName, vValue, dExpires ){
   document.cookie = sName + "=" + escape( vValue )
	   + ( dExpires == null ? "" : ( "; expires=" + dExpires.toGMTString() ) )
	   + "; path=/";
}

function cmnGet_cookie( sName ){
	return cmnPairs_string_get_value( document.cookie, sName );
}

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;
}