function $(id) {
	return document.getElementById(id);	
}
function ajax(){
    try {
        return new ActiveXObject("Microsoft.XMLHTTP");
    } catch(e) {
        try {
            return new ActiveXObject("Msxml2.XMLHTTP");
        } catch(ex) {
            try {
                return new XMLHttpRequest();
            } catch(exc) {
                alert("Esse browser não tem recursos para uso do AJAX");
                return false;
            }
        }
    }
}
function createXMLHTTP_S(){
	return ajax();
}
function createXMLHTTP(){
	return ajax();
}
// JavaScript Document
var FontSise =
{
	maximo:30,
	minimo:8,
	base:12,
	obj:false,
	size:false,
	elementFont:function(obj, op, bot)
	{
//		bot.blur();
		if(obj=='ArtigoTexto')this.obj = $(obj).getFirst();
		else this.obj = $(obj);
		this.size = this.obj.getStyle('font-size').replace('px','');
		switch(op)
		{
			case '+': this.aumentar();break;
			case '-': this.diminuir();break;
			default: this.clear(op);break;
		}
		if(this.alt)
		{
			this.obj.setStyle('font-size',this.size + 'px'); 
		}
	},
	aumentar:function()
	{
		this.size++;
		if(this.size<=this.maximo)
		{
			this.alt = true;
		}
		else
		{
			this.alt = false;
		}
	},
	diminuir:function()
	{
		this.size--;
		if(this.size>=this.minimo)
		{
			this.alt = true;
		}
		else
		{
			this.alt = false;
		}
	},
	clear:function(base)
	{
		this.size = base;
		this.alt = true;
	}
}


function geraParamList(id)
{
	var param = '';
	formu = $(id);
	elementos = Array('input','select','textarea');
	for(i = 0;i<formu.length;i++)
	{
		tag = formu[i];
		if(!tag)break;
		if(tag.type == "checkbox") 
		{
			if (!tag.checked) 
			{
				continue;
			} 
		}
		if (tag.type == "radio") 
		{
			if (!tag.checked) 
			{
				continue;
			}
		}
		if(param != "")param += '&';
		param += tag.name +"=" + escape(tag.value) + ""; 
	}
	return param;
}

function checkMail(mail){
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
    if(typeof(mail) == "string"){
        if(er.test(mail)){ return true; }
    }else if(typeof(mail) == "object"){
        if(er.test(mail.value)){
                    return true;
                }
    }else{
        return false;
        }
}


