function changeListImage(imgid){
	var imgid = "#list_image_" +imgid;
	$(imgid).attr('src',site_base_url+"/images/static/arrow4.png");
}

function changeListImageBack(imgid){
	var imgid = "#list_image_" +imgid;
	$(imgid).attr('src',site_base_url+"/images/static/arrow.png");
}

function valFrmCad(){
	borderSettings = "1px solid #AF1515";

	if($('#nome').val() == ''){
		toggle_box('Nome em branco.', 'nome');
		$('#nome').focus();
		$('#nome').css("border", borderSettings); 
		return false;
	}
	if($('#sobrenome').val() == ''){
		toggle_box('Sobrenome em branco.', 'sobrenome');
		$('#sobrenome').focus();
		$('#sobrenome').css("border", borderSettings); 
		return false;
	}
	if($('#dia').val() == ''){
		toggle_box('Data de nascimento incompleta.', 'dtnasc');
		return false;
	}
	if($('#mes').val() == ''){
		toggle_box('Data de nascimento incompleta.', 'dtnasc');
		return false;
	}
	if($('#ano').val() == ''){
		toggle_box('Data de nascimento incompleta.', 'dtnasc');
		return false;
	}
	var dtNasc = $('#dia').val() + "/" + $('#mes').val() + "/" + $('#ano').val();
	var d = new Date();
	var dtMin = d.getFullYear() - 18;
	var dtMax = d.getFullYear() - 100;
	if( !VerificaData( dtNasc )){
		toggle_box('Data de nascimento inválida.', 'dtnasc');
		$('#dia').focus();
		return false;
	}
	if($('#ano').val() > dtMin || $('#ano').val() < dtMax ){
		toggle_box('Data de nascimento inválida.', 'dtnasc');
		$('#ano').focus();
		return false;
	}
	if (!$("input[type=radio][name=sexo]:checked").val()){
		toggle_box('Sexo em branco.', 'sexo');
		$('#sexo').focus();
		$('#lbl_sexo').css("color","#AF1515"); 
		return false;
	}
	if($('#estado_civil').val() == 'sel'){
		toggle_box('Selecione o Estado Civil.', 'est_civil');
		$('#estado_civil').focus();
		$('#estado_civil').css("border", borderSettings); 
		return false;
	}
	if($('#logradouro').val() == 'sel'){
		toggle_box('Selecione o Logradouro.', 'logradouro');
		$('#logradouro').focus();
		$('#logradouro').css("border", borderSettings); 
		return false;
	}
	if($('#endereco').val() == ''){
		toggle_box('Endereço em branco.', 'endereco');
		$('#endereco').focus();
		$('#endereco').css("border", borderSettings); 
		return false;
	}
	if($('#numero').val() == ''){
		toggle_box('Nº em branco.', 'numero');
		$('#numero').focus();
		$('#numero').css("border", borderSettings); 
		return false;
	}
	if($('#bairro').val() == ''){
		toggle_box('Bairro em branco.', 'bairro');
		$('#bairro').focus();
		$('#bairro').css("border", borderSettings); 
		return false;
	}
	if($('#cidade').val() == ''){
		toggle_box('Cidade em branco.', 'cidade');
		$('#cidade').focus();
		$('#cidade').css("border", borderSettings); 
		return false;
	}
	if($('#estado').val() == 'sel'){
		toggle_box('Selecione o Estado.', 'estado');
		$('#estado').focus();
		$('#estado').css("border", borderSettings); 
		return false;
	}
	if($('#cep').val() == ''){
		toggle_box('CEP em branco.', 'cep');
		$('#cep').focus();
		$('#cep').css("border", borderSettings); 
		return false;
	}
	if($('#cep').val().length < 9){
		toggle_box('CEP incompleto.', 'cep');
		$('#cep').focus();
		$('#cep').css("border", borderSettings); 
		return false;
	}
	if(!checkMail($('#email').val())){
		toggle_box('E-mail inválido.', 'email');
		$('#email').focus();
		$('#email').css("border", borderSettings); 
		return false;
	}
	if($('#ddd_tel').val() == ''){
		toggle_box('DDD em branco.', 'tel');
		$('#ddd_tel').focus();
		$('#ddd_tel').css("border", borderSettings); 
		return false;
	}
	if($('#ddd_tel').val().length < 2){
		toggle_box('DDD incompleto.', 'tel');
		$('#ddd_tel').focus();
		$('#ddd_tel').css("border", borderSettings);
		return false;
	}
	if($('#tel').val() == ''){
		toggle_box('Telefone Residencial em branco.', 'tel');
		$('#tel').focus();
		$('#tel').css("border", borderSettings); 
		return false;
	}
	if($('#tel').val().length < 9){
		toggle_box('Telefone Residencial incompleto.', 'tel');
		$('#tel').focus();
		$('#tel').css("border", borderSettings);
		return false;
	}
	if($('#ddd_cel').val() == ''){
		toggle_box('DDD em branco.', 'cel');
		$('#ddd_cel').focus();
		$('#ddd_cel').css("border", borderSettings); 
		return false;
	}
	if($('#ddd_cel').val().length < 2){
		toggle_box('DDD incompleto.', 'cel');
		$('#ddd_cel').focus();
		$('#ddd_cel').css("border", borderSettings);
		return false;
	}
	if($('#cel').val() == ''){
		toggle_box('Telefone Celular em branco.', 'cel');
		$('#cel').focus();
		$('#cel').css("border", borderSettings);
		return false;
	}
	if($('#cel').val().length < 9){
		toggle_box('Telefone Celular incompleto.', 'cel');
		$('#cel').focus();
		$('#cel').css("border", borderSettings);
		return false;
	}
	if (!$("input[type=checkbox][name=termo]:checked").val()){
		toggle_box('Verifique o termo de privacidade.', 'acc');
		$('#termo').focus();
		$('#termo').css("border", borderSettings);
		return false;
	}
	return true;
}

