var isIE = window.ActiveXObject ? true : false;

function pub_flash2( 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 abreimagem( url, id, w, h ) {
	window.open( url, id, 'width='+(w+30)+',height='+(h+30)+',left=25,top=25,toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0' );
}

function chkestadoform(f)
{
	var erro = '';
	
	if( !erro && f.id.value == '' ) erro = 'Por favor, selecione o estado que deseja consultar';
	
	if( erro )
	{
		alert( erro );
		return false;
	}
	return true;
}

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 ) || ( letra == 45 ) )
			{
				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 ) && !( letra == 45 && last == 45 ) ) { 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 ) || ( letra == 45 ) ) { if( x >= 1 ) retorno = valor.substr( c, 1 ) + retorno; x = x + 1; } }
	}   	
	if( arr == 0 || pto == 0 ) retorno = '';
  	obj.value = retorno; return;
}

function objnumero( obj )
{
	obj.value = sonumero( obj.value );
}

function sonumero( valor )
{
	var retorno = '';
	for( c = 0; c < valor.length; c++ )
	{
		var letra = asc( valor.substr( c, 1 ) );
		if( letra >= 48 && letra <= 57 ) retorno = retorno + valor.substr( c, 1 );
	}
	return retorno;
}

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] );
	}
}

//
// controle de tamanho de fonte
//
tamanhotexto = GetCookie('tamanhotexto');
if( tamanhotexto == undefined ) tamanhotexto = 0;
function tamtexto(flag)
{
	var c = '';
	if( flag == -1 ) c = 'menor';
	if( flag ==  1 ) c = 'maior';
	SetCookie( 'tamanhotexto', tamanhotexto );
	document.getElementById("texto").className = c; 
}

//
// versão para impressão
//
function verimpressao()
{
	var url = window.location.href;
	url += ( url.indexOf('?') < 0 ? '?' : '&' ) + 'print=1';
	window.open( url, 'impressao', 'top=10,left=10,width=770,height=400,location=no,toolbar=yes,menubar=no,resizable=yes,scrollbars=yes,status=no' );
}

function verimpressao2()
{
	var url = window.location.href;
	url += ( url.indexOf('?') < 0 ? '?' : '&' ) + 'print=1';
	window.open( url, 'impressao', 'top=10,left=0,width=920,height=450,location=no,toolbar=yes,menubar=no,resizable=yes,scrollbars=yes,status=no' );
}

function imprimir()
{
	setTimeout( 'window.print()', 1000 );
}

function favoritos()
{
    u = 'http://www.vacinacontragripe.com.br';
    t = 'Vacina Contra Gripe';
    if( document.all )
    {
        window.external.AddFavorite(u,t);
    } else {
        alert("Use CTRL+D para adicionar este site ao seu Favoritos!");
    }
}

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)+';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 pub_flash( swf, w, h, transp ) {
	document.write( '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+w+'" height="'+h+'">'+"\n" );
	document.write( '<param name="movie" value="'+swf+'">'+"\n" );
	document.write( '<param name="quality" value="high">'+"\n" );
	document.write( '<param name="menu" value="false">'+"\n" );
	if( transp == 1 ) document.write('<param name="wmode" value="transparent">'+"\n" );
	document.write( '<embed src="'+swf+'" '+( transp == 1 ? 'wmode="transparent"' : '' )+'menu="false" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+w+'" height="'+h+'"></embed>'+"\n" );
	document.write( '</object>'+"\n" );
}

function getradiovalue( o )
{
	var ret = undefined;
	for( var i=0; i < o.length; i++ )
		if( o[i].checked )
			ret = o[i].value;
	return ret;
}

function carregaXML( url, metodo, param, funcao )
{
	var xmlhttp, bComplete = false;
	
	try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
	catch (e)
	{
		try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
		catch (e)
		{
			try { xmlhttp = new XMLHttpRequest(); }
			catch (e) { xmlhttp = false; }
		}
	}
	
	if ( !xmlhttp ) return null;
	this.connect = function( sURL, sMethod, sVars, fnDone )
	{
		sVars = 'sessid='+GetCookie('PHPSESSID')+'&'+sVars;
		if ( !xmlhttp ) return false;
		bComplete = false;
		sMethod = sMethod.toUpperCase();
		
		try
		{
			if ( sMethod == "GET" )
		      {
				xmlhttp.open( sMethod, sURL+"?"+sVars, true );
				sVars = "";
			} else {
				xmlhttp.open( sMethod, sURL, true );
				xmlhttp.setRequestHeader( "Method", "POST "+sURL+" HTTP/1.1" );
				xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded" );
			}
			xmlhttp.onreadystatechange = function()
			{
				if (xmlhttp.readyState == 4 && !bComplete)
				{
					bComplete = true;
					fnDone( xmlhttp.responseText.replace(/\+/g,' ') );
				}
			};
			xmlhttp.send(sVars);
		}
		catch(z) { return false; }
		return true;
	};
	return this.connect( url, metodo, param, funcao );
}