agenda =
{
	req:new  ajax(),
	data:false,
	dataExt:false,
	fx:false,
	horarios : [ [ 8 , 11 ], [ 14 , 18 ] ],
	enviando:false,
	reqOn:false,
	nome:false,
	get_data:function(data)
	{
		if(agenda.reqOn==false)
		{
			agenda.req.open('GET','calendario.php?req&data=' + data,true);
			agenda.req.onreadystatechange = function()
			{
				if(agenda.req.readyState==4)
				{
					agenda.reqOn=false;
					$('AgendaHomeCalendario').innerHTML = '' ;
					$('AgendaHomeCalendario').innerHTML = agenda.req.responseText;
				}
			}
			agenda.reqOn=true;
			agenda.req.send(0);
		}
	},
	escolheData:function (data, dataExt)
	{
		agenda.data = data;
		agenda.dataExt = dataExt;
		$('agendaHomeData').setHTML(agenda.dataExt);
		agenda.fx = $('AgendaHomeCalendario').effects({duration: 500, transition: Fx.Transitions.Quart.easeInOut});
		agenda.fx.start({ 'opacity' : [ 1, 0]}).chain(function(){ $('AgendaHomeCalendario').setStyle( 'display','none'); agenda.exibeDados();} );
	},
	exibeData:function()
	{
		agenda.fx.stop();
		$('AgendaHomeCalendario').setStyle('display','block');
		agenda.fx = $('AgendaHomeCalendario').effects({duration:500, transition: Fx.Transitions.Quart.easeInOut});
		agenda.fx.start({'opacity': [0,1]});
		
	},
	escondeDados:function()
	{
		agenda.fx = $('AgendaHomeFormulario').effects({duration: 500, transition: Fx.Transitions.Quart.easeInOut});
		agenda.fx.start({ 'opacity' : [ 1, 0]}).chain(function(){ $('AgendaHomeFormulario').setStyle( 'display','none'); agenda.exibeData();} );
		
	},
	exibeDados:function()
	{
		agenda.fx.stop();
		$('AgendaHomeFormulario').setStyle('display','block');
		agenda.fx = $('AgendaHomeFormulario').effects({duration:500, transition: Fx.Transitions.Quart.easeInOut});
		agenda.fx.start({'opacity': [0,1]}).chain(function()
														   {
															   		focusElement($('agendaNome'));
														   });
		if(this.data=='2007-12-24' || this.data=='2007-12-31')
		{
			$('pAM').checked = true;
			$('pPM').checked = false;
			$('pAM').click($('pAM'));
		}
		
	},
	exibeResposta:function()
	{
		agenda.fx.stop();
		$('AgendaHomeResposta').setStyle('display','block');
		agenda.fx = $('AgendaHomeResposta').effects({duration:500, transition: Fx.Transitions.Quart.easeInOut});
		agenda.fx.start({'opacity': [0,1]});
	},
	voltarCalendario:function()
	{
		agenda.escondeDados();
	},

	altHora:function(obj, acao, objp)
	{
		obj = $(obj);
		objp = $(objp);// 0 - 08:00 as 11:30 | 1 - 14:00 as 18:30
		objpv = objp.checked == true ? 1: 0;
		var horarios = agenda.horarios[objpv];
		hora  = obj.value.split(':');
		hora[1] = hora[1]== '00' ? '30':'00';
		hora[0] = parseInt(hora[0]);
		if(acao=='+'){
			hora[0] = hora[1]=='00'? hora[0] + 1: hora[0];
		} else {
			hora[0] = hora[1]=='30'? hora[0] - 1: hora[0];
		}
		if(hora[0] < horarios[0] || hora[0] > horarios[1]){
			return false;	
		}else{
			obj.value = hora[0] + ':' + hora[1];
		}
	},
	altPeriodo: function (obj)
	{
		$('ihorario').value = obj.value == 0?'8:00':'14:00';
		if(this.data=='2007-12-24' || this.data=='2007-12-31' && obj.value != 0)
		{
			$('pAM').checked = true;
			$('pPM').checked = false;
			$('pAM').click($('pAM'));
		}
	},
	
	validaFormulario: function ( form )
	{
		if(form.nome.value=="")
		{
			agenda.alert(idioma.preencha_nome);
			form.nome.focus();
			return false;
		}
		if(form.email.value != '' && !checkMail(form.email.value)  )
		{
			agenda.alert(idioma.email_invalido);
			form.email.focus();
			return false;
		}
		if(form.ddd.value=="")
		{
			agenda.alert(idioma.informe_ddd);	
			form.ddd.focus();
			return false;
		}
		if(isNaN(form.ddd.value))
		{
			agenda.alert(idioma.invalido_ddd);	
			form.ddd.focus();
			return false;
		}
		if(form.telefone.value=="")
		{
			agenda.alert(idioma.preencha_tel);
			form.telefone.focus();
			return false;
		}
		if(!validaTelefone(form.telefone.value, true))
		{
			agenda.alert(idioma.telefone_invalido);
			form.telefone.focus();
			return false;
		}

		return true;
	},
	
	enviaFormulario: function ( form )
	{//||
		if(agenda.enviando)return ;
		if(agenda.validaFormulario(form) )
		{
			var data = agenda.data + ' ' + $('ihorario').value;
			var telefone = '(' + form.ddd.value  + ') ' + form.telefone.value ;
			var telefone2 = '(' + form.ddd2.value  + ') ' + form.telefone2.value ;
			var pForm = 'nome=' + form.nome.value +
						'&email=' + form.email.value + 
						'&telefone=' + telefone + 
						'&telefone2=' + telefone2 + 
						'&dataN=' + form.dataN.value +
						'&data=' + data;
			$('agendaHomeNome').setHTML(form.nome.value);
			agenda.req = createXMLHTTP_S();
			agenda.req.open('POST','marcarConsulta.php',true);
			agenda.req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 			agenda.req.onreadystatechange = function()
			{
				if(agenda.req.readyState==4)
				{
					if(agenda.req.responseText.indexOf('ok')!= -1){
						agenda.respostaFormulario();
					} else {
						agenda.alert(agenda.req.responseText);
					}
					agenda.enviandoForm(1);
				}
			}
			agenda.alert('');
			agenda.enviandoForm(0);
			agenda.req.send(pForm);

		}
	},
	respostaFormulario : function()
	{
		
		agenda.fx = $('AgendaHomeFormulario').effects({duration: 500, transition: Fx.Transitions.Quart.easeInOut});
		agenda.fx.start({ 'opacity' : [ 1, 0]}).chain(function(){ $('AgendaHomeFormulario').setStyle( 'display','none'); agenda.exibeResposta();} );
	},
	escondeResposta:function()
	{
		agenda.fx = $('AgendaHomeResposta').effects({duration: 500, transition: Fx.Transitions.Quart.easeInOut});
		agenda.fx.start({ 'opacity' : [ 1, 0]}).chain(function(){ $('AgendaHomeResposta').setStyle( 'display','none'); agenda.exibeData();} );
	},
	exibeResposta:function()
	{
		agenda.fx.stop();
		$('AgendaHomeResposta').setStyle('display','block');
		agenda.fx = $('AgendaHomeResposta').effects({duration:500, transition: Fx.Transitions.Quart.easeInOut});
		agenda.fx.start({'opacity': [0,1]});		
	},
	enviandoForm: function(acao)
	{
		switch(acao)
		{
			case 0:
				agenda.enviando = true;
				$('agendaBotao').value = 'aguarde...';
			break;
			case 1:
				agenda.enviando = false;
				$('agendaBotao').value = 'Marcar Consulta';
			break;
		}
	},
	alert:function(msg)
	{
		if(msg=='')
		{
			$('agendaErro').setHTML('&nbsp;');
			$('agendaErro').setStyles('background: none; border-color: #F6F6F6;');
			return;
		}
		$('agendaErro').setHTML(msg);
		agenda.fx.stop();
		agenda.fx = new Fx.Styles('agendaErro', {duration: 1000, transition: Fx.Transitions.linear});		
		agenda.fx.start({ 'background-color' : [ '#ffffff' , '#FFcccc'], 'border-color' : ['#ffffff', '#ff000'] })
			.chain(function()
							{
								this.start.delay(200,this, { 'background-color' : [ '#FFcccc' , '#ffeeee'], 'border-color' : ['#ff000','#ffcccc'] });
							});
	},
	onChangeDDD: function (obj, objTel)
	{
		if(obj.value.length>=2)
			objTel.focus();
			
	}
}
function validaTelefone(valor, notDdd)
{
	if(notDdd)
		var reg = /^([0-9]{4}(-){0,1}[0-9]{4})$/;
	else
		var reg = /^(((\([0-9]{2}\)){0,1}( ){0,1}[0-9]{4}(-){0,1}[0-9]{4})|([0-9]{10}))$/;
	if(reg.test(valor))
	{
		return true;	
	}
	else
	{
		return false;	
	}
}

