/**
 * Funções para funcionalidade "Fotografo"
 *
 * @version  0.0.1
 * @autor: Jonathan B. Kolling (jonathan@gadbrivia.com.br) 
 */
function Fotografo()
{
	// ID do formulario de filtro
	var frmFotografoFiltro = '#frmFotografoFiltro';
	// ID do formulario de contato
	var frmFotografoContato = '#frmFotografoContato';
	// ID do formulario de perfil
	var frmFotografoPerfil = '#frmFotografoPerfil';
	// ID do formulario de Portfolio
	var frmFotosPortfolio = '#frmFotosPortfolio';
	// ID do formulario de Portfolio de alterar titulo e legenda
	var frmFotografoPortfolioAlteraTituloLegenda = '#frmFotografoPortfolioAlteraTituloLegenda';
	
	
	// Verifica se o formulario está definido
	if($(frmFotografoFiltro).length > 0)
	{
		
		if($("#selEstado").val() == "")
		{
			$("#selCidade").attr("disabled", true); 
		}
		complementoUrl = "";
		if($("#hdnBusca").val() != "")
		{
			complementoUrl = complementoUrl  + "busca-" + $("#hdnBusca").val() + "/";
		}
		if($("#hdnCategoria").val() != "")
		{
			complementoUrl = complementoUrl  + "categoria-" + $("#hdnCategoria").val() + "/";
		}
		$("#selEstado").change(function()
		{
			window.location.href = SITE_CAMINHO_ABSOLUTO + "fotografo/estado-"+ $(this).val() +"/"+ complementoUrl
		});
		
		$("#selCidade").change(function()
		{
			valorEstado = $("#selEstado").val();
			window.location.href = SITE_CAMINHO_ABSOLUTO + "fotografo/estado-"+ valorEstado + "/" + "cidade-" + $(this).val() +"/"+ complementoUrl
		});
	}
	
	
	
	
	// Formulario de contato
	if($(frmFotografoContato).length > 0)
	{
		// Limitar campo textarea para no máximo 500 caracteres
		$(frmFotografoContato+" #txaMensagem").keydown(function()
		{
			$(this).val($(this).val().substr(0,500));
		});
	
		$(frmFotografoContato).validate
		(
			{
				submitHandler:function(frm)
				{
					var formularioDados = $(frmFotografoContato).serialize();
					
					$.ajax(
					{
						type: "POST",
						dataType: "json",
						data: formularioDados,
						url: SITE_CAMINHO_ABSOLUTO + 'fotografo/enviar-contato/',
						complete: function(resposta, status)
						{
							var retorno 		= new Array();
						   	var totalRegistros 	= 0;
						   	
						   	eval("retorno = "+resposta.responseText+";");				
							
							if(retorno)
							{
								try
								{
									if(retorno.length > 0)
									{										
										$("#mensagemErro").html(MSG41);	
										$("#txtNome").val('');
										$("#txtEmail").val('');
										$("#txaMensagem").val('');
									}
								}
								catch(e)
								{}
							}
							else
							{
								$("#mensagemErro").html(MSG42);
							}					
						}
					});
					
				},
				errorPlacement:function(error,element)
				{					
					if(error.html() != $("#mensagemErro").html()) $("#mensagemErro").html(error.html());					
				},
				highlight: function(element, errorClass)
				{
					$(element).addClass(errorClass);
				},		
				unhighlight: function(element, errorClass)
				{
					$(element).removeClass(errorClass);
					
					if($(".input-erro",frmFotografoContato).length == 0) $("#mensagemErro").html("");
				},
				errorClass: "input-erro",
				errorElement:"span",
				rules:
				{
					txtNome:
					{
						required: true
					},
					txtEmail:
					{
						required: true,
						email: true
					},
					txaMensagem:
					{
						required: true
					}
				},
				messages:
				{
					txtNome:
					{
						required: MSG04
					},
					txtEmail:
					{
						required: MSG04,
						email: MSG27.replace("{CAMPO}","E-mail")
					},
					txaMensagem:
					{
						required: MSG04
					}
				}
			}
		);
	}
	
	if($(frmFotografoPerfil).length > 0)
	{
		$(frmFotografoPerfil).validate
		(
			{
				submitHandler:function(frm)
				{
					$(frm)[0].submit();					
				},
				errorPlacement:function(error,element)
				{					
					if(error.html() != $("#mensagemErro").html()) $("#mensagemErro").html(error.html());					
				},
				highlight: function(element, errorClass)
				{
					$(element).addClass(errorClass);
				},		
				unhighlight: function(element, errorClass)
				{
					$(element).removeClass(errorClass);
					
					if($(".erro",frmFotografoContato).length == 0) $("#mensagemErro").html("");
				},
				errorClass: "erro",
				errorElement:"span",
				rules:
				{
					uplFoto:
					{
						required: true,
						accept: 'png|jpe?g|gif'
					},
					txaSobre:
					{
						required: true
					}
				},
				messages:
				{
					uplFoto:
					{
						required: MSG04,
						accept: MSG14.replace('{EXTENSOES}','JPG, GIF, PNG.')
					},
					txaSobre:
					{
						required: MSG04
					}
				}
			}
		);
	}
		
	if($(frmFotosPortfolio).length > 0)
	{
		$(frmFotosPortfolio).validate
		(
			{
				submitHandler:function(frm)
				{
					$(frm)[0].submit();					
				},
				errorPlacement:function(error,element)
				{					
					if(error.html() != $("#mensagemErro").html()) $("#mensagemErro").html(error.html());					
				},
				highlight: function(element, errorClass)
				{
					$(element).addClass(errorClass);
				},		
				unhighlight: function(element, errorClass)
				{
					$(element).removeClass(errorClass);
					
					if($(".erro",frmFotografoContato).length == 0) $("#mensagemErro").html("");
				},
				errorClass: "erro",
				errorElement:"span",
				rules:
				{
					uplFoto:
					{
						required: true,
						accept: 'png|jpe?g|gif'
					},
					txtTitulo:
					{
						required: true
					}
				},
				messages:
				{
					uplFoto:
					{
						required: MSG04,
						accept: MSG14.replace('{EXTENSOES}','JPG, GIF, PNG.')
					},
					txtTitulo:
					{
						required: MSG04
					}
				}
			}
		);
	}
	
		
	if($(frmFotografoPortfolioAlteraTituloLegenda).length > 0)
	{
		$(frmFotografoPortfolioAlteraTituloLegenda).validate
		(
			{
				submitHandler:function(frm)
				{
					$(frm)[0].submit();					
				},
				errorPlacement:function(error,element)
				{					
					if(error.html() != $("#mensagemErro").html()) $("#mensagemErro").html(error.html());					
				},
				highlight: function(element, errorClass)
				{
					$(element).addClass(errorClass);
				},		
				unhighlight: function(element, errorClass)
				{
					$(element).removeClass(errorClass);
					
					if($(".erro",frmFotografoContato).length == 0) $("#mensagemErro").html("");
				},
				errorClass: "erro",
				errorElement:"span",
				rules:
				{
					txtTitulo:
					{
						required: true
					}
				},
				messages:
				{
					txtTitulo:
					{
						required: MSG04
					}
				}
			}
		);
	}
	
} 
