var isIE = window.ActiveXObject ? true : false;

function promocaoinscricao2() {
	window.open( 'promocoes-inscricao.htm?id=110', 'coisascoracao', 'width=300,height=380,left=50,top=50,toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0' );
}
function promocaoinscricao3() {
	window.open( 'promocoes-inscricao.htm?id=111', 'aniversariantes', 'width=300,height=395,left=50,top=50,toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0' );
}

function pub_flash( swf, w, h, trans ) {
	if( trans == null || trans == undefined ) trans = 0;
	document.write( '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+w+'" height="'+h+'">'+"\n" );
	document.write( '<param name="movie" value="'+swf+'" />'+"\n" );
	document.write( '<param name="quality" value="high" />'+"\n" );
	if( trans != 0 ) document.write( '<param name="wmode" value="transparent"></param>'+"\n" );
	document.write( '<param name="menu" value="false" />'+"\n" );
	document.write( '<embed src="'+swf+'" menu="false" quality="high"'+(trans!=0?' wmode="transparent"':'')+' pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+w+'" height="'+h+'"></embed>'+"\n" );
	document.write( '</object>'+"\n" );
}

function pub_youtube( video )
{
	var url = 'http://www.youtube.com/v/'+video+'&rel=1&autoplay=1&color1=0xFAE04D&color2=0xF1AB0D&border=0';
	pub_flash( url, 480, 395, 1 );
}

function radioonline(flag) {
	if( flag == 1 )
	{
		window.location.reload();
	} else {
		window.open( 'ronline.htm', 'ronlinefm', 'width=590,height=190,left=50,top=50,toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0' );
	}
}

function estudioonline() {
	var d=new Date();
	window.open( 'eonline.htm?r='+d.getTime(), 'eonlinefm', 'width=540,height=390,left=50,top=50,toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0' );
}

function pecasucesso() {
	window.open( 'pecasucesso.htm', 'pecasucesso', 'width=300,height=350,left=50,top=50,toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0' );
}

function fotogaleria( idg, idf, w, h ) {
	window.open( 'galerias/'+idg+'/g'+idg+'f'+idf+'.jpg', idg+'f'+idf, 'width='+(w+40)+',height='+(h+40)+',left=50,top=50,toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0' );
}

function pub_mp( objid, w, h, url )
{
	var objDiv = document.getElementById( objid );
	if( !objDiv || objDiv == undefined || objDiv == null ) return;
	
	var opc = {
		TransparentAtStart: 'true',
		ShowControls: 'true',
		AutoPlay: 'true',
		AutoStart: 'true',
		ShowStatusBar: 1,
		uiMode: 'mini',
		EnableContextMenu: 0
	}
	
	var embed = out = opc1 = opc2 = '';
	for( var x in opc )
	{
		opc1 += '<param name="'+x+'" value="'+opc[x]+'" />';
		opc2 += ' '+x+'="'+opc[x]+'"';
	}
	
	h -= 6;
	embed += '<embed src="'+url+'" width="'+w+'" height="'+h+'" type="application/x-mplayer2" pluginspage="http://www.microsoft.com/windows/windowsmedia/"'+opc2+'></embed>';
	
	if( isIE )
	{
		var WMP7;
		if( window.ActiveXObject )
		{
			WMP7 = new ActiveXObject("WMPlayer.OCX.7");
		} else if (window.GeckoActiveXObject) {
			WMP7 = new GeckoActiveXObject("WMPlayer.OCX.7");
		}
		if( WMP7 )
		{
			out += '<object id="'+objid+'" width="'+w+'" height="'+h+'" classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6" type="application/x-oleobject">';
			out += '<param name="URL" value="'+url+'" />'+opc1+embed+'</object>';
		} else {
			out += '<object id="'+objid+'" width="'+w+'" height="'+h+'" classid="clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95" type="application/x-oleobject" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715">';
			out += '<param name="FileName" value="'+url+'" />'+opc1+embed+'</object>';
		}
		/* out += embed; */
	} else {
		out += '<object id="'+objid+'" width="'+w+'" height="'+h+'" classid="clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715" type="application/x-oleobject">';
		out += '<param name="FileName" value="'+url+'" />';
		out += '<param name="URL" value="'+url+'" />'+opc1+embed+'</object>';
	}
	objDiv.innerHTML = out;
}

function pub_mpv( objid, w, h, url )
{
	var objDiv = document.getElementById( objid );
	if( !objDiv || objDiv == undefined || objDiv == null ) return;
	
	var opc = {
		TransparentAtStart: 'true',
		ShowControls: 'true',
		AutoPlay: 'true',
		AutoStart: 'true',
		ShowStatusBar: 1,
		uiMode: 'mini',
		EnableContextMenu: 0
	}
	
	var embed = out = opc1 = opc2 = '';
	for( var x in opc )
	{
		opc1 += '<param name="'+x+'" value="'+opc[x]+'" />';
		opc2 += ' '+x+'="'+opc[x]+'"';
	}
	
	h -= 6;
	embed += '<embed src="'+url+'" width="'+w+'" height="'+h+'" type="application/x-mplayer2" pluginspage="http://www.microsoft.com/windows/windowsmedia/"'+opc2+'></embed>';
	
	if( isIE )
	{
		var WMP7;
		if( window.ActiveXObject )
		{
			WMP7 = new ActiveXObject("WMPlayer.OCX.7");
		} else if (window.GeckoActiveXObject) {
			WMP7 = new GeckoActiveXObject("WMPlayer.OCX.7");
		}
		if( WMP7 )
		{
			out += '<object id="'+objid+'" width="'+w+'" height="'+h+'" classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6" type="application/x-oleobject">';
			out += '<param name="URL" value="'+url+'" />'+opc1+embed+'</object>';
		} else {
			out += '<object id="'+objid+'" width="'+w+'" height="'+h+'" classid="clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95" type="application/x-oleobject" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715">';
			out += '<param name="FileName" value="'+url+'" />'+opc1+embed+'</object>';
		}
		/* out += embed; */
	} else {
		out += '<object id="'+objid+'" width="'+w+'" height="'+h+'" classid="clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715" type="application/x-oleobject">';
		out += '<param name="FileName" value="'+url+'" />';
		out += '<param name="URL" value="'+url+'" />'+opc1+embed+'</object>';
	}
	objDiv.innerHTML = out;
}

var maisouvida = {
	img: 1,
	artista: '',
	fadepos: 1,
	faderate: 0.1,
	fadedelay: 10,
	changedelay: 60000,
	firsttime: 1,
	carrega: function( artista, nome )
	{
		this.artista = artista;
		this.nome = nome;
		this.oA = document.getElementById("maisouvidaartista"+this.img); this.img = ( this.img == 1 ? 2 : 1 );
		this.oB = document.getElementById("maisouvidaartista"+this.img);
		this.oM = document.getElementById("maisouvidamask");
		this.oA.src = 'img/artistas/'+this.artista+'.jpg';
		this.oA.alt = nome;
		this.oA.title = nome;
		setTimeout( 'maisouvida.checa()', 10 );
	},
	checa: function()
	{
		if( this.imgok( this.oA ))
		{
			this.fadepos = this.firsttime;
			this.firsttime = 0;
			maisouvida.fade(1);
		} else {
			setTimeout('maisouvida.checa()',10);
		}
	},
	fade: function(flag)
	{
		var mask = this.oM;
		this.fadepos += this.faderate * ( flag == 0 ? -1 : 1 );
		this.fadepos = Math.min( 1, Math.max( this.fadepos, 0 ));
		setOpacity( mask, this.fadepos );
		if( flag == 1 ) this.oM.className = "";
		if( flag == 1 && this.fadepos >= 1 )
		{
			this.oA.className = "";
			this.oB.className = "hide";
			setTimeout( 'maisouvida.fade(0)', this.fadedelay * 10 );
			return;
		}
		if( flag == 0 && this.fadepos <= 0 )
		{
			this.oM.className = "hide";
			setTimeout('maisouvida.chkartista()',this.changedelay);
			return;
		}
		setTimeout( 'maisouvida.fade('+flag+')', this.fadedelay );
	},
	imgok: function(obj)
	{
		if (!obj.complete) return false;
		if (typeof obj.naturalWidth != "undefined" && obj.naturalWidth == 0) return false;
		return true;
	},
	chkartista: function()
	{
		if( this.scriptobj != undefined ) this.scriptobj.parentNode.removeChild( this.scriptobj );
		var url = 'fotoartista.php?r='+Math.random()+(this.artista!=''?'&a='+this.artista:'');
		var e = document.createElement("script");
		e.src = url;
		e.type = 'text/javascript';
		this.scriptobj = document.getElementsByTagName("head")[0].appendChild(e);
		
	}
}

function setOpacity( obj, opacity )
{
	var s = obj.style;
	if( isIE )
	{
		s.zoom = 1;
		s.filter = (s.filter || '').replace(/alpha\([^\)]*\)/gi,"") +
			(opacity == 1 ? "" : "alpha(opacity=" + opacity * 100 + ")");
	} else {
		s.opacity = opacity;
	}
}

function objnome( obj )
{
	var ret = '';
	if( typeof( obj ) != 'object' ) return;
	var v = obj.value.trim().toLowerCase();
	var v = v.replace( '/', '/ ' );
	var a = v.split(" ");
	var prep = ['de','do','dos','da','das','e','ou','del','ltda','ltda.','apto','apto.','ap','ap.','apt','apt','conj','conj.','cj','cj.','sala','sl.','andar'];
	var ignore = ['me','sa','s/a'];
	for( i=0; i<a.length; i++ ) ret += (i>0?' ':'') + ( prep.indexOf(a[i].toLowerCase()) == -1 ? ( ignore.indexOf(a[i].toLowerCase()) == -1 ? a[i].substr(0,1).toUpperCase() + a[i].substr(1) : a[i].toUpperCase() ) : a[i].toLowerCase() );
	
	obj.value = ret;
}

function objemail( obj )
{
	valor = obj.value.toLowerCase(); retorno = ''; x = 0; arr = 0;
	for( c = 0; c < valor.length; c++ )
	{
		letra = asc( valor.substr( c, 1 ) );
		if( x == 0 ) { if( ( letra >= 48 && letra <= 57 ) || ( letra >= 97 && letra <= 122 ) ) { retorno = retorno + valor.substr( c, 1 ); x = 1; } }
		else {
			if( ( letra >= 48 && letra <= 57 ) || ( letra >= 97 && letra <= 122 ) || ( letra == 46 ) || ( letra == 95 ) || ( letra == 64 ) )
			{
				if( ( letra == 64 ) && arr == 0 ) { retorno = retorno + valor.substr( c, 1 ); arr = 1; }
				else { if( !( letra == 46 && last == 46 ) && !( letra == 95 && last == 95 ) && !( letra == 46 && last == 64 ) ) { if( x >= 1 ) retorno = retorno + valor.substr( c, 1 ); x = x + 1; }}
			}
		}
		last = letra;
	}
	valor = retorno; retorno = ''; x = 0; pto = 0;
	for( c = ( valor.length - 1 ); c >= 0; c-- )
	{
		letra = asc( valor.substr( c, 1 ) );
		if( letra == 46 ) pto = 1;
		if( x == 0 ) { if( ( letra >= 48 && letra <= 57 ) || ( letra >= 97 && letra <= 122 ) ) { retorno = valor.substr( c, 1 ) + retorno; x = 1; } }
		else { if( ( letra >= 48 && letra <= 57 ) || ( letra >= 97 && letra <= 122 ) || ( letra == 46 ) || ( letra == 95 ) || ( letra == 64 ) ) { if( x >= 1 ) retorno = valor.substr( c, 1 ) + retorno; x = x + 1; } }
	}   	
	if( arr == 0 || pto == 0 ) retorno = '';
  	obj.value = retorno; return;
}

function asc( each_char )
{
	var n = 0;
	var char_str = ' !"#$%&' + "'" + '()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
	for (i = 0; i < char_str.length; i++) { if (each_char == char_str.substring(i, i+1)) break; }
	return i + 32;
}

function textmax( obj, max )
{
	str = obj.value; if( str.length > max ) obj.value = str.substring( 0, max );
}

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };
Array.prototype.unescape = function() { for(var x=0,len=this.length;x<len;x++) { this[x] = unescape(this[x]); } return this };
Array.prototype.indexOf = function(v) { var r=-1;for(var x=0,len=this.length;x<len;x++) { if( r == -1 && this[x] == v ) r = x; }; return r; };
Array.prototype.inverte = function() { var a=new Array();for(var x=0,len=this.length;x<len;x++) a[x]=this[len-x-1]; return a; };
if ( typeof Array.prototype.push == "undefined" )
	Array.prototype.push = function() { for(var x=0,len=arguments.length;x<arguments.length;x++) this[this.length] = arguments[x]; }