function focusElement(obj)
{
	$(obj).setStyle('background', '#ffe');
	obj.focus();
	obj.onblur = function(){ blurElement(this); };
}
function blurElement(obj)
{
	$(obj).setStyle('background', '#fff');
	obj.onfocus = function(){ focusElement(this); };
}


//Formularios
// JavaScript Document
fcontato =
{	form : false,
	valida:function(Form)
	{
		if(Form.nome.value=="")
		{
			alert(idioma.preencha_nome);
			return false;
		}
		if(!ValidaEmail(Form.email.value))
		{
			alert(idioma.email_invalido);
			return false;
		}
		if(Form.assunto.value=="")
		{
			alert(idioma.preencha_assunto);
			return false;
		}
		if(Form.assunto.mensagem=="")
		{
			alert(idioma.escreva_mensagem);
			return false;
		}
		
		return true;
//		escreva_mensagem
	},
	envia: function(objForm)
	{
		if(this.valida(objForm))
		{
			objForm.submit();
		}
	}
}


//Validar e-mail
function ValidaEmail(valor)
{
	regex_email=/^([a-zA-Z0-9._-]*)@[a-zA-Z0-9._-]+(\.[a-zA-Z0-9._-]*)+$/i;
	
	if(!regex_email.test(valor))
	{
		return false;
	}
	else
	{
		return true;
	}
}