function toggle_box(txt, cx){
	$('#cx_'+cx).html(txt);
	$('#cx_'+cx).fadeIn();
	$('#cx_'+cx).delay(5000).fadeOut();
}

function VerificaData(digData){
	var bissexto = 0;
	var data = digData;
	var tam = data.length;
	if (tam == 10){
		var dia = data.substr(0,2);
		var mes = data.substr(3,2);
		var ano = data.substr(6,4);
		
		if ((ano > 1900)||(ano < 2100)){
			switch (mes){
				case '01':
				case '03':
				case '05':
				case '07':
				case '08':
				case '10':
				case '12':
					if  (dia <= 31){
						return true;
					}
					break;
				case '04':          
				case '06':
				case '09':
				case '11':
					if  (dia <= 30){
						return true;
					}
					break;
				case '02':
					if ((ano % 4 == 0) || (ano % 100 == 0) || (ano % 400 == 0)){ 
						bissexto = 1; 
					}
					if ((bissexto == 1) && (dia <= 29)){ 
						return true;              
					} 
					if ((bissexto != 1) && (dia <= 28)){
						return true; 
					}
					break;
			}
		}
	}
	return false;
}

function mascara(o,f){
    v_obj=o;
    v_fun=f;
    setTimeout("execmascara()",1);
}

function execmascara(){
    v_obj.value=v_fun(v_obj.value);
}

function soNumeros(v){
    return v.replace(/\D/g,"");
}

function mcep(v){
    v=v.replace(/\D/g,"");
    v=v.replace(/^(\d{5})(\d)/,"$1-$2");
    return v;
}

function telefone(v){
    v=v.replace(/\D/g,"");
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2");
    v=v.replace(/(\d{4})(\d)/,"$1-$2");
    return v;
}

function telefone2(v){
    v=v.replace(/\D/g,"");
    v=v.replace(/(\d{4})(\d)/,"$1-$2");
    return v;
}
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;
	}
}