function SetCookie(name, value, expires)
{
	if( expires == null ) expires = 15*24*60*60;
	var today = new Date(), expire = new Date();
	expire.setTime( today.getTime() + ( expires * 1000 ) );
	document.cookie = name+'='+escape(value)+';path=/;expires='+expire.toGMTString();
}

function GetCookie(name)
{
	var c = document.cookie;
	c = c.split(";");
	for( var x = 0; x < c.length; x++ )
	{
		var v = c[x].split("=");
		if( v[0].replace(/ /g,'') == name ) return unescape( v[1] );
	}
}

function form2post(f)
{
	var r = '';
	for( i=0; i<f.length; i++ ) if( f[i].name ) r += escape( f[i].name )+'='+escape( f[i].value )+'&';
	return r;
}

function post2form(f,dados)
{
	var ret = new Array();
	if( !dados || !f || f == undefined || f == null ) return;
	var dados = dados.split('&');
	for( x=0; x<dados.length; x++ )
	{
		reg = dados[x].split('=');
		if( typeof( f[reg[0]] ) == 'object' && f[reg[0]].name == reg[0] )
		{
			f[reg[0]].value = unescape( reg[1] );
			if( f[reg[0]].options && f[reg[0]].value != unescape( reg[1] ))
			{
				f[reg[0]].options[f[reg[0]].options.length] = new Option( unescape( reg[1] ), unescape( reg[1] ));
				if( f[reg[0]].value != unescape( reg[1] )) f[reg[0]].value = unescape( reg[1] );
			}
		}
	}
	
	return ret;
}