function shMenu()
{
		document.removeEvent('click',nEvent);
	if($('cores').getStyle('display')== 'block')
	{
		$('cores').setStyle('display','none');
	}
	else
	{
		$('cores').setStyle('display','block');
		(function() { document.addEvent('click', nEvent ) }).delay(100);
	}
}

function nEvent(event)
{
	document.removeEvent('click',nEvent);
	$('cores').setStyle('display','none');
}



function exibeIcone(url){
	var icone;
	icone = "<div style='position:absolute; margin-left:115px;	margin-top:-5px; width:74px; height:70px; z-index:300; background:url("+url+")'>&nbsp;</div>";
	document.write(icone);
}
function trocaCaso(caso, img1, img2)
{
	var so = new SWFObject("flash/comparativo" + iSufix + ".swf", "semFlash", "450", "245", "6", "#D5C391");
	so.addParam("wmode", "transparent");
	so.addVariable("img1",'imagens/casos/' + img1);
	so.addVariable("img2",'imagens/casos/' + img2);
	so.addVariable("caso",'Caso 0' + caso);
	
	for($i=1;cas = $('caso_' + $i);$i++){
		if(caso == $i)
			cas.addClass('ativo');
		else
			cas.removeClass('ativo');
	}
	if(!so.write('CasCaso')){
		$('casoInicial').src = 'imagens/casos/' + img1;
		$('casoCir').src = 'imagens/casos/' + img2;
	}
}

Color = {

	altColor:function (cor) {
		
			req = createXMLHTTP_S();
			req.open('GET','index.php?ajax=1&cor=' + cor,true);
			req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 			req.onreadystatechange = function()
			{
				if(req.readyState==4)
				{
					location = window.location;
				}
			}
			req.send('');
	}
}
function altIdioma (idioma) {
		req = createXMLHTTP_S();
		req.open('GET','index.php?ajax=1&idioma=' + idioma,true);
		req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		req.onreadystatechange = function()
		{
			if(req.readyState==4)
			{
				location = window.location.href.split('#')[0];
			}
		}
		req.send('');		
}
function MenuTopo(cor, area) {
	var so = new SWFObject("flash/menu_horizontal_final.swf", "semFlash", "1003", "120", "6", "#EBE9D4");
	so.addParam("wmode", "transparent");
	if(area)
		so.addVariable("cat",area);
	if(cor)
		so.addVariable("pintar",cor);

	so.addVariable("local",1);
	
	so.write('menuInternoTopo');
	
}

function orcamento ()  
{
 document.forms[0].submit();
}
function impre_pes(parm1)
 {
    window.open("paginas/enquete_resultado.php?id="+parm1+"&modo=1&qual="+document.getElementById('qual').value,"_new","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=180,height=210");
  }

function passarValor(parm1)
  { 
    document.getElementById('qual').value = parm1; 
  } 
  
  function verifica(parm1)
  {
  	for(i=0;document.fenquete.resp.length > i;i++)
	{
		if(document.fenquete.resp[i].checked == true )
		{
			    window.open("include/enquete_resultado.php?id="+parm1+"&modo=1&qual="+document.fenquete.resp[i].value,"_new","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=311,height=300");

			vazio = false;
			break;
		}
		else{
			vazio = 1;
		}
	}
	if(vazio){
		alert('Marque uma opção')
	}
  }
  
  
  function resultado(id){
   	window.open("include/enquete_resultado.php?id="+id,"_new","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=311,height=300");

  }


