


function Browser() {
	var b=navigator.appName;
	if (b=="Netscape") this.b="ns";
	else if ((b=="Opera") || (navigator.userAgent.indexOf("Opera")>0)) this.b = "opera";
	else if (b=="Microsoft Internet Explorer") this.b="ie";
	if (!b) alert('Unidentified browser./nThis browser is not supported,');
	this.version=navigator.appVersion;
	this.v=parseInt(this.version);
	this.ns=(this.b=="ns" && this.v>=4);
	this.ns4=(this.b=="ns" && this.v==4);
	this.ns6=(this.b=="ns" && this.v==5);
	this.ie=(this.b=="ie" && this.v>=4);
	this.ie4=(this.version.indexOf('MSIE 4')>0);
	this.ie5=(this.version.indexOf('MSIE 5')>0);
	this.ie55=(this.version.indexOf('MSIE 5.5')>0);
	this.ie6=(this.version.indexOf('MSIE 6')>0);
//	if (this.ie6) this.ie5 = true; // since we don't modify all the dynapi libraries, we trate ie6 as ie5 (we hope they are compatible)
	this.opera=(this.b=="opera");
	this.dom=(document.createElement && document.appendChild && document.getElementsByTagName)?true:false;
	this.def=(this.ie||this.dom); // most used browsers, for faster if loops
	var ua=navigator.userAgent.toLowerCase();
	if (ua.indexOf("win")>-1) this.platform="win32";
	else if (ua.indexOf("mac")>-1) this.platform="mac";
	else this.platform="other";
}

var myBrowser = new Browser();




//----------------------------------



function Flash_checkForPlugIn( minPlayer ) {
  var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ?
					navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
  if (plugin) {
    var pluginversion = parseInt( plugin.description.substring(plugin.description.indexOf(".")-1)  ) 
    if(pluginversion >= minPlayer) {return true;}
  }
  return false;
}

function Flash_getActiveXVersion(){
   var obj = "ShockwaveFlash.ShockwaveFlash.";
   var ver = 5.0;
   var found = false;
   while ((false == found) && (ver > 0)){
      found = true;
      try{
         var obj = new ActiveXObject(obj+ver);
      }
      catch (e){
         found = false;
         ver --;
      }
   }
   return(ver);
}

function Flash_checkForMinPlayer() {
	var winIEpass = ((navigator.appName.indexOf("Microsoft") != -1) && 
			(navigator.appVersion.indexOf("Windows") != -1)) && 
			(parseFloat(navigator.appVersion) >= 4) ? true : false;

	var NNpass = ((navigator.appName == "Netscape") && 
		(navigator.userAgent.indexOf("Mozilla") != -1) && 
		(parseFloat(navigator.appVersion) >= 4) && 
		(navigator.javaEnabled())) ? true : false;

	var supportedBrowser = (winIEpass || NNpass) ? true : false;

	if(!supportedBrowser) return false;
	if(NNpass) return (Flash_checkForPlugIn( 4 ));
	if(winIEpass) return (Flash_getActiveXVersion());
}





//---------------------------------




