var __openedMenu = '';
var __openedSubMenu = '';

function validateReservaForm(__IDTag){
	if(checkInputValues(__IDTag) > 0){
		alert('Existem Campos Obrigatorios por preencher!');
		return false;
	}else{
		if(isValidEmailAddress($('#tfEmail').val())){
			return true;
		}else{
			alert('Email não é valido!');
			return false;
		}
	}
}

//********************************************************************************************************************************
//********************************************************************************************************************************
//********************************************************************************************************************************

function checkConsultaEventosCampos(__IDTag){
	if(checkInputValues(__IDTag) > 0){
		alert('Existem Campos Obrigatorios por preencher!');
		return false;
	}else{
		if(isValidEmailAddress($('#tfEmail').val())){
			$.post('enviarconsulta.php',$("#formEventos").serialize(),
				function(data) {
					//alert(data);
					if($.trim(data) != 1){
						$('.scroll-pane').html(data);
					}else{
						$('.scroll-pane').html(data);
					}
				}
			);
			//alert('sadsad');
			return false;
		}else{
			alert('Email não é valido!');
			return false;
		}
	}
}

//********************************************************************************************************************************
//********************************************************************************************************************************
//********************************************************************************************************************************

function checkLivroCampos(__IDTag){
	if(checkInputValues(__IDTag) > 0){
		alert('Existem Campos Obrigatorios por preencher!');
		return false;
	}else{
		if(isValidEmailAddress($('#tfEmail').val())){
			$.post('enviarlivro.php',$("#formEventos").serialize(),
				function(data) {
					//alert(data);
					if($.trim(data) != 1){
						$('.scroll-pane').html(data);
					}else{
						$('.scroll-pane').html(data);
					}
				}
			);
			//alert('sadsad');
			return false;
		}else{
			alert('Email não é valido!');
			return false;
		}
	}
}

//********************************************************************************************************************************
//********************************************************************************************************************************
//********************************************************************************************************************************

function checkContactenosCampos(__IDTag){
	if(checkInputValues(__IDTag) > 0){
		alert('Existem Campos Obrigatorios por preencher!');
		return false;
	}else{
		if(isValidEmailAddress($('#tfEmail').val())){
			$.post('enviarcontactenos.php',$("#formEventos").serialize(),
				function(data) {
					//alert(data);
					if($.trim(data) != 1){
						$('.scroll-pane').html(data);
					}else{
						$('.scroll-pane').html(data);
					}
				}
			);
			//alert('sadsad');
			return false;
		}else{
			alert('Email não é valido!');
			return false;
		}
	}
}

//********************************************************************************************************************************
//********************************************************************************************************************************
//********************************************************************************************************************************

function isValidEmailAddress(emailAddress) {
 		var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
 		return pattern.test(emailAddress);
}

function slideMenu(id,level){
	if(__openedMenu != ""){
		if(level == 2){
			if(__openedSubMenu != ""){
				$('#'+id).slideToggle('slow');
			}else{
				$('#'+id).slideToggle('slow');
				__openedSubMenu = id;
			}
		}else{
			if(__openedSubMenu != ""){
				$('#'+__openedSubMenu).slideToggle('slow',function(){
					$('#'+__openedMenu).slideToggle('slow',function(){
						$('#'+id).slideToggle('slow');
						__openedMenu = id;
						__openedSubMenu = '';
					});
					
				});
			}else{
				$('#'+__openedMenu).slideToggle('slow',function(){
					$('#'+id).slideToggle('slow');
					__openedMenu = id;
					__openedSubMenu = '';
				});
			}
		}
	}else{
		$('#'+id).slideToggle('slow');
		__openedMenu = id;
	}
	
}

function setOpenedMenu(id){
	__openedMenu = id;
}

function setOpenedSubMenu(id){
	__openedSubMenu = id;
}


//********************************************************************************************************************************
//********************************************************************************************************************************
//********************************************************************************************************************************

function  checkInputValues(__IDTag){
	var mensagem = "";
	var counter = 0;
	$("#"+__IDTag+" input[class*=required],#"+__IDTag+" textarea[class*=required]").each(function()
		{
			if($(this).val() == ""){
				counter++;
				//$(this).css("border","#FF0000 dotted 1px");
				//$("#"+__IDTag+" #alert-"+$(this).attr('id')).css("display","block");
				//mensagem += $(this).attr('title')+'<br>';
			}
		}
	);
	
	return counter;
}

//******************************************************************************************
//******************************************************************************************
//******************************************************************************************

function validateValue(element){
	if(element.val() =="")
		element.css("border","#FF0000 dotted 1px");
	else
		element.css("border","#7F9DB9 dotted 1px");
}

//******************************************************************************************
//******************************************************************************************
//******************************************************************************************

function aplicarFancybox(){
	$("img[src*=uploads]").each(function(){
			$(this).wrap('<a href="'+$(this).attr('src')+'" rel="pics"></a>');
	});
	
	$("a[rel=pics]").fancybox({
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'titlePosition' 	: 'over',
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Image ' +  (currentIndex + 1) + ' / ' + currentArray.length + '</span>';
		}
	});
}