function mostra(id)
{
	var x;
	if(document.getElementById(id).style.display == 'block')
	{
	document.getElementById(id).style.display = 'none';
	x = 1;
	}
	
	$$('.respostaKIDS').setStyle('display','none');
	
	
	if(document.getElementById(id).style.display == 'none' && x!=1)
	{
	document.getElementById(id).style.display = 'block';
	}
}

function in_array (needle, haystack, argStrict) {
    // Checks if the given value exists in the array  
    // 
    // version: 911.718
    // discuss at: http://phpjs.org/functions/in_array    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: vlado houba
    // +   input by: Billy
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);    // *     returns 1: true
    // *     example 2: in_array('vlado', {0: 'Kevin', vlado: 'van', 1: 'Zonneveld'});
    // *     returns 2: false
    // *     example 3: in_array(1, ['1', '2', '3']);
    // *     returns 3: true    // *     example 3: in_array(1, ['1', '2', '3'], false);
    // *     returns 3: true
    // *     example 4: in_array(1, ['1', '2', '3'], true);
    // *     returns 4: false
    var key = '', strict = !!argStrict; 
    if (strict) {
        for (key in haystack) {
            if (haystack[key] === needle) {
                return true;            }
        }
    } else {
        for (key in haystack) {
            if (haystack[key] == needle) {                return true;
            }
        }
    }
     return false;
}


depoimentos = {
	anterior: false,
	carregados:new Array(),
	carregar:function(depoimento, local){
		if(in_array(local,depoimentos.carregados)) {
			return false;	
		}
		if($(local).innerHTML != '') return;
		var so2 = new SWFObject("flash/depoimentos.swf" , "depoimentos" + depoimento, '240', "160", "6", "#333333");
		so2.addParam("wmode", "transparent");
		$(local).addClass('black');
		//depoimento
		//'depoimentos.swf'
		depoimentos.desativar(depoimentos.anterior);
		depoimentos.anterior = local;
		so2.addVariable("fvideo",'http://www.cir.com.br/flvs/'+depoimento);
		so2.addVariable("endVideo","depoimentos.desativar('" + local + "')");
		
		so2.write(local);		
	},
	desativar:function(local){
		if(local){
			$(local).removeClass('black');
			$(local).empty();
		}
	},
	fechar:function(){
		if($('video') && !$('video_not')){
			$('video').remove();
			$('video_fim').setStyle('display','block');
		}
	},
	abrir_filme:function(){
		if($('ImgHospital'))$('ImgHospital').setStyle('display','none');
		
		var so2 = new SWFObject("flash/idioma_filme.swf", "boxPublicidade2", '555', "305", "6", "#000000");
		//so2.addParam("wmode", "transparent");
		if($('idioma_filme'))
			$('idioma_filme').remove();
		so2.addVariable("ext_idioma",Idioma);
		//
		$('filme_flash').setStyle('display','block');
		so2.write('filme_flash');
	},
	fechar_filme:function(){
		if($('filme_link')){
			$('filme_link').setStyle('display','block');
			$('filme_flash').remove();
		}else if($('ImgHospital')){
			$('filme_flash').empty();
			$('ImgHospital').setStyle('display','');
		}
	}
}

CasosClinicos = {
	inReq:false,
	call : function( idEspecialidade, antes, depois, obj ) {
		if(CasosClinicos.inReq)return;
		req = new ajax();
		req.open('GET','ajax.php?pg=include/box_casos&id_especialidade=' + idEspecialidade,true);
		tes = $$('.linkAtivo');
		
		tes.removeClass('linkAtivo');
		//alert(obj);
		$(obj).addClass('linkAtivo');
		location = "#topo_casos";
		req.onreadystatechange = function()
		{
			if(req.readyState==4)
			{
				CasosClinicos.inReq=false;
				$('box_casos').innerHTML = '' ;
				$('box_casos').innerHTML = req.responseText;
				trocaCaso('1', antes, depois);
			}
		}
		CasosClinicos.inReq=true;
		req.send(0);
			
	}
}