function advertising_startFlash( srcURL , id , cxwidth , cxheight , cxleft , cxtop , wmode , timeoutMs ) {

	if (!Flash_checkForMinPlayer()) return;

	var str = '';
	str += '<div id="' + id + 'Layer" style="position:absolute; left:'+cxleft+'; top:'+cxtop+'; width:'+cxwidth+'; height:'+cxheight+'; z-index:1500; visibility: visible">';
	str += '<table><tr><td align="right"><a href="#" onClick="advertising_stop(\'' + id + 'Layer\');" ><img src="/images/sams/botao_ok.gif" alt="Fechar" ></a></td></tr><tr><td>' ;
	str += '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0" ';
	str += 'ID="' + id + '" WIDTH="'+ cxwidth +'" HEIGHT="'+ cxheight +'">';
	str += '<PARAM NAME="movie" VALUE="' + srcURL + '">';
	str += '<PARAM NAME="quality" VALUE="high">';
	if(wmode=='transparent') str += '<PARAM NAME="wmode" VALUE="transparent">';
	str += '<PARAM NAME="autostart" VALUE="true">';
	str += '<embed src="' + srcURL + '" quality="high"' + 'width="'+ cxwidth +'" height="'+ cxheight +'"';
	str += 'type="application/x-shockwave-flash" NAME="' + id + '"';
	str += 'pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed>';
	str += '</OBJECT>';
	str += '</td></tr></table>' ;
	str += '</div>';

	var winIEpass = ((navigator.appName.indexOf("Microsoft") != -1) && 
			(navigator.appVersion.indexOf("Windows") != -1)) && 
			(parseFloat(navigator.appVersion) >= 4) ? true : false;

	var NNpass = ((navigator.appName == "Netscape") && 
		(navigator.userAgent.indexOf("Mozilla") != -1) && 
		(parseFloat(navigator.appVersion) >= 4) && 
		(navigator.javaEnabled())) ? true : false;

//alert( str ) ;
//alert( winIEpass + ' ' + NNpass ) ;

    if(winIEpass){document.body.insertAdjacentHTML('afterBegin',str);}
    if(NNpass){document.write(str)}

	if ( winIEpass || NNpass ) {
		setTimeout( "advertising_stop( '" + id + "Layer' )" , timeoutMs ) ;
	}

}

function advertising_stop( id ) {

	if ( ! ( typeof( document.readyState ) == 'undefined' || document.readyState == 'complete' )  ) {
		window.setTimeout( "advertising_stop( '" + id + "' ) " , 500 ) ;
		return ;
	}

//javascript: var x = document.all[ '0mscons1Layer' ] ;  for ( p in x ) { alert( ""+p + "=" + x[ p ]   ) ; }

	if ( document.getElementById && document.getElementById( id ) ) {
		advertising_hideSelect( id , 0 ) ;
		document.getElementById( id ).innerHTML = "" ;
		document.getElementById( id ).outerHTML = "" ;
		return ;
	}

	if ( document.all && typeof( document.all[ id ] ) == "object" 
		&& typeof( document.all[ id ].length ) == "undefined" ) {
		advertising_hideSelect( id , 0 ) ;
		document.all[ id ].innerHTML = '' ;
		document.all[ id ].outerHTML = '' ;
	}
}



function advertising_hideSelect( id , hide ) {

	var tagName = "SELECT" ;
	var els = ( document.getElementsByTagName ? document.getElementsByTagName(tagName) : document.all.tags(tagName)  ) ;
	var o = ( document.getElementById ? document.getElementById(id) : document.all.tags(id)  ) ;
	for (  var i=0;i<els.length;i++  ) {
		var el=els.item(i);

/*
var str = "" ;
for ( e in o ) { if ( o[ e ] > 0 ) str += " " + e + '=' + o[ e ] ; }
str += "\n\n"
for ( e in el ) { if ( el[ e ] > 0 ) str += " " + e + '=' + el[ e ] ; }
alert( str ) ;
*/

		// obter posicao abs
		var elt = el ; elol = 0 , elot = 0 ;
		while( elt ) { elol += elt.offsetLeft ; elot += elt.offsetTop ; elt = elt.offsetParent ; }
		var ot = o ; ool = 0 , oot = 0 ;
		while( ot ) { ool += ot.offsetLeft ; oot += ot.offsetTop ; ot = ot.offsetParent ; }

		var elol_ = elol + el.offsetWidth , elot_ = oot + el.offsetHeight ;
		var ool_ = ool + o.offsetWidth , oot_ = oot + o.offsetHeight ;
/*
		alert( 'el Left : ' + elol + 'x' + elot + ' -> ' + elol_ + 'x' + elot_ ) ;
		alert( 'swf Left : ' + ool + 'x' + oot + ' -> ' + ool_ + 'x' + oot_ ) ;
*/
		if (
			( ool <= elol && elol <= ool_ && oot <= elot && elot <= oot_ )
			||
			( ool <= elol_ && elol_ <= ool_ && oot <= elot_ && elot_ <= oot_ )
		) {
			if ( hide ) {
				el.myVisibility = el.style.visibility ;
				el.style.visibility = "hidden" ;
			} else {
				el.style.visibility = el.myVisibility ;
			}
		}
	}
}

