//
// library basica
//
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] );
	}
}
//
// valida o médico
//
function validaMedico(f)
{
	var erro = '';
	var frase = 'Doutor, por favor, preencha corretamente ';
	if( !erro && f.crm.value.length < 4 )	erro = frase+'seu CRM';
	if( !erro && isNaN(f.crm.value) ) erro = 'Preencha o CRM APENAS com numeros';
	if( !erro && f.crm2.value.length < 2 )	erro = frase+'o estado (UF) de seu CRM';
	if( !erro && f.email.value.length < 3 )	erro = frase+'seu e-mail';
	if( !erro && f.senha.value.length < 3 )	erro = frase+'sua senha';
	if( erro ) { alert( erro ); return false; }
}
function validaCadastroMedico(f)
{
	var erro = '';
	var frase = 'Doutor, por favor, preencha corretamente ';
	if( !erro && f.nome.value.length < 10 ) erro = frase+'seu Nome';
	if( !erro && f.endereco.value.length < 5 ) erro = frase+'o Endereço';
	if( !erro && f.cidade.value.length < 3 ) erro = frase+'o nome da Cidade';
	if( !erro && f.bairro.value.length < 3 ) erro = frase+'o Bairro';
	if( !erro && f.cep.value.length < 8 ) erro = frase+'o CEP, com um mínimo de 8 digitos.';
	if( !erro && isNaN(f.cep.value) ) erro = 'Preencha o CEP APENAS com numeros';
	if( !erro && f.fone_ddd.value.length < 2 ) erro = frase+'o DDD do telefone';
	if( !erro && isNaN(f.fone_ddd.value) ) erro = 'Preencha o DDD APENAS com numeros';
	if( !erro && f.fone_num.value.length < 8 ) erro = frase+'o Telefone';
	if( !erro && isNaN(f.fone_num.value) ) erro = 'Preencha o numero do telefone APENAS com numeros';
	if( erro ) { alert( erro ); return false; }
}
//
// 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 imprimir()
{
	setTimeout( 'window.print()', 1000 );
}
//
// controle de tamanho de fonte
//
tamanhotexto = GetCookie('tamanhotexto');
if( tamanhotexto == undefined ) tamanhotexto = 0;
function tamtexto(flag)
{
	if( flag ==  1 && tamanhotexto <= 0 ) tamanhotexto++;
	if( flag == -1 && tamanhotexto >= 0 ) tamanhotexto--;
	var c = '';
	if( tamanhotexto == -1 ) c = 'menor';
	if( tamanhotexto ==  1 ) c = 'maior';
	SetCookie( 'tamanhotexto', tamanhotexto );
	document.getElementById("texto").className = c; 
}
//
// programação para o menu
//
menudelayin = 100; menudelayout = 4000;
menuobj = new Array(); menutimer = 0;
overmenu = function()
{
	var lis = document.getElementById("nav").getElementsByTagName("li");
	for( var i=0, l=lis.length; i<l; i++ )
	{
		if( lis[i].className != "p" )			
		{
			lis[i].onmouseover = function() { this.className+=" hover"; };
			lis[i].onmouseout = function() { this.className=(" "+this.className).replace(/ hover/g, ""); };
		} else {
			menuobj[menuobj.length] = lis[i];
			lis[i].hover = 0;
			lis[i].onmouseover = function() { this.hover = 2; clearTimeout(menutimer); menutimer = setTimeout( 'hidemenu()', menudelayin  ); };
			lis[i].onmouseout = function() { this.hover = -1; clearTimeout(menutimer); menutimer = setTimeout( 'hidemenu()', menudelayout ); };
		}
	}
}
hidemenu = function()
{
	var lis = menuobj;
	for( var i=0, l=lis.length; i<l; i++ )
	{
		if( lis[i].hover < 0 ) {
			lis[i].className=lis[i].className.replace(/ hover/g, "");
			lis[i].hover = 0;
		} else if( lis[i].hover > 1 ) {
			lis[i].className += " hover";
			lis[i].hover = 1;
		}
	}
}
//
// carregar algumas funções onload
//
if( window.addEventListener )
{
	window.addEventListener('load', overmenu, false);
	window.addEventListener('load', tamtexto, false);
	document.addEventListener('click', hidemenu, false );
} else {
	window.attachEvent('onload', overmenu );
	window.attachEvent('onload', tamtexto );
	document.attachEvent('onclick', hidemenu );
}
//
// adicionando aos favoritos
//
function favoritos()
{
    u = 'http://www.dorarticular.com.br';
    t = 'Osteoartrose - Cuidados para a sua saúde';
    if( document.all )
    {
        window.external.AddFavorite(u,t);
    } else {
        alert("Use CTRL+D para adicionar este site ao seu Favoritos!");
    }
}
//
// validação de formulários
//
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 chkemail( valor )
{
	valor = valor.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 = '';
	return retorno;
   	
}
function textmax( obj, max )
{
	str = obj.value;
	if( str.length > max ) obj.value = str.substring( 0, max );
}
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" );
}