function validaformblog( f )
{
	var erro = '';
	if( !erro && f.nome.value.length < 3 ) erro = 'O Nome precisa ter no mínimo 3 letras';
	if( !erro && !f.email.value ) erro = 'O campo E-mail precisa ser preenchido corretamente';
	if( !erro && f.bairro.value.length < 3 ) erro = 'O Bairro precisa ter no mínimo 3 letras';
	if( !erro && f.cidade.value.length < 3 ) erro = 'A Cidade precisa ter no mínimo 3 letras';
	if( !erro && f.mensagem.value.length < 5 ) erro = 'A Mensagem precisa ter no mínimo 5 letras';
	if( erro )
	{
		alert( erro );
		return false;
	}
	
	var dados = '';

	for( i=0; i<f.length; i++ )
		if( f[i].name && f[i].name != 'mensagem' && f[i].name[0] != '_' )
			dados += escape( f[i].name )+'='+escape( f[i].value )+'&';
	
	SetCookie( 'blogdados', dados, 86400 * 15 );
	
	return true;
}

function validaformbloglocutor( f )
{
	var erro = '';
	if( !erro && f.mensagem.value.length < 5 ) erro = 'A Mensagem precisa ter no mínimo 5 letras';
	if( erro )
	{
		alert( erro );
		return false;
	}
	
	return true;
}

validaformblogreplica = validaformbloglocutor;