function verify_to_clear(obj,label){
	if ($(obj).val() == label) {
		$(obj).val("");
		$(obj).css("textTransform","none");
	} else if ($(obj).attr('name') == 'search'){
		$(obj).val("Buscar");
		$(obj).css("textTransform","none");	
	} else if ($(obj).val().length == 0) {
		$(obj).val(label);
		$(obj).css("textTransform","uppercase");
	}
}

function show_xbox(title,content){
	$('#xbox-bg').animate({"opacity":0.80});
	$('#xbox-bg').show();
	$('.xbox').fadeIn("slow");
	$('.xbox').animate({"opacity":1});
	$('#xbox_title').html(title);
	$('#xbox_content').html(content);
}
function close_xbox(){
	$('#xbox-bg,.xbox').fadeTo("fast",0,function(){
		$(this).hide();
		$('.xbox').hide();
	});
}
function valFrmInd(){
	var bgColor = "#FAE8C8";
	if($('#my_name').val().length < 2 || $('#my_name').val() == "Seu Nome Completo"){
		$('#my_name').focus();
		$('#my_name').css("backgroundColor",bgColor);
		return false;
	}
	
	if(!checkMail($('#my_email').val()) || $('#my_email').val() == "Seu E-Mail"){
		$('#my_email').focus();
		$('#my_email').css("backgroundColor",bgColor);
		return false;
	}

	if($('#his_name').val().length < 2 || $('#his_name').val() == "Nome do Seu Amigo(a)"){
		$('#his_name').focus();
		$('#his_name').css("backgroundColor",bgColor);
		return false;
	}

	if(!checkMail($('#his_email').val()) || $('#his_name').val() == "E-Mail do Seu Amigo(a)"){
		$('#his_email').focus();
		$('#his_email').css("backgroundColor",bgColor);
		return false;
	}
	
	$.post("do.indique.php", $('#indique_form').serialize(),
		function(data){
			if(data=="1"){
				$('#my_name').val("Seu Nome Completo");
				$('#my_email').val("Seu E-Mail");
				$('#his_name').val("Nome do Seu Amigo(a)");
				$('#his_email').val("E-Mail do Seu Amigo(a)");
				
				show_xbox("Indique","Indicação enviada com sucesso!");
			} else {
				show_xbox("Indique","Falha ao enviar indicação. Tente novamente.");
			}
		});
	return false;
}

function go_menu(item){
	window.top.location.href = item;
}

function showTerms(){
	$.get('termo.html', function(data){
		show_xbox("Termo de Privacidade - Dr. Wilson Aguiar",data);
	});
}

function increaseInfoSize(){
	var currentSize = parseInt($('.content p').css('fontSize'));
	$('.content p').animate({
		fontSize: (currentSize+2)+"px"
	}, 500, function(){});
}

function decreaseInfoSize(){
	var currentSize = parseInt($('.content p').css('fontSize'));
	$('.content p').animate({
		fontSize: (currentSize-2)+"px"
	}, 500, function(){});
}

function openAddress(num){
	if(num == 1){
		var link = "http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=Avenida+Moema,+300,+Moema,+S%C3%A3o+Paulo+04077-020,+Brasil&aq=0&sll=-23.591677,-46.627007&sspn=0.168955,0.308647&ie=UTF8&hq=&hnear=Av.+Moema,+300+-+Moema,+S%C3%A3o+Paulo,+04077-020,+Brazil&ll=-23.604321,-46.659064&spn=0.01105,0.01929&z=16";
	}else{
		var link = "http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=Alameda+Purus,+105+Alphaville+Barueri,+S%C3%A3o+Paulo&aq=&sll=-23.493398,-46.853256&sspn=0.01106,0.01929&ie=UTF8&hq=&hnear=Alameda+Purus,+105+-+Alphaville+Industrial,+Barueri+-+S%C3%A3o+Paulo,+06454-030,+Brazil&z=16&iwloc=A";
	}
	window.open(link, '_blank');
}

function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',o='opera',h=document.documentElement,b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